os/security/cryptoservices/certificateandkeymgmt/tpkixcert_tef/src/pkixcertstepbase.cpp
First public contribution.
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "pkixcertstepbase.h"
20 #include "cleanuputils.h"
23 CPkixCertStepBase::~CPkixCertStepBase()
25 delete iConcatenatedChain;
26 iConcatenatedChain = NULL;
28 iProcessedOids.Reset();
30 iRootCerts.ResetAndDestroy();
31 CActiveScheduler::Install(NULL);
35 TVerdict CPkixCertStepBase::doTestStepPreambleL()
37 //read in stuff from config
39 GetBoolFromConfig(ConfigSection(), KPerformOom, iPerformOom);
41 iFileServer.Connect();
44 //temporary storage of the DER encoded certs so we can calculate the combined size for iConcatenatedChain
45 RPointerArray<HBufC8> rawCerts;
46 CleanupResetAndDestroy<RPointerArray<HBufC8> >::PushL(rawCerts);
49 GetStringFromConfig(ConfigSection(), KEndEntity, configString);
50 HBufC8* certBuf = ReadFileLC(configString);
51 rawCerts.AppendL(certBuf);
52 CleanupStack::Pop(certBuf);
53 chainSize += certBuf->Size();
56 RArray<TPtrC> certFileNames;
57 CleanupClosePushL(certFileNames);
59 GetStringArrayFromConfigL(ConfigSection(), KIntermediateCert, certFileNames);
62 for (i = 0; i < certFileNames.Count(); ++i)
64 certBuf = ReadFileLC(certFileNames[i]);
65 rawCerts.AppendL(certBuf);
66 CleanupStack::Pop(certBuf);
67 chainSize += certBuf->Size();
70 CleanupStack::PopAndDestroy(&certFileNames);
72 iConcatenatedChain = HBufC8::NewL(chainSize);
73 TPtr8 modPtr = iConcatenatedChain->Des();
74 for (i = 0; i < rawCerts.Count(); i++)
76 modPtr.Append(*rawCerts[i]);
79 CleanupStack::PopAndDestroy(&rawCerts);
83 //read in oid values. the usage of these is dependant on the test step
84 GetStringArrayFromConfigL(ConfigSection(), KOid, iOids);
85 //convert into argument format used by APIs
86 for (i=0; i < iOids.Count(); ++i)
88 iProcessedOids.AppendL(&(iOids[i]));
92 RArray<TPtrC> certFileNames2;
93 CleanupClosePushL(certFileNames2);
95 GetStringArrayFromConfigL(ConfigSection(), KRootCert, certFileNames2);
96 CX509Certificate* cert;
97 for (i = 0; i < certFileNames2.Count(); ++i)
99 certBuf = ReadFileLC(certFileNames2[i]);
100 cert = CX509Certificate::NewLC(*certBuf);
101 iRootCerts.AppendL(cert);
102 CleanupStack::Pop(cert);
103 CleanupStack::PopAndDestroy(certBuf);
105 CleanupStack::PopAndDestroy(&certFileNames2);
108 iUseUidOverload = GetIntFromConfig(ConfigSection(), KUid, uid);
111 iScheduler=new(ELeave) CActiveScheduler();
112 CActiveScheduler::Install(iScheduler);
118 //N.B. iCertChain must be popped and destroyed at the end of any deriving class's PerformTestL() method
119 void CPkixCertStepBase::PerformTestL()
121 iPtr.Set(*iConcatenatedChain);
123 //split on which of the NewLs to use
126 iCertChain = CPKIXCertChain::NewLC(iFileServer, iPtr, iUid);
130 iCertChain = CPKIXCertChain::NewLC(iFileServer, iPtr, iRootCerts);
135 HBufC8* CPkixCertStepBase::ReadFileLC(const TDesC& aFileName)
138 User::LeaveIfError(file.Open(iFileServer, aFileName, EFileRead));
139 CleanupClosePushL(file);
142 CleanupStack::PopAndDestroy();//fileClose
144 HBufC8* result = HBufC8::NewLC(size);
145 TPtr8 ptr(result->Des());
148 RFileReadStream stream;
149 User::LeaveIfError(stream.Open(iFileServer, aFileName, EFileStream));
150 CleanupClosePushL(stream);
151 stream.ReadL(ptr, size);
152 CleanupStack::PopAndDestroy();//streamClose
157 void CPkixCertStepBase::GetStringArrayFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, RArray<TPtrC>& aArray)
159 HBufC* buf = HBufC::NewLC(aKeyName.Length() + KKeyFormat().Length());
160 TPtr ptr(buf->Des());
161 INFO_PRINTF2(_L("Parsing attribute: %S"), &aKeyName);
169 ptr.AppendFormat(KKeyFormat(), i);
172 cont = GetStringFromConfig(aSectName, ptr, val);
175 User::LeaveIfError(aArray.Append(val));
179 INFO_PRINTF2(_L("Element count: %d"), i-1);
180 CleanupStack::PopAndDestroy(buf);
184 void CPkixCertStepBase::GetIntArrayFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, RArray<TInt>& aArray)
186 HBufC* buf = HBufC::NewLC(aKeyName.Length() + KKeyFormat().Length());
187 TPtr ptr(buf->Des());
188 INFO_PRINTF2(_L("Parsing attribute: %S"), &aKeyName);
196 ptr.AppendFormat(KKeyFormat(), i);
199 cont = GetIntFromConfig(aSectName, ptr, val);
202 User::LeaveIfError(aArray.Append(val));
206 INFO_PRINTF2(_L("Element count: %d"), i-1);
207 CleanupStack::PopAndDestroy(buf);
210 TVerdict CPkixCertStepBase::doTestStepL()
214 TRAPD(err, PerformTestL());
217 SetTestStepResult(EPass);
220 SetTestStepResult(EFail);
228 return TestStepResult();
233 void CPkixCertStepBase::PerformOomTestL()
235 for (TInt oomCount = 0; ; oomCount++)
238 __UHEAP_SETFAIL(RHeap::EDeterministic, oomCount);
239 TInt countBefore = User::CountAllocCells();
240 TRAPD(error, PerformTestL());// ----> This is the actual test that runs under OOM conditions.
241 TInt countAfter = User::CountAllocCells();
243 if (countBefore != countAfter)
245 INFO_PRINTF2(_L("OOM Failed at %d"), oomCount);
246 SetTestStepResult(EFail);
249 INFO_PRINTF2(_L("Result: %d"), error);
250 if (error == KErrNone)
252 INFO_PRINTF1(_L("Test outcome : Passed"));
253 SetTestStepResult(EPass);