|
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 "plugincharscommonstep.h" |
|
25 #include "plugincharschecker.h" |
|
26 |
|
27 #include "cryptosymmetriccipherapi.h" |
|
28 #include "keys.h" |
|
29 |
|
30 using namespace CryptoSpi; |
|
31 |
|
32 CPluginCharsCommonStep::~CPluginCharsCommonStep() |
|
33 { |
|
34 } |
|
35 |
|
36 CPluginCharsCommonStep::CPluginCharsCommonStep() |
|
37 { |
|
38 SetTestStepName(KPluginCharsCommonStep); |
|
39 } |
|
40 |
|
41 TVerdict CPluginCharsCommonStep::doTestStepPreambleL() |
|
42 { |
|
43 SetTestStepResult(EPass); |
|
44 return TestStepResult(); |
|
45 } |
|
46 |
|
47 TVerdict CPluginCharsCommonStep::doTestStepL() |
|
48 { |
|
49 |
|
50 INFO_PRINTF1(_L("Plugin Characteristics - Common 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 |
|
66 //Each of the individual parameters required to create the Symmetric Cipher object |
|
67 //are read in from the specified INI configuration file |
|
68 if(!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) || |
|
69 !GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) || |
|
70 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) || |
|
71 !GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) || |
|
72 !GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) || |
|
73 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode)) |
|
74 { |
|
75 ERR_PRINTF1(_L("** .INI Error: Symmetric Cipher Arguments Not Located **")); |
|
76 SetTestStepResult(EFail); |
|
77 } |
|
78 else |
|
79 { |
|
80 //Convert encryption key to an 8 Bit Descriptor |
|
81 HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length()); |
|
82 TPtr8 keyStrPtr = keyStr->Des(); |
|
83 |
|
84 keyStrPtr.Copy(encryptKey); |
|
85 |
|
86 //Create an new CryptoParams object to encapsulate the key type and secret key string |
|
87 CCryptoParams* keyParams = CCryptoParams::NewL(); |
|
88 CleanupStack::PushL(keyParams); |
|
89 keyParams->AddL(*keyStr,keyType); |
|
90 |
|
91 //Create Key Object |
|
92 TKeyProperty keyProperty; |
|
93 CKey* key=CKey::NewL(keyProperty,*keyParams); |
|
94 CleanupStack::PushL(key); |
|
95 |
|
96 CSymmetricCipher* symmetricCipherImpl = NULL; |
|
97 |
|
98 TRAPD_LOG(err,CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipherImpl, |
|
99 algorithmUid, |
|
100 *key, |
|
101 cryptoMode, |
|
102 operationMode, |
|
103 paddingMode, |
|
104 NULL)); |
|
105 |
|
106 |
|
107 |
|
108 if(symmetricCipherImpl && (err == KErrNone)) |
|
109 { |
|
110 |
|
111 CleanupStack::PushL(symmetricCipherImpl); |
|
112 |
|
113 INFO_PRINTF1(_L("** Successfully Loaded Symmetric Cipher Object **")); |
|
114 |
|
115 //Define a pointer of type TCharacteristics in order to store the symmetric cipher |
|
116 //encryption object's characterisctics |
|
117 const TCharacteristics* chars(NULL); |
|
118 |
|
119 //Retrieve the characteristics for the symmetric cipher implementation object |
|
120 TRAP_LOG(err, symmetricCipherImpl->GetCharacteristicsL(chars)); |
|
121 |
|
122 //Static cast the characteristics to type TCommonCharacteristics |
|
123 const TCommonCharacteristics* commonChars = static_cast<const TCommonCharacteristics*>(chars); |
|
124 |
|
125 //Retrieve all the Common characteristics that are required for all test cases |
|
126 TVariantPtrC exInterfaceUid; |
|
127 TVariantPtrC exAlgorithmUid; |
|
128 TVariantPtrC exImplementationUid; |
|
129 TVariantPtrC exCreatorName; |
|
130 TBool exFIPSApproved; |
|
131 TBool exHardwareSupported; |
|
132 TInt exMaxConcurrencySupported; |
|
133 TVariantPtrC exAlgorithmName; |
|
134 TInt exLatency; |
|
135 TInt exThroughput; |
|
136 |
|
137 if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) || |
|
138 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) || |
|
139 !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) || |
|
140 !GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) || |
|
141 !GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) || |
|
142 !GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) || |
|
143 !GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) || |
|
144 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) || |
|
145 !GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) || |
|
146 !GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput)) |
|
147 { |
|
148 ERR_PRINTF1(_L("** .INI Error: Expected Common Characteristic Arguments Not Located **")); |
|
149 SetTestStepResult(EFail); |
|
150 } |
|
151 else |
|
152 { |
|
153 |
|
154 INFO_PRINTF1(_L("** Checking common Characteristics.... **")); |
|
155 |
|
156 CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC(); |
|
157 |
|
158 TPtrC errorMessage; |
|
159 |
|
160 //****************************************************************** |
|
161 //Perform Characteristic Checks |
|
162 //****************************************************************** |
|
163 if(pluginCheck->checkCommonCharacteristics(commonChars, |
|
164 exInterfaceUid, |
|
165 exAlgorithmUid, |
|
166 exImplementationUid, |
|
167 exCreatorName, |
|
168 exFIPSApproved, |
|
169 exHardwareSupported, |
|
170 exMaxConcurrencySupported, |
|
171 exAlgorithmName, |
|
172 exLatency, |
|
173 exThroughput, |
|
174 errorMessage)) |
|
175 { |
|
176 INFO_PRINTF1(_L("** PASS : Common characteristics successfully match expected values **")); |
|
177 SetTestStepResult(EPass); |
|
178 } |
|
179 else |
|
180 { |
|
181 ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage); |
|
182 } |
|
183 |
|
184 CleanupStack::PopAndDestroy(pluginCheck); |
|
185 } |
|
186 |
|
187 CleanupStack::PopAndDestroy(symmetricCipherImpl); |
|
188 } |
|
189 else |
|
190 { |
|
191 ERR_PRINTF2(_L("*** FAIL: Failed to Create Symmetric Cipher Object - %d ***"), err); |
|
192 } |
|
193 |
|
194 CleanupStack::PopAndDestroy(3,keyStr); |
|
195 } |
|
196 } |
|
197 |
|
198 |
|
199 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); |
|
200 return TestStepResult(); |
|
201 } |
|
202 |
|
203 TVerdict CPluginCharsCommonStep::doTestStepPostambleL() |
|
204 { |
|
205 return TestStepResult(); |
|
206 } |