sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2005-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 "CSWICertStoreImpl.h"
|
sl@0
|
20 |
#include "CSWICertStoreEntryList.h"
|
sl@0
|
21 |
#include "CSWICertStoreEntry.h"
|
sl@0
|
22 |
#include "CSWICertStoreTokenType.h"
|
sl@0
|
23 |
#include "CSWICertStoreToken.h"
|
sl@0
|
24 |
#include "unifiedcertstore.h"
|
sl@0
|
25 |
#include "log.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
#include <certstorepatchdata.h>
|
sl@0
|
28 |
#include <ccertattributefilter.h>
|
sl@0
|
29 |
#include <f32file.h>
|
sl@0
|
30 |
#include <u32hal.h>
|
sl@0
|
31 |
#include <e32svr.h>
|
sl@0
|
32 |
|
sl@0
|
33 |
_LIT(KSWICertStoreZFilename,"z:\\resource\\swicertstore.dat");
|
sl@0
|
34 |
_LIT(KSWIWritableCertStorePath,"!:\\resource\\swicertstore\\dat\\");
|
sl@0
|
35 |
_LIT(KSWIROMCertStoreFilenamePattern,"z:\\resource\\swicertstore*.dat");
|
sl@0
|
36 |
|
sl@0
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
38 |
//CFSCertStoreServer
|
sl@0
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
40 |
|
sl@0
|
41 |
CSWICertStoreImpl* CSWICertStoreImpl::NewL(MCTToken& aToken, RFs& aFs)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
CSWICertStoreImpl* self = new (ELeave) CSWICertStoreImpl(aToken, aFs);
|
sl@0
|
44 |
CleanupStack::PushL(self);
|
sl@0
|
45 |
self->ConstructL();
|
sl@0
|
46 |
CleanupStack::Pop(self);
|
sl@0
|
47 |
return self;
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
CSWICertStoreImpl::CSWICertStoreImpl(MCTToken& aToken, RFs& aFs) :
|
sl@0
|
51 |
CActive(EPriorityStandard), iToken(aToken), iFs(aFs)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
CActiveScheduler::Add(this);
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
void CSWICertStoreImpl::ConstructL()
|
sl@0
|
57 |
{
|
sl@0
|
58 |
TInt err = iSwicertstoreProperty.Attach(KUnifiedCertStorePropertyCat,
|
sl@0
|
59 |
EUnifiedCertStoreFlag, EOwnerThread);
|
sl@0
|
60 |
|
sl@0
|
61 |
User::LeaveIfError(err);
|
sl@0
|
62 |
|
sl@0
|
63 |
iPatchableConst = KAggregateCertStore;
|
sl@0
|
64 |
|
sl@0
|
65 |
#ifdef __WINS__
|
sl@0
|
66 |
// For the emulator allow the constant to be patched via epoc.ini
|
sl@0
|
67 |
UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalIntProperty,
|
sl@0
|
68 |
(TAny*)"KAggregateCertStore", &iPatchableConst); // read emulator property (if present)
|
sl@0
|
69 |
#endif
|
sl@0
|
70 |
|
sl@0
|
71 |
|
sl@0
|
72 |
// if patchable constant is enabled
|
sl@0
|
73 |
if(iPatchableConst)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
// Setup composite ROM Certstore
|
sl@0
|
76 |
SetupCompositeROMCertStoreL();
|
sl@0
|
77 |
}
|
sl@0
|
78 |
else
|
sl@0
|
79 |
{
|
sl@0
|
80 |
// Setup the ROM CertStore
|
sl@0
|
81 |
SetupROMCertStoreL();
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
// Setup the Writable CertStore
|
sl@0
|
85 |
// Bear in mind we need to trap NewL(), OpenLC() etc.
|
sl@0
|
86 |
// Any error occurs, it should still setup the z:\ certstore
|
sl@0
|
87 |
TRAP_IGNORE(SetupWritableCertStoreL());
|
sl@0
|
88 |
|
sl@0
|
89 |
// aggregate ROM composite certstore and writable certstore if patchable constant is enabled
|
sl@0
|
90 |
if(iPatchableConst)
|
sl@0
|
91 |
{
|
sl@0
|
92 |
if(iCEntryList)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
// ETrue to indicate that we are passing 'iZEntryList'.
|
sl@0
|
95 |
// This action will remove duplicate entries from 'iZEntryList'.
|
sl@0
|
96 |
MergeCertificateEntryListsL(*iZEntryList, ETrue);
|
sl@0
|
97 |
}
|
sl@0
|
98 |
}
|
sl@0
|
99 |
// Subscribe to the Property
|
sl@0
|
100 |
iSwicertstoreProperty.Subscribe(iStatus);
|
sl@0
|
101 |
SetActive();
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
void CSWICertStoreImpl::DoCancel()
|
sl@0
|
105 |
{
|
sl@0
|
106 |
// Cancel outstanding request
|
sl@0
|
107 |
iSwicertstoreProperty.Cancel();
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
void CSWICertStoreImpl::RunL()
|
sl@0
|
111 |
{
|
sl@0
|
112 |
// Resubscribe before processing new value to prevent missing updates
|
sl@0
|
113 |
iSwicertstoreProperty.Subscribe(iStatus);
|
sl@0
|
114 |
SetActive();
|
sl@0
|
115 |
|
sl@0
|
116 |
// Bear in mind we need to trap NewL(), OpenLC() etc.
|
sl@0
|
117 |
TRAP_IGNORE(SetupWritableCertStoreL());
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
void CSWICertStoreImpl::SetupWritableCertStoreL()
|
sl@0
|
121 |
{
|
sl@0
|
122 |
TInt err = KErrNone;
|
sl@0
|
123 |
|
sl@0
|
124 |
delete iCEntryList;
|
sl@0
|
125 |
iCEntryList = NULL;
|
sl@0
|
126 |
|
sl@0
|
127 |
// The attached file will be freed as well.
|
sl@0
|
128 |
delete iCStore;
|
sl@0
|
129 |
iCStore = NULL;
|
sl@0
|
130 |
|
sl@0
|
131 |
do
|
sl@0
|
132 |
{
|
sl@0
|
133 |
// Open the store if it is there
|
sl@0
|
134 |
RFile file;
|
sl@0
|
135 |
CDir* entryList = NULL;
|
sl@0
|
136 |
|
sl@0
|
137 |
TPath writableSwiCertStorePath(KSWIWritableCertStorePath);
|
sl@0
|
138 |
|
sl@0
|
139 |
TChar systemDriveChar = RFs::GetSystemDriveChar();
|
sl@0
|
140 |
|
sl@0
|
141 |
writableSwiCertStorePath[0] = systemDriveChar;
|
sl@0
|
142 |
|
sl@0
|
143 |
if (KErrNone == iFs.GetDir (writableSwiCertStorePath, KEntryAttNormal,
|
sl@0
|
144 |
ESortByName|EDirsFirst, entryList))
|
sl@0
|
145 |
{
|
sl@0
|
146 |
if (entryList)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
CleanupStack::PushL(entryList);
|
sl@0
|
149 |
|
sl@0
|
150 |
TFileName certstoreFile;
|
sl@0
|
151 |
TInt count = entryList->Count();
|
sl@0
|
152 |
|
sl@0
|
153 |
if (count > 0)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
// Get the highest version certstore file
|
sl@0
|
156 |
const TEntry& entry = (*entryList)[count - 1];
|
sl@0
|
157 |
|
sl@0
|
158 |
certstoreFile.Append(writableSwiCertStorePath);
|
sl@0
|
159 |
certstoreFile.Append(entry.iName);
|
sl@0
|
160 |
|
sl@0
|
161 |
CleanupStack::PopAndDestroy(1, entryList);
|
sl@0
|
162 |
}
|
sl@0
|
163 |
else
|
sl@0
|
164 |
{
|
sl@0
|
165 |
CleanupStack::PopAndDestroy(1, entryList);
|
sl@0
|
166 |
|
sl@0
|
167 |
// No certstore in this directory
|
sl@0
|
168 |
// Currently there should not have any directory in this path
|
sl@0
|
169 |
return;
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
err = file.Open(iFs, certstoreFile, EFileShareReadersOnly);
|
sl@0
|
173 |
|
sl@0
|
174 |
if (err != KErrNone && err != KErrNotFound)
|
sl@0
|
175 |
{
|
sl@0
|
176 |
// Log the error to the system file.
|
sl@0
|
177 |
DEBUG_PRINTF2(_L8("Error Opening SWI writable certstore: %S."), &certstoreFile);
|
sl@0
|
178 |
return;
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
if (err == KErrNone)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
// File exist
|
sl@0
|
184 |
CleanupClosePushL(file);
|
sl@0
|
185 |
|
sl@0
|
186 |
TRAP_IGNORE(iCStore = CPermanentFileStore::FromL(file));
|
sl@0
|
187 |
|
sl@0
|
188 |
if (iCStore)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
CleanupStack::Pop(&file); // now owned by store
|
sl@0
|
191 |
|
sl@0
|
192 |
// Read id of cert list stream
|
sl@0
|
193 |
TStreamId streamId;
|
sl@0
|
194 |
RStoreReadStream stream;
|
sl@0
|
195 |
stream.OpenLC(*iCStore, iCStore->Root());
|
sl@0
|
196 |
stream >> streamId;
|
sl@0
|
197 |
CleanupStack::PopAndDestroy(&stream);
|
sl@0
|
198 |
|
sl@0
|
199 |
// Read the certificate list
|
sl@0
|
200 |
RStoreReadStream entryStream;
|
sl@0
|
201 |
entryStream.OpenLC(*iCStore, streamId);
|
sl@0
|
202 |
iCEntryList = CSWICertStoreEntryList::NewL(entryStream, iToken, iCertIndex);
|
sl@0
|
203 |
|
sl@0
|
204 |
CleanupStack::PopAndDestroy(&entryStream);
|
sl@0
|
205 |
|
sl@0
|
206 |
// Record the writable certstore index
|
sl@0
|
207 |
// The index will then be used to set the tokenId in the
|
sl@0
|
208 |
// in handle, so to make the handle unique.
|
sl@0
|
209 |
iCertIndex += iCEntryList->Count();
|
sl@0
|
210 |
}
|
sl@0
|
211 |
else
|
sl@0
|
212 |
{
|
sl@0
|
213 |
// The file format might not comply to the CPermanentFileStore format
|
sl@0
|
214 |
CleanupStack::PopAndDestroy(&file);
|
sl@0
|
215 |
|
sl@0
|
216 |
// Log the error to the system file.
|
sl@0
|
217 |
DEBUG_PRINTF2(_L8("Error Opening SWI writable certstore: %S."), &certstoreFile);
|
sl@0
|
218 |
|
sl@0
|
219 |
return;
|
sl@0
|
220 |
}
|
sl@0
|
221 |
}
|
sl@0
|
222 |
}
|
sl@0
|
223 |
}
|
sl@0
|
224 |
}while (err == KErrNotFound); // There is a very slight chance that the file has been deleted
|
sl@0
|
225 |
}
|
sl@0
|
226 |
|
sl@0
|
227 |
void CSWICertStoreImpl::MergeCertificateEntryListsL(const CSWICertStoreEntryList& aSourceList, TBool aIsZEntryList)
|
sl@0
|
228 |
{
|
sl@0
|
229 |
ASSERT(iPatchableConst);
|
sl@0
|
230 |
// if patchable constant is enabled
|
sl@0
|
231 |
|
sl@0
|
232 |
TInt sourceCount = aSourceList.Count();
|
sl@0
|
233 |
for(TInt i = 0; i < sourceCount; i++)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
if(!aIsZEntryList)
|
sl@0
|
236 |
{
|
sl@0
|
237 |
if (!iZEntryList->LabelExists(aSourceList.GetByIndex(i).CertInfo().Label()))
|
sl@0
|
238 |
{
|
sl@0
|
239 |
// Aggregation: Append this entry in the ROM composite list
|
sl@0
|
240 |
const CSWICertStoreEntry& entry = aSourceList.GetByIndex(i);
|
sl@0
|
241 |
CSWICertStoreEntry* newEntry = CSWICertStoreEntry::NewL(entry.CertInfo(),
|
sl@0
|
242 |
entry.CertificateApps(),
|
sl@0
|
243 |
entry.Trusted(),
|
sl@0
|
244 |
entry.DataStreamId(),
|
sl@0
|
245 |
entry.CertMetaInfo(),
|
sl@0
|
246 |
entry.StoreIndex());
|
sl@0
|
247 |
CleanupStack::PushL(newEntry);
|
sl@0
|
248 |
iZEntryList->AppendL(newEntry);
|
sl@0
|
249 |
// iZEntryList has taken ownership
|
sl@0
|
250 |
CleanupStack::Pop(newEntry);
|
sl@0
|
251 |
}
|
sl@0
|
252 |
// Eclipsing: Higher order store certificates with same labels take precedence over lower order store certificates.
|
sl@0
|
253 |
// therefore the later are not included in the composite certificate entry list.
|
sl@0
|
254 |
// N.B iCertIndex will not give total count of certificates because of Eclipsing mechanism.
|
sl@0
|
255 |
// Higher order store certificates are ones which are aggregated prior to other certificates.
|
sl@0
|
256 |
}
|
sl@0
|
257 |
else
|
sl@0
|
258 |
{
|
sl@0
|
259 |
// remove duplicate label entries from the 'iZEntryList'
|
sl@0
|
260 |
if (iCEntryList->LabelExists(aSourceList.GetByIndex(i).CertInfo().Label()))
|
sl@0
|
261 |
{
|
sl@0
|
262 |
// Remove entries from iZEntryList having same labels as in iCEntryList.
|
sl@0
|
263 |
iZEntryList->Remove(i);
|
sl@0
|
264 |
}
|
sl@0
|
265 |
}
|
sl@0
|
266 |
}
|
sl@0
|
267 |
}
|
sl@0
|
268 |
|
sl@0
|
269 |
void CSWICertStoreImpl::SetupCompositeROMCertStoreL()
|
sl@0
|
270 |
{
|
sl@0
|
271 |
ASSERT(iPatchableConst);
|
sl@0
|
272 |
|
sl@0
|
273 |
// Collect the file present in ROM certstore private directory.
|
sl@0
|
274 |
//The files in this list will be in descending order by name.
|
sl@0
|
275 |
CDir* filenameList = NULL;
|
sl@0
|
276 |
|
sl@0
|
277 |
User::LeaveIfError(iFs.GetDir(KSWIROMCertStoreFilenamePattern, KEntryAttNormal, ESortByName|EDescending, filenameList));
|
sl@0
|
278 |
CleanupStack::PushL(filenameList);
|
sl@0
|
279 |
TInt count = filenameList->Count();
|
sl@0
|
280 |
TStreamId streamId;
|
sl@0
|
281 |
|
sl@0
|
282 |
// make full path to the certstore files residing on ROM drive
|
sl@0
|
283 |
// N.B filenameList will contain filenames in descending order.
|
sl@0
|
284 |
RFile file;
|
sl@0
|
285 |
RStoreReadStream stream;
|
sl@0
|
286 |
|
sl@0
|
287 |
// create an empty list, this will be the composite certificate entry list
|
sl@0
|
288 |
iZEntryList = CSWICertStoreEntryList::NewL();
|
sl@0
|
289 |
// the 'corruptCount' is used for proper correctly referencing valid certstores
|
sl@0
|
290 |
TInt corruptCount=0;
|
sl@0
|
291 |
for(TInt i = 0; i < count; i++)
|
sl@0
|
292 |
{
|
sl@0
|
293 |
RBuf romFile;
|
sl@0
|
294 |
romFile.CreateL(KMaxFileName);
|
sl@0
|
295 |
CleanupClosePushL(romFile);
|
sl@0
|
296 |
romFile.Append(_L("z:\\resource\\"));
|
sl@0
|
297 |
romFile.Append(((*filenameList)[i]).iName);
|
sl@0
|
298 |
User::LeaveIfError(file.Open(iFs,romFile,EFileShareReadersOnly));
|
sl@0
|
299 |
CleanupClosePushL(file);
|
sl@0
|
300 |
// open and append the store in array of stores
|
sl@0
|
301 |
CPermanentFileStore* store = NULL;
|
sl@0
|
302 |
// if there is any corrupt certstore present then we will simply ignore its
|
sl@0
|
303 |
// aggregation and proceed with aggregating remaining stores.
|
sl@0
|
304 |
// ownership is transfered to 'iZArrayOfStores'
|
sl@0
|
305 |
TRAPD(err, store = CPermanentFileStore::FromL(file));
|
sl@0
|
306 |
if(err != KErrNone)
|
sl@0
|
307 |
{
|
sl@0
|
308 |
corruptCount++;
|
sl@0
|
309 |
//cleanup file and romFile.
|
sl@0
|
310 |
CleanupStack::PopAndDestroy(2, &romFile);
|
sl@0
|
311 |
continue;
|
sl@0
|
312 |
}
|
sl@0
|
313 |
iZArrayOfStores.AppendL(store);
|
sl@0
|
314 |
TInt index = i - corruptCount;
|
sl@0
|
315 |
// open the root stream containing the streamId of info stream.
|
sl@0
|
316 |
stream.OpenLC(*(iZArrayOfStores)[index],(iZArrayOfStores[index])->Root());
|
sl@0
|
317 |
stream >> streamId;
|
sl@0
|
318 |
CleanupStack::PopAndDestroy(&stream);
|
sl@0
|
319 |
|
sl@0
|
320 |
// re-open the info stream containing the certificates entry list.
|
sl@0
|
321 |
stream.OpenLC(*(iZArrayOfStores)[index],streamId);
|
sl@0
|
322 |
|
sl@0
|
323 |
// store index for these entries will be 'index'.
|
sl@0
|
324 |
// iCertIndex will be 0 for the first certificate entry list passed.
|
sl@0
|
325 |
CSWICertStoreEntryList* temp_list = CSWICertStoreEntryList::NewL(stream, iToken,iCertIndex,index);
|
sl@0
|
326 |
// increment to have unique certificate Ids allocation.
|
sl@0
|
327 |
iCertIndex += temp_list->Count();
|
sl@0
|
328 |
CleanupStack::PushL(temp_list);
|
sl@0
|
329 |
MergeCertificateEntryListsL(*temp_list);
|
sl@0
|
330 |
//temp_list, stream, file and romFile.
|
sl@0
|
331 |
CleanupStack::PopAndDestroy(4, &romFile);
|
sl@0
|
332 |
}
|
sl@0
|
333 |
CleanupStack::PopAndDestroy(filenameList);
|
sl@0
|
334 |
}
|
sl@0
|
335 |
|
sl@0
|
336 |
void CSWICertStoreImpl::SetupROMCertStoreL()
|
sl@0
|
337 |
{
|
sl@0
|
338 |
// Open the store
|
sl@0
|
339 |
RFile file;
|
sl@0
|
340 |
User::LeaveIfError(file.Open(iFs, KSWICertStoreZFilename, EFileShareReadersOnly));
|
sl@0
|
341 |
CleanupClosePushL(file);
|
sl@0
|
342 |
iZStore = CPermanentFileStore::FromL(file);
|
sl@0
|
343 |
CleanupStack::Pop(&file); // now owned by store
|
sl@0
|
344 |
|
sl@0
|
345 |
// Read id of cert list stream
|
sl@0
|
346 |
TStreamId streamId;
|
sl@0
|
347 |
RStoreReadStream stream;
|
sl@0
|
348 |
stream.OpenLC(*iZStore, iZStore->Root());
|
sl@0
|
349 |
stream >> streamId;
|
sl@0
|
350 |
CleanupStack::PopAndDestroy(&stream);
|
sl@0
|
351 |
|
sl@0
|
352 |
// Read the certificate list
|
sl@0
|
353 |
RStoreReadStream entryStream;
|
sl@0
|
354 |
entryStream.OpenLC(*iZStore, streamId);
|
sl@0
|
355 |
iZEntryList = CSWICertStoreEntryList::NewL(entryStream, iToken);
|
sl@0
|
356 |
CleanupStack::PopAndDestroy(&entryStream);
|
sl@0
|
357 |
|
sl@0
|
358 |
// set the valid indexes of writable certstore
|
sl@0
|
359 |
iCertIndex = iZEntryList->Count();
|
sl@0
|
360 |
}
|
sl@0
|
361 |
|
sl@0
|
362 |
CSWICertStoreImpl::~CSWICertStoreImpl()
|
sl@0
|
363 |
{
|
sl@0
|
364 |
Cancel();
|
sl@0
|
365 |
iSwicertstoreProperty.Close();
|
sl@0
|
366 |
delete iCEntryList;
|
sl@0
|
367 |
delete iZEntryList;
|
sl@0
|
368 |
delete iCStore;
|
sl@0
|
369 |
delete iZStore;
|
sl@0
|
370 |
iZArrayOfStores.ResetAndDestroy();
|
sl@0
|
371 |
}
|
sl@0
|
372 |
|
sl@0
|
373 |
void CSWICertStoreImpl::ListL(RMPointerArray<CCTCertInfo>& aCerts,
|
sl@0
|
374 |
const CCertAttributeFilter& aFilter)
|
sl@0
|
375 |
{
|
sl@0
|
376 |
if (iCEntryList)
|
sl@0
|
377 |
{
|
sl@0
|
378 |
FilterCertificateListL(aCerts, aFilter, *iCEntryList);
|
sl@0
|
379 |
}
|
sl@0
|
380 |
FilterCertificateListL(aCerts, aFilter, *iZEntryList);
|
sl@0
|
381 |
}
|
sl@0
|
382 |
|
sl@0
|
383 |
CCTCertInfo* CSWICertStoreImpl::GetCertL(const TCTTokenObjectHandle& aHandle)
|
sl@0
|
384 |
{
|
sl@0
|
385 |
TBool isCEntryHandle = EFalse;
|
sl@0
|
386 |
const CSWICertStoreEntry* entry = GetCSWICertStoreEntryL(aHandle, isCEntryHandle);
|
sl@0
|
387 |
return CCTCertInfo::NewL(entry->CertInfo());
|
sl@0
|
388 |
}
|
sl@0
|
389 |
|
sl@0
|
390 |
void CSWICertStoreImpl::ApplicationsL(const TCTTokenObjectHandle& aHandle, RArray<TUid>& aApplications)
|
sl@0
|
391 |
{
|
sl@0
|
392 |
TBool isCEntryHandle = EFalse;
|
sl@0
|
393 |
const CSWICertStoreEntry* entry = GetCSWICertStoreEntryL(aHandle, isCEntryHandle);
|
sl@0
|
394 |
|
sl@0
|
395 |
const RArray<TUid>& apps = entry->CertificateApps();
|
sl@0
|
396 |
TInt count = apps.Count();
|
sl@0
|
397 |
|
sl@0
|
398 |
for (TInt i = 0 ; i < count ; ++i)
|
sl@0
|
399 |
{
|
sl@0
|
400 |
User::LeaveIfError(aApplications.Append(apps[i]));
|
sl@0
|
401 |
}
|
sl@0
|
402 |
}
|
sl@0
|
403 |
|
sl@0
|
404 |
TBool CSWICertStoreImpl::IsApplicableL(const TCTTokenObjectHandle& aHandle, TUid aApplication)
|
sl@0
|
405 |
{
|
sl@0
|
406 |
TBool isCEntryHandle = EFalse;
|
sl@0
|
407 |
const CSWICertStoreEntry* entry = GetCSWICertStoreEntryL(aHandle, isCEntryHandle);
|
sl@0
|
408 |
return entry->IsApplicable(aApplication);
|
sl@0
|
409 |
}
|
sl@0
|
410 |
|
sl@0
|
411 |
TBool CSWICertStoreImpl::TrustedL(const TCTTokenObjectHandle& aHandle)
|
sl@0
|
412 |
{
|
sl@0
|
413 |
TBool isCEntryHandle = EFalse;
|
sl@0
|
414 |
const CSWICertStoreEntry* entry = GetCSWICertStoreEntryL(aHandle, isCEntryHandle);
|
sl@0
|
415 |
return entry->Trusted();
|
sl@0
|
416 |
}
|
sl@0
|
417 |
|
sl@0
|
418 |
void CSWICertStoreImpl::RetrieveL(const TCTTokenObjectHandle& aHandle, TDes8& aEncodedCert)
|
sl@0
|
419 |
{
|
sl@0
|
420 |
TBool isCEntryHandle = EFalse;
|
sl@0
|
421 |
const CSWICertStoreEntry* entry = GetCSWICertStoreEntryL(aHandle, isCEntryHandle);
|
sl@0
|
422 |
RStoreReadStream stream;
|
sl@0
|
423 |
|
sl@0
|
424 |
if (iCEntryList && isCEntryHandle)
|
sl@0
|
425 |
{
|
sl@0
|
426 |
stream.OpenLC(*iCStore, entry->DataStreamId());
|
sl@0
|
427 |
}
|
sl@0
|
428 |
else
|
sl@0
|
429 |
{
|
sl@0
|
430 |
// if patchable constant is enabled
|
sl@0
|
431 |
if (iPatchableConst)
|
sl@0
|
432 |
{
|
sl@0
|
433 |
stream.OpenLC(*(iZArrayOfStores[entry->StoreIndex()]), entry->DataStreamId());
|
sl@0
|
434 |
}
|
sl@0
|
435 |
else
|
sl@0
|
436 |
{
|
sl@0
|
437 |
stream.OpenLC(*iZStore, entry->DataStreamId());
|
sl@0
|
438 |
}
|
sl@0
|
439 |
}
|
sl@0
|
440 |
|
sl@0
|
441 |
TInt size = entry->CertInfo().Size();
|
sl@0
|
442 |
|
sl@0
|
443 |
if (aEncodedCert.MaxLength() < size)
|
sl@0
|
444 |
{
|
sl@0
|
445 |
User::Leave(KErrOverflow);
|
sl@0
|
446 |
}
|
sl@0
|
447 |
|
sl@0
|
448 |
stream.ReadL(aEncodedCert, size);
|
sl@0
|
449 |
CleanupStack::PopAndDestroy(&stream);
|
sl@0
|
450 |
}
|
sl@0
|
451 |
|
sl@0
|
452 |
const TCertMetaInfo& CSWICertStoreImpl::CertMetaInfoL(const TCTTokenObjectHandle& aHandle) const
|
sl@0
|
453 |
{
|
sl@0
|
454 |
TBool isCEntryHandle = EFalse;
|
sl@0
|
455 |
const CSWICertStoreEntry* entry = GetCSWICertStoreEntryL(aHandle, isCEntryHandle);
|
sl@0
|
456 |
return entry->CertMetaInfo();
|
sl@0
|
457 |
}
|
sl@0
|
458 |
|
sl@0
|
459 |
const CSWICertStoreEntry* CSWICertStoreImpl::GetCSWICertStoreEntryL(const TCTTokenObjectHandle& aHandle, TBool& aCEntryHandle) const
|
sl@0
|
460 |
{
|
sl@0
|
461 |
if (iCEntryList)
|
sl@0
|
462 |
{
|
sl@0
|
463 |
const CSWICertStoreEntry* entry = NULL;
|
sl@0
|
464 |
|
sl@0
|
465 |
TRAPD (retCode, entry = &(iCEntryList->GetByHandleL(aHandle)));
|
sl@0
|
466 |
|
sl@0
|
467 |
if (entry && (retCode == KErrNone))
|
sl@0
|
468 |
{
|
sl@0
|
469 |
aCEntryHandle = ETrue;
|
sl@0
|
470 |
return entry;
|
sl@0
|
471 |
}
|
sl@0
|
472 |
}
|
sl@0
|
473 |
return &iZEntryList->GetByHandleL(aHandle);
|
sl@0
|
474 |
}
|
sl@0
|
475 |
|
sl@0
|
476 |
void CSWICertStoreImpl::AddIfMatchesFilterL(RMPointerArray<CCTCertInfo>& aCerts, const CCertAttributeFilter& aFilter, const CSWICertStoreEntry& aEntry)
|
sl@0
|
477 |
{
|
sl@0
|
478 |
const CCTCertInfo& certInfo = aEntry.CertInfo();
|
sl@0
|
479 |
TBool accept = ETrue;
|
sl@0
|
480 |
|
sl@0
|
481 |
if (aFilter.iUidIsSet)
|
sl@0
|
482 |
{
|
sl@0
|
483 |
accept = aEntry.IsApplicable(aFilter.iUid);
|
sl@0
|
484 |
}
|
sl@0
|
485 |
if (aFilter.iFormatIsSet && accept)
|
sl@0
|
486 |
{
|
sl@0
|
487 |
accept = (aFilter.iFormat == certInfo.CertificateFormat());
|
sl@0
|
488 |
}
|
sl@0
|
489 |
if (aFilter.iOwnerTypeIsSet && accept)
|
sl@0
|
490 |
{
|
sl@0
|
491 |
accept = (aFilter.iOwnerType == certInfo.CertificateOwnerType());
|
sl@0
|
492 |
}
|
sl@0
|
493 |
if (aFilter.iSubjectKeyIdIsSet && accept)
|
sl@0
|
494 |
{
|
sl@0
|
495 |
accept = (aFilter.iSubjectKeyId == certInfo.SubjectKeyId());
|
sl@0
|
496 |
}
|
sl@0
|
497 |
if (aFilter.iLabelIsSet && accept)
|
sl@0
|
498 |
{
|
sl@0
|
499 |
accept = (aFilter.iLabel == certInfo.Label());
|
sl@0
|
500 |
}
|
sl@0
|
501 |
|
sl@0
|
502 |
if (accept)
|
sl@0
|
503 |
{
|
sl@0
|
504 |
CCTCertInfo* newCertInfo = CCTCertInfo::NewLC(certInfo);
|
sl@0
|
505 |
User::LeaveIfError(aCerts.Append(newCertInfo));
|
sl@0
|
506 |
CleanupStack::Pop(newCertInfo);
|
sl@0
|
507 |
}
|
sl@0
|
508 |
}
|
sl@0
|
509 |
|
sl@0
|
510 |
void CSWICertStoreImpl::FilterCertificateListL(RMPointerArray<CCTCertInfo>& aCerts,
|
sl@0
|
511 |
const CCertAttributeFilter& aFilter, const CSWICertStoreEntryList& aEntryList)
|
sl@0
|
512 |
{
|
sl@0
|
513 |
TInt count = aEntryList.Count();
|
sl@0
|
514 |
for (TInt index = 0; index < count; index++)
|
sl@0
|
515 |
{
|
sl@0
|
516 |
const CSWICertStoreEntry& entry = aEntryList.GetByIndex(index);
|
sl@0
|
517 |
AddIfMatchesFilterL(aCerts, aFilter, entry);
|
sl@0
|
518 |
}
|
sl@0
|
519 |
}
|
sl@0
|
520 |
|
sl@0
|
521 |
|