os/security/cryptoservices/certificateandkeymgmt/tpkcs12intgrtn/src/tpkcs12libteststep.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tpkcs12intgrtn/src/tpkcs12libteststep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1429 @@
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 is used for the verification function of the pkcs12 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 <test/testexecutelog.h>
1.30 +
1.31 +//User Include
1.32 +#include "tpkcs12libteststep.h"
1.33 +#include "tpkcs12data.h"
1.34 +#include "tpkcs12common.h"
1.35 +
1.36 +using namespace PKCS12;
1.37 +
1.38 +const TInt KBagDataLength = 7;
1.39 +const TInt KContentInfoLength = 11;
1.40 +/**
1.41 +Description:constructor:used for initialization of the variables declared
1.42 +@test
1.43 +@internalTechnology
1.44 +*/
1.45 +CPKCS12LibTestStep::CPKCS12LibTestStep()
1.46 + {
1.47 + iActualResult=ETrue;
1.48 + iUnitTest=EFalse;
1.49 + iUnitTestContinueFlag = ETrue;
1.50 + iExpectedError = ETrue;
1.51 + iExpectedResult=KPositiveTest;
1.52 + }
1.53 +/**
1.54 +Description:Destructor
1.55 +@test
1.56 +@internalTechnology
1.57 +*/
1.58 +CPKCS12LibTestStep::~CPKCS12LibTestStep()
1.59 + {
1.60 + iFileSession.Close();
1.61 + delete iParser;
1.62 + iPrivacyPassword.ResetAndDestroy();
1.63 + }
1.64 +
1.65 +/**
1.66 +Function is intended to parse the pkcs12 file, compare the results and
1.67 +log the same
1.68 +@internalTechnology:
1.69 +@return:TVerdict -returns EFail if there is a failure else EPass
1.70 +@test
1.71 +@leave:- if memory allocation fails
1.72 +*/
1.73 +TVerdict CPKCS12LibTestStep::doTestStepL()
1.74 + {
1.75 + //__UHEAP_MARK;
1.76 + TPtrC integrityMode(KNullDesC);
1.77 + TPtrC integrityPassword(KNullDesC);
1.78 + TPtrC privacyPassword(KNullDesC);
1.79 + TPtrC dataPath(KNullDesC);
1.80 + TBool flagReturn=ETrue;
1.81 +
1.82 +
1.83 + if(iFileSession.Connect())
1.84 + {
1.85 + INFO_PRINTF1(_L("File server session failed"));
1.86 + flagReturn=EFalse;
1.87 + }
1.88 +
1.89 + if(flagReturn)
1.90 + {
1.91 + if((!GetStringFromConfig(KMainSec,KFilePath,dataPath)) ||
1.92 + !GetStringFromConfig(KMainSec,KIntegrityMode,integrityMode))
1.93 + {
1.94 + SetTestStepResult(EAbort);
1.95 + ERR_PRINTF1(_L("Input Data not found in ini file"));
1.96 + flagReturn=EFalse;
1.97 + }
1.98 + }
1.99 + //Check the input
1.100 + if(flagReturn)
1.101 + {
1.102 + if(!GetBoolFromConfig(KMainSec,KUnitTest,iUnitTest))
1.103 + {
1.104 + iUnitTest=EFalse;
1.105 + }
1.106 + //Password Integrity Mode
1.107 + if(integrityMode.CompareF(KPassword)==0)
1.108 + {
1.109 + if(!GetStringFromConfig(KMainSec,KIntegrityPassword,integrityPassword))
1.110 + {
1.111 + ERR_PRINTF1(_L("Problem in the Main section of the ini file"));
1.112 + SetTestStepResult(EFail);
1.113 + flagReturn=EFalse;
1.114 + }
1.115 + else
1.116 + {
1.117 +
1.118 + iParser = CPkcs12Parser::NewL();
1.119 + // set the integrity password
1.120 + iParser->SetIntegrityPasswordL(integrityPassword);
1.121 + // set the datapath
1.122 + iParser->SetDataL(dataPath);
1.123 + //set the privacy password
1.124 + ParsePrivacyPwdL();
1.125 + //parse the pkcs12 file
1.126 + iParser->ParseL();
1.127 +
1.128 + if(!GetBoolFromConfig(KMainSec,KIntegrityValid,iExpectedResult))
1.129 + {
1.130 + WARN_PRINTF1(_L("Integrity valid not found in ini file"));
1.131 + iExpectedResult=KPositiveTest;
1.132 + }
1.133 + if(!VerifyMainSecL())
1.134 + {
1.135 + ERR_PRINTF1(_L("Main section failed"));
1.136 + flagReturn=EFalse;
1.137 + }
1.138 + else if(!iUnitTestContinueFlag)
1.139 + {
1.140 + SetTestStepResult(EPass);
1.141 + delete iParser;
1.142 + iParser = NULL;
1.143 + flagReturn = EFalse;
1.144 + }
1.145 + }
1.146 + }
1.147 + else if(integrityMode.CompareF(KPublicIntegrity)==0)
1.148 + {
1.149 + //public Integrity Mode
1.150 + }
1.151 + else
1.152 + {
1.153 + ERR_PRINTF1(_L("Integrity pwd not known in ini file"));
1.154 + SetTestStepResult(EFail);
1.155 + flagReturn=EFalse;
1.156 + }
1.157 + }
1.158 + if(flagReturn)
1.159 + {
1.160 + //Check the Authenticated safe section
1.161 + if(!VerifyAuthSafe())
1.162 + {
1.163 + ERR_PRINTF1(_L("Authenticated safe section failed"));
1.164 + SetTestStepResult(EFail);
1.165 + flagReturn=EFalse;
1.166 + }
1.167 + else if(!iUnitTestContinueFlag )
1.168 + {
1.169 + SetTestStepResult(EPass);
1.170 + delete iParser;
1.171 + iParser = NULL;
1.172 + flagReturn = EFalse;
1.173 + }
1.174 + }
1.175 + if(flagReturn)
1.176 + {
1.177 + //calculate the totalsafebags in the pkcs12 file
1.178 + TInt totalsafebags = iParser->PfxHeader().TotalSafeBagCount();
1.179 +
1.180 + //calculate the totalbags(including the safecontentsbag) in the pkcs12 file
1.181 + TInt totalbags = totalsafebags + iParser->PfxHeader().SafecontentBagCount();
1.182 +
1.183 + //Check the BagData section
1.184 + if(!ChkBagDataL(totalsafebags,totalbags))
1.185 + {
1.186 + ERR_PRINTF1(_L("Bag Data section failed"));
1.187 + SetTestStepResult(EFail);
1.188 + flagReturn=EFalse;
1.189 + }
1.190 + else if(!iUnitTestContinueFlag)
1.191 + {
1.192 + delete iParser;
1.193 + iParser = NULL;
1.194 + flagReturn = EFalse;
1.195 + }
1.196 + }
1.197 + if(flagReturn)
1.198 + {
1.199 + SetTestStepResult(EPass);
1.200 + }
1.201 +
1.202 + //__UHEAP_MARKEND;
1.203 + return TestStepResult();
1.204 + }
1.205 +/**
1.206 +Function is intended to verify the expected error in each section of the ini file
1.207 +@internalTechnology:
1.208 +@return:TBool:returns EFalse if there is a failure else ETrue
1.209 +@test:
1.210 +*/
1.211 +TBool CPKCS12LibTestStep::VerifyExpectedError(const TDesC& aSecName)
1.212 + {
1.213 + TBool flagReturn = ETrue;
1.214 + if ( iUnitTest )
1.215 + {
1.216 + if(GetIntFromConfig(aSecName,KExpectedError,iExpectedError)==EFalse)
1.217 + {
1.218 + INFO_PRINTF1(_L("ExpectedError not found in INI File"));
1.219 + }
1.220 + // Checks the error returned by the library with the expected error read
1.221 + // from the INI file.
1.222 + TInt actualError = 0;
1.223 +
1.224 + if ( (!aSecName.Compare(KMainSec) || !aSecName.Compare(KAuthSafeSec) ||
1.225 + !aSecName.Compare(_L("MacData")) || (!aSecName.Left(KBagDataLength).Compare(KBagDataSec)) ||
1.226 + (!aSecName.Left(KContentInfoLength).CompareF(KContentInfoKey))) && !iExpectedResult )
1.227 + {
1.228 + actualError = iParser->PfxHeader().Pkcs12ActualError();
1.229 + }
1.230 + if (actualError == iExpectedError)
1.231 + {
1.232 + INFO_PRINTF1(_L("ExpectedError matchs"));
1.233 + iUnitTestContinueFlag = EFalse;
1.234 + iExpectedResult = ETrue;
1.235 + }
1.236 + }
1.237 +
1.238 + if(iExpectedResult!=iActualResult)
1.239 + {
1.240 + SetTestStepResult(EFail);
1.241 + flagReturn= EFalse;
1.242 + }
1.243 + iActualResult = ETrue;
1.244 + return flagReturn;
1.245 + }
1.246 +/**
1.247 +Function is intended to set the privacy passwords of the contentinfotype
1.248 +@internalTechnology:
1.249 +@test:
1.250 +@leave: if leave occurs if memory allocation fails
1.251 +*/
1.252 +void CPKCS12LibTestStep::ParsePrivacyPwdL()
1.253 + {
1.254 + TPtrC pass(KNullDesC);
1.255 + //to append the number to get the actual key value
1.256 + TInt count=0;
1.257 + //return value
1.258 + TBool privacyPwdPresent=EFalse;
1.259 +
1.260 + //Put all the content info privacy passwords in an array
1.261 + do
1.262 + {
1.263 + TBuf<KPrivacyPwdStrLen> privacyPwdBuf(KPrivacyPassword);
1.264 + pass.Set(KNullDesC);
1.265 + count++;
1.266 + //appending the count to the Keyvalue
1.267 + privacyPwdBuf.AppendNum(count);
1.268 + privacyPwdPresent=GetStringFromConfig(KMainSec,privacyPwdBuf,pass);
1.269 + if(privacyPwdPresent)
1.270 + {
1.271 + HBufC *temp=pass.AllocLC();
1.272 + iPrivacyPassword.AppendL(temp);
1.273 + CleanupStack::Pop(temp);
1.274 + }
1.275 + }while(privacyPwdPresent);
1.276 + iParser->SetPrivacyPassword(iPrivacyPassword);
1.277 + }
1.278 +/**
1.279 +Function is intended to parse the main section of the ini file
1.280 +@internalTechnology:
1.281 +@return:returns EFalse if there is a failure else ETrue
1.282 +@test:
1.283 +*/
1.284 +TBool CPKCS12LibTestStep::VerifyMainSecL()
1.285 + {
1.286 + TBool mac=EFalse;
1.287 + TBool flagReturn=ETrue;
1.288 +
1.289 + //retrieve the expected result:PositiveTest/NegativeTest
1.290 + if(!GetBoolFromConfig(KMainSec,KExpectedResult,iExpectedResult))
1.291 + {
1.292 + WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.293 + iExpectedResult=KPositiveTest;
1.294 + }
1.295 + if(!GetBoolFromConfig(KMainSec,KMacPresent,mac))
1.296 + {
1.297 + WARN_PRINTF1(_L("Mac present not found in ini file"));
1.298 + //default only integration test
1.299 + mac=EFalse;
1.300 + }
1.301 + else if(mac && iUnitTest)
1.302 + {
1.303 + //call the mac data function and check for all the macdata section values
1.304 + iActualResult=ChkMacValueL();
1.305 + if (!iUnitTestContinueFlag)
1.306 + {
1.307 + return flagReturn;
1.308 + }
1.309 + }
1.310 + if(!VerifyExpectedError(KMainSec))
1.311 + {
1.312 + SetTestStepResult(EFail);
1.313 + flagReturn = EFalse;
1.314 + }
1.315 + return flagReturn;
1.316 + }
1.317 +/**
1.318 +Function is intended to parse the AuthSafe section of the ini file
1.319 +@internalTechnology:
1.320 +@return:returns EFalse if there is a failure else ETrue
1.321 +@test:
1.322 +*/
1.323 +TBool CPKCS12LibTestStep::VerifyAuthSafe()
1.324 + {
1.325 + TInt contentInfoCount=0;
1.326 + TPtrC contentSection(KNullDesC);
1.327 + TInt contentIndex=0;
1.328 + TBool flagReturn=ETrue;
1.329 +
1.330 + if(!GetIntFromConfig(KAuthSafeSec,KContentInfoNum,contentInfoCount))
1.331 + {
1.332 + ERR_PRINTF1(_L("Count not available in the inifile"));
1.333 + SetTestStepResult(EFail);
1.334 + flagReturn=EFalse;
1.335 + }
1.336 + //retrieve the expected result:PositiveTest/NegativeTest
1.337 + if(GetIntFromConfig(KAuthSafeSec,KExpectedResult,iExpectedResult)==EFalse)
1.338 + {
1.339 + INFO_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.340 + }
1.341 + //verify positive or negative test
1.342 + if(!VerifyExpectedError(KAuthSafeSec()))
1.343 + {
1.344 + INFO_PRINTF1(_L("Content Info Failure"));
1.345 + SetTestStepResult(EFail);
1.346 + flagReturn = EFalse;
1.347 + }
1.348 + else if(!iUnitTestContinueFlag)
1.349 + {
1.350 + return flagReturn;
1.351 + }
1.352 + for(TInt i=1;i<=contentInfoCount;i++)
1.353 + {
1.354 + TBuf<KContentInfoBufLen> contentBuf(KContentInfoKey);
1.355 + //Append the counter to the keyname
1.356 + contentBuf.AppendNum(i);
1.357 + if(!GetStringFromConfig(KAuthSafeSec,contentBuf,contentSection))
1.358 + {
1.359 + ERR_PRINTF1(_L("ContentSection not available in the inifile"));
1.360 + SetTestStepResult(EFail);
1.361 + flagReturn=EFalse;
1.362 + break;
1.363 + }
1.364 + //retrieve the expected result:PositiveTest/NegativeTest
1.365 + if(GetIntFromConfig(contentSection,KExpectedResult,iExpectedResult)==EFalse)
1.366 + {
1.367 + INFO_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.368 + iExpectedResult=KPositiveTest;
1.369 + }
1.370 + // Verify before calling array to access the data.
1.371 + if(!VerifyExpectedError(contentSection))
1.372 + {
1.373 + INFO_PRINTF1(_L("Content Info Failure"));
1.374 + SetTestStepResult(EFail);
1.375 + flagReturn = EFalse;
1.376 + break;
1.377 + }
1.378 + else if(!iUnitTestContinueFlag)
1.379 + {
1.380 + flagReturn = ETrue;
1.381 + break;
1.382 + }
1.383 + //Call the function for checking the contentinfo,pass the contntsction as parameter
1.384 + iBagData=iParser->ArraySafeBagData()[contentIndex];
1.385 + contentIndex++;
1.386 + //Check the contentinfo type
1.387 + iActualResult=ChkCIType(contentSection,*iBagData);
1.388 + }
1.389 + return flagReturn;
1.390 + }
1.391 +/**
1.392 +Function is intended to parse the BagData section of the ini file
1.393 +@param-aTotalsafebags:total number of safebags
1.394 +@param-aTotalbags:total number of bags including the safecontentbags
1.395 +@internalTechnology:
1.396 +@return:returns EFalse if there is a failure else return ETrue
1.397 +@test:
1.398 +@leave: if leave occurs at the ChkBagValL function
1.399 +*/
1.400 +TBool CPKCS12LibTestStep::ChkBagDataL(TInt aTotalsafebags,TInt aTotalbags)
1.401 + {
1.402 + TInt bagType=0;
1.403 + TInt safeContentIndex=0;
1.404 + TInt safeBagIndex=0;
1.405 + CSafeContentBag* safeContentBag;
1.406 + TBool flagReturn=ETrue;
1.407 +
1.408 + TInt totalSafeContentsBag = iParser->PfxHeader().SafecontentBagCount();
1.409 +
1.410 +
1.411 + //loop for the totalbags
1.412 + for(TInt bags=0;bags<aTotalbags;bags++)
1.413 + {
1.414 + TBuf<KBagDataSecBufLen> bagSection(KBagDataSec);
1.415 + //Append the bags to the sectionname :BagData1
1.416 + bagSection.AppendNum(bags+1);
1.417 + if(!GetIntFromConfig(bagSection,KBagType,bagType))
1.418 + {
1.419 + ERR_PRINTF1(_L("Not able to get the BagType from the ini file"));
1.420 + flagReturn=EFalse;
1.421 + break;
1.422 + }
1.423 + if(bagType == CDecPkcs12SafeBag::ESafeContentsBag && flagReturn)
1.424 + {
1.425 + //loop for the safecontents bags
1.426 + while(safeContentIndex < totalSafeContentsBag && flagReturn)
1.427 + {
1.428 + safeContentBag=iParser->ArraySafeContentBag()[safeContentIndex];
1.429 + if(!ChkSafeContsBagData(bagSection,*safeContentBag))
1.430 + {
1.431 + ERR_PRINTF1(_L("SafeContent Bag Failed"));
1.432 + flagReturn=EFalse;
1.433 + }
1.434 + safeContentIndex++;
1.435 + break;
1.436 + }
1.437 + }
1.438 + else
1.439 + {
1.440 + while(safeBagIndex < aTotalsafebags && flagReturn)
1.441 + {
1.442 + //retrieve the safebag sructure pointer
1.443 + iBagData=iParser->ArraySafeBagData()[safeBagIndex];
1.444 + //Chk the BagType
1.445 + if(!ChkBagType(bagSection,*iBagData,bagType))
1.446 + {
1.447 + ERR_PRINTF1(_L("Bag Type does not match"));
1.448 + flagReturn=EFalse;
1.449 + break;
1.450 + }
1.451 + if(!iUnitTestContinueFlag)
1.452 + {
1.453 + break;
1.454 + }
1.455 + iBagAttrNumVal=0;
1.456 + if(!ChkBagAttbutesL(bagSection,*iBagData))
1.457 + {
1.458 + ERR_PRINTF1(_L("Failure in Attributes"));
1.459 + flagReturn=EFalse;
1.460 + break;
1.461 + }
1.462 + switch(bagType)
1.463 + {
1.464 + case CDecPkcs12SafeBag::ECertBag:
1.465 + {
1.466 + //check the bagvalue
1.467 + if(!ChkBagValL(bagSection,*iBagData))
1.468 + {
1.469 + flagReturn=EFalse;
1.470 + ERR_PRINTF1(_L("Certificate Bag Value comparison Failed"));
1.471 + }
1.472 + //check the certificate type
1.473 + if(flagReturn)
1.474 + {
1.475 + if(!ChkCertId(bagSection,*iBagData))
1.476 + {
1.477 + flagReturn=EFalse;
1.478 + ERR_PRINTF1(_L("Certificate Bag certID comparison Failed"));
1.479 + }
1.480 + }
1.481 + break;
1.482 + }
1.483 + case CDecPkcs12SafeBag::EKeyBag:
1.484 + {
1.485 + if(!ChkBagValL(bagSection,*iBagData))
1.486 + {
1.487 + flagReturn = EFalse;
1.488 + ERR_PRINTF1(_L("Key Bag Failed"));
1.489 + }
1.490 + break;
1.491 + }
1.492 + case CDecPkcs12SafeBag::EShroudedKeyBag:
1.493 + {
1.494 + if(!ChkEncodedBagValL(bagSection,*iBagData))
1.495 + {
1.496 + flagReturn = EFalse;
1.497 + ERR_PRINTF1(_L("Shrouded Bag Failed"));
1.498 + }
1.499 + break;
1.500 + }
1.501 + case CDecPkcs12SafeBag::ECrlBag:
1.502 + {
1.503 + break;
1.504 + }
1.505 + case CDecPkcs12SafeBag::ESecretBag:
1.506 + {
1.507 + break;
1.508 + }
1.509 + }
1.510 + if(flagReturn)
1.511 + {
1.512 + safeBagIndex++;
1.513 + break;
1.514 + }
1.515 + }
1.516 + }
1.517 + }
1.518 +
1.519 + return flagReturn;
1.520 + }
1.521 +/**
1.522 +Function is intended to check the safecontents bag
1.523 +@param-aSec:BagData Section
1.524 +@param-aSfContBag:safecontent class pointer
1.525 +@internalTechnology:
1.526 +@return:returns EFalse if there is a failure else return ETrue
1.527 +@test:
1.528 +*/
1.529 +TBool CPKCS12LibTestStep::ChkSafeContsBagData(TDesC& aSec,CSafeContentBag &aSfContBag)
1.530 + {
1.531 + TInt safeContentsCount=0;
1.532 + TBool flagReturn=ETrue;
1.533 + //retrieve the safecontentsbag count from ini file
1.534 + if(!GetIntFromConfig(aSec,KSafeBagsCount,safeContentsCount))
1.535 + {
1.536 + ERR_PRINTF1(_L("SafeContent Bags count not found in INI file"));
1.537 + SetTestStepResult(EFail);
1.538 + flagReturn=EFalse;
1.539 + }
1.540 + //compare the data with the ini file data
1.541 + if(safeContentsCount != aSfContBag.SafeBagCount() && flagReturn)
1.542 + {
1.543 + ERR_PRINTF1(_L("Number of Bags in the safecontent bag is different"));
1.544 + iActualResult=EFalse;
1.545 + }
1.546 + //retrieve the expected result:PositiveTest/NegativeTest
1.547 + if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult))
1.548 + {
1.549 + INFO_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.550 + iExpectedResult=KPositiveTest;
1.551 + }
1.552 + //check whether its a positive or a negative test
1.553 + if(flagReturn)
1.554 + {
1.555 + //check whether its a positive or a negative test
1.556 + if(!VerifyExpectedError(aSec))
1.557 + {
1.558 + INFO_PRINTF1(_L("SafeContentsBag Failed"));
1.559 + SetTestStepResult(EFail);
1.560 + flagReturn = EFalse;
1.561 + }
1.562 + }
1.563 + return flagReturn;
1.564 + }
1.565 +/**
1.566 +Function is intended to check the content info type
1.567 +@param-aSecName:BagData Section
1.568 +@param-aBagData:safebag class pointer
1.569 +@internalTechnology:
1.570 +@return:returns EFalse if there is a failure else return ETrue
1.571 +@test:
1.572 +*/
1.573 +TBool CPKCS12LibTestStep::ChkCIType(TDesC &aSecName,CSafeBagData &aBagData)
1.574 + {
1.575 + TInt contentType=0;
1.576 + TBool flagReturn=ETrue;
1.577 + //retrieve the contentype from the ini file
1.578 + if(!GetIntFromConfig(aSecName,KContentInfoType,contentType))
1.579 + {
1.580 + ERR_PRINTF1(_L("ContentInfoType value not found in INI file"));
1.581 + SetTestStepResult(EFail);
1.582 + flagReturn=EFalse;
1.583 + }
1.584 + //compare the contentype with the ini file data
1.585 + if(flagReturn)
1.586 + {
1.587 + if(aBagData.ContentInfoType() != contentType)
1.588 + {
1.589 + iActualResult=EFalse;
1.590 + INFO_PRINTF1(_L("ContentType Comparison Failed"));
1.591 + }
1.592 + //retrieve the expected result:PositiveTest/NegativeTest
1.593 + if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult))
1.594 + {
1.595 + WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.596 + iExpectedResult=KPositiveTest;
1.597 + }
1.598 + //check whether its a positive or a negative test
1.599 + if(!VerifyExpectedError(aSecName))
1.600 + {
1.601 + INFO_PRINTF1(_L("ContentInfo Failed"));
1.602 + SetTestStepResult(EFail);
1.603 + flagReturn = EFalse;
1.604 + }
1.605 + }
1.606 + return flagReturn;
1.607 + }
1.608 +/**
1.609 +Function is intended to check the bag type
1.610 +@param-aSec:BagData Section
1.611 +@param-aBgDta:safebag class pointer
1.612 +@param-aId:Bag ID
1.613 +@internalTechnology:
1.614 +@return:returns EFalse if there is a failure else return ETrue
1.615 +@test:
1.616 +*/
1.617 +TBool CPKCS12LibTestStep::ChkBagType(TDesC &aSec,CSafeBagData &aBagData,TInt aId)
1.618 + {
1.619 + TBool flagReturn=ETrue;
1.620 +
1.621 + //check for the bagid
1.622 + if(aId != aBagData.BagType())
1.623 + {
1.624 + iActualResult=EFalse;
1.625 + INFO_PRINTF1(_L("BagType Comparision Failed"));
1.626 + }
1.627 +
1.628 + //retrieve the expected result:PositiveTest/NegativeTest
1.629 + if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult))
1.630 + {
1.631 + WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.632 + iExpectedResult=KPositiveTest;
1.633 + }
1.634 +
1.635 + //check whether its a positive or a negative test
1.636 + if(!VerifyExpectedError(aSec))
1.637 + {
1.638 + INFO_PRINTF1(_L("BagType Failed"));
1.639 + SetTestStepResult(EFail);
1.640 + flagReturn = EFalse;
1.641 + }
1.642 + return flagReturn;
1.643 + }
1.644 +/**
1.645 +Function is intended to check the bag attributes
1.646 +@param-aSec:BagData Section
1.647 +@param-aBagData:safebag class pointer
1.648 +@internalTechnology:
1.649 +@return:returns EFalse if there is a failure else return ETrue
1.650 +@test:
1.651 +*/
1.652 +TBool CPKCS12LibTestStep::ChkBagAttbutesL(TDesC &aSec,CSafeBagData &aBagData)
1.653 + {
1.654 + TInt numAttr=0;
1.655 + TInt count=0;
1.656 + TPtrC attrSec(KNullDesC);
1.657 + TBool flagReturn=ETrue;
1.658 +
1.659 + //retrieve the number of attributes
1.660 + if(!GetIntFromConfig(aSec,KBagAttributesNum,numAttr))
1.661 + {
1.662 + WARN_PRINTF1(_L("Number of attributes not found in INI file"));
1.663 + }
1.664 +
1.665 + for(TInt attrindex=0;attrindex < numAttr;attrindex++)
1.666 + {
1.667 + TBuf<KAttributeBufLen> attrBuf(KBagAttributesKey);
1.668 + //increment the attr counter
1.669 + count++;
1.670 + //appending to get the attr key from the ini file
1.671 + attrBuf.AppendNum(count);
1.672 +
1.673 + if(!GetStringFromConfig(aSec,attrBuf,attrSec))
1.674 + {
1.675 + ERR_PRINTF1(_L("Number of attributes not found in INI file"));
1.676 + SetTestStepResult(EFail);
1.677 + flagReturn=EFalse;
1.678 + break;
1.679 + }
1.680 + //retrieve the expected result:PositiveTest/NegativeTest
1.681 + if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult))
1.682 + {
1.683 + WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.684 + iExpectedResult=KPositiveTest;
1.685 + }
1.686 + //check whether its a positive or a negative test
1.687 + if(!VerifyExpectedError(aSec))
1.688 + {
1.689 + INFO_PRINTF1(_L("BagAttributes Failed"));
1.690 + SetTestStepResult(EFail);
1.691 + flagReturn = EFalse;
1.692 + }
1.693 + else if(!iUnitTestContinueFlag)
1.694 + {
1.695 + flagReturn = ETrue;
1.696 + break;
1.697 + }
1.698 + //retrieve the expected result:PositiveTest/NegativeTest
1.699 + if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult))
1.700 + {
1.701 + WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.702 + iExpectedResult=KPositiveTest;
1.703 + }
1.704 + //check whether its a positive or a negative test
1.705 + if(!VerifyExpectedError(aSec))
1.706 + {
1.707 + INFO_PRINTF1(_L("BagAttributes Failed"));
1.708 + SetTestStepResult(EFail);
1.709 + flagReturn = EFalse;
1.710 + }
1.711 + else if(!iUnitTestContinueFlag)
1.712 + {
1.713 + flagReturn = ETrue;
1.714 + break;
1.715 + }
1.716 + //Check the BagAttribute section
1.717 + if(!ChkAtrSecL(attrSec,aBagData,attrindex))
1.718 + {
1.719 + ERR_PRINTF1(_L("Attributes comparison failed"));
1.720 + flagReturn=EFalse;
1.721 + break;
1.722 + }
1.723 + }
1.724 + return flagReturn;
1.725 + }
1.726 +/**
1.727 +Function is intended to check the attribute section
1.728 +@param-aSec:BagData Section
1.729 +@param-aBgDta:safebag class pointer
1.730 +@param-aIndx:attribute index
1.731 +@param-aAttrindex:attribute index
1.732 +@internalTechnology:
1.733 +@return:returns EFalse if there is a failure else return ETrue
1.734 +@test:
1.735 +@leave: if leave occurs if ChkAtrValL fails
1.736 +*/
1.737 +TBool CPKCS12LibTestStep::ChkAtrSecL(TDesC &aSec,CSafeBagData &aBagData,TInt aIndex)
1.738 + {
1.739 + TPtrC attrId(KNullDesC);
1.740 + TInt numVal=0;
1.741 + CSafeBagAttribute *bagAttr;
1.742 + TPtrC friendlyName(KFriendlyNameOid);
1.743 + TPtrC localKey(KLocalKeyOid);
1.744 + TBool flagReturn=ETrue;
1.745 +
1.746 + //retrieve the attribute id
1.747 + if(!GetStringFromConfig(aSec,KBagAttributesID,attrId))
1.748 + {
1.749 + ERR_PRINTF1(_L("attribute id not found in INI file"));
1.750 + SetTestStepResult(EFail);
1.751 + flagReturn=EFalse;
1.752 + }
1.753 + if(flagReturn)
1.754 + {
1.755 + //retrieve the number of values
1.756 + if(!GetIntFromConfig(aSec,KBagAttributeValuesNum,numVal))
1.757 + {
1.758 + ERR_PRINTF1(_L("total number of attribute values not found in INI file"));
1.759 + SetTestStepResult(EFail);
1.760 + flagReturn=EFalse;
1.761 + }
1.762 + }
1.763 + if(flagReturn)
1.764 + {
1.765 + bagAttr = aBagData.iAttributeIDs[aIndex];
1.766 +
1.767 + //increment the Number of BagAttrValues
1.768 + iBagAttrNumVal+=numVal;
1.769 +
1.770 + //compare the attrval count and the attrid
1.771 + if((bagAttr->AttributeValueCount()!=numVal) ||
1.772 + (attrId.CompareF((bagAttr->AttributeId()))!=0))
1.773 + {
1.774 + iActualResult=EFalse;
1.775 + }
1.776 + else if((friendlyName.CompareF((bagAttr->AttributeId()))==0) ||
1.777 + (localKey.CompareF((bagAttr->AttributeId()))==0))
1.778 + {
1.779 + //Check for BagAttribute values
1.780 + if(!ChkAtrValL(aSec,aBagData,numVal))
1.781 + {
1.782 + iActualResult=EFalse;
1.783 + }
1.784 + }
1.785 + //retrieve the expected result:PositiveTest/NegativeTest
1.786 + if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult))
1.787 + {
1.788 + WARN_PRINTF1(_L("ExpectedResult not found in INI file"));
1.789 + iExpectedResult=KPositiveTest;
1.790 + }
1.791 + //check for positive or negative test
1.792 + if(!VerifyExpectedError(aSec))
1.793 + {
1.794 + INFO_PRINTF1(_L("Attributes Comparison Test Case failed"));
1.795 + SetTestStepResult(EFail);
1.796 + flagReturn = EFalse;
1.797 + }
1.798 +
1.799 + }
1.800 + //retrieve the bag attribute structure pointer
1.801 + return flagReturn;
1.802 + }
1.803 +/**
1.804 +Function is intended to check the attribute values
1.805 +@param-aSec:BagData Section
1.806 +@param-aBgDta:safebag class pointer
1.807 +@param-aNum:Bagattribute value count
1.808 +@param-aAtr:Bagattribute ID
1.809 +@param-aNumVal:Bagattribute value count
1.810 +@internalTechnology:
1.811 +@return:returns EFalse if there is a failure else return ETrue
1.812 +@test:
1.813 +@leave: if memory allocation of buffer fails
1.814 +*/
1.815 +TBool CPKCS12LibTestStep::ChkAtrValL(TDesC &aSec,CSafeBagData &aBagData,TInt aNum)
1.816 + {
1.817 + TInt start=iBagAttrNumVal - aNum;
1.818 + TInt end=iBagAttrNumVal + aNum;
1.819 +
1.820 + TBool flagReturn=ETrue;
1.821 + TInt index=0;
1.822 + TPtrC value(KNullDesC);
1.823 +
1.824 + HBufC8 *bufferVal;
1.825 +
1.826 + //loop till the total number of values
1.827 + do
1.828 + {
1.829 + TBuf<KBagValBufLen> bagVal(KBagAttributeValue);
1.830 + //increment the index to append the count
1.831 + index++;
1.832 + //append the value
1.833 + bagVal.AppendNum(index);
1.834 + //retrieve the value from the ini file
1.835 + if(!GetStringFromConfig(aSec,bagVal,value))
1.836 + {
1.837 + ERR_PRINTF1(_L("Bag Value not found in the ini file"));
1.838 + SetTestStepResult(EFail);
1.839 + flagReturn=EFalse;
1.840 + break;
1.841 + }
1.842 + for(TInt startIndex=start;startIndex<end;startIndex++)
1.843 + {
1.844 + bufferVal=aBagData.iAttributeValues[startIndex];
1.845 +
1.846 + //check the local key value
1.847 + if(!CompareFileDataL(value,*bufferVal))
1.848 + {
1.849 + ERR_PRINTF1(_L("Bag Attribute Value comparison failed"));
1.850 + iActualResult=EFalse;
1.851 + break;
1.852 + }
1.853 + else
1.854 + {
1.855 + iActualResult=ETrue;
1.856 + break;
1.857 + }
1.858 + }
1.859 + //retrieve the expected result:PositiveTest/NegativeTest
1.860 + if(!GetBoolFromConfig(aSec,KExpectedResult,iExpectedResult))
1.861 + {
1.862 + WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.863 + iExpectedResult=KPositiveTest;
1.864 + }
1.865 + //check for positive or negative test
1.866 + if(!VerifyExpectedError(aSec))
1.867 + {
1.868 + INFO_PRINTF1(_L("Bag Value Test failed"));
1.869 + SetTestStepResult(EFail);
1.870 + flagReturn = EFalse;
1.871 + break;
1.872 + }
1.873 + else if(!iUnitTestContinueFlag)
1.874 + {
1.875 + break;
1.876 + }
1.877 + }while(index<aNum);
1.878 + return flagReturn;
1.879 + }
1.880 +/**
1.881 +Function is intended to check the value.
1.882 +@param-aPValue:filepath containing the path of the file
1.883 + retrieved from the ini file
1.884 +@param-aBufferVal:Value retrieved after parsing the pkcs12 file
1.885 +@internalTechnology:
1.886 +@return:returns EFalse if there is a failure else return ETrue
1.887 +@test:
1.888 +@leave: if leave occurs if openfile fails or allocation to buffer fails
1.889 +*/
1.890 +TBool CPKCS12LibTestStep::CompareFileDataL(TDesC &aPValue,TDesC8 &aBufferVal)
1.891 + {
1.892 + RFile file;
1.893 + TInt fileSize=0;
1.894 + TBool flagReturn=ETrue;
1.895 + // Negative Test: If mac/ macSalt is not present.
1.896 + if (&aBufferVal)
1.897 + {
1.898 + //open the file
1.899 + User::LeaveIfError(file.Open(iFileSession,aPValue,EFileRead));
1.900 + User::LeaveIfError(file.Size(fileSize));
1.901 + //raw data for reading the bagvalue
1.902 + HBufC8 *rawData=HBufC8::NewMaxLC(fileSize);
1.903 + //converting the HBufC8 to TPtr8
1.904 + TPtr8 data(rawData->Des());
1.905 + //read the contents of the file
1.906 + User::LeaveIfError(file.Read(data));
1.907 + //compare the value
1.908 + if(rawData->CompareF(aBufferVal)!=0)
1.909 + {
1.910 + ERR_PRINTF1(_L("comparison failed"));
1.911 + flagReturn=EFalse;
1.912 + }
1.913 + //closes the data file
1.914 + file.Close();
1.915 +
1.916 + CleanupStack::PopAndDestroy(rawData);
1.917 + }
1.918 + return flagReturn;
1.919 + }
1.920 +/**
1.921 +Function is intended to check the algorithm id
1.922 +@param-aSecName:BagData Section
1.923 +@param-aBagData:safebagdata class pointer
1.924 +@internalTechnology:
1.925 +@return:returns EFalse if there is a failure else return ETrue
1.926 +@test:
1.927 +*/
1.928 +TBool CPKCS12LibTestStep::ChkAlgId(TDesC &aSecName,CSafeBagData &aBagData)
1.929 + {
1.930 + TPtrC algorithm(KNullDesC);
1.931 + TBool flagReturn=ETrue;
1.932 + //retrieve the algorithm section name
1.933 + if(!GetStringFromConfig(aSecName,_L("Algorithm"),algorithm))
1.934 + {
1.935 + ERR_PRINTF1(_L("AlgorithmID value not found in INI file"));
1.936 + SetTestStepResult(EFail);
1.937 + flagReturn=EFalse;
1.938 + }
1.939 + if(flagReturn)
1.940 + {
1.941 + if(algorithm.CompareF((aBagData.AlgorithmId()))!=0)
1.942 + {
1.943 + iActualResult=EFalse;
1.944 + }
1.945 + //retrieve the expected result:PositiveTest/NegativeTest
1.946 + if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult))
1.947 + {
1.948 + WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.949 + iExpectedResult=KPositiveTest;
1.950 + }
1.951 + //check for positive oor negative test
1.952 + if(!VerifyExpectedError(aSecName))
1.953 + {
1.954 + INFO_PRINTF1(_L("Algorithm Comparison Test Case failed"));
1.955 + SetTestStepResult(EFail);
1.956 + flagReturn = EFalse;
1.957 + }
1.958 + }
1.959 + return flagReturn;
1.960 + }
1.961 +/**
1.962 +Function is intended to check the certificate type
1.963 +@param-aSecName:BagData Section
1.964 +@param-aBagData:safebagdata class pointer
1.965 +@internalTechnology:
1.966 +@return:returns EFalse if there is a failure else return ETrue
1.967 +@test:
1.968 +*/
1.969 +TBool CPKCS12LibTestStep::ChkCertId(TDesC &aSecName,CSafeBagData &aBagData)
1.970 + {
1.971 + TPtrC certid(KNullDesC);
1.972 + TBool flagReturn=ETrue;
1.973 + //retrieve the cert name from ini file
1.974 + if(!GetStringFromConfig(aSecName,KCertType,certid))
1.975 + {
1.976 + ERR_PRINTF1(_L("certificateID value not found in INI file"));
1.977 + SetTestStepResult(EFail);
1.978 + flagReturn= EFalse;
1.979 + }
1.980 + if(flagReturn)
1.981 + {
1.982 + if(certid.CompareF((aBagData.CertificateId()))!=0)
1.983 + {
1.984 + INFO_PRINTF1(_L("certificateID comparision Failed"));
1.985 + iActualResult=EFalse;
1.986 + }
1.987 + //retrieve the expected result:PositiveTest/NegativeTest
1.988 + if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult))
1.989 + {
1.990 + WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.991 + iExpectedResult=KPositiveTest;
1.992 + }
1.993 + //check for positive or negative test
1.994 + if(!VerifyExpectedError(aSecName))
1.995 + {
1.996 + INFO_PRINTF1(_L("Certificate Comparison Test Case failed"));
1.997 + SetTestStepResult(EFail);
1.998 + flagReturn = EFalse;
1.999 + }
1.1000 + }
1.1001 + return flagReturn;
1.1002 + }
1.1003 +/**
1.1004 +Function is intended to check for the bag value
1.1005 +@param-aSecName:BagData Section
1.1006 +@param-aBagData:safebag class pointer
1.1007 +@internalTechnology:
1.1008 +@return:returns EFalse if there is a failure else return ETrue
1.1009 +@test:
1.1010 +*/
1.1011 +TBool CPKCS12LibTestStep::ChkBagValL(TDesC &aSecName,CSafeBagData &aBagData)
1.1012 + {
1.1013 + TPtrC certBagPath(KNullDesC);
1.1014 + TBool flagReturn=ETrue;
1.1015 +
1.1016 + //retrieve the certificate bag value
1.1017 + if(!GetStringFromConfig(aSecName,KBagValue,certBagPath))
1.1018 + {
1.1019 + ERR_PRINTF1(_L("Not able to get the CertBagValue from the ini file"));
1.1020 + SetTestStepResult(EFail);
1.1021 + flagReturn=EFalse;
1.1022 + }
1.1023 + TInt fileReturn=0;
1.1024 + RFile file;
1.1025 +
1.1026 + if(flagReturn)
1.1027 + {
1.1028 + fileReturn=file.Open(iFileSession,certBagPath,EFileRead);
1.1029 +
1.1030 + if(fileReturn)
1.1031 + {
1.1032 + ERR_PRINTF1(_L("CertBagValue:Not able to open the file"));
1.1033 + SetTestStepResult(EFail);
1.1034 + flagReturn=EFalse;
1.1035 + }
1.1036 + }
1.1037 + //raw data for reading the bagvalue
1.1038 + HBufC8 *rawData=NULL;
1.1039 + TInt filesize=0;
1.1040 + if(flagReturn)
1.1041 + {
1.1042 + User::LeaveIfError(file.Size(filesize));
1.1043 + rawData=HBufC8::NewMaxLC(filesize);
1.1044 + TPtr8 data(rawData->Des());
1.1045 + if(file.Read(data))
1.1046 + {
1.1047 + ERR_PRINTF1(_L("CertBagValue:Not able to Read the file"));
1.1048 + SetTestStepResult(EFail);
1.1049 + flagReturn=EFalse;
1.1050 + }
1.1051 + }
1.1052 + if(flagReturn)
1.1053 + {
1.1054 + //compare the data
1.1055 + if(rawData->CompareF(aBagData.BagValue())!=0)
1.1056 + {
1.1057 + iActualResult=EFalse;
1.1058 + }
1.1059 + //retrieve the expected result:PositiveTest/NegativeTest
1.1060 + if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult))
1.1061 + {
1.1062 + WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.1063 + iExpectedResult=KPositiveTest;
1.1064 + }
1.1065 + //check for positive or negative test
1.1066 + if(!VerifyExpectedError(aSecName))
1.1067 + {
1.1068 + INFO_PRINTF1(_L("BagValue Failed"));
1.1069 + SetTestStepResult(EFail);
1.1070 + flagReturn = EFalse;
1.1071 + }
1.1072 + }
1.1073 + if(rawData!=NULL)
1.1074 + {
1.1075 + CleanupStack::PopAndDestroy(rawData);
1.1076 + }
1.1077 + if(!fileReturn)
1.1078 + {
1.1079 + file.Close();
1.1080 + }
1.1081 + return flagReturn;
1.1082 + }
1.1083 +/**
1.1084 +Function is intended to check for the mac value
1.1085 +@internalTechnology:
1.1086 +@return:returns EFalse if there is a failure else return ETrue
1.1087 +@test:
1.1088 +@leave: if leave occurs at the CompareFileDataL function
1.1089 +*/
1.1090 +TBool CPKCS12LibTestStep::ChkMacValueL()
1.1091 + {
1.1092 + TPtrC mac(KNullDesC);
1.1093 + TPtrC macSalt(KNullDesC);
1.1094 + TPtrC secName(_S("MacData"));
1.1095 + TPtrC expectedError(KNullDesC);
1.1096 + TInt itCount=0;
1.1097 + TBool flagReturn=ETrue;
1.1098 +
1.1099 + //retrieve the macid,macsalt and iteration count
1.1100 + if((!GetStringFromConfig(secName,KMac,mac)) ||
1.1101 + (!GetStringFromConfig(secName,KMacSalt,macSalt)) ||
1.1102 + (!GetIntFromConfig(secName,KIterationCount,itCount)))
1.1103 + {
1.1104 + ERR_PRINTF1(_L("Not able to access the mac values from ini file"));
1.1105 + SetTestStepResult(EFail);
1.1106 + flagReturn=EFalse;
1.1107 + }
1.1108 + //comapre the data with the ini file
1.1109 + if((CompareFileDataL(mac,iParser->PfxHeader().MacId()) ==0)||
1.1110 + (CompareFileDataL(macSalt,iParser->PfxHeader().MacSalt()) == 0)||
1.1111 + (itCount!=iParser->PfxHeader().IterationCount()))
1.1112 + {
1.1113 + WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.1114 + flagReturn=EFalse;
1.1115 + }
1.1116 + //retrieve the expected result:PositiveTest/NegativeTest
1.1117 + if(!GetBoolFromConfig(secName,KExpectedResult,iExpectedResult))
1.1118 + {
1.1119 + WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.1120 + iExpectedResult=KPositiveTest;
1.1121 + }
1.1122 + if(!VerifyExpectedError(secName))
1.1123 + {
1.1124 + SetTestStepResult(EFail);
1.1125 + flagReturn = EFalse;
1.1126 + }
1.1127 + return flagReturn;
1.1128 + }
1.1129 +
1.1130 +CTPKCS12OOMStep::CTPKCS12OOMStep()
1.1131 + {
1.1132 +
1.1133 + }
1.1134 +CTPKCS12OOMStep::~CTPKCS12OOMStep()
1.1135 + {
1.1136 + delete iRawData;
1.1137 + delete iAuthSafeData;
1.1138 + iFs.Close();
1.1139 + }
1.1140 +/**
1.1141 +Function is intended to do the OOM test.
1.1142 +@internalTechnology:
1.1143 +@return:TVerdict -returns EFail if there is a failure else EPass
1.1144 +@leave:- if memory allocation fails
1.1145 +@test
1.1146 +*/
1.1147 +TVerdict CTPKCS12OOMStep::doTestStepL()
1.1148 + {
1.1149 + TInt OOMTest;
1.1150 + GetIntFromConfig(ConfigSection(),_L("OOMTest"),OOMTest);
1.1151 +
1.1152 + __UHEAP_MARK;
1.1153 +
1.1154 + switch(OOMTest)
1.1155 + {
1.1156 + case 1:
1.1157 + {
1.1158 + CDecPkcs12* theTest = NULL;
1.1159 + theTest = CDecPkcs12::NewL(iRawData->Des());
1.1160 + delete theTest;
1.1161 + }
1.1162 + break;
1.1163 + // File Stream
1.1164 + case 2:
1.1165 + {
1.1166 + TPtrC fileName;
1.1167 + GetStringFromConfig(ConfigSection(), _L("File"), fileName);
1.1168 +
1.1169 + RFile file;
1.1170 + User::LeaveIfError(file.Open(iFs, fileName, EFileRead) );
1.1171 +
1.1172 + TInt size;
1.1173 + file.Size(size);
1.1174 + file.Close();
1.1175 +
1.1176 + HBufC8* res = HBufC8::NewLC(size);
1.1177 + TPtr8 p(res->Des());
1.1178 + p.SetLength(size);
1.1179 +
1.1180 + RFileReadStream stream;
1.1181 + User::LeaveIfError(stream.Open(iFs, fileName, EFileStream));
1.1182 + CleanupClosePushL(stream);
1.1183 +
1.1184 + stream.ReadL(p, size);
1.1185 +
1.1186 + CDecPkcs12* theTest = NULL;
1.1187 + theTest = CDecPkcs12::NewL(stream);
1.1188 + delete theTest;
1.1189 + CleanupStack::PopAndDestroy(2,res); // stream
1.1190 + }
1.1191 + break;
1.1192 + // MacData
1.1193 + case 3:
1.1194 + {
1.1195 + CDecPkcs12MacData* theTest = NULL;
1.1196 + theTest = CDecPkcs12MacData::NewL(iRawData->Des(),iAuthSafeData->Des());
1.1197 + delete theTest;
1.1198 + }
1.1199 + break;
1.1200 + // Attribute
1.1201 + case 4:
1.1202 + {
1.1203 + CDecPkcs12Attribute* theTest = NULL;
1.1204 + theTest = CDecPkcs12Attribute::NewL(iRawData->Des());
1.1205 + delete theTest;
1.1206 + }
1.1207 + break;
1.1208 + // ShroudedBag
1.1209 + case 5:
1.1210 + {
1.1211 + CDecPkcs12ShroudedKeyBag* theTest = NULL;
1.1212 + theTest = CDecPkcs12ShroudedKeyBag::NewL(iRawData->Des());
1.1213 + delete theTest;
1.1214 + }
1.1215 + break;
1.1216 + // CertBag
1.1217 + case 6:
1.1218 + {
1.1219 + CDecPkcs12CertBag* theTest = NULL;
1.1220 + theTest = CDecPkcs12CertBag::NewL(iRawData->Des());
1.1221 + delete theTest;
1.1222 + }
1.1223 + break;
1.1224 + // KeyBag
1.1225 + case 7:
1.1226 + {
1.1227 + CDecPkcs12KeyBag* theTest = NULL;
1.1228 + theTest = CDecPkcs12KeyBag::NewL(iRawData->Des());
1.1229 + delete theTest;
1.1230 + }
1.1231 + break;
1.1232 + // SafeContentsBag
1.1233 + case 8:
1.1234 + {
1.1235 + CDecPkcs12SafeContentsBag* theTest = NULL;
1.1236 + theTest = CDecPkcs12SafeContentsBag::NewL(iRawData->Des());
1.1237 + delete theTest;
1.1238 + }
1.1239 + break;
1.1240 + // Safebag/CRL bag
1.1241 + case 9:
1.1242 + {
1.1243 + CDecPkcs12SafeBag* theTest = NULL;
1.1244 + theTest = CDecPkcs12SafeBag::NewL(iRawData->Des());
1.1245 + delete theTest;
1.1246 + }
1.1247 + break;
1.1248 + // SafeContentsData / SafeContentsEncryptedData
1.1249 + case 10:
1.1250 + {
1.1251 + CDecPkcs12* p12 = NULL;
1.1252 + p12 = CDecPkcs12::NewL(iRawData->Des());
1.1253 + CleanupStack::PushL(p12);
1.1254 +
1.1255 + const RPointerArray<CPKCS7ContentInfo>& contentInfos = p12->AuthenticatedSafeContents();
1.1256 +
1.1257 + TInt contentInfoCount = contentInfos.Count();
1.1258 + for ( TInt index = 0; index < contentInfoCount; index++ )
1.1259 + {
1.1260 + TInt contentType = contentInfos[index]->ContentType();
1.1261 + CDecPkcs12SafeContents* pkcs12SafeContents ;
1.1262 + TInt contentTypeData;
1.1263 + GetIntFromConfig(ConfigSection(),_L("ContentTypeData"),contentTypeData);
1.1264 +
1.1265 + TInt contentTypeEncryptedData;
1.1266 + GetIntFromConfig(ConfigSection(),_L("ContentTypeEncryptedData"),contentTypeEncryptedData);
1.1267 +
1.1268 + if ( contentType == contentTypeEncryptedData )
1.1269 + {
1.1270 + TPtrC expectedPassword(KNullDesC());
1.1271 + GetStringFromConfig(ConfigSection(), _L("Password"), expectedPassword);
1.1272 + pkcs12SafeContents = CDecPkcs12SafeContents::NewL(*contentInfos[index],expectedPassword);
1.1273 + delete pkcs12SafeContents;
1.1274 + }
1.1275 + else if ( contentType == contentTypeData )
1.1276 + {
1.1277 + pkcs12SafeContents = CDecPkcs12SafeContents::NewL(*contentInfos[index]);
1.1278 + delete pkcs12SafeContents;
1.1279 + }
1.1280 + }
1.1281 + CleanupStack::PopAndDestroy(p12);
1.1282 + break;
1.1283 + }
1.1284 + }
1.1285 + __UHEAP_MARKEND;
1.1286 + return TestStepResult();
1.1287 + }
1.1288 +
1.1289 +/**
1.1290 +Function is intended to read the data from the specified path.
1.1291 +@param-aPValue:filepath containing the path of the file
1.1292 + retrieved from the ini file.
1.1293 +@internalTechnology:
1.1294 +@return:returns data retrieved after reading from the file.
1.1295 +@test:
1.1296 +*/
1.1297 +HBufC8* CTPKCS12OOMStep::ReadFileDataL(TPtrC tag)
1.1298 + {
1.1299 + TPtrC fileName;
1.1300 + if (!GetStringFromConfig(ConfigSection(), tag, fileName))
1.1301 + {
1.1302 + return NULL;
1.1303 + }
1.1304 +
1.1305 + RFile file;
1.1306 + if (file.Open(iFs, fileName, EFileRead))
1.1307 + {
1.1308 + INFO_PRINTF2(_L("Cannot open file %S for reading"), &fileName);
1.1309 + return NULL;
1.1310 + }
1.1311 + CleanupClosePushL(file);
1.1312 +
1.1313 + TInt fileSize = 0;
1.1314 + User::LeaveIfError(file.Size(fileSize));
1.1315 +
1.1316 + HBufC8* result = HBufC8::NewL(fileSize);
1.1317 + result->Des().SetLength(fileSize);
1.1318 +
1.1319 + TPtr8 rawDataPtr(result->Des());
1.1320 + rawDataPtr.SetLength(fileSize);
1.1321 + file.Read (rawDataPtr);
1.1322 +
1.1323 + CleanupStack::PopAndDestroy (&file);
1.1324 +
1.1325 + INFO_PRINTF3(_L("Read %d octets from %S"), result->Size(), &fileName);
1.1326 +
1.1327 + return result;
1.1328 + }
1.1329 +
1.1330 +TVerdict CTPKCS12OOMStep::doTestStepPreambleL()
1.1331 + {
1.1332 + User::LeaveIfError (iFs.Connect());
1.1333 +
1.1334 + SetTestStepResult(EPass);
1.1335 +
1.1336 + iRawData = ReadFileDataL(_L("File"));
1.1337 + if (iRawData == NULL)
1.1338 + {
1.1339 + INFO_PRINTF1(_L("Failed to read 'File' section of script"));
1.1340 + SetTestStepResult(ETestSuiteError);
1.1341 + }
1.1342 + iAuthSafeData = ReadFileDataL(_L("AuthSafe"));
1.1343 + if (iAuthSafeData == NULL)
1.1344 + {
1.1345 + INFO_PRINTF1(_L("authsafedata file is not required"));
1.1346 + }
1.1347 + return TestStepResult();
1.1348 + }
1.1349 +/**
1.1350 +Function is intended to check for the re encoded shrouded key
1.1351 +@param-aSecName:BagData Section
1.1352 +@param-aBagData:safebag class pointer
1.1353 +@internalTechnology:
1.1354 +@return:returns EFalse if there is a failure else return ETrue
1.1355 +@test:
1.1356 +*/
1.1357 +TBool CPKCS12LibTestStep::ChkEncodedBagValL(TDesC &aSecName,CSafeBagData &aBagData)
1.1358 + {
1.1359 + TPtrC bagPath(KNullDesC);
1.1360 + TBool flagReturn=ETrue;
1.1361 +
1.1362 + //retrieve the shrouded bag value
1.1363 + if(!GetStringFromConfig(aSecName,KEncBagValue,bagPath))
1.1364 + {
1.1365 + ERR_PRINTF1(_L("Not able to get the EncBagValue from the ini file"));
1.1366 + SetTestStepResult(EFail);
1.1367 + flagReturn=EFalse;
1.1368 + }
1.1369 + TInt fileReturn=0;
1.1370 + RFile file;
1.1371 +
1.1372 + if(flagReturn)
1.1373 + {
1.1374 + fileReturn=file.Open(iFileSession,bagPath,EFileRead);
1.1375 +
1.1376 + if(fileReturn)
1.1377 + {
1.1378 + ERR_PRINTF1(_L("BagValue:Not able to open the file"));
1.1379 + SetTestStepResult(EFail);
1.1380 + flagReturn=EFalse;
1.1381 + }
1.1382 + }
1.1383 + CleanupClosePushL(file);
1.1384 + //raw data for reading the bagvalue
1.1385 + HBufC8 *rawData=NULL;
1.1386 + TInt filesize=0;
1.1387 + if(flagReturn)
1.1388 + {
1.1389 + User::LeaveIfError(file.Size(filesize));
1.1390 + rawData=HBufC8::NewMaxLC(filesize);
1.1391 + TPtr8 data(rawData->Des());
1.1392 + if(file.Read(data))
1.1393 + {
1.1394 + ERR_PRINTF1(_L("BagValue:Not able to Read the file"));
1.1395 + SetTestStepResult(EFail);
1.1396 + flagReturn=EFalse;
1.1397 + }
1.1398 + }
1.1399 + if(flagReturn)
1.1400 + {
1.1401 + //compare the data
1.1402 + if(rawData->CompareC(aBagData.EncodedShroudedKey())!=0)
1.1403 + {
1.1404 + iActualResult=EFalse;
1.1405 + }
1.1406 + //retrieve the expected result:PositiveTest/NegativeTest
1.1407 + if(!GetBoolFromConfig(aSecName,KExpectedResult,iExpectedResult))
1.1408 + {
1.1409 + WARN_PRINTF1(_L("ExpectedResult not found in INI file:Default:PositiveTest"));
1.1410 + iExpectedResult=KPositiveTest;
1.1411 + }
1.1412 + //check for positive or negative test
1.1413 + if(!VerifyExpectedError(aSecName))
1.1414 + {
1.1415 + INFO_PRINTF1(_L("BagValue Failed"));
1.1416 + SetTestStepResult(EFail);
1.1417 + flagReturn = EFalse;
1.1418 + }
1.1419 + }
1.1420 + if(rawData!=NULL)
1.1421 + {
1.1422 + CleanupStack::PopAndDestroy(rawData);
1.1423 + }
1.1424 + if(!fileReturn)
1.1425 + {
1.1426 + file.Close();
1.1427 + }
1.1428 + CleanupStack::PopAndDestroy(&file);
1.1429 + return flagReturn;
1.1430 + }
1.1431 +
1.1432 +