|
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 "plugincharssymmetriccipherstep.h" |
|
25 #include "plugincharschecker.h" |
|
26 |
|
27 #include "cryptosymmetriccipherapi.h" |
|
28 #include "keys.h" |
|
29 |
|
30 using namespace CryptoSpi; |
|
31 |
|
32 CPluginCharsSymmetricCipherStep::~CPluginCharsSymmetricCipherStep() |
|
33 { |
|
34 } |
|
35 |
|
36 CPluginCharsSymmetricCipherStep::CPluginCharsSymmetricCipherStep() |
|
37 { |
|
38 SetTestStepName(KPluginCharsSymmetricCipherStep); |
|
39 } |
|
40 |
|
41 TVerdict CPluginCharsSymmetricCipherStep::doTestStepPreambleL() |
|
42 { |
|
43 SetTestStepResult(EPass); |
|
44 return TestStepResult(); |
|
45 } |
|
46 |
|
47 TVerdict CPluginCharsSymmetricCipherStep::doTestStepL() |
|
48 { |
|
49 |
|
50 INFO_PRINTF1(_L("Plugin Characteristics - Symmetric Cipher Chracteristics")); |
|
51 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); |
|
52 |
|
53 if (TestStepResult()==EPass) |
|
54 { |
|
55 |
|
56 //Assume faliure, unless all is successful |
|
57 SetTestStepResult(EFail); |
|
58 |
|
59 TPtrC encryptKey; |
|
60 TVariantPtrC keyType; |
|
61 TVariantPtrC algorithmUid; |
|
62 TVariantPtrC cryptoMode; |
|
63 TVariantPtrC operationMode; |
|
64 TVariantPtrC paddingMode; |
|
65 TVariantPtrC invalidOperationMode; |
|
66 TVariantPtrC invalidPaddingMode; |
|
67 |
|
68 //Each of the individual parameters required to create the Symmetric Cipher object |
|
69 //are read in from the specified INI configuration file |
|
70 if(!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) || |
|
71 !GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) || |
|
72 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) || |
|
73 !GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) || |
|
74 !GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) || |
|
75 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) || |
|
76 !GetStringFromConfig(ConfigSection(),KConfigInvalidOperationMode,invalidOperationMode) || |
|
77 !GetStringFromConfig(ConfigSection(),KConfigInvalidPaddingMode,invalidPaddingMode)) |
|
78 { |
|
79 ERR_PRINTF1(_L("** .INI Error: Symmetric Cipher Arguments Not Located **")); |
|
80 SetTestStepResult(EFail); |
|
81 } |
|
82 else |
|
83 { |
|
84 //Convert encryption key to an 8 Bit Descriptor |
|
85 HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length()); |
|
86 TPtr8 keyStrPtr = keyStr->Des(); |
|
87 |
|
88 keyStrPtr.Copy(encryptKey); |
|
89 |
|
90 //Create an new CryptoParams object to encapsulate the key type and secret key string |
|
91 CCryptoParams* keyParams = CCryptoParams::NewL(); |
|
92 CleanupStack::PushL(keyParams); |
|
93 keyParams->AddL(*keyStr,keyType); |
|
94 |
|
95 //Create Key Object |
|
96 TKeyProperty keyProperty; |
|
97 CKey* key=CKey::NewL(keyProperty,*keyParams); |
|
98 CleanupStack::PushL(key); |
|
99 |
|
100 CSymmetricCipher* symmetricCipherImpl = NULL; |
|
101 |
|
102 TRAPD_LOG(err,CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipherImpl, |
|
103 algorithmUid, |
|
104 *key, |
|
105 cryptoMode, |
|
106 operationMode, |
|
107 paddingMode, |
|
108 NULL)); |
|
109 |
|
110 |
|
111 |
|
112 if(symmetricCipherImpl && (err == KErrNone)) |
|
113 { |
|
114 |
|
115 CleanupStack::PushL(symmetricCipherImpl); |
|
116 |
|
117 INFO_PRINTF1(_L("** Successfully Loaded Symmetric Cipher Object **")); |
|
118 |
|
119 //Define a pointer of type TCharacteristics in order to store the symmetric cipher |
|
120 //encryption object's characterisctics |
|
121 const TCharacteristics* chars(NULL); |
|
122 |
|
123 //Retrieve the characteristics for the symmetric cipher implementation object |
|
124 TRAP_LOG(err, symmetricCipherImpl->GetCharacteristicsL(chars)); |
|
125 |
|
126 //Static cast the characteristics to type TSymmetricCipherCharacteristics |
|
127 const TSymmetricCipherCharacteristics* symmetricChars = static_cast<const TSymmetricCipherCharacteristics*>(chars); |
|
128 |
|
129 //Retrieve all the Common characteristics that are required for all test cases |
|
130 TVariantPtrC exInterfaceUid; |
|
131 TVariantPtrC exAlgorithmUid; |
|
132 TVariantPtrC exImplementationUid; |
|
133 TVariantPtrC exCreatorName; |
|
134 TBool exFIPSApproved; |
|
135 TBool exHardwareSupported; |
|
136 TInt exMaxConcurrencySupported; |
|
137 TVariantPtrC exAlgorithmName; |
|
138 TInt exLatency; |
|
139 TInt exThroughput; |
|
140 |
|
141 //Retrieve all the Symmetric Cipher characteristics that are required for all test cases |
|
142 TInt exSymmetricMaxKeyLength; |
|
143 TInt exSymmetricBlockSize; |
|
144 TVariantPtrC exSymmetricPaddingModes; |
|
145 TInt exSymmetricPaddingModeNum; |
|
146 TVariantPtrC exSymmetricOperationModes; |
|
147 TInt exSymmetricOperationModeNum; |
|
148 TInt exSymmetricKeySupportMode; |
|
149 |
|
150 if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) || |
|
151 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) || |
|
152 !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) || |
|
153 !GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) || |
|
154 !GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) || |
|
155 !GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) || |
|
156 !GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) || |
|
157 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) || |
|
158 !GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) || |
|
159 !GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) || |
|
160 !GetIntFromConfig(ConfigSection(),KConfigExMaxKeyLength,exSymmetricMaxKeyLength) || |
|
161 !GetIntFromConfig(ConfigSection(),KConfigExBlockSize,exSymmetricBlockSize) || |
|
162 !GetStringFromConfig(ConfigSection(),KConfigExPaddingModes,exSymmetricPaddingModes) || |
|
163 !GetIntFromConfig(ConfigSection(),KConfigExPaddingModeNum,exSymmetricPaddingModeNum) || |
|
164 !GetStringFromConfig(ConfigSection(),KConfigExOperationModes,exSymmetricOperationModes) || |
|
165 !GetIntFromConfig(ConfigSection(),KConfigExOperationModeNum,exSymmetricOperationModeNum) || |
|
166 !GetIntFromConfig(ConfigSection(),KConfigExKeySupportMode,exSymmetricKeySupportMode)) |
|
167 { |
|
168 ERR_PRINTF1(_L("** .INI Error: Expected Symmetric Cipher/Common Characteristics Not Located **")); |
|
169 SetTestStepResult(EFail); |
|
170 } |
|
171 else |
|
172 { |
|
173 |
|
174 INFO_PRINTF1(_L("** Checking Symmetric Cipher/Common Characteristics.... **")); |
|
175 |
|
176 CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC(); |
|
177 |
|
178 //Retrieve the Common Characteristics from TSymmetricCipherCharacteristics |
|
179 const TCommonCharacteristics* symCommonChars = &symmetricChars->cmn; |
|
180 |
|
181 TPtrC errorMessage; |
|
182 |
|
183 //Perform Symmetric Cipher/Common Characteristic Checks |
|
184 if(pluginCheck->checkCommonCharacteristics(symCommonChars, |
|
185 exInterfaceUid, |
|
186 exAlgorithmUid, |
|
187 exImplementationUid, |
|
188 exCreatorName, |
|
189 exFIPSApproved, |
|
190 exHardwareSupported, |
|
191 exMaxConcurrencySupported, |
|
192 exAlgorithmName, |
|
193 exLatency, |
|
194 exThroughput, |
|
195 errorMessage) && |
|
196 pluginCheck->checkSymmetricCharacteristics(symmetricChars, |
|
197 exSymmetricMaxKeyLength, |
|
198 exSymmetricBlockSize, |
|
199 exSymmetricPaddingModes, |
|
200 exSymmetricPaddingModeNum, |
|
201 exSymmetricOperationModes, |
|
202 exSymmetricOperationModeNum, |
|
203 exSymmetricKeySupportMode, |
|
204 errorMessage)) |
|
205 { |
|
206 INFO_PRINTF1(_L("Symmetric Cipher/Common characteristics successfully match expected values....")); |
|
207 |
|
208 if(symmetricChars->IsOperationModeSupported(operationMode) && !symmetricChars->IsOperationModeSupported(invalidOperationMode)) |
|
209 { |
|
210 |
|
211 INFO_PRINTF1(_L("Successful Operation Mode Supported Tests....")); |
|
212 |
|
213 if(symmetricChars->IsPaddingModeSupported(paddingMode) && !symmetricChars->IsPaddingModeSupported(invalidPaddingMode)) |
|
214 { |
|
215 INFO_PRINTF1(_L("Successful Padding Mode Supported Tests....")); |
|
216 |
|
217 INFO_PRINTF1(_L("** PASS: Symmetric Cipher/Common Characteristics Tests Successful **")); |
|
218 |
|
219 SetTestStepResult(EPass); |
|
220 } |
|
221 else |
|
222 { |
|
223 ERR_PRINTF1(_L("** FAIL: Unexpected 'Operation' Mode Supported Results")); |
|
224 } |
|
225 } |
|
226 else |
|
227 { |
|
228 ERR_PRINTF1(_L("** FAIL: Unexpected 'Padding' Mode Supported Results")); |
|
229 } |
|
230 |
|
231 } |
|
232 else |
|
233 { |
|
234 ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage); |
|
235 } |
|
236 |
|
237 CleanupStack::PopAndDestroy(pluginCheck); |
|
238 } |
|
239 |
|
240 CleanupStack::PopAndDestroy(symmetricCipherImpl); |
|
241 } |
|
242 else |
|
243 { |
|
244 ERR_PRINTF2(_L("*** FAIL: Failed to Create Symmetric Cipher Object - %d ***"), err); |
|
245 } |
|
246 |
|
247 CleanupStack::PopAndDestroy(3,keyStr); |
|
248 } |
|
249 } |
|
250 |
|
251 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); |
|
252 return TestStepResult(); |
|
253 } |
|
254 |
|
255 TVerdict CPluginCharsSymmetricCipherStep::doTestStepPostambleL() |
|
256 { |
|
257 return TestStepResult(); |
|
258 } |