os/security/cryptoservices/certificateandkeymgmt/tpkcs12intgrtn/src/tpkcs12libteststep.cpp
First public contribution.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * This file is used for the verification function of the pkcs12 file
26 #include <test/testexecutelog.h>
29 #include "tpkcs12libteststep.h"
30 #include "tpkcs12data.h"
31 #include "tpkcs12common.h"
33 using namespace PKCS12;
35 const TInt KBagDataLength = 7;
36 const TInt KContentInfoLength = 11;
38 Description:constructor:used for initialization of the variables declared
42 CPKCS12LibTestStep::CPKCS12LibTestStep()
46 iUnitTestContinueFlag = ETrue;
47 iExpectedError = ETrue;
48 iExpectedResult=KPositiveTest;
51 Description:Destructor
55 CPKCS12LibTestStep::~CPKCS12LibTestStep()
59 iPrivacyPassword.ResetAndDestroy();
63 Function is intended to parse the pkcs12 file, compare the results and
66 @return:TVerdict -returns EFail if there is a failure else EPass
68 @leave:- if memory allocation fails
70 TVerdict CPKCS12LibTestStep::doTestStepL()
73 TPtrC integrityMode(KNullDesC);
74 TPtrC integrityPassword(KNullDesC);
75 TPtrC privacyPassword(KNullDesC);
76 TPtrC dataPath(KNullDesC);
77 TBool flagReturn=ETrue;
80 if(iFileSession.Connect())
82 INFO_PRINTF1(_L("File server session failed"));
88 if((!GetStringFromConfig(KMainSec,KFilePath,dataPath)) ||
89 !GetStringFromConfig(KMainSec,KIntegrityMode,integrityMode))
91 SetTestStepResult(EAbort);
92 ERR_PRINTF1(_L("Input Data not found in ini file"));
99 if(!GetBoolFromConfig(KMainSec,KUnitTest,iUnitTest))
103 //Password Integrity Mode
104 if(integrityMode.CompareF(KPassword)==0)
106 if(!GetStringFromConfig(KMainSec,KIntegrityPassword,integrityPassword))
108 ERR_PRINTF1(_L("Problem in the Main section of the ini file"));
109 SetTestStepResult(EFail);
115 iParser = CPkcs12Parser::NewL();
116 // set the integrity password
117 iParser->SetIntegrityPasswordL(integrityPassword);
119 iParser->SetDataL(dataPath);
120 //set the privacy password
122 //parse the pkcs12 file
125 if(!GetBoolFromConfig(KMainSec,KIntegrityValid,iExpectedResult))
127 WARN_PRINTF1(_L("Integrity valid not found in ini file"));
128 iExpectedResult=KPositiveTest;
130 if(!VerifyMainSecL())
132 ERR_PRINTF1(_L("Main section failed"));
135 else if(!iUnitTestContinueFlag)
137 SetTestStepResult(EPass);
144 else if(integrityMode.CompareF(KPublicIntegrity)==0)
146 //public Integrity Mode
150 ERR_PRINTF1(_L("Integrity pwd not known in ini file"));
151 SetTestStepResult(EFail);
157 //Check the Authenticated safe section
158 if(!VerifyAuthSafe())
160 ERR_PRINTF1(_L("Authenticated safe section failed"));
161 SetTestStepResult(EFail);
164 else if(!iUnitTestContinueFlag )
166 SetTestStepResult(EPass);
174 //calculate the totalsafebags in the pkcs12 file
175 TInt totalsafebags = iParser->PfxHeader().TotalSafeBagCount();
177 //calculate the totalbags(including the safecontentsbag) in the pkcs12 file
178 TInt totalbags = totalsafebags + iParser->PfxHeader().SafecontentBagCount();
180 //Check the BagData section
181 if(!ChkBagDataL(totalsafebags,totalbags))
183 ERR_PRINTF1(_L("Bag Data section failed"));
184 SetTestStepResult(EFail);
187 else if(!iUnitTestContinueFlag)
196 SetTestStepResult(EPass);
200 return TestStepResult();
203 Function is intended to verify the expected error in each section of the ini file
205 @return:TBool:returns EFalse if there is a failure else ETrue
208 TBool CPKCS12LibTestStep::VerifyExpectedError(const TDesC& aSecName)
210 TBool flagReturn = ETrue;
213 if(GetIntFromConfig(aSecName,KExpectedError,iExpectedError)==EFalse)
215 INFO_PRINTF1(_L("ExpectedError not found in INI File"));
217 // Checks the error returned by the library with the expected error read
218 // from the INI file.
219 TInt actualError = 0;
221 if ( (!aSecName.Compare(KMainSec) || !aSecName.Compare(KAuthSafeSec) ||
222 !aSecName.Compare(_L("MacData")) || (!aSecName.Left(KBagDataLength).Compare(KBagDataSec)) ||
223 (!aSecName.Left(KContentInfoLength).CompareF(KContentInfoKey))) && !iExpectedResult )
225 actualError = iParser->PfxHeader().Pkcs12ActualError();
227 if (actualError == iExpectedError)
229 INFO_PRINTF1(_L("ExpectedError matchs"));
230 iUnitTestContinueFlag = EFalse;
231 iExpectedResult = ETrue;
235 if(iExpectedResult!=iActualResult)
237 SetTestStepResult(EFail);
240 iActualResult = ETrue;
244 Function is intended to set the privacy passwords of the contentinfotype
247 @leave: if leave occurs if memory allocation fails
249 void CPKCS12LibTestStep::ParsePrivacyPwdL()
251 TPtrC pass(KNullDesC);
252 //to append the number to get the actual key value
255 TBool privacyPwdPresent=EFalse;
257 //Put all the content info privacy passwords in an array
260 TBuf<KPrivacyPwdStrLen> privacyPwdBuf(KPrivacyPassword);
263 //appending the count to the Keyvalue
264 privacyPwdBuf.AppendNum(count);
265 privacyPwdPresent=GetStringFromConfig(KMainSec,privacyPwdBuf,pass);
266 if(privacyPwdPresent)
268 HBufC *temp=pass.AllocLC();
269 iPrivacyPassword.AppendL(temp);
270 CleanupStack::Pop(temp);
272 }while(privacyPwdPresent);
273 iParser->SetPrivacyPassword(iPrivacyPassword);
276 Function is intended to parse the main section of the ini file
278 @return:returns EFalse if there is a failure else ETrue
281 TBool CPKCS12LibTestStep::VerifyMainSecL()
284 TBool flagReturn=ETrue;
286 //retrieve the expected result:PositiveTest/NegativeTest
287 if(!GetBoolFromConfig(KMainSec,KExpectedResult,iExpectedResult))
289 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
290 iExpectedResult=KPositiveTest;
292 if(!GetBoolFromConfig(KMainSec,KMacPresent,mac))
294 WARN_PRINTF1(_L("Mac present not found in ini file"));
295 //default only integration test
298 else if(mac && iUnitTest)
300 //call the mac data function and check for all the macdata section values
301 iActualResult=ChkMacValueL();
302 if (!iUnitTestContinueFlag)
307 if(!VerifyExpectedError(KMainSec))
309 SetTestStepResult(EFail);
315 Function is intended to parse the AuthSafe section of the ini file
317 @return:returns EFalse if there is a failure else ETrue
320 TBool CPKCS12LibTestStep::VerifyAuthSafe()
322 TInt contentInfoCount=0;
323 TPtrC contentSection(KNullDesC);
325 TBool flagReturn=ETrue;
327 if(!GetIntFromConfig(KAuthSafeSec,KContentInfoNum,contentInfoCount))
329 ERR_PRINTF1(_L("Count not available in the inifile"));
330 SetTestStepResult(EFail);
333 //retrieve the expected result:PositiveTest/NegativeTest
334 if(GetIntFromConfig(KAuthSafeSec,KExpectedResult,iExpectedResult)==EFalse)
336 INFO_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
338 //verify positive or negative test
339 if(!VerifyExpectedError(KAuthSafeSec()))
341 INFO_PRINTF1(_L("Content Info Failure"));
342 SetTestStepResult(EFail);
345 else if(!iUnitTestContinueFlag)
349 for(TInt i=1;i<=contentInfoCount;i++)
351 TBuf<KContentInfoBufLen> contentBuf(KContentInfoKey);
352 //Append the counter to the keyname
353 contentBuf.AppendNum(i);
354 if(!GetStringFromConfig(KAuthSafeSec,contentBuf,contentSection))
356 ERR_PRINTF1(_L("ContentSection not available in the inifile"));
357 SetTestStepResult(EFail);
361 //retrieve the expected result:PositiveTest/NegativeTest
362 if(GetIntFromConfig(contentSection,KExpectedResult,iExpectedResult)==EFalse)
364 INFO_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
365 iExpectedResult=KPositiveTest;
367 // Verify before calling array to access the data.
368 if(!VerifyExpectedError(contentSection))
370 INFO_PRINTF1(_L("Content Info Failure"));
371 SetTestStepResult(EFail);
375 else if(!iUnitTestContinueFlag)
380 //Call the function for checking the contentinfo,pass the contntsction as parameter
381 iBagData=iParser->ArraySafeBagData()[contentIndex];
383 //Check the contentinfo type
384 iActualResult=ChkCIType(contentSection,*iBagData);
389 Function is intended to parse the BagData section of the ini file
390 @param-aTotalsafebags:total number of safebags
391 @param-aTotalbags:total number of bags including the safecontentbags
393 @return:returns EFalse if there is a failure else return ETrue
395 @leave: if leave occurs at the ChkBagValL function
397 TBool CPKCS12LibTestStep::ChkBagDataL(TInt aTotalsafebags,TInt aTotalbags)
400 TInt safeContentIndex=0;
402 CSafeContentBag* safeContentBag;
403 TBool flagReturn=ETrue;
405 TInt totalSafeContentsBag = iParser->PfxHeader().SafecontentBagCount();
408 //loop for the totalbags
409 for(TInt bags=0;bags<aTotalbags;bags++)
411 TBuf<KBagDataSecBufLen> bagSection(KBagDataSec);
412 //Append the bags to the sectionname :BagData1
413 bagSection.AppendNum(bags+1);
414 if(!GetIntFromConfig(bagSection,KBagType,bagType))
416 ERR_PRINTF1(_L("Not able to get the BagType from the ini file"));
420 if(bagType == CDecPkcs12SafeBag::ESafeContentsBag && flagReturn)
422 //loop for the safecontents bags
423 while(safeContentIndex < totalSafeContentsBag && flagReturn)
425 safeContentBag=iParser->ArraySafeContentBag()[safeContentIndex];
426 if(!ChkSafeContsBagData(bagSection,*safeContentBag))
428 ERR_PRINTF1(_L("SafeContent Bag Failed"));
437 while(safeBagIndex < aTotalsafebags && flagReturn)
439 //retrieve the safebag sructure pointer
440 iBagData=iParser->ArraySafeBagData()[safeBagIndex];
442 if(!ChkBagType(bagSection,*iBagData,bagType))
444 ERR_PRINTF1(_L("Bag Type does not match"));
448 if(!iUnitTestContinueFlag)
453 if(!ChkBagAttbutesL(bagSection,*iBagData))
455 ERR_PRINTF1(_L("Failure in Attributes"));
461 case CDecPkcs12SafeBag::ECertBag:
464 if(!ChkBagValL(bagSection,*iBagData))
467 ERR_PRINTF1(_L("Certificate Bag Value comparison Failed"));
469 //check the certificate type
472 if(!ChkCertId(bagSection,*iBagData))
475 ERR_PRINTF1(_L("Certificate Bag certID comparison Failed"));
480 case CDecPkcs12SafeBag::EKeyBag:
482 if(!ChkBagValL(bagSection,*iBagData))
485 ERR_PRINTF1(_L("Key Bag Failed"));
489 case CDecPkcs12SafeBag::EShroudedKeyBag:
491 if(!ChkEncodedBagValL(bagSection,*iBagData))
494 ERR_PRINTF1(_L("Shrouded Bag Failed"));
498 case CDecPkcs12SafeBag::ECrlBag:
502 case CDecPkcs12SafeBag::ESecretBag:
519 Function is intended to check the safecontents bag
520 @param-aSec:BagData Section
521 @param-aSfContBag:safecontent class pointer
523 @return:returns EFalse if there is a failure else return ETrue
526 TBool CPKCS12LibTestStep::ChkSafeContsBagData(TDesC& aSec,CSafeContentBag &aSfContBag)
528 TInt safeContentsCount=0;
529 TBool flagReturn=ETrue;
530 //retrieve the safecontentsbag count from ini file
531 if(!GetIntFromConfig(aSec,KSafeBagsCount,safeContentsCount))
533 ERR_PRINTF1(_L("SafeContent Bags count not found in INI file"));
534 SetTestStepResult(EFail);
537 //compare the data with the ini file data
538 if(safeContentsCount != aSfContBag.SafeBagCount() && flagReturn)
540 ERR_PRINTF1(_L("Number of Bags in the safecontent bag is different"));
541 iActualResult=EFalse;
543 //retrieve the expected result:PositiveTest/NegativeTest
544 if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult))
546 INFO_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
547 iExpectedResult=KPositiveTest;
549 //check whether its a positive or a negative test
552 //check whether its a positive or a negative test
553 if(!VerifyExpectedError(aSec))
555 INFO_PRINTF1(_L("SafeContentsBag Failed"));
556 SetTestStepResult(EFail);
563 Function is intended to check the content info type
564 @param-aSecName:BagData Section
565 @param-aBagData:safebag class pointer
567 @return:returns EFalse if there is a failure else return ETrue
570 TBool CPKCS12LibTestStep::ChkCIType(TDesC &aSecName,CSafeBagData &aBagData)
573 TBool flagReturn=ETrue;
574 //retrieve the contentype from the ini file
575 if(!GetIntFromConfig(aSecName,KContentInfoType,contentType))
577 ERR_PRINTF1(_L("ContentInfoType value not found in INI file"));
578 SetTestStepResult(EFail);
581 //compare the contentype with the ini file data
584 if(aBagData.ContentInfoType() != contentType)
586 iActualResult=EFalse;
587 INFO_PRINTF1(_L("ContentType Comparison Failed"));
589 //retrieve the expected result:PositiveTest/NegativeTest
590 if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult))
592 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
593 iExpectedResult=KPositiveTest;
595 //check whether its a positive or a negative test
596 if(!VerifyExpectedError(aSecName))
598 INFO_PRINTF1(_L("ContentInfo Failed"));
599 SetTestStepResult(EFail);
606 Function is intended to check the bag type
607 @param-aSec:BagData Section
608 @param-aBgDta:safebag class pointer
611 @return:returns EFalse if there is a failure else return ETrue
614 TBool CPKCS12LibTestStep::ChkBagType(TDesC &aSec,CSafeBagData &aBagData,TInt aId)
616 TBool flagReturn=ETrue;
618 //check for the bagid
619 if(aId != aBagData.BagType())
621 iActualResult=EFalse;
622 INFO_PRINTF1(_L("BagType Comparision Failed"));
625 //retrieve the expected result:PositiveTest/NegativeTest
626 if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult))
628 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
629 iExpectedResult=KPositiveTest;
632 //check whether its a positive or a negative test
633 if(!VerifyExpectedError(aSec))
635 INFO_PRINTF1(_L("BagType Failed"));
636 SetTestStepResult(EFail);
642 Function is intended to check the bag attributes
643 @param-aSec:BagData Section
644 @param-aBagData:safebag class pointer
646 @return:returns EFalse if there is a failure else return ETrue
649 TBool CPKCS12LibTestStep::ChkBagAttbutesL(TDesC &aSec,CSafeBagData &aBagData)
653 TPtrC attrSec(KNullDesC);
654 TBool flagReturn=ETrue;
656 //retrieve the number of attributes
657 if(!GetIntFromConfig(aSec,KBagAttributesNum,numAttr))
659 WARN_PRINTF1(_L("Number of attributes not found in INI file"));
662 for(TInt attrindex=0;attrindex < numAttr;attrindex++)
664 TBuf<KAttributeBufLen> attrBuf(KBagAttributesKey);
665 //increment the attr counter
667 //appending to get the attr key from the ini file
668 attrBuf.AppendNum(count);
670 if(!GetStringFromConfig(aSec,attrBuf,attrSec))
672 ERR_PRINTF1(_L("Number of attributes not found in INI file"));
673 SetTestStepResult(EFail);
677 //retrieve the expected result:PositiveTest/NegativeTest
678 if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult))
680 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
681 iExpectedResult=KPositiveTest;
683 //check whether its a positive or a negative test
684 if(!VerifyExpectedError(aSec))
686 INFO_PRINTF1(_L("BagAttributes Failed"));
687 SetTestStepResult(EFail);
690 else if(!iUnitTestContinueFlag)
695 //retrieve the expected result:PositiveTest/NegativeTest
696 if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult))
698 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
699 iExpectedResult=KPositiveTest;
701 //check whether its a positive or a negative test
702 if(!VerifyExpectedError(aSec))
704 INFO_PRINTF1(_L("BagAttributes Failed"));
705 SetTestStepResult(EFail);
708 else if(!iUnitTestContinueFlag)
713 //Check the BagAttribute section
714 if(!ChkAtrSecL(attrSec,aBagData,attrindex))
716 ERR_PRINTF1(_L("Attributes comparison failed"));
724 Function is intended to check the attribute section
725 @param-aSec:BagData Section
726 @param-aBgDta:safebag class pointer
727 @param-aIndx:attribute index
728 @param-aAttrindex:attribute index
730 @return:returns EFalse if there is a failure else return ETrue
732 @leave: if leave occurs if ChkAtrValL fails
734 TBool CPKCS12LibTestStep::ChkAtrSecL(TDesC &aSec,CSafeBagData &aBagData,TInt aIndex)
736 TPtrC attrId(KNullDesC);
738 CSafeBagAttribute *bagAttr;
739 TPtrC friendlyName(KFriendlyNameOid);
740 TPtrC localKey(KLocalKeyOid);
741 TBool flagReturn=ETrue;
743 //retrieve the attribute id
744 if(!GetStringFromConfig(aSec,KBagAttributesID,attrId))
746 ERR_PRINTF1(_L("attribute id not found in INI file"));
747 SetTestStepResult(EFail);
752 //retrieve the number of values
753 if(!GetIntFromConfig(aSec,KBagAttributeValuesNum,numVal))
755 ERR_PRINTF1(_L("total number of attribute values not found in INI file"));
756 SetTestStepResult(EFail);
762 bagAttr = aBagData.iAttributeIDs[aIndex];
764 //increment the Number of BagAttrValues
765 iBagAttrNumVal+=numVal;
767 //compare the attrval count and the attrid
768 if((bagAttr->AttributeValueCount()!=numVal) ||
769 (attrId.CompareF((bagAttr->AttributeId()))!=0))
771 iActualResult=EFalse;
773 else if((friendlyName.CompareF((bagAttr->AttributeId()))==0) ||
774 (localKey.CompareF((bagAttr->AttributeId()))==0))
776 //Check for BagAttribute values
777 if(!ChkAtrValL(aSec,aBagData,numVal))
779 iActualResult=EFalse;
782 //retrieve the expected result:PositiveTest/NegativeTest
783 if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult))
785 WARN_PRINTF1(_L("ExpectedResult not found in INI file"));
786 iExpectedResult=KPositiveTest;
788 //check for positive or negative test
789 if(!VerifyExpectedError(aSec))
791 INFO_PRINTF1(_L("Attributes Comparison Test Case failed"));
792 SetTestStepResult(EFail);
797 //retrieve the bag attribute structure pointer
801 Function is intended to check the attribute values
802 @param-aSec:BagData Section
803 @param-aBgDta:safebag class pointer
804 @param-aNum:Bagattribute value count
805 @param-aAtr:Bagattribute ID
806 @param-aNumVal:Bagattribute value count
808 @return:returns EFalse if there is a failure else return ETrue
810 @leave: if memory allocation of buffer fails
812 TBool CPKCS12LibTestStep::ChkAtrValL(TDesC &aSec,CSafeBagData &aBagData,TInt aNum)
814 TInt start=iBagAttrNumVal - aNum;
815 TInt end=iBagAttrNumVal + aNum;
817 TBool flagReturn=ETrue;
819 TPtrC value(KNullDesC);
823 //loop till the total number of values
826 TBuf<KBagValBufLen> bagVal(KBagAttributeValue);
827 //increment the index to append the count
830 bagVal.AppendNum(index);
831 //retrieve the value from the ini file
832 if(!GetStringFromConfig(aSec,bagVal,value))
834 ERR_PRINTF1(_L("Bag Value not found in the ini file"));
835 SetTestStepResult(EFail);
839 for(TInt startIndex=start;startIndex<end;startIndex++)
841 bufferVal=aBagData.iAttributeValues[startIndex];
843 //check the local key value
844 if(!CompareFileDataL(value,*bufferVal))
846 ERR_PRINTF1(_L("Bag Attribute Value comparison failed"));
847 iActualResult=EFalse;
856 //retrieve the expected result:PositiveTest/NegativeTest
857 if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult))
859 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
860 iExpectedResult=KPositiveTest;
862 //check for positive or negative test
863 if(!VerifyExpectedError(aSec))
865 INFO_PRINTF1(_L("Bag Value Test failed"));
866 SetTestStepResult(EFail);
870 else if(!iUnitTestContinueFlag)
878 Function is intended to check the value.
879 @param-aPValue:filepath containing the path of the file
880 retrieved from the ini file
881 @param-aBufferVal:Value retrieved after parsing the pkcs12 file
883 @return:returns EFalse if there is a failure else return ETrue
885 @leave: if leave occurs if openfile fails or allocation to buffer fails
887 TBool CPKCS12LibTestStep::CompareFileDataL(TDesC &aPValue,TDesC8 &aBufferVal)
891 TBool flagReturn=ETrue;
892 // Negative Test: If mac/ macSalt is not present.
896 User::LeaveIfError(file.Open(iFileSession,aPValue,EFileRead));
897 User::LeaveIfError(file.Size(fileSize));
898 //raw data for reading the bagvalue
899 HBufC8 *rawData=HBufC8::NewMaxLC(fileSize);
900 //converting the HBufC8 to TPtr8
901 TPtr8 data(rawData->Des());
902 //read the contents of the file
903 User::LeaveIfError(file.Read(data));
905 if(rawData->CompareF(aBufferVal)!=0)
907 ERR_PRINTF1(_L("comparison failed"));
910 //closes the data file
913 CleanupStack::PopAndDestroy(rawData);
918 Function is intended to check the algorithm id
919 @param-aSecName:BagData Section
920 @param-aBagData:safebagdata class pointer
922 @return:returns EFalse if there is a failure else return ETrue
925 TBool CPKCS12LibTestStep::ChkAlgId(TDesC &aSecName,CSafeBagData &aBagData)
927 TPtrC algorithm(KNullDesC);
928 TBool flagReturn=ETrue;
929 //retrieve the algorithm section name
930 if(!GetStringFromConfig(aSecName,_L("Algorithm"),algorithm))
932 ERR_PRINTF1(_L("AlgorithmID value not found in INI file"));
933 SetTestStepResult(EFail);
938 if(algorithm.CompareF((aBagData.AlgorithmId()))!=0)
940 iActualResult=EFalse;
942 //retrieve the expected result:PositiveTest/NegativeTest
943 if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult))
945 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
946 iExpectedResult=KPositiveTest;
948 //check for positive oor negative test
949 if(!VerifyExpectedError(aSecName))
951 INFO_PRINTF1(_L("Algorithm Comparison Test Case failed"));
952 SetTestStepResult(EFail);
959 Function is intended to check the certificate type
960 @param-aSecName:BagData Section
961 @param-aBagData:safebagdata class pointer
963 @return:returns EFalse if there is a failure else return ETrue
966 TBool CPKCS12LibTestStep::ChkCertId(TDesC &aSecName,CSafeBagData &aBagData)
968 TPtrC certid(KNullDesC);
969 TBool flagReturn=ETrue;
970 //retrieve the cert name from ini file
971 if(!GetStringFromConfig(aSecName,KCertType,certid))
973 ERR_PRINTF1(_L("certificateID value not found in INI file"));
974 SetTestStepResult(EFail);
979 if(certid.CompareF((aBagData.CertificateId()))!=0)
981 INFO_PRINTF1(_L("certificateID comparision Failed"));
982 iActualResult=EFalse;
984 //retrieve the expected result:PositiveTest/NegativeTest
985 if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult))
987 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
988 iExpectedResult=KPositiveTest;
990 //check for positive or negative test
991 if(!VerifyExpectedError(aSecName))
993 INFO_PRINTF1(_L("Certificate Comparison Test Case failed"));
994 SetTestStepResult(EFail);
1001 Function is intended to check for the bag value
1002 @param-aSecName:BagData Section
1003 @param-aBagData:safebag class pointer
1004 @internalTechnology:
1005 @return:returns EFalse if there is a failure else return ETrue
1008 TBool CPKCS12LibTestStep::ChkBagValL(TDesC &aSecName,CSafeBagData &aBagData)
1010 TPtrC certBagPath(KNullDesC);
1011 TBool flagReturn=ETrue;
1013 //retrieve the certificate bag value
1014 if(!GetStringFromConfig(aSecName,KBagValue,certBagPath))
1016 ERR_PRINTF1(_L("Not able to get the CertBagValue from the ini file"));
1017 SetTestStepResult(EFail);
1025 fileReturn=file.Open(iFileSession,certBagPath,EFileRead);
1029 ERR_PRINTF1(_L("CertBagValue:Not able to open the file"));
1030 SetTestStepResult(EFail);
1034 //raw data for reading the bagvalue
1035 HBufC8 *rawData=NULL;
1039 User::LeaveIfError(file.Size(filesize));
1040 rawData=HBufC8::NewMaxLC(filesize);
1041 TPtr8 data(rawData->Des());
1044 ERR_PRINTF1(_L("CertBagValue:Not able to Read the file"));
1045 SetTestStepResult(EFail);
1052 if(rawData->CompareF(aBagData.BagValue())!=0)
1054 iActualResult=EFalse;
1056 //retrieve the expected result:PositiveTest/NegativeTest
1057 if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult))
1059 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1060 iExpectedResult=KPositiveTest;
1062 //check for positive or negative test
1063 if(!VerifyExpectedError(aSecName))
1065 INFO_PRINTF1(_L("BagValue Failed"));
1066 SetTestStepResult(EFail);
1067 flagReturn = EFalse;
1072 CleanupStack::PopAndDestroy(rawData);
1081 Function is intended to check for the mac value
1082 @internalTechnology:
1083 @return:returns EFalse if there is a failure else return ETrue
1085 @leave: if leave occurs at the CompareFileDataL function
1087 TBool CPKCS12LibTestStep::ChkMacValueL()
1089 TPtrC mac(KNullDesC);
1090 TPtrC macSalt(KNullDesC);
1091 TPtrC secName(_S("MacData"));
1092 TPtrC expectedError(KNullDesC);
1094 TBool flagReturn=ETrue;
1096 //retrieve the macid,macsalt and iteration count
1097 if((!GetStringFromConfig(secName,KMac,mac)) ||
1098 (!GetStringFromConfig(secName,KMacSalt,macSalt)) ||
1099 (!GetIntFromConfig(secName,KIterationCount,itCount)))
1101 ERR_PRINTF1(_L("Not able to access the mac values from ini file"));
1102 SetTestStepResult(EFail);
1105 //comapre the data with the ini file
1106 if((CompareFileDataL(mac,iParser->PfxHeader().MacId()) ==0)||
1107 (CompareFileDataL(macSalt,iParser->PfxHeader().MacSalt()) == 0)||
1108 (itCount!=iParser->PfxHeader().IterationCount()))
1110 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1113 //retrieve the expected result:PositiveTest/NegativeTest
1114 if(!GetBoolFromConfig(secName,KExpectedResult,iExpectedResult))
1116 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1117 iExpectedResult=KPositiveTest;
1119 if(!VerifyExpectedError(secName))
1121 SetTestStepResult(EFail);
1122 flagReturn = EFalse;
1127 CTPKCS12OOMStep::CTPKCS12OOMStep()
1131 CTPKCS12OOMStep::~CTPKCS12OOMStep()
1134 delete iAuthSafeData;
1138 Function is intended to do the OOM test.
1139 @internalTechnology:
1140 @return:TVerdict -returns EFail if there is a failure else EPass
1141 @leave:- if memory allocation fails
1144 TVerdict CTPKCS12OOMStep::doTestStepL()
1147 GetIntFromConfig(ConfigSection(),_L("OOMTest"),OOMTest);
1155 CDecPkcs12* theTest = NULL;
1156 theTest = CDecPkcs12::NewL(iRawData->Des());
1164 GetStringFromConfig(ConfigSection(), _L("File"), fileName);
1167 User::LeaveIfError(file.Open(iFs, fileName, EFileRead) );
1173 HBufC8* res = HBufC8::NewLC(size);
1174 TPtr8 p(res->Des());
1177 RFileReadStream stream;
1178 User::LeaveIfError(stream.Open(iFs, fileName, EFileStream));
1179 CleanupClosePushL(stream);
1181 stream.ReadL(p, size);
1183 CDecPkcs12* theTest = NULL;
1184 theTest = CDecPkcs12::NewL(stream);
1186 CleanupStack::PopAndDestroy(2,res); // stream
1192 CDecPkcs12MacData* theTest = NULL;
1193 theTest = CDecPkcs12MacData::NewL(iRawData->Des(),iAuthSafeData->Des());
1200 CDecPkcs12Attribute* theTest = NULL;
1201 theTest = CDecPkcs12Attribute::NewL(iRawData->Des());
1208 CDecPkcs12ShroudedKeyBag* theTest = NULL;
1209 theTest = CDecPkcs12ShroudedKeyBag::NewL(iRawData->Des());
1216 CDecPkcs12CertBag* theTest = NULL;
1217 theTest = CDecPkcs12CertBag::NewL(iRawData->Des());
1224 CDecPkcs12KeyBag* theTest = NULL;
1225 theTest = CDecPkcs12KeyBag::NewL(iRawData->Des());
1232 CDecPkcs12SafeContentsBag* theTest = NULL;
1233 theTest = CDecPkcs12SafeContentsBag::NewL(iRawData->Des());
1240 CDecPkcs12SafeBag* theTest = NULL;
1241 theTest = CDecPkcs12SafeBag::NewL(iRawData->Des());
1245 // SafeContentsData / SafeContentsEncryptedData
1248 CDecPkcs12* p12 = NULL;
1249 p12 = CDecPkcs12::NewL(iRawData->Des());
1250 CleanupStack::PushL(p12);
1252 const RPointerArray<CPKCS7ContentInfo>& contentInfos = p12->AuthenticatedSafeContents();
1254 TInt contentInfoCount = contentInfos.Count();
1255 for ( TInt index = 0; index < contentInfoCount; index++ )
1257 TInt contentType = contentInfos[index]->ContentType();
1258 CDecPkcs12SafeContents* pkcs12SafeContents ;
1259 TInt contentTypeData;
1260 GetIntFromConfig(ConfigSection(),_L("ContentTypeData"),contentTypeData);
1262 TInt contentTypeEncryptedData;
1263 GetIntFromConfig(ConfigSection(),_L("ContentTypeEncryptedData"),contentTypeEncryptedData);
1265 if ( contentType == contentTypeEncryptedData )
1267 TPtrC expectedPassword(KNullDesC());
1268 GetStringFromConfig(ConfigSection(), _L("Password"), expectedPassword);
1269 pkcs12SafeContents = CDecPkcs12SafeContents::NewL(*contentInfos[index],expectedPassword);
1270 delete pkcs12SafeContents;
1272 else if ( contentType == contentTypeData )
1274 pkcs12SafeContents = CDecPkcs12SafeContents::NewL(*contentInfos[index]);
1275 delete pkcs12SafeContents;
1278 CleanupStack::PopAndDestroy(p12);
1283 return TestStepResult();
1287 Function is intended to read the data from the specified path.
1288 @param-aPValue:filepath containing the path of the file
1289 retrieved from the ini file.
1290 @internalTechnology:
1291 @return:returns data retrieved after reading from the file.
1294 HBufC8* CTPKCS12OOMStep::ReadFileDataL(TPtrC tag)
1297 if (!GetStringFromConfig(ConfigSection(), tag, fileName))
1303 if (file.Open(iFs, fileName, EFileRead))
1305 INFO_PRINTF2(_L("Cannot open file %S for reading"), &fileName);
1308 CleanupClosePushL(file);
1311 User::LeaveIfError(file.Size(fileSize));
1313 HBufC8* result = HBufC8::NewL(fileSize);
1314 result->Des().SetLength(fileSize);
1316 TPtr8 rawDataPtr(result->Des());
1317 rawDataPtr.SetLength(fileSize);
1318 file.Read (rawDataPtr);
1320 CleanupStack::PopAndDestroy (&file);
1322 INFO_PRINTF3(_L("Read %d octets from %S"), result->Size(), &fileName);
1327 TVerdict CTPKCS12OOMStep::doTestStepPreambleL()
1329 User::LeaveIfError (iFs.Connect());
1331 SetTestStepResult(EPass);
1333 iRawData = ReadFileDataL(_L("File"));
1334 if (iRawData == NULL)
1336 INFO_PRINTF1(_L("Failed to read 'File' section of script"));
1337 SetTestStepResult(ETestSuiteError);
1339 iAuthSafeData = ReadFileDataL(_L("AuthSafe"));
1340 if (iAuthSafeData == NULL)
1342 INFO_PRINTF1(_L("authsafedata file is not required"));
1344 return TestStepResult();
1347 Function is intended to check for the re encoded shrouded key
1348 @param-aSecName:BagData Section
1349 @param-aBagData:safebag class pointer
1350 @internalTechnology:
1351 @return:returns EFalse if there is a failure else return ETrue
1354 TBool CPKCS12LibTestStep::ChkEncodedBagValL(TDesC &aSecName,CSafeBagData &aBagData)
1356 TPtrC bagPath(KNullDesC);
1357 TBool flagReturn=ETrue;
1359 //retrieve the shrouded bag value
1360 if(!GetStringFromConfig(aSecName,KEncBagValue,bagPath))
1362 ERR_PRINTF1(_L("Not able to get the EncBagValue from the ini file"));
1363 SetTestStepResult(EFail);
1371 fileReturn=file.Open(iFileSession,bagPath,EFileRead);
1375 ERR_PRINTF1(_L("BagValue:Not able to open the file"));
1376 SetTestStepResult(EFail);
1380 CleanupClosePushL(file);
1381 //raw data for reading the bagvalue
1382 HBufC8 *rawData=NULL;
1386 User::LeaveIfError(file.Size(filesize));
1387 rawData=HBufC8::NewMaxLC(filesize);
1388 TPtr8 data(rawData->Des());
1391 ERR_PRINTF1(_L("BagValue:Not able to Read the file"));
1392 SetTestStepResult(EFail);
1399 if(rawData->CompareC(aBagData.EncodedShroudedKey())!=0)
1401 iActualResult=EFalse;
1403 //retrieve the expected result:PositiveTest/NegativeTest
1404 if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult))
1406 WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1407 iExpectedResult=KPositiveTest;
1409 //check for positive or negative test
1410 if(!VerifyExpectedError(aSecName))
1412 INFO_PRINTF1(_L("BagValue Failed"));
1413 SetTestStepResult(EFail);
1414 flagReturn = EFalse;
1419 CleanupStack::PopAndDestroy(rawData);
1425 CleanupStack::PopAndDestroy(&file);