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