cryptoservices/certificateandkeymgmt/tpkcs12intgrtn/src/tpkcs12common.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     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 contains the implementation of the CPkcs12Parser class, to parse the PKCS#12 file.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @file 
       
    24  @internalTechnology
       
    25 */
       
    26 
       
    27 // System Include
       
    28 #include <f32file.h>
       
    29 
       
    30 //User Include 
       
    31 #include "tpkcs12common.h"
       
    32 using namespace PKCS12;
       
    33 /**
       
    34 Description:constructor
       
    35 @internalTechnology:
       
    36 @test
       
    37 */
       
    38 CPkcs12Parser::CPkcs12Parser()
       
    39 	{
       
    40 	}
       
    41 /**
       
    42 Description:destructor
       
    43 @internalTechnology:
       
    44 @test
       
    45 */
       
    46 CPkcs12Parser::~CPkcs12Parser()
       
    47 	{
       
    48 	delete iIntegrityPassword;	
       
    49 	delete iRawData;	
       
    50 	delete iPkcs12Header;
       
    51 	iArraySafecontentBag.ResetAndDestroy();
       
    52 	iArrayBagData.ResetAndDestroy();
       
    53 	}
       
    54 
       
    55 /**
       
    56 Description:Function is intended to creates a new CPKCS12Parser object.	 
       
    57 @return:CPKCS12Parser* : parser object to parse the PKCS12 file
       
    58 @internalTechnology
       
    59 @test
       
    60 */
       
    61 CPkcs12Parser* CPkcs12Parser::NewL()
       
    62 	{	
       
    63 	CPkcs12Parser* parser = NewLC();
       
    64 	CleanupStack::Pop(parser);	
       
    65 	return parser;
       
    66 	}
       
    67 /**
       
    68 Description:Function is intended to creates a new CPKCS12Parser object.	 
       
    69 @return:CPKCS12Parser* : parser object to parse the PKCS12 file
       
    70 @test
       
    71 */
       
    72 CPkcs12Parser* CPkcs12Parser::NewLC()
       
    73 	{	
       
    74 	CPkcs12Parser* parser = new (ELeave) CPkcs12Parser();
       
    75 	CleanupStack::PushL(parser);	
       
    76 	return parser;
       
    77 	}
       
    78 /**
       
    79 Description:Function is intended to set the integrity password 
       
    80 @param	aIntegrityPassword, contains the integrity password
       
    81 @internalTechnology
       
    82 @test
       
    83 */
       
    84 void CPkcs12Parser::SetIntegrityPasswordL(const TDesC& aIntegrityPassword)
       
    85 	{
       
    86 	iIntegrityPassword = aIntegrityPassword.AllocL();
       
    87 	}
       
    88 
       
    89 /**
       
    90 Description:Function is intended to set the privacy password(s) 
       
    91 @param aPrivacyPassword, contains  the privacy passwords.The ownership is not transferred
       
    92 @internalTechnology
       
    93 @test
       
    94 */
       
    95 void CPkcs12Parser::SetPrivacyPassword(RPointerArray<TDesC>& aPrivacyPassword)
       
    96 	{
       
    97 	iPrivacyPassword = 	&aPrivacyPassword;
       
    98 	}
       
    99 /**
       
   100 Description:Function is intended to set the test data. 
       
   101 			It opens the data file and stores it in the buffer.
       
   102 @param aDatapath, contains the path of the PKCS12 file
       
   103 @internalTechnology
       
   104 @test
       
   105 */
       
   106 void CPkcs12Parser::SetDataL(const TDesC& aDatapath)
       
   107 	{ 	
       
   108 	if(iRawData)
       
   109 		{
       
   110 		delete iRawData ;
       
   111 		iRawData  = NULL;
       
   112 		}
       
   113 	RFs fs;
       
   114 	//connects the file server
       
   115 	User::LeaveIfError (fs.Connect());
       
   116 	//opens the data file
       
   117 	CleanupClosePushL(fs);
       
   118 	RFile file;
       
   119 	User::LeaveIfError(file.Open(fs, aDatapath, EFileRead)) ; 
       
   120 	CleanupClosePushL(file);
       
   121 	
       
   122 	TInt fileSize = 0;
       
   123 	User::LeaveIfError(file.Size(fileSize));	
       
   124 
       
   125 	iRawData = HBufC8::NewL(fileSize);
       
   126 	TPtr8 rawData(iRawData->Des());
       
   127 	rawData.SetLength(fileSize);	
       
   128 	file.Read (rawData);
       
   129 
       
   130 	CleanupStack::PopAndDestroy(&file);
       
   131 	//closes the file session
       
   132 	CleanupStack::PopAndDestroy(&fs);
       
   133 	}
       
   134 /**
       
   135 Description:Function is intended to parse the PKCS#12 data
       
   136 @leave:- if the number of contentinfos and number of privacy passwords does not match.	
       
   137 @internalTechnology
       
   138 @test
       
   139 */
       
   140 void CPkcs12Parser::ParseL()
       
   141 	{
       
   142 	//creates the CDecPkcs12 object		
       
   143 	CDecPkcs12* decPkcs12 = NULL;
       
   144 	TRAPD(error, decPkcs12	= CDecPkcs12::NewL(*iRawData));
       
   145 	if(error == KErrNone)
       
   146 		CleanupStack::PushL(decPkcs12);	
       
   147 
       
   148 	//Creates a CPfxHeader object
       
   149 	iPkcs12Header = CPfxHeader::NewL(*decPkcs12 , error);	
       
   150 	if(error != KErrNone)
       
   151 		{
       
   152 		
       
   153 		return ;	
       
   154 		}
       
   155 	const CDecPkcs12MacData* macData = decPkcs12->MacData();
       
   156 	TRAPD(err,macData->VerifyIntegrityL(iIntegrityPassword->Des()));
       
   157 	if(err)
       
   158 		{
       
   159 		iPkcs12Header->SetPkcs12ActualError(err);
       
   160 		CleanupStack::PopAndDestroy(decPkcs12);
       
   161 		return;
       
   162 		}
       
   163 	//get the ContentInfo collection
       
   164 	const RPointerArray<CPKCS7ContentInfo>& contentInfos = decPkcs12->AuthenticatedSafeContents();	
       
   165 	TInt contentInfoCount = contentInfos.Count();
       
   166 	//put the content info count in the Header
       
   167 	iPkcs12Header->SetContentInfoCount(contentInfoCount) ;
       
   168 
       
   169 	// start iterate through the contentinfos
       
   170 	for(TInt index = 0 ; index < contentInfoCount; index++)
       
   171 		{
       
   172 		TInt contentType = contentInfos[index]->ContentType() ; 
       
   173 		TPtrC8 contentData = contentInfos[index]->ContentData();
       
   174 		if( contentData == KNullDesC8()) 
       
   175 			{
       
   176 			iPkcs12Header->SetPkcs12ActualError(0);
       
   177 			continue;
       
   178 			}
       
   179 		CDecPkcs12SafeContents* pkcs12SafeContents = NULL;			
       
   180 		switch(contentType)
       
   181 			{
       
   182 			case CPKCS7ContentInfo::EContentTypeData:
       
   183 				{
       
   184 				TRAPD(error1,pkcs12SafeContents = CDecPkcs12SafeContents::NewL(*contentInfos[index]));	
       
   185 				if(error1)
       
   186 					{
       
   187 					iPkcs12Header->SetPkcs12ActualError(error1);
       
   188 					CSafeBagData* bagData = NULL; 
       
   189 					bagData = CreateBagDataL(index,contentType);
       
   190 					iArrayBagData.AppendL(bagData) ;
       
   191 					CleanupStack::PopAndDestroy(decPkcs12);
       
   192 					return;
       
   193 					}	
       
   194 				CleanupStack::PushL(pkcs12SafeContents);			
       
   195 				break;
       
   196 				}
       
   197 			case CPKCS7ContentInfo::EContentTypeEncryptedData:
       
   198 				{
       
   199 				if(contentInfoCount != iPrivacyPassword->Count())	
       
   200 					{
       
   201 					User::Leave(KErrArgument);
       
   202 					}
       
   203 						
       
   204 				TRAPD(error2,pkcs12SafeContents = CDecPkcs12SafeContents::NewL(*contentInfos[index],
       
   205 																	*((*iPrivacyPassword)[index]) ) );
       
   206 				if(error2)
       
   207 					{
       
   208 					iPkcs12Header->SetPkcs12ActualError(error2);
       
   209 					CSafeBagData* bagData = NULL; 
       
   210 					bagData = CreateBagDataL(index,contentType);
       
   211 					iArrayBagData.AppendL(bagData) ;
       
   212 					CleanupStack::PopAndDestroy(decPkcs12);
       
   213 					return;
       
   214 					}							
       
   215 				CleanupStack::PushL(pkcs12SafeContents);	
       
   216 				break;							
       
   217 				}
       
   218 			case CPKCS7ContentInfo::EContentTypeEnvelopedData:
       
   219 				{
       
   220 				//creates a Bagdata object in the heap to store the content type. 
       
   221 				CSafeBagData* bagData = CreateBagDataL(index+1 ,contentType);
       
   222 				iArrayBagData.AppendL(bagData) ;
       
   223 				//continue in the loop
       
   224 				continue;
       
   225 				}
       
   226 
       
   227 			default:
       
   228 				{	
       
   229 				//continue in the loop
       
   230 				continue;
       
   231 				}
       
   232 			}
       
   233 		// Get the safebags count.
       
   234 		const RPointerArray<CDecPkcs12SafeBag>& safeBags = pkcs12SafeContents->SafeContentsBags();
       
   235 		TInt safeBagCount = safeBags.Count();
       
   236 	
       
   237 		
       
   238 		//start parsing the bags
       
   239 		for (TInt bagsCount=0; bagsCount < safeBagCount; bagsCount++)
       
   240 			{	
       
   241 			TRAPD(error3,ParseSafeBagL(index+1, contentType , *safeBags[bagsCount]));
       
   242 			if(error3 != KErrNone)
       
   243 				{
       
   244 				iPkcs12Header->SetPkcs12ActualError(error3);
       
   245 				CSafeBagData* bagData = NULL; 
       
   246 				bagData = CreateBagDataL(index,contentType);
       
   247 				iArrayBagData.AppendL(bagData) ;
       
   248 				CleanupStack::PopAndDestroy(2,decPkcs12);
       
   249 				return;
       
   250 				}	
       
   251 			}	
       
   252 			CleanupStack::PopAndDestroy(pkcs12SafeContents);
       
   253 		}		
       
   254 	CleanupStack::PopAndDestroy(decPkcs12);	
       
   255 
       
   256 	}
       
   257 
       
   258 /**
       
   259 Description: Creates a CSafeBagData to store the safebag details
       
   260 @param:aContentInfo, the contentinfo number of the safe bag 
       
   261 @param:aContentType, the content type of the safe contents.
       
   262 @return:a pointer to CSafeBagData, which is used to store the safebag details 
       
   263 @internalTechnology:
       
   264 @test:
       
   265 */
       
   266 CSafeBagData* CPkcs12Parser::CreateBagDataL(TInt aContentInfo, TInt aContentType)
       
   267 	{
       
   268 	CSafeBagData* bagData = CSafeBagData::NewL();	
       
   269 	if ( iPkcs12Header->Pkcs12ActualError() == KErrNone )
       
   270 		{
       
   271 		//set the contentinfo # and content type in CSafeBagData
       
   272 		bagData->SetContentInfoNumber(aContentInfo);	
       
   273 		bagData->SetBagNumber(++iSafebagNumber );	
       
   274 		// set the content type in CSafeBagData		
       
   275 		bagData->SetContentInfoType(aContentType);
       
   276 		}
       
   277 	return bagData ;
       
   278 	}
       
   279 
       
   280 /**
       
   281 Description:To parse the safebags
       
   282 @param:aContentInfoIndex	content info number
       
   283 @param:aContentType	contentinfo type
       
   284 @param:aSafeBag	reference to the CDecPkcs12SafeBag 
       
   285 @internalTechnology:
       
   286 @test:
       
   287 */
       
   288 void CPkcs12Parser::ParseSafeBagL(TInt aContentInfo,TInt aContentType,CDecPkcs12SafeBag& aSafeBag)
       
   289 	{
       
   290 	//get the bag type 
       
   291 	CDecPkcs12SafeBag::TBagId bagType = aSafeBag.BagID();
       
   292 	switch(bagType)
       
   293 		{
       
   294 		case CDecPkcs12SafeBag::ESafeContentsBag:
       
   295 			{
       
   296 			CDecPkcs12SafeContentsBag* safeContentsBag = static_cast<CDecPkcs12SafeContentsBag *>(&aSafeBag);
       
   297 			// increment the count
       
   298 			iPkcs12Header->IncrementSafecontentBagCount();
       
   299 			// parsing code to parse SafeContentsBag		
       
   300 			ParseSafeContentBagL(*safeContentsBag, aContentInfo ,aContentType );
       
   301 			break;
       
   302 			}
       
   303 		case CDecPkcs12SafeBag::EKeyBag:
       
   304 			{
       
   305 			CDecPkcs12KeyBag* keyBag = static_cast<CDecPkcs12KeyBag *>(&aSafeBag);					
       
   306 			//create the CSafeBagData object in heap to store the bag details
       
   307 			CSafeBagData* bagData = CreateBagDataL(aContentInfo,aContentType);
       
   308 			CleanupStack::PushL(bagData);			
       
   309 			ParseKeyBag(*keyBag , *bagData);
       
   310 			//get the safeBag attributes
       
   311 			BagAttributesL(*keyBag ,*bagData) ;	
       
   312 			iArrayBagData.AppendL(bagData) ;
       
   313 			CleanupStack::Pop(bagData);					
       
   314 			break;
       
   315 			}
       
   316 		case CDecPkcs12SafeBag::EShroudedKeyBag:
       
   317 			{
       
   318 			CDecPkcs12ShroudedKeyBag* shroudedkeyBag = static_cast<CDecPkcs12ShroudedKeyBag *>(&aSafeBag);
       
   319 			//create the CSafeBagData object in heap to store the bag details
       
   320 			CSafeBagData* bagData = CreateBagDataL(aContentInfo,aContentType );
       
   321 			CleanupStack::PushL(bagData);			
       
   322 			ParseShroudedKeyBagL(*shroudedkeyBag , *bagData ,aContentInfo );		
       
   323 			//get the safeBag attributes
       
   324 			BagAttributesL(*shroudedkeyBag ,*bagData) ;	
       
   325 			iArrayBagData.AppendL(bagData) ;	
       
   326 			CleanupStack::Pop(bagData);			
       
   327 			break;
       
   328 			}
       
   329 		case CDecPkcs12SafeBag::ECertBag:
       
   330 			{
       
   331 			CDecPkcs12CertBag* certBag = static_cast<CDecPkcs12CertBag *>(&aSafeBag);					
       
   332 			//create the CSafeBagData object in heap to store the bag details
       
   333 			CSafeBagData* bagData = CreateBagDataL(aContentInfo,aContentType);
       
   334 			CleanupStack::PushL(bagData);		
       
   335 			ParseCertBag(*certBag , *bagData);
       
   336 			// Get the bag Attributes
       
   337 			BagAttributesL(*certBag , *bagData) ;	
       
   338 			iArrayBagData.AppendL(bagData) ;
       
   339 			CleanupStack::Pop(bagData);			
       
   340 			break;
       
   341 			}
       
   342 		case CDecPkcs12SafeBag::ECrlBag:
       
   343 			{
       
   344 			//create the CSafeBagData object in heap to store the bag details
       
   345 			CSafeBagData* bagData = CreateBagDataL(aContentInfo,aContentType);;
       
   346 			CleanupStack::PushL(bagData);				
       
   347 			//set the bagId in CSafeBagData
       
   348 			bagData->SetBagType(bagType) ; 
       
   349 			//increment the count - unsupported
       
   350 			iPkcs12Header->IncrementCrlBagCount();
       
   351 			iArrayBagData.AppendL(bagData) ;
       
   352 			CleanupStack::Pop(bagData);				
       
   353 			break;
       
   354 			}
       
   355 		case CDecPkcs12SafeBag::ESecretBag:
       
   356 			{
       
   357 			//create the CSafeBagData object in heap to store the bag details
       
   358 			CSafeBagData* bagData = CreateBagDataL(aContentInfo,aContentType );	
       
   359 			CleanupStack::PushL(bagData);
       
   360 			//set the iBagId in CSafeBagData
       
   361 			bagData->SetBagType(bagType) ; 
       
   362 			//increment the count - unsupported
       
   363 			iPkcs12Header->IncrementSecretBagCount();
       
   364 			iArrayBagData.AppendL(bagData) ;		
       
   365 			CleanupStack::Pop(bagData);	
       
   366 			break;
       
   367 			}
       
   368 		default:
       
   369 			{
       
   370 			}
       
   371 		}
       
   372 	}
       
   373 
       
   374 /**
       
   375 Description:Function is intended to get the attributes of Safebag
       
   376 @param-aSafeBag: reference to the CDecPkcs12SafeBag.
       
   377 @param-abagData: reference to the CSafeBagData
       
   378 @internalTechnology:
       
   379 @test
       
   380 */
       
   381 void CPkcs12Parser::BagAttributesL(const CDecPkcs12SafeBag& aSafeBag,CSafeBagData& aBagData )
       
   382 	{
       
   383 	const RPointerArray<CDecPkcs12Attribute>& safeBagAttributes = aSafeBag.BagAttributes();
       
   384 
       
   385 	TInt attributeCount = safeBagAttributes.Count() ;
       
   386 	for (TInt index = 0;index < attributeCount; index++ )
       
   387 		{						
       
   388 		//get the attribute object pointer
       
   389 		CDecPkcs12Attribute* attribute = safeBagAttributes[index];
       
   390 		//create the CSafeBagAttribute object in heap.	
       
   391 		CSafeBagAttribute* bagAttr = CSafeBagAttribute::NewL(*safeBagAttributes[index]);
       
   392 		CleanupStack::PushL(bagAttr);
       
   393 		//get the attribute values
       
   394 		const RPointerArray<TDesC8>& attrValues = attribute->AttributeValue();			
       
   395 		//append the pointer in the iAttributeIDs array
       
   396 		aBagData.iAttributeIDs.AppendL(bagAttr) ;
       
   397 		CleanupStack::Pop(bagAttr);	
       
   398 		//store the attribute values
       
   399 		TInt numberOfAttributes = bagAttr->AttributeValueCount();
       
   400 		for(TInt attrvalCnt = 0 ; attrvalCnt < numberOfAttributes ; attrvalCnt++)
       
   401 			{
       
   402 			//get the atribute value and store the it address in the aBagData.iAttributeValues array				
       
   403 			HBufC8* ptr =  attrValues[attrvalCnt]->AllocLC();								
       
   404 			aBagData.iAttributeValues.AppendL(ptr);
       
   405 			CleanupStack::Pop(ptr);
       
   406 			}			
       
   407 		}	
       
   408 	}
       
   409 /**
       
   410 Description:Function is intended to parse the  keybag
       
   411 @param-aKeyBag: reference to the keybag
       
   412 @param-abagData: reference to the CSafeBagData
       
   413 @internalTechnology:
       
   414 @test:
       
   415 */
       
   416 void CPkcs12Parser::ParseKeyBag(CDecPkcs12KeyBag& aKeyBag , CSafeBagData& aBagData)
       
   417 	{
       
   418 	//set the bagID
       
   419 	aBagData.SetBagType( CDecPkcs12SafeBag::EKeyBag ); 				
       
   420 	// Get the Algorithm(RSA key or DSA key) ID 
       
   421 	CDecPKCS8Data* pkcs8Data = aKeyBag.PrivateKeyInfoL();				
       
   422 	aBagData.SetPrivateKeyInfoVersion(pkcs8Data->Version() );
       
   423 	TAlgorithmId algorithmId = pkcs8Data->Algorithm();
       
   424 	// Set the Algorithm Id in CSafeBagData
       
   425 	aBagData.SetKeyType( algorithmId );
       
   426 	//set the bag value in CSafeBagData
       
   427 	aBagData.SetBagValue( aKeyBag.BagValue());				
       
   428 	// increment the count
       
   429 	iPkcs12Header->IncrementKeyBagCount();
       
   430 	delete pkcs8Data;
       
   431 	}
       
   432 /**
       
   433 Description:Function is intended to parse the  ShroudedKeyBag
       
   434 @param-aShroudedkeyBag: pointer to the CDecPkcs12ShroudedKeyBag
       
   435 @param-abagData: reference to the CSafeBagData
       
   436 @param- aPassIndex: the index of the array from where the privacy password is to be taken
       
   437 @internalTechnology:
       
   438 @test
       
   439 */
       
   440 void CPkcs12Parser::ParseShroudedKeyBagL(CDecPkcs12ShroudedKeyBag& aShroudedkeyBag , CSafeBagData& aBagData , TInt aPassIndex)
       
   441 	{
       
   442 	//set the bag Id in CSafeBagData
       
   443 	aBagData.SetBagType( CDecPkcs12SafeBag::EShroudedKeyBag ); 				
       
   444 	// Get the Algorithm(RSA key or DSA key) ID 
       
   445 	CDecPKCS8Data* pkcs8Data = aShroudedkeyBag.PrivateKeyInfoL(*(*iPrivacyPassword)[aPassIndex-1]);
       
   446 	if(pkcs8Data)
       
   447 		{
       
   448 		aBagData.SetPrivateKeyInfoVersion(pkcs8Data->Version() );	
       
   449 		TAlgorithmId algorithm  = pkcs8Data->Algorithm();	
       
   450 		// Set the Algorithm Id in CSafeBagData
       
   451 		aBagData.SetKeyType(algorithm);
       
   452 	
       
   453 		CASN1EncSequence* seq = NULL ;
       
   454 		switch(algorithm)
       
   455 			{
       
   456 			case ERSA:
       
   457 				{	
       
   458 				
       
   459 				CPKCS8KeyPairRSA* keypair = static_cast<CPKCS8KeyPairRSA*>(pkcs8Data->KeyPairData());
       
   460 
       
   461 				const CRSAPrivateKey& priv = keypair->PrivateKey();
       
   462 				
       
   463 				const CRSAPublicKey& publicKey = keypair->PublicKey(); 
       
   464 				
       
   465 				TRSAPrivateKeyType keytype = priv.PrivateKeyType();
       
   466 				
       
   467 				switch(keytype)
       
   468 					{
       
   469 					case EStandardCRT:
       
   470 						{
       
   471 						const CRSAPrivateKeyCRT* privateKeyCRT = static_cast<const CRSAPrivateKeyCRT*>(&priv);
       
   472 						seq =  TASN1EncPKCS8::EncodeL(*privateKeyCRT, publicKey,pkcs8Data->PKCS8Attributes());	
       
   473 					
       
   474 						break;
       
   475 						}					
       
   476 					case EStandard:		
       
   477 						{
       
   478 						User::Leave(KErrNotSupported);
       
   479 						}
       
   480 					default:
       
   481 						{
       
   482 						User::Leave(KErrNotSupported);	
       
   483 						}
       
   484 					}
       
   485 					
       
   486 				break;
       
   487 				}		
       
   488 			case EDSA:
       
   489 				{
       
   490 				
       
   491 				CPKCS8KeyPairDSA* keypair = static_cast<CPKCS8KeyPairDSA*>(pkcs8Data->KeyPairData());
       
   492 			
       
   493 				const CDSAPrivateKey& priv = keypair->PrivateKey();
       
   494 				
       
   495 				seq =  TASN1EncPKCS8::EncodeL(priv , pkcs8Data->PKCS8Attributes());
       
   496 			
       
   497 				break;
       
   498 				}			
       
   499 			default:
       
   500 				User::Leave(KErrNotSupported);
       
   501 
       
   502 			}
       
   503 	
       
   504 		HBufC8* bufSeq = HBufC8::NewMaxLC(seq->LengthDER());
       
   505 		TPtr8 temp(bufSeq->Des());
       
   506 
       
   507 		TUint pos = 0;
       
   508 		seq->WriteDERL(temp ,pos);
       
   509 			
       
   510 		aBagData.SetEncodedShroudedKey(temp);
       
   511 		CleanupStack::PopAndDestroy();
       
   512 
       
   513 		delete pkcs8Data;
       
   514 		}
       
   515 		//set the bag value in CSafeBagData
       
   516 		aBagData.SetBagValue(aShroudedkeyBag.BagValue()) ;				
       
   517 		// increment the count 
       
   518 		iPkcs12Header->IncrementShroudedKeyBagCount();											
       
   519 	}
       
   520 
       
   521 /**
       
   522 Description:Function is intended to parse the  certbag
       
   523 @param-aCertBag: pointer to the CDecPkcs12CertBag
       
   524 @param-abagData: reference to the CSafeBagData
       
   525 @internalTechnology:
       
   526 @test
       
   527 */
       
   528 void CPkcs12Parser::ParseCertBag(CDecPkcs12CertBag& aCertBag , CSafeBagData& aBagData)
       
   529 	{
       
   530 	//set the bagID 
       
   531 	aBagData.SetBagType( CDecPkcs12SafeBag::ECertBag );	
       
   532 	aBagData.SetCertificateId(aCertBag.CertId()); 		
       
   533 	//set the bag value in CSafeBagData
       
   534 	aBagData.SetBagValue(aCertBag.CertValue());
       
   535 	
       
   536 	//set the X509Certificate
       
   537 	aBagData.SetX509Certificate((aCertBag.X509CertificateL()) );
       
   538 	// increment the count 
       
   539 	iPkcs12Header->IncrementCertBagCount();			 
       
   540 	}
       
   541 
       
   542 /**
       
   543 Description:Function is intended to parse the  safecontentbag
       
   544 @param-safeContentsBag: reference to the CDecPkcs12SafeContentsBag
       
   545 @param-aContentinfo: contentinfo number
       
   546 @param- aContentType : contentinfo type
       
   547 @internalTechnology
       
   548 @test
       
   549 */
       
   550 void CPkcs12Parser::ParseSafeContentBagL(CDecPkcs12SafeContentsBag& aSafeContntBag, TInt aContentinfo , TInt aContentType )
       
   551 	{	
       
   552 	const RPointerArray<CDecPkcs12SafeBag>& safebags = aSafeContntBag.SafeBags();  
       
   553 	// Get the safe bag count
       
   554 	TInt safeBagCount = safebags.Count();
       
   555 	//Create a CSafeContentBag , store the bag number and the number of bags in it,append it in the array
       
   556 	CSafeContentBag* safecontentbag = CSafeContentBag::NewL() ;	
       
   557 	if(safecontentbag)
       
   558 		{
       
   559 		safecontentbag->SetBagNumber(iPkcs12Header->SafecontentBagCount()) ; 
       
   560 		safecontentbag->SetSafeBagCount(safeBagCount) ;
       
   561 		CleanupStack::PushL(&iArraySafecontentBag);
       
   562 		iArraySafecontentBag.AppendL(safecontentbag) ;
       
   563 		CleanupStack::Pop(&iArraySafecontentBag);
       
   564 		}
       
   565 	if(safeBagCount>0) 
       
   566 		{				
       
   567 		TInt loopindex = 0 ;
       
   568 		while(loopindex < safeBagCount )
       
   569 			{
       
   570 			ParseSafeBagL(aContentinfo ,aContentType, *(safebags[loopindex]));
       
   571 			loopindex++;
       
   572 			}//end while
       
   573 		}
       
   574 	}