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 "unifiedcertstore.h"
|
sl@0
|
20 |
#include "unifiedcertstoreworkingvars.h"
|
sl@0
|
21 |
#include "CCheckedCertStore.h"
|
sl@0
|
22 |
#include <certificateapps.h>
|
sl@0
|
23 |
#include <x509cert.h>
|
sl@0
|
24 |
#include <wtlscert.h>
|
sl@0
|
25 |
#include <hash.h>
|
sl@0
|
26 |
#include <ecom/ecom.h>
|
sl@0
|
27 |
|
sl@0
|
28 |
_LIT(KUCSPanic, "CUnifiedCertStore");
|
sl@0
|
29 |
#define assert(x) __ASSERT_ALWAYS((x), User::Panic(KUCSPanic, 1));
|
sl@0
|
30 |
|
sl@0
|
31 |
/////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
32 |
//CUnifiedCertStore
|
sl@0
|
33 |
/////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
34 |
|
sl@0
|
35 |
EXPORT_C CUnifiedCertStore* CUnifiedCertStore::NewL(RFs& aFs, TBool aOpenForWrite)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
CUnifiedCertStore* self = CUnifiedCertStore::NewLC(aFs, aOpenForWrite);
|
sl@0
|
38 |
CleanupStack::Pop(self);
|
sl@0
|
39 |
return self;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
EXPORT_C CUnifiedCertStore* CUnifiedCertStore::NewLC(RFs& aFs, TBool aOpenForWrite)
|
sl@0
|
43 |
{
|
sl@0
|
44 |
CUnifiedCertStore* self = new(ELeave) CUnifiedCertStore(aFs, aOpenForWrite);
|
sl@0
|
45 |
CleanupStack::PushL(self);
|
sl@0
|
46 |
RArray<TInt> orderingFilter;
|
sl@0
|
47 |
self->ConstructL(orderingFilter);
|
sl@0
|
48 |
return self;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
EXPORT_C CUnifiedCertStore::~CUnifiedCertStore()
|
sl@0
|
52 |
{
|
sl@0
|
53 |
Cancel();
|
sl@0
|
54 |
|
sl@0
|
55 |
assert(!iWorkingVars);
|
sl@0
|
56 |
|
sl@0
|
57 |
TInt end = iReadOnlyCertStores.Count();
|
sl@0
|
58 |
TInt i;
|
sl@0
|
59 |
for (i = 0; i < end; i++)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
iReadOnlyCertStores[i]->Release();
|
sl@0
|
62 |
}
|
sl@0
|
63 |
iReadOnlyCertStores.Close();
|
sl@0
|
64 |
|
sl@0
|
65 |
end = iWritableCertStores.Count();
|
sl@0
|
66 |
for (i = 0; i < end; i++)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
iWritableCertStores[i]->Release();
|
sl@0
|
69 |
}
|
sl@0
|
70 |
iWritableCertStores.Close();
|
sl@0
|
71 |
|
sl@0
|
72 |
// The elements are already released by the two loops above
|
sl@0
|
73 |
iCertStores.Close();
|
sl@0
|
74 |
|
sl@0
|
75 |
// release resources allocated to order attributes list
|
sl@0
|
76 |
iOrderAttributes.Close();
|
sl@0
|
77 |
|
sl@0
|
78 |
DestroyTemporaryMembers();
|
sl@0
|
79 |
iHardwareTypeUids.Close();
|
sl@0
|
80 |
REComSession::FinalClose();
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
|
sl@0
|
84 |
EXPORT_C void CUnifiedCertStore::Initialize(TRequestStatus& aStatus)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
BeginAsyncOp(aStatus, EInitializeGetTokenList);
|
sl@0
|
87 |
TRAPD(err, InitializeL());
|
sl@0
|
88 |
if (err != KErrNone)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
Complete(err);
|
sl@0
|
91 |
}
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
void CUnifiedCertStore::InitializeL()
|
sl@0
|
95 |
{
|
sl@0
|
96 |
AllocWorkingVarsL();
|
sl@0
|
97 |
|
sl@0
|
98 |
// We want the list of all token types that support a readable or writable
|
sl@0
|
99 |
// certstore interface
|
sl@0
|
100 |
RArray<TUid> uidArray;
|
sl@0
|
101 |
CleanupClosePushL(uidArray);
|
sl@0
|
102 |
|
sl@0
|
103 |
User::LeaveIfError(uidArray.Append(TUid::Uid(KInterfaceWritableCertStore)));
|
sl@0
|
104 |
|
sl@0
|
105 |
TCTFindTokenTypesByInterface filter(uidArray.Array());
|
sl@0
|
106 |
CCTTokenTypeInfo::ListL(iWorkingVars->iWritableTokenTypes, filter);
|
sl@0
|
107 |
|
sl@0
|
108 |
uidArray.Reset();
|
sl@0
|
109 |
|
sl@0
|
110 |
User::LeaveIfError(uidArray.Append(TUid::Uid(KInterfaceCertStore)));
|
sl@0
|
111 |
|
sl@0
|
112 |
RCPointerArray<CCTTokenTypeInfo> tokenTypes;
|
sl@0
|
113 |
CleanupClosePushL(tokenTypes);
|
sl@0
|
114 |
|
sl@0
|
115 |
TCTFindTokenTypesByInterface filter2(uidArray.Array());
|
sl@0
|
116 |
CCTTokenTypeInfo::ListL(tokenTypes, filter2);
|
sl@0
|
117 |
|
sl@0
|
118 |
// Check whether client specified order list has attributes in it
|
sl@0
|
119 |
if(iOrderAttributes.Count() > 0)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
ApplyOrderingL(tokenTypes);
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
// Make a note of all hardware token types
|
sl@0
|
125 |
TInt i = 0;
|
sl@0
|
126 |
TInt end = tokenTypes.Count();
|
sl@0
|
127 |
for (; i < end; i++)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
TCTTokenTypeAttribute software;
|
sl@0
|
130 |
software.iUID = KCTSoftware;
|
sl@0
|
131 |
TInt find = tokenTypes[i]->Attributes().Find(software);
|
sl@0
|
132 |
// In the case (TInt)ETrue == KThirdPartyCertStore == 1
|
sl@0
|
133 |
if (find != KErrNotFound && tokenTypes[i]->Attributes()[find].iVal !=
|
sl@0
|
134 |
(TInt)ETrue && tokenTypes[i]->Attributes()[find].iVal != KManufactureCertStore)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
// This is a hardware type. Add its UID to the list.
|
sl@0
|
137 |
User::LeaveIfError(iHardwareTypeUids.Append(tokenTypes[i]->Type()));
|
sl@0
|
138 |
}
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
i = 0;
|
sl@0
|
142 |
while (i < end)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
TInt j = 0;
|
sl@0
|
145 |
TInt jEnd = iWorkingVars->iWritableTokenTypes.Count();
|
sl@0
|
146 |
while (j < jEnd)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
if (iWorkingVars->iWritableTokenTypes[j]->Type() == tokenTypes[i]->Type())
|
sl@0
|
149 |
{
|
sl@0
|
150 |
break;
|
sl@0
|
151 |
}
|
sl@0
|
152 |
j++;
|
sl@0
|
153 |
}
|
sl@0
|
154 |
if (j == jEnd)
|
sl@0
|
155 |
{
|
sl@0
|
156 |
User::LeaveIfError(iWorkingVars->iReadOnlyTokenTypes.Append(tokenTypes[i]));
|
sl@0
|
157 |
tokenTypes.Remove(i);
|
sl@0
|
158 |
end--;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
else
|
sl@0
|
161 |
{
|
sl@0
|
162 |
i++;
|
sl@0
|
163 |
}
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
CleanupStack::PopAndDestroy(2); // uidArray, tokenTypes
|
sl@0
|
167 |
|
sl@0
|
168 |
iWorkingVars->iIndex = -1;
|
sl@0
|
169 |
|
sl@0
|
170 |
TRequestStatus* status = &iStatus;
|
sl@0
|
171 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
172 |
SetActive();
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
EXPORT_C void CUnifiedCertStore::CancelInitialize()
|
sl@0
|
176 |
{
|
sl@0
|
177 |
if (iState == EInitializeGetTokenList ||
|
sl@0
|
178 |
iState == EInitializeGetToken ||
|
sl@0
|
179 |
iState == EInitializeGetWritableInterface ||
|
sl@0
|
180 |
iState == EInitializeGetReadableInterface ||
|
sl@0
|
181 |
iState == EInitializeGetReadableInterfaceFinished ||
|
sl@0
|
182 |
iState == EInitializeFinished)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
Cancel();
|
sl@0
|
185 |
}
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
void CUnifiedCertStore::List(RMPointerArray<CCTCertInfo>& aCertInfos,
|
sl@0
|
189 |
const CCertAttributeFilter& aFilter,
|
sl@0
|
190 |
TRequestStatus& aStatus)
|
sl@0
|
191 |
{
|
sl@0
|
192 |
BeginAsyncOp(aStatus, EList);
|
sl@0
|
193 |
TRAPD(err, ListL(aCertInfos, aFilter));
|
sl@0
|
194 |
if (err != KErrNone)
|
sl@0
|
195 |
{
|
sl@0
|
196 |
Complete(err);
|
sl@0
|
197 |
}
|
sl@0
|
198 |
}
|
sl@0
|
199 |
|
sl@0
|
200 |
void CUnifiedCertStore::ListL(RMPointerArray<CCTCertInfo>& aCertInfos,
|
sl@0
|
201 |
const CCertAttributeFilter& aFilter)
|
sl@0
|
202 |
{
|
sl@0
|
203 |
if (!iIsInitialized)
|
sl@0
|
204 |
{
|
sl@0
|
205 |
User::Leave(KErrNotReady);
|
sl@0
|
206 |
}
|
sl@0
|
207 |
|
sl@0
|
208 |
AllocWorkingVarsL();
|
sl@0
|
209 |
iWorkingVars->iCertInfos = &aCertInfos;
|
sl@0
|
210 |
iWorkingVars->iFilter = &aFilter;
|
sl@0
|
211 |
iWorkingVars->iCertIndex = aCertInfos.Count();
|
sl@0
|
212 |
iIndex = -1;
|
sl@0
|
213 |
|
sl@0
|
214 |
SetActive();
|
sl@0
|
215 |
TRequestStatus* status = &iStatus;
|
sl@0
|
216 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
void CUnifiedCertStore::CancelList()
|
sl@0
|
220 |
{
|
sl@0
|
221 |
if (iState == EList ||
|
sl@0
|
222 |
iState == ERetrieveForList)
|
sl@0
|
223 |
{
|
sl@0
|
224 |
Cancel();
|
sl@0
|
225 |
}
|
sl@0
|
226 |
}
|
sl@0
|
227 |
|
sl@0
|
228 |
EXPORT_C void CUnifiedCertStore::List(RMPointerArray<CCTCertInfo>& aCertInfos,
|
sl@0
|
229 |
const CCertAttributeFilter& aFilter,
|
sl@0
|
230 |
const TDesC8& aIssuer,
|
sl@0
|
231 |
TRequestStatus& aStatus)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
RPointerArray<const TDesC8> array;
|
sl@0
|
234 |
if (array.Append(&aIssuer) != KErrNone)
|
sl@0
|
235 |
{
|
sl@0
|
236 |
TRequestStatus* status = &aStatus;
|
sl@0
|
237 |
User::RequestComplete(status, KErrNoMemory);
|
sl@0
|
238 |
}
|
sl@0
|
239 |
else
|
sl@0
|
240 |
{
|
sl@0
|
241 |
List(aCertInfos, aFilter, array, aStatus);
|
sl@0
|
242 |
array.Close();
|
sl@0
|
243 |
}
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
EXPORT_C void CUnifiedCertStore::List(RMPointerArray<CCTCertInfo>& aCertInfos,
|
sl@0
|
247 |
const CCertAttributeFilter& aFilter,
|
sl@0
|
248 |
RPointerArray<const TDesC8> aIssuers,
|
sl@0
|
249 |
TRequestStatus& aStatus)
|
sl@0
|
250 |
{
|
sl@0
|
251 |
BeginAsyncOp(aStatus, EList);
|
sl@0
|
252 |
TRAPD(err, ListL(aCertInfos, aFilter, aIssuers));
|
sl@0
|
253 |
if (err != KErrNone)
|
sl@0
|
254 |
{
|
sl@0
|
255 |
Complete(err);
|
sl@0
|
256 |
}
|
sl@0
|
257 |
}
|
sl@0
|
258 |
|
sl@0
|
259 |
void CUnifiedCertStore::ListL(RMPointerArray<CCTCertInfo>& aCertInfos,
|
sl@0
|
260 |
const CCertAttributeFilter& aFilter,
|
sl@0
|
261 |
RPointerArray<const TDesC8> aIssuers)
|
sl@0
|
262 |
{
|
sl@0
|
263 |
// Obscure special case: If aIssuers has no elements, we should
|
sl@0
|
264 |
// return nothing.
|
sl@0
|
265 |
if (aIssuers.Count() == 0)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
Complete(KErrNone);
|
sl@0
|
268 |
return;
|
sl@0
|
269 |
}
|
sl@0
|
270 |
|
sl@0
|
271 |
AllocWorkingVarsL();
|
sl@0
|
272 |
iWorkingVars->iCertInfos = &aCertInfos;
|
sl@0
|
273 |
iWorkingVars->iFilter = &aFilter;
|
sl@0
|
274 |
iWorkingVars->iCertIndex = aCertInfos.Count();
|
sl@0
|
275 |
|
sl@0
|
276 |
TInt count = aIssuers.Count();
|
sl@0
|
277 |
for (TInt i = 0 ; i < count ; ++i)
|
sl@0
|
278 |
{
|
sl@0
|
279 |
User::LeaveIfError(iWorkingVars->iIssuerNames.Append(aIssuers[i]));
|
sl@0
|
280 |
}
|
sl@0
|
281 |
|
sl@0
|
282 |
iIndex = -1;
|
sl@0
|
283 |
SetActive();
|
sl@0
|
284 |
TRequestStatus* status = &iStatus;
|
sl@0
|
285 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
286 |
}
|
sl@0
|
287 |
|
sl@0
|
288 |
EXPORT_C void CUnifiedCertStore::Retrieve(const CCTCertInfo& aCertInfo,
|
sl@0
|
289 |
CCertificate*& aCert,
|
sl@0
|
290 |
TRequestStatus& aStatus)
|
sl@0
|
291 |
{
|
sl@0
|
292 |
BeginAsyncOp(aStatus, ERetrieve);
|
sl@0
|
293 |
TRAPD(err, RetrieveL(aCertInfo, aCert));
|
sl@0
|
294 |
if (err != KErrNone)
|
sl@0
|
295 |
{
|
sl@0
|
296 |
Complete(err);
|
sl@0
|
297 |
}
|
sl@0
|
298 |
}
|
sl@0
|
299 |
|
sl@0
|
300 |
void CUnifiedCertStore::RetrieveL(const CCTCertInfo& aCertInfo,
|
sl@0
|
301 |
CCertificate*& aCert)
|
sl@0
|
302 |
{
|
sl@0
|
303 |
FindCertStoreL(aCertInfo.Handle());
|
sl@0
|
304 |
|
sl@0
|
305 |
if (aCertInfo.CertificateFormat() != EX509Certificate &&
|
sl@0
|
306 |
aCertInfo.CertificateFormat() != EWTLSCertificate)
|
sl@0
|
307 |
{
|
sl@0
|
308 |
User::Leave(KErrNotSupported);
|
sl@0
|
309 |
}
|
sl@0
|
310 |
|
sl@0
|
311 |
AllocWorkingVarsL();
|
sl@0
|
312 |
iWorkingVars->iCertDesC = HBufC8::NewMaxL(aCertInfo.Size());
|
sl@0
|
313 |
iWorkingVars->iReturnedCert = &aCert;
|
sl@0
|
314 |
iWorkingVars->iCertType = aCertInfo.CertificateFormat();
|
sl@0
|
315 |
iWorkingVars->iCertDes.Set(iWorkingVars->iCertDesC->Des());
|
sl@0
|
316 |
iCurrentCertStore->Retrieve(aCertInfo, iWorkingVars->iCertDes, iStatus);
|
sl@0
|
317 |
SetActive();
|
sl@0
|
318 |
}
|
sl@0
|
319 |
|
sl@0
|
320 |
void CUnifiedCertStore::GetCert(CCTCertInfo*& aCertInfo,
|
sl@0
|
321 |
const TCTTokenObjectHandle& aHandle,
|
sl@0
|
322 |
TRequestStatus& aStatus)
|
sl@0
|
323 |
{
|
sl@0
|
324 |
BeginAsyncOp(aStatus, EGetCert);
|
sl@0
|
325 |
TRAPD(err, GetCertL(aCertInfo, aHandle));
|
sl@0
|
326 |
if (err != KErrNone)
|
sl@0
|
327 |
{
|
sl@0
|
328 |
Complete(err);
|
sl@0
|
329 |
}
|
sl@0
|
330 |
}
|
sl@0
|
331 |
|
sl@0
|
332 |
void CUnifiedCertStore::GetCertL(CCTCertInfo*& aCertInfo,
|
sl@0
|
333 |
const TCTTokenObjectHandle& aHandle)
|
sl@0
|
334 |
{
|
sl@0
|
335 |
FindCertStoreL(aHandle);
|
sl@0
|
336 |
iCurrentCertStore->GetCert(aCertInfo, aHandle, iStatus);
|
sl@0
|
337 |
SetActive();
|
sl@0
|
338 |
}
|
sl@0
|
339 |
|
sl@0
|
340 |
void CUnifiedCertStore::CancelGetCert()
|
sl@0
|
341 |
{
|
sl@0
|
342 |
if (iState == EGetCert)
|
sl@0
|
343 |
{
|
sl@0
|
344 |
Cancel();
|
sl@0
|
345 |
}
|
sl@0
|
346 |
}
|
sl@0
|
347 |
|
sl@0
|
348 |
void CUnifiedCertStore::Applications(const CCTCertInfo& aCertInfo,
|
sl@0
|
349 |
RArray<TUid>& aApplications,
|
sl@0
|
350 |
TRequestStatus& aStatus)
|
sl@0
|
351 |
{
|
sl@0
|
352 |
BeginAsyncOp(aStatus, EApplications);
|
sl@0
|
353 |
TRAPD(err, ApplicationsL(aCertInfo, aApplications));
|
sl@0
|
354 |
if (err != KErrNone)
|
sl@0
|
355 |
{
|
sl@0
|
356 |
Complete(err);
|
sl@0
|
357 |
}
|
sl@0
|
358 |
}
|
sl@0
|
359 |
|
sl@0
|
360 |
void CUnifiedCertStore::ApplicationsL(const CCTCertInfo& aCertInfo,
|
sl@0
|
361 |
RArray<TUid>& aApplications)
|
sl@0
|
362 |
{
|
sl@0
|
363 |
FindCertStoreL(aCertInfo.Handle());
|
sl@0
|
364 |
iCurrentCertStore->Applications(aCertInfo, aApplications, iStatus);
|
sl@0
|
365 |
SetActive();
|
sl@0
|
366 |
}
|
sl@0
|
367 |
|
sl@0
|
368 |
void CUnifiedCertStore::CancelApplications()
|
sl@0
|
369 |
{
|
sl@0
|
370 |
if (iState == EApplications)
|
sl@0
|
371 |
{
|
sl@0
|
372 |
Cancel();
|
sl@0
|
373 |
}
|
sl@0
|
374 |
}
|
sl@0
|
375 |
|
sl@0
|
376 |
void CUnifiedCertStore::IsApplicable(const CCTCertInfo& aCertInfo,
|
sl@0
|
377 |
TUid aApplication,
|
sl@0
|
378 |
TBool& aIsApplicable,
|
sl@0
|
379 |
TRequestStatus& aStatus)
|
sl@0
|
380 |
{
|
sl@0
|
381 |
BeginAsyncOp(aStatus, EIsApplicable);
|
sl@0
|
382 |
TRAPD(err, IsApplicableL(aCertInfo, aApplication, aIsApplicable));
|
sl@0
|
383 |
if (err != KErrNone)
|
sl@0
|
384 |
{
|
sl@0
|
385 |
Complete(err);
|
sl@0
|
386 |
}
|
sl@0
|
387 |
}
|
sl@0
|
388 |
|
sl@0
|
389 |
void CUnifiedCertStore::IsApplicableL(const CCTCertInfo& aCertInfo,
|
sl@0
|
390 |
TUid aApplication,
|
sl@0
|
391 |
TBool& aIsApplicable)
|
sl@0
|
392 |
{
|
sl@0
|
393 |
FindCertStoreL(aCertInfo.Handle());
|
sl@0
|
394 |
iCurrentCertStore->IsApplicable(aCertInfo, aApplication, aIsApplicable, iStatus);
|
sl@0
|
395 |
SetActive();
|
sl@0
|
396 |
}
|
sl@0
|
397 |
|
sl@0
|
398 |
void CUnifiedCertStore::CancelIsApplicable()
|
sl@0
|
399 |
{
|
sl@0
|
400 |
if (iState == EIsApplicable)
|
sl@0
|
401 |
{
|
sl@0
|
402 |
Cancel();
|
sl@0
|
403 |
}
|
sl@0
|
404 |
}
|
sl@0
|
405 |
|
sl@0
|
406 |
void CUnifiedCertStore::Trusted(const CCTCertInfo& aCertInfo,
|
sl@0
|
407 |
TBool& aTrusted,
|
sl@0
|
408 |
TRequestStatus& aStatus)
|
sl@0
|
409 |
{
|
sl@0
|
410 |
BeginAsyncOp(aStatus, ETrusted);
|
sl@0
|
411 |
TRAPD(err, TrustedL(aCertInfo, aTrusted));
|
sl@0
|
412 |
if (err != KErrNone)
|
sl@0
|
413 |
{
|
sl@0
|
414 |
Complete(err);
|
sl@0
|
415 |
}
|
sl@0
|
416 |
}
|
sl@0
|
417 |
|
sl@0
|
418 |
void CUnifiedCertStore::TrustedL(const CCTCertInfo& aCertInfo,
|
sl@0
|
419 |
TBool& aTrusted)
|
sl@0
|
420 |
{
|
sl@0
|
421 |
FindCertStoreL(aCertInfo.Handle());
|
sl@0
|
422 |
iCurrentCertStore->Trusted(aCertInfo, aTrusted, iStatus);
|
sl@0
|
423 |
SetActive();
|
sl@0
|
424 |
}
|
sl@0
|
425 |
|
sl@0
|
426 |
void CUnifiedCertStore::CancelTrusted()
|
sl@0
|
427 |
{
|
sl@0
|
428 |
if (iState == ETrusted)
|
sl@0
|
429 |
{
|
sl@0
|
430 |
Cancel();
|
sl@0
|
431 |
}
|
sl@0
|
432 |
}
|
sl@0
|
433 |
|
sl@0
|
434 |
void CUnifiedCertStore::Retrieve(const CCTCertInfo& aCertInfo,
|
sl@0
|
435 |
TDes8& aEncodedCert,
|
sl@0
|
436 |
TRequestStatus& aStatus)
|
sl@0
|
437 |
{
|
sl@0
|
438 |
BeginAsyncOp(aStatus, ERetrieveData);
|
sl@0
|
439 |
TRAPD(err, RetrieveDataL(aCertInfo, aEncodedCert));
|
sl@0
|
440 |
if (err != KErrNone)
|
sl@0
|
441 |
{
|
sl@0
|
442 |
Complete(err);
|
sl@0
|
443 |
}
|
sl@0
|
444 |
}
|
sl@0
|
445 |
|
sl@0
|
446 |
void CUnifiedCertStore::RetrieveDataL(const CCTCertInfo& aCertInfo,
|
sl@0
|
447 |
TDes8& aEncodedCert)
|
sl@0
|
448 |
{
|
sl@0
|
449 |
FindCertStoreL(aCertInfo.Handle());
|
sl@0
|
450 |
iCurrentCertStore->Retrieve(aCertInfo, aEncodedCert, iStatus);
|
sl@0
|
451 |
SetActive();
|
sl@0
|
452 |
}
|
sl@0
|
453 |
|
sl@0
|
454 |
void CUnifiedCertStore::CancelRetrieve()
|
sl@0
|
455 |
{
|
sl@0
|
456 |
if (iState == ERetrieveData)
|
sl@0
|
457 |
{
|
sl@0
|
458 |
Cancel();
|
sl@0
|
459 |
}
|
sl@0
|
460 |
}
|
sl@0
|
461 |
|
sl@0
|
462 |
EXPORT_C void CUnifiedCertStore::Remove(const CCTCertInfo& aCertInfo,
|
sl@0
|
463 |
TRequestStatus& aStatus)
|
sl@0
|
464 |
{
|
sl@0
|
465 |
BeginAsyncOp(aStatus, ERemove);
|
sl@0
|
466 |
TRAPD(err, RemoveL(aCertInfo));
|
sl@0
|
467 |
if (err != KErrNone)
|
sl@0
|
468 |
{
|
sl@0
|
469 |
Complete(err);
|
sl@0
|
470 |
}
|
sl@0
|
471 |
}
|
sl@0
|
472 |
|
sl@0
|
473 |
void CUnifiedCertStore::RemoveL(const CCTCertInfo& aCertInfo)
|
sl@0
|
474 |
{
|
sl@0
|
475 |
FindWritableCertStoreL(aCertInfo.Handle());
|
sl@0
|
476 |
iCurrentWritableCertStore->Remove(aCertInfo, iStatus);
|
sl@0
|
477 |
SetActive();
|
sl@0
|
478 |
}
|
sl@0
|
479 |
|
sl@0
|
480 |
EXPORT_C void CUnifiedCertStore::CancelRemove()
|
sl@0
|
481 |
{
|
sl@0
|
482 |
if (iState == ERemove)
|
sl@0
|
483 |
{
|
sl@0
|
484 |
Cancel();
|
sl@0
|
485 |
}
|
sl@0
|
486 |
}
|
sl@0
|
487 |
|
sl@0
|
488 |
EXPORT_C void CUnifiedCertStore::SetApplicability(const CCTCertInfo& aCertInfo,
|
sl@0
|
489 |
const RArray<TUid>& aApplications,
|
sl@0
|
490 |
TRequestStatus& aStatus)
|
sl@0
|
491 |
{
|
sl@0
|
492 |
BeginAsyncOp(aStatus, ESetApplicability);
|
sl@0
|
493 |
TRAPD(err, SetApplicabilityL(aCertInfo, aApplications));
|
sl@0
|
494 |
if (err != KErrNone)
|
sl@0
|
495 |
{
|
sl@0
|
496 |
Complete(err);
|
sl@0
|
497 |
}
|
sl@0
|
498 |
}
|
sl@0
|
499 |
|
sl@0
|
500 |
void CUnifiedCertStore::SetApplicabilityL(const CCTCertInfo& aCertInfo,
|
sl@0
|
501 |
const RArray<TUid>& aApplications)
|
sl@0
|
502 |
{
|
sl@0
|
503 |
FindWritableCertStoreL(aCertInfo.Handle());
|
sl@0
|
504 |
|
sl@0
|
505 |
// Search for duplicates in the array of application
|
sl@0
|
506 |
// complete with KErrArgument if there are any duplicates
|
sl@0
|
507 |
if(aApplications.Count() > 1)
|
sl@0
|
508 |
{
|
sl@0
|
509 |
TInt i=0, j=1;
|
sl@0
|
510 |
|
sl@0
|
511 |
for(i=0; i<aApplications.Count()-1; i++ )
|
sl@0
|
512 |
{
|
sl@0
|
513 |
for(j=i+1; j<aApplications.Count(); j++)
|
sl@0
|
514 |
{
|
sl@0
|
515 |
if(aApplications[i] == aApplications[j])
|
sl@0
|
516 |
{
|
sl@0
|
517 |
User::Leave(KErrArgument);
|
sl@0
|
518 |
}
|
sl@0
|
519 |
}
|
sl@0
|
520 |
}
|
sl@0
|
521 |
}
|
sl@0
|
522 |
|
sl@0
|
523 |
// Check requested applications actaully exist
|
sl@0
|
524 |
CCertificateAppInfoManager* appInfoManager = CCertificateAppInfoManager::NewLC(iFs, EFalse);
|
sl@0
|
525 |
const RArray<TCertificateAppInfo>& applications = appInfoManager->Applications();
|
sl@0
|
526 |
|
sl@0
|
527 |
for (TInt i = 0 ; i < aApplications.Count() ; ++i)
|
sl@0
|
528 |
{
|
sl@0
|
529 |
TInt j = 0;
|
sl@0
|
530 |
for ( ; j < applications.Count() ; ++j)
|
sl@0
|
531 |
{
|
sl@0
|
532 |
if (aApplications[i] == applications[j].Id())
|
sl@0
|
533 |
{
|
sl@0
|
534 |
break;
|
sl@0
|
535 |
}
|
sl@0
|
536 |
}
|
sl@0
|
537 |
if (j == applications.Count())
|
sl@0
|
538 |
{
|
sl@0
|
539 |
User::Leave(KErrArgument);
|
sl@0
|
540 |
}
|
sl@0
|
541 |
}
|
sl@0
|
542 |
CleanupStack::PopAndDestroy(appInfoManager);
|
sl@0
|
543 |
|
sl@0
|
544 |
iCurrentWritableCertStore->SetApplicability(aCertInfo, aApplications, iStatus);
|
sl@0
|
545 |
SetActive();
|
sl@0
|
546 |
}
|
sl@0
|
547 |
|
sl@0
|
548 |
EXPORT_C void CUnifiedCertStore::CancelSetApplicability()
|
sl@0
|
549 |
{
|
sl@0
|
550 |
if (iState == ESetApplicability)
|
sl@0
|
551 |
{
|
sl@0
|
552 |
Cancel();
|
sl@0
|
553 |
}
|
sl@0
|
554 |
}
|
sl@0
|
555 |
|
sl@0
|
556 |
EXPORT_C void CUnifiedCertStore::SetTrust(const CCTCertInfo& aCertInfo,
|
sl@0
|
557 |
TBool aTrusted,
|
sl@0
|
558 |
TRequestStatus& aStatus)
|
sl@0
|
559 |
{
|
sl@0
|
560 |
BeginAsyncOp(aStatus, ESetTrust);
|
sl@0
|
561 |
TRAPD(err, SetTrustL(aCertInfo, aTrusted));
|
sl@0
|
562 |
if (err != KErrNone)
|
sl@0
|
563 |
{
|
sl@0
|
564 |
Complete(err);
|
sl@0
|
565 |
}
|
sl@0
|
566 |
}
|
sl@0
|
567 |
|
sl@0
|
568 |
void CUnifiedCertStore::SetTrustL(const CCTCertInfo& aCertInfo, TBool aTrusted)
|
sl@0
|
569 |
{
|
sl@0
|
570 |
FindWritableCertStoreL(aCertInfo.Handle());
|
sl@0
|
571 |
iCurrentWritableCertStore->SetTrust(aCertInfo, aTrusted, iStatus);
|
sl@0
|
572 |
SetActive();
|
sl@0
|
573 |
}
|
sl@0
|
574 |
|
sl@0
|
575 |
EXPORT_C void CUnifiedCertStore::CancelSetTrust()
|
sl@0
|
576 |
{
|
sl@0
|
577 |
if (iState == ESetTrust)
|
sl@0
|
578 |
{
|
sl@0
|
579 |
Cancel();
|
sl@0
|
580 |
}
|
sl@0
|
581 |
}
|
sl@0
|
582 |
|
sl@0
|
583 |
/**
|
sl@0
|
584 |
* Get the certstore containing a given certificate.
|
sl@0
|
585 |
*
|
sl@0
|
586 |
* Returns the certstore containing the cert referenced in certinfo or NULL if
|
sl@0
|
587 |
* not found.
|
sl@0
|
588 |
*/
|
sl@0
|
589 |
MCTCertStore* CUnifiedCertStore::GetCertStore(const TCTTokenObjectHandle& aHandle)
|
sl@0
|
590 |
{
|
sl@0
|
591 |
TInt count = iCertStores.Count();
|
sl@0
|
592 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
593 |
{
|
sl@0
|
594 |
MCTCertStore* certstore = iCertStores[i];
|
sl@0
|
595 |
MCTToken& token = certstore->Token();
|
sl@0
|
596 |
if (token.Handle() == aHandle.iTokenHandle)
|
sl@0
|
597 |
{
|
sl@0
|
598 |
return certstore;
|
sl@0
|
599 |
}
|
sl@0
|
600 |
}
|
sl@0
|
601 |
return NULL;
|
sl@0
|
602 |
}
|
sl@0
|
603 |
|
sl@0
|
604 |
/**
|
sl@0
|
605 |
* Set iCurrentCertStore to the certstore containing a given certificate, or
|
sl@0
|
606 |
* leave if it could not be found. The handle is the handle of the *certinfo*,
|
sl@0
|
607 |
* *NOT* the token.
|
sl@0
|
608 |
*/
|
sl@0
|
609 |
void CUnifiedCertStore::FindCertStoreL(const TCTTokenObjectHandle& aHandle)
|
sl@0
|
610 |
{
|
sl@0
|
611 |
assert(!iCurrentCertStore);
|
sl@0
|
612 |
assert(!iCurrentWritableCertStore);
|
sl@0
|
613 |
|
sl@0
|
614 |
if (!iIsInitialized)
|
sl@0
|
615 |
{
|
sl@0
|
616 |
User::Leave(KErrNotReady);
|
sl@0
|
617 |
}
|
sl@0
|
618 |
|
sl@0
|
619 |
iCurrentCertStore = GetCertStore(aHandle);
|
sl@0
|
620 |
|
sl@0
|
621 |
if (!iCurrentCertStore)
|
sl@0
|
622 |
{
|
sl@0
|
623 |
User::Leave(KErrNotFound);
|
sl@0
|
624 |
}
|
sl@0
|
625 |
}
|
sl@0
|
626 |
|
sl@0
|
627 |
/**
|
sl@0
|
628 |
* Set iCurrentWritableCertStore to the writable certstore containing a given
|
sl@0
|
629 |
* certificate, or leave if it could not be found. The handle is the handle of
|
sl@0
|
630 |
* the *certinfo*, *NOT* the token.
|
sl@0
|
631 |
*/
|
sl@0
|
632 |
void CUnifiedCertStore::FindWritableCertStoreL(const TCTTokenObjectHandle& aHandle)
|
sl@0
|
633 |
{
|
sl@0
|
634 |
assert(!iCurrentCertStore);
|
sl@0
|
635 |
assert(!iCurrentWritableCertStore);
|
sl@0
|
636 |
|
sl@0
|
637 |
if (!iIsInitialized)
|
sl@0
|
638 |
{
|
sl@0
|
639 |
User::Leave(KErrNotReady);
|
sl@0
|
640 |
}
|
sl@0
|
641 |
|
sl@0
|
642 |
if (!iOpenedForWrite)
|
sl@0
|
643 |
{
|
sl@0
|
644 |
User::Leave(KErrAccessDenied);
|
sl@0
|
645 |
}
|
sl@0
|
646 |
|
sl@0
|
647 |
iCurrentWritableCertStore = NULL;
|
sl@0
|
648 |
TInt count = iWritableCertStores.Count();
|
sl@0
|
649 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
650 |
{
|
sl@0
|
651 |
MCTWritableCertStore* certstore = iWritableCertStores[i];
|
sl@0
|
652 |
MCTToken& token = certstore->Token();
|
sl@0
|
653 |
if (token.Handle() == aHandle.iTokenHandle)
|
sl@0
|
654 |
{
|
sl@0
|
655 |
iCurrentWritableCertStore = certstore;
|
sl@0
|
656 |
break;
|
sl@0
|
657 |
}
|
sl@0
|
658 |
}
|
sl@0
|
659 |
|
sl@0
|
660 |
if (!iCurrentWritableCertStore)
|
sl@0
|
661 |
{
|
sl@0
|
662 |
User::Leave(KErrNotFound);
|
sl@0
|
663 |
}
|
sl@0
|
664 |
}
|
sl@0
|
665 |
|
sl@0
|
666 |
EXPORT_C TInt CUnifiedCertStore::CertStoreCount() const
|
sl@0
|
667 |
{
|
sl@0
|
668 |
return iCertStores.Count();
|
sl@0
|
669 |
}
|
sl@0
|
670 |
|
sl@0
|
671 |
EXPORT_C MCTCertStore& CUnifiedCertStore::CertStore(TInt aIndex)
|
sl@0
|
672 |
{
|
sl@0
|
673 |
assert(aIndex < iCertStores.Count());
|
sl@0
|
674 |
return *iCertStores[aIndex];
|
sl@0
|
675 |
}
|
sl@0
|
676 |
|
sl@0
|
677 |
EXPORT_C TInt CUnifiedCertStore::WritableCertStoreCount() const
|
sl@0
|
678 |
{
|
sl@0
|
679 |
return iWritableCertStores.Count();
|
sl@0
|
680 |
}
|
sl@0
|
681 |
|
sl@0
|
682 |
EXPORT_C MCTWritableCertStore& CUnifiedCertStore::WritableCertStore(TInt aIndex)
|
sl@0
|
683 |
{
|
sl@0
|
684 |
assert(aIndex < iWritableCertStores.Count());
|
sl@0
|
685 |
return *iWritableCertStores[aIndex];
|
sl@0
|
686 |
}
|
sl@0
|
687 |
|
sl@0
|
688 |
EXPORT_C TInt CUnifiedCertStore::ReadOnlyCertStoreCount() const
|
sl@0
|
689 |
{
|
sl@0
|
690 |
return iReadOnlyCertStores.Count();
|
sl@0
|
691 |
}
|
sl@0
|
692 |
|
sl@0
|
693 |
EXPORT_C MCTCertStore& CUnifiedCertStore::ReadOnlyCertStore(TInt aIndex)
|
sl@0
|
694 |
{
|
sl@0
|
695 |
assert(aIndex < iReadOnlyCertStores.Count());
|
sl@0
|
696 |
return *iReadOnlyCertStores[aIndex];
|
sl@0
|
697 |
}
|
sl@0
|
698 |
|
sl@0
|
699 |
CUnifiedCertStore::CUnifiedCertStore(RFs& aFs, TBool aOpenForWrite)
|
sl@0
|
700 |
: CActive(EPriorityNormal), iFs(aFs), iOpenedForWrite(aOpenForWrite), iOrderAttributes()
|
sl@0
|
701 |
{
|
sl@0
|
702 |
CActiveScheduler::Add(this);
|
sl@0
|
703 |
assert(IsAdded());
|
sl@0
|
704 |
}
|
sl@0
|
705 |
|
sl@0
|
706 |
void CUnifiedCertStore::ConstructL(RArray<TInt>& aOrderFilter)
|
sl@0
|
707 |
{
|
sl@0
|
708 |
|
sl@0
|
709 |
for (TInt i=0;i<aOrderFilter.Count();i++)
|
sl@0
|
710 |
{
|
sl@0
|
711 |
User::LeaveIfError(iOrderAttributes.Append(aOrderFilter[i]));
|
sl@0
|
712 |
}
|
sl@0
|
713 |
}
|
sl@0
|
714 |
|
sl@0
|
715 |
void CUnifiedCertStore::RunL()
|
sl@0
|
716 |
{
|
sl@0
|
717 |
if ((iState != EInitializeGetReadableInterface) &&
|
sl@0
|
718 |
(iState != EInitializeGetReadableInterfaceFinished) &&
|
sl@0
|
719 |
(iState != EInitializeGetToken)) // We don't want to leave if we're in this state
|
sl@0
|
720 |
// since we want to enumerate all tokens, see below
|
sl@0
|
721 |
{
|
sl@0
|
722 |
User::LeaveIfError(iStatus.Int());
|
sl@0
|
723 |
}
|
sl@0
|
724 |
|
sl@0
|
725 |
switch (iState)
|
sl@0
|
726 |
{
|
sl@0
|
727 |
case EInitializeGetTokenList:
|
sl@0
|
728 |
// We need to try to get a list of Tokens for each of the Token Types
|
sl@0
|
729 |
iWorkingVars->iIndex++;
|
sl@0
|
730 |
TInt end;
|
sl@0
|
731 |
if (!iCurrentlyDoingReadOnly)
|
sl@0
|
732 |
{
|
sl@0
|
733 |
end = iWorkingVars->iWritableTokenTypes.Count();
|
sl@0
|
734 |
}
|
sl@0
|
735 |
else
|
sl@0
|
736 |
{
|
sl@0
|
737 |
end = iWorkingVars->iReadOnlyTokenTypes.Count();
|
sl@0
|
738 |
}
|
sl@0
|
739 |
if (iWorkingVars->iIndex < end)
|
sl@0
|
740 |
{
|
sl@0
|
741 |
assert(!iTokenType);
|
sl@0
|
742 |
TInt createRes = KErrNone;
|
sl@0
|
743 |
if (iCurrentlyDoingReadOnly)
|
sl@0
|
744 |
{
|
sl@0
|
745 |
TRAP(createRes, iTokenType = MCTTokenType::NewL(*iWorkingVars->iReadOnlyTokenTypes[iWorkingVars->iIndex], iFs));
|
sl@0
|
746 |
}
|
sl@0
|
747 |
else
|
sl@0
|
748 |
{
|
sl@0
|
749 |
TRAP(createRes, iTokenType = MCTTokenType::NewL(*iWorkingVars->iWritableTokenTypes[iWorkingVars->iIndex], iFs));
|
sl@0
|
750 |
}
|
sl@0
|
751 |
|
sl@0
|
752 |
if (KErrNoMemory==createRes)
|
sl@0
|
753 |
{
|
sl@0
|
754 |
// Leave if there's no memory, so OOM tests work
|
sl@0
|
755 |
User::Leave(createRes);
|
sl@0
|
756 |
}
|
sl@0
|
757 |
else if (KErrNone!=createRes)
|
sl@0
|
758 |
{
|
sl@0
|
759 |
// ECOM couldn't load that token type, don't give up, try the next...
|
sl@0
|
760 |
TRequestStatus* stat = &iStatus;
|
sl@0
|
761 |
User::RequestComplete(stat, KErrNone);
|
sl@0
|
762 |
}
|
sl@0
|
763 |
else
|
sl@0
|
764 |
{
|
sl@0
|
765 |
assert(iTokens.Count() == 0);
|
sl@0
|
766 |
iTokenType->List(iTokens, iStatus);
|
sl@0
|
767 |
iIndexTokens = -1;
|
sl@0
|
768 |
iState = EInitializeGetToken;
|
sl@0
|
769 |
}
|
sl@0
|
770 |
}
|
sl@0
|
771 |
else if (!iCurrentlyDoingReadOnly)
|
sl@0
|
772 |
{
|
sl@0
|
773 |
iCurrentlyDoingReadOnly = ETrue;
|
sl@0
|
774 |
iWorkingVars->iIndex = -1;
|
sl@0
|
775 |
TRequestStatus* status = &iStatus;
|
sl@0
|
776 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
777 |
}
|
sl@0
|
778 |
else
|
sl@0
|
779 |
{
|
sl@0
|
780 |
iState = EInitializeFinished;
|
sl@0
|
781 |
TRequestStatus* status = &iStatus;
|
sl@0
|
782 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
783 |
}
|
sl@0
|
784 |
SetActive();
|
sl@0
|
785 |
break;
|
sl@0
|
786 |
|
sl@0
|
787 |
case EInitializeGetToken:
|
sl@0
|
788 |
if (iStatus.Int() == KErrHardwareNotAvailable)
|
sl@0
|
789 |
{
|
sl@0
|
790 |
// If the hardware corresponding to this
|
sl@0
|
791 |
// TokenType has been removed then just skip it
|
sl@0
|
792 |
// but DO NOT leave!
|
sl@0
|
793 |
++iIndexTokens;
|
sl@0
|
794 |
iState = EInitializeGetToken;
|
sl@0
|
795 |
TRequestStatus* status = &iStatus;
|
sl@0
|
796 |
User::RequestComplete(status,KErrNone);
|
sl@0
|
797 |
}
|
sl@0
|
798 |
else
|
sl@0
|
799 |
{
|
sl@0
|
800 |
User::LeaveIfError(iStatus.Int());
|
sl@0
|
801 |
|
sl@0
|
802 |
// iIndexTokens is initialized at EInitializeGetTokenList
|
sl@0
|
803 |
++iIndexTokens;
|
sl@0
|
804 |
|
sl@0
|
805 |
// We need to try to get a certstore interface (readable or
|
sl@0
|
806 |
// writable) for each of the Tokens in iTokens
|
sl@0
|
807 |
if (iIndexTokens < iTokens.Count())
|
sl@0
|
808 |
{
|
sl@0
|
809 |
assert(!iToken);
|
sl@0
|
810 |
iTokenType->OpenToken(*iTokens[iIndexTokens], iToken, iStatus);
|
sl@0
|
811 |
if ((iOpenedForWrite) && !iCurrentlyDoingReadOnly)
|
sl@0
|
812 |
{
|
sl@0
|
813 |
iState = EInitializeGetWritableInterface;
|
sl@0
|
814 |
}
|
sl@0
|
815 |
else
|
sl@0
|
816 |
{
|
sl@0
|
817 |
iState = EInitializeGetReadableInterface;
|
sl@0
|
818 |
}
|
sl@0
|
819 |
}
|
sl@0
|
820 |
else
|
sl@0
|
821 |
{
|
sl@0
|
822 |
// We don't need the iTokenType anymore
|
sl@0
|
823 |
iTokenType->Release();
|
sl@0
|
824 |
iTokenType = 0;
|
sl@0
|
825 |
// We don't need the list of Tokens anymore
|
sl@0
|
826 |
iTokens.Close();
|
sl@0
|
827 |
iState = EInitializeGetTokenList;
|
sl@0
|
828 |
TRequestStatus* status = &iStatus;
|
sl@0
|
829 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
830 |
}
|
sl@0
|
831 |
}
|
sl@0
|
832 |
SetActive();
|
sl@0
|
833 |
break;
|
sl@0
|
834 |
|
sl@0
|
835 |
case EInitializeGetWritableInterface:
|
sl@0
|
836 |
{
|
sl@0
|
837 |
User::LeaveIfError(iStatus.Int());
|
sl@0
|
838 |
// First we try to get a writable interface to the store, if
|
sl@0
|
839 |
// that doesn't work we will try to get a readable interface
|
sl@0
|
840 |
assert(iToken);
|
sl@0
|
841 |
assert(!iTokenInterface);
|
sl@0
|
842 |
TUid uid = { KInterfaceWritableCertStore };
|
sl@0
|
843 |
iToken->GetInterface(uid, iTokenInterface, iStatus);
|
sl@0
|
844 |
iState = EInitializeGetReadableInterface;
|
sl@0
|
845 |
SetActive();
|
sl@0
|
846 |
}
|
sl@0
|
847 |
break;
|
sl@0
|
848 |
|
sl@0
|
849 |
case EInitializeGetReadableInterface:
|
sl@0
|
850 |
// We check if we managed to get a writable interface
|
sl@0
|
851 |
if (iStatus == KErrNoMemory)
|
sl@0
|
852 |
{
|
sl@0
|
853 |
User::Leave(KErrNoMemory);
|
sl@0
|
854 |
}
|
sl@0
|
855 |
|
sl@0
|
856 |
if (!iCurrentlyDoingReadOnly && iOpenedForWrite && (iStatus == KErrNone))
|
sl@0
|
857 |
{
|
sl@0
|
858 |
assert(iTokenInterface);
|
sl@0
|
859 |
|
sl@0
|
860 |
// Drop the interface into a "writable checking" object
|
sl@0
|
861 |
CCheckedCertStore* interf =
|
sl@0
|
862 |
CCheckedCertStore::NewCheckedWritableCertStoreL(iTokenInterface, iPSCertstoreChangeProperty);
|
sl@0
|
863 |
|
sl@0
|
864 |
CleanupReleasePushL(*interf);
|
sl@0
|
865 |
iTokenInterface = 0;
|
sl@0
|
866 |
|
sl@0
|
867 |
User::LeaveIfError(iWritableCertStores.Append(interf));
|
sl@0
|
868 |
CleanupStack::Pop();
|
sl@0
|
869 |
|
sl@0
|
870 |
User::LeaveIfError(iCertStores.Append(interf));
|
sl@0
|
871 |
|
sl@0
|
872 |
// We don't need the Token anymore
|
sl@0
|
873 |
iToken->Release();
|
sl@0
|
874 |
iToken = 0;
|
sl@0
|
875 |
iState = EInitializeGetToken;
|
sl@0
|
876 |
TRequestStatus* status = &iStatus;
|
sl@0
|
877 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
878 |
}
|
sl@0
|
879 |
else
|
sl@0
|
880 |
{
|
sl@0
|
881 |
// We do the check only if we were not trying to get a Writeable Interface
|
sl@0
|
882 |
// before, if we trying to get a writeable interface before, we know that we
|
sl@0
|
883 |
// have a valid iToken.
|
sl@0
|
884 |
if ((iCurrentlyDoingReadOnly || !iOpenedForWrite) && (iStatus != KErrNone))
|
sl@0
|
885 |
{
|
sl@0
|
886 |
User::Leave(iStatus.Int());
|
sl@0
|
887 |
}
|
sl@0
|
888 |
else
|
sl@0
|
889 |
{
|
sl@0
|
890 |
assert(iToken);
|
sl@0
|
891 |
assert(!iTokenInterface);
|
sl@0
|
892 |
TUid uid = { KInterfaceCertStore };
|
sl@0
|
893 |
iToken->GetInterface(uid, iTokenInterface, iStatus);
|
sl@0
|
894 |
iState = EInitializeGetReadableInterfaceFinished;
|
sl@0
|
895 |
}
|
sl@0
|
896 |
}
|
sl@0
|
897 |
SetActive();
|
sl@0
|
898 |
break;
|
sl@0
|
899 |
|
sl@0
|
900 |
case EInitializeGetReadableInterfaceFinished:
|
sl@0
|
901 |
{
|
sl@0
|
902 |
if (iStatus == KErrNoMemory)
|
sl@0
|
903 |
{
|
sl@0
|
904 |
User::Leave(KErrNoMemory);
|
sl@0
|
905 |
}
|
sl@0
|
906 |
|
sl@0
|
907 |
if (iStatus == KErrNone)
|
sl@0
|
908 |
{
|
sl@0
|
909 |
assert(iTokenInterface);
|
sl@0
|
910 |
|
sl@0
|
911 |
// Drop the interface into a "read only checking" object
|
sl@0
|
912 |
CCheckedCertStore* interf =
|
sl@0
|
913 |
CCheckedCertStore::NewCheckedCertStoreL(iTokenInterface, iPSCertstoreChangeProperty);
|
sl@0
|
914 |
|
sl@0
|
915 |
CleanupReleasePushL(*interf);
|
sl@0
|
916 |
iTokenInterface = 0;
|
sl@0
|
917 |
|
sl@0
|
918 |
User::LeaveIfError(iReadOnlyCertStores.Append(interf));
|
sl@0
|
919 |
CleanupStack::Pop(interf);
|
sl@0
|
920 |
|
sl@0
|
921 |
User::LeaveIfError(iCertStores.Append(interf));
|
sl@0
|
922 |
}
|
sl@0
|
923 |
|
sl@0
|
924 |
// We don't need the Token anymore
|
sl@0
|
925 |
iToken->Release();
|
sl@0
|
926 |
iToken = 0;
|
sl@0
|
927 |
|
sl@0
|
928 |
iStatus = KErrNone;
|
sl@0
|
929 |
iState = EInitializeGetToken;
|
sl@0
|
930 |
TRequestStatus* status = &iStatus;
|
sl@0
|
931 |
User::RequestComplete(status, iStatus.Int());
|
sl@0
|
932 |
SetActive();
|
sl@0
|
933 |
}
|
sl@0
|
934 |
break;
|
sl@0
|
935 |
|
sl@0
|
936 |
case EInitializeFinished:
|
sl@0
|
937 |
assert(!iTokenType);
|
sl@0
|
938 |
assert(!iToken);
|
sl@0
|
939 |
assert(!iTokenInterface);
|
sl@0
|
940 |
iIsInitialized = ETrue;
|
sl@0
|
941 |
Complete(iStatus.Int());
|
sl@0
|
942 |
break;
|
sl@0
|
943 |
|
sl@0
|
944 |
case EList:
|
sl@0
|
945 |
// iIndex has been initialized in List
|
sl@0
|
946 |
iIndex++;
|
sl@0
|
947 |
iCurrentCertStore = NULL;
|
sl@0
|
948 |
if (iIndex < iCertStores.Count())
|
sl@0
|
949 |
{
|
sl@0
|
950 |
iCurrentCertStore = iCertStores[iIndex];
|
sl@0
|
951 |
iCurrentCertStore->List(*iWorkingVars->iCertInfos, *iWorkingVars->iFilter, iStatus);
|
sl@0
|
952 |
iWorkingVars->iCertIndex = 0;
|
sl@0
|
953 |
SetActive();
|
sl@0
|
954 |
}
|
sl@0
|
955 |
else if (iWorkingVars->iIssuerNames.Count() > 0)
|
sl@0
|
956 |
{
|
sl@0
|
957 |
// We have an issuer name. We now remove all certs
|
sl@0
|
958 |
// that don't match that issuer.
|
sl@0
|
959 |
|
sl@0
|
960 |
// If this is the first time in here, we need to parse
|
sl@0
|
961 |
// and hash all the issuer names.
|
sl@0
|
962 |
if (iWorkingVars->iParsedIssuerNames.Count() == 0)
|
sl@0
|
963 |
{
|
sl@0
|
964 |
CSHA1* sha1 = CSHA1::NewL();
|
sl@0
|
965 |
CleanupStack::PushL(sha1);
|
sl@0
|
966 |
TInt count = iWorkingVars->iIssuerNames.Count();
|
sl@0
|
967 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
968 |
{
|
sl@0
|
969 |
CX500DistinguishedName* dn =
|
sl@0
|
970 |
CX500DistinguishedName::NewLC(*iWorkingVars->
|
sl@0
|
971 |
iIssuerNames[i]);
|
sl@0
|
972 |
User::LeaveIfError(
|
sl@0
|
973 |
iWorkingVars->iParsedIssuerNames.Append(dn));
|
sl@0
|
974 |
CleanupStack::Pop(dn);
|
sl@0
|
975 |
TPtrC8 hash=sha1->Hash(*iWorkingVars->iIssuerNames[i]);
|
sl@0
|
976 |
User::LeaveIfError(
|
sl@0
|
977 |
iWorkingVars->iHashedIssuerNames.Append(
|
sl@0
|
978 |
hash.AllocLC()));
|
sl@0
|
979 |
CleanupStack::Pop();
|
sl@0
|
980 |
}
|
sl@0
|
981 |
CleanupStack::PopAndDestroy();
|
sl@0
|
982 |
}
|
sl@0
|
983 |
|
sl@0
|
984 |
while (iWorkingVars->iCertIndex <
|
sl@0
|
985 |
iWorkingVars->iCertInfos->Count())
|
sl@0
|
986 |
{
|
sl@0
|
987 |
CCTCertInfo* info =
|
sl@0
|
988 |
(*iWorkingVars->iCertInfos)[iWorkingVars->iCertIndex];
|
sl@0
|
989 |
TCompareResults res = CompareCertInfoDN(info);
|
sl@0
|
990 |
if (res == EYes)
|
sl@0
|
991 |
{
|
sl@0
|
992 |
// It matches. leave it for the next one.
|
sl@0
|
993 |
iWorkingVars->iCertIndex++;
|
sl@0
|
994 |
}
|
sl@0
|
995 |
else if (res == ENo)
|
sl@0
|
996 |
{
|
sl@0
|
997 |
// It doesn't match. Remove it and try the next one.
|
sl@0
|
998 |
info->Release();
|
sl@0
|
999 |
iWorkingVars->iCertInfos->
|
sl@0
|
1000 |
Remove(iWorkingVars->iCertIndex);
|
sl@0
|
1001 |
}
|
sl@0
|
1002 |
else // res == EMaybe
|
sl@0
|
1003 |
{
|
sl@0
|
1004 |
// Need to load the cert and properly compare the DNs.
|
sl@0
|
1005 |
iCurrentCertStore = GetCertStore(info->Handle());
|
sl@0
|
1006 |
assert(iCurrentCertStore);
|
sl@0
|
1007 |
|
sl@0
|
1008 |
iWorkingVars->iCertDesC=HBufC8::NewMaxL(info->Size());
|
sl@0
|
1009 |
iWorkingVars->iCertType = info->CertificateFormat();
|
sl@0
|
1010 |
iState = ERetrieveForList;
|
sl@0
|
1011 |
iWorkingVars->iCertDes.Set(iWorkingVars->iCertDesC->Des());
|
sl@0
|
1012 |
iCurrentCertStore->Retrieve(*info, iWorkingVars->iCertDes, iStatus);
|
sl@0
|
1013 |
SetActive();
|
sl@0
|
1014 |
return;
|
sl@0
|
1015 |
}
|
sl@0
|
1016 |
}
|
sl@0
|
1017 |
Complete(KErrNone);
|
sl@0
|
1018 |
}
|
sl@0
|
1019 |
else
|
sl@0
|
1020 |
{
|
sl@0
|
1021 |
Complete(KErrNone);
|
sl@0
|
1022 |
}
|
sl@0
|
1023 |
break;
|
sl@0
|
1024 |
|
sl@0
|
1025 |
case ERetrieve:
|
sl@0
|
1026 |
{
|
sl@0
|
1027 |
switch (iWorkingVars->iCertType)
|
sl@0
|
1028 |
{
|
sl@0
|
1029 |
case EX509Certificate:
|
sl@0
|
1030 |
{
|
sl@0
|
1031 |
TPtr8 theCert(iWorkingVars->iCertDesC->Des());
|
sl@0
|
1032 |
*(iWorkingVars->iReturnedCert) = CX509Certificate::NewL(theCert);
|
sl@0
|
1033 |
}
|
sl@0
|
1034 |
break;
|
sl@0
|
1035 |
case EWTLSCertificate:
|
sl@0
|
1036 |
{
|
sl@0
|
1037 |
TPtr8 theCert(iWorkingVars->iCertDesC->Des());
|
sl@0
|
1038 |
*(iWorkingVars->iReturnedCert) = CWTLSCertificate::NewL(theCert);
|
sl@0
|
1039 |
}
|
sl@0
|
1040 |
break;
|
sl@0
|
1041 |
default:
|
sl@0
|
1042 |
assert(EFalse);
|
sl@0
|
1043 |
break;
|
sl@0
|
1044 |
}
|
sl@0
|
1045 |
Complete(KErrNone);
|
sl@0
|
1046 |
}
|
sl@0
|
1047 |
break;
|
sl@0
|
1048 |
|
sl@0
|
1049 |
case ERetrieveForList:
|
sl@0
|
1050 |
{
|
sl@0
|
1051 |
TPtr8 theCert(iWorkingVars->iCertDesC->Des());
|
sl@0
|
1052 |
CX509Certificate* cert=CX509Certificate::NewLC(theCert);
|
sl@0
|
1053 |
if (MatchL(cert->IssuerName()))
|
sl@0
|
1054 |
{
|
sl@0
|
1055 |
// It matches. leave it for the next one.
|
sl@0
|
1056 |
iWorkingVars->iCertIndex++;
|
sl@0
|
1057 |
}
|
sl@0
|
1058 |
else
|
sl@0
|
1059 |
{
|
sl@0
|
1060 |
// It doesn't match. Remove it and try the next one.
|
sl@0
|
1061 |
(*iWorkingVars->iCertInfos)[iWorkingVars->iCertIndex]->Release();
|
sl@0
|
1062 |
iWorkingVars->iCertInfos->Remove(iWorkingVars->iCertIndex);
|
sl@0
|
1063 |
}
|
sl@0
|
1064 |
CleanupStack::PopAndDestroy(cert);
|
sl@0
|
1065 |
delete iWorkingVars->iCertDesC;
|
sl@0
|
1066 |
iWorkingVars->iCertDesC = 0;
|
sl@0
|
1067 |
iState = EList;
|
sl@0
|
1068 |
SetActive();
|
sl@0
|
1069 |
TRequestStatus* status = & iStatus;
|
sl@0
|
1070 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
1071 |
break;
|
sl@0
|
1072 |
}
|
sl@0
|
1073 |
|
sl@0
|
1074 |
case ERemove:
|
sl@0
|
1075 |
case ESetApplicability:
|
sl@0
|
1076 |
case ESetTrust:
|
sl@0
|
1077 |
case EGetCert:
|
sl@0
|
1078 |
case EApplications:
|
sl@0
|
1079 |
case EIsApplicable:
|
sl@0
|
1080 |
case ETrusted:
|
sl@0
|
1081 |
case ERetrieveData:
|
sl@0
|
1082 |
Complete(KErrNone);
|
sl@0
|
1083 |
break;
|
sl@0
|
1084 |
|
sl@0
|
1085 |
default:
|
sl@0
|
1086 |
User::Panic(KUCSPanic, 1);
|
sl@0
|
1087 |
break;
|
sl@0
|
1088 |
}
|
sl@0
|
1089 |
}
|
sl@0
|
1090 |
|
sl@0
|
1091 |
TInt CUnifiedCertStore::RunError(TInt aError)
|
sl@0
|
1092 |
{
|
sl@0
|
1093 |
Complete(aError);
|
sl@0
|
1094 |
return KErrNone;
|
sl@0
|
1095 |
}
|
sl@0
|
1096 |
|
sl@0
|
1097 |
void CUnifiedCertStore::DoCancel()
|
sl@0
|
1098 |
{
|
sl@0
|
1099 |
// If the current state is the last state involved in handling a request, we
|
sl@0
|
1100 |
// check to see if we have already been completed - in this case we can
|
sl@0
|
1101 |
// simply complete the client with iStatus (this may be KErrNone). If we
|
sl@0
|
1102 |
// have not we cancel the outstanding request and pass the resulting iStatus
|
sl@0
|
1103 |
// back to the client - this too may indicate a successful completion if the
|
sl@0
|
1104 |
// cancel arrived after the request was executed.
|
sl@0
|
1105 |
//
|
sl@0
|
1106 |
// For more complex cases, where there are more states to go through before
|
sl@0
|
1107 |
// we finish servicing the client request, we cancel any outstanding
|
sl@0
|
1108 |
// request, and return KErrCancel to the client.
|
sl@0
|
1109 |
|
sl@0
|
1110 |
switch (iState)
|
sl@0
|
1111 |
{
|
sl@0
|
1112 |
case EInitializeFinished:
|
sl@0
|
1113 |
case ERetrieve:
|
sl@0
|
1114 |
case EGetCert:
|
sl@0
|
1115 |
case EApplications:
|
sl@0
|
1116 |
case EIsApplicable:
|
sl@0
|
1117 |
case ETrusted:
|
sl@0
|
1118 |
case ERetrieveData:
|
sl@0
|
1119 |
case ERemove:
|
sl@0
|
1120 |
case ESetApplicability:
|
sl@0
|
1121 |
case ESetTrust:
|
sl@0
|
1122 |
if (iStatus == KRequestPending)
|
sl@0
|
1123 |
{
|
sl@0
|
1124 |
// Attempt to cancel outstanding request and pass status back to
|
sl@0
|
1125 |
// client
|
sl@0
|
1126 |
CancelOutstandingRequest();
|
sl@0
|
1127 |
Complete(iStatus.Int());
|
sl@0
|
1128 |
}
|
sl@0
|
1129 |
else
|
sl@0
|
1130 |
{
|
sl@0
|
1131 |
// We've already been completed - call RunL() to process results
|
sl@0
|
1132 |
// and complete client
|
sl@0
|
1133 |
TRAPD(err, RunL());
|
sl@0
|
1134 |
if (err != KErrNone)
|
sl@0
|
1135 |
{
|
sl@0
|
1136 |
RunError(err);
|
sl@0
|
1137 |
}
|
sl@0
|
1138 |
}
|
sl@0
|
1139 |
break;
|
sl@0
|
1140 |
|
sl@0
|
1141 |
default:
|
sl@0
|
1142 |
CancelOutstandingRequest();
|
sl@0
|
1143 |
Complete(KErrCancel);
|
sl@0
|
1144 |
break;
|
sl@0
|
1145 |
}
|
sl@0
|
1146 |
}
|
sl@0
|
1147 |
|
sl@0
|
1148 |
void CUnifiedCertStore::CancelOutstandingRequest()
|
sl@0
|
1149 |
{
|
sl@0
|
1150 |
switch (iState)
|
sl@0
|
1151 |
{
|
sl@0
|
1152 |
case EInitializeGetTokenList:
|
sl@0
|
1153 |
case EInitializeGetToken:
|
sl@0
|
1154 |
case EInitializeGetWritableInterface:
|
sl@0
|
1155 |
case EInitializeGetReadableInterface:
|
sl@0
|
1156 |
case EInitializeGetReadableInterfaceFinished:
|
sl@0
|
1157 |
case EInitializeFinished:
|
sl@0
|
1158 |
// Don't have to cancel initialisation stuff - this happens when we
|
sl@0
|
1159 |
// release the objects in DestroyTemporaryMembers().
|
sl@0
|
1160 |
iStatus = KErrCancel;
|
sl@0
|
1161 |
break;
|
sl@0
|
1162 |
|
sl@0
|
1163 |
case EList:
|
sl@0
|
1164 |
if (iCurrentCertStore)
|
sl@0
|
1165 |
{
|
sl@0
|
1166 |
iCurrentCertStore->CancelList();
|
sl@0
|
1167 |
}
|
sl@0
|
1168 |
break;
|
sl@0
|
1169 |
|
sl@0
|
1170 |
case ERetrieve:
|
sl@0
|
1171 |
case ERetrieveForList:
|
sl@0
|
1172 |
case ERetrieveData:
|
sl@0
|
1173 |
assert(iCurrentCertStore);
|
sl@0
|
1174 |
iCurrentCertStore->CancelRetrieve();
|
sl@0
|
1175 |
break;
|
sl@0
|
1176 |
|
sl@0
|
1177 |
case EGetCert:
|
sl@0
|
1178 |
assert(iCurrentCertStore);
|
sl@0
|
1179 |
iCurrentCertStore->CancelGetCert();
|
sl@0
|
1180 |
break;
|
sl@0
|
1181 |
|
sl@0
|
1182 |
case EApplications:
|
sl@0
|
1183 |
assert(iCurrentCertStore);
|
sl@0
|
1184 |
iCurrentCertStore->CancelApplications();
|
sl@0
|
1185 |
break;
|
sl@0
|
1186 |
|
sl@0
|
1187 |
case EIsApplicable:
|
sl@0
|
1188 |
assert(iCurrentCertStore);
|
sl@0
|
1189 |
iCurrentCertStore->CancelIsApplicable();
|
sl@0
|
1190 |
break;
|
sl@0
|
1191 |
|
sl@0
|
1192 |
case ETrusted:
|
sl@0
|
1193 |
assert(iCurrentCertStore);
|
sl@0
|
1194 |
iCurrentCertStore->CancelTrusted();
|
sl@0
|
1195 |
break;
|
sl@0
|
1196 |
|
sl@0
|
1197 |
case ERemove:
|
sl@0
|
1198 |
assert(iCurrentWritableCertStore);
|
sl@0
|
1199 |
iCurrentWritableCertStore->CancelRemove();
|
sl@0
|
1200 |
break;
|
sl@0
|
1201 |
|
sl@0
|
1202 |
case ESetApplicability:
|
sl@0
|
1203 |
assert(iCurrentWritableCertStore);
|
sl@0
|
1204 |
iCurrentWritableCertStore->CancelSetApplicability();
|
sl@0
|
1205 |
break;
|
sl@0
|
1206 |
|
sl@0
|
1207 |
case ESetTrust:
|
sl@0
|
1208 |
assert(iCurrentWritableCertStore);
|
sl@0
|
1209 |
iCurrentWritableCertStore->CancelSetTrust();
|
sl@0
|
1210 |
break;
|
sl@0
|
1211 |
|
sl@0
|
1212 |
default:
|
sl@0
|
1213 |
User::Panic(KUCSPanic, 1);
|
sl@0
|
1214 |
break;
|
sl@0
|
1215 |
}
|
sl@0
|
1216 |
}
|
sl@0
|
1217 |
|
sl@0
|
1218 |
TBool CUnifiedCertStore::MatchL(const CX500DistinguishedName& aName) const
|
sl@0
|
1219 |
{
|
sl@0
|
1220 |
// Return true if the supplied DN is the same as any of the supplied DNs.
|
sl@0
|
1221 |
TInt count = iWorkingVars->iIssuerNames.Count();
|
sl@0
|
1222 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
1223 |
{
|
sl@0
|
1224 |
if (aName.ExactMatchL(*iWorkingVars->iParsedIssuerNames[i]))
|
sl@0
|
1225 |
return ETrue;
|
sl@0
|
1226 |
}
|
sl@0
|
1227 |
return EFalse;
|
sl@0
|
1228 |
}
|
sl@0
|
1229 |
|
sl@0
|
1230 |
void CUnifiedCertStore::AllocWorkingVarsL()
|
sl@0
|
1231 |
{
|
sl@0
|
1232 |
assert(!iWorkingVars);
|
sl@0
|
1233 |
iWorkingVars = new (ELeave) CUnifiedCertStoreWorkingVars;
|
sl@0
|
1234 |
}
|
sl@0
|
1235 |
|
sl@0
|
1236 |
void CUnifiedCertStore::BeginAsyncOp(TRequestStatus& aStatus, TState aState)
|
sl@0
|
1237 |
{
|
sl@0
|
1238 |
assert(iState == EIdle);
|
sl@0
|
1239 |
assert(!iClientStatus);
|
sl@0
|
1240 |
|
sl@0
|
1241 |
iClientStatus = &aStatus;
|
sl@0
|
1242 |
*iClientStatus = KRequestPending;
|
sl@0
|
1243 |
iState = aState;
|
sl@0
|
1244 |
}
|
sl@0
|
1245 |
|
sl@0
|
1246 |
void CUnifiedCertStore::Complete(TInt aError)
|
sl@0
|
1247 |
{
|
sl@0
|
1248 |
assert(iClientStatus);
|
sl@0
|
1249 |
User::RequestComplete(iClientStatus, aError);
|
sl@0
|
1250 |
DestroyTemporaryMembers();
|
sl@0
|
1251 |
iState = EIdle;
|
sl@0
|
1252 |
}
|
sl@0
|
1253 |
|
sl@0
|
1254 |
void CUnifiedCertStore::DestroyTemporaryMembers()
|
sl@0
|
1255 |
{
|
sl@0
|
1256 |
if (!iIsInitialized)
|
sl@0
|
1257 |
{
|
sl@0
|
1258 |
TInt end = iReadOnlyCertStores.Count();
|
sl@0
|
1259 |
TInt i;
|
sl@0
|
1260 |
for (i = 0; i < end; i++)
|
sl@0
|
1261 |
{
|
sl@0
|
1262 |
iReadOnlyCertStores[i]->Release();
|
sl@0
|
1263 |
}
|
sl@0
|
1264 |
iReadOnlyCertStores.Close();
|
sl@0
|
1265 |
|
sl@0
|
1266 |
end = iWritableCertStores.Count();
|
sl@0
|
1267 |
for (i = 0; i < end; i++)
|
sl@0
|
1268 |
{
|
sl@0
|
1269 |
iWritableCertStores[i]->Release();
|
sl@0
|
1270 |
}
|
sl@0
|
1271 |
iWritableCertStores.Close();
|
sl@0
|
1272 |
|
sl@0
|
1273 |
// The elements are already released by the two loops above
|
sl@0
|
1274 |
iCertStores.Close();
|
sl@0
|
1275 |
}
|
sl@0
|
1276 |
|
sl@0
|
1277 |
if (iTokenType)
|
sl@0
|
1278 |
{
|
sl@0
|
1279 |
iTokenType->Release();
|
sl@0
|
1280 |
iTokenType = 0;
|
sl@0
|
1281 |
}
|
sl@0
|
1282 |
|
sl@0
|
1283 |
if (iToken)
|
sl@0
|
1284 |
{
|
sl@0
|
1285 |
iToken->Release();
|
sl@0
|
1286 |
iToken = 0;
|
sl@0
|
1287 |
}
|
sl@0
|
1288 |
|
sl@0
|
1289 |
if (iTokenInterface)
|
sl@0
|
1290 |
{
|
sl@0
|
1291 |
iTokenInterface->Release();
|
sl@0
|
1292 |
iTokenInterface = 0;
|
sl@0
|
1293 |
}
|
sl@0
|
1294 |
|
sl@0
|
1295 |
iTokens.Close();
|
sl@0
|
1296 |
|
sl@0
|
1297 |
delete iWorkingVars;
|
sl@0
|
1298 |
iWorkingVars = 0;
|
sl@0
|
1299 |
|
sl@0
|
1300 |
iCurrentCertStore = NULL;
|
sl@0
|
1301 |
iCurrentWritableCertStore = NULL;
|
sl@0
|
1302 |
}
|
sl@0
|
1303 |
|
sl@0
|
1304 |
CUnifiedCertStore::TCompareResults
|
sl@0
|
1305 |
CUnifiedCertStore::CompareCertInfoDN(const CCTCertInfo* aCertInfo)
|
sl@0
|
1306 |
{
|
sl@0
|
1307 |
if (aCertInfo->IssuerHash() &&
|
sl@0
|
1308 |
(aCertInfo->CertificateFormat() == EX509CertificateUrl ||
|
sl@0
|
1309 |
iHardwareTypeUids.Find(aCertInfo->Token().TokenType().Type()) !=
|
sl@0
|
1310 |
KErrNotFound))
|
sl@0
|
1311 |
{
|
sl@0
|
1312 |
TInt count = iWorkingVars->iHashedIssuerNames.Count();
|
sl@0
|
1313 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
1314 |
{
|
sl@0
|
1315 |
if (*aCertInfo->IssuerHash()==*iWorkingVars->iHashedIssuerNames[i])
|
sl@0
|
1316 |
return EYes;
|
sl@0
|
1317 |
}
|
sl@0
|
1318 |
return ENo;
|
sl@0
|
1319 |
}
|
sl@0
|
1320 |
if (aCertInfo->CertificateFormat() != EX509Certificate)
|
sl@0
|
1321 |
return ENo;
|
sl@0
|
1322 |
return EMaybe;
|
sl@0
|
1323 |
}
|
sl@0
|
1324 |
|
sl@0
|
1325 |
EXPORT_C CUnifiedCertStore* CUnifiedCertStore::NewL(RFs& aFs,
|
sl@0
|
1326 |
TBool aOpenForWrite,
|
sl@0
|
1327 |
RArray<TInt>& aOrderFilter)
|
sl@0
|
1328 |
{
|
sl@0
|
1329 |
CUnifiedCertStore* self = CUnifiedCertStore::NewLC(aFs,
|
sl@0
|
1330 |
aOpenForWrite,
|
sl@0
|
1331 |
aOrderFilter);
|
sl@0
|
1332 |
CleanupStack::Pop(self);
|
sl@0
|
1333 |
return self;
|
sl@0
|
1334 |
}
|
sl@0
|
1335 |
|
sl@0
|
1336 |
EXPORT_C CUnifiedCertStore* CUnifiedCertStore::NewLC(RFs& aFs,
|
sl@0
|
1337 |
TBool aOpenForWrite,
|
sl@0
|
1338 |
RArray<TInt>& aOrderFilter)
|
sl@0
|
1339 |
{
|
sl@0
|
1340 |
CUnifiedCertStore* self = new(ELeave) CUnifiedCertStore(aFs,
|
sl@0
|
1341 |
aOpenForWrite);
|
sl@0
|
1342 |
CleanupStack::PushL(self);
|
sl@0
|
1343 |
self->ConstructL(aOrderFilter);
|
sl@0
|
1344 |
return self;
|
sl@0
|
1345 |
}
|
sl@0
|
1346 |
|
sl@0
|
1347 |
void CUnifiedCertStore::FilterTokenTypesL(RCPointerArray<CCTTokenTypeInfo>& aSearchTokenTypes,
|
sl@0
|
1348 |
RCPointerArray<CCTTokenTypeInfo>& aTempTokenTypes,
|
sl@0
|
1349 |
TInt aOrderAttribute)
|
sl@0
|
1350 |
{
|
sl@0
|
1351 |
//We allow aOrderAttribute=KUnknownHardwareCertStore here to keep DC.
|
sl@0
|
1352 |
//assert(aOrderAttribute);
|
sl@0
|
1353 |
|
sl@0
|
1354 |
// Get number of token types
|
sl@0
|
1355 |
TInt tokenTypesCount = aSearchTokenTypes.Count();
|
sl@0
|
1356 |
|
sl@0
|
1357 |
// loop through token types
|
sl@0
|
1358 |
for(TInt tokenTypesLoop = tokenTypesCount-1; tokenTypesLoop >= 0; tokenTypesLoop--)
|
sl@0
|
1359 |
{
|
sl@0
|
1360 |
// get the list of attributes supported by this token type.
|
sl@0
|
1361 |
// Note: The attribute list consists of values such as
|
sl@0
|
1362 |
// KCTSoftware defined in TCTTokenTypeAttribute.h
|
sl@0
|
1363 |
const RArray<TCTTokenTypeAttribute>& attributesList =
|
sl@0
|
1364 |
aSearchTokenTypes[tokenTypesLoop]->Attributes();
|
sl@0
|
1365 |
|
sl@0
|
1366 |
// Get the number of attributes in the attribute list.
|
sl@0
|
1367 |
// The number of attributes will match the ECOM resource
|
sl@0
|
1368 |
// file definition. E.g. see 101f5015.rss for the software
|
sl@0
|
1369 |
// implementation of certstore.
|
sl@0
|
1370 |
TInt attributeCount = attributesList.Count();
|
sl@0
|
1371 |
|
sl@0
|
1372 |
// Check each attribute in the attribute list
|
sl@0
|
1373 |
for(TInt attribLoop = 0; attribLoop < attributeCount; attribLoop++)
|
sl@0
|
1374 |
{
|
sl@0
|
1375 |
// Check whether attribute in the list matches an order attribute
|
sl@0
|
1376 |
// E.g. KCTSoftware
|
sl@0
|
1377 |
if(attributesList[attribLoop].iUID == KCTSoftware
|
sl@0
|
1378 |
&& attributesList[attribLoop].iVal == aOrderAttribute)
|
sl@0
|
1379 |
{
|
sl@0
|
1380 |
// Found the attribute of interest. Add token type to the temp container.
|
sl@0
|
1381 |
User::LeaveIfError(aTempTokenTypes.Append(aSearchTokenTypes[tokenTypesLoop]));
|
sl@0
|
1382 |
// Remove from the Searchlist.
|
sl@0
|
1383 |
aSearchTokenTypes.Remove(tokenTypesLoop);
|
sl@0
|
1384 |
// No need to examine the other attributes, so break loop
|
sl@0
|
1385 |
break;
|
sl@0
|
1386 |
}
|
sl@0
|
1387 |
}
|
sl@0
|
1388 |
}
|
sl@0
|
1389 |
}
|
sl@0
|
1390 |
|
sl@0
|
1391 |
void CUnifiedCertStore::ApplyOrderingL(RCPointerArray<CCTTokenTypeInfo>& aTokenTypes)
|
sl@0
|
1392 |
{
|
sl@0
|
1393 |
// Number of attributes in ordering filter
|
sl@0
|
1394 |
TInt numOrderAttributes=iOrderAttributes.Count();
|
sl@0
|
1395 |
assert(numOrderAttributes>0);
|
sl@0
|
1396 |
|
sl@0
|
1397 |
// Contains writable tokens types
|
sl@0
|
1398 |
RCPointerArray<CCTTokenTypeInfo> tempWritableTokenTypes;
|
sl@0
|
1399 |
CleanupClosePushL(tempWritableTokenTypes);
|
sl@0
|
1400 |
|
sl@0
|
1401 |
// Contains read-only tokens types
|
sl@0
|
1402 |
RCPointerArray<CCTTokenTypeInfo> tempReadOnlyTokenTypes;
|
sl@0
|
1403 |
CleanupClosePushL(tempReadOnlyTokenTypes);
|
sl@0
|
1404 |
|
sl@0
|
1405 |
// For each order attribute, order the token types
|
sl@0
|
1406 |
for(TInt attributeLoop = 0; attributeLoop < numOrderAttributes; attributeLoop++)
|
sl@0
|
1407 |
{
|
sl@0
|
1408 |
// Get ordering attribute Uid from Order filter
|
sl@0
|
1409 |
TInt orderAttribute = iOrderAttributes[attributeLoop];
|
sl@0
|
1410 |
|
sl@0
|
1411 |
// Order for writable token types
|
sl@0
|
1412 |
FilterTokenTypesL(iWorkingVars->iWritableTokenTypes,
|
sl@0
|
1413 |
tempWritableTokenTypes,
|
sl@0
|
1414 |
orderAttribute);
|
sl@0
|
1415 |
|
sl@0
|
1416 |
// Order for read-only token types
|
sl@0
|
1417 |
FilterTokenTypesL(aTokenTypes,
|
sl@0
|
1418 |
tempReadOnlyTokenTypes,
|
sl@0
|
1419 |
orderAttribute);
|
sl@0
|
1420 |
}
|
sl@0
|
1421 |
|
sl@0
|
1422 |
// release and close the resources so can refill container, and get rid of
|
sl@0
|
1423 |
// the TokenType which have been filtered out.
|
sl@0
|
1424 |
TInt tokenTypesCount = iWorkingVars->iWritableTokenTypes.Count();
|
sl@0
|
1425 |
TInt i;
|
sl@0
|
1426 |
for(i = tokenTypesCount-1; i >= 0 ;i--)
|
sl@0
|
1427 |
{
|
sl@0
|
1428 |
if (iWorkingVars->iWritableTokenTypes[i])
|
sl@0
|
1429 |
{
|
sl@0
|
1430 |
CCTTokenTypeInfo* ptr=iWorkingVars->iWritableTokenTypes[i];
|
sl@0
|
1431 |
iWorkingVars->iWritableTokenTypes.Remove(i);
|
sl@0
|
1432 |
delete ptr;
|
sl@0
|
1433 |
}
|
sl@0
|
1434 |
}
|
sl@0
|
1435 |
iWorkingVars->iWritableTokenTypes.Reset();
|
sl@0
|
1436 |
|
sl@0
|
1437 |
// release and close the resources so can refill container, and get rid of
|
sl@0
|
1438 |
// the TokenType which have been filtered out.
|
sl@0
|
1439 |
tokenTypesCount = aTokenTypes.Count();
|
sl@0
|
1440 |
for(i = tokenTypesCount-1; i >= 0 ;i--)
|
sl@0
|
1441 |
{
|
sl@0
|
1442 |
if (aTokenTypes[i])
|
sl@0
|
1443 |
{
|
sl@0
|
1444 |
CCTTokenTypeInfo* ptr=aTokenTypes[i];
|
sl@0
|
1445 |
aTokenTypes.Remove(i);
|
sl@0
|
1446 |
delete ptr;
|
sl@0
|
1447 |
}
|
sl@0
|
1448 |
}
|
sl@0
|
1449 |
aTokenTypes.Reset();
|
sl@0
|
1450 |
|
sl@0
|
1451 |
// Assign contents of temp token types to containers.
|
sl@0
|
1452 |
// Note: temp tokens types are ordered according to user specification
|
sl@0
|
1453 |
tokenTypesCount = tempWritableTokenTypes.Count();
|
sl@0
|
1454 |
for(i = 0; i < tokenTypesCount; i++)
|
sl@0
|
1455 |
{
|
sl@0
|
1456 |
User::LeaveIfError(iWorkingVars->iWritableTokenTypes.Append(tempWritableTokenTypes[i]));
|
sl@0
|
1457 |
tempWritableTokenTypes[i] = NULL;
|
sl@0
|
1458 |
}
|
sl@0
|
1459 |
|
sl@0
|
1460 |
tokenTypesCount = tempReadOnlyTokenTypes.Count();
|
sl@0
|
1461 |
for(i = 0; i < tokenTypesCount; i++)
|
sl@0
|
1462 |
{
|
sl@0
|
1463 |
User::LeaveIfError(aTokenTypes.Append(tempReadOnlyTokenTypes[i]));
|
sl@0
|
1464 |
tempReadOnlyTokenTypes[i] = NULL;
|
sl@0
|
1465 |
}
|
sl@0
|
1466 |
|
sl@0
|
1467 |
CleanupStack::PopAndDestroy(2); // tempReadOnlyTokenTypes, tempWritableTokenTypes,
|
sl@0
|
1468 |
}
|
sl@0
|
1469 |
|