|
1 /* |
|
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalTechnology |
|
22 */ |
|
23 |
|
24 #include "plugincharsasymsignstep.h" |
|
25 #include "plugincharschecker.h" |
|
26 |
|
27 #include "keypair.h" |
|
28 #include "cryptokeypairgeneratorapi.h" |
|
29 #include "cryptosignatureapi.h" |
|
30 |
|
31 using namespace CryptoSpi; |
|
32 |
|
33 CPluginCharsAsymSignStep::~CPluginCharsAsymSignStep() |
|
34 { |
|
35 } |
|
36 |
|
37 CPluginCharsAsymSignStep::CPluginCharsAsymSignStep() |
|
38 { |
|
39 SetTestStepName(KPluginCharsAsymSignStep); |
|
40 } |
|
41 |
|
42 TVerdict CPluginCharsAsymSignStep::doTestStepPreambleL() |
|
43 { |
|
44 SetTestStepResult(EPass); |
|
45 return TestStepResult(); |
|
46 } |
|
47 |
|
48 TVerdict CPluginCharsAsymSignStep::doTestStepL() |
|
49 { |
|
50 |
|
51 INFO_PRINTF1(_L("Plugin Characteristics - Asymmetric Signer Chracteristics")); |
|
52 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); |
|
53 |
|
54 if (TestStepResult()==EPass) |
|
55 { |
|
56 |
|
57 //Assume faliure, unless all is successful |
|
58 SetTestStepResult(EFail); |
|
59 |
|
60 TVariantPtrC algorithmUid; |
|
61 TVariantPtrC paddingMode; |
|
62 TVariantPtrC invalidPaddingMode; |
|
63 |
|
64 //Each of the individual parameters required to create the Asymmetric Singer object |
|
65 //are read in from the specified INI configuration file |
|
66 if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) || |
|
67 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) || |
|
68 !GetStringFromConfig(ConfigSection(),KConfigInvalidPaddingMode,invalidPaddingMode)) |
|
69 { |
|
70 ERR_PRINTF1(_L("** .INI Error: Asymmetric Signer Arguments Not Located **")); |
|
71 SetTestStepResult(EFail); |
|
72 } |
|
73 else |
|
74 { |
|
75 CCryptoParams* keyParams = CCryptoParams::NewLC(); |
|
76 |
|
77 //**************************************************** |
|
78 //Create Key Pair and Key Pair Generator Objects |
|
79 CKeyPair* keyPair = NULL; |
|
80 CKeyPairGenerator * keypairImpl = NULL; |
|
81 |
|
82 INFO_PRINTF1(_L("Generating RSA keys")); |
|
83 |
|
84 // create an RSA key pair |
|
85 keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid); |
|
86 keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid); |
|
87 |
|
88 // create a key pair generator implementation interface |
|
89 TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl, |
|
90 KRSAKeyPairGeneratorUid, |
|
91 keyParams)); |
|
92 |
|
93 CleanupStack::PushL(keypairImpl); |
|
94 |
|
95 // Create a Key Pair |
|
96 TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair)); |
|
97 |
|
98 CleanupStack::PushL(keyPair); |
|
99 |
|
100 //***************************************************** |
|
101 |
|
102 CSigner* asymmetricSignerImpl = NULL; |
|
103 |
|
104 TRAP(err,CSignatureFactory::CreateSignerL(asymmetricSignerImpl, |
|
105 algorithmUid, |
|
106 keyPair->PublicKey(), |
|
107 paddingMode, |
|
108 NULL)); |
|
109 |
|
110 if(asymmetricSignerImpl && (err == KErrNone)) |
|
111 { |
|
112 |
|
113 CleanupStack::PushL(asymmetricSignerImpl); |
|
114 |
|
115 INFO_PRINTF1(_L("** Successfully Loaded Asymmetric Signer Object **")); |
|
116 |
|
117 //Define a pointer of type TCharacteristics in order to store the asymmetric signer |
|
118 //object's characterisctics |
|
119 const TCharacteristics* chars(NULL); |
|
120 |
|
121 //Retrieve the characteristics for the asymmetric signer implementation object |
|
122 TRAP_LOG(err, asymmetricSignerImpl->GetCharacteristicsL(chars)); |
|
123 |
|
124 //Static cast the characteristics to type TAsymmetricSignatureCharacteristics |
|
125 const TAsymmetricSignatureCharacteristics* asymsignChars = static_cast<const TAsymmetricSignatureCharacteristics*>(chars); |
|
126 |
|
127 //Retrieve all the Common characteristics that are required for the test |
|
128 TVariantPtrC exInterfaceUid; |
|
129 TVariantPtrC exAlgorithmUid; |
|
130 TVariantPtrC exImplementationUid; |
|
131 TVariantPtrC exCreatorName; |
|
132 TBool exFIPSApproved; |
|
133 TBool exHardwareSupported; |
|
134 TInt exMaxConcurrencySupported; |
|
135 TVariantPtrC exAlgorithmName; |
|
136 TInt exLatency; |
|
137 TInt exThroughput; |
|
138 |
|
139 //Retrieve all the Asymmetric Signer characteristics that are required for the test |
|
140 TInt exAsymSignMaxKeyLength; |
|
141 TInt exAsymSignKeySupportMode; |
|
142 TVariantPtrC exAsymSignPaddingModes; |
|
143 TInt exAsymSignPaddingModeNum; |
|
144 |
|
145 if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) || |
|
146 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) || |
|
147 !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) || |
|
148 !GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) || |
|
149 !GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) || |
|
150 !GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) || |
|
151 !GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) || |
|
152 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) || |
|
153 !GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) || |
|
154 !GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) || |
|
155 !GetIntFromConfig(ConfigSection(),KConfigExMaxKeyLength,exAsymSignMaxKeyLength) || |
|
156 !GetStringFromConfig(ConfigSection(),KConfigExPaddingModes,exAsymSignPaddingModes) || |
|
157 !GetIntFromConfig(ConfigSection(),KConfigExPaddingModeNum,exAsymSignPaddingModeNum) || |
|
158 !GetIntFromConfig(ConfigSection(),KConfigExKeySupportMode,exAsymSignKeySupportMode)) |
|
159 { |
|
160 ERR_PRINTF1(_L("** .INI Error: Expected Asymmetric Signer/Common Characteristics Not Located **")); |
|
161 SetTestStepResult(EFail); |
|
162 } |
|
163 else |
|
164 { |
|
165 |
|
166 INFO_PRINTF1(_L("** Checking Asymmetric Signer/Common Characteristics.... **")); |
|
167 |
|
168 CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC(); |
|
169 |
|
170 //Retrieve the Common Characteristics from TAsymmetricSignatureCharacteristics |
|
171 const TCommonCharacteristics* asymsignCommonChars = &asymsignChars->cmn; |
|
172 |
|
173 TPtrC errorMessage; |
|
174 |
|
175 //Perform Asymmetric Signer/Common Characteristic Checks |
|
176 if(pluginCheck->checkCommonCharacteristics(asymsignCommonChars, |
|
177 exInterfaceUid, |
|
178 exAlgorithmUid, |
|
179 exImplementationUid, |
|
180 exCreatorName, |
|
181 exFIPSApproved, |
|
182 exHardwareSupported, |
|
183 exMaxConcurrencySupported, |
|
184 exAlgorithmName, |
|
185 exLatency, |
|
186 exThroughput, |
|
187 errorMessage) && |
|
188 pluginCheck->checkAsymSignatureCharacteristics(asymsignChars, |
|
189 exAsymSignMaxKeyLength, |
|
190 exAsymSignPaddingModes, |
|
191 exAsymSignPaddingModeNum, |
|
192 exAsymSignKeySupportMode, |
|
193 errorMessage)) |
|
194 { |
|
195 INFO_PRINTF1(_L("Asymmetric Signer/Common characteristics successfully match expected values...")); |
|
196 |
|
197 if(asymsignChars->IsPaddingModeSupported(paddingMode) && !asymsignChars->IsPaddingModeSupported(invalidPaddingMode)) |
|
198 { |
|
199 INFO_PRINTF1(_L("Successful Padding Mode Supported Tests....")); |
|
200 |
|
201 INFO_PRINTF1(_L("** PASS: Asymmetric Signer/Common Characteristics Tests Successful **")); |
|
202 |
|
203 SetTestStepResult(EPass); |
|
204 } |
|
205 else |
|
206 { |
|
207 ERR_PRINTF1(_L("** FAIL: Unexpected 'Padding' Mode Supported Results")); |
|
208 } |
|
209 } |
|
210 else |
|
211 { |
|
212 ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage); |
|
213 } |
|
214 |
|
215 CleanupStack::PopAndDestroy(pluginCheck); |
|
216 } |
|
217 |
|
218 CleanupStack::PopAndDestroy(asymmetricSignerImpl); |
|
219 } |
|
220 else |
|
221 { |
|
222 ERR_PRINTF2(_L("*** FAIL: Failed to Create Asymmetric Signer Object - %d ***"), err); |
|
223 } |
|
224 |
|
225 CleanupStack::PopAndDestroy(3,keyParams); |
|
226 } |
|
227 |
|
228 } |
|
229 |
|
230 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); |
|
231 return TestStepResult(); |
|
232 |
|
233 } |
|
234 |
|
235 TVerdict CPluginCharsAsymSignStep::doTestStepPostambleL() |
|
236 { |
|
237 return TestStepResult(); |
|
238 } |