sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
/**
|
sl@0
|
20 |
@file
|
sl@0
|
21 |
@internalTechnology
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
#include "ruleselectcommonstep.h"
|
sl@0
|
24 |
#include "plugincharschecker.h"
|
sl@0
|
25 |
#include <cryptospi/cryptosymmetriccipherapi.h>
|
sl@0
|
26 |
#include <cryptospi/cryptoasymmetriccipherapi.h>
|
sl@0
|
27 |
#include <cryptospi/cryptohashapi.h>
|
sl@0
|
28 |
#include <cryptospi/cryptorandomapi.h>
|
sl@0
|
29 |
#include <cryptospi/cryptosignatureapi.h>
|
sl@0
|
30 |
#include <cryptospi/cryptokeyagreementapi.h>
|
sl@0
|
31 |
#include <cryptospi/cryptokeypairgeneratorapi.h>
|
sl@0
|
32 |
#include <cryptospi/keypair.h>
|
sl@0
|
33 |
#include <cryptospi/keys.h>
|
sl@0
|
34 |
|
sl@0
|
35 |
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
|
sl@0
|
36 |
#include <cryptospi/cryptomacapi.h>
|
sl@0
|
37 |
#endif
|
sl@0
|
38 |
|
sl@0
|
39 |
#include <cryptospi/cryptospistateapi.h>
|
sl@0
|
40 |
#include <cryptospi/ruleselector.h>
|
sl@0
|
41 |
|
sl@0
|
42 |
using namespace CryptoSpi;
|
sl@0
|
43 |
|
sl@0
|
44 |
CRuleSelectCommonStep::~CRuleSelectCommonStep()
|
sl@0
|
45 |
{
|
sl@0
|
46 |
}
|
sl@0
|
47 |
|
sl@0
|
48 |
CRuleSelectCommonStep::CRuleSelectCommonStep()
|
sl@0
|
49 |
{
|
sl@0
|
50 |
SetTestStepName(KRuleSelectCommonStep);
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
TVerdict CRuleSelectCommonStep::doTestStepPreambleL()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
SetTestStepResult(EPass);
|
sl@0
|
56 |
return TestStepResult();
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
TVerdict CRuleSelectCommonStep::doTestStepL()
|
sl@0
|
60 |
{
|
sl@0
|
61 |
|
sl@0
|
62 |
INFO_PRINTF1(_L("Rule Selection - Common Characteristics Selection"));
|
sl@0
|
63 |
INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
|
sl@0
|
64 |
|
sl@0
|
65 |
if (TestStepResult()==EPass)
|
sl@0
|
66 |
{
|
sl@0
|
67 |
|
sl@0
|
68 |
TInt err = 0;
|
sl@0
|
69 |
|
sl@0
|
70 |
//Create Default Selection Rules Object
|
sl@0
|
71 |
CSelectionRules* rules = CSelectionRules::NewL();
|
sl@0
|
72 |
CleanupStack::PushL(rules);
|
sl@0
|
73 |
|
sl@0
|
74 |
//*************SELECTION RULE CREATION AND ADDITION**************
|
sl@0
|
75 |
|
sl@0
|
76 |
//Boolean to determine whether there are more rules to apply
|
sl@0
|
77 |
TBool moreRules;
|
sl@0
|
78 |
moreRules = ETrue;
|
sl@0
|
79 |
|
sl@0
|
80 |
//Itterator representing the current rule. Appended to the end of each selection
|
sl@0
|
81 |
//rule INI parameter
|
sl@0
|
82 |
TInt currentRule;
|
sl@0
|
83 |
currentRule = 1;
|
sl@0
|
84 |
|
sl@0
|
85 |
//Total number of selection rules added to the CSelectionRules object
|
sl@0
|
86 |
TInt totalRules;
|
sl@0
|
87 |
totalRules = 0;
|
sl@0
|
88 |
|
sl@0
|
89 |
TVariantPtrC interfaceScope;
|
sl@0
|
90 |
TVariantPtrC algorithmScope;
|
sl@0
|
91 |
TVariantPtrC charUid;
|
sl@0
|
92 |
TVariantPtrC compareOperator;
|
sl@0
|
93 |
TVariantPtrC charValue;
|
sl@0
|
94 |
TVariantPtrC charValueType;
|
sl@0
|
95 |
TBool isOptional;
|
sl@0
|
96 |
|
sl@0
|
97 |
|
sl@0
|
98 |
//Whilst there are selection rules present in the INI file that have yet to be
|
sl@0
|
99 |
//added to the CSelectionRules object
|
sl@0
|
100 |
while(moreRules)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
|
sl@0
|
103 |
|
sl@0
|
104 |
//Constructs each of the parameter names required to extract the necessary
|
sl@0
|
105 |
//selection rule data from the specified INI configuration file
|
sl@0
|
106 |
TBuf<KMaxConfigParamStringSize> interfaceScopeStr(KConfigInterfaceScopeBase);
|
sl@0
|
107 |
interfaceScopeStr.AppendNum(currentRule);
|
sl@0
|
108 |
INFO_PRINTF2(_L("interfaceScopeStr = %S"), &interfaceScopeStr);
|
sl@0
|
109 |
|
sl@0
|
110 |
TBuf<KMaxConfigParamStringSize> algorithmScopeStr(KConfigAlgorithmScopeBase);
|
sl@0
|
111 |
algorithmScopeStr.AppendNum(currentRule);
|
sl@0
|
112 |
INFO_PRINTF2(_L("algorithmScopeStr = %S"), &algorithmScopeStr);
|
sl@0
|
113 |
|
sl@0
|
114 |
TBuf<KMaxConfigParamStringSize> charUidStr(KConfigCharUidBase);
|
sl@0
|
115 |
charUidStr.AppendNum(currentRule);
|
sl@0
|
116 |
INFO_PRINTF2(_L("charUidStr = %S"), &charUidStr);
|
sl@0
|
117 |
|
sl@0
|
118 |
TBuf<KMaxConfigParamStringSize> compareOperatorStr(KConfigCompareOperatorBase);
|
sl@0
|
119 |
compareOperatorStr.AppendNum(currentRule);
|
sl@0
|
120 |
INFO_PRINTF2(_L("compareOperatorStr = %S"), &compareOperatorStr);
|
sl@0
|
121 |
|
sl@0
|
122 |
TBuf<KMaxConfigParamStringSize> charValueStr(KConfigCharValueBase);
|
sl@0
|
123 |
charValueStr.AppendNum(currentRule);
|
sl@0
|
124 |
INFO_PRINTF2(_L("charValueStr = %S"), &charValueStr);
|
sl@0
|
125 |
|
sl@0
|
126 |
TBuf<KMaxConfigParamStringSize> charValueTypeStr(KConfigCharValueTypeBase);
|
sl@0
|
127 |
charValueTypeStr.AppendNum(currentRule);
|
sl@0
|
128 |
INFO_PRINTF2(_L("charValueTypeStr = %S"), &charValueTypeStr);
|
sl@0
|
129 |
|
sl@0
|
130 |
TBuf<KMaxConfigParamStringSize> isOptionalStr(KConfigIsOptionalBase);
|
sl@0
|
131 |
isOptionalStr.AppendNum(currentRule);
|
sl@0
|
132 |
INFO_PRINTF2(_L("isOptionalStr = %S"), &isOptionalStr);
|
sl@0
|
133 |
|
sl@0
|
134 |
|
sl@0
|
135 |
//Extracts the parameter data for a single rule from the specified INI file
|
sl@0
|
136 |
if(!GetStringFromConfig(ConfigSection(),interfaceScopeStr,interfaceScope) ||
|
sl@0
|
137 |
!GetStringFromConfig(ConfigSection(),algorithmScopeStr,algorithmScope) ||
|
sl@0
|
138 |
!GetStringFromConfig(ConfigSection(),charUidStr,charUid) ||
|
sl@0
|
139 |
!GetStringFromConfig(ConfigSection(),compareOperatorStr,compareOperator) ||
|
sl@0
|
140 |
!GetStringFromConfig(ConfigSection(),charValueTypeStr,charValueType) ||
|
sl@0
|
141 |
!GetBoolFromConfig(ConfigSection(),isOptionalStr,isOptional))
|
sl@0
|
142 |
{
|
sl@0
|
143 |
moreRules = EFalse;
|
sl@0
|
144 |
}
|
sl@0
|
145 |
else
|
sl@0
|
146 |
{
|
sl@0
|
147 |
|
sl@0
|
148 |
//Creates a pointer to store the address of the newly created selection rule
|
sl@0
|
149 |
CSelectionRuleContent* rule = NULL;
|
sl@0
|
150 |
|
sl@0
|
151 |
//Creates a pointer to store the contents of the rule value parameter, so that
|
sl@0
|
152 |
//it can be passed in at construction of the selection rule.
|
sl@0
|
153 |
CCryptoParam* ruleValueParam = NULL;
|
sl@0
|
154 |
|
sl@0
|
155 |
//Depending on the 'RuleValueType' parameter read in from the INI file, the 'RuleValue'
|
sl@0
|
156 |
//parameter will either be read in as an Integer,String or a Boolean.
|
sl@0
|
157 |
switch(charValueType)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
case ERuleValueInteger:
|
sl@0
|
160 |
{
|
sl@0
|
161 |
TInt charValue;
|
sl@0
|
162 |
|
sl@0
|
163 |
if(!GetIntFromConfig(ConfigSection(),charValueStr,charValue))
|
sl@0
|
164 |
{
|
sl@0
|
165 |
//Should the integer value be represented by a constant..
|
sl@0
|
166 |
TVariantPtrC strCharValue;
|
sl@0
|
167 |
|
sl@0
|
168 |
if(!GetStringFromConfig(ConfigSection(),charValueStr,strCharValue))
|
sl@0
|
169 |
{
|
sl@0
|
170 |
ERR_PRINTF1(_L("** .INI Error: INTEGER Rule Value Not Initialised Correctly **"));
|
sl@0
|
171 |
SetTestStepResult(EFail);
|
sl@0
|
172 |
}
|
sl@0
|
173 |
else
|
sl@0
|
174 |
{
|
sl@0
|
175 |
ruleValueParam = CCryptoIntParam::NewL(TInt(strCharValue),TUid(charUid));
|
sl@0
|
176 |
}
|
sl@0
|
177 |
}
|
sl@0
|
178 |
else
|
sl@0
|
179 |
{
|
sl@0
|
180 |
//The Integer Rule Value is encapsulated as a CCryptoIntParam object so that it can be passed in as
|
sl@0
|
181 |
//a parameter when constructing the selection rule
|
sl@0
|
182 |
ruleValueParam = CCryptoIntParam::NewL(charValue,charUid);
|
sl@0
|
183 |
}
|
sl@0
|
184 |
|
sl@0
|
185 |
break;
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
case ERuleValueDes8:
|
sl@0
|
189 |
{
|
sl@0
|
190 |
TPtrC charValue;
|
sl@0
|
191 |
|
sl@0
|
192 |
if(!GetStringFromConfig(ConfigSection(),charValueStr,charValue))
|
sl@0
|
193 |
{
|
sl@0
|
194 |
ERR_PRINTF1(_L("** .INI Error: STRING Rule Value Not Initialised Correctly **"));
|
sl@0
|
195 |
SetTestStepResult(EFail);
|
sl@0
|
196 |
}
|
sl@0
|
197 |
else
|
sl@0
|
198 |
{
|
sl@0
|
199 |
//Convert encryption key to an 8 Bit Descriptor
|
sl@0
|
200 |
HBufC8* charStr = HBufC8::NewLC(charValue.Length());
|
sl@0
|
201 |
TPtr8 charStrPtr = charStr->Des();
|
sl@0
|
202 |
|
sl@0
|
203 |
charStrPtr.Copy(charValue);
|
sl@0
|
204 |
|
sl@0
|
205 |
//The String Rule Value is encapsulated as a CCryptoDesC8Param object so that it can be passed in as
|
sl@0
|
206 |
//a parameter when constructing the selection rule
|
sl@0
|
207 |
ruleValueParam = CCryptoDesC8Param::NewL(charStrPtr,charUid);
|
sl@0
|
208 |
|
sl@0
|
209 |
CleanupStack::PopAndDestroy(charStr);
|
sl@0
|
210 |
}
|
sl@0
|
211 |
|
sl@0
|
212 |
break;
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
case ERuleValueDes16:
|
sl@0
|
216 |
{
|
sl@0
|
217 |
TPtrC charValue;
|
sl@0
|
218 |
|
sl@0
|
219 |
if(!GetStringFromConfig(ConfigSection(),charValueStr,charValue))
|
sl@0
|
220 |
{
|
sl@0
|
221 |
ERR_PRINTF1(_L("** .INI Error: STRING Rule Value Not Initialised Correctly **"));
|
sl@0
|
222 |
SetTestStepResult(EFail);
|
sl@0
|
223 |
}
|
sl@0
|
224 |
else
|
sl@0
|
225 |
{
|
sl@0
|
226 |
//The String Rule Value is encapsulated as a CCryptoDesC8Param object so that it can be passed in as
|
sl@0
|
227 |
//a parameter when constructing the selection rule
|
sl@0
|
228 |
ruleValueParam = CCryptoDesC16Param::NewL(charValue,charUid);
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
break;
|
sl@0
|
232 |
}
|
sl@0
|
233 |
|
sl@0
|
234 |
case ERuleValueBoolean:
|
sl@0
|
235 |
{
|
sl@0
|
236 |
TBool charValue;
|
sl@0
|
237 |
|
sl@0
|
238 |
if(!GetBoolFromConfig(ConfigSection(),charValueStr,charValue))
|
sl@0
|
239 |
{
|
sl@0
|
240 |
ERR_PRINTF1(_L("** .INI Error: BOOLEAN Rule Value Not Initialised Correctly **"));
|
sl@0
|
241 |
SetTestStepResult(EFail);
|
sl@0
|
242 |
}
|
sl@0
|
243 |
else
|
sl@0
|
244 |
{
|
sl@0
|
245 |
//The Boolean Rule Value is encapsulated as a CCryptoInt8Param object so that it can be passed in as
|
sl@0
|
246 |
//a parameter when constructing the selection rule
|
sl@0
|
247 |
ruleValueParam = CCryptoIntParam::NewL(charValue,charUid);
|
sl@0
|
248 |
}
|
sl@0
|
249 |
|
sl@0
|
250 |
break;
|
sl@0
|
251 |
}
|
sl@0
|
252 |
|
sl@0
|
253 |
default:
|
sl@0
|
254 |
{
|
sl@0
|
255 |
ERR_PRINTF1(_L("** .INI Error: Rule Value Type Unknown **"));
|
sl@0
|
256 |
SetTestStepResult(EFail);
|
sl@0
|
257 |
break;
|
sl@0
|
258 |
}
|
sl@0
|
259 |
}
|
sl@0
|
260 |
|
sl@0
|
261 |
|
sl@0
|
262 |
if(TestStepResult() == EPass)
|
sl@0
|
263 |
{
|
sl@0
|
264 |
|
sl@0
|
265 |
//Creates the CSelectionRuleContent object, passing in all the parameters read in
|
sl@0
|
266 |
//from the specified INI configuration file
|
sl@0
|
267 |
|
sl@0
|
268 |
TRAP_LOG(err, rule = CSelectionRuleContent::NewL(interfaceScope,
|
sl@0
|
269 |
algorithmScope,
|
sl@0
|
270 |
ruleValueParam,
|
sl@0
|
271 |
TRuleOperator((TInt)compareOperator),
|
sl@0
|
272 |
isOptional));
|
sl@0
|
273 |
if(err == KErrNone)
|
sl@0
|
274 |
{
|
sl@0
|
275 |
//Add the newly created selection rule to the CSelectionRules collection by
|
sl@0
|
276 |
//calling the 'AddSelectionRule' method and passing in the address of the rule
|
sl@0
|
277 |
TRAP_LOG(err,rules->AddSelectionRuleL(rule));
|
sl@0
|
278 |
|
sl@0
|
279 |
if(err == KErrNone)
|
sl@0
|
280 |
{
|
sl@0
|
281 |
INFO_PRINTF2(_L("Rule %d Created, Added and Destoryed"), currentRule);
|
sl@0
|
282 |
|
sl@0
|
283 |
currentRule++;
|
sl@0
|
284 |
totalRules++;
|
sl@0
|
285 |
}
|
sl@0
|
286 |
else
|
sl@0
|
287 |
{
|
sl@0
|
288 |
ERR_PRINTF2(_L("RULE FAILURE: Failed to Add Selection Rule %d "), currentRule);
|
sl@0
|
289 |
moreRules = EFalse;
|
sl@0
|
290 |
SetTestStepResult(EFail);
|
sl@0
|
291 |
}
|
sl@0
|
292 |
}
|
sl@0
|
293 |
else
|
sl@0
|
294 |
{
|
sl@0
|
295 |
ERR_PRINTF2(_L("RULE FAILURE: Failed to Create Selection Rule %d "), currentRule);
|
sl@0
|
296 |
moreRules = EFalse;
|
sl@0
|
297 |
SetTestStepResult(EFail);
|
sl@0
|
298 |
}
|
sl@0
|
299 |
|
sl@0
|
300 |
|
sl@0
|
301 |
}
|
sl@0
|
302 |
else
|
sl@0
|
303 |
{
|
sl@0
|
304 |
moreRules = EFalse;
|
sl@0
|
305 |
}
|
sl@0
|
306 |
}
|
sl@0
|
307 |
}
|
sl@0
|
308 |
|
sl@0
|
309 |
//If 1 or more selection rule objects were added successfully without error, the test step
|
sl@0
|
310 |
//can proceed to the next phase
|
sl@0
|
311 |
if((TestStepResult() == EPass) && (totalRules > 0))
|
sl@0
|
312 |
{
|
sl@0
|
313 |
INFO_PRINTF2(_L("Successfully Added Selection Rules: %d"), totalRules);
|
sl@0
|
314 |
}
|
sl@0
|
315 |
else if((TestStepResult() == EFail) && (totalRules > 0))
|
sl@0
|
316 |
{
|
sl@0
|
317 |
ERR_PRINTF1(_L("** .INI Error: Errornous Selection Rule Data **"));
|
sl@0
|
318 |
SetTestStepResult(EFail);
|
sl@0
|
319 |
}
|
sl@0
|
320 |
else
|
sl@0
|
321 |
{
|
sl@0
|
322 |
ERR_PRINTF1(_L("** NO VALID SELECTION RULE DATA FOUND **"));
|
sl@0
|
323 |
}
|
sl@0
|
324 |
|
sl@0
|
325 |
//**************************************************************
|
sl@0
|
326 |
|
sl@0
|
327 |
INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
|
sl@0
|
328 |
|
sl@0
|
329 |
if(TestStepResult()==EPass)
|
sl@0
|
330 |
{
|
sl@0
|
331 |
|
sl@0
|
332 |
//Assume faliure, unless all is successful
|
sl@0
|
333 |
SetTestStepResult(EFail);
|
sl@0
|
334 |
|
sl@0
|
335 |
//Create Rule Selector Object
|
sl@0
|
336 |
CRuleSelector* ruleSelector = CRuleSelector::NewL(rules);
|
sl@0
|
337 |
CleanupStack::Pop(rules);
|
sl@0
|
338 |
CleanupStack::PushL(ruleSelector);
|
sl@0
|
339 |
|
sl@0
|
340 |
//Set the Selector Passing in a pointer to the Rule Selector and SPI State
|
sl@0
|
341 |
CCryptoSpiStateApi::SetSelector(ruleSelector);
|
sl@0
|
342 |
|
sl@0
|
343 |
//Define a pointer of type CCryptoBase to store the address ofthe instantiated encryption object
|
sl@0
|
344 |
CCryptoBase* plugin = NULL;
|
sl@0
|
345 |
|
sl@0
|
346 |
TVariantPtrC interfaceType;
|
sl@0
|
347 |
|
sl@0
|
348 |
//Extract the Encryption Type parameter from the specified INI file
|
sl@0
|
349 |
if(!GetStringFromConfig(ConfigSection(),KConfigInterfaceType,interfaceType))
|
sl@0
|
350 |
{
|
sl@0
|
351 |
ERR_PRINTF1(_L("** .INI Error: Encryption Type Data Not Located **"));
|
sl@0
|
352 |
SetTestStepResult(EFail);
|
sl@0
|
353 |
}
|
sl@0
|
354 |
else
|
sl@0
|
355 |
{
|
sl@0
|
356 |
//Depending on the Interface Type retrieved, the appropriate factory object
|
sl@0
|
357 |
//is created and assigned to the previously CCryptoBase plugin pointer
|
sl@0
|
358 |
switch(interfaceType)
|
sl@0
|
359 |
{
|
sl@0
|
360 |
case KAsymmetricCipherInterface:
|
sl@0
|
361 |
{
|
sl@0
|
362 |
|
sl@0
|
363 |
TPtrC16 encryptKey;
|
sl@0
|
364 |
TVariantPtrC keyType;
|
sl@0
|
365 |
TVariantPtrC algorithmUid;
|
sl@0
|
366 |
TVariantPtrC cryptoMode;
|
sl@0
|
367 |
TVariantPtrC paddingMode;
|
sl@0
|
368 |
TVariantPtrC algorithmParams;
|
sl@0
|
369 |
|
sl@0
|
370 |
//Each of the individual parameters required to create the Asymmetric Cipher object
|
sl@0
|
371 |
//are read in from the specified INI configuration file
|
sl@0
|
372 |
if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
|
sl@0
|
373 |
!GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
|
sl@0
|
374 |
!GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
|
sl@0
|
375 |
!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
|
sl@0
|
376 |
{
|
sl@0
|
377 |
ERR_PRINTF1(_L("** .INI Error: Asymmetric Cipher Arguments Not Located **"));
|
sl@0
|
378 |
SetTestStepResult(EFail);
|
sl@0
|
379 |
}
|
sl@0
|
380 |
else
|
sl@0
|
381 |
{
|
sl@0
|
382 |
|
sl@0
|
383 |
//********** Rule Selector Unselcted to Create Key Pair ************
|
sl@0
|
384 |
CCryptoSpiStateApi::UnsetSelector();
|
sl@0
|
385 |
|
sl@0
|
386 |
CCryptoParams* keyParams = CCryptoParams::NewLC();
|
sl@0
|
387 |
|
sl@0
|
388 |
//Create Key Pair and Key Pair Generator Objects
|
sl@0
|
389 |
CKeyPair* keyPair = NULL;
|
sl@0
|
390 |
CKeyPairGenerator * keypairImpl = NULL;
|
sl@0
|
391 |
|
sl@0
|
392 |
INFO_PRINTF1(_L("Generating RSA keys"));
|
sl@0
|
393 |
|
sl@0
|
394 |
// create an RSA key pair
|
sl@0
|
395 |
keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
|
sl@0
|
396 |
keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
|
sl@0
|
397 |
|
sl@0
|
398 |
// create a key pair generator implementation interface
|
sl@0
|
399 |
TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(
|
sl@0
|
400 |
keypairImpl,
|
sl@0
|
401 |
KRSAKeyPairGeneratorUid,
|
sl@0
|
402 |
keyParams));
|
sl@0
|
403 |
|
sl@0
|
404 |
CleanupStack::PushL(keypairImpl);
|
sl@0
|
405 |
|
sl@0
|
406 |
// Create a Key Pair
|
sl@0
|
407 |
TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
|
sl@0
|
408 |
|
sl@0
|
409 |
CleanupStack::PushL(keyPair);
|
sl@0
|
410 |
|
sl@0
|
411 |
CCryptoSpiStateApi::SetSelector(ruleSelector);
|
sl@0
|
412 |
//******************************************************************
|
sl@0
|
413 |
|
sl@0
|
414 |
CAsymmetricCipher* asymmetricCipherImpl;
|
sl@0
|
415 |
|
sl@0
|
416 |
TRAP_LOG(err,CAsymmetricCipherFactory::CreateAsymmetricCipherL(asymmetricCipherImpl,
|
sl@0
|
417 |
algorithmUid,
|
sl@0
|
418 |
keyPair->PublicKey(),
|
sl@0
|
419 |
cryptoMode,
|
sl@0
|
420 |
paddingMode,
|
sl@0
|
421 |
NULL));
|
sl@0
|
422 |
|
sl@0
|
423 |
if(asymmetricCipherImpl && (err == KErrNone))
|
sl@0
|
424 |
{
|
sl@0
|
425 |
plugin = static_cast<CCryptoBase*>(asymmetricCipherImpl);
|
sl@0
|
426 |
|
sl@0
|
427 |
INFO_PRINTF1(_L("** Successfully Loaded Asymmetric Cipher Object **"));
|
sl@0
|
428 |
SetTestStepResult(EPass);
|
sl@0
|
429 |
}
|
sl@0
|
430 |
else
|
sl@0
|
431 |
{
|
sl@0
|
432 |
ERR_PRINTF2(_L("** Error: Loading Asymmetric Cipher Object - %d **"), err);
|
sl@0
|
433 |
SetTestStepResult(EFail);
|
sl@0
|
434 |
}
|
sl@0
|
435 |
|
sl@0
|
436 |
CleanupStack::PopAndDestroy(3,keyParams);
|
sl@0
|
437 |
}
|
sl@0
|
438 |
|
sl@0
|
439 |
break;
|
sl@0
|
440 |
}
|
sl@0
|
441 |
|
sl@0
|
442 |
case KSymmetricCipherInterface:
|
sl@0
|
443 |
{
|
sl@0
|
444 |
|
sl@0
|
445 |
TPtrC16 encryptKey;
|
sl@0
|
446 |
TVariantPtrC keyType;
|
sl@0
|
447 |
TVariantPtrC algorithmUid;
|
sl@0
|
448 |
TVariantPtrC cryptoMode;
|
sl@0
|
449 |
TVariantPtrC operationMode;
|
sl@0
|
450 |
TVariantPtrC paddingMode;
|
sl@0
|
451 |
TVariantPtrC algorithmParams;
|
sl@0
|
452 |
|
sl@0
|
453 |
//Each of the individual parameters required to create the Symmetric Cipher object
|
sl@0
|
454 |
//are read in from the specified INI configuration file
|
sl@0
|
455 |
if(!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
|
sl@0
|
456 |
!GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) ||
|
sl@0
|
457 |
!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
|
sl@0
|
458 |
!GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
|
sl@0
|
459 |
!GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
|
sl@0
|
460 |
!GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
|
sl@0
|
461 |
!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
|
sl@0
|
462 |
{
|
sl@0
|
463 |
ERR_PRINTF1(_L("** .INI Error: Symmetric Cipher Arguments Not Located **"));
|
sl@0
|
464 |
SetTestStepResult(EFail);
|
sl@0
|
465 |
}
|
sl@0
|
466 |
else
|
sl@0
|
467 |
{
|
sl@0
|
468 |
//Convert encryption key to an 8 Bit Descriptor
|
sl@0
|
469 |
HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
|
sl@0
|
470 |
TPtr8 keyStrPtr = keyStr->Des();
|
sl@0
|
471 |
|
sl@0
|
472 |
keyStrPtr.Copy(encryptKey);
|
sl@0
|
473 |
|
sl@0
|
474 |
//Create an new CryptoParams object to encapsulate the key type and secret key string
|
sl@0
|
475 |
CCryptoParams* keyParams = CCryptoParams::NewL();
|
sl@0
|
476 |
CleanupStack::PushL(keyParams);
|
sl@0
|
477 |
keyParams->AddL(*keyStr,keyType);
|
sl@0
|
478 |
|
sl@0
|
479 |
//Create Key Object
|
sl@0
|
480 |
TKeyProperty keyProperty;
|
sl@0
|
481 |
CKey* key=CKey::NewL(keyProperty,*keyParams);
|
sl@0
|
482 |
CleanupStack::PushL(key);
|
sl@0
|
483 |
|
sl@0
|
484 |
CSymmetricCipher* symmetricCipherImpl = NULL;
|
sl@0
|
485 |
|
sl@0
|
486 |
TRAP_LOG(err,CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipherImpl,
|
sl@0
|
487 |
algorithmUid,
|
sl@0
|
488 |
*key,
|
sl@0
|
489 |
cryptoMode,
|
sl@0
|
490 |
operationMode,
|
sl@0
|
491 |
paddingMode,
|
sl@0
|
492 |
NULL));
|
sl@0
|
493 |
|
sl@0
|
494 |
|
sl@0
|
495 |
if(symmetricCipherImpl && (err == KErrNone))
|
sl@0
|
496 |
{
|
sl@0
|
497 |
|
sl@0
|
498 |
plugin = static_cast<CCryptoBase*>(symmetricCipherImpl);
|
sl@0
|
499 |
|
sl@0
|
500 |
INFO_PRINTF1(_L("** Successfully Loaded Symmetric Cipher Object **"));
|
sl@0
|
501 |
SetTestStepResult(EPass);
|
sl@0
|
502 |
}
|
sl@0
|
503 |
else
|
sl@0
|
504 |
{
|
sl@0
|
505 |
ERR_PRINTF2(_L("** Error: Loading Symmetric Cipher Object - %d **"), err);
|
sl@0
|
506 |
SetTestStepResult(EFail);
|
sl@0
|
507 |
}
|
sl@0
|
508 |
|
sl@0
|
509 |
CleanupStack::PopAndDestroy(3,keyStr);
|
sl@0
|
510 |
}
|
sl@0
|
511 |
|
sl@0
|
512 |
break;
|
sl@0
|
513 |
}
|
sl@0
|
514 |
|
sl@0
|
515 |
case KHashInterface:
|
sl@0
|
516 |
{
|
sl@0
|
517 |
TVariantPtrC algorithmUid;
|
sl@0
|
518 |
TVariantPtrC operationMode;
|
sl@0
|
519 |
TVariantPtrC algorithmParams;
|
sl@0
|
520 |
|
sl@0
|
521 |
//Each of the individual parameters required to create the Hash object
|
sl@0
|
522 |
//are read in from the specified INI configuration file
|
sl@0
|
523 |
if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
|
sl@0
|
524 |
#ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
|
sl@0
|
525 |
!GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
|
sl@0
|
526 |
#endif
|
sl@0
|
527 |
!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
|
sl@0
|
528 |
{
|
sl@0
|
529 |
ERR_PRINTF1(_L("** .INI Error: Hash Arguments Not Located **"));
|
sl@0
|
530 |
SetTestStepResult(EFail);
|
sl@0
|
531 |
}
|
sl@0
|
532 |
else
|
sl@0
|
533 |
{
|
sl@0
|
534 |
CHash* hashImpl = NULL;
|
sl@0
|
535 |
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
|
sl@0
|
536 |
if (GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode))
|
sl@0
|
537 |
{
|
sl@0
|
538 |
TRAP_LOG(err,CHashFactory::CreateHashL(hashImpl,
|
sl@0
|
539 |
algorithmUid,
|
sl@0
|
540 |
operationMode,
|
sl@0
|
541 |
NULL,
|
sl@0
|
542 |
NULL));
|
sl@0
|
543 |
}
|
sl@0
|
544 |
else
|
sl@0
|
545 |
{
|
sl@0
|
546 |
TRAP_LOG(err,CHashFactory::CreateHashL(hashImpl,
|
sl@0
|
547 |
algorithmUid,
|
sl@0
|
548 |
NULL));
|
sl@0
|
549 |
}
|
sl@0
|
550 |
#else
|
sl@0
|
551 |
TRAP_LOG(err,CHashFactory::CreateHashL(hashImpl,
|
sl@0
|
552 |
algorithmUid,
|
sl@0
|
553 |
operationMode,
|
sl@0
|
554 |
NULL,
|
sl@0
|
555 |
NULL));
|
sl@0
|
556 |
#endif
|
sl@0
|
557 |
|
sl@0
|
558 |
if(hashImpl && (err == KErrNone))
|
sl@0
|
559 |
{
|
sl@0
|
560 |
plugin = static_cast<CCryptoBase*>(hashImpl);
|
sl@0
|
561 |
|
sl@0
|
562 |
INFO_PRINTF1(_L("** Successfully Loaded Hash Object **"));
|
sl@0
|
563 |
SetTestStepResult(EPass);
|
sl@0
|
564 |
}
|
sl@0
|
565 |
else
|
sl@0
|
566 |
{
|
sl@0
|
567 |
ERR_PRINTF2(_L("** Error: Loading Hash Object - %d **"), err);
|
sl@0
|
568 |
SetTestStepResult(EFail);
|
sl@0
|
569 |
}
|
sl@0
|
570 |
}
|
sl@0
|
571 |
|
sl@0
|
572 |
break;
|
sl@0
|
573 |
}
|
sl@0
|
574 |
|
sl@0
|
575 |
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
|
sl@0
|
576 |
case KMacInterface:
|
sl@0
|
577 |
{
|
sl@0
|
578 |
TVariantPtrC algorithmUid;
|
sl@0
|
579 |
TPtrC encryptKey;
|
sl@0
|
580 |
TVariantPtrC keyType;
|
sl@0
|
581 |
|
sl@0
|
582 |
//Each of the individual parameters required to create the Mac object
|
sl@0
|
583 |
//are read in from the specified INI configuration file
|
sl@0
|
584 |
if (!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
|
sl@0
|
585 |
!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
|
sl@0
|
586 |
!GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType))
|
sl@0
|
587 |
{
|
sl@0
|
588 |
ERR_PRINTF1(_L("** .INI Error: Mac Arguments Not Located **"));
|
sl@0
|
589 |
SetTestStepResult(EFail);
|
sl@0
|
590 |
}
|
sl@0
|
591 |
else
|
sl@0
|
592 |
{
|
sl@0
|
593 |
CMac* macImpl = NULL;
|
sl@0
|
594 |
|
sl@0
|
595 |
//Convert encryption key to an 8 Bit Descriptor
|
sl@0
|
596 |
HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
|
sl@0
|
597 |
TPtr8 keyStrPtr = keyStr->Des();
|
sl@0
|
598 |
|
sl@0
|
599 |
keyStrPtr.Copy(encryptKey);
|
sl@0
|
600 |
|
sl@0
|
601 |
//Create an new CryptoParams object to encapsulate the key type and secret key string
|
sl@0
|
602 |
CCryptoParams* keyParams = CCryptoParams::NewL();
|
sl@0
|
603 |
CleanupStack::PushL(keyParams);
|
sl@0
|
604 |
keyParams->AddL(*keyStr,keyType);
|
sl@0
|
605 |
|
sl@0
|
606 |
//Create Key Object
|
sl@0
|
607 |
TKeyProperty keyProperty;
|
sl@0
|
608 |
CKey* key=CKey::NewL(keyProperty,*keyParams);
|
sl@0
|
609 |
CleanupStack::PushL(key);
|
sl@0
|
610 |
|
sl@0
|
611 |
TRAP_LOG(err,CMacFactory::CreateMacL(macImpl,
|
sl@0
|
612 |
algorithmUid,
|
sl@0
|
613 |
*key,
|
sl@0
|
614 |
NULL));
|
sl@0
|
615 |
|
sl@0
|
616 |
if(macImpl && (err == KErrNone))
|
sl@0
|
617 |
{
|
sl@0
|
618 |
plugin = static_cast<CCryptoBase*>(macImpl);
|
sl@0
|
619 |
|
sl@0
|
620 |
INFO_PRINTF1(_L("** Successfully Loaded Mac Object **"));
|
sl@0
|
621 |
SetTestStepResult(EPass);
|
sl@0
|
622 |
}
|
sl@0
|
623 |
else
|
sl@0
|
624 |
{
|
sl@0
|
625 |
delete macImpl;
|
sl@0
|
626 |
ERR_PRINTF2(_L("** Error: Loading Mac Object - %d **"), err);
|
sl@0
|
627 |
SetTestStepResult(EFail);
|
sl@0
|
628 |
}
|
sl@0
|
629 |
|
sl@0
|
630 |
CleanupStack::PopAndDestroy(3,keyStr);
|
sl@0
|
631 |
}
|
sl@0
|
632 |
|
sl@0
|
633 |
break;
|
sl@0
|
634 |
}
|
sl@0
|
635 |
#endif
|
sl@0
|
636 |
|
sl@0
|
637 |
case KRandomInterface:
|
sl@0
|
638 |
{
|
sl@0
|
639 |
|
sl@0
|
640 |
TVariantPtrC algorithmUid;
|
sl@0
|
641 |
TVariantPtrC algorithmParams;
|
sl@0
|
642 |
|
sl@0
|
643 |
//Each of the individual parameters required to create the Random object
|
sl@0
|
644 |
//are read in from the specified INI configuration file
|
sl@0
|
645 |
if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
|
sl@0
|
646 |
!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
|
sl@0
|
647 |
{
|
sl@0
|
648 |
ERR_PRINTF1(_L("** .INI Error: Random Arguments Not Located **"));
|
sl@0
|
649 |
SetTestStepResult(EFail);
|
sl@0
|
650 |
}
|
sl@0
|
651 |
else
|
sl@0
|
652 |
{
|
sl@0
|
653 |
CryptoSpi::CRandom* randomImpl = NULL;
|
sl@0
|
654 |
|
sl@0
|
655 |
TRAP_LOG(err,CRandomFactory::CreateRandomL(randomImpl,
|
sl@0
|
656 |
algorithmUid,
|
sl@0
|
657 |
NULL));
|
sl@0
|
658 |
|
sl@0
|
659 |
if(randomImpl && (err == KErrNone))
|
sl@0
|
660 |
{
|
sl@0
|
661 |
plugin = static_cast<CCryptoBase*>(randomImpl);
|
sl@0
|
662 |
|
sl@0
|
663 |
INFO_PRINTF1(_L("** Successfully Loaded Random Object **"));
|
sl@0
|
664 |
SetTestStepResult(EPass);
|
sl@0
|
665 |
}
|
sl@0
|
666 |
else
|
sl@0
|
667 |
{
|
sl@0
|
668 |
ERR_PRINTF2(_L("** Error: Loading Random Object - %d **"), err);
|
sl@0
|
669 |
SetTestStepResult(EFail);
|
sl@0
|
670 |
}
|
sl@0
|
671 |
|
sl@0
|
672 |
}
|
sl@0
|
673 |
|
sl@0
|
674 |
break;
|
sl@0
|
675 |
}
|
sl@0
|
676 |
|
sl@0
|
677 |
case KSignerInterface:
|
sl@0
|
678 |
{
|
sl@0
|
679 |
TVariantPtrC algorithmUid;
|
sl@0
|
680 |
TVariantPtrC paddingMode;
|
sl@0
|
681 |
TVariantPtrC algorithmParams;
|
sl@0
|
682 |
|
sl@0
|
683 |
//Each of the individual parameters required to create the Signer object
|
sl@0
|
684 |
//are read in from the specified INI configuration file
|
sl@0
|
685 |
if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
|
sl@0
|
686 |
!GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
|
sl@0
|
687 |
!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
|
sl@0
|
688 |
{
|
sl@0
|
689 |
ERR_PRINTF1(_L("** .INI Error: Signer Arguments Not Located **"));
|
sl@0
|
690 |
SetTestStepResult(EFail);
|
sl@0
|
691 |
}
|
sl@0
|
692 |
else
|
sl@0
|
693 |
{
|
sl@0
|
694 |
|
sl@0
|
695 |
//********** Rule Selector Unselected to Create Key Pair ************
|
sl@0
|
696 |
CCryptoSpiStateApi::UnsetSelector();
|
sl@0
|
697 |
|
sl@0
|
698 |
CCryptoParams* keyParams = CCryptoParams::NewLC();
|
sl@0
|
699 |
|
sl@0
|
700 |
//Create Key Pair and Key Pair Generator Objects
|
sl@0
|
701 |
CKeyPair* keyPair = NULL;
|
sl@0
|
702 |
CKeyPairGenerator * keypairImpl = NULL;
|
sl@0
|
703 |
|
sl@0
|
704 |
INFO_PRINTF1(_L("Generating RSA keys"));
|
sl@0
|
705 |
|
sl@0
|
706 |
// create an RSA key pair
|
sl@0
|
707 |
keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
|
sl@0
|
708 |
keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
|
sl@0
|
709 |
|
sl@0
|
710 |
// create a key pair generator implementation interface
|
sl@0
|
711 |
TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
|
sl@0
|
712 |
KRSAKeyPairGeneratorUid,
|
sl@0
|
713 |
keyParams));
|
sl@0
|
714 |
|
sl@0
|
715 |
CleanupStack::PushL(keypairImpl);
|
sl@0
|
716 |
|
sl@0
|
717 |
// Create a Key Pair
|
sl@0
|
718 |
TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
|
sl@0
|
719 |
|
sl@0
|
720 |
CleanupStack::PushL(keyPair);
|
sl@0
|
721 |
|
sl@0
|
722 |
CCryptoSpiStateApi::SetSelector(ruleSelector);
|
sl@0
|
723 |
//******************************************************************
|
sl@0
|
724 |
|
sl@0
|
725 |
CSigner* signerImpl = NULL;
|
sl@0
|
726 |
|
sl@0
|
727 |
TRAP_LOG(err,CSignatureFactory::CreateSignerL(signerImpl,
|
sl@0
|
728 |
algorithmUid,
|
sl@0
|
729 |
keyPair->PrivateKey(),
|
sl@0
|
730 |
paddingMode,
|
sl@0
|
731 |
NULL));
|
sl@0
|
732 |
|
sl@0
|
733 |
if(signerImpl && (err == KErrNone))
|
sl@0
|
734 |
{
|
sl@0
|
735 |
plugin = static_cast<CCryptoBase*>(signerImpl);
|
sl@0
|
736 |
|
sl@0
|
737 |
INFO_PRINTF1(_L("** Successfully Loaded Signer Object **"));
|
sl@0
|
738 |
SetTestStepResult(EPass);
|
sl@0
|
739 |
}
|
sl@0
|
740 |
else
|
sl@0
|
741 |
{
|
sl@0
|
742 |
ERR_PRINTF2(_L("** Error: Loading Signer Object - %d **"), err);
|
sl@0
|
743 |
SetTestStepResult(EFail);
|
sl@0
|
744 |
}
|
sl@0
|
745 |
|
sl@0
|
746 |
CleanupStack::PopAndDestroy(3,keyParams);
|
sl@0
|
747 |
}
|
sl@0
|
748 |
|
sl@0
|
749 |
break;
|
sl@0
|
750 |
}
|
sl@0
|
751 |
|
sl@0
|
752 |
case KVerifierInterface:
|
sl@0
|
753 |
{
|
sl@0
|
754 |
TVariantPtrC algorithmUid;
|
sl@0
|
755 |
TVariantPtrC paddingMode;
|
sl@0
|
756 |
TVariantPtrC algorithmParams;
|
sl@0
|
757 |
|
sl@0
|
758 |
//Each of the individual parameters required to create the Verifier object
|
sl@0
|
759 |
//are read in from the specified INI configuration file
|
sl@0
|
760 |
if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
|
sl@0
|
761 |
!GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
|
sl@0
|
762 |
!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
|
sl@0
|
763 |
{
|
sl@0
|
764 |
ERR_PRINTF1(_L("** .INI Error: Verifier Arguments Not Located **"));
|
sl@0
|
765 |
SetTestStepResult(EFail);
|
sl@0
|
766 |
}
|
sl@0
|
767 |
else
|
sl@0
|
768 |
{
|
sl@0
|
769 |
|
sl@0
|
770 |
//********** Rule Selector Unselected to Create Key Pair ************
|
sl@0
|
771 |
CCryptoSpiStateApi::UnsetSelector();
|
sl@0
|
772 |
|
sl@0
|
773 |
CCryptoParams* keyParams = CCryptoParams::NewLC();
|
sl@0
|
774 |
|
sl@0
|
775 |
//Create Key Pair and Key Pair Generator Objects
|
sl@0
|
776 |
CKeyPair* keyPair = NULL;
|
sl@0
|
777 |
CKeyPairGenerator * keypairImpl = NULL;
|
sl@0
|
778 |
|
sl@0
|
779 |
INFO_PRINTF1(_L("Generating RSA keys"));
|
sl@0
|
780 |
|
sl@0
|
781 |
// create an RSA key pair
|
sl@0
|
782 |
keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
|
sl@0
|
783 |
keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
|
sl@0
|
784 |
|
sl@0
|
785 |
// create a key pair generator implementation interface
|
sl@0
|
786 |
TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
|
sl@0
|
787 |
KRSAKeyPairGeneratorUid,
|
sl@0
|
788 |
keyParams));
|
sl@0
|
789 |
|
sl@0
|
790 |
CleanupStack::PushL(keypairImpl);
|
sl@0
|
791 |
|
sl@0
|
792 |
// Create a Key Pair
|
sl@0
|
793 |
TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
|
sl@0
|
794 |
|
sl@0
|
795 |
CleanupStack::PushL(keyPair);
|
sl@0
|
796 |
|
sl@0
|
797 |
CCryptoSpiStateApi::SetSelector(ruleSelector);
|
sl@0
|
798 |
//******************************************************************
|
sl@0
|
799 |
|
sl@0
|
800 |
CVerifier* verifierImpl = NULL;
|
sl@0
|
801 |
|
sl@0
|
802 |
TRAP_LOG(err,CSignatureFactory::CreateVerifierL(verifierImpl,
|
sl@0
|
803 |
algorithmUid,
|
sl@0
|
804 |
keyPair->PublicKey(),
|
sl@0
|
805 |
paddingMode,
|
sl@0
|
806 |
NULL));
|
sl@0
|
807 |
|
sl@0
|
808 |
if(verifierImpl && (err == KErrNone))
|
sl@0
|
809 |
{
|
sl@0
|
810 |
plugin = static_cast<CCryptoBase*>(verifierImpl);
|
sl@0
|
811 |
|
sl@0
|
812 |
INFO_PRINTF1(_L("** Successfully Loaded Verifier Object **"));
|
sl@0
|
813 |
SetTestStepResult(EPass);
|
sl@0
|
814 |
}
|
sl@0
|
815 |
else
|
sl@0
|
816 |
{
|
sl@0
|
817 |
ERR_PRINTF2(_L("** Error: Loading Verifier Object - %d **"), err);
|
sl@0
|
818 |
SetTestStepResult(EFail);
|
sl@0
|
819 |
}
|
sl@0
|
820 |
|
sl@0
|
821 |
CleanupStack::PopAndDestroy(3,keyParams);
|
sl@0
|
822 |
}
|
sl@0
|
823 |
|
sl@0
|
824 |
break;
|
sl@0
|
825 |
}
|
sl@0
|
826 |
|
sl@0
|
827 |
case KKeypairGeneratorInterface:
|
sl@0
|
828 |
{
|
sl@0
|
829 |
TVariantPtrC algorithmUid;
|
sl@0
|
830 |
TVariantPtrC algorithmParams;
|
sl@0
|
831 |
|
sl@0
|
832 |
//Each of the individual parameters required to create the Key Pair Generator object
|
sl@0
|
833 |
//are read in from the specified INI configuration file
|
sl@0
|
834 |
if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
|
sl@0
|
835 |
!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
|
sl@0
|
836 |
{
|
sl@0
|
837 |
ERR_PRINTF1(_L("** .INI Error: Key Pair Generator Arguments Not Located **"));
|
sl@0
|
838 |
SetTestStepResult(EFail);
|
sl@0
|
839 |
}
|
sl@0
|
840 |
else
|
sl@0
|
841 |
{
|
sl@0
|
842 |
|
sl@0
|
843 |
CCryptoParams* keyParams = CCryptoParams::NewLC();
|
sl@0
|
844 |
|
sl@0
|
845 |
//Create Key Pair and Key Pair Generator Objects
|
sl@0
|
846 |
CKeyPairGenerator * keypairImpl = NULL;
|
sl@0
|
847 |
|
sl@0
|
848 |
INFO_PRINTF1(_L("Generating RSA keys"));
|
sl@0
|
849 |
|
sl@0
|
850 |
// create an RSA key pair
|
sl@0
|
851 |
keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
|
sl@0
|
852 |
keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
|
sl@0
|
853 |
|
sl@0
|
854 |
// create a key pair generator implementation interface
|
sl@0
|
855 |
TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
|
sl@0
|
856 |
algorithmUid,
|
sl@0
|
857 |
keyParams));
|
sl@0
|
858 |
|
sl@0
|
859 |
if(keypairImpl && (err == KErrNone))
|
sl@0
|
860 |
{
|
sl@0
|
861 |
plugin = static_cast<CCryptoBase*>(keypairImpl);
|
sl@0
|
862 |
|
sl@0
|
863 |
INFO_PRINTF1(_L("** Successfully Loaded Key Pair Generator Object **"));
|
sl@0
|
864 |
SetTestStepResult(EPass);
|
sl@0
|
865 |
}
|
sl@0
|
866 |
else
|
sl@0
|
867 |
{
|
sl@0
|
868 |
ERR_PRINTF2(_L("** Error: Loading Key Pair Generator Object - %d **"), err);
|
sl@0
|
869 |
SetTestStepResult(EFail);
|
sl@0
|
870 |
}
|
sl@0
|
871 |
|
sl@0
|
872 |
CleanupStack::PopAndDestroy(keyParams);
|
sl@0
|
873 |
}
|
sl@0
|
874 |
|
sl@0
|
875 |
break;
|
sl@0
|
876 |
}
|
sl@0
|
877 |
|
sl@0
|
878 |
case KKeyAgreementInterface:
|
sl@0
|
879 |
{
|
sl@0
|
880 |
TVariantPtrC algorithmUid;
|
sl@0
|
881 |
TVariantPtrC algorithmParams;
|
sl@0
|
882 |
|
sl@0
|
883 |
//Each of the individual parameters required to create the Key Agreement object
|
sl@0
|
884 |
//are read in from the specified INI configuration file
|
sl@0
|
885 |
if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
|
sl@0
|
886 |
!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
|
sl@0
|
887 |
{
|
sl@0
|
888 |
ERR_PRINTF1(_L("** .INI Error: Key Agreement Arguments Not Located **"));
|
sl@0
|
889 |
SetTestStepResult(EFail);
|
sl@0
|
890 |
}
|
sl@0
|
891 |
else
|
sl@0
|
892 |
{
|
sl@0
|
893 |
//********** Rule Selector Unselected to Create Key Pair ************
|
sl@0
|
894 |
CCryptoSpiStateApi::UnsetSelector();
|
sl@0
|
895 |
|
sl@0
|
896 |
RInteger DH_N = RInteger::NewPrimeL(64);
|
sl@0
|
897 |
CleanupClosePushL(DH_N);
|
sl@0
|
898 |
|
sl@0
|
899 |
RInteger DH_N_MinusOne = RInteger::NewL(DH_N);
|
sl@0
|
900 |
CleanupClosePushL(DH_N_MinusOne);
|
sl@0
|
901 |
DH_N_MinusOne-=1;
|
sl@0
|
902 |
|
sl@0
|
903 |
RInteger DH_G = RInteger::NewRandomL(TInteger::Two(), DH_N_MinusOne);
|
sl@0
|
904 |
CleanupClosePushL(DH_G);
|
sl@0
|
905 |
|
sl@0
|
906 |
CCryptoParams* keyParams = CCryptoParams::NewLC();
|
sl@0
|
907 |
|
sl@0
|
908 |
TRAP_LOG(err,keyParams->AddL(DH_N, KDhKeyParameterNUid));
|
sl@0
|
909 |
TRAP_LOG(err,keyParams->AddL(DH_G, KDhKeyParameterGUid));
|
sl@0
|
910 |
|
sl@0
|
911 |
//Create Key Pair and Key Pair Generator Objects
|
sl@0
|
912 |
CKeyPair* keyPair = NULL;
|
sl@0
|
913 |
CKeyPairGenerator * keypairImpl = NULL;
|
sl@0
|
914 |
|
sl@0
|
915 |
INFO_PRINTF1(_L("Generating Key Pair..."));
|
sl@0
|
916 |
|
sl@0
|
917 |
// create a key pair generator implementation interface
|
sl@0
|
918 |
TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
|
sl@0
|
919 |
KDHKeyPairGeneratorUid,
|
sl@0
|
920 |
keyParams));
|
sl@0
|
921 |
CleanupStack::PushL(keypairImpl);
|
sl@0
|
922 |
|
sl@0
|
923 |
// Create a Key Pair
|
sl@0
|
924 |
TRAP_LOG(err,keypairImpl->GenerateKeyPairL(NULL, *keyParams, keyPair));
|
sl@0
|
925 |
|
sl@0
|
926 |
CleanupStack::PushL(keyPair);
|
sl@0
|
927 |
|
sl@0
|
928 |
CCryptoSpiStateApi::SetSelector(ruleSelector);
|
sl@0
|
929 |
//******************************************************************
|
sl@0
|
930 |
|
sl@0
|
931 |
CKeyAgreement* keyAgreementImpl = NULL;
|
sl@0
|
932 |
|
sl@0
|
933 |
TRAP_LOG(err,CKeyAgreementFactory::CreateKeyAgreementL(keyAgreementImpl,
|
sl@0
|
934 |
algorithmUid,
|
sl@0
|
935 |
keyPair->PrivateKey(),
|
sl@0
|
936 |
keyParams));
|
sl@0
|
937 |
|
sl@0
|
938 |
if(keyAgreementImpl && (err == KErrNone))
|
sl@0
|
939 |
{
|
sl@0
|
940 |
plugin = static_cast<CCryptoBase*>(keyAgreementImpl);
|
sl@0
|
941 |
|
sl@0
|
942 |
INFO_PRINTF1(_L("** Successfully Loaded Key Agreement Object **"));
|
sl@0
|
943 |
SetTestStepResult(EPass);
|
sl@0
|
944 |
}
|
sl@0
|
945 |
else
|
sl@0
|
946 |
{
|
sl@0
|
947 |
ERR_PRINTF2(_L("** Error: Loading Key Agreement Object - %d **"), err);
|
sl@0
|
948 |
SetTestStepResult(EFail);
|
sl@0
|
949 |
}
|
sl@0
|
950 |
|
sl@0
|
951 |
CleanupStack::PopAndDestroy(6,&DH_N);
|
sl@0
|
952 |
}
|
sl@0
|
953 |
|
sl@0
|
954 |
break;
|
sl@0
|
955 |
}
|
sl@0
|
956 |
|
sl@0
|
957 |
default:
|
sl@0
|
958 |
{
|
sl@0
|
959 |
ERR_PRINTF1(_L("** .INI Error: Interface Type Unknown **"));
|
sl@0
|
960 |
SetTestStepResult(EFail);
|
sl@0
|
961 |
break;
|
sl@0
|
962 |
}
|
sl@0
|
963 |
|
sl@0
|
964 |
}
|
sl@0
|
965 |
}
|
sl@0
|
966 |
|
sl@0
|
967 |
if(TestStepResult()==EPass)
|
sl@0
|
968 |
{
|
sl@0
|
969 |
//Push the selected implementation onto the Cleanup Stack
|
sl@0
|
970 |
CleanupStack::PushL(plugin);
|
sl@0
|
971 |
|
sl@0
|
972 |
//Assume faliure, unless all is successful
|
sl@0
|
973 |
SetTestStepResult(EFail);
|
sl@0
|
974 |
|
sl@0
|
975 |
//Define a pointer of type TCharacteristics in order to store the appropriate
|
sl@0
|
976 |
//encryption object's characterisctics
|
sl@0
|
977 |
const TCharacteristics* characteristics(NULL);
|
sl@0
|
978 |
|
sl@0
|
979 |
//Retrieve the characteristics for the symmetric cipher implementation object
|
sl@0
|
980 |
TRAP_LOG(err, plugin->GetCharacteristicsL(characteristics));
|
sl@0
|
981 |
|
sl@0
|
982 |
TVariantPtrC exAlgorithmUid;
|
sl@0
|
983 |
TVariantPtrC exImplementationUid;
|
sl@0
|
984 |
|
sl@0
|
985 |
if(!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
|
sl@0
|
986 |
!GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid))
|
sl@0
|
987 |
{
|
sl@0
|
988 |
ERR_PRINTF1(_L("** .INI Error: Expected Algorithm Arguments Not Located **"));
|
sl@0
|
989 |
SetTestStepResult(EFail);
|
sl@0
|
990 |
}
|
sl@0
|
991 |
else
|
sl@0
|
992 |
{
|
sl@0
|
993 |
INFO_PRINTF1(_L("Checking Plug-in Selection..."));
|
sl@0
|
994 |
|
sl@0
|
995 |
CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
|
sl@0
|
996 |
|
sl@0
|
997 |
TPtrC errorMessage;
|
sl@0
|
998 |
|
sl@0
|
999 |
//Perform plug-in Check
|
sl@0
|
1000 |
if(pluginCheck->checkSelectedPlugin(characteristics,
|
sl@0
|
1001 |
exAlgorithmUid,
|
sl@0
|
1002 |
exImplementationUid,
|
sl@0
|
1003 |
errorMessage))
|
sl@0
|
1004 |
{
|
sl@0
|
1005 |
INFO_PRINTF1(_L("** PASS: Correct Plugin Implementation Selected **"));
|
sl@0
|
1006 |
SetTestStepResult(EPass);
|
sl@0
|
1007 |
}
|
sl@0
|
1008 |
else
|
sl@0
|
1009 |
{
|
sl@0
|
1010 |
ERR_PRINTF2(_L("** FAIL: Wrong Plugin Implementation Selected - %S **"),&errorMessage);
|
sl@0
|
1011 |
}
|
sl@0
|
1012 |
|
sl@0
|
1013 |
CleanupStack::PopAndDestroy(pluginCheck);
|
sl@0
|
1014 |
}
|
sl@0
|
1015 |
|
sl@0
|
1016 |
CleanupStack::PopAndDestroy(plugin);
|
sl@0
|
1017 |
}
|
sl@0
|
1018 |
|
sl@0
|
1019 |
//Unselect Rule Selector
|
sl@0
|
1020 |
CCryptoSpiStateApi::UnsetSelector();
|
sl@0
|
1021 |
|
sl@0
|
1022 |
//Pop and Destroy Rule Selector from the Cleanup Stack
|
sl@0
|
1023 |
CleanupStack::PopAndDestroy(ruleSelector);
|
sl@0
|
1024 |
}
|
sl@0
|
1025 |
}
|
sl@0
|
1026 |
|
sl@0
|
1027 |
INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
|
sl@0
|
1028 |
return TestStepResult();
|
sl@0
|
1029 |
}
|
sl@0
|
1030 |
|
sl@0
|
1031 |
|
sl@0
|
1032 |
TVerdict CRuleSelectCommonStep::doTestStepPostambleL()
|
sl@0
|
1033 |
{
|
sl@0
|
1034 |
return TestStepResult();
|
sl@0
|
1035 |
}
|
sl@0
|
1036 |
|