sl@0: /* sl@0: * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "tpkcs7step.h" sl@0: #include sl@0: #include "pkcs7signedobject.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "validate.h" sl@0: sl@0: CTPKCS7CorruptTest::CTPKCS7CorruptTest() sl@0: { sl@0: SetTestStepName(KTPKCS7CorruptTest); sl@0: } sl@0: sl@0: CTPKCS7ValidTest::CTPKCS7ValidTest() sl@0: { sl@0: SetTestStepName(KTPKCS7ValidTest); sl@0: } sl@0: sl@0: CTPKCS7ContentTest::CTPKCS7ContentTest() sl@0: { sl@0: SetTestStepName(KTPKCS7ContentTest); sl@0: } sl@0: sl@0: CTPKCS7CertificateTest::CTPKCS7CertificateTest() sl@0: { sl@0: SetTestStepName(KTPKCS7CertificateTest); sl@0: } sl@0: sl@0: CTPKCS7SignerTest::CTPKCS7SignerTest() sl@0: { sl@0: SetTestStepName(KTPKCS7SignerTest); sl@0: } sl@0: CTPKCS7EncryptedDataTest::CTPKCS7EncryptedDataTest() sl@0: { sl@0: SetTestStepName(KTPKCS7EncryptedDataTest); sl@0: } sl@0: sl@0: CTPKCS7DigestInfoTest::CTPKCS7DigestInfoTest() sl@0: { sl@0: SetTestStepName(KTPKCS7DigestInfoTest); sl@0: } sl@0: sl@0: CTPKCS7EncryptedDataCorruptTest::CTPKCS7EncryptedDataCorruptTest() sl@0: { sl@0: SetTestStepName(KTPKCS7EncryptedDataCorruptTest); sl@0: } sl@0: sl@0: CTPKCS7DigestInfoCorruptTest::CTPKCS7DigestInfoCorruptTest() sl@0: { sl@0: SetTestStepName(KTPKCS7DigestInfoCorruptTest); sl@0: } sl@0: sl@0: CTPKCS7OOMTest::CTPKCS7OOMTest() sl@0: { sl@0: SetTestStepName(KTPKCS7OOMTest); sl@0: } sl@0: sl@0: TVerdict CTPKCS7OOMTest::doTestStepL() sl@0: { sl@0: TVerdict verdict = EFail; sl@0: TInt countAfter = 0; sl@0: TInt countBefore = 0; sl@0: for (TInt oomCount = 0; ; oomCount++) sl@0: { sl@0: __UHEAP_RESET; sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic, oomCount); sl@0: countBefore = User::CountAllocCells(); sl@0: TRAPD(error, doTestOOML()); sl@0: countAfter = User::CountAllocCells(); sl@0: __UHEAP_RESET; sl@0: if (error != KErrNoMemory) sl@0: { sl@0: verdict = EPass; sl@0: INFO_PRINTF2(_L("OOM Status %d"),error); sl@0: INFO_PRINTF1(_L("Test outcome : Passed")); sl@0: break; sl@0: } sl@0: else sl@0: { sl@0: if (countBefore != countAfter) sl@0: { sl@0: INFO_PRINTF2(_L("OOM Status %d"),error); sl@0: INFO_PRINTF2(_L("OOM Failed at %d"), oomCount); sl@0: verdict = EFail; sl@0: break; sl@0: } sl@0: } sl@0: INFO_PRINTF2(_L("OOM Failed Point status %d"), error); sl@0: } sl@0: INFO_PRINTF3(_L("Heap alloc count ok: %d final vs %d initial"), countAfter,countBefore); sl@0: SetTestStepResult(verdict); sl@0: return verdict; sl@0: } sl@0: sl@0: void CTPKCS7OOMTest::doTestOOML() sl@0: { sl@0: TInt OOMTest; sl@0: GetIntFromConfig(ConfigSection(),_L("OOMTestNo"),OOMTest); sl@0: __UHEAP_MARK; sl@0: sl@0: if (OOMTest == 1) sl@0: { sl@0: CPKCS7ContentInfo* theTest = NULL; sl@0: theTest = CPKCS7ContentInfo::NewL(iRawData->Des()); sl@0: delete theTest; sl@0: } sl@0: // Digest Info sl@0: else if (OOMTest == 2) sl@0: { sl@0: CPKCS7DigestInfo* theTest0 = NULL; sl@0: theTest0 = CPKCS7DigestInfo::NewL(iRawData->Des()); sl@0: delete theTest0; sl@0: } sl@0: // Encrypted Data sl@0: else if (OOMTest == 3) sl@0: { sl@0: CPKCS7ContentInfo* theTest1 = NULL; sl@0: theTest1 = CPKCS7ContentInfo::NewL(iRawData->Des()); sl@0: sl@0: CleanupStack::PushL(theTest1); sl@0: CPKCS7EncryptedDataObject* theTest2 = NULL; sl@0: theTest2 = CPKCS7EncryptedDataObject::NewL(*theTest1); sl@0: sl@0: CleanupStack::PopAndDestroy(theTest1); sl@0: delete theTest2; sl@0: } sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: // Step 1 Corrupt sl@0: TVerdict CTPKCS7CorruptTest::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TInt reason; sl@0: if (GetIntFromConfig(ConfigSection(),_L("Reason"),reason) == EFalse) sl@0: { sl@0: reason = KErrNone; sl@0: } sl@0: sl@0: TInt err; sl@0: sl@0: //Use CPKCS7ContentInfo class in order to obtain the ContentType and ContentData. sl@0: //Depending on the ContentType the corresponding Object of that ContentType is created. sl@0: CPKCS7ContentInfo * contentInfo = NULL; sl@0: TRAP (err, contentInfo = CPKCS7ContentInfo::NewL(iRawData->Des())); sl@0: sl@0: //Checks if the file is empty, Corrupt sl@0: if (err == reason) sl@0: { sl@0: delete contentInfo; sl@0: SetTestStepResult(EPass); sl@0: INFO_PRINTF3(_L("Expected result %d, got %d"), reason, err); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: if( err == KErrNone) sl@0: { sl@0: //ContentType is SignedData sl@0: if( contentInfo->ContentType() == KPkcs7SignedData) sl@0: { sl@0: CPKCS7SignedObject * p7 = NULL; sl@0: TRAP (err, p7 = CPKCS7SignedObject::NewL(*contentInfo)); sl@0: delete p7; sl@0: } sl@0: } sl@0: delete contentInfo; sl@0: sl@0: if (err != reason) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("Expected result %d, got %d"), reason, err); sl@0: } sl@0: //Not corrupt , repeat files sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: TVerdict CTPKCS7ValidTest::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: __UHEAP_MARK; sl@0: TBool expectedValid; sl@0: if (GetBoolFromConfig(ConfigSection(),_L("IsValid"), expectedValid) == EFalse) sl@0: { sl@0: expectedValid = ETrue; sl@0: } sl@0: sl@0: TInt err; sl@0: sl@0: CPKCS7ContentInfo * contentInfo = NULL; sl@0: TRAP (err, contentInfo = CPKCS7ContentInfo::NewL(iRawData->Des())); sl@0: sl@0: if(err == KErrNone) sl@0: { sl@0: CPKCS7SignedObject * p7 = NULL; sl@0: if( contentInfo->ContentType() == KPkcs7SignedData) sl@0: { sl@0: TRAP (err, p7 = CPKCS7SignedObject::NewL(*contentInfo)); sl@0: //expired, and the case where certificate chain root is not on the device sl@0: if (!expectedValid) sl@0: { sl@0: if (err != KErrNone) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: INFO_PRINTF2(_L("Got %d building PKCS7 object"), err); sl@0: return TestStepResult(); sl@0: } sl@0: } sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF2(_L("Got %d building PKCS7 object"), err); sl@0: } sl@0: else sl@0: { sl@0: CleanupStack::PushL (p7); sl@0: sl@0: const RPointerArray& signers = p7->SignerInfo(); sl@0: TBool isValid = EFalse; sl@0: HBufC8* certificateEncoding = NULL; sl@0: if(!p7->ValidateSignerL(*signers[0], certificateEncoding)) sl@0: { sl@0: INFO_PRINTF1(_L("Couldn't validate signer")); sl@0: } sl@0: else sl@0: { sl@0: CActiveScheduler* sched = NULL; sl@0: if (CActiveScheduler::Current() == NULL) sl@0: { sl@0: INFO_PRINTF1(_L("Installing scheduler")); sl@0: sched = new (ELeave) CActiveScheduler(); sl@0: CleanupStack::PushL (sched); sl@0: __UHEAP_MARK; sl@0: CActiveScheduler::Install (sched); sl@0: } sl@0: RPointerArray roots (&iRootCertificate, 1); sl@0: CPKIXCertChain * chain = CPKIXCertChain::NewLC(iFs, *certificateEncoding, roots); sl@0: TTime tm; sl@0: _LIT(KDateCorrect1,"20040801:"); sl@0: TBuf <24> theDate(KDateCorrect1); sl@0: TInt err=tm.Set(theDate); sl@0: if(err) sl@0: { sl@0: tm.HomeTime(); sl@0: } sl@0: CPKIXValidationResult* result = CPKIXValidationResult::NewLC(); sl@0: CTPKCS7Validator* validator = new (ELeave) CTPKCS7Validator (chain, result, &tm); sl@0: CleanupStack::PushL (validator); sl@0: validator->doValidate (); sl@0: sched->Start (); sl@0: if (result->Error().iReason == EValidatedOK) sl@0: { sl@0: isValid = ETrue; sl@0: INFO_PRINTF1(_L("Validation success")); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Validation failed: %d"), result->Error().iReason); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(validator); sl@0: CleanupStack::PopAndDestroy(result); sl@0: CleanupStack::PopAndDestroy(chain); sl@0: if (sched) sl@0: { sl@0: CActiveScheduler::Install (NULL); sl@0: CleanupStack::PopAndDestroy (sched); sl@0: } sl@0: } sl@0: if (certificateEncoding) sl@0: { sl@0: CleanupStack::PopAndDestroy(certificateEncoding); sl@0: } sl@0: CleanupStack::PopAndDestroy (p7); sl@0: if (isValid != expectedValid) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: if (expectedValid) sl@0: { sl@0: INFO_PRINTF1(_L("Expected valid, got invalid")); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Expected invalid, got valid")); sl@0: } sl@0: } sl@0: } sl@0: sl@0: } sl@0: } sl@0: else sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: // Step 3 Content sl@0: TVerdict CTPKCS7ContentTest::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TBool checkType; sl@0: TBool checkLength; sl@0: TBool checkContent; sl@0: TInt expectedType; sl@0: TInt expectedLength; sl@0: TPtrC expectedString; sl@0: HBufC8 * expectedContent = NULL; sl@0: sl@0: checkType = GetIntFromConfig (ConfigSection(),_L("ContentType"), expectedType); sl@0: checkLength = GetIntFromConfig (ConfigSection(),_L("ContentLength"), expectedLength); sl@0: checkContent = GetStringFromConfig(ConfigSection(),_L("ContentString"), expectedString); sl@0: sl@0: if (checkContent) sl@0: { sl@0: if (expectedString.Length() & 1) sl@0: { sl@0: SetTestStepResult(ETestSuiteError); sl@0: INFO_PRINTF1(_L("ContentString is not a multiple of 2 long")); sl@0: checkContent = EFalse; sl@0: } sl@0: else sl@0: { sl@0: // workaround to parse the expectedstring sl@0: expectedContent = HBufC8::NewLC (expectedString.Length()/2); sl@0: TPtr8 des = expectedContent->Des (); sl@0: for (TInt i = 0; i < expectedString.Length()/2; i++) sl@0: { sl@0: TInt top = expectedString[2*i]; sl@0: TInt low = expectedString[2*i+1]; sl@0: if (top >= 0x61) top -= (0x61-10); sl@0: else top -= 0x30; sl@0: if (low >= 0x61) low -= (0x61-10); sl@0: else low -= 0x30; sl@0: des.Append (top*16+low); sl@0: } sl@0: } sl@0: } sl@0: TInt err; sl@0: sl@0: CPKCS7ContentInfo * contentInfo = NULL; sl@0: TRAP (err, contentInfo = CPKCS7ContentInfo::NewL(iRawData->Des())); sl@0: if(err == KErrNone) sl@0: { sl@0: CPKCS7SignedObject * p7 = NULL; sl@0: if( contentInfo->ContentType() == 2) sl@0: { sl@0: TRAPD (err, p7 = CPKCS7SignedObject::NewL(*contentInfo)); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF2(_L("Got %d building PKCS7 object"), err); sl@0: } sl@0: else sl@0: { sl@0: CleanupStack::PushL (p7); sl@0: const CPKCS7ContentInfo& p7info = p7->ContentInfo (); sl@0: if (checkType) sl@0: { sl@0: if (p7info.ContentType() != expectedType) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("Expected ContentType %d, got %d"), expectedType, p7info.ContentType()); sl@0: } sl@0: } sl@0: const TDesC8& content = p7info.ContentData(); sl@0: sl@0: if (checkLength) sl@0: { sl@0: if (content.Length() != expectedLength) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("Expected ContentLength %d, got %d"), expectedLength, content.Length()); sl@0: } sl@0: } sl@0: if (checkContent) sl@0: { sl@0: if (content.Length() != expectedContent->Length()) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("Expected ContentString length %d does not correspond to PKCS7 data length %d"), sl@0: expectedContent->Length(), content.Length()); sl@0: } sl@0: else sl@0: { sl@0: if (expectedContent->Compare(content) != 0) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF1(_L("Expected ContentString does not match PKCS7 content")); sl@0: } sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy (p7); sl@0: } sl@0: sl@0: } sl@0: } sl@0: else sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if (expectedContent) sl@0: { sl@0: CleanupStack::PopAndDestroy (expectedContent); sl@0: } sl@0: sl@0: if (!checkType && !checkLength && !checkContent && (TestStepResult()==EPass)) sl@0: { sl@0: SetTestStepResult(EInconclusive); sl@0: INFO_PRINTF1(_L("No test performed in this step")); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: // Step 4 Certificate sl@0: TVerdict CTPKCS7CertificateTest::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TBool checkCount; sl@0: TInt expectedCount; sl@0: sl@0: checkCount = GetIntFromConfig (ConfigSection(),_L("CertificateCount"), expectedCount); sl@0: sl@0: TInt err; sl@0: sl@0: sl@0: CPKCS7ContentInfo * contentInfo = NULL; sl@0: TRAP (err, contentInfo = CPKCS7ContentInfo::NewL(iRawData->Des())); sl@0: sl@0: if(err == KErrNone) sl@0: { sl@0: CPKCS7SignedObject * p7 = NULL; sl@0: if( contentInfo->ContentType() == 2) sl@0: { sl@0: TRAP (err, p7 = CPKCS7SignedObject::NewL(*contentInfo)); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF2(_L("Got %d building PKCS7 object"), err); sl@0: } sl@0: else sl@0: { sl@0: CleanupStack::PushL (p7); sl@0: const RPointerArray& certificates = p7->Certificates(); sl@0: if (checkCount) sl@0: { sl@0: if (certificates.Count() != expectedCount) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("Expected %d certificates, got %d"), expectedCount, certificates.Count()); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy (p7); sl@0: } sl@0: sl@0: } sl@0: } sl@0: else sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if (!checkCount && (TestStepResult()==EPass)) sl@0: { sl@0: SetTestStepResult(EInconclusive); sl@0: INFO_PRINTF1(_L("No test performed in this step")); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: // Step 5 Signer sl@0: TVerdict CTPKCS7SignerTest::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TBool checkCount; sl@0: TInt expectedCount; sl@0: sl@0: checkCount = GetIntFromConfig (ConfigSection(),_L("SignerCount"), expectedCount); sl@0: sl@0: TInt err; sl@0: sl@0: CPKCS7ContentInfo * contentInfo = NULL; sl@0: TRAP (err, contentInfo = CPKCS7ContentInfo::NewL(iRawData->Des())); sl@0: if(err == KErrNone) sl@0: { sl@0: CPKCS7SignedObject * p7 = NULL; sl@0: if( contentInfo->ContentType() == 2) sl@0: { sl@0: TRAPD (err, p7 = CPKCS7SignedObject::NewL(*contentInfo)); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF2(_L("Got %d building PKCS7 object"), err); sl@0: } sl@0: else sl@0: { sl@0: CleanupStack::PushL (p7); sl@0: const RPointerArray& signers = p7->SignerInfo(); sl@0: if (checkCount) sl@0: { sl@0: if (signers.Count() != expectedCount) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("Expected %d signers, got %d"), expectedCount, signers.Count()); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy (p7); sl@0: } sl@0: sl@0: } sl@0: } sl@0: sl@0: sl@0: if (!checkCount && (TestStepResult()==EPass)) sl@0: { sl@0: SetTestStepResult(EInconclusive); sl@0: INFO_PRINTF1(_L("No test performed in this step")); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: sl@0: //Encrypted Data sl@0: TVerdict CTPKCS7EncryptedDataTest::doTestStepL() sl@0: { sl@0: sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TInt reason; sl@0: // Read from INI file. sl@0: GetIntFromConfig(ConfigSection(),_L("Reason"),reason); sl@0: sl@0: //Is Valid sl@0: TBool expectedValid; sl@0: TBool checkValid; sl@0: sl@0: checkValid = GetBoolFromConfig(ConfigSection(),_L("IsValid"), expectedValid); sl@0: sl@0: __UHEAP_MARK; sl@0: CPKCS7ContentInfo *contentInfo = NULL; sl@0: TRAPD (err, contentInfo = CPKCS7ContentInfo::NewL(iRawData->Des())); sl@0: CleanupStack::PushL(contentInfo); sl@0: if(err == KErrNone) sl@0: { sl@0: sl@0: CPKCS7EncryptedDataObject* p7 = NULL; sl@0: TInt type = contentInfo->ContentType(); sl@0: if( contentInfo->ContentType() == CPKCS7ContentInfo::EContentTypeEncryptedData) sl@0: { sl@0: TRAPD (err, p7 = CPKCS7EncryptedDataObject::NewL(*contentInfo)); sl@0: CleanupStack::PushL(p7); sl@0: __UHEAP_MARK; sl@0: sl@0: if (checkValid) sl@0: { sl@0: if(!expectedValid && err == reason) sl@0: { sl@0: CleanupStack::PopAndDestroy(2,contentInfo);//p7, contentInfo sl@0: return TestStepResult(); sl@0: } sl@0: if(!expectedValid && contentInfo->ContentType() == 1) sl@0: { sl@0: CleanupStack::PopAndDestroy(2,contentInfo);//p7, contentInfo sl@0: return TestStepResult(); sl@0: } sl@0: } sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: ERR_PRINTF2(_L("Got %d building PKCS7 object"), err); sl@0: } sl@0: sl@0: //CONTENT TYPE sl@0: CPKCS7EncryptedDataObject::TContentType contentType = p7->ContentType(); sl@0: if(contentType != CPKCS7EncryptedDataObject::EPkcs7Data) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: ERR_PRINTF1(_L("ContentType does not match")); sl@0: CleanupStack::PopAndDestroy(3,contentInfo);//expectedContentType, p7, contentInfo sl@0: return TestStepResult(); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("ContentType matches")); sl@0: } sl@0: sl@0: //ENCRYPTEDCONTENT DATA sl@0: const TDesC8& contentData = p7->EncryptedContentInfoData(); sl@0: if(contentData.Compare(*iContentData) != 0) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: ERR_PRINTF1(_L("EncryptedContentData does not match")); sl@0: CleanupStack::PopAndDestroy(2,contentInfo); //p7, contentInfo sl@0: return TestStepResult(); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("EncryptedContentData matches")); sl@0: } sl@0: sl@0: sl@0: //SALT sl@0: const CPBEncryptParms& encryptParams = p7->EncryptParams(); sl@0: if((encryptParams.Salt()).Compare(*iSaltValue) != 0) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: ERR_PRINTF1(_L("Salt Value does not match")); sl@0: CleanupStack::PopAndDestroy(2, contentInfo);//p7,contentInfo sl@0: return TestStepResult(); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Salt Value matches")); sl@0: } sl@0: sl@0: sl@0: //ITERATION COUNT sl@0: TBool checkIteration; sl@0: TInt expectedIterationCount; sl@0: sl@0: checkIteration = GetIntFromConfig(ConfigSection(),_L("Iteration"), expectedIterationCount); sl@0: if(checkIteration) sl@0: { sl@0: if(encryptParams.Iterations() != expectedIterationCount) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: ERR_PRINTF1(_L("Iterations does not match")); sl@0: CleanupStack::PopAndDestroy(2, contentInfo);//p7, contentInfo sl@0: return TestStepResult(); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Iteration matches")); sl@0: } sl@0: } sl@0: sl@0: //CIPHER sl@0: TBool checkCipher; sl@0: TPtrC expectedCipher; sl@0: TPBECipher cipherValue = (TPBECipher) -1;//assign to impossible value sl@0: sl@0: checkCipher = GetStringFromConfig(ConfigSection(),_L("Algorithm"), expectedCipher); sl@0: sl@0: if(checkCipher) sl@0: { sl@0: if(expectedCipher.Compare(_L("pbeWithSHA1And40BitRC2_CBC")) == 0) sl@0: { sl@0: cipherValue = ECipherRC2_CBC_40_5; sl@0: } sl@0: else if(expectedCipher.Compare(_L("pbeWithSHA1And128BitRC4")) == 0) sl@0: { sl@0: cipherValue = ECipherARC4_128; sl@0: } sl@0: else if(expectedCipher.Compare(_L("pbeWithSHA1AndDES-CBC")) == 0) sl@0: { sl@0: cipherValue = ECipherDES_CBC; sl@0: } sl@0: else if(expectedCipher.Compare(_L("pbeWithSHAAnd3_KeyTripleDES_CBC")) == 0) sl@0: { sl@0: cipherValue = ECipher3DES_CBC; sl@0: } sl@0: else if(expectedCipher.Compare(_L("pbeWithSHAAnd2-KeyTripleDES-CBC"))==0) sl@0: { sl@0: cipherValue = ECipher2Key3DES_CBC; sl@0: } sl@0: else if(expectedCipher.Compare(_L("pbeWithSHA1And40BitRC4")) == 0) sl@0: { sl@0: cipherValue = ECipherARC4_40; sl@0: } sl@0: else if(expectedCipher.Compare(_L("pbewithSHAAnd128BitRC2CBC")) == 0) sl@0: { sl@0: cipherValue = ECipherRC2_CBC_128_16; sl@0: } sl@0: else if(expectedCipher.Compare(_L("pbeWithSHA1AndRC2_CBC")) == 0) sl@0: { sl@0: cipherValue = ECipherRC2_CBC_40; sl@0: } sl@0: sl@0: if(encryptParams.Cipher() != cipherValue) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: ERR_PRINTF1(_L("Cipher does not match")); sl@0: CleanupStack::PopAndDestroy(3, contentInfo);//expectedCipher,p7,contentInfo sl@0: return TestStepResult(); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Cipher matches")); sl@0: } sl@0: } sl@0: sl@0: if(contentData.Length() != 0) sl@0: { sl@0: //Decryption sl@0: TBool checkPassword; sl@0: TPtrC password; sl@0: sl@0: checkPassword = GetStringFromConfig(ConfigSection(),_L("Password"), password); sl@0: sl@0: if(checkPassword) sl@0: { sl@0: HBufC8* plainText = p7->DecryptDataL(password); sl@0: delete plainText; sl@0: SetTestStepResult(EPass); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(p7); sl@0: } sl@0: //If ContentType is not Encrypted Data sl@0: else sl@0: { sl@0: sl@0: if(checkValid) sl@0: { sl@0: if(!expectedValid && err == reason) sl@0: { sl@0: CleanupStack::PopAndDestroy(contentInfo); sl@0: return TestStepResult(); sl@0: } sl@0: else sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: sl@0: } sl@0: } sl@0: else if(err != reason) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: CleanupStack::PopAndDestroy(contentInfo); sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: //Digest Info sl@0: TVerdict CTPKCS7DigestInfoTest::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: __UHEAP_MARK; sl@0: sl@0: TInt reason; sl@0: // Read from INI file. sl@0: GetIntFromConfig(ConfigSection(),_L("Reason"),reason); sl@0: sl@0: CPKCS7DigestInfo* p7 = NULL; sl@0: TRAPD (err, p7 = CPKCS7DigestInfo::NewL(iRawData->Des())); sl@0: CleanupStack::PushL(p7); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: if(err == reason) sl@0: { sl@0: CleanupStack::PopAndDestroy(p7); sl@0: SetTestStepResult(EPass); sl@0: return TestStepResult(); sl@0: } sl@0: else sl@0: { sl@0: SetTestStepResult(EFail); sl@0: ERR_PRINTF2(_L("Got %d building PKCS7 object"), err); sl@0: } sl@0: } sl@0: sl@0: //DIGEST sl@0: const TDesC8& digest = p7->Digest(); sl@0: if(digest.Compare(*iDigest) != 0) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: ERR_PRINTF1(_L("Digest does not match")); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Digest matches")); sl@0: } sl@0: sl@0: //ALGORITHM ID sl@0: TBool checkAlgorithm; sl@0: TPtrC expectedAlgorithm; sl@0: TAlgorithmId algorithmId = (TAlgorithmId) -1; sl@0: sl@0: checkAlgorithm = GetStringFromConfig(ConfigSection(),_L("AlgorithmId"), expectedAlgorithm); sl@0: sl@0: if(checkAlgorithm) sl@0: { sl@0: if(expectedAlgorithm.Compare(_L("SHA1")) == 0) sl@0: { sl@0: algorithmId = ESHA1; sl@0: } sl@0: else if(expectedAlgorithm.Compare(_L("MD5")) == 0) sl@0: { sl@0: algorithmId = EMD5; sl@0: } sl@0: sl@0: if(algorithmId != p7->Algorithm()) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: ERR_PRINTF1(_L("Algorithm Id does not match")); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Algorithm Id matches")); sl@0: } sl@0: } sl@0: sl@0: //ENCODED PARAMS sl@0: const TDesC8& encodedParams= p7->EncodedParams(); sl@0: sl@0: if(encodedParams.Length() != 0) sl@0: { sl@0: if(encodedParams.Compare(*iEncodedParams)) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: ERR_PRINTF1(_L("EncodedParams does not match")); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("EncodedParams match")); sl@0: } sl@0: } sl@0: else if(!iEncodedParams) sl@0: { sl@0: INFO_PRINTF1(_L("EncodedParams not present")); sl@0: } sl@0: sl@0: sl@0: CleanupStack::PopAndDestroy(p7); sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: //EncryptedDataCorrupt sl@0: //Step8 sl@0: TVerdict CTPKCS7EncryptedDataCorruptTest::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: __UHEAP_MARK; sl@0: TInt reason; sl@0: GetIntFromConfig(ConfigSection(),_L("Reason"),reason); sl@0: sl@0: CPKCS7ContentInfo *contentInfo = NULL; sl@0: TRAPD (err, contentInfo = CPKCS7ContentInfo::NewL(iRawData->Des())); sl@0: CleanupStack::PushL(contentInfo); sl@0: sl@0: if(err != KErrNone) sl@0: { sl@0: if (err != reason) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("Expected result %d, got %d"), reason, err); sl@0: } sl@0: } sl@0: sl@0: sl@0: if (err == reason) sl@0: { sl@0: CleanupStack::PopAndDestroy(contentInfo); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: CPKCS7EncryptedDataObject* p7 = NULL; sl@0: TRAPD (err1, p7 = CPKCS7EncryptedDataObject::NewL(*contentInfo)); sl@0: CleanupStack::PushL(p7); sl@0: sl@0: if (err1 != reason) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("Expected result %d, got %d"), reason, err); sl@0: } sl@0: CleanupStack::PopAndDestroy(2,contentInfo);//p7, contentInfo sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: //DigestInfoCorrupt sl@0: //Step 9 sl@0: TVerdict CTPKCS7DigestInfoCorruptTest::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: __UHEAP_MARK; sl@0: TInt reason; sl@0: GetIntFromConfig(ConfigSection(),_L("Reason"),reason); sl@0: sl@0: CPKCS7DigestInfo* p7 = NULL; sl@0: TRAPD (err, p7 = CPKCS7DigestInfo::NewL(iRawData->Des())); sl@0: delete p7; sl@0: sl@0: if (err != reason) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("Expected result %d, got %d"), reason, err); sl@0: } sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: