sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "tactionvalidate.h"
|
sl@0
|
20 |
#include "t_inputextra.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
_LIT(KChainStart, "<chain>");
|
sl@0
|
23 |
_LIT(KChainEnd, "</chain>");
|
sl@0
|
24 |
_LIT(KIOStart, "<io>");
|
sl@0
|
25 |
_LIT(KIOEnd, "</io>");
|
sl@0
|
26 |
_LIT(KCertPath, "\\pkixtestdata\\");
|
sl@0
|
27 |
|
sl@0
|
28 |
CActionValidate::~CActionValidate()
|
sl@0
|
29 |
{
|
sl@0
|
30 |
if (iPolicies)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
iPolicies->ResetAndDestroy();
|
sl@0
|
33 |
delete iPolicies;
|
sl@0
|
34 |
iPolicies = 0;
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
delete iValidationResult;
|
sl@0
|
38 |
delete iChain;
|
sl@0
|
39 |
|
sl@0
|
40 |
delete iCertUtils;
|
sl@0
|
41 |
|
sl@0
|
42 |
delete iTestChain;
|
sl@0
|
43 |
delete iTestIO;
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
CActionValidate::CActionValidate(RFs& aFs,
|
sl@0
|
47 |
CConsoleBase& aConsole,
|
sl@0
|
48 |
Output& aOut)
|
sl@0
|
49 |
: CTestAction(aConsole, aOut), iFs(aFs)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
|
sl@0
|
54 |
void CActionValidate::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
CTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
57 |
HBufC* aBody = HBufC::NewLC(aTestActionSpec.iActionBody.Length());
|
sl@0
|
58 |
aBody->Des().Copy(aTestActionSpec.iActionBody);
|
sl@0
|
59 |
TInt pos = 0;
|
sl@0
|
60 |
TInt err = KErrNone;
|
sl@0
|
61 |
TPtrC chainBuf = Input::ParseElement(*aBody, KChainStart, KChainEnd, pos, err);
|
sl@0
|
62 |
iTestChain = CTestChain::NewL(chainBuf);
|
sl@0
|
63 |
if (!AddParametersL(*aBody, pos))
|
sl@0
|
64 |
{
|
sl@0
|
65 |
// There must be at least one IO thing
|
sl@0
|
66 |
User::Leave(KErrNotFound);
|
sl@0
|
67 |
}
|
sl@0
|
68 |
while(AddParametersL(*aBody, pos))
|
sl@0
|
69 |
{
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
iValidationResult = CPKIXValidationResult::NewL();
|
sl@0
|
73 |
TDriveUnit sysDrive (RFs::GetSystemDrive());
|
sl@0
|
74 |
TDriveName driveName(sysDrive.Name());
|
sl@0
|
75 |
iCertPath.Copy(driveName);
|
sl@0
|
76 |
iCertPath.Append(KCertPath);
|
sl@0
|
77 |
|
sl@0
|
78 |
CleanupStack::PopAndDestroy(aBody);
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
void CActionValidate::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
switch (iState)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
case EDoValidateTestStart:
|
sl@0
|
86 |
{
|
sl@0
|
87 |
__ASSERT_DEBUG(!iChain, User::Panic(_L("CPKIXCertTest"), 1));
|
sl@0
|
88 |
TRAPD(err, CreateChainL());
|
sl@0
|
89 |
iState = EDoValidateTestValidate;
|
sl@0
|
90 |
TRequestStatus* status = &aStatus;
|
sl@0
|
91 |
User::RequestComplete(status, err);
|
sl@0
|
92 |
break;
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
case EDoValidateTestValidate:
|
sl@0
|
96 |
{
|
sl@0
|
97 |
// 1) write the overall result we expect
|
sl@0
|
98 |
iOut.writeSpaces(4);
|
sl@0
|
99 |
iOut.writeString(_L("Expected result = "));
|
sl@0
|
100 |
iOut.writeString(iTestIO->iError);
|
sl@0
|
101 |
iOut.writeNewLine();
|
sl@0
|
102 |
|
sl@0
|
103 |
// 2) now do the validation
|
sl@0
|
104 |
|
sl@0
|
105 |
iTime.UniversalTime();
|
sl@0
|
106 |
|
sl@0
|
107 |
if (iTestIO->iPolicyInput->Count() > 0)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
__ASSERT_DEBUG(!iPolicies, User::Panic(_L("CPKIXCertTest"), 1));
|
sl@0
|
110 |
__ASSERT_DEBUG(iChain, User::Panic(_L("CPKIXCertTest"), 1));
|
sl@0
|
111 |
|
sl@0
|
112 |
iPolicies = new (ELeave) CArrayPtrFlat<HBufC> (1);
|
sl@0
|
113 |
TInt count = iTestIO->iPolicyInput->Count();
|
sl@0
|
114 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
TPtrC policy = iTestIO->iPolicyInput->MdcaPoint(i);
|
sl@0
|
117 |
HBufC* pBuf = policy.AllocL();
|
sl@0
|
118 |
CleanupStack::PushL(pBuf);
|
sl@0
|
119 |
iPolicies->AppendL(pBuf);
|
sl@0
|
120 |
CleanupStack::Pop();
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
iChain->ValidateL(*iValidationResult, iTime, *iPolicies, aStatus);
|
sl@0
|
124 |
}
|
sl@0
|
125 |
else
|
sl@0
|
126 |
{
|
sl@0
|
127 |
iChain->ValidateL(*iValidationResult, iTime, aStatus);
|
sl@0
|
128 |
}
|
sl@0
|
129 |
iState = EDoValidateTestValidated;
|
sl@0
|
130 |
}
|
sl@0
|
131 |
break;
|
sl@0
|
132 |
|
sl@0
|
133 |
case EDoValidateTestValidated:
|
sl@0
|
134 |
{
|
sl@0
|
135 |
// 3) write the overall result
|
sl@0
|
136 |
iOut.writeSpaces(4);
|
sl@0
|
137 |
iOut.writeString(_L("Actual result = "));
|
sl@0
|
138 |
CCertUtils::WriteError(iValidationResult->Error().iReason, iOut);
|
sl@0
|
139 |
TBuf<128> iActualResult = CCertUtils::MapError(iValidationResult->Error().iReason);
|
sl@0
|
140 |
iOut.writeNewLine();
|
sl@0
|
141 |
iOut.writeNewLine();
|
sl@0
|
142 |
|
sl@0
|
143 |
// 4) write the policy info
|
sl@0
|
144 |
TBool checkingPolicies =
|
sl@0
|
145 |
((iTestIO->iIPoliciesSet) || (iTestIO->iOPoliciesSet));
|
sl@0
|
146 |
if (checkingPolicies)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
if (iTestIO->iIPoliciesSet)
|
sl@0
|
149 |
{
|
sl@0
|
150 |
// 4.1) policies we supplied
|
sl@0
|
151 |
iOut.writeSpaces(4);
|
sl@0
|
152 |
iOut.writeString(_L("Supplied policy set: "));
|
sl@0
|
153 |
iOut.writeNewLine();
|
sl@0
|
154 |
WritePolicies(*(iTestIO->iPolicyInput));
|
sl@0
|
155 |
}
|
sl@0
|
156 |
if (iTestIO->iOPoliciesSet)
|
sl@0
|
157 |
{
|
sl@0
|
158 |
// 4.2) policies we expect
|
sl@0
|
159 |
iOut.writeSpaces(4);
|
sl@0
|
160 |
iOut.writeString(_L("Expected user-constrained policy set: "));
|
sl@0
|
161 |
iOut.writeNewLine();
|
sl@0
|
162 |
WritePolicies(*(iTestIO->iExpectedPolicyOutput));
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
// 4.3) policies we collected
|
sl@0
|
166 |
iOut.writeSpaces(4);
|
sl@0
|
167 |
iOut.writeString(_L("Actual user-constrained policy set: "));
|
sl@0
|
168 |
iOut.writeNewLine();
|
sl@0
|
169 |
const CArrayPtrFlat<CX509CertPolicyInfo>& policies = iValidationResult->Policies();
|
sl@0
|
170 |
TInt actualPolicyCount = policies.Count();
|
sl@0
|
171 |
for (TInt j = 0; j < actualPolicyCount; j++)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
iOut.writeSpaces(8);
|
sl@0
|
174 |
iOut.writeString(policies.At(j)->Id());
|
sl@0
|
175 |
iOut.writeNewLine();
|
sl@0
|
176 |
}
|
sl@0
|
177 |
iOut.writeNewLine();
|
sl@0
|
178 |
|
sl@0
|
179 |
//check expected user-constrained policy set == actual user-constrained policy set
|
sl@0
|
180 |
TBool policyOutputCorrect = ETrue;
|
sl@0
|
181 |
CDesCArray* expectedPolicies = iTestIO->iExpectedPolicyOutput;
|
sl@0
|
182 |
TInt expectedPolicyCount = expectedPolicies->MdcaCount();
|
sl@0
|
183 |
if (expectedPolicyCount == actualPolicyCount)
|
sl@0
|
184 |
{
|
sl@0
|
185 |
for (TInt k = 0; k < expectedPolicyCount; k++)
|
sl@0
|
186 |
{
|
sl@0
|
187 |
TPtrC expectedPolicy = expectedPolicies->MdcaPoint(k);
|
sl@0
|
188 |
TBool policyFound = EFalse;
|
sl@0
|
189 |
for (TInt l = 0; l < actualPolicyCount; l++)
|
sl@0
|
190 |
{
|
sl@0
|
191 |
TPtrC actualPolicy = policies.At(l)->Id();
|
sl@0
|
192 |
if (actualPolicy == expectedPolicy)
|
sl@0
|
193 |
{
|
sl@0
|
194 |
policyFound = ETrue;
|
sl@0
|
195 |
break;
|
sl@0
|
196 |
}
|
sl@0
|
197 |
}
|
sl@0
|
198 |
if (!policyFound)
|
sl@0
|
199 |
{
|
sl@0
|
200 |
policyOutputCorrect = EFalse;
|
sl@0
|
201 |
}
|
sl@0
|
202 |
}
|
sl@0
|
203 |
}
|
sl@0
|
204 |
else
|
sl@0
|
205 |
{
|
sl@0
|
206 |
policyOutputCorrect = EFalse;
|
sl@0
|
207 |
}
|
sl@0
|
208 |
iResult = (iTestIO->iError == iActualResult) && (policyOutputCorrect);
|
sl@0
|
209 |
}
|
sl@0
|
210 |
else //! checking policies
|
sl@0
|
211 |
{
|
sl@0
|
212 |
iResult = (iTestIO->iError == iActualResult);
|
sl@0
|
213 |
}
|
sl@0
|
214 |
iState = EDoValidateTestFinished;
|
sl@0
|
215 |
if (iPolicies)
|
sl@0
|
216 |
{
|
sl@0
|
217 |
iPolicies->ResetAndDestroy();
|
sl@0
|
218 |
delete iPolicies;
|
sl@0
|
219 |
iPolicies = 0;
|
sl@0
|
220 |
}
|
sl@0
|
221 |
TRequestStatus* status = &aStatus;
|
sl@0
|
222 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
223 |
}
|
sl@0
|
224 |
break;
|
sl@0
|
225 |
|
sl@0
|
226 |
case EDoValidateTestFinished:
|
sl@0
|
227 |
{
|
sl@0
|
228 |
__ASSERT_DEBUG(!iPolicies, User::Panic(_L("CPKIXCertTest"), 1));
|
sl@0
|
229 |
delete iChain;
|
sl@0
|
230 |
iChain = 0;
|
sl@0
|
231 |
iState = ERemoveCertsAfterTest;
|
sl@0
|
232 |
iActionState = EPostrequisite;
|
sl@0
|
233 |
TRequestStatus* status = &aStatus;
|
sl@0
|
234 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
235 |
}
|
sl@0
|
236 |
break;
|
sl@0
|
237 |
default:
|
sl@0
|
238 |
break;
|
sl@0
|
239 |
}
|
sl@0
|
240 |
}
|
sl@0
|
241 |
|
sl@0
|
242 |
TBool CActionValidate::TestResult(TInt /*aError*/)
|
sl@0
|
243 |
{
|
sl@0
|
244 |
return 0;
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
void CActionValidate::PerformCancel()
|
sl@0
|
248 |
{
|
sl@0
|
249 |
delete iChain;
|
sl@0
|
250 |
iChain = 0;
|
sl@0
|
251 |
}
|
sl@0
|
252 |
|
sl@0
|
253 |
void CActionValidate::AfterOOMFailure()
|
sl@0
|
254 |
{
|
sl@0
|
255 |
if (iPolicies)
|
sl@0
|
256 |
{
|
sl@0
|
257 |
iPolicies->ResetAndDestroy();
|
sl@0
|
258 |
delete iPolicies;
|
sl@0
|
259 |
iPolicies = 0;
|
sl@0
|
260 |
}
|
sl@0
|
261 |
}
|
sl@0
|
262 |
|
sl@0
|
263 |
void CActionValidate::Reset()
|
sl@0
|
264 |
{
|
sl@0
|
265 |
iState = EDoValidateTestStart;
|
sl@0
|
266 |
if (iPolicies)
|
sl@0
|
267 |
{
|
sl@0
|
268 |
iPolicies->ResetAndDestroy();
|
sl@0
|
269 |
delete iPolicies;
|
sl@0
|
270 |
iPolicies = 0;
|
sl@0
|
271 |
}
|
sl@0
|
272 |
delete iChain;
|
sl@0
|
273 |
iChain = 0;
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
void CActionValidate::DoReportAction()
|
sl@0
|
277 |
{
|
sl@0
|
278 |
iConsole.Printf(_L("u"));
|
sl@0
|
279 |
}
|
sl@0
|
280 |
|
sl@0
|
281 |
void CActionValidate::DoCheckResult(TInt /*aError*/)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
}
|
sl@0
|
284 |
|
sl@0
|
285 |
TBool CActionValidate::AddParametersL(const TDesC& aBuf, TInt& aPos)
|
sl@0
|
286 |
{
|
sl@0
|
287 |
TPtrC ioBuf = Input::ParseElement(aBuf, KIOStart, KIOEnd, aPos);
|
sl@0
|
288 |
if (ioBuf != KNullDesC)
|
sl@0
|
289 |
{
|
sl@0
|
290 |
iTestIO = CTestParameters::NewL(ioBuf);
|
sl@0
|
291 |
return ETrue;
|
sl@0
|
292 |
}
|
sl@0
|
293 |
return EFalse;
|
sl@0
|
294 |
}
|
sl@0
|
295 |
|
sl@0
|
296 |
void CActionValidate::WritePolicies(const CDesCArray& aPolicySet)
|
sl@0
|
297 |
{
|
sl@0
|
298 |
TInt count = aPolicySet.Count();
|
sl@0
|
299 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
300 |
{
|
sl@0
|
301 |
iOut.writeSpaces(8);
|
sl@0
|
302 |
iOut.writeString(aPolicySet.MdcaPoint(i));
|
sl@0
|
303 |
iOut.writeNewLine();
|
sl@0
|
304 |
}
|
sl@0
|
305 |
}
|
sl@0
|
306 |
|
sl@0
|
307 |
/*
|
sl@0
|
308 |
validate using the cert store as a source of root certificates
|
sl@0
|
309 |
*/
|
sl@0
|
310 |
|
sl@0
|
311 |
CTestAction* CActionValidateWithStore::NewL(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
312 |
Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
313 |
{
|
sl@0
|
314 |
CTestAction* self = CActionValidateWithStore::NewLC(aFs, aConsole,
|
sl@0
|
315 |
aOut, aTestActionSpec);
|
sl@0
|
316 |
CleanupStack::Pop(self);
|
sl@0
|
317 |
return self;
|
sl@0
|
318 |
}
|
sl@0
|
319 |
|
sl@0
|
320 |
CTestAction* CActionValidateWithStore::NewLC(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
321 |
Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
322 |
{
|
sl@0
|
323 |
CActionValidateWithStore* self = new(ELeave) CActionValidateWithStore(aFs, aConsole, aOut);
|
sl@0
|
324 |
CleanupStack::PushL(self);
|
sl@0
|
325 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
326 |
return self;
|
sl@0
|
327 |
}
|
sl@0
|
328 |
|
sl@0
|
329 |
CActionValidateWithStore::CActionValidateWithStore(RFs& aFs, CConsoleBase& aConsole,Output& aOut)
|
sl@0
|
330 |
:CActionValidate(aFs, aConsole, aOut)
|
sl@0
|
331 |
{
|
sl@0
|
332 |
}
|
sl@0
|
333 |
|
sl@0
|
334 |
void CActionValidateWithStore::DoPerformPrerequisite(TRequestStatus& aStatus)
|
sl@0
|
335 |
{
|
sl@0
|
336 |
switch (iState)
|
sl@0
|
337 |
{
|
sl@0
|
338 |
case ERemoveCertsBeforeTest:
|
sl@0
|
339 |
__ASSERT_DEBUG(!iCertUtils, User::Panic(_L("CPKIXCertTest"), 1));
|
sl@0
|
340 |
iCertUtils = CCertUtils::NewL(iFs);
|
sl@0
|
341 |
iCertUtils->RemoveCertsL(aStatus);
|
sl@0
|
342 |
iState = EAddRoot;
|
sl@0
|
343 |
break;
|
sl@0
|
344 |
|
sl@0
|
345 |
case EAddRoot:
|
sl@0
|
346 |
{
|
sl@0
|
347 |
TUid uid = { 1 };
|
sl@0
|
348 |
TRAPD(err, iCertUtils->RemoveApplicationL(uid));
|
sl@0
|
349 |
iCertUtils->AddApplicationL(_L("testpkix"), uid);
|
sl@0
|
350 |
TUid uid2 = { 2 };
|
sl@0
|
351 |
TRAP(err, iCertUtils->RemoveApplicationL(uid2));
|
sl@0
|
352 |
iCertUtils->AddApplicationL(_L("testpkix"), uid2);
|
sl@0
|
353 |
iCertUtils->AddCertL(iTestChain->iRootCertLabel,
|
sl@0
|
354 |
EX509Certificate, ECACertificate, 1, iCertPath,
|
sl@0
|
355 |
iTestChain->iRootCertFileName,
|
sl@0
|
356 |
aStatus); // 1 is trusted for our use
|
sl@0
|
357 |
iState = EAddIntermediateCerts;
|
sl@0
|
358 |
break;
|
sl@0
|
359 |
}
|
sl@0
|
360 |
|
sl@0
|
361 |
case EAddIntermediateCerts:
|
sl@0
|
362 |
{
|
sl@0
|
363 |
iCertUtils->AddCACertsL(*(iTestChain->iIntermediateCertsFileName),
|
sl@0
|
364 |
*(iTestChain->iIntermediateCertsLabel),
|
sl@0
|
365 |
EX509Certificate, 2, iCertPath,
|
sl@0
|
366 |
aStatus); //2 not trusted for our use
|
sl@0
|
367 |
iState = EDoValidateTestStart;
|
sl@0
|
368 |
iActionState = EAction;
|
sl@0
|
369 |
break;
|
sl@0
|
370 |
}
|
sl@0
|
371 |
default:
|
sl@0
|
372 |
break;
|
sl@0
|
373 |
}
|
sl@0
|
374 |
}
|
sl@0
|
375 |
|
sl@0
|
376 |
void CActionValidateWithStore::DoPerformPostrequisite(TRequestStatus& aStatus)
|
sl@0
|
377 |
{
|
sl@0
|
378 |
switch (iState)
|
sl@0
|
379 |
{
|
sl@0
|
380 |
case ERemoveCertsAfterTest:
|
sl@0
|
381 |
iCertUtils->RemoveCertsL(aStatus);
|
sl@0
|
382 |
iState = EEnd;
|
sl@0
|
383 |
break;
|
sl@0
|
384 |
|
sl@0
|
385 |
case EEnd:
|
sl@0
|
386 |
{
|
sl@0
|
387 |
delete iCertUtils;
|
sl@0
|
388 |
iCertUtils = 0;
|
sl@0
|
389 |
TRequestStatus* status = &aStatus;
|
sl@0
|
390 |
iFinished = ETrue;
|
sl@0
|
391 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
392 |
}
|
sl@0
|
393 |
break;
|
sl@0
|
394 |
default:
|
sl@0
|
395 |
break;
|
sl@0
|
396 |
}
|
sl@0
|
397 |
}
|
sl@0
|
398 |
|
sl@0
|
399 |
|
sl@0
|
400 |
void CActionValidateWithStore::CreateChainL()
|
sl@0
|
401 |
{
|
sl@0
|
402 |
HBufC8* eeCert = 0;
|
sl@0
|
403 |
|
sl@0
|
404 |
TRAPD(err,
|
sl@0
|
405 |
eeCert = Input::ReadFileL(iTestChain->iEECertFileName,
|
sl@0
|
406 |
iCertPath, iFs));
|
sl@0
|
407 |
if (err != KErrNone)
|
sl@0
|
408 |
{
|
sl@0
|
409 |
iConsole.Printf(_L("Error : couldn't open file "));
|
sl@0
|
410 |
iConsole.Printf(iTestChain->iEECertFileName);
|
sl@0
|
411 |
iConsole.Printf(_L("\n"));
|
sl@0
|
412 |
iOut.writeString(_L("Error : couldn't open file "));
|
sl@0
|
413 |
iOut.writeString(iTestChain->iEECertFileName);
|
sl@0
|
414 |
iOut.writeNewLine();
|
sl@0
|
415 |
User::Leave(err);
|
sl@0
|
416 |
}
|
sl@0
|
417 |
CleanupStack::PushL(eeCert);
|
sl@0
|
418 |
TUid testUid = TUid::Uid(1);
|
sl@0
|
419 |
iChain = CPKIXCertChain::NewL(iFs, *eeCert, testUid);
|
sl@0
|
420 |
CleanupStack::PopAndDestroy(eeCert);
|
sl@0
|
421 |
}
|
sl@0
|
422 |
|
sl@0
|
423 |
/*
|
sl@0
|
424 |
validate using a set of candidates root certs supplied by the client
|
sl@0
|
425 |
*/
|
sl@0
|
426 |
CTestAction* CActionValidateWithSuppliedCerts::NewL(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
427 |
Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
428 |
{
|
sl@0
|
429 |
CTestAction* self = CActionValidateWithSuppliedCerts::NewLC(aFs, aConsole,
|
sl@0
|
430 |
aOut, aTestActionSpec);
|
sl@0
|
431 |
CleanupStack::Pop(self);
|
sl@0
|
432 |
return self;
|
sl@0
|
433 |
}
|
sl@0
|
434 |
|
sl@0
|
435 |
CTestAction* CActionValidateWithSuppliedCerts::NewLC(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
436 |
Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
437 |
{
|
sl@0
|
438 |
CActionValidateWithSuppliedCerts* self = new(ELeave) CActionValidateWithSuppliedCerts(aFs, aConsole, aOut);
|
sl@0
|
439 |
CleanupStack::PushL(self);
|
sl@0
|
440 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
441 |
return self;
|
sl@0
|
442 |
}
|
sl@0
|
443 |
|
sl@0
|
444 |
CActionValidateWithSuppliedCerts::CActionValidateWithSuppliedCerts(RFs& aFs, CConsoleBase& aConsole,Output& aOut)
|
sl@0
|
445 |
:CActionValidate(aFs, aConsole, aOut)
|
sl@0
|
446 |
{
|
sl@0
|
447 |
}
|
sl@0
|
448 |
|
sl@0
|
449 |
void CActionValidateWithSuppliedCerts::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
450 |
{
|
sl@0
|
451 |
CActionValidate::ConstructL(aTestActionSpec);
|
sl@0
|
452 |
iRootCerts = new(ELeave) RPointerArray<CX509Certificate>;
|
sl@0
|
453 |
}
|
sl@0
|
454 |
|
sl@0
|
455 |
CActionValidateWithSuppliedCerts::~CActionValidateWithSuppliedCerts()
|
sl@0
|
456 |
{
|
sl@0
|
457 |
if (iRootCerts)
|
sl@0
|
458 |
{
|
sl@0
|
459 |
iRootCerts->ResetAndDestroy();
|
sl@0
|
460 |
delete iRootCerts;
|
sl@0
|
461 |
}
|
sl@0
|
462 |
delete iEndEntityAndIntermediateCerts;
|
sl@0
|
463 |
}
|
sl@0
|
464 |
|
sl@0
|
465 |
void CActionValidateWithSuppliedCerts::DoPerformPrerequisite(TRequestStatus& aStatus)
|
sl@0
|
466 |
{
|
sl@0
|
467 |
//initialise the big descriptor containing ee cert followed by all intermediate certs
|
sl@0
|
468 |
//and the array of candidate root certs
|
sl@0
|
469 |
|
sl@0
|
470 |
HBufC8* eeCert = Input::ReadFileLC(iTestChain->iEECertFileName, iCertPath, iFs);
|
sl@0
|
471 |
HBufC8* inter = InputExtra::ReadFilesLC(*(iTestChain->iIntermediateCertsFileName), iCertPath, iFs);
|
sl@0
|
472 |
TInt totalSize = (eeCert->Size()) + (inter->Size());
|
sl@0
|
473 |
iEndEntityAndIntermediateCerts = HBufC8::NewL(totalSize);
|
sl@0
|
474 |
TPtr8 pRes = iEndEntityAndIntermediateCerts->Des();
|
sl@0
|
475 |
pRes.Append(*eeCert);
|
sl@0
|
476 |
pRes.Append(*inter);
|
sl@0
|
477 |
CleanupStack::PopAndDestroy(2);//eeCert, inter
|
sl@0
|
478 |
|
sl@0
|
479 |
HBufC8* rootBuf = Input::ReadFileLC(iTestChain->iRootCertFileName, iCertPath, iFs);
|
sl@0
|
480 |
CX509Certificate* root = CX509Certificate::NewL(*rootBuf);
|
sl@0
|
481 |
CleanupStack::PopAndDestroy(rootBuf);
|
sl@0
|
482 |
CleanupStack::PushL(root);
|
sl@0
|
483 |
|
sl@0
|
484 |
User::LeaveIfError(iRootCerts->Append(root));
|
sl@0
|
485 |
CleanupStack::Pop(root);//
|
sl@0
|
486 |
|
sl@0
|
487 |
TRequestStatus* status = &aStatus;
|
sl@0
|
488 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
489 |
iState = EDoValidateTestStart;
|
sl@0
|
490 |
iActionState = EAction;
|
sl@0
|
491 |
}
|
sl@0
|
492 |
|
sl@0
|
493 |
void CActionValidateWithSuppliedCerts::DoPerformPostrequisite(TRequestStatus& aStatus)
|
sl@0
|
494 |
{
|
sl@0
|
495 |
delete iCertUtils;
|
sl@0
|
496 |
iCertUtils = NULL;
|
sl@0
|
497 |
TRequestStatus* status = &aStatus;
|
sl@0
|
498 |
iFinished = ETrue;
|
sl@0
|
499 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
500 |
}
|
sl@0
|
501 |
|
sl@0
|
502 |
void CActionValidateWithSuppliedCerts::CreateChainL()
|
sl@0
|
503 |
{
|
sl@0
|
504 |
//create chain object
|
sl@0
|
505 |
iChain = CPKIXCertChain::NewL(iFs, *iEndEntityAndIntermediateCerts, *iRootCerts);
|
sl@0
|
506 |
}
|