os/security/cryptoservices/certificateandkeymgmt/tpkcs12intgrtn/src/tpkcs12common.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tpkcs12intgrtn/src/tpkcs12common.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,573 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* This file contains the implementation of the CPkcs12Parser class, to parse the PKCS#12 file.
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file 
    1.25 + @internalTechnology
    1.26 +*/
    1.27 +
    1.28 +// System Include
    1.29 +#include <f32file.h>
    1.30 +
    1.31 +//User Include 
    1.32 +#include "tpkcs12common.h"
    1.33 +using namespace PKCS12;
    1.34 +/**
    1.35 +Description:constructor
    1.36 +@internalTechnology:
    1.37 +@test
    1.38 +*/
    1.39 +CPkcs12Parser::CPkcs12Parser()
    1.40 +	{
    1.41 +	}
    1.42 +/**
    1.43 +Description:destructor
    1.44 +@internalTechnology:
    1.45 +@test
    1.46 +*/
    1.47 +CPkcs12Parser::~CPkcs12Parser()
    1.48 +	{
    1.49 +	delete iIntegrityPassword;	
    1.50 +	delete iRawData;	
    1.51 +	delete iPkcs12Header;
    1.52 +	iArraySafecontentBag.ResetAndDestroy();
    1.53 +	iArrayBagData.ResetAndDestroy();
    1.54 +	}
    1.55 +
    1.56 +/**
    1.57 +Description:Function is intended to creates a new CPKCS12Parser object.	 
    1.58 +@return:CPKCS12Parser* : parser object to parse the PKCS12 file
    1.59 +@internalTechnology
    1.60 +@test
    1.61 +*/
    1.62 +CPkcs12Parser* CPkcs12Parser::NewL()
    1.63 +	{	
    1.64 +	CPkcs12Parser* parser = NewLC();
    1.65 +	CleanupStack::Pop(parser);	
    1.66 +	return parser;
    1.67 +	}
    1.68 +/**
    1.69 +Description:Function is intended to creates a new CPKCS12Parser object.	 
    1.70 +@return:CPKCS12Parser* : parser object to parse the PKCS12 file
    1.71 +@test
    1.72 +*/
    1.73 +CPkcs12Parser* CPkcs12Parser::NewLC()
    1.74 +	{	
    1.75 +	CPkcs12Parser* parser = new (ELeave) CPkcs12Parser();
    1.76 +	CleanupStack::PushL(parser);	
    1.77 +	return parser;
    1.78 +	}
    1.79 +/**
    1.80 +Description:Function is intended to set the integrity password 
    1.81 +@param	aIntegrityPassword, contains the integrity password
    1.82 +@internalTechnology
    1.83 +@test
    1.84 +*/
    1.85 +void CPkcs12Parser::SetIntegrityPasswordL(const TDesC& aIntegrityPassword)
    1.86 +	{
    1.87 +	iIntegrityPassword = aIntegrityPassword.AllocL();
    1.88 +	}
    1.89 +
    1.90 +/**
    1.91 +Description:Function is intended to set the privacy password(s) 
    1.92 +@param aPrivacyPassword, contains  the privacy passwords.The ownership is not transferred
    1.93 +@internalTechnology
    1.94 +@test
    1.95 +*/
    1.96 +void CPkcs12Parser::SetPrivacyPassword(RPointerArray<TDesC>& aPrivacyPassword)
    1.97 +	{
    1.98 +	iPrivacyPassword = 	&aPrivacyPassword;
    1.99 +	}
   1.100 +/**
   1.101 +Description:Function is intended to set the test data. 
   1.102 +			It opens the data file and stores it in the buffer.
   1.103 +@param aDatapath, contains the path of the PKCS12 file
   1.104 +@internalTechnology
   1.105 +@test
   1.106 +*/
   1.107 +void CPkcs12Parser::SetDataL(const TDesC& aDatapath)
   1.108 +	{ 	
   1.109 +	if(iRawData)
   1.110 +		{
   1.111 +		delete iRawData ;
   1.112 +		iRawData  = NULL;
   1.113 +		}
   1.114 +	RFs fs;
   1.115 +	//connects the file server
   1.116 +	User::LeaveIfError (fs.Connect());
   1.117 +	//opens the data file
   1.118 +	CleanupClosePushL(fs);
   1.119 +	RFile file;
   1.120 +	User::LeaveIfError(file.Open(fs, aDatapath, EFileRead)) ; 
   1.121 +	CleanupClosePushL(file);
   1.122 +	
   1.123 +	TInt fileSize = 0;
   1.124 +	User::LeaveIfError(file.Size(fileSize));	
   1.125 +
   1.126 +	iRawData = HBufC8::NewL(fileSize);
   1.127 +	TPtr8 rawData(iRawData->Des());
   1.128 +	rawData.SetLength(fileSize);	
   1.129 +	file.Read (rawData);
   1.130 +
   1.131 +	CleanupStack::PopAndDestroy(&file);
   1.132 +	//closes the file session
   1.133 +	CleanupStack::PopAndDestroy(&fs);
   1.134 +	}
   1.135 +/**
   1.136 +Description:Function is intended to parse the PKCS#12 data
   1.137 +@leave:- if the number of contentinfos and number of privacy passwords does not match.	
   1.138 +@internalTechnology
   1.139 +@test
   1.140 +*/
   1.141 +void CPkcs12Parser::ParseL()
   1.142 +	{
   1.143 +	//creates the CDecPkcs12 object		
   1.144 +	CDecPkcs12* decPkcs12 = NULL;
   1.145 +	TRAPD(error, decPkcs12	= CDecPkcs12::NewL(*iRawData));
   1.146 +	if(error == KErrNone)
   1.147 +		CleanupStack::PushL(decPkcs12);	
   1.148 +
   1.149 +	//Creates a CPfxHeader object
   1.150 +	iPkcs12Header = CPfxHeader::NewL(*decPkcs12 , error);	
   1.151 +	if(error != KErrNone)
   1.152 +		{
   1.153 +		
   1.154 +		return ;	
   1.155 +		}
   1.156 +	const CDecPkcs12MacData* macData = decPkcs12->MacData();
   1.157 +	TRAPD(err,macData->VerifyIntegrityL(iIntegrityPassword->Des()));
   1.158 +	if(err)
   1.159 +		{
   1.160 +		iPkcs12Header->SetPkcs12ActualError(err);
   1.161 +		CleanupStack::PopAndDestroy(decPkcs12);
   1.162 +		return;
   1.163 +		}
   1.164 +	//get the ContentInfo collection
   1.165 +	const RPointerArray<CPKCS7ContentInfo>& contentInfos = decPkcs12->AuthenticatedSafeContents();	
   1.166 +	TInt contentInfoCount = contentInfos.Count();
   1.167 +	//put the content info count in the Header
   1.168 +	iPkcs12Header->SetContentInfoCount(contentInfoCount) ;
   1.169 +
   1.170 +	// start iterate through the contentinfos
   1.171 +	for(TInt index = 0 ; index < contentInfoCount; index++)
   1.172 +		{
   1.173 +		TInt contentType = contentInfos[index]->ContentType() ; 
   1.174 +		TPtrC8 contentData = contentInfos[index]->ContentData();
   1.175 +		if( contentData == KNullDesC8()) 
   1.176 +			{
   1.177 +			iPkcs12Header->SetPkcs12ActualError(0);
   1.178 +			continue;
   1.179 +			}
   1.180 +		CDecPkcs12SafeContents* pkcs12SafeContents = NULL;			
   1.181 +		switch(contentType)
   1.182 +			{
   1.183 +			case CPKCS7ContentInfo::EContentTypeData:
   1.184 +				{
   1.185 +				TRAPD(error1,pkcs12SafeContents = CDecPkcs12SafeContents::NewL(*contentInfos[index]));	
   1.186 +				if(error1)
   1.187 +					{
   1.188 +					iPkcs12Header->SetPkcs12ActualError(error1);
   1.189 +					CSafeBagData* bagData = NULL; 
   1.190 +					bagData = CreateBagDataL(index,contentType);
   1.191 +					iArrayBagData.AppendL(bagData) ;
   1.192 +					CleanupStack::PopAndDestroy(decPkcs12);
   1.193 +					return;
   1.194 +					}	
   1.195 +				CleanupStack::PushL(pkcs12SafeContents);			
   1.196 +				break;
   1.197 +				}
   1.198 +			case CPKCS7ContentInfo::EContentTypeEncryptedData:
   1.199 +				{
   1.200 +				if(contentInfoCount != iPrivacyPassword->Count())	
   1.201 +					{
   1.202 +					User::Leave(KErrArgument);
   1.203 +					}
   1.204 +						
   1.205 +				TRAPD(error2,pkcs12SafeContents = CDecPkcs12SafeContents::NewL(*contentInfos[index],
   1.206 +																	*((*iPrivacyPassword)[index]) ) );
   1.207 +				if(error2)
   1.208 +					{
   1.209 +					iPkcs12Header->SetPkcs12ActualError(error2);
   1.210 +					CSafeBagData* bagData = NULL; 
   1.211 +					bagData = CreateBagDataL(index,contentType);
   1.212 +					iArrayBagData.AppendL(bagData) ;
   1.213 +					CleanupStack::PopAndDestroy(decPkcs12);
   1.214 +					return;
   1.215 +					}							
   1.216 +				CleanupStack::PushL(pkcs12SafeContents);	
   1.217 +				break;							
   1.218 +				}
   1.219 +			case CPKCS7ContentInfo::EContentTypeEnvelopedData:
   1.220 +				{
   1.221 +				//creates a Bagdata object in the heap to store the content type. 
   1.222 +				CSafeBagData* bagData = CreateBagDataL(index+1 ,contentType);
   1.223 +				iArrayBagData.AppendL(bagData) ;
   1.224 +				//continue in the loop
   1.225 +				continue;
   1.226 +				}
   1.227 +
   1.228 +			default:
   1.229 +				{	
   1.230 +				//continue in the loop
   1.231 +				continue;
   1.232 +				}
   1.233 +			}
   1.234 +		// Get the safebags count.
   1.235 +		const RPointerArray<CDecPkcs12SafeBag>& safeBags = pkcs12SafeContents->SafeContentsBags();
   1.236 +		TInt safeBagCount = safeBags.Count();
   1.237 +	
   1.238 +		
   1.239 +		//start parsing the bags
   1.240 +		for (TInt bagsCount=0; bagsCount < safeBagCount; bagsCount++)
   1.241 +			{	
   1.242 +			TRAPD(error3,ParseSafeBagL(index+1, contentType , *safeBags[bagsCount]));
   1.243 +			if(error3 != KErrNone)
   1.244 +				{
   1.245 +				iPkcs12Header->SetPkcs12ActualError(error3);
   1.246 +				CSafeBagData* bagData = NULL; 
   1.247 +				bagData = CreateBagDataL(index,contentType);
   1.248 +				iArrayBagData.AppendL(bagData) ;
   1.249 +				CleanupStack::PopAndDestroy(2,decPkcs12);
   1.250 +				return;
   1.251 +				}	
   1.252 +			}	
   1.253 +			CleanupStack::PopAndDestroy(pkcs12SafeContents);
   1.254 +		}		
   1.255 +	CleanupStack::PopAndDestroy(decPkcs12);	
   1.256 +
   1.257 +	}
   1.258 +
   1.259 +/**
   1.260 +Description: Creates a CSafeBagData to store the safebag details
   1.261 +@param:aContentInfo, the contentinfo number of the safe bag 
   1.262 +@param:aContentType, the content type of the safe contents.
   1.263 +@return:a pointer to CSafeBagData, which is used to store the safebag details 
   1.264 +@internalTechnology:
   1.265 +@test:
   1.266 +*/
   1.267 +CSafeBagData* CPkcs12Parser::CreateBagDataL(TInt aContentInfo, TInt aContentType)
   1.268 +	{
   1.269 +	CSafeBagData* bagData = CSafeBagData::NewL();	
   1.270 +	if ( iPkcs12Header->Pkcs12ActualError() == KErrNone )
   1.271 +		{
   1.272 +		//set the contentinfo # and content type in CSafeBagData
   1.273 +		bagData->SetContentInfoNumber(aContentInfo);	
   1.274 +		bagData->SetBagNumber(++iSafebagNumber );	
   1.275 +		// set the content type in CSafeBagData		
   1.276 +		bagData->SetContentInfoType(aContentType);
   1.277 +		}
   1.278 +	return bagData ;
   1.279 +	}
   1.280 +
   1.281 +/**
   1.282 +Description:To parse the safebags
   1.283 +@param:aContentInfoIndex	content info number
   1.284 +@param:aContentType	contentinfo type
   1.285 +@param:aSafeBag	reference to the CDecPkcs12SafeBag 
   1.286 +@internalTechnology:
   1.287 +@test:
   1.288 +*/
   1.289 +void CPkcs12Parser::ParseSafeBagL(TInt aContentInfo,TInt aContentType,CDecPkcs12SafeBag& aSafeBag)
   1.290 +	{
   1.291 +	//get the bag type 
   1.292 +	CDecPkcs12SafeBag::TBagId bagType = aSafeBag.BagID();
   1.293 +	switch(bagType)
   1.294 +		{
   1.295 +		case CDecPkcs12SafeBag::ESafeContentsBag:
   1.296 +			{
   1.297 +			CDecPkcs12SafeContentsBag* safeContentsBag = static_cast<CDecPkcs12SafeContentsBag *>(&aSafeBag);
   1.298 +			// increment the count
   1.299 +			iPkcs12Header->IncrementSafecontentBagCount();
   1.300 +			// parsing code to parse SafeContentsBag		
   1.301 +			ParseSafeContentBagL(*safeContentsBag, aContentInfo ,aContentType );
   1.302 +			break;
   1.303 +			}
   1.304 +		case CDecPkcs12SafeBag::EKeyBag:
   1.305 +			{
   1.306 +			CDecPkcs12KeyBag* keyBag = static_cast<CDecPkcs12KeyBag *>(&aSafeBag);					
   1.307 +			//create the CSafeBagData object in heap to store the bag details
   1.308 +			CSafeBagData* bagData = CreateBagDataL(aContentInfo,aContentType);
   1.309 +			CleanupStack::PushL(bagData);			
   1.310 +			ParseKeyBag(*keyBag , *bagData);
   1.311 +			//get the safeBag attributes
   1.312 +			BagAttributesL(*keyBag ,*bagData) ;	
   1.313 +			iArrayBagData.AppendL(bagData) ;
   1.314 +			CleanupStack::Pop(bagData);					
   1.315 +			break;
   1.316 +			}
   1.317 +		case CDecPkcs12SafeBag::EShroudedKeyBag:
   1.318 +			{
   1.319 +			CDecPkcs12ShroudedKeyBag* shroudedkeyBag = static_cast<CDecPkcs12ShroudedKeyBag *>(&aSafeBag);
   1.320 +			//create the CSafeBagData object in heap to store the bag details
   1.321 +			CSafeBagData* bagData = CreateBagDataL(aContentInfo,aContentType );
   1.322 +			CleanupStack::PushL(bagData);			
   1.323 +			ParseShroudedKeyBagL(*shroudedkeyBag , *bagData ,aContentInfo );		
   1.324 +			//get the safeBag attributes
   1.325 +			BagAttributesL(*shroudedkeyBag ,*bagData) ;	
   1.326 +			iArrayBagData.AppendL(bagData) ;	
   1.327 +			CleanupStack::Pop(bagData);			
   1.328 +			break;
   1.329 +			}
   1.330 +		case CDecPkcs12SafeBag::ECertBag:
   1.331 +			{
   1.332 +			CDecPkcs12CertBag* certBag = static_cast<CDecPkcs12CertBag *>(&aSafeBag);					
   1.333 +			//create the CSafeBagData object in heap to store the bag details
   1.334 +			CSafeBagData* bagData = CreateBagDataL(aContentInfo,aContentType);
   1.335 +			CleanupStack::PushL(bagData);		
   1.336 +			ParseCertBag(*certBag , *bagData);
   1.337 +			// Get the bag Attributes
   1.338 +			BagAttributesL(*certBag , *bagData) ;	
   1.339 +			iArrayBagData.AppendL(bagData) ;
   1.340 +			CleanupStack::Pop(bagData);			
   1.341 +			break;
   1.342 +			}
   1.343 +		case CDecPkcs12SafeBag::ECrlBag:
   1.344 +			{
   1.345 +			//create the CSafeBagData object in heap to store the bag details
   1.346 +			CSafeBagData* bagData = CreateBagDataL(aContentInfo,aContentType);;
   1.347 +			CleanupStack::PushL(bagData);				
   1.348 +			//set the bagId in CSafeBagData
   1.349 +			bagData->SetBagType(bagType) ; 
   1.350 +			//increment the count - unsupported
   1.351 +			iPkcs12Header->IncrementCrlBagCount();
   1.352 +			iArrayBagData.AppendL(bagData) ;
   1.353 +			CleanupStack::Pop(bagData);				
   1.354 +			break;
   1.355 +			}
   1.356 +		case CDecPkcs12SafeBag::ESecretBag:
   1.357 +			{
   1.358 +			//create the CSafeBagData object in heap to store the bag details
   1.359 +			CSafeBagData* bagData = CreateBagDataL(aContentInfo,aContentType );	
   1.360 +			CleanupStack::PushL(bagData);
   1.361 +			//set the iBagId in CSafeBagData
   1.362 +			bagData->SetBagType(bagType) ; 
   1.363 +			//increment the count - unsupported
   1.364 +			iPkcs12Header->IncrementSecretBagCount();
   1.365 +			iArrayBagData.AppendL(bagData) ;		
   1.366 +			CleanupStack::Pop(bagData);	
   1.367 +			break;
   1.368 +			}
   1.369 +		default:
   1.370 +			{
   1.371 +			}
   1.372 +		}
   1.373 +	}
   1.374 +
   1.375 +/**
   1.376 +Description:Function is intended to get the attributes of Safebag
   1.377 +@param-aSafeBag: reference to the CDecPkcs12SafeBag.
   1.378 +@param-abagData: reference to the CSafeBagData
   1.379 +@internalTechnology:
   1.380 +@test
   1.381 +*/
   1.382 +void CPkcs12Parser::BagAttributesL(const CDecPkcs12SafeBag& aSafeBag,CSafeBagData& aBagData )
   1.383 +	{
   1.384 +	const RPointerArray<CDecPkcs12Attribute>& safeBagAttributes = aSafeBag.BagAttributes();
   1.385 +
   1.386 +	TInt attributeCount = safeBagAttributes.Count() ;
   1.387 +	for (TInt index = 0;index < attributeCount; index++ )
   1.388 +		{						
   1.389 +		//get the attribute object pointer
   1.390 +		CDecPkcs12Attribute* attribute = safeBagAttributes[index];
   1.391 +		//create the CSafeBagAttribute object in heap.	
   1.392 +		CSafeBagAttribute* bagAttr = CSafeBagAttribute::NewL(*safeBagAttributes[index]);
   1.393 +		CleanupStack::PushL(bagAttr);
   1.394 +		//get the attribute values
   1.395 +		const RPointerArray<TDesC8>& attrValues = attribute->AttributeValue();			
   1.396 +		//append the pointer in the iAttributeIDs array
   1.397 +		aBagData.iAttributeIDs.AppendL(bagAttr) ;
   1.398 +		CleanupStack::Pop(bagAttr);	
   1.399 +		//store the attribute values
   1.400 +		TInt numberOfAttributes = bagAttr->AttributeValueCount();
   1.401 +		for(TInt attrvalCnt = 0 ; attrvalCnt < numberOfAttributes ; attrvalCnt++)
   1.402 +			{
   1.403 +			//get the atribute value and store the it address in the aBagData.iAttributeValues array				
   1.404 +			HBufC8* ptr =  attrValues[attrvalCnt]->AllocLC();								
   1.405 +			aBagData.iAttributeValues.AppendL(ptr);
   1.406 +			CleanupStack::Pop(ptr);
   1.407 +			}			
   1.408 +		}	
   1.409 +	}
   1.410 +/**
   1.411 +Description:Function is intended to parse the  keybag
   1.412 +@param-aKeyBag: reference to the keybag
   1.413 +@param-abagData: reference to the CSafeBagData
   1.414 +@internalTechnology:
   1.415 +@test:
   1.416 +*/
   1.417 +void CPkcs12Parser::ParseKeyBag(CDecPkcs12KeyBag& aKeyBag , CSafeBagData& aBagData)
   1.418 +	{
   1.419 +	//set the bagID
   1.420 +	aBagData.SetBagType( CDecPkcs12SafeBag::EKeyBag ); 				
   1.421 +	// Get the Algorithm(RSA key or DSA key) ID 
   1.422 +	CDecPKCS8Data* pkcs8Data = aKeyBag.PrivateKeyInfoL();				
   1.423 +	aBagData.SetPrivateKeyInfoVersion(pkcs8Data->Version() );
   1.424 +	TAlgorithmId algorithmId = pkcs8Data->Algorithm();
   1.425 +	// Set the Algorithm Id in CSafeBagData
   1.426 +	aBagData.SetKeyType( algorithmId );
   1.427 +	//set the bag value in CSafeBagData
   1.428 +	aBagData.SetBagValue( aKeyBag.BagValue());				
   1.429 +	// increment the count
   1.430 +	iPkcs12Header->IncrementKeyBagCount();
   1.431 +	delete pkcs8Data;
   1.432 +	}
   1.433 +/**
   1.434 +Description:Function is intended to parse the  ShroudedKeyBag
   1.435 +@param-aShroudedkeyBag: pointer to the CDecPkcs12ShroudedKeyBag
   1.436 +@param-abagData: reference to the CSafeBagData
   1.437 +@param- aPassIndex: the index of the array from where the privacy password is to be taken
   1.438 +@internalTechnology:
   1.439 +@test
   1.440 +*/
   1.441 +void CPkcs12Parser::ParseShroudedKeyBagL(CDecPkcs12ShroudedKeyBag& aShroudedkeyBag , CSafeBagData& aBagData , TInt aPassIndex)
   1.442 +	{
   1.443 +	//set the bag Id in CSafeBagData
   1.444 +	aBagData.SetBagType( CDecPkcs12SafeBag::EShroudedKeyBag ); 				
   1.445 +	// Get the Algorithm(RSA key or DSA key) ID 
   1.446 +	CDecPKCS8Data* pkcs8Data = aShroudedkeyBag.PrivateKeyInfoL(*(*iPrivacyPassword)[aPassIndex-1]);
   1.447 +	if(pkcs8Data)
   1.448 +		{
   1.449 +		aBagData.SetPrivateKeyInfoVersion(pkcs8Data->Version() );	
   1.450 +		TAlgorithmId algorithm  = pkcs8Data->Algorithm();	
   1.451 +		// Set the Algorithm Id in CSafeBagData
   1.452 +		aBagData.SetKeyType(algorithm);
   1.453 +	
   1.454 +		CASN1EncSequence* seq = NULL ;
   1.455 +		switch(algorithm)
   1.456 +			{
   1.457 +			case ERSA:
   1.458 +				{	
   1.459 +				
   1.460 +				CPKCS8KeyPairRSA* keypair = static_cast<CPKCS8KeyPairRSA*>(pkcs8Data->KeyPairData());
   1.461 +
   1.462 +				const CRSAPrivateKey& priv = keypair->PrivateKey();
   1.463 +				
   1.464 +				const CRSAPublicKey& publicKey = keypair->PublicKey(); 
   1.465 +				
   1.466 +				TRSAPrivateKeyType keytype = priv.PrivateKeyType();
   1.467 +				
   1.468 +				switch(keytype)
   1.469 +					{
   1.470 +					case EStandardCRT:
   1.471 +						{
   1.472 +						const CRSAPrivateKeyCRT* privateKeyCRT = static_cast<const CRSAPrivateKeyCRT*>(&priv);
   1.473 +						seq =  TASN1EncPKCS8::EncodeL(*privateKeyCRT, publicKey,pkcs8Data->PKCS8Attributes());	
   1.474 +					
   1.475 +						break;
   1.476 +						}					
   1.477 +					case EStandard:		
   1.478 +						{
   1.479 +						User::Leave(KErrNotSupported);
   1.480 +						}
   1.481 +					default:
   1.482 +						{
   1.483 +						User::Leave(KErrNotSupported);	
   1.484 +						}
   1.485 +					}
   1.486 +					
   1.487 +				break;
   1.488 +				}		
   1.489 +			case EDSA:
   1.490 +				{
   1.491 +				
   1.492 +				CPKCS8KeyPairDSA* keypair = static_cast<CPKCS8KeyPairDSA*>(pkcs8Data->KeyPairData());
   1.493 +			
   1.494 +				const CDSAPrivateKey& priv = keypair->PrivateKey();
   1.495 +				
   1.496 +				seq =  TASN1EncPKCS8::EncodeL(priv , pkcs8Data->PKCS8Attributes());
   1.497 +			
   1.498 +				break;
   1.499 +				}			
   1.500 +			default:
   1.501 +				User::Leave(KErrNotSupported);
   1.502 +
   1.503 +			}
   1.504 +	
   1.505 +		HBufC8* bufSeq = HBufC8::NewMaxLC(seq->LengthDER());
   1.506 +		TPtr8 temp(bufSeq->Des());
   1.507 +
   1.508 +		TUint pos = 0;
   1.509 +		seq->WriteDERL(temp ,pos);
   1.510 +			
   1.511 +		aBagData.SetEncodedShroudedKey(temp);
   1.512 +		CleanupStack::PopAndDestroy();
   1.513 +
   1.514 +		delete pkcs8Data;
   1.515 +		}
   1.516 +		//set the bag value in CSafeBagData
   1.517 +		aBagData.SetBagValue(aShroudedkeyBag.BagValue()) ;				
   1.518 +		// increment the count 
   1.519 +		iPkcs12Header->IncrementShroudedKeyBagCount();											
   1.520 +	}
   1.521 +
   1.522 +/**
   1.523 +Description:Function is intended to parse the  certbag
   1.524 +@param-aCertBag: pointer to the CDecPkcs12CertBag
   1.525 +@param-abagData: reference to the CSafeBagData
   1.526 +@internalTechnology:
   1.527 +@test
   1.528 +*/
   1.529 +void CPkcs12Parser::ParseCertBag(CDecPkcs12CertBag& aCertBag , CSafeBagData& aBagData)
   1.530 +	{
   1.531 +	//set the bagID 
   1.532 +	aBagData.SetBagType( CDecPkcs12SafeBag::ECertBag );	
   1.533 +	aBagData.SetCertificateId(aCertBag.CertId()); 		
   1.534 +	//set the bag value in CSafeBagData
   1.535 +	aBagData.SetBagValue(aCertBag.CertValue());
   1.536 +	
   1.537 +	//set the X509Certificate
   1.538 +	aBagData.SetX509Certificate((aCertBag.X509CertificateL()) );
   1.539 +	// increment the count 
   1.540 +	iPkcs12Header->IncrementCertBagCount();			 
   1.541 +	}
   1.542 +
   1.543 +/**
   1.544 +Description:Function is intended to parse the  safecontentbag
   1.545 +@param-safeContentsBag: reference to the CDecPkcs12SafeContentsBag
   1.546 +@param-aContentinfo: contentinfo number
   1.547 +@param- aContentType : contentinfo type
   1.548 +@internalTechnology
   1.549 +@test
   1.550 +*/
   1.551 +void CPkcs12Parser::ParseSafeContentBagL(CDecPkcs12SafeContentsBag& aSafeContntBag, TInt aContentinfo , TInt aContentType )
   1.552 +	{	
   1.553 +	const RPointerArray<CDecPkcs12SafeBag>& safebags = aSafeContntBag.SafeBags();  
   1.554 +	// Get the safe bag count
   1.555 +	TInt safeBagCount = safebags.Count();
   1.556 +	//Create a CSafeContentBag , store the bag number and the number of bags in it,append it in the array
   1.557 +	CSafeContentBag* safecontentbag = CSafeContentBag::NewL() ;	
   1.558 +	if(safecontentbag)
   1.559 +		{
   1.560 +		safecontentbag->SetBagNumber(iPkcs12Header->SafecontentBagCount()) ; 
   1.561 +		safecontentbag->SetSafeBagCount(safeBagCount) ;
   1.562 +		CleanupStack::PushL(&iArraySafecontentBag);
   1.563 +		iArraySafecontentBag.AppendL(safecontentbag) ;
   1.564 +		CleanupStack::Pop(&iArraySafecontentBag);
   1.565 +		}
   1.566 +	if(safeBagCount>0) 
   1.567 +		{				
   1.568 +		TInt loopindex = 0 ;
   1.569 +		while(loopindex < safeBagCount )
   1.570 +			{
   1.571 +			ParseSafeBagL(aContentinfo ,aContentType, *(safebags[loopindex]));
   1.572 +			loopindex++;
   1.573 +			}//end while
   1.574 +		}
   1.575 +	}
   1.576 +