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 |
|
sl@0
|
20 |
#include "ValidateTest.h"
|
sl@0
|
21 |
#include "t_input.h"
|
sl@0
|
22 |
#include <ecom/ecom.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
_LIT(KPath, "");
|
sl@0
|
25 |
_LIT(KChainStart, "<chain>");
|
sl@0
|
26 |
_LIT(KDateIssuedStart, "<dateissued>");
|
sl@0
|
27 |
_LIT(KIOStart, "<io>");
|
sl@0
|
28 |
|
sl@0
|
29 |
CTestAction* CValidateTest::NewL(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
30 |
Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
CTestAction* self = CValidateTest::NewLC(aFs, aConsole, aOut, aTestActionSpec);
|
sl@0
|
33 |
CleanupStack::Pop(self);
|
sl@0
|
34 |
return self;
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
CTestAction* CValidateTest::NewLC(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
38 |
Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
39 |
{
|
sl@0
|
40 |
CValidateTest* self = new(ELeave) CValidateTest(aFs, aConsole, aOut);
|
sl@0
|
41 |
CleanupStack::PushL(self);
|
sl@0
|
42 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
43 |
return self;
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
|
sl@0
|
47 |
void CValidateTest::TestValidation(TRequestStatus& aStatus)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
iOriginalRequestStatus = &aStatus;
|
sl@0
|
50 |
aStatus = KRequestPending;
|
sl@0
|
51 |
|
sl@0
|
52 |
iState = EInit;
|
sl@0
|
53 |
TRequestStatus* status = &aStatus;
|
sl@0
|
54 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
55 |
}
|
sl@0
|
56 |
|
sl@0
|
57 |
CValidateTest::CValidateTest(RFs& aFs,
|
sl@0
|
58 |
CConsoleBase& aConsole,
|
sl@0
|
59 |
Output& aOut)
|
sl@0
|
60 |
: CTestAction(aConsole, aOut), iFs(aFs)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
void CValidateTest::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
65 |
{
|
sl@0
|
66 |
CTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
67 |
iValidationResult = CWTLSValidationResult::NewL();
|
sl@0
|
68 |
HBufC* aBody = HBufC::NewLC(aTestActionSpec.iActionBody.Length());
|
sl@0
|
69 |
aBody->Des().Copy(aTestActionSpec.iActionBody);
|
sl@0
|
70 |
// creates the test chan validation object
|
sl@0
|
71 |
iTestChain = CTestChainValidate::NewL();
|
sl@0
|
72 |
TPtrC chainBuf = Input::ParseElement(*aBody, KChainStart);
|
sl@0
|
73 |
|
sl@0
|
74 |
iTestChain->AddChainL(chainBuf);
|
sl@0
|
75 |
TPtrC ioDateIssued = Input::ParseElement(*aBody, KDateIssuedStart);
|
sl@0
|
76 |
iTestChain->AddDateIssued(ioDateIssued);
|
sl@0
|
77 |
TPtrC ioBuf = Input::ParseElement(*aBody, KIOStart);
|
sl@0
|
78 |
iTestChain->AddIOL(ioBuf);
|
sl@0
|
79 |
|
sl@0
|
80 |
CleanupStack::PopAndDestroy(aBody);
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
CValidateTest::~CValidateTest()
|
sl@0
|
84 |
{
|
sl@0
|
85 |
delete iTestChain;
|
sl@0
|
86 |
delete iCertUtils;
|
sl@0
|
87 |
delete iValidationResult;
|
sl@0
|
88 |
delete iChain;
|
sl@0
|
89 |
REComSession::FinalClose();
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
void CValidateTest::DoPerformPrerequisite(TRequestStatus& aStatus)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
TInt err = KErrNone;
|
sl@0
|
95 |
|
sl@0
|
96 |
switch (iState)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
case EInit:
|
sl@0
|
99 |
iResult = ETrue;
|
sl@0
|
100 |
__ASSERT_DEBUG(!iCertUtils, User::Panic(_L("TWTLSCertTest"), 1));
|
sl@0
|
101 |
iCertUtils = CCertUtils::NewL(iFs);
|
sl@0
|
102 |
TRAP(err, HandleEInitL(aStatus));
|
sl@0
|
103 |
break;
|
sl@0
|
104 |
|
sl@0
|
105 |
case EValidationStoreInitStoreManager1:
|
sl@0
|
106 |
TRAP(err, HandleEValidationInitStoreManager1L(aStatus));
|
sl@0
|
107 |
iActionState = EAction;
|
sl@0
|
108 |
break;
|
sl@0
|
109 |
case EValidationStoreDepopulateStore1:
|
sl@0
|
110 |
case EValidationStorePopulateStoreRoots:
|
sl@0
|
111 |
case EValidationStorePopulateStoreExtras:
|
sl@0
|
112 |
case EValidationStoreValidate:
|
sl@0
|
113 |
case EValidationStoreValidated:
|
sl@0
|
114 |
case EValidationStoreInitStoreManager2:
|
sl@0
|
115 |
case EValidationStoreDepopulateStore2:
|
sl@0
|
116 |
case EValidationStoreEnd:
|
sl@0
|
117 |
case EValidationSuppliedInit:
|
sl@0
|
118 |
case EValidationSuppliedValidate:
|
sl@0
|
119 |
case EValidationSuppliedValidated:
|
sl@0
|
120 |
case EFinished:
|
sl@0
|
121 |
break; // Nothing to do, for compiler
|
sl@0
|
122 |
}
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
void CValidateTest::DoPerformPostrequisite(TRequestStatus& aStatus)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
TInt err = KErrNone;
|
sl@0
|
128 |
|
sl@0
|
129 |
switch (iState)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
case EInit:
|
sl@0
|
132 |
case EValidationStoreInitStoreManager1:
|
sl@0
|
133 |
case EValidationStoreDepopulateStore1:
|
sl@0
|
134 |
case EValidationStorePopulateStoreRoots:
|
sl@0
|
135 |
case EValidationStorePopulateStoreExtras:
|
sl@0
|
136 |
case EValidationStoreValidate:
|
sl@0
|
137 |
case EValidationStoreValidated:
|
sl@0
|
138 |
case EValidationStoreInitStoreManager2:
|
sl@0
|
139 |
case EValidationStoreDepopulateStore2:
|
sl@0
|
140 |
case EValidationStoreEnd:
|
sl@0
|
141 |
break; // Nothing to do, for compiler
|
sl@0
|
142 |
case EValidationSuppliedInit:
|
sl@0
|
143 |
{
|
sl@0
|
144 |
iConsole.Printf(_L("started with supplied certs...\n"));
|
sl@0
|
145 |
iOut.writeString(_L("started with supplied certs..."));
|
sl@0
|
146 |
iOut.writeNewLine();
|
sl@0
|
147 |
|
sl@0
|
148 |
iState = EValidationSuppliedValidate;
|
sl@0
|
149 |
TRequestStatus* status = &aStatus;
|
sl@0
|
150 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
151 |
}
|
sl@0
|
152 |
break;
|
sl@0
|
153 |
|
sl@0
|
154 |
case EValidationSuppliedValidate:
|
sl@0
|
155 |
{
|
sl@0
|
156 |
HBufC8* encodedCerts = ReadFilesLC(*iTestChain->iServerCerts);
|
sl@0
|
157 |
|
sl@0
|
158 |
if(!encodedCerts)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
TRequestStatus* status = &aStatus;
|
sl@0
|
161 |
iFinished = ETrue;
|
sl@0
|
162 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
163 |
}
|
sl@0
|
164 |
else
|
sl@0
|
165 |
{
|
sl@0
|
166 |
TInt certCount = iTestChain->iRootCerts->MdcaCount();
|
sl@0
|
167 |
CArrayPtrFlat<CWTLSCertificate>* roots =
|
sl@0
|
168 |
new(ELeave) CArrayPtrFlat<CWTLSCertificate>(1);
|
sl@0
|
169 |
TCleanupItem cleanup(CleanupCertArray, roots);
|
sl@0
|
170 |
CleanupStack::PushL(cleanup);
|
sl@0
|
171 |
for (TInt i = 0; i < certCount; i++)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
// build the root certificates array including all the candidates.
|
sl@0
|
174 |
HBufC8* encCert =
|
sl@0
|
175 |
ReadFileLC(iTestChain->iRootCerts->MdcaPoint(i));
|
sl@0
|
176 |
CWTLSCertificate* cert = CWTLSCertificate::NewLC(encCert->Des());
|
sl@0
|
177 |
roots->AppendL(cert);
|
sl@0
|
178 |
CleanupStack::Pop(); // cert
|
sl@0
|
179 |
CleanupStack::PopAndDestroy(); // encCert
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
__ASSERT_DEBUG(!iChain, User::Panic(_L("CValidateTest"), 1));
|
sl@0
|
183 |
iChain = CWTLSCertChain::NewL(iFs, *encodedCerts, *roots);
|
sl@0
|
184 |
|
sl@0
|
185 |
CleanupStack::PopAndDestroy(2); // encodedCerts, roots
|
sl@0
|
186 |
|
sl@0
|
187 |
TDateTime dt(2000, EJuly, 0, 0, 0, 0, 0);
|
sl@0
|
188 |
if(iTestChain->iDateIssued == 1)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
dt.SetYear(2002);
|
sl@0
|
191 |
}
|
sl@0
|
192 |
iTime = dt;
|
sl@0
|
193 |
|
sl@0
|
194 |
iChain->ValidateL(*iValidationResult, iTime, aStatus);
|
sl@0
|
195 |
iState = EValidationSuppliedValidated;
|
sl@0
|
196 |
}
|
sl@0
|
197 |
}
|
sl@0
|
198 |
break;
|
sl@0
|
199 |
|
sl@0
|
200 |
case EValidationSuppliedValidated:
|
sl@0
|
201 |
{
|
sl@0
|
202 |
delete iChain;
|
sl@0
|
203 |
iChain = 0;
|
sl@0
|
204 |
TWTLSValidationStatus* expectedStatus = iTestChain->iError;
|
sl@0
|
205 |
const TWTLSValidationStatus& actualStatus = iValidationResult->Error();
|
sl@0
|
206 |
|
sl@0
|
207 |
iOut.writeString(_L("Expected Error = "));
|
sl@0
|
208 |
WriteError(expectedStatus->iReason);
|
sl@0
|
209 |
iOut.writeNewLine();
|
sl@0
|
210 |
|
sl@0
|
211 |
iOut.writeString(_L("Actual Error = "));
|
sl@0
|
212 |
WriteError(actualStatus.iReason);
|
sl@0
|
213 |
iOut.writeNewLine();
|
sl@0
|
214 |
|
sl@0
|
215 |
TInt wCount = iTestChain->iWarnings->Count();
|
sl@0
|
216 |
iOut.writeString(_L("Expected Warnings = "));
|
sl@0
|
217 |
iOut.writeNewLine();
|
sl@0
|
218 |
for (TInt i = 0; i < wCount; i++)
|
sl@0
|
219 |
{
|
sl@0
|
220 |
TWTLSValidationStatus warning = iTestChain->iWarnings->At(i);
|
sl@0
|
221 |
WriteError(warning.iReason);
|
sl@0
|
222 |
iOut.writeNewLine();
|
sl@0
|
223 |
}
|
sl@0
|
224 |
|
sl@0
|
225 |
iOut.writeString(_L("Actual Warnings = "));
|
sl@0
|
226 |
iOut.writeNewLine();
|
sl@0
|
227 |
const CArrayFixFlat<TWTLSValidationStatus>& warnings =
|
sl@0
|
228 |
iValidationResult->Warnings();
|
sl@0
|
229 |
wCount = warnings.Count();
|
sl@0
|
230 |
for (TInt j = 0; j < wCount; j++)
|
sl@0
|
231 |
{
|
sl@0
|
232 |
TWTLSValidationStatus warning = warnings.At(j);
|
sl@0
|
233 |
WriteError(warning.iReason);
|
sl@0
|
234 |
iOut.writeNewLine();
|
sl@0
|
235 |
}
|
sl@0
|
236 |
iOut.writeNewLine();
|
sl@0
|
237 |
|
sl@0
|
238 |
if(expectedStatus->iReason != actualStatus.iReason)
|
sl@0
|
239 |
{
|
sl@0
|
240 |
iConsole.Printf(_L("FAILED!!!!\n"));
|
sl@0
|
241 |
iOut.writeString(_L("FAILED!!!!"));
|
sl@0
|
242 |
iOut.writeNewLine();
|
sl@0
|
243 |
iResult = EFalse;
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
// End of validatewith supplied
|
sl@0
|
247 |
if (err != KErrNone)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
iOut.writeString(_L("Failed: leave code = "));
|
sl@0
|
250 |
iOut.writeNum(err);
|
sl@0
|
251 |
iOut.writeNewLine();
|
sl@0
|
252 |
}
|
sl@0
|
253 |
|
sl@0
|
254 |
iState = EFinished;
|
sl@0
|
255 |
TRequestStatus* status = &aStatus;
|
sl@0
|
256 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
257 |
}
|
sl@0
|
258 |
break;
|
sl@0
|
259 |
|
sl@0
|
260 |
case EFinished:
|
sl@0
|
261 |
{
|
sl@0
|
262 |
TTime end;
|
sl@0
|
263 |
end.HomeTime();
|
sl@0
|
264 |
TTimeIntervalMicroSeconds intervalMS = end.MicroSecondsFrom(iStart);
|
sl@0
|
265 |
iConsole.Printf(_L("Time taken = %d milliseconds\n"), (intervalMS.Int64()/1000));
|
sl@0
|
266 |
|
sl@0
|
267 |
TRequestStatus* status = &aStatus;
|
sl@0
|
268 |
iFinished = ETrue;
|
sl@0
|
269 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
270 |
}
|
sl@0
|
271 |
break;
|
sl@0
|
272 |
}
|
sl@0
|
273 |
}
|
sl@0
|
274 |
|
sl@0
|
275 |
void CValidateTest::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
276 |
{
|
sl@0
|
277 |
TRequestStatus* status = &aStatus;
|
sl@0
|
278 |
|
sl@0
|
279 |
switch (iState)
|
sl@0
|
280 |
{
|
sl@0
|
281 |
case EValidationStoreDepopulateStore1:
|
sl@0
|
282 |
{
|
sl@0
|
283 |
iCertUtils->RemoveCertsL(aStatus);
|
sl@0
|
284 |
iState = EValidationStorePopulateStoreRoots;
|
sl@0
|
285 |
break;
|
sl@0
|
286 |
}
|
sl@0
|
287 |
|
sl@0
|
288 |
case EValidationStorePopulateStoreRoots:
|
sl@0
|
289 |
{
|
sl@0
|
290 |
TUid uid = { 1 };
|
sl@0
|
291 |
TRAP_IGNORE(iCertUtils->RemoveApplicationL(uid));
|
sl@0
|
292 |
iCertUtils->AddApplicationL(_L("testwtls"), uid);
|
sl@0
|
293 |
iCertUtils->AddCACertsL(*iTestChain->iRootCerts,
|
sl@0
|
294 |
*iTestChain->iRootLabels, EWTLSCertificate, 1, KPath, aStatus);
|
sl@0
|
295 |
iState = EValidationStorePopulateStoreExtras;
|
sl@0
|
296 |
break;
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
case EValidationStorePopulateStoreExtras:
|
sl@0
|
300 |
{
|
sl@0
|
301 |
iCertUtils->AddCACertsL(*iTestChain->iExtraCerts,
|
sl@0
|
302 |
*iTestChain->iExtraLabels, EWTLSCertificate, 2, KPath, aStatus);
|
sl@0
|
303 |
iState = EValidationStoreValidate;
|
sl@0
|
304 |
break;
|
sl@0
|
305 |
}
|
sl@0
|
306 |
|
sl@0
|
307 |
case EValidationStoreValidate:
|
sl@0
|
308 |
{
|
sl@0
|
309 |
HBufC8* encodedCerts = ReadFilesLC(*iTestChain->iServerCerts);
|
sl@0
|
310 |
|
sl@0
|
311 |
TUid testUid = TUid::Uid(1);
|
sl@0
|
312 |
|
sl@0
|
313 |
if(!encodedCerts)
|
sl@0
|
314 |
{
|
sl@0
|
315 |
TRequestStatus* status = &aStatus;
|
sl@0
|
316 |
iFinished = ETrue;
|
sl@0
|
317 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
318 |
}
|
sl@0
|
319 |
else
|
sl@0
|
320 |
{
|
sl@0
|
321 |
__ASSERT_DEBUG(!iChain, User::Panic(_L("CValidateTest"), 1));
|
sl@0
|
322 |
iChain = CWTLSCertChain::NewL(iFs, *encodedCerts, testUid);
|
sl@0
|
323 |
CleanupStack::PopAndDestroy(); // encodedCerts
|
sl@0
|
324 |
|
sl@0
|
325 |
TDateTime dt(2000, EJuly, 0, 0, 0, 0, 0);
|
sl@0
|
326 |
if(iTestChain->iDateIssued == 1)
|
sl@0
|
327 |
{
|
sl@0
|
328 |
dt.SetYear(2002);
|
sl@0
|
329 |
}
|
sl@0
|
330 |
iTime = dt;
|
sl@0
|
331 |
|
sl@0
|
332 |
TRAP_IGNORE(iChain->ValidateL(*iValidationResult, iTime, aStatus));
|
sl@0
|
333 |
iState = EValidationStoreValidated;
|
sl@0
|
334 |
};
|
sl@0
|
335 |
break;
|
sl@0
|
336 |
}
|
sl@0
|
337 |
|
sl@0
|
338 |
case EValidationStoreValidated:
|
sl@0
|
339 |
{
|
sl@0
|
340 |
TInt count = iChain->Count();
|
sl@0
|
341 |
if (count > 0)
|
sl@0
|
342 |
{
|
sl@0
|
343 |
iOut.writeString(_L("EE certificate = "));
|
sl@0
|
344 |
const CWTLSCertificate& eeCert = iChain->Cert(0);
|
sl@0
|
345 |
HBufC* eeSubject = eeCert.SubjectL();
|
sl@0
|
346 |
CleanupStack::PushL(eeSubject);
|
sl@0
|
347 |
iOut.writeString(*eeSubject);
|
sl@0
|
348 |
CleanupStack::PopAndDestroy();
|
sl@0
|
349 |
iOut.writeNewLine();
|
sl@0
|
350 |
for (TInt i = 1; i < count - 1; i++)
|
sl@0
|
351 |
{
|
sl@0
|
352 |
iOut.writeString(_L("Intermediate certificate = "));
|
sl@0
|
353 |
const CWTLSCertificate& iCert = iChain->Cert(i);
|
sl@0
|
354 |
HBufC* subject = iCert.SubjectL();
|
sl@0
|
355 |
CleanupStack::PushL(subject);
|
sl@0
|
356 |
iOut.writeString(*subject);
|
sl@0
|
357 |
CleanupStack::PopAndDestroy();
|
sl@0
|
358 |
iOut.writeNewLine();
|
sl@0
|
359 |
}
|
sl@0
|
360 |
iOut.writeString(_L("Root certificate = "));
|
sl@0
|
361 |
const CWTLSCertificate& rCert = iChain->Cert(count-1);
|
sl@0
|
362 |
HBufC* rSubject = rCert.SubjectL();
|
sl@0
|
363 |
CleanupStack::PushL(rSubject);
|
sl@0
|
364 |
iOut.writeString(*rSubject);
|
sl@0
|
365 |
CleanupStack::PopAndDestroy();
|
sl@0
|
366 |
iOut.writeNewLine();
|
sl@0
|
367 |
}
|
sl@0
|
368 |
|
sl@0
|
369 |
TWTLSValidationStatus* expectedStatus = iTestChain->iError;
|
sl@0
|
370 |
const TWTLSValidationStatus& actualStatus = iValidationResult->Error();
|
sl@0
|
371 |
|
sl@0
|
372 |
iOut.writeString(_L("Expected Error = "));
|
sl@0
|
373 |
WriteError(expectedStatus->iReason);
|
sl@0
|
374 |
iOut.writeNewLine();
|
sl@0
|
375 |
|
sl@0
|
376 |
iOut.writeString(_L("Actual Error = "));
|
sl@0
|
377 |
WriteError(actualStatus.iReason);
|
sl@0
|
378 |
iOut.writeNewLine();
|
sl@0
|
379 |
|
sl@0
|
380 |
TInt wCount = iTestChain->iWarnings->Count();
|
sl@0
|
381 |
iOut.writeString(_L("Expected Warnings = "));
|
sl@0
|
382 |
iOut.writeNewLine();
|
sl@0
|
383 |
for (TInt i = 0; i < wCount; i++)
|
sl@0
|
384 |
{
|
sl@0
|
385 |
TWTLSValidationStatus warning = iTestChain->iWarnings->At(i);
|
sl@0
|
386 |
WriteError(warning.iReason);
|
sl@0
|
387 |
iOut.writeNewLine();
|
sl@0
|
388 |
}
|
sl@0
|
389 |
|
sl@0
|
390 |
iOut.writeString(_L("Actual Warnings = "));
|
sl@0
|
391 |
iOut.writeNewLine();
|
sl@0
|
392 |
const CArrayFixFlat<TWTLSValidationStatus>& warnings =
|
sl@0
|
393 |
iValidationResult->Warnings();
|
sl@0
|
394 |
wCount = warnings.Count();
|
sl@0
|
395 |
for (TInt j = 0; j < wCount; j++)
|
sl@0
|
396 |
{
|
sl@0
|
397 |
TWTLSValidationStatus warning = warnings.At(j);
|
sl@0
|
398 |
WriteError(warning.iReason);
|
sl@0
|
399 |
iOut.writeNewLine();
|
sl@0
|
400 |
}
|
sl@0
|
401 |
iOut.writeNewLine();
|
sl@0
|
402 |
|
sl@0
|
403 |
if(expectedStatus->iReason != actualStatus.iReason)
|
sl@0
|
404 |
{
|
sl@0
|
405 |
iConsole.Printf(_L("FAILED!!!!\n"));
|
sl@0
|
406 |
iOut.writeString(_L("FAILED!!!!"));
|
sl@0
|
407 |
iOut.writeNewLine();
|
sl@0
|
408 |
iResult = EFalse;
|
sl@0
|
409 |
}
|
sl@0
|
410 |
|
sl@0
|
411 |
// End of DoValidate
|
sl@0
|
412 |
iState = EValidationStoreInitStoreManager2;
|
sl@0
|
413 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
414 |
delete iChain;
|
sl@0
|
415 |
iChain = 0;
|
sl@0
|
416 |
break;
|
sl@0
|
417 |
}
|
sl@0
|
418 |
|
sl@0
|
419 |
case EValidationStoreInitStoreManager2:
|
sl@0
|
420 |
{
|
sl@0
|
421 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
422 |
iState = EValidationStoreDepopulateStore2;
|
sl@0
|
423 |
break;
|
sl@0
|
424 |
}
|
sl@0
|
425 |
|
sl@0
|
426 |
case EValidationStoreDepopulateStore2:
|
sl@0
|
427 |
{
|
sl@0
|
428 |
iCertUtils->RemoveCertsL(aStatus);
|
sl@0
|
429 |
TUid uid = { 1 };
|
sl@0
|
430 |
iCertUtils->RemoveApplicationL(uid);
|
sl@0
|
431 |
iState = EValidationStoreEnd;
|
sl@0
|
432 |
break;
|
sl@0
|
433 |
}
|
sl@0
|
434 |
|
sl@0
|
435 |
case EValidationStoreEnd:
|
sl@0
|
436 |
{
|
sl@0
|
437 |
iState = EValidationSuppliedInit;
|
sl@0
|
438 |
iActionState = EPostrequisite;
|
sl@0
|
439 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
440 |
break;
|
sl@0
|
441 |
}
|
sl@0
|
442 |
case EInit:
|
sl@0
|
443 |
case EValidationStoreInitStoreManager1:
|
sl@0
|
444 |
case EValidationSuppliedInit:
|
sl@0
|
445 |
case EValidationSuppliedValidate:
|
sl@0
|
446 |
case EValidationSuppliedValidated:
|
sl@0
|
447 |
case EFinished:
|
sl@0
|
448 |
break; // Nothing to do, for compiler
|
sl@0
|
449 |
}
|
sl@0
|
450 |
}
|
sl@0
|
451 |
|
sl@0
|
452 |
HBufC8* CValidateTest::ReadFileLC(const TDesC& aFilename)
|
sl@0
|
453 |
{
|
sl@0
|
454 |
RFile file;
|
sl@0
|
455 |
User::LeaveIfError(file.Open(iFs, aFilename, EFileRead));
|
sl@0
|
456 |
CleanupClosePushL(file);
|
sl@0
|
457 |
TInt size;
|
sl@0
|
458 |
file.Size(size);
|
sl@0
|
459 |
CleanupStack::PopAndDestroy(1);//fileClose
|
sl@0
|
460 |
|
sl@0
|
461 |
HBufC8* res = HBufC8::NewLC(size);
|
sl@0
|
462 |
TPtr8 p(res->Des());
|
sl@0
|
463 |
p.SetLength(size);
|
sl@0
|
464 |
|
sl@0
|
465 |
RFileReadStream stream;
|
sl@0
|
466 |
User::LeaveIfError(stream.Open(iFs, aFilename, EFileStream));
|
sl@0
|
467 |
CleanupClosePushL(stream);
|
sl@0
|
468 |
stream.ReadL(p, size);
|
sl@0
|
469 |
CleanupStack::PopAndDestroy();//streamClose...bleurgh
|
sl@0
|
470 |
return res;
|
sl@0
|
471 |
}
|
sl@0
|
472 |
|
sl@0
|
473 |
|
sl@0
|
474 |
HBufC8* CValidateTest::ReadFilesLC(CDesCArray& aServerCerts)
|
sl@0
|
475 |
{
|
sl@0
|
476 |
TInt count = aServerCerts.MdcaCount();
|
sl@0
|
477 |
TInt totalSize = 0;
|
sl@0
|
478 |
TInt i;
|
sl@0
|
479 |
|
sl@0
|
480 |
for (i = 0; i < count; i++)
|
sl@0
|
481 |
{
|
sl@0
|
482 |
TPtrC filename = aServerCerts.MdcaPoint(i);
|
sl@0
|
483 |
RFile file;
|
sl@0
|
484 |
TRAPD(err, file.Open(iFs, filename, EFileRead));
|
sl@0
|
485 |
if(err != KErrNone)
|
sl@0
|
486 |
{
|
sl@0
|
487 |
HBufC *failedToLoad = filename.AllocLC();
|
sl@0
|
488 |
SetScriptError(EFileNotFound, failedToLoad->Des());
|
sl@0
|
489 |
CleanupStack::PopAndDestroy(2);//fsclose, fileClose
|
sl@0
|
490 |
return(NULL);
|
sl@0
|
491 |
};
|
sl@0
|
492 |
CleanupClosePushL(file);
|
sl@0
|
493 |
TInt size;
|
sl@0
|
494 |
file.Size(size);
|
sl@0
|
495 |
CleanupStack::PopAndDestroy(1); // fileClose
|
sl@0
|
496 |
totalSize += size;
|
sl@0
|
497 |
}
|
sl@0
|
498 |
|
sl@0
|
499 |
HBufC8* res = HBufC8::NewLC(totalSize);
|
sl@0
|
500 |
TPtr8 pRes = res->Des();
|
sl@0
|
501 |
for (i = 0; i < count; i++)
|
sl@0
|
502 |
{
|
sl@0
|
503 |
HBufC8* cert = ReadFileLC(aServerCerts.MdcaPoint(i));
|
sl@0
|
504 |
pRes.Append(cert->Des());
|
sl@0
|
505 |
CleanupStack::PopAndDestroy();//cert
|
sl@0
|
506 |
}
|
sl@0
|
507 |
return res;
|
sl@0
|
508 |
}
|
sl@0
|
509 |
|
sl@0
|
510 |
void CValidateTest::WriteError(TValidationError aError)
|
sl@0
|
511 |
{
|
sl@0
|
512 |
switch(aError)
|
sl@0
|
513 |
{
|
sl@0
|
514 |
//errors
|
sl@0
|
515 |
case EValidatedOK:
|
sl@0
|
516 |
{
|
sl@0
|
517 |
iOut.writeString(_L("Validated OK"));
|
sl@0
|
518 |
break;
|
sl@0
|
519 |
}
|
sl@0
|
520 |
case EChainHasNoRoot:
|
sl@0
|
521 |
{
|
sl@0
|
522 |
iOut.writeString(_L("No trusted root found"));
|
sl@0
|
523 |
break;
|
sl@0
|
524 |
}
|
sl@0
|
525 |
case ESignatureInvalid:
|
sl@0
|
526 |
{
|
sl@0
|
527 |
iOut.writeString(_L("Signature invalid"));
|
sl@0
|
528 |
break;
|
sl@0
|
529 |
}
|
sl@0
|
530 |
case EDateOutOfRange:
|
sl@0
|
531 |
{
|
sl@0
|
532 |
iOut.writeString(_L("Date out of range"));
|
sl@0
|
533 |
break;
|
sl@0
|
534 |
}
|
sl@0
|
535 |
case ENamesDontChain:
|
sl@0
|
536 |
{
|
sl@0
|
537 |
iOut.writeString(_L("Names don't chain"));
|
sl@0
|
538 |
break;
|
sl@0
|
539 |
}
|
sl@0
|
540 |
case ENotCACert:
|
sl@0
|
541 |
{
|
sl@0
|
542 |
iOut.writeString(_L("Cert not authorised to sign other certs"));
|
sl@0
|
543 |
break;
|
sl@0
|
544 |
}
|
sl@0
|
545 |
|
sl@0
|
546 |
default:
|
sl@0
|
547 |
{
|
sl@0
|
548 |
iOut.writeString(_L("Unknown"));
|
sl@0
|
549 |
break;
|
sl@0
|
550 |
}
|
sl@0
|
551 |
}
|
sl@0
|
552 |
}
|
sl@0
|
553 |
|
sl@0
|
554 |
void CValidateTest::CleanupCertArray(TAny* aCertArray)
|
sl@0
|
555 |
{
|
sl@0
|
556 |
CArrayPtrFlat<CWTLSCertificate>* certs = REINTERPRET_CAST(CArrayPtrFlat<CWTLSCertificate>*, aCertArray);
|
sl@0
|
557 |
certs->ResetAndDestroy();
|
sl@0
|
558 |
delete certs;
|
sl@0
|
559 |
}
|
sl@0
|
560 |
|
sl@0
|
561 |
void CValidateTest::HandleEInitL(TRequestStatus& aStatus)
|
sl@0
|
562 |
{
|
sl@0
|
563 |
iConsole.Printf(_L("Chain validation tests...\n"));
|
sl@0
|
564 |
iStart.HomeTime();
|
sl@0
|
565 |
|
sl@0
|
566 |
iConsole.Printf(_L("started with store...\n"));
|
sl@0
|
567 |
iOut.writeString(_L("started with store..."));
|
sl@0
|
568 |
iOut.writeNewLine();
|
sl@0
|
569 |
|
sl@0
|
570 |
iState = EValidationStoreInitStoreManager1;
|
sl@0
|
571 |
TRequestStatus* status = &aStatus;
|
sl@0
|
572 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
573 |
}
|
sl@0
|
574 |
|
sl@0
|
575 |
void CValidateTest::HandleEValidationInitStoreManager1L(TRequestStatus& aStatus)
|
sl@0
|
576 |
{
|
sl@0
|
577 |
TRequestStatus* status = &aStatus;
|
sl@0
|
578 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
579 |
iState = EValidationStoreDepopulateStore1;
|
sl@0
|
580 |
}
|
sl@0
|
581 |
|
sl@0
|
582 |
|
sl@0
|
583 |
void CValidateTest::DoReportAction()
|
sl@0
|
584 |
{
|
sl@0
|
585 |
}
|
sl@0
|
586 |
|
sl@0
|
587 |
void CValidateTest::DoCheckResult(TInt /*aError*/)
|
sl@0
|
588 |
{
|
sl@0
|
589 |
}
|
sl@0
|
590 |
|