sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2007-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 "ttesttoolengine.h"
|
sl@0
|
20 |
#include <ccertattributefilter.h>
|
sl@0
|
21 |
#include <mctcertstore.h>
|
sl@0
|
22 |
#include <mctkeystore.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
const TInt swinstalluid = 268452523;
|
sl@0
|
25 |
const TInt swinstallocspuid = 268478646;
|
sl@0
|
26 |
const TInt midletinstalluid = 270506792;
|
sl@0
|
27 |
const TInt tlsuid = 268441661;
|
sl@0
|
28 |
const TInt tocspuid = 268477445;
|
sl@0
|
29 |
|
sl@0
|
30 |
|
sl@0
|
31 |
_LIT(KSWInstall, "SWInstall");
|
sl@0
|
32 |
_LIT(KSWInstallOCSP, "SWInstallOCSP");
|
sl@0
|
33 |
_LIT(KMidletInstall, "MidletInstall");
|
sl@0
|
34 |
_LIT(KTls, "SSL/TLS");
|
sl@0
|
35 |
_LIT(KTOcsp, "OCSP Test");
|
sl@0
|
36 |
|
sl@0
|
37 |
_LIT(KCaType, "ca");
|
sl@0
|
38 |
_LIT(KUserType, "user");
|
sl@0
|
39 |
_LIT(KPeerType, "peer");
|
sl@0
|
40 |
|
sl@0
|
41 |
|
sl@0
|
42 |
/*static*/ CTestToolEngine* CTestToolEngine::NewLC()
|
sl@0
|
43 |
{
|
sl@0
|
44 |
CTestToolEngine* self = new (ELeave) CTestToolEngine();
|
sl@0
|
45 |
CleanupStack::PushL(self);
|
sl@0
|
46 |
self->ConstructL();
|
sl@0
|
47 |
return self;
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
CTestToolEngine::CTestToolEngine() : CActive(EPriorityNormal)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
iStore = -1;
|
sl@0
|
53 |
iPolicy = EFalse;
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
CTestToolEngine::~CTestToolEngine()
|
sl@0
|
57 |
{
|
sl@0
|
58 |
Cancel();
|
sl@0
|
59 |
|
sl@0
|
60 |
delete iCertStore;
|
sl@0
|
61 |
delete iKeyStore;
|
sl@0
|
62 |
|
sl@0
|
63 |
delete iFilter;
|
sl@0
|
64 |
Cancel();
|
sl@0
|
65 |
iCertInfos.Close();
|
sl@0
|
66 |
iFsKeyStore.Close();
|
sl@0
|
67 |
iFs.Close();
|
sl@0
|
68 |
iUids.Reset();
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
void CTestToolEngine::ConstructL()
|
sl@0
|
72 |
{
|
sl@0
|
73 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
74 |
|
sl@0
|
75 |
iCertStore = CUnifiedCertStore::NewL(iFs, ETrue);
|
sl@0
|
76 |
|
sl@0
|
77 |
User::LeaveIfError(iFsKeyStore.Connect());
|
sl@0
|
78 |
iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore);
|
sl@0
|
79 |
|
sl@0
|
80 |
// This filter will accept any certificates
|
sl@0
|
81 |
iFilter = CCertAttributeFilter::NewL();
|
sl@0
|
82 |
|
sl@0
|
83 |
CActiveScheduler::Add(this);
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
void CTestToolEngine::RunL()
|
sl@0
|
87 |
{
|
sl@0
|
88 |
if (iStatus.Int() != KErrNone)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
User::Leave(iStatus.Int());
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
switch (iState)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
case EInitialiseKeyStore:
|
sl@0
|
96 |
{
|
sl@0
|
97 |
// Construct a catch-all filter!
|
sl@0
|
98 |
iKeyFilter.iKeyAlgorithm = CCTKeyInfo::EInvalidAlgorithm;
|
sl@0
|
99 |
iKeyFilter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys;
|
sl@0
|
100 |
iKeyFilter.iUsage = EPKCS15UsageAll;
|
sl@0
|
101 |
if (iStore != -1)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
MCTKeyStore& chosen = iKeyStore->KeyStore(iStore);
|
sl@0
|
104 |
chosen.List(iKeys, iKeyFilter, iStatus);
|
sl@0
|
105 |
}
|
sl@0
|
106 |
else
|
sl@0
|
107 |
{
|
sl@0
|
108 |
iKeyStore->List(iKeys, iKeyFilter, iStatus);
|
sl@0
|
109 |
}
|
sl@0
|
110 |
if(iPolicy)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
iState = EGetPolicy;
|
sl@0
|
113 |
}
|
sl@0
|
114 |
else if (iKeysListCount > 0)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
iState = EDone;
|
sl@0
|
117 |
}
|
sl@0
|
118 |
else
|
sl@0
|
119 |
{
|
sl@0
|
120 |
iState = EFilterKey;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
SetActive();
|
sl@0
|
123 |
}
|
sl@0
|
124 |
break;
|
sl@0
|
125 |
case EFilterKey:
|
sl@0
|
126 |
{
|
sl@0
|
127 |
TInt index = 0;
|
sl@0
|
128 |
if (iLabel1.Length())
|
sl@0
|
129 |
{
|
sl@0
|
130 |
iNumCert1 = FilterKeys(iKeys, iLabel1, index);
|
sl@0
|
131 |
}
|
sl@0
|
132 |
if (iLabel2.Length())
|
sl@0
|
133 |
{
|
sl@0
|
134 |
iNumCert2 = FilterKeys(iKeys, iLabel2, index);
|
sl@0
|
135 |
}
|
sl@0
|
136 |
CActiveScheduler::Stop();
|
sl@0
|
137 |
}
|
sl@0
|
138 |
break;
|
sl@0
|
139 |
case EInitialise:
|
sl@0
|
140 |
{
|
sl@0
|
141 |
if (iStore != -1)
|
sl@0
|
142 |
{
|
sl@0
|
143 |
MCTCertStore& chosen = iCertStore->CertStore(iStore);
|
sl@0
|
144 |
chosen.List(iCertInfos, *iFilter, iStatus);
|
sl@0
|
145 |
}
|
sl@0
|
146 |
else
|
sl@0
|
147 |
{
|
sl@0
|
148 |
iCertStore->List(iCertInfos, *iFilter, iStatus);
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
if(iAppsCount > 0)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
iState = EGetApps;
|
sl@0
|
154 |
}
|
sl@0
|
155 |
else if (iGetTrust == 1)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
iState = EGetTrust;
|
sl@0
|
158 |
}
|
sl@0
|
159 |
else if (iCertsCount > 0)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
iState = EDone;
|
sl@0
|
162 |
}
|
sl@0
|
163 |
else
|
sl@0
|
164 |
{
|
sl@0
|
165 |
iState = EFilter;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
SetActive();
|
sl@0
|
168 |
}
|
sl@0
|
169 |
break;
|
sl@0
|
170 |
case EGetPolicy:
|
sl@0
|
171 |
{
|
sl@0
|
172 |
FilterKeys(iKeys, iLabel1, iIndex);
|
sl@0
|
173 |
CActiveScheduler::Stop();
|
sl@0
|
174 |
}
|
sl@0
|
175 |
break;
|
sl@0
|
176 |
case EGetApps:
|
sl@0
|
177 |
{
|
sl@0
|
178 |
TInt index = 0;
|
sl@0
|
179 |
FilterCerts(iCertInfos, iLabel1, index);
|
sl@0
|
180 |
iCertStore->Applications(*iCertInfos[index], iUids, iStatus);
|
sl@0
|
181 |
CActiveScheduler::Stop();
|
sl@0
|
182 |
}
|
sl@0
|
183 |
break;
|
sl@0
|
184 |
case EGetTrust:
|
sl@0
|
185 |
{
|
sl@0
|
186 |
TInt index = 0;
|
sl@0
|
187 |
FilterCerts(iCertInfos, iLabel1, index);
|
sl@0
|
188 |
iCertStore->Trusted(*iCertInfos[index], iActualTrust, iStatus);
|
sl@0
|
189 |
CActiveScheduler::Stop();
|
sl@0
|
190 |
}
|
sl@0
|
191 |
break;
|
sl@0
|
192 |
case EFilter:
|
sl@0
|
193 |
{
|
sl@0
|
194 |
TInt index = 0;
|
sl@0
|
195 |
TBool filteronly = ETrue;
|
sl@0
|
196 |
if (iLabel1.Length())
|
sl@0
|
197 |
{
|
sl@0
|
198 |
iNumCert1 = FilterCerts(iCertInfos, iLabel1, index, filteronly);
|
sl@0
|
199 |
}
|
sl@0
|
200 |
if (iLabel2.Length())
|
sl@0
|
201 |
{
|
sl@0
|
202 |
iNumCert2 = FilterCerts(iCertInfos, iLabel2, index, filteronly);
|
sl@0
|
203 |
}
|
sl@0
|
204 |
CActiveScheduler::Stop();
|
sl@0
|
205 |
}
|
sl@0
|
206 |
break;
|
sl@0
|
207 |
case EDone:
|
sl@0
|
208 |
{
|
sl@0
|
209 |
CActiveScheduler::Stop();
|
sl@0
|
210 |
}
|
sl@0
|
211 |
break;
|
sl@0
|
212 |
default:
|
sl@0
|
213 |
{
|
sl@0
|
214 |
User::Panic(_L("Testtool Engine - Illegal state"), 0);
|
sl@0
|
215 |
}
|
sl@0
|
216 |
}
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
TInt CTestToolEngine::RunError(TInt /*aError*/)
|
sl@0
|
220 |
{
|
sl@0
|
221 |
CActiveScheduler::Stop();
|
sl@0
|
222 |
|
sl@0
|
223 |
return KErrNone;
|
sl@0
|
224 |
}
|
sl@0
|
225 |
|
sl@0
|
226 |
|
sl@0
|
227 |
void CTestToolEngine::DoCancel()
|
sl@0
|
228 |
{
|
sl@0
|
229 |
//CActiveScheduler::Stop();
|
sl@0
|
230 |
}
|
sl@0
|
231 |
|
sl@0
|
232 |
TVerdict CTestToolEngine::ListCerts(const TDesC& aLabel1, const TInt aExpectedNumLabel)
|
sl@0
|
233 |
{
|
sl@0
|
234 |
TVerdict returnValue = EPass;
|
sl@0
|
235 |
iLabel1.Set(aLabel1);
|
sl@0
|
236 |
|
sl@0
|
237 |
Initilize();
|
sl@0
|
238 |
if (iNumCert1 != aExpectedNumLabel)
|
sl@0
|
239 |
{
|
sl@0
|
240 |
returnValue = EFail;
|
sl@0
|
241 |
}
|
sl@0
|
242 |
return returnValue;
|
sl@0
|
243 |
}
|
sl@0
|
244 |
|
sl@0
|
245 |
|
sl@0
|
246 |
TVerdict CTestToolEngine::ListCerts(const TDesC& aLabel1, const TDesC& aLabel2, const TInt aExpectedNumLabel)
|
sl@0
|
247 |
{
|
sl@0
|
248 |
TVerdict returnValue = EPass;
|
sl@0
|
249 |
iLabel1.Set(aLabel1);
|
sl@0
|
250 |
iLabel2.Set(aLabel2);
|
sl@0
|
251 |
|
sl@0
|
252 |
Initilize();
|
sl@0
|
253 |
if (iNumCert1 != aExpectedNumLabel || iNumCert2 != aExpectedNumLabel)
|
sl@0
|
254 |
{
|
sl@0
|
255 |
returnValue = EFail;
|
sl@0
|
256 |
}
|
sl@0
|
257 |
return returnValue;
|
sl@0
|
258 |
}
|
sl@0
|
259 |
|
sl@0
|
260 |
TVerdict CTestToolEngine::ListStore(RPointerArray<HBufC>& aCerts)
|
sl@0
|
261 |
{
|
sl@0
|
262 |
TVerdict returnValue = EPass;
|
sl@0
|
263 |
iCertsCount = aCerts.Count();
|
sl@0
|
264 |
|
sl@0
|
265 |
Initilize();
|
sl@0
|
266 |
|
sl@0
|
267 |
if (!CompareWithExpectedStore(aCerts))
|
sl@0
|
268 |
{
|
sl@0
|
269 |
returnValue = EFail;
|
sl@0
|
270 |
}
|
sl@0
|
271 |
return returnValue;
|
sl@0
|
272 |
}
|
sl@0
|
273 |
|
sl@0
|
274 |
TVerdict CTestToolEngine::ListCerts(RPointerArray<HBufC>& aCerts)
|
sl@0
|
275 |
{
|
sl@0
|
276 |
TVerdict returnValue = EPass;
|
sl@0
|
277 |
iCertsCount = aCerts.Count();
|
sl@0
|
278 |
|
sl@0
|
279 |
Initilize();
|
sl@0
|
280 |
|
sl@0
|
281 |
if (!CompareWithExpectedCertificates(aCerts))
|
sl@0
|
282 |
{
|
sl@0
|
283 |
returnValue = EFail;
|
sl@0
|
284 |
}
|
sl@0
|
285 |
return returnValue;
|
sl@0
|
286 |
}
|
sl@0
|
287 |
|
sl@0
|
288 |
TVerdict CTestToolEngine::ListCerts(RPointerArray<HBufC>& aCerts, const TDesC& aLabel)
|
sl@0
|
289 |
{
|
sl@0
|
290 |
TVerdict returnValue = EPass;
|
sl@0
|
291 |
iLabel1.Set(aLabel);
|
sl@0
|
292 |
iCertsCount = aCerts.Count();
|
sl@0
|
293 |
|
sl@0
|
294 |
Initilize();
|
sl@0
|
295 |
TCertificateOwnerType owner;
|
sl@0
|
296 |
if (iLabel1.CompareF(KCaType) == KErrNone)
|
sl@0
|
297 |
{
|
sl@0
|
298 |
owner = ECACertificate;
|
sl@0
|
299 |
}
|
sl@0
|
300 |
else if (iLabel1.CompareF(KUserType) == KErrNone)
|
sl@0
|
301 |
{
|
sl@0
|
302 |
owner = EUserCertificate;
|
sl@0
|
303 |
}
|
sl@0
|
304 |
else if (iLabel1.CompareF(KPeerType) == KErrNone)
|
sl@0
|
305 |
{
|
sl@0
|
306 |
owner = EPeerCertificate;
|
sl@0
|
307 |
}
|
sl@0
|
308 |
FilterCerts(iCertInfos, owner);
|
sl@0
|
309 |
if (!CompareWithExpectedCertificates(aCerts))
|
sl@0
|
310 |
{
|
sl@0
|
311 |
returnValue = EFail;
|
sl@0
|
312 |
}
|
sl@0
|
313 |
return returnValue;
|
sl@0
|
314 |
}
|
sl@0
|
315 |
|
sl@0
|
316 |
TVerdict CTestToolEngine::ListCerts(RPointerArray<HBufC>& aCerts, TInt aStore)
|
sl@0
|
317 |
{
|
sl@0
|
318 |
TVerdict returnValue = EPass;
|
sl@0
|
319 |
iStore = aStore;
|
sl@0
|
320 |
iCertsCount = aCerts.Count();
|
sl@0
|
321 |
|
sl@0
|
322 |
Initilize();
|
sl@0
|
323 |
if (!CompareWithExpectedCertificates(aCerts))
|
sl@0
|
324 |
{
|
sl@0
|
325 |
returnValue = EFail;
|
sl@0
|
326 |
}
|
sl@0
|
327 |
return returnValue;
|
sl@0
|
328 |
}
|
sl@0
|
329 |
|
sl@0
|
330 |
TVerdict CTestToolEngine::CheckApps(RPointerArray<HBufC>& aApps, const TDesC& aLabel)
|
sl@0
|
331 |
{
|
sl@0
|
332 |
TVerdict returnValue = EPass;
|
sl@0
|
333 |
iAppsCount = aApps.Count();
|
sl@0
|
334 |
iLabel1.Set(aLabel);
|
sl@0
|
335 |
Initilize();
|
sl@0
|
336 |
if (!VerifyApps(aApps))
|
sl@0
|
337 |
{
|
sl@0
|
338 |
returnValue = EFail;
|
sl@0
|
339 |
}
|
sl@0
|
340 |
return returnValue;
|
sl@0
|
341 |
}
|
sl@0
|
342 |
|
sl@0
|
343 |
TVerdict CTestToolEngine::CheckTrust(const TDesC& aLabel,TBool aTrust)
|
sl@0
|
344 |
{
|
sl@0
|
345 |
TVerdict returnValue = EPass;
|
sl@0
|
346 |
iLabel1.Set(aLabel);
|
sl@0
|
347 |
iGetTrust = 1;
|
sl@0
|
348 |
Initilize();
|
sl@0
|
349 |
if (!VerifyTrust(aTrust))
|
sl@0
|
350 |
{
|
sl@0
|
351 |
returnValue = EFail;
|
sl@0
|
352 |
}
|
sl@0
|
353 |
return returnValue;
|
sl@0
|
354 |
}
|
sl@0
|
355 |
|
sl@0
|
356 |
TVerdict CTestToolEngine::ListStoreKey(RPointerArray<HBufC>& aKeys)
|
sl@0
|
357 |
{
|
sl@0
|
358 |
TVerdict returnValue = EPass;
|
sl@0
|
359 |
iKeysListCount = aKeys.Count();
|
sl@0
|
360 |
|
sl@0
|
361 |
KeyInitilize();
|
sl@0
|
362 |
|
sl@0
|
363 |
if (!CompareWithExpectedStoreKey(aKeys))
|
sl@0
|
364 |
{
|
sl@0
|
365 |
returnValue = EFail;
|
sl@0
|
366 |
}
|
sl@0
|
367 |
return returnValue;
|
sl@0
|
368 |
}
|
sl@0
|
369 |
|
sl@0
|
370 |
TVerdict CTestToolEngine::ListKeys(const TDesC& aLabel1, const TInt aExpectedNumLabel)
|
sl@0
|
371 |
{
|
sl@0
|
372 |
TVerdict returnValue = EPass;
|
sl@0
|
373 |
iLabel1.Set(aLabel1);
|
sl@0
|
374 |
|
sl@0
|
375 |
KeyInitilize();
|
sl@0
|
376 |
if (iNumCert1 != aExpectedNumLabel)
|
sl@0
|
377 |
{
|
sl@0
|
378 |
returnValue = EFail;
|
sl@0
|
379 |
}
|
sl@0
|
380 |
return returnValue;
|
sl@0
|
381 |
}
|
sl@0
|
382 |
|
sl@0
|
383 |
|
sl@0
|
384 |
TVerdict CTestToolEngine::ListKeys(const TDesC& aLabel1, const TDesC& aLabel2, const TInt aExpectedNumLabel)
|
sl@0
|
385 |
{
|
sl@0
|
386 |
TVerdict returnValue = EPass;
|
sl@0
|
387 |
iLabel1.Set(aLabel1);
|
sl@0
|
388 |
iLabel2.Set(aLabel2);
|
sl@0
|
389 |
|
sl@0
|
390 |
KeyInitilize();
|
sl@0
|
391 |
if (iNumCert1 != aExpectedNumLabel || iNumCert2 != aExpectedNumLabel)
|
sl@0
|
392 |
{
|
sl@0
|
393 |
returnValue = EFail;
|
sl@0
|
394 |
}
|
sl@0
|
395 |
return returnValue;
|
sl@0
|
396 |
}
|
sl@0
|
397 |
|
sl@0
|
398 |
TVerdict CTestToolEngine::ListKeys(RPointerArray<HBufC>& aKeys, TInt aStore)
|
sl@0
|
399 |
{
|
sl@0
|
400 |
TVerdict returnValue = EPass;
|
sl@0
|
401 |
iStore = aStore;
|
sl@0
|
402 |
iKeysListCount = aKeys.Count();
|
sl@0
|
403 |
|
sl@0
|
404 |
KeyInitilize();
|
sl@0
|
405 |
if (!CompareWithExpectedKeys(aKeys))
|
sl@0
|
406 |
{
|
sl@0
|
407 |
returnValue = EFail;
|
sl@0
|
408 |
}
|
sl@0
|
409 |
return returnValue;
|
sl@0
|
410 |
}
|
sl@0
|
411 |
|
sl@0
|
412 |
|
sl@0
|
413 |
TVerdict CTestToolEngine::ListKeys(RPointerArray<HBufC>& aKeys)
|
sl@0
|
414 |
{
|
sl@0
|
415 |
TVerdict returnValue = EPass;
|
sl@0
|
416 |
iKeysListCount = aKeys.Count();
|
sl@0
|
417 |
|
sl@0
|
418 |
KeyInitilize();
|
sl@0
|
419 |
|
sl@0
|
420 |
if (!CompareWithExpectedKeys(aKeys))
|
sl@0
|
421 |
{
|
sl@0
|
422 |
returnValue = EFail;
|
sl@0
|
423 |
}
|
sl@0
|
424 |
return returnValue;
|
sl@0
|
425 |
}
|
sl@0
|
426 |
|
sl@0
|
427 |
TVerdict CTestToolEngine::GetPolicy(const TDesC& aLabel1, const TDesC& aLabel2, TInt aUser)
|
sl@0
|
428 |
{
|
sl@0
|
429 |
TVerdict returnValue = EPass;
|
sl@0
|
430 |
iLabel1.Set(aLabel1);
|
sl@0
|
431 |
iLabel2.Set(aLabel2);
|
sl@0
|
432 |
iPolicy = ETrue;
|
sl@0
|
433 |
KeyInitilize();
|
sl@0
|
434 |
VerifyPolicy(aUser);
|
sl@0
|
435 |
|
sl@0
|
436 |
return returnValue;
|
sl@0
|
437 |
}
|
sl@0
|
438 |
|
sl@0
|
439 |
void CTestToolEngine::Initilize()
|
sl@0
|
440 |
{
|
sl@0
|
441 |
iState = EInitialise;
|
sl@0
|
442 |
iCertStore->Initialize(iStatus);
|
sl@0
|
443 |
SetActive();
|
sl@0
|
444 |
CActiveScheduler::Start();
|
sl@0
|
445 |
}
|
sl@0
|
446 |
|
sl@0
|
447 |
void CTestToolEngine::KeyInitilize()
|
sl@0
|
448 |
{
|
sl@0
|
449 |
iState = EInitialiseKeyStore;
|
sl@0
|
450 |
iKeyStore->Initialize(iStatus);
|
sl@0
|
451 |
SetActive();
|
sl@0
|
452 |
CActiveScheduler::Start();
|
sl@0
|
453 |
}
|
sl@0
|
454 |
|
sl@0
|
455 |
TBool CTestToolEngine::VerifyApps(RPointerArray<HBufC>& aApps)
|
sl@0
|
456 |
{
|
sl@0
|
457 |
TInt uidsCount = iUids.Count();
|
sl@0
|
458 |
TInt appsCount = aApps.Count();
|
sl@0
|
459 |
TBool result = ETrue;
|
sl@0
|
460 |
if ( uidsCount != appsCount)
|
sl@0
|
461 |
{
|
sl@0
|
462 |
return EFalse;
|
sl@0
|
463 |
}
|
sl@0
|
464 |
for (TInt i = 0; i < uidsCount; i++)
|
sl@0
|
465 |
{
|
sl@0
|
466 |
if (iUids[i] == TUid::Uid(swinstalluid))
|
sl@0
|
467 |
{
|
sl@0
|
468 |
result = CheckAppForUid(KSWInstall, aApps);
|
sl@0
|
469 |
}
|
sl@0
|
470 |
else if (iUids[i] == TUid::Uid(swinstallocspuid))
|
sl@0
|
471 |
{
|
sl@0
|
472 |
result = CheckAppForUid(KSWInstallOCSP, aApps);
|
sl@0
|
473 |
}
|
sl@0
|
474 |
else if (iUids[i] == TUid::Uid(midletinstalluid))
|
sl@0
|
475 |
{
|
sl@0
|
476 |
result = CheckAppForUid(KMidletInstall, aApps);
|
sl@0
|
477 |
}
|
sl@0
|
478 |
else if (iUids[i] == TUid::Uid(tlsuid))
|
sl@0
|
479 |
{
|
sl@0
|
480 |
result = CheckAppForUid(KTls, aApps);
|
sl@0
|
481 |
}
|
sl@0
|
482 |
else if (iUids[i] == TUid::Uid(tocspuid))
|
sl@0
|
483 |
{
|
sl@0
|
484 |
result = CheckAppForUid(KTOcsp, aApps);
|
sl@0
|
485 |
}
|
sl@0
|
486 |
else
|
sl@0
|
487 |
{
|
sl@0
|
488 |
result = EFalse;
|
sl@0
|
489 |
}
|
sl@0
|
490 |
if (!result)
|
sl@0
|
491 |
{
|
sl@0
|
492 |
break;
|
sl@0
|
493 |
}
|
sl@0
|
494 |
}
|
sl@0
|
495 |
return result;
|
sl@0
|
496 |
}
|
sl@0
|
497 |
|
sl@0
|
498 |
TBool CTestToolEngine::CheckAppForUid(const TDesC& aAppName, RPointerArray<HBufC>& aApps)
|
sl@0
|
499 |
{
|
sl@0
|
500 |
TBool result = EFalse;
|
sl@0
|
501 |
for (TInt i = 0; i < aApps.Count();i++)
|
sl@0
|
502 |
{
|
sl@0
|
503 |
if (aAppName.CompareF(*aApps[i]) == KErrNone)
|
sl@0
|
504 |
{
|
sl@0
|
505 |
result = ETrue;
|
sl@0
|
506 |
break;
|
sl@0
|
507 |
}
|
sl@0
|
508 |
else
|
sl@0
|
509 |
{
|
sl@0
|
510 |
result = EFalse;
|
sl@0
|
511 |
}
|
sl@0
|
512 |
}
|
sl@0
|
513 |
return result;
|
sl@0
|
514 |
}
|
sl@0
|
515 |
|
sl@0
|
516 |
TBool CTestToolEngine::VerifyPolicy(TInt aUser)
|
sl@0
|
517 |
{
|
sl@0
|
518 |
TBool result = EFalse;
|
sl@0
|
519 |
_LIT(KCab, "WriteDeviceData");
|
sl@0
|
520 |
TLex lex(iLabel2);
|
sl@0
|
521 |
TUid secid;
|
sl@0
|
522 |
lex.Val(secid.iUid);
|
sl@0
|
523 |
TCompiledSecurityPolicy managementPolicy = iKeys[iIndex]->ManagementPolicy();
|
sl@0
|
524 |
TCompiledSecurityPolicy usePolicy = iKeys[iIndex]->UsePolicy();
|
sl@0
|
525 |
TUint32 mSecureid = managementPolicy.SecureId();
|
sl@0
|
526 |
TUint32 uSecureid = usePolicy.SecureId();
|
sl@0
|
527 |
|
sl@0
|
528 |
if (aUser == 2)
|
sl@0
|
529 |
{
|
sl@0
|
530 |
if (mSecureid == 0xffffffff)
|
sl@0
|
531 |
{
|
sl@0
|
532 |
TCapability cab = managementPolicy.Capability(0);
|
sl@0
|
533 |
// currently only possible for keyowner other than secure id.
|
sl@0
|
534 |
if (cab == ECapabilityWriteDeviceData && iLabel2.CompareF(KCab) == KErrNone)
|
sl@0
|
535 |
{
|
sl@0
|
536 |
result = ETrue;
|
sl@0
|
537 |
}
|
sl@0
|
538 |
else
|
sl@0
|
539 |
{
|
sl@0
|
540 |
result = EFalse;
|
sl@0
|
541 |
}
|
sl@0
|
542 |
}
|
sl@0
|
543 |
else
|
sl@0
|
544 |
{
|
sl@0
|
545 |
TUid mSecureUid = TUid::Uid(mSecureid);
|
sl@0
|
546 |
if (mSecureUid == secid)
|
sl@0
|
547 |
{
|
sl@0
|
548 |
result = ETrue;
|
sl@0
|
549 |
}
|
sl@0
|
550 |
else
|
sl@0
|
551 |
{
|
sl@0
|
552 |
result = EFalse;
|
sl@0
|
553 |
}
|
sl@0
|
554 |
}
|
sl@0
|
555 |
}
|
sl@0
|
556 |
else if (aUser == 1)
|
sl@0
|
557 |
{
|
sl@0
|
558 |
if (uSecureid == 0xffffffff)
|
sl@0
|
559 |
{
|
sl@0
|
560 |
TSecurityPolicy::TType utype = usePolicy.Type();
|
sl@0
|
561 |
_LIT(KType, "ALL");
|
sl@0
|
562 |
// currently only possible for keyuser other than secure id
|
sl@0
|
563 |
if (utype == TSecurityPolicy::ETypePass && iLabel2.CompareF(KType) == KErrNone)
|
sl@0
|
564 |
{
|
sl@0
|
565 |
result = ETrue;
|
sl@0
|
566 |
}
|
sl@0
|
567 |
else
|
sl@0
|
568 |
{
|
sl@0
|
569 |
result = EFalse;
|
sl@0
|
570 |
}
|
sl@0
|
571 |
}
|
sl@0
|
572 |
else
|
sl@0
|
573 |
{
|
sl@0
|
574 |
TUid uSecureUid = TUid::Uid(uSecureid);
|
sl@0
|
575 |
if (uSecureUid == secid)
|
sl@0
|
576 |
{
|
sl@0
|
577 |
result = ETrue;
|
sl@0
|
578 |
}
|
sl@0
|
579 |
else
|
sl@0
|
580 |
{
|
sl@0
|
581 |
result = EFalse;
|
sl@0
|
582 |
}
|
sl@0
|
583 |
}
|
sl@0
|
584 |
}
|
sl@0
|
585 |
return result;
|
sl@0
|
586 |
}
|
sl@0
|
587 |
|
sl@0
|
588 |
TInt CTestToolEngine::FilterCerts(RMPointerArray<CCTCertInfo>& aCertList,
|
sl@0
|
589 |
TDesC& aLabel, TInt& aIndex, TBool aFilterOnly)
|
sl@0
|
590 |
{
|
sl@0
|
591 |
TInt j = 0, count = 0;
|
sl@0
|
592 |
while (j < aCertList.Count())
|
sl@0
|
593 |
{
|
sl@0
|
594 |
if ( aCertList[j]->Label().MatchF(aLabel) != KErrNotFound)
|
sl@0
|
595 |
{
|
sl@0
|
596 |
count++;
|
sl@0
|
597 |
if (count == 1)
|
sl@0
|
598 |
{
|
sl@0
|
599 |
//first certificate to be selected for retreiving
|
sl@0
|
600 |
aIndex = j;
|
sl@0
|
601 |
}
|
sl@0
|
602 |
j++;
|
sl@0
|
603 |
}
|
sl@0
|
604 |
else
|
sl@0
|
605 |
{
|
sl@0
|
606 |
if (!aFilterOnly)
|
sl@0
|
607 |
{
|
sl@0
|
608 |
CCTCertInfo* tmp = aCertList[j];
|
sl@0
|
609 |
tmp->Release();
|
sl@0
|
610 |
aCertList.Remove(j);
|
sl@0
|
611 |
}
|
sl@0
|
612 |
else
|
sl@0
|
613 |
{
|
sl@0
|
614 |
j++;
|
sl@0
|
615 |
}
|
sl@0
|
616 |
}
|
sl@0
|
617 |
}
|
sl@0
|
618 |
return count;
|
sl@0
|
619 |
}
|
sl@0
|
620 |
|
sl@0
|
621 |
void CTestToolEngine::FilterCerts(RMPointerArray<CCTCertInfo>& aCertList, TCertificateOwnerType& aOwnerType)
|
sl@0
|
622 |
{
|
sl@0
|
623 |
TInt j = 0;
|
sl@0
|
624 |
while (j < aCertList.Count())
|
sl@0
|
625 |
{
|
sl@0
|
626 |
if ( aCertList[j]->CertificateOwnerType() != aOwnerType)
|
sl@0
|
627 |
{
|
sl@0
|
628 |
CCTCertInfo* tmp = aCertList[j];
|
sl@0
|
629 |
tmp->Release();
|
sl@0
|
630 |
aCertList.Remove(j);
|
sl@0
|
631 |
}
|
sl@0
|
632 |
else
|
sl@0
|
633 |
{
|
sl@0
|
634 |
j++;
|
sl@0
|
635 |
}
|
sl@0
|
636 |
}
|
sl@0
|
637 |
}
|
sl@0
|
638 |
|
sl@0
|
639 |
|
sl@0
|
640 |
TInt CTestToolEngine::FilterKeys(RMPointerArray<CCTKeyInfo>& aKeyList,
|
sl@0
|
641 |
TDesC& aLabel, TInt& aIndex)
|
sl@0
|
642 |
{
|
sl@0
|
643 |
TInt j = 0, count = 0;
|
sl@0
|
644 |
while (j < aKeyList.Count())
|
sl@0
|
645 |
{
|
sl@0
|
646 |
if ( aKeyList[j]->Label().MatchF(aLabel) != KErrNotFound)
|
sl@0
|
647 |
{
|
sl@0
|
648 |
count++;
|
sl@0
|
649 |
if (count == 1)
|
sl@0
|
650 |
{
|
sl@0
|
651 |
//first key to be selected for retreiving
|
sl@0
|
652 |
aIndex = j;
|
sl@0
|
653 |
}
|
sl@0
|
654 |
j++;
|
sl@0
|
655 |
}
|
sl@0
|
656 |
else
|
sl@0
|
657 |
{
|
sl@0
|
658 |
j++;
|
sl@0
|
659 |
}
|
sl@0
|
660 |
}
|
sl@0
|
661 |
return count;
|
sl@0
|
662 |
}
|
sl@0
|
663 |
|
sl@0
|
664 |
TBool CTestToolEngine::CompareWithExpectedCertificates(RPointerArray<HBufC>& aCerts)
|
sl@0
|
665 |
{
|
sl@0
|
666 |
if ( iCertInfos.Count() != aCerts.Count())
|
sl@0
|
667 |
{
|
sl@0
|
668 |
return EFalse;
|
sl@0
|
669 |
}
|
sl@0
|
670 |
for (TInt i = 0 ; i < iCertInfos.Count(); i++)
|
sl@0
|
671 |
{
|
sl@0
|
672 |
const TDesC& label = iCertInfos[i]->Label();
|
sl@0
|
673 |
TBool found = EFalse;
|
sl@0
|
674 |
for (TInt j = 0; j < aCerts.Count(); j++)
|
sl@0
|
675 |
{
|
sl@0
|
676 |
if (aCerts[j]->CompareF(label) == KErrNone)
|
sl@0
|
677 |
{
|
sl@0
|
678 |
found = ETrue;
|
sl@0
|
679 |
break;
|
sl@0
|
680 |
}
|
sl@0
|
681 |
}
|
sl@0
|
682 |
if (!found)
|
sl@0
|
683 |
{
|
sl@0
|
684 |
return EFalse;
|
sl@0
|
685 |
}
|
sl@0
|
686 |
}
|
sl@0
|
687 |
return ETrue;
|
sl@0
|
688 |
}
|
sl@0
|
689 |
|
sl@0
|
690 |
|
sl@0
|
691 |
TBool CTestToolEngine::CompareWithExpectedKeys(RPointerArray<HBufC>& aKeys)
|
sl@0
|
692 |
{
|
sl@0
|
693 |
if ( iKeys.Count() != iKeysListCount)
|
sl@0
|
694 |
{
|
sl@0
|
695 |
return EFalse;
|
sl@0
|
696 |
}
|
sl@0
|
697 |
for (TInt i = 0 ; i < iKeys.Count(); i++)
|
sl@0
|
698 |
{
|
sl@0
|
699 |
const TDesC& label = iKeys[i]->Label();
|
sl@0
|
700 |
TBool found = EFalse;
|
sl@0
|
701 |
for (TInt j = 0; j < iKeysListCount; j++)
|
sl@0
|
702 |
{
|
sl@0
|
703 |
if (aKeys[j]->CompareF(label) == KErrNone)
|
sl@0
|
704 |
{
|
sl@0
|
705 |
found = ETrue;
|
sl@0
|
706 |
break;
|
sl@0
|
707 |
}
|
sl@0
|
708 |
}
|
sl@0
|
709 |
if (!found)
|
sl@0
|
710 |
{
|
sl@0
|
711 |
return EFalse;
|
sl@0
|
712 |
}
|
sl@0
|
713 |
}
|
sl@0
|
714 |
return ETrue;
|
sl@0
|
715 |
}
|
sl@0
|
716 |
|
sl@0
|
717 |
TBool CTestToolEngine::CompareWithExpectedStore(RPointerArray<HBufC>& aCerts)
|
sl@0
|
718 |
{
|
sl@0
|
719 |
TBool result = EFalse;
|
sl@0
|
720 |
TInt storeCount = iCertStore->CertStoreCount();
|
sl@0
|
721 |
for (TInt i = 0; i < storeCount ; i++)
|
sl@0
|
722 |
{
|
sl@0
|
723 |
result = EFalse;
|
sl@0
|
724 |
MCTToken& token = (iCertStore->CertStore(i)).Token();
|
sl@0
|
725 |
const TDesC& tmp = token.Label();
|
sl@0
|
726 |
for (TInt j = 0; j < aCerts.Count(); j++)
|
sl@0
|
727 |
{
|
sl@0
|
728 |
if (tmp.CompareF(*aCerts[j]) == KErrNone)
|
sl@0
|
729 |
{
|
sl@0
|
730 |
result = ETrue;
|
sl@0
|
731 |
break;
|
sl@0
|
732 |
}
|
sl@0
|
733 |
}
|
sl@0
|
734 |
if (!result)
|
sl@0
|
735 |
{
|
sl@0
|
736 |
break;
|
sl@0
|
737 |
}
|
sl@0
|
738 |
}
|
sl@0
|
739 |
return result;
|
sl@0
|
740 |
}
|
sl@0
|
741 |
|
sl@0
|
742 |
|
sl@0
|
743 |
TBool CTestToolEngine::CompareWithExpectedStoreKey(RPointerArray<HBufC>& aKeys)
|
sl@0
|
744 |
{
|
sl@0
|
745 |
TBool result = EFalse;
|
sl@0
|
746 |
TInt storeCount = iKeyStore->KeyStoreCount();
|
sl@0
|
747 |
for (TInt i = 0; i < storeCount ; i++)
|
sl@0
|
748 |
{
|
sl@0
|
749 |
result = EFalse;
|
sl@0
|
750 |
MCTToken& token = (iKeyStore->KeyStore(i)).Token();
|
sl@0
|
751 |
const TDesC& tmp = token.Label();
|
sl@0
|
752 |
for (TInt j = 0; j < aKeys.Count(); j++)
|
sl@0
|
753 |
{
|
sl@0
|
754 |
if (tmp.CompareF(*aKeys[j]) == KErrNone)
|
sl@0
|
755 |
{
|
sl@0
|
756 |
result = ETrue;
|
sl@0
|
757 |
break;
|
sl@0
|
758 |
}
|
sl@0
|
759 |
}
|
sl@0
|
760 |
if (!result)
|
sl@0
|
761 |
{
|
sl@0
|
762 |
break;
|
sl@0
|
763 |
}
|
sl@0
|
764 |
}
|
sl@0
|
765 |
return result;
|
sl@0
|
766 |
}
|
sl@0
|
767 |
|
sl@0
|
768 |
|
sl@0
|
769 |
|
sl@0
|
770 |
TBool CTestToolEngine::VerifyTrust(TBool aTrust)
|
sl@0
|
771 |
{
|
sl@0
|
772 |
TBool result = EFalse;
|
sl@0
|
773 |
if (aTrust == iActualTrust)
|
sl@0
|
774 |
{
|
sl@0
|
775 |
result = ETrue;
|
sl@0
|
776 |
}
|
sl@0
|
777 |
else
|
sl@0
|
778 |
{
|
sl@0
|
779 |
result = EFalse;
|
sl@0
|
780 |
}
|
sl@0
|
781 |
return result;
|
sl@0
|
782 |
}
|