|
1 /* |
|
2 * Copyright (c) 2005-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 * This file is used for the verification function of the pkcs12 file |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 /** |
|
23 @file |
|
24 @internalTechnology |
|
25 */ |
|
26 |
|
27 // System Include |
|
28 #include <testexecutelog.h> |
|
29 |
|
30 //User Include |
|
31 #include "tpkcs12libteststep.h" |
|
32 #include "tpkcs12data.h" |
|
33 #include "tpkcs12common.h" |
|
34 |
|
35 using namespace PKCS12; |
|
36 |
|
37 const TInt KBagDataLength = 7; |
|
38 const TInt KContentInfoLength = 11; |
|
39 /** |
|
40 Description:constructor:used for initialization of the variables declared |
|
41 @test |
|
42 @internalTechnology |
|
43 */ |
|
44 CPKCS12LibTestStep::CPKCS12LibTestStep() |
|
45 { |
|
46 iActualResult=ETrue; |
|
47 iUnitTest=EFalse; |
|
48 iUnitTestContinueFlag = ETrue; |
|
49 iExpectedError = ETrue; |
|
50 iExpectedResult=KPositiveTest; |
|
51 } |
|
52 /** |
|
53 Description:Destructor |
|
54 @test |
|
55 @internalTechnology |
|
56 */ |
|
57 CPKCS12LibTestStep::~CPKCS12LibTestStep() |
|
58 { |
|
59 iFileSession.Close(); |
|
60 delete iParser; |
|
61 iPrivacyPassword.ResetAndDestroy(); |
|
62 } |
|
63 |
|
64 /** |
|
65 Function is intended to parse the pkcs12 file, compare the results and |
|
66 log the same |
|
67 @internalTechnology: |
|
68 @return:TVerdict -returns EFail if there is a failure else EPass |
|
69 @test |
|
70 @leave:- if memory allocation fails |
|
71 */ |
|
72 TVerdict CPKCS12LibTestStep::doTestStepL() |
|
73 { |
|
74 //__UHEAP_MARK; |
|
75 TPtrC integrityMode(KNullDesC); |
|
76 TPtrC integrityPassword(KNullDesC); |
|
77 TPtrC privacyPassword(KNullDesC); |
|
78 TPtrC dataPath(KNullDesC); |
|
79 TBool flagReturn=ETrue; |
|
80 |
|
81 |
|
82 if(iFileSession.Connect()) |
|
83 { |
|
84 INFO_PRINTF1(_L("File server session failed")); |
|
85 flagReturn=EFalse; |
|
86 } |
|
87 |
|
88 if(flagReturn) |
|
89 { |
|
90 if((!GetStringFromConfig(KMainSec,KFilePath,dataPath)) || |
|
91 !GetStringFromConfig(KMainSec,KIntegrityMode,integrityMode)) |
|
92 { |
|
93 SetTestStepResult(EAbort); |
|
94 ERR_PRINTF1(_L("Input Data not found in ini file")); |
|
95 flagReturn=EFalse; |
|
96 } |
|
97 } |
|
98 //Check the input |
|
99 if(flagReturn) |
|
100 { |
|
101 if(!GetBoolFromConfig(KMainSec,KUnitTest,iUnitTest)) |
|
102 { |
|
103 iUnitTest=EFalse; |
|
104 } |
|
105 //Password Integrity Mode |
|
106 if(integrityMode.CompareF(KPassword)==0) |
|
107 { |
|
108 if(!GetStringFromConfig(KMainSec,KIntegrityPassword,integrityPassword)) |
|
109 { |
|
110 ERR_PRINTF1(_L("Problem in the Main section of the ini file")); |
|
111 SetTestStepResult(EFail); |
|
112 flagReturn=EFalse; |
|
113 } |
|
114 else |
|
115 { |
|
116 |
|
117 iParser = CPkcs12Parser::NewL(); |
|
118 // set the integrity password |
|
119 iParser->SetIntegrityPasswordL(integrityPassword); |
|
120 // set the datapath |
|
121 iParser->SetDataL(dataPath); |
|
122 //set the privacy password |
|
123 ParsePrivacyPwdL(); |
|
124 //parse the pkcs12 file |
|
125 iParser->ParseL(); |
|
126 |
|
127 if(!GetBoolFromConfig(KMainSec,KIntegrityValid,iExpectedResult)) |
|
128 { |
|
129 WARN_PRINTF1(_L("Integrity valid not found in ini file")); |
|
130 iExpectedResult=KPositiveTest; |
|
131 } |
|
132 if(!VerifyMainSecL()) |
|
133 { |
|
134 ERR_PRINTF1(_L("Main section failed")); |
|
135 flagReturn=EFalse; |
|
136 } |
|
137 else if(!iUnitTestContinueFlag) |
|
138 { |
|
139 SetTestStepResult(EPass); |
|
140 delete iParser; |
|
141 iParser = NULL; |
|
142 flagReturn = EFalse; |
|
143 } |
|
144 } |
|
145 } |
|
146 else if(integrityMode.CompareF(KPublicIntegrity)==0) |
|
147 { |
|
148 //public Integrity Mode |
|
149 } |
|
150 else |
|
151 { |
|
152 ERR_PRINTF1(_L("Integrity pwd not known in ini file")); |
|
153 SetTestStepResult(EFail); |
|
154 flagReturn=EFalse; |
|
155 } |
|
156 } |
|
157 if(flagReturn) |
|
158 { |
|
159 //Check the Authenticated safe section |
|
160 if(!VerifyAuthSafe()) |
|
161 { |
|
162 ERR_PRINTF1(_L("Authenticated safe section failed")); |
|
163 SetTestStepResult(EFail); |
|
164 flagReturn=EFalse; |
|
165 } |
|
166 else if(!iUnitTestContinueFlag ) |
|
167 { |
|
168 SetTestStepResult(EPass); |
|
169 delete iParser; |
|
170 iParser = NULL; |
|
171 flagReturn = EFalse; |
|
172 } |
|
173 } |
|
174 if(flagReturn) |
|
175 { |
|
176 //calculate the totalsafebags in the pkcs12 file |
|
177 TInt totalsafebags = iParser->PfxHeader().TotalSafeBagCount(); |
|
178 |
|
179 //calculate the totalbags(including the safecontentsbag) in the pkcs12 file |
|
180 TInt totalbags = totalsafebags + iParser->PfxHeader().SafecontentBagCount(); |
|
181 |
|
182 //Check the BagData section |
|
183 if(!ChkBagDataL(totalsafebags,totalbags)) |
|
184 { |
|
185 ERR_PRINTF1(_L("Bag Data section failed")); |
|
186 SetTestStepResult(EFail); |
|
187 flagReturn=EFalse; |
|
188 } |
|
189 else if(!iUnitTestContinueFlag) |
|
190 { |
|
191 delete iParser; |
|
192 iParser = NULL; |
|
193 flagReturn = EFalse; |
|
194 } |
|
195 } |
|
196 if(flagReturn) |
|
197 { |
|
198 SetTestStepResult(EPass); |
|
199 } |
|
200 |
|
201 //__UHEAP_MARKEND; |
|
202 return TestStepResult(); |
|
203 } |
|
204 /** |
|
205 Function is intended to verify the expected error in each section of the ini file |
|
206 @internalTechnology: |
|
207 @return:TBool:returns EFalse if there is a failure else ETrue |
|
208 @test: |
|
209 */ |
|
210 TBool CPKCS12LibTestStep::VerifyExpectedError(const TDesC& aSecName) |
|
211 { |
|
212 TBool flagReturn = ETrue; |
|
213 if ( iUnitTest ) |
|
214 { |
|
215 if(GetIntFromConfig(aSecName,KExpectedError,iExpectedError)==EFalse) |
|
216 { |
|
217 INFO_PRINTF1(_L("ExpectedError not found in INI File")); |
|
218 } |
|
219 // Checks the error returned by the library with the expected error read |
|
220 // from the INI file. |
|
221 TInt actualError = 0; |
|
222 |
|
223 if ( (!aSecName.Compare(KMainSec) || !aSecName.Compare(KAuthSafeSec) || |
|
224 !aSecName.Compare(_L("MacData")) || (!aSecName.Left(KBagDataLength).Compare(KBagDataSec)) || |
|
225 (!aSecName.Left(KContentInfoLength).CompareF(KContentInfoKey))) && !iExpectedResult ) |
|
226 { |
|
227 actualError = iParser->PfxHeader().Pkcs12ActualError(); |
|
228 } |
|
229 if (actualError == iExpectedError) |
|
230 { |
|
231 INFO_PRINTF1(_L("ExpectedError matchs")); |
|
232 iUnitTestContinueFlag = EFalse; |
|
233 iExpectedResult = ETrue; |
|
234 } |
|
235 } |
|
236 |
|
237 if(iExpectedResult!=iActualResult) |
|
238 { |
|
239 SetTestStepResult(EFail); |
|
240 flagReturn= EFalse; |
|
241 } |
|
242 iActualResult = ETrue; |
|
243 return flagReturn; |
|
244 } |
|
245 /** |
|
246 Function is intended to set the privacy passwords of the contentinfotype |
|
247 @internalTechnology: |
|
248 @test: |
|
249 @leave: if leave occurs if memory allocation fails |
|
250 */ |
|
251 void CPKCS12LibTestStep::ParsePrivacyPwdL() |
|
252 { |
|
253 TPtrC pass(KNullDesC); |
|
254 //to append the number to get the actual key value |
|
255 TInt count=0; |
|
256 //return value |
|
257 TBool privacyPwdPresent=EFalse; |
|
258 |
|
259 //Put all the content info privacy passwords in an array |
|
260 do |
|
261 { |
|
262 TBuf<KPrivacyPwdStrLen> privacyPwdBuf(KPrivacyPassword); |
|
263 pass.Set(KNullDesC); |
|
264 count++; |
|
265 //appending the count to the Keyvalue |
|
266 privacyPwdBuf.AppendNum(count); |
|
267 privacyPwdPresent=GetStringFromConfig(KMainSec,privacyPwdBuf,pass); |
|
268 if(privacyPwdPresent) |
|
269 { |
|
270 HBufC *temp=pass.AllocLC(); |
|
271 iPrivacyPassword.AppendL(temp); |
|
272 CleanupStack::Pop(temp); |
|
273 } |
|
274 }while(privacyPwdPresent); |
|
275 iParser->SetPrivacyPassword(iPrivacyPassword); |
|
276 } |
|
277 /** |
|
278 Function is intended to parse the main section of the ini file |
|
279 @internalTechnology: |
|
280 @return:returns EFalse if there is a failure else ETrue |
|
281 @test: |
|
282 */ |
|
283 TBool CPKCS12LibTestStep::VerifyMainSecL() |
|
284 { |
|
285 TBool mac=EFalse; |
|
286 TBool flagReturn=ETrue; |
|
287 |
|
288 //retrieve the expected result:PositiveTest/NegativeTest |
|
289 if(!GetBoolFromConfig(KMainSec,KExpectedResult,iExpectedResult)) |
|
290 { |
|
291 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
292 iExpectedResult=KPositiveTest; |
|
293 } |
|
294 if(!GetBoolFromConfig(KMainSec,KMacPresent,mac)) |
|
295 { |
|
296 WARN_PRINTF1(_L("Mac present not found in ini file")); |
|
297 //default only integration test |
|
298 mac=EFalse; |
|
299 } |
|
300 else if(mac && iUnitTest) |
|
301 { |
|
302 //call the mac data function and check for all the macdata section values |
|
303 iActualResult=ChkMacValueL(); |
|
304 if (!iUnitTestContinueFlag) |
|
305 { |
|
306 return flagReturn; |
|
307 } |
|
308 } |
|
309 if(!VerifyExpectedError(KMainSec)) |
|
310 { |
|
311 SetTestStepResult(EFail); |
|
312 flagReturn = EFalse; |
|
313 } |
|
314 return flagReturn; |
|
315 } |
|
316 /** |
|
317 Function is intended to parse the AuthSafe section of the ini file |
|
318 @internalTechnology: |
|
319 @return:returns EFalse if there is a failure else ETrue |
|
320 @test: |
|
321 */ |
|
322 TBool CPKCS12LibTestStep::VerifyAuthSafe() |
|
323 { |
|
324 TInt contentInfoCount=0; |
|
325 TPtrC contentSection(KNullDesC); |
|
326 TInt contentIndex=0; |
|
327 TBool flagReturn=ETrue; |
|
328 |
|
329 if(!GetIntFromConfig(KAuthSafeSec,KContentInfoNum,contentInfoCount)) |
|
330 { |
|
331 ERR_PRINTF1(_L("Count not available in the inifile")); |
|
332 SetTestStepResult(EFail); |
|
333 flagReturn=EFalse; |
|
334 } |
|
335 //retrieve the expected result:PositiveTest/NegativeTest |
|
336 if(GetIntFromConfig(KAuthSafeSec,KExpectedResult,iExpectedResult)==EFalse) |
|
337 { |
|
338 INFO_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
339 } |
|
340 //verify positive or negative test |
|
341 if(!VerifyExpectedError(KAuthSafeSec())) |
|
342 { |
|
343 INFO_PRINTF1(_L("Content Info Failure")); |
|
344 SetTestStepResult(EFail); |
|
345 flagReturn = EFalse; |
|
346 } |
|
347 else if(!iUnitTestContinueFlag) |
|
348 { |
|
349 return flagReturn; |
|
350 } |
|
351 for(TInt i=1;i<=contentInfoCount;i++) |
|
352 { |
|
353 TBuf<KContentInfoBufLen> contentBuf(KContentInfoKey); |
|
354 //Append the counter to the keyname |
|
355 contentBuf.AppendNum(i); |
|
356 if(!GetStringFromConfig(KAuthSafeSec,contentBuf,contentSection)) |
|
357 { |
|
358 ERR_PRINTF1(_L("ContentSection not available in the inifile")); |
|
359 SetTestStepResult(EFail); |
|
360 flagReturn=EFalse; |
|
361 break; |
|
362 } |
|
363 //retrieve the expected result:PositiveTest/NegativeTest |
|
364 if(GetIntFromConfig(contentSection,KExpectedResult,iExpectedResult)==EFalse) |
|
365 { |
|
366 INFO_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
367 iExpectedResult=KPositiveTest; |
|
368 } |
|
369 // Verify before calling array to access the data. |
|
370 if(!VerifyExpectedError(contentSection)) |
|
371 { |
|
372 INFO_PRINTF1(_L("Content Info Failure")); |
|
373 SetTestStepResult(EFail); |
|
374 flagReturn = EFalse; |
|
375 break; |
|
376 } |
|
377 else if(!iUnitTestContinueFlag) |
|
378 { |
|
379 flagReturn = ETrue; |
|
380 break; |
|
381 } |
|
382 //Call the function for checking the contentinfo,pass the contntsction as parameter |
|
383 iBagData=iParser->ArraySafeBagData()[contentIndex]; |
|
384 contentIndex++; |
|
385 //Check the contentinfo type |
|
386 iActualResult=ChkCIType(contentSection,*iBagData); |
|
387 } |
|
388 return flagReturn; |
|
389 } |
|
390 /** |
|
391 Function is intended to parse the BagData section of the ini file |
|
392 @param-aTotalsafebags:total number of safebags |
|
393 @param-aTotalbags:total number of bags including the safecontentbags |
|
394 @internalTechnology: |
|
395 @return:returns EFalse if there is a failure else return ETrue |
|
396 @test: |
|
397 @leave: if leave occurs at the ChkBagValL function |
|
398 */ |
|
399 TBool CPKCS12LibTestStep::ChkBagDataL(TInt aTotalsafebags,TInt aTotalbags) |
|
400 { |
|
401 TInt bagType=0; |
|
402 TInt safeContentIndex=0; |
|
403 TInt safeBagIndex=0; |
|
404 CSafeContentBag* safeContentBag; |
|
405 TBool flagReturn=ETrue; |
|
406 |
|
407 TInt totalSafeContentsBag = iParser->PfxHeader().SafecontentBagCount(); |
|
408 |
|
409 |
|
410 //loop for the totalbags |
|
411 for(TInt bags=0;bags<aTotalbags;bags++) |
|
412 { |
|
413 TBuf<KBagDataSecBufLen> bagSection(KBagDataSec); |
|
414 //Append the bags to the sectionname :BagData1 |
|
415 bagSection.AppendNum(bags+1); |
|
416 if(!GetIntFromConfig(bagSection,KBagType,bagType)) |
|
417 { |
|
418 ERR_PRINTF1(_L("Not able to get the BagType from the ini file")); |
|
419 flagReturn=EFalse; |
|
420 break; |
|
421 } |
|
422 if(bagType == CDecPkcs12SafeBag::ESafeContentsBag && flagReturn) |
|
423 { |
|
424 //loop for the safecontents bags |
|
425 while(safeContentIndex < totalSafeContentsBag && flagReturn) |
|
426 { |
|
427 safeContentBag=iParser->ArraySafeContentBag()[safeContentIndex]; |
|
428 if(!ChkSafeContsBagData(bagSection,*safeContentBag)) |
|
429 { |
|
430 ERR_PRINTF1(_L("SafeContent Bag Failed")); |
|
431 flagReturn=EFalse; |
|
432 } |
|
433 safeContentIndex++; |
|
434 break; |
|
435 } |
|
436 } |
|
437 else |
|
438 { |
|
439 while(safeBagIndex < aTotalsafebags && flagReturn) |
|
440 { |
|
441 //retrieve the safebag sructure pointer |
|
442 iBagData=iParser->ArraySafeBagData()[safeBagIndex]; |
|
443 //Chk the BagType |
|
444 if(!ChkBagType(bagSection,*iBagData,bagType)) |
|
445 { |
|
446 ERR_PRINTF1(_L("Bag Type does not match")); |
|
447 flagReturn=EFalse; |
|
448 break; |
|
449 } |
|
450 if(!iUnitTestContinueFlag) |
|
451 { |
|
452 break; |
|
453 } |
|
454 iBagAttrNumVal=0; |
|
455 if(!ChkBagAttbutesL(bagSection,*iBagData)) |
|
456 { |
|
457 ERR_PRINTF1(_L("Failure in Attributes")); |
|
458 flagReturn=EFalse; |
|
459 break; |
|
460 } |
|
461 switch(bagType) |
|
462 { |
|
463 case CDecPkcs12SafeBag::ECertBag: |
|
464 { |
|
465 //check the bagvalue |
|
466 if(!ChkBagValL(bagSection,*iBagData)) |
|
467 { |
|
468 flagReturn=EFalse; |
|
469 ERR_PRINTF1(_L("Certificate Bag Value comparison Failed")); |
|
470 } |
|
471 //check the certificate type |
|
472 if(flagReturn) |
|
473 { |
|
474 if(!ChkCertId(bagSection,*iBagData)) |
|
475 { |
|
476 flagReturn=EFalse; |
|
477 ERR_PRINTF1(_L("Certificate Bag certID comparison Failed")); |
|
478 } |
|
479 } |
|
480 break; |
|
481 } |
|
482 case CDecPkcs12SafeBag::EKeyBag: |
|
483 { |
|
484 if(!ChkBagValL(bagSection,*iBagData)) |
|
485 { |
|
486 flagReturn = EFalse; |
|
487 ERR_PRINTF1(_L("Key Bag Failed")); |
|
488 } |
|
489 break; |
|
490 } |
|
491 case CDecPkcs12SafeBag::EShroudedKeyBag: |
|
492 { |
|
493 if(!ChkEncodedBagValL(bagSection,*iBagData)) |
|
494 { |
|
495 flagReturn = EFalse; |
|
496 ERR_PRINTF1(_L("Shrouded Bag Failed")); |
|
497 } |
|
498 break; |
|
499 } |
|
500 case CDecPkcs12SafeBag::ECrlBag: |
|
501 { |
|
502 break; |
|
503 } |
|
504 case CDecPkcs12SafeBag::ESecretBag: |
|
505 { |
|
506 break; |
|
507 } |
|
508 } |
|
509 if(flagReturn) |
|
510 { |
|
511 safeBagIndex++; |
|
512 break; |
|
513 } |
|
514 } |
|
515 } |
|
516 } |
|
517 |
|
518 return flagReturn; |
|
519 } |
|
520 /** |
|
521 Function is intended to check the safecontents bag |
|
522 @param-aSec:BagData Section |
|
523 @param-aSfContBag:safecontent class pointer |
|
524 @internalTechnology: |
|
525 @return:returns EFalse if there is a failure else return ETrue |
|
526 @test: |
|
527 */ |
|
528 TBool CPKCS12LibTestStep::ChkSafeContsBagData(TDesC& aSec,CSafeContentBag &aSfContBag) |
|
529 { |
|
530 TInt safeContentsCount=0; |
|
531 TBool flagReturn=ETrue; |
|
532 //retrieve the safecontentsbag count from ini file |
|
533 if(!GetIntFromConfig(aSec,KSafeBagsCount,safeContentsCount)) |
|
534 { |
|
535 ERR_PRINTF1(_L("SafeContent Bags count not found in INI file")); |
|
536 SetTestStepResult(EFail); |
|
537 flagReturn=EFalse; |
|
538 } |
|
539 //compare the data with the ini file data |
|
540 if(safeContentsCount != aSfContBag.SafeBagCount() && flagReturn) |
|
541 { |
|
542 ERR_PRINTF1(_L("Number of Bags in the safecontent bag is different")); |
|
543 iActualResult=EFalse; |
|
544 } |
|
545 //retrieve the expected result:PositiveTest/NegativeTest |
|
546 if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult)) |
|
547 { |
|
548 INFO_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
549 iExpectedResult=KPositiveTest; |
|
550 } |
|
551 //check whether its a positive or a negative test |
|
552 if(flagReturn) |
|
553 { |
|
554 //check whether its a positive or a negative test |
|
555 if(!VerifyExpectedError(aSec)) |
|
556 { |
|
557 INFO_PRINTF1(_L("SafeContentsBag Failed")); |
|
558 SetTestStepResult(EFail); |
|
559 flagReturn = EFalse; |
|
560 } |
|
561 } |
|
562 return flagReturn; |
|
563 } |
|
564 /** |
|
565 Function is intended to check the content info type |
|
566 @param-aSecName:BagData Section |
|
567 @param-aBagData:safebag class pointer |
|
568 @internalTechnology: |
|
569 @return:returns EFalse if there is a failure else return ETrue |
|
570 @test: |
|
571 */ |
|
572 TBool CPKCS12LibTestStep::ChkCIType(TDesC &aSecName,CSafeBagData &aBagData) |
|
573 { |
|
574 TInt contentType=0; |
|
575 TBool flagReturn=ETrue; |
|
576 //retrieve the contentype from the ini file |
|
577 if(!GetIntFromConfig(aSecName,KContentInfoType,contentType)) |
|
578 { |
|
579 ERR_PRINTF1(_L("ContentInfoType value not found in INI file")); |
|
580 SetTestStepResult(EFail); |
|
581 flagReturn=EFalse; |
|
582 } |
|
583 //compare the contentype with the ini file data |
|
584 if(flagReturn) |
|
585 { |
|
586 if(aBagData.ContentInfoType() != contentType) |
|
587 { |
|
588 iActualResult=EFalse; |
|
589 INFO_PRINTF1(_L("ContentType Comparison Failed")); |
|
590 } |
|
591 //retrieve the expected result:PositiveTest/NegativeTest |
|
592 if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult)) |
|
593 { |
|
594 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
595 iExpectedResult=KPositiveTest; |
|
596 } |
|
597 //check whether its a positive or a negative test |
|
598 if(!VerifyExpectedError(aSecName)) |
|
599 { |
|
600 INFO_PRINTF1(_L("ContentInfo Failed")); |
|
601 SetTestStepResult(EFail); |
|
602 flagReturn = EFalse; |
|
603 } |
|
604 } |
|
605 return flagReturn; |
|
606 } |
|
607 /** |
|
608 Function is intended to check the bag type |
|
609 @param-aSec:BagData Section |
|
610 @param-aBgDta:safebag class pointer |
|
611 @param-aId:Bag ID |
|
612 @internalTechnology: |
|
613 @return:returns EFalse if there is a failure else return ETrue |
|
614 @test: |
|
615 */ |
|
616 TBool CPKCS12LibTestStep::ChkBagType(TDesC &aSec,CSafeBagData &aBagData,TInt aId) |
|
617 { |
|
618 TBool flagReturn=ETrue; |
|
619 |
|
620 //check for the bagid |
|
621 if(aId != aBagData.BagType()) |
|
622 { |
|
623 iActualResult=EFalse; |
|
624 INFO_PRINTF1(_L("BagType Comparision Failed")); |
|
625 } |
|
626 |
|
627 //retrieve the expected result:PositiveTest/NegativeTest |
|
628 if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult)) |
|
629 { |
|
630 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
631 iExpectedResult=KPositiveTest; |
|
632 } |
|
633 |
|
634 //check whether its a positive or a negative test |
|
635 if(!VerifyExpectedError(aSec)) |
|
636 { |
|
637 INFO_PRINTF1(_L("BagType Failed")); |
|
638 SetTestStepResult(EFail); |
|
639 flagReturn = EFalse; |
|
640 } |
|
641 return flagReturn; |
|
642 } |
|
643 /** |
|
644 Function is intended to check the bag attributes |
|
645 @param-aSec:BagData Section |
|
646 @param-aBagData:safebag class pointer |
|
647 @internalTechnology: |
|
648 @return:returns EFalse if there is a failure else return ETrue |
|
649 @test: |
|
650 */ |
|
651 TBool CPKCS12LibTestStep::ChkBagAttbutesL(TDesC &aSec,CSafeBagData &aBagData) |
|
652 { |
|
653 TInt numAttr=0; |
|
654 TInt count=0; |
|
655 TPtrC attrSec(KNullDesC); |
|
656 TBool flagReturn=ETrue; |
|
657 |
|
658 //retrieve the number of attributes |
|
659 if(!GetIntFromConfig(aSec,KBagAttributesNum,numAttr)) |
|
660 { |
|
661 WARN_PRINTF1(_L("Number of attributes not found in INI file")); |
|
662 } |
|
663 |
|
664 for(TInt attrindex=0;attrindex < numAttr;attrindex++) |
|
665 { |
|
666 TBuf<KAttributeBufLen> attrBuf(KBagAttributesKey); |
|
667 //increment the attr counter |
|
668 count++; |
|
669 //appending to get the attr key from the ini file |
|
670 attrBuf.AppendNum(count); |
|
671 |
|
672 if(!GetStringFromConfig(aSec,attrBuf,attrSec)) |
|
673 { |
|
674 ERR_PRINTF1(_L("Number of attributes not found in INI file")); |
|
675 SetTestStepResult(EFail); |
|
676 flagReturn=EFalse; |
|
677 break; |
|
678 } |
|
679 //retrieve the expected result:PositiveTest/NegativeTest |
|
680 if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult)) |
|
681 { |
|
682 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
683 iExpectedResult=KPositiveTest; |
|
684 } |
|
685 //check whether its a positive or a negative test |
|
686 if(!VerifyExpectedError(aSec)) |
|
687 { |
|
688 INFO_PRINTF1(_L("BagAttributes Failed")); |
|
689 SetTestStepResult(EFail); |
|
690 flagReturn = EFalse; |
|
691 } |
|
692 else if(!iUnitTestContinueFlag) |
|
693 { |
|
694 flagReturn = ETrue; |
|
695 break; |
|
696 } |
|
697 //retrieve the expected result:PositiveTest/NegativeTest |
|
698 if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult)) |
|
699 { |
|
700 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
701 iExpectedResult=KPositiveTest; |
|
702 } |
|
703 //check whether its a positive or a negative test |
|
704 if(!VerifyExpectedError(aSec)) |
|
705 { |
|
706 INFO_PRINTF1(_L("BagAttributes Failed")); |
|
707 SetTestStepResult(EFail); |
|
708 flagReturn = EFalse; |
|
709 } |
|
710 else if(!iUnitTestContinueFlag) |
|
711 { |
|
712 flagReturn = ETrue; |
|
713 break; |
|
714 } |
|
715 //Check the BagAttribute section |
|
716 if(!ChkAtrSecL(attrSec,aBagData,attrindex)) |
|
717 { |
|
718 ERR_PRINTF1(_L("Attributes comparison failed")); |
|
719 flagReturn=EFalse; |
|
720 break; |
|
721 } |
|
722 } |
|
723 return flagReturn; |
|
724 } |
|
725 /** |
|
726 Function is intended to check the attribute section |
|
727 @param-aSec:BagData Section |
|
728 @param-aBgDta:safebag class pointer |
|
729 @param-aIndx:attribute index |
|
730 @param-aAttrindex:attribute index |
|
731 @internalTechnology: |
|
732 @return:returns EFalse if there is a failure else return ETrue |
|
733 @test: |
|
734 @leave: if leave occurs if ChkAtrValL fails |
|
735 */ |
|
736 TBool CPKCS12LibTestStep::ChkAtrSecL(TDesC &aSec,CSafeBagData &aBagData,TInt aIndex) |
|
737 { |
|
738 TPtrC attrId(KNullDesC); |
|
739 TInt numVal=0; |
|
740 CSafeBagAttribute *bagAttr; |
|
741 TPtrC friendlyName(KFriendlyNameOid); |
|
742 TPtrC localKey(KLocalKeyOid); |
|
743 TBool flagReturn=ETrue; |
|
744 |
|
745 //retrieve the attribute id |
|
746 if(!GetStringFromConfig(aSec,KBagAttributesID,attrId)) |
|
747 { |
|
748 ERR_PRINTF1(_L("attribute id not found in INI file")); |
|
749 SetTestStepResult(EFail); |
|
750 flagReturn=EFalse; |
|
751 } |
|
752 if(flagReturn) |
|
753 { |
|
754 //retrieve the number of values |
|
755 if(!GetIntFromConfig(aSec,KBagAttributeValuesNum,numVal)) |
|
756 { |
|
757 ERR_PRINTF1(_L("total number of attribute values not found in INI file")); |
|
758 SetTestStepResult(EFail); |
|
759 flagReturn=EFalse; |
|
760 } |
|
761 } |
|
762 if(flagReturn) |
|
763 { |
|
764 bagAttr = aBagData.iAttributeIDs[aIndex]; |
|
765 |
|
766 //increment the Number of BagAttrValues |
|
767 iBagAttrNumVal+=numVal; |
|
768 |
|
769 //compare the attrval count and the attrid |
|
770 if((bagAttr->AttributeValueCount()!=numVal) || |
|
771 (attrId.CompareF((bagAttr->AttributeId()))!=0)) |
|
772 { |
|
773 iActualResult=EFalse; |
|
774 } |
|
775 else if((friendlyName.CompareF((bagAttr->AttributeId()))==0) || |
|
776 (localKey.CompareF((bagAttr->AttributeId()))==0)) |
|
777 { |
|
778 //Check for BagAttribute values |
|
779 if(!ChkAtrValL(aSec,aBagData,numVal)) |
|
780 { |
|
781 iActualResult=EFalse; |
|
782 } |
|
783 } |
|
784 //retrieve the expected result:PositiveTest/NegativeTest |
|
785 if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult)) |
|
786 { |
|
787 WARN_PRINTF1(_L("ExpectedResult not found in INI file")); |
|
788 iExpectedResult=KPositiveTest; |
|
789 } |
|
790 //check for positive or negative test |
|
791 if(!VerifyExpectedError(aSec)) |
|
792 { |
|
793 INFO_PRINTF1(_L("Attributes Comparison Test Case failed")); |
|
794 SetTestStepResult(EFail); |
|
795 flagReturn = EFalse; |
|
796 } |
|
797 |
|
798 } |
|
799 //retrieve the bag attribute structure pointer |
|
800 return flagReturn; |
|
801 } |
|
802 /** |
|
803 Function is intended to check the attribute values |
|
804 @param-aSec:BagData Section |
|
805 @param-aBgDta:safebag class pointer |
|
806 @param-aNum:Bagattribute value count |
|
807 @param-aAtr:Bagattribute ID |
|
808 @param-aNumVal:Bagattribute value count |
|
809 @internalTechnology: |
|
810 @return:returns EFalse if there is a failure else return ETrue |
|
811 @test: |
|
812 @leave: if memory allocation of buffer fails |
|
813 */ |
|
814 TBool CPKCS12LibTestStep::ChkAtrValL(TDesC &aSec,CSafeBagData &aBagData,TInt aNum) |
|
815 { |
|
816 TInt start=iBagAttrNumVal - aNum; |
|
817 TInt end=iBagAttrNumVal + aNum; |
|
818 |
|
819 TBool flagReturn=ETrue; |
|
820 TInt index=0; |
|
821 TPtrC value(KNullDesC); |
|
822 |
|
823 HBufC8 *bufferVal; |
|
824 |
|
825 //loop till the total number of values |
|
826 do |
|
827 { |
|
828 TBuf<KBagValBufLen> bagVal(KBagAttributeValue); |
|
829 //increment the index to append the count |
|
830 index++; |
|
831 //append the value |
|
832 bagVal.AppendNum(index); |
|
833 //retrieve the value from the ini file |
|
834 if(!GetStringFromConfig(aSec,bagVal,value)) |
|
835 { |
|
836 ERR_PRINTF1(_L("Bag Value not found in the ini file")); |
|
837 SetTestStepResult(EFail); |
|
838 flagReturn=EFalse; |
|
839 break; |
|
840 } |
|
841 for(TInt startIndex=start;startIndex<end;startIndex++) |
|
842 { |
|
843 bufferVal=aBagData.iAttributeValues[startIndex]; |
|
844 |
|
845 //check the local key value |
|
846 if(!CompareFileDataL(value,*bufferVal)) |
|
847 { |
|
848 ERR_PRINTF1(_L("Bag Attribute Value comparison failed")); |
|
849 iActualResult=EFalse; |
|
850 break; |
|
851 } |
|
852 else |
|
853 { |
|
854 iActualResult=ETrue; |
|
855 break; |
|
856 } |
|
857 } |
|
858 //retrieve the expected result:PositiveTest/NegativeTest |
|
859 if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult)) |
|
860 { |
|
861 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
862 iExpectedResult=KPositiveTest; |
|
863 } |
|
864 //check for positive or negative test |
|
865 if(!VerifyExpectedError(aSec)) |
|
866 { |
|
867 INFO_PRINTF1(_L("Bag Value Test failed")); |
|
868 SetTestStepResult(EFail); |
|
869 flagReturn = EFalse; |
|
870 break; |
|
871 } |
|
872 else if(!iUnitTestContinueFlag) |
|
873 { |
|
874 break; |
|
875 } |
|
876 }while(index<aNum); |
|
877 return flagReturn; |
|
878 } |
|
879 /** |
|
880 Function is intended to check the value. |
|
881 @param-aPValue:filepath containing the path of the file |
|
882 retrieved from the ini file |
|
883 @param-aBufferVal:Value retrieved after parsing the pkcs12 file |
|
884 @internalTechnology: |
|
885 @return:returns EFalse if there is a failure else return ETrue |
|
886 @test: |
|
887 @leave: if leave occurs if openfile fails or allocation to buffer fails |
|
888 */ |
|
889 TBool CPKCS12LibTestStep::CompareFileDataL(TDesC &aPValue,TDesC8 &aBufferVal) |
|
890 { |
|
891 RFile file; |
|
892 TInt fileSize=0; |
|
893 TBool flagReturn=ETrue; |
|
894 // Negative Test: If mac/ macSalt is not present. |
|
895 if (&aBufferVal) |
|
896 { |
|
897 //open the file |
|
898 User::LeaveIfError(file.Open(iFileSession,aPValue,EFileRead)); |
|
899 User::LeaveIfError(file.Size(fileSize)); |
|
900 //raw data for reading the bagvalue |
|
901 HBufC8 *rawData=HBufC8::NewMaxLC(fileSize); |
|
902 //converting the HBufC8 to TPtr8 |
|
903 TPtr8 data(rawData->Des()); |
|
904 //read the contents of the file |
|
905 User::LeaveIfError(file.Read(data)); |
|
906 //compare the value |
|
907 if(rawData->CompareF(aBufferVal)!=0) |
|
908 { |
|
909 ERR_PRINTF1(_L("comparison failed")); |
|
910 flagReturn=EFalse; |
|
911 } |
|
912 //closes the data file |
|
913 file.Close(); |
|
914 |
|
915 CleanupStack::PopAndDestroy(rawData); |
|
916 } |
|
917 return flagReturn; |
|
918 } |
|
919 /** |
|
920 Function is intended to check the algorithm id |
|
921 @param-aSecName:BagData Section |
|
922 @param-aBagData:safebagdata class pointer |
|
923 @internalTechnology: |
|
924 @return:returns EFalse if there is a failure else return ETrue |
|
925 @test: |
|
926 */ |
|
927 TBool CPKCS12LibTestStep::ChkAlgId(TDesC &aSecName,CSafeBagData &aBagData) |
|
928 { |
|
929 TPtrC algorithm(KNullDesC); |
|
930 TBool flagReturn=ETrue; |
|
931 //retrieve the algorithm section name |
|
932 if(!GetStringFromConfig(aSecName,_L("Algorithm"),algorithm)) |
|
933 { |
|
934 ERR_PRINTF1(_L("AlgorithmID value not found in INI file")); |
|
935 SetTestStepResult(EFail); |
|
936 flagReturn=EFalse; |
|
937 } |
|
938 if(flagReturn) |
|
939 { |
|
940 if(algorithm.CompareF((aBagData.AlgorithmId()))!=0) |
|
941 { |
|
942 iActualResult=EFalse; |
|
943 } |
|
944 //retrieve the expected result:PositiveTest/NegativeTest |
|
945 if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult)) |
|
946 { |
|
947 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
948 iExpectedResult=KPositiveTest; |
|
949 } |
|
950 //check for positive oor negative test |
|
951 if(!VerifyExpectedError(aSecName)) |
|
952 { |
|
953 INFO_PRINTF1(_L("Algorithm Comparison Test Case failed")); |
|
954 SetTestStepResult(EFail); |
|
955 flagReturn = EFalse; |
|
956 } |
|
957 } |
|
958 return flagReturn; |
|
959 } |
|
960 /** |
|
961 Function is intended to check the certificate type |
|
962 @param-aSecName:BagData Section |
|
963 @param-aBagData:safebagdata class pointer |
|
964 @internalTechnology: |
|
965 @return:returns EFalse if there is a failure else return ETrue |
|
966 @test: |
|
967 */ |
|
968 TBool CPKCS12LibTestStep::ChkCertId(TDesC &aSecName,CSafeBagData &aBagData) |
|
969 { |
|
970 TPtrC certid(KNullDesC); |
|
971 TBool flagReturn=ETrue; |
|
972 //retrieve the cert name from ini file |
|
973 if(!GetStringFromConfig(aSecName,KCertType,certid)) |
|
974 { |
|
975 ERR_PRINTF1(_L("certificateID value not found in INI file")); |
|
976 SetTestStepResult(EFail); |
|
977 flagReturn= EFalse; |
|
978 } |
|
979 if(flagReturn) |
|
980 { |
|
981 if(certid.CompareF((aBagData.CertificateId()))!=0) |
|
982 { |
|
983 INFO_PRINTF1(_L("certificateID comparision Failed")); |
|
984 iActualResult=EFalse; |
|
985 } |
|
986 //retrieve the expected result:PositiveTest/NegativeTest |
|
987 if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult)) |
|
988 { |
|
989 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
990 iExpectedResult=KPositiveTest; |
|
991 } |
|
992 //check for positive or negative test |
|
993 if(!VerifyExpectedError(aSecName)) |
|
994 { |
|
995 INFO_PRINTF1(_L("Certificate Comparison Test Case failed")); |
|
996 SetTestStepResult(EFail); |
|
997 flagReturn = EFalse; |
|
998 } |
|
999 } |
|
1000 return flagReturn; |
|
1001 } |
|
1002 /** |
|
1003 Function is intended to check for the bag value |
|
1004 @param-aSecName:BagData Section |
|
1005 @param-aBagData:safebag class pointer |
|
1006 @internalTechnology: |
|
1007 @return:returns EFalse if there is a failure else return ETrue |
|
1008 @test: |
|
1009 */ |
|
1010 TBool CPKCS12LibTestStep::ChkBagValL(TDesC &aSecName,CSafeBagData &aBagData) |
|
1011 { |
|
1012 TPtrC certBagPath(KNullDesC); |
|
1013 TBool flagReturn=ETrue; |
|
1014 |
|
1015 //retrieve the certificate bag value |
|
1016 if(!GetStringFromConfig(aSecName,KBagValue,certBagPath)) |
|
1017 { |
|
1018 ERR_PRINTF1(_L("Not able to get the CertBagValue from the ini file")); |
|
1019 SetTestStepResult(EFail); |
|
1020 flagReturn=EFalse; |
|
1021 } |
|
1022 TInt fileReturn=0; |
|
1023 RFile file; |
|
1024 |
|
1025 if(flagReturn) |
|
1026 { |
|
1027 fileReturn=file.Open(iFileSession,certBagPath,EFileRead); |
|
1028 |
|
1029 if(fileReturn) |
|
1030 { |
|
1031 ERR_PRINTF1(_L("CertBagValue:Not able to open the file")); |
|
1032 SetTestStepResult(EFail); |
|
1033 flagReturn=EFalse; |
|
1034 } |
|
1035 } |
|
1036 //raw data for reading the bagvalue |
|
1037 HBufC8 *rawData=NULL; |
|
1038 TInt filesize=0; |
|
1039 if(flagReturn) |
|
1040 { |
|
1041 User::LeaveIfError(file.Size(filesize)); |
|
1042 rawData=HBufC8::NewMaxLC(filesize); |
|
1043 TPtr8 data(rawData->Des()); |
|
1044 if(file.Read(data)) |
|
1045 { |
|
1046 ERR_PRINTF1(_L("CertBagValue:Not able to Read the file")); |
|
1047 SetTestStepResult(EFail); |
|
1048 flagReturn=EFalse; |
|
1049 } |
|
1050 } |
|
1051 if(flagReturn) |
|
1052 { |
|
1053 //compare the data |
|
1054 if(rawData->CompareF(aBagData.BagValue())!=0) |
|
1055 { |
|
1056 iActualResult=EFalse; |
|
1057 } |
|
1058 //retrieve the expected result:PositiveTest/NegativeTest |
|
1059 if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult)) |
|
1060 { |
|
1061 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
1062 iExpectedResult=KPositiveTest; |
|
1063 } |
|
1064 //check for positive or negative test |
|
1065 if(!VerifyExpectedError(aSecName)) |
|
1066 { |
|
1067 INFO_PRINTF1(_L("BagValue Failed")); |
|
1068 SetTestStepResult(EFail); |
|
1069 flagReturn = EFalse; |
|
1070 } |
|
1071 } |
|
1072 if(rawData!=NULL) |
|
1073 { |
|
1074 CleanupStack::PopAndDestroy(rawData); |
|
1075 } |
|
1076 if(!fileReturn) |
|
1077 { |
|
1078 file.Close(); |
|
1079 } |
|
1080 return flagReturn; |
|
1081 } |
|
1082 /** |
|
1083 Function is intended to check for the mac value |
|
1084 @internalTechnology: |
|
1085 @return:returns EFalse if there is a failure else return ETrue |
|
1086 @test: |
|
1087 @leave: if leave occurs at the CompareFileDataL function |
|
1088 */ |
|
1089 TBool CPKCS12LibTestStep::ChkMacValueL() |
|
1090 { |
|
1091 TPtrC mac(KNullDesC); |
|
1092 TPtrC macSalt(KNullDesC); |
|
1093 TPtrC secName(_S("MacData")); |
|
1094 TPtrC expectedError(KNullDesC); |
|
1095 TInt itCount=0; |
|
1096 TBool flagReturn=ETrue; |
|
1097 |
|
1098 //retrieve the macid,macsalt and iteration count |
|
1099 if((!GetStringFromConfig(secName,KMac,mac)) || |
|
1100 (!GetStringFromConfig(secName,KMacSalt,macSalt)) || |
|
1101 (!GetIntFromConfig(secName,KIterationCount,itCount))) |
|
1102 { |
|
1103 ERR_PRINTF1(_L("Not able to access the mac values from ini file")); |
|
1104 SetTestStepResult(EFail); |
|
1105 flagReturn=EFalse; |
|
1106 } |
|
1107 //comapre the data with the ini file |
|
1108 if((CompareFileDataL(mac,iParser->PfxHeader().MacId()) ==0)|| |
|
1109 (CompareFileDataL(macSalt,iParser->PfxHeader().MacSalt()) == 0)|| |
|
1110 (itCount!=iParser->PfxHeader().IterationCount())) |
|
1111 { |
|
1112 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
1113 flagReturn=EFalse; |
|
1114 } |
|
1115 //retrieve the expected result:PositiveTest/NegativeTest |
|
1116 if(!GetBoolFromConfig(secName,KExpectedResult,iExpectedResult)) |
|
1117 { |
|
1118 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
1119 iExpectedResult=KPositiveTest; |
|
1120 } |
|
1121 if(!VerifyExpectedError(secName)) |
|
1122 { |
|
1123 SetTestStepResult(EFail); |
|
1124 flagReturn = EFalse; |
|
1125 } |
|
1126 return flagReturn; |
|
1127 } |
|
1128 |
|
1129 CTPKCS12OOMStep::CTPKCS12OOMStep() |
|
1130 { |
|
1131 |
|
1132 } |
|
1133 CTPKCS12OOMStep::~CTPKCS12OOMStep() |
|
1134 { |
|
1135 delete iRawData; |
|
1136 delete iAuthSafeData; |
|
1137 iFs.Close(); |
|
1138 } |
|
1139 /** |
|
1140 Function is intended to do the OOM test. |
|
1141 @internalTechnology: |
|
1142 @return:TVerdict -returns EFail if there is a failure else EPass |
|
1143 @leave:- if memory allocation fails |
|
1144 @test |
|
1145 */ |
|
1146 TVerdict CTPKCS12OOMStep::doTestStepL() |
|
1147 { |
|
1148 TInt OOMTest; |
|
1149 GetIntFromConfig(ConfigSection(),_L("OOMTest"),OOMTest); |
|
1150 |
|
1151 __UHEAP_MARK; |
|
1152 |
|
1153 switch(OOMTest) |
|
1154 { |
|
1155 case 1: |
|
1156 { |
|
1157 CDecPkcs12* theTest = NULL; |
|
1158 theTest = CDecPkcs12::NewL(iRawData->Des()); |
|
1159 delete theTest; |
|
1160 } |
|
1161 break; |
|
1162 // File Stream |
|
1163 case 2: |
|
1164 { |
|
1165 TPtrC fileName; |
|
1166 GetStringFromConfig(ConfigSection(), _L("File"), fileName); |
|
1167 |
|
1168 RFile file; |
|
1169 User::LeaveIfError(file.Open(iFs, fileName, EFileRead) ); |
|
1170 |
|
1171 TInt size; |
|
1172 file.Size(size); |
|
1173 file.Close(); |
|
1174 |
|
1175 HBufC8* res = HBufC8::NewLC(size); |
|
1176 TPtr8 p(res->Des()); |
|
1177 p.SetLength(size); |
|
1178 |
|
1179 RFileReadStream stream; |
|
1180 User::LeaveIfError(stream.Open(iFs, fileName, EFileStream)); |
|
1181 CleanupClosePushL(stream); |
|
1182 |
|
1183 stream.ReadL(p, size); |
|
1184 |
|
1185 CDecPkcs12* theTest = NULL; |
|
1186 theTest = CDecPkcs12::NewL(stream); |
|
1187 delete theTest; |
|
1188 CleanupStack::PopAndDestroy(2,res); // stream |
|
1189 } |
|
1190 break; |
|
1191 // MacData |
|
1192 case 3: |
|
1193 { |
|
1194 CDecPkcs12MacData* theTest = NULL; |
|
1195 theTest = CDecPkcs12MacData::NewL(iRawData->Des(),iAuthSafeData->Des()); |
|
1196 delete theTest; |
|
1197 } |
|
1198 break; |
|
1199 // Attribute |
|
1200 case 4: |
|
1201 { |
|
1202 CDecPkcs12Attribute* theTest = NULL; |
|
1203 theTest = CDecPkcs12Attribute::NewL(iRawData->Des()); |
|
1204 delete theTest; |
|
1205 } |
|
1206 break; |
|
1207 // ShroudedBag |
|
1208 case 5: |
|
1209 { |
|
1210 CDecPkcs12ShroudedKeyBag* theTest = NULL; |
|
1211 theTest = CDecPkcs12ShroudedKeyBag::NewL(iRawData->Des()); |
|
1212 delete theTest; |
|
1213 } |
|
1214 break; |
|
1215 // CertBag |
|
1216 case 6: |
|
1217 { |
|
1218 CDecPkcs12CertBag* theTest = NULL; |
|
1219 theTest = CDecPkcs12CertBag::NewL(iRawData->Des()); |
|
1220 delete theTest; |
|
1221 } |
|
1222 break; |
|
1223 // KeyBag |
|
1224 case 7: |
|
1225 { |
|
1226 CDecPkcs12KeyBag* theTest = NULL; |
|
1227 theTest = CDecPkcs12KeyBag::NewL(iRawData->Des()); |
|
1228 delete theTest; |
|
1229 } |
|
1230 break; |
|
1231 // SafeContentsBag |
|
1232 case 8: |
|
1233 { |
|
1234 CDecPkcs12SafeContentsBag* theTest = NULL; |
|
1235 theTest = CDecPkcs12SafeContentsBag::NewL(iRawData->Des()); |
|
1236 delete theTest; |
|
1237 } |
|
1238 break; |
|
1239 // Safebag/CRL bag |
|
1240 case 9: |
|
1241 { |
|
1242 CDecPkcs12SafeBag* theTest = NULL; |
|
1243 theTest = CDecPkcs12SafeBag::NewL(iRawData->Des()); |
|
1244 delete theTest; |
|
1245 } |
|
1246 break; |
|
1247 // SafeContentsData / SafeContentsEncryptedData |
|
1248 case 10: |
|
1249 { |
|
1250 CDecPkcs12* p12 = NULL; |
|
1251 p12 = CDecPkcs12::NewL(iRawData->Des()); |
|
1252 CleanupStack::PushL(p12); |
|
1253 |
|
1254 const RPointerArray<CPKCS7ContentInfo>& contentInfos = p12->AuthenticatedSafeContents(); |
|
1255 |
|
1256 TInt contentInfoCount = contentInfos.Count(); |
|
1257 for ( TInt index = 0; index < contentInfoCount; index++ ) |
|
1258 { |
|
1259 TInt contentType = contentInfos[index]->ContentType(); |
|
1260 CDecPkcs12SafeContents* pkcs12SafeContents ; |
|
1261 TInt contentTypeData; |
|
1262 GetIntFromConfig(ConfigSection(),_L("ContentTypeData"),contentTypeData); |
|
1263 |
|
1264 TInt contentTypeEncryptedData; |
|
1265 GetIntFromConfig(ConfigSection(),_L("ContentTypeEncryptedData"),contentTypeEncryptedData); |
|
1266 |
|
1267 if ( contentType == contentTypeEncryptedData ) |
|
1268 { |
|
1269 TPtrC expectedPassword(KNullDesC()); |
|
1270 GetStringFromConfig(ConfigSection(), _L("Password"), expectedPassword); |
|
1271 pkcs12SafeContents = CDecPkcs12SafeContents::NewL(*contentInfos[index],expectedPassword); |
|
1272 delete pkcs12SafeContents; |
|
1273 } |
|
1274 else if ( contentType == contentTypeData ) |
|
1275 { |
|
1276 pkcs12SafeContents = CDecPkcs12SafeContents::NewL(*contentInfos[index]); |
|
1277 delete pkcs12SafeContents; |
|
1278 } |
|
1279 } |
|
1280 CleanupStack::PopAndDestroy(p12); |
|
1281 break; |
|
1282 } |
|
1283 } |
|
1284 __UHEAP_MARKEND; |
|
1285 return TestStepResult(); |
|
1286 } |
|
1287 |
|
1288 /** |
|
1289 Function is intended to read the data from the specified path. |
|
1290 @param-aPValue:filepath containing the path of the file |
|
1291 retrieved from the ini file. |
|
1292 @internalTechnology: |
|
1293 @return:returns data retrieved after reading from the file. |
|
1294 @test: |
|
1295 */ |
|
1296 HBufC8* CTPKCS12OOMStep::ReadFileDataL(TPtrC tag) |
|
1297 { |
|
1298 TPtrC fileName; |
|
1299 if (!GetStringFromConfig(ConfigSection(), tag, fileName)) |
|
1300 { |
|
1301 return NULL; |
|
1302 } |
|
1303 |
|
1304 RFile file; |
|
1305 if (file.Open(iFs, fileName, EFileRead)) |
|
1306 { |
|
1307 INFO_PRINTF2(_L("Cannot open file %S for reading"), &fileName); |
|
1308 return NULL; |
|
1309 } |
|
1310 CleanupClosePushL(file); |
|
1311 |
|
1312 TInt fileSize = 0; |
|
1313 User::LeaveIfError(file.Size(fileSize)); |
|
1314 |
|
1315 HBufC8* result = HBufC8::NewL(fileSize); |
|
1316 result->Des().SetLength(fileSize); |
|
1317 |
|
1318 TPtr8 rawDataPtr(result->Des()); |
|
1319 rawDataPtr.SetLength(fileSize); |
|
1320 file.Read (rawDataPtr); |
|
1321 |
|
1322 CleanupStack::PopAndDestroy (&file); |
|
1323 |
|
1324 INFO_PRINTF3(_L("Read %d octets from %S"), result->Size(), &fileName); |
|
1325 |
|
1326 return result; |
|
1327 } |
|
1328 |
|
1329 TVerdict CTPKCS12OOMStep::doTestStepPreambleL() |
|
1330 { |
|
1331 User::LeaveIfError (iFs.Connect()); |
|
1332 |
|
1333 SetTestStepResult(EPass); |
|
1334 |
|
1335 iRawData = ReadFileDataL(_L("File")); |
|
1336 if (iRawData == NULL) |
|
1337 { |
|
1338 INFO_PRINTF1(_L("Failed to read 'File' section of script")); |
|
1339 SetTestStepResult(ETestSuiteError); |
|
1340 } |
|
1341 iAuthSafeData = ReadFileDataL(_L("AuthSafe")); |
|
1342 if (iAuthSafeData == NULL) |
|
1343 { |
|
1344 INFO_PRINTF1(_L("authsafedata file is not required")); |
|
1345 } |
|
1346 return TestStepResult(); |
|
1347 } |
|
1348 /** |
|
1349 Function is intended to check for the re encoded shrouded key |
|
1350 @param-aSecName:BagData Section |
|
1351 @param-aBagData:safebag class pointer |
|
1352 @internalTechnology: |
|
1353 @return:returns EFalse if there is a failure else return ETrue |
|
1354 @test: |
|
1355 */ |
|
1356 TBool CPKCS12LibTestStep::ChkEncodedBagValL(TDesC &aSecName,CSafeBagData &aBagData) |
|
1357 { |
|
1358 TPtrC bagPath(KNullDesC); |
|
1359 TBool flagReturn=ETrue; |
|
1360 |
|
1361 //retrieve the shrouded bag value |
|
1362 if(!GetStringFromConfig(aSecName,KEncBagValue,bagPath)) |
|
1363 { |
|
1364 ERR_PRINTF1(_L("Not able to get the EncBagValue from the ini file")); |
|
1365 SetTestStepResult(EFail); |
|
1366 flagReturn=EFalse; |
|
1367 } |
|
1368 TInt fileReturn=0; |
|
1369 RFile file; |
|
1370 |
|
1371 if(flagReturn) |
|
1372 { |
|
1373 fileReturn=file.Open(iFileSession,bagPath,EFileRead); |
|
1374 |
|
1375 if(fileReturn) |
|
1376 { |
|
1377 ERR_PRINTF1(_L("BagValue:Not able to open the file")); |
|
1378 SetTestStepResult(EFail); |
|
1379 flagReturn=EFalse; |
|
1380 } |
|
1381 } |
|
1382 CleanupClosePushL(file); |
|
1383 //raw data for reading the bagvalue |
|
1384 HBufC8 *rawData=NULL; |
|
1385 TInt filesize=0; |
|
1386 if(flagReturn) |
|
1387 { |
|
1388 User::LeaveIfError(file.Size(filesize)); |
|
1389 rawData=HBufC8::NewMaxLC(filesize); |
|
1390 TPtr8 data(rawData->Des()); |
|
1391 if(file.Read(data)) |
|
1392 { |
|
1393 ERR_PRINTF1(_L("BagValue:Not able to Read the file")); |
|
1394 SetTestStepResult(EFail); |
|
1395 flagReturn=EFalse; |
|
1396 } |
|
1397 } |
|
1398 if(flagReturn) |
|
1399 { |
|
1400 //compare the data |
|
1401 if(rawData->CompareC(aBagData.EncodedShroudedKey())!=0) |
|
1402 { |
|
1403 iActualResult=EFalse; |
|
1404 } |
|
1405 //retrieve the expected result:PositiveTest/NegativeTest |
|
1406 if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult)) |
|
1407 { |
|
1408 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest")); |
|
1409 iExpectedResult=KPositiveTest; |
|
1410 } |
|
1411 //check for positive or negative test |
|
1412 if(!VerifyExpectedError(aSecName)) |
|
1413 { |
|
1414 INFO_PRINTF1(_L("BagValue Failed")); |
|
1415 SetTestStepResult(EFail); |
|
1416 flagReturn = EFalse; |
|
1417 } |
|
1418 } |
|
1419 if(rawData!=NULL) |
|
1420 { |
|
1421 CleanupStack::PopAndDestroy(rawData); |
|
1422 } |
|
1423 if(!fileReturn) |
|
1424 { |
|
1425 file.Close(); |
|
1426 } |
|
1427 CleanupStack::PopAndDestroy(&file); |
|
1428 return flagReturn; |
|
1429 } |