|
1 /* |
|
2 * Copyright (c) 2003-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implements a synchronous wrapper for easier use of Symbian's |
|
15 * Security Frameworks's API's. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <unifiedcertstore.h> |
|
22 #include <unifiedkeystore.h> |
|
23 #include <mctwritablecertstore.h> |
|
24 #include <x509cert.h> |
|
25 #include <pkixcertchain.h> |
|
26 #include "CertmanuiSyncWrapper.h" |
|
27 #include "CertmanuiCommon.h" |
|
28 #include "CertManUILogger.h" |
|
29 |
|
30 // CONSTANTS |
|
31 _LIT_SECURITY_POLICY_C1( KKeyStoreUsePolicy, ECapabilityReadUserData ); |
|
32 |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CCertManUISyncWrapper::CCertManUISyncWrapper() |
|
38 // C++ default constructor can NOT contain any code, that |
|
39 // might leave. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CCertManUISyncWrapper::CCertManUISyncWrapper() : CActive( EPriorityStandard ), iCertPtr(0,0) |
|
43 { |
|
44 CActiveScheduler::Add( this ); |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CCertManUISyncWrapper::ConstructL() |
|
49 // Symbian 2nd phase constructor can leave. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 void CCertManUISyncWrapper::ConstructL() |
|
53 { |
|
54 } |
|
55 |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CCertManUISyncWrapper::NewLC |
|
59 // Two-phased constructor. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CCertManUISyncWrapper* CCertManUISyncWrapper::NewLC() |
|
63 { |
|
64 CCertManUISyncWrapper* wrap = new ( ELeave ) CCertManUISyncWrapper(); |
|
65 CleanupStack::PushL( wrap ); |
|
66 wrap->ConstructL(); |
|
67 return wrap; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CCertManUISyncWrapper::NewL |
|
72 // Two-phased constructor. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CCertManUISyncWrapper* CCertManUISyncWrapper::NewL() |
|
76 { |
|
77 CCertManUISyncWrapper* wrap = CCertManUISyncWrapper::NewLC(); |
|
78 CleanupStack::Pop(); |
|
79 return wrap; |
|
80 } |
|
81 |
|
82 // Destructor |
|
83 CCertManUISyncWrapper::~CCertManUISyncWrapper() |
|
84 { |
|
85 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::~CCertManUISyncWrapper()" ); |
|
86 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::~CCertManUISyncWrapper()" ); |
|
87 } |
|
88 |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CCertManUISyncWrapper::DoCancel |
|
92 // Cancels the ongoing operation if possible. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CCertManUISyncWrapper::DoCancel() |
|
96 { |
|
97 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::DoCancel" ); |
|
98 |
|
99 switch ( iOperation ) |
|
100 { |
|
101 case EOperationInit: |
|
102 { |
|
103 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EOperationInit" ); |
|
104 iStore->CancelInitialize(); |
|
105 break; |
|
106 } |
|
107 case EOperationList: |
|
108 { |
|
109 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EOperationList" ); |
|
110 iStore->CancelList(); |
|
111 break; |
|
112 } |
|
113 case EGetCertificate: |
|
114 { |
|
115 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EGetCertificate" ); |
|
116 iStore->CancelRetrieve(); |
|
117 break; |
|
118 } |
|
119 case EAddCertificate: |
|
120 { |
|
121 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EAddCertificate" ); |
|
122 iStore->Cancel(); |
|
123 break; |
|
124 } |
|
125 case ERetriveURLCertificate: |
|
126 { |
|
127 LOG_WRITE(" CCertManUISyncWrapper::DoCancel ERetriveURLCertificate "); |
|
128 iStore->CancelRetrieve(); |
|
129 break; |
|
130 } |
|
131 case EOperationDelete: |
|
132 { |
|
133 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EOperationDelete" ); |
|
134 iStore->CancelRemove(); |
|
135 break; |
|
136 } |
|
137 case EOperationGetApps: |
|
138 { |
|
139 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EOperationGetApps" ); |
|
140 iStore->CancelApplications(); |
|
141 break; |
|
142 } |
|
143 case EOperationValidateX509Root: |
|
144 { |
|
145 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EOperationValidateX509Root" ); |
|
146 iChain->CancelValidate(); |
|
147 break; |
|
148 } |
|
149 case EShowErrorNote: |
|
150 { |
|
151 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EShowErrorNote" ); |
|
152 break; |
|
153 } |
|
154 case EOperationInitKeyStore: |
|
155 { |
|
156 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EOperationInitKeyStore" ); |
|
157 iKeyStore->CancelInitialize(); |
|
158 break; |
|
159 } |
|
160 case EOperationKeyList: |
|
161 { |
|
162 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EOperationKeyList" ); |
|
163 iKeyStore->CancelList(); |
|
164 break; |
|
165 } |
|
166 case EOperationGetInterface: |
|
167 { |
|
168 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EOperationGetInterface" ); |
|
169 iToken->CancelGetInterface(); |
|
170 break; |
|
171 } |
|
172 case EOperationExportKey: |
|
173 { |
|
174 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EOperationExportKey" ); |
|
175 iKeyStore->CancelExportKey(); |
|
176 break; |
|
177 } |
|
178 case EOperationImportKey: |
|
179 { |
|
180 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EOperationImportKey" ); |
|
181 iKeyStore->CancelImportKey(); |
|
182 break; |
|
183 } |
|
184 case EOperationDeleteKey: |
|
185 { |
|
186 LOG_WRITE( "CCertManUISyncWrapper::DoCancel EOperationDeleteKey" ); |
|
187 iKeyStore->CancelDeleteKey(); |
|
188 break; |
|
189 } |
|
190 default: |
|
191 { |
|
192 break; |
|
193 } |
|
194 } |
|
195 |
|
196 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::DoCancel" ); |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CCertManUISyncWrapper::InitStoreL |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 TInt CCertManUISyncWrapper::InitStoreL( CUnifiedCertStore*& aStore ) |
|
204 { |
|
205 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::InitStoreL Certstore" ); |
|
206 |
|
207 aStore->Initialize( iStatus ); |
|
208 iOperation = EOperationInit; |
|
209 iStore = aStore; |
|
210 SetActive(); |
|
211 iWait.Start(); |
|
212 HandleErrorL(); |
|
213 iOperation = EOperationNone; |
|
214 |
|
215 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::InitStoreL Certstore" ); |
|
216 return iStatus.Int(); |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CCertManUISyncWrapper::InitStoreL |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 TInt CCertManUISyncWrapper::InitStoreL( CUnifiedKeyStore*& aStore ) |
|
224 { |
|
225 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::InitStoreL Keystore" ); |
|
226 |
|
227 aStore->Initialize( iStatus ); |
|
228 iOperation = EOperationInitKeyStore; |
|
229 iKeyStore = aStore; |
|
230 SetActive(); |
|
231 iWait.Start(); |
|
232 HandleErrorL(); |
|
233 iOperation = EOperationNone; |
|
234 |
|
235 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::InitStoreL Keystore" ); |
|
236 return iStatus.Int(); |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CCertManUISyncWrapper::ListL |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 TInt CCertManUISyncWrapper::ListL( |
|
244 CUnifiedCertStore*& aStore, |
|
245 RMPointerArray<CCTCertInfo>* aArray, |
|
246 const CCertAttributeFilter& aFilter ) |
|
247 { |
|
248 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::ListL 1" ); |
|
249 |
|
250 if ( IsActive() ) |
|
251 { |
|
252 // Wrapper is active. Don't go further |
|
253 return KErrGeneral; |
|
254 } |
|
255 |
|
256 aStore->List( *aArray, aFilter, iStatus ); |
|
257 iOperation = EOperationList; |
|
258 iStore = aStore; |
|
259 SetActive(); |
|
260 iWait.Start(); |
|
261 HandleErrorL(); |
|
262 iOperation = EOperationNone; |
|
263 |
|
264 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::ListL 1" ); |
|
265 return iStatus.Int(); |
|
266 } |
|
267 |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CCertManUISyncWrapper::ListL |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 TInt CCertManUISyncWrapper::ListL( |
|
274 CUnifiedCertStore*& aStore, |
|
275 RMPointerArray<CCTCertInfo>* aArray, |
|
276 const CCertAttributeFilter& aFilter, |
|
277 const TUid aTokenUid ) |
|
278 { |
|
279 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::ListL 2" ); |
|
280 |
|
281 TInt status( KErrNone ); |
|
282 |
|
283 if ( IsActive() ) |
|
284 { |
|
285 // Wrapper is active. Don't go further |
|
286 return KErrGeneral; |
|
287 } |
|
288 |
|
289 TInt count = aStore->CertStoreCount(); |
|
290 for ( TInt ii = 0; ii < count; ii++ ) |
|
291 { |
|
292 MCTCertStore& certstore = aStore->CertStore( ii ); |
|
293 MCTToken& token = certstore.Token(); |
|
294 TUid tokenuid = token.Handle().iTokenTypeUid; |
|
295 if ( tokenuid == aTokenUid ) |
|
296 { |
|
297 certstore.List( *aArray, aFilter, iStatus ); |
|
298 iOperation = EOperationList; |
|
299 iStore = aStore; |
|
300 SetActive(); |
|
301 iWait.Start(); |
|
302 HandleErrorL(); |
|
303 status = iStatus.Int(); |
|
304 break; |
|
305 } |
|
306 } |
|
307 |
|
308 iOperation = EOperationNone; |
|
309 |
|
310 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::ListL 2" ); |
|
311 return status; |
|
312 } |
|
313 |
|
314 // ----------------------------------------------------------------------------- |
|
315 // CCertManUISyncWrapper::ListL |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 TInt CCertManUISyncWrapper::ListL( |
|
319 CUnifiedKeyStore*& aStore, |
|
320 RMPointerArray<CCTKeyInfo>* aArray, |
|
321 const TCTKeyAttributeFilter& aFilter ) |
|
322 { |
|
323 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::ListL 3" ); |
|
324 |
|
325 if ( IsActive() ) |
|
326 { |
|
327 // Wrapper is active. Don't go further |
|
328 return KErrGeneral; |
|
329 } |
|
330 |
|
331 aStore->List( *aArray, aFilter, iStatus ); |
|
332 iOperation = EOperationKeyList; |
|
333 iKeyStore = aStore; |
|
334 SetActive(); |
|
335 iWait.Start(); |
|
336 HandleErrorL(); |
|
337 |
|
338 iOperation = EOperationNone; |
|
339 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::ListL 3" ); |
|
340 return iStatus.Int(); |
|
341 } |
|
342 |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CCertManUISyncWrapper::ListL |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 TInt CCertManUISyncWrapper::ListL( |
|
349 CUnifiedKeyStore*& aStore, |
|
350 RMPointerArray<CCTKeyInfo>* aArray, |
|
351 const TCTKeyAttributeFilter& aFilter, |
|
352 const TUid aTokenUid ) |
|
353 { |
|
354 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::ListL 4" ); |
|
355 |
|
356 TInt status( KErrNone ); |
|
357 |
|
358 if ( IsActive() ) |
|
359 { |
|
360 // Wrapper is active. Don't go further |
|
361 return KErrGeneral; |
|
362 } |
|
363 |
|
364 TInt count = aStore->KeyStoreManagerCount(); |
|
365 for ( TInt ii = 0; ii < count; ii++ ) |
|
366 { |
|
367 MCTKeyStoreManager& keystoremanager = aStore->KeyStoreManager( ii ); |
|
368 MCTToken& token = keystoremanager.Token(); |
|
369 TUid tokenuid = token.Handle().iTokenTypeUid; |
|
370 if ( tokenuid == aTokenUid ) |
|
371 { |
|
372 keystoremanager.List( *aArray, aFilter, iStatus ); |
|
373 iOperation = EOperationKeyList; |
|
374 iKeyStore = aStore; |
|
375 SetActive(); |
|
376 iWait.Start(); |
|
377 HandleErrorL(); |
|
378 status = iStatus.Int(); |
|
379 break; |
|
380 } |
|
381 } |
|
382 |
|
383 iOperation = EOperationNone; |
|
384 |
|
385 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::ListL 4" ); |
|
386 return status; |
|
387 } |
|
388 |
|
389 // ----------------------------------------------------------------------------- |
|
390 // CCertManUISyncWrapper::GetCertificateL |
|
391 // ----------------------------------------------------------------------------- |
|
392 // |
|
393 TInt CCertManUISyncWrapper::GetCertificateL( |
|
394 CUnifiedCertStore*& aStore, |
|
395 const CCTCertInfo& aCertInfo, |
|
396 CCertificate*& aCert ) |
|
397 { |
|
398 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::GetCertificateL 1" ); |
|
399 |
|
400 aCert = NULL; |
|
401 HBufC8* buf = HBufC8::NewLC( KMaxCertificateLength ); |
|
402 iCertPtr.Set( buf->Des() ); |
|
403 aStore->Retrieve( aCertInfo, iCertPtr, iStatus); |
|
404 iOperation = EGetCertificate; |
|
405 iStore = aStore; |
|
406 SetActive(); |
|
407 iWait.Start(); |
|
408 |
|
409 if ( iStatus.Int() == KErrNone ) |
|
410 { |
|
411 switch ( aCertInfo.CertificateFormat() ) |
|
412 { |
|
413 case EX509Certificate: |
|
414 { |
|
415 aCert = CX509Certificate::NewL( iCertPtr ); |
|
416 break; |
|
417 } |
|
418 case EX509CertificateUrl: |
|
419 { |
|
420 #ifdef _CERTMANUI_LOG_ |
|
421 TPtrC8 dump = buf->Des(); |
|
422 LOG_HEXDUMP(dump); |
|
423 #endif |
|
424 break; |
|
425 } |
|
426 default: |
|
427 { |
|
428 break; |
|
429 } |
|
430 } |
|
431 } |
|
432 |
|
433 CleanupStack::PopAndDestroy(); // buf |
|
434 HandleErrorL(); |
|
435 iOperation = EOperationNone; |
|
436 |
|
437 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::GetCertificateL 1" ); |
|
438 return iStatus.Int(); |
|
439 } |
|
440 |
|
441 // ----------------------------------------------------------------------------- |
|
442 // CCertManUISyncWrapper::GetUrlCertificateL |
|
443 // ----------------------------------------------------------------------------- |
|
444 // |
|
445 TInt CCertManUISyncWrapper::GetUrlCertificateL( |
|
446 CUnifiedCertStore*& aStore, |
|
447 const CCTCertInfo& aCertInfo, |
|
448 TDes8& aUrl ) |
|
449 { |
|
450 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::GetUrlCertificateL" ); |
|
451 |
|
452 aStore->Retrieve( aCertInfo, aUrl, iStatus); |
|
453 iOperation = ERetriveURLCertificate; |
|
454 iStore = aStore; |
|
455 SetActive(); |
|
456 iWait.Start(); |
|
457 HandleErrorL(); |
|
458 iOperation = EOperationNone; |
|
459 |
|
460 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::GetUrlCertificateL" ); |
|
461 return iStatus.Int(); |
|
462 } |
|
463 |
|
464 |
|
465 // ----------------------------------------------------------------------------- |
|
466 // CCertManUISyncWrapper::GetCertificateL |
|
467 // ----------------------------------------------------------------------------- |
|
468 // |
|
469 TInt CCertManUISyncWrapper::GetCertificateL( CUnifiedCertStore*& aStore, |
|
470 const CCTCertInfo& aCertInfo, |
|
471 CCertificate*& aCert, |
|
472 TUid aTokenUid ) |
|
473 { |
|
474 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::GetCertificateL 2 " ); |
|
475 |
|
476 aCert = NULL; |
|
477 TInt status( KErrNone ); |
|
478 |
|
479 HBufC8* buf = HBufC8::NewLC( KMaxCertificateLength ); |
|
480 iCertPtr.Set( buf->Des() ); |
|
481 |
|
482 TInt count = aStore->CertStoreCount(); |
|
483 for (TInt i = 0; i < count; i++) |
|
484 { |
|
485 MCTCertStore& certstore = aStore->CertStore( i ); |
|
486 MCTToken& token = certstore.Token(); |
|
487 TUid tokenuid = token.Handle().iTokenTypeUid; |
|
488 if ( tokenuid == aTokenUid ) |
|
489 { |
|
490 certstore.Retrieve( aCertInfo, iCertPtr, iStatus ); |
|
491 iOperation = EGetCertificate; |
|
492 iStore = aStore; |
|
493 SetActive(); |
|
494 iWait.Start(); |
|
495 HandleErrorL(); |
|
496 status = iStatus.Int(); |
|
497 break; |
|
498 } |
|
499 } |
|
500 |
|
501 if ( status == KErrNone ) |
|
502 { |
|
503 switch ( aCertInfo.CertificateFormat() ) |
|
504 { |
|
505 case EX509Certificate: |
|
506 { |
|
507 aCert = CX509Certificate::NewL( iCertPtr ); |
|
508 break; |
|
509 } |
|
510 case EX509CertificateUrl: |
|
511 { |
|
512 #ifdef _CERTMANUI_LOG_ |
|
513 TPtrC8 dump = buf->Des(); |
|
514 LOG_HEXDUMP( dump ); |
|
515 #endif |
|
516 break; |
|
517 } |
|
518 default: |
|
519 { |
|
520 break; |
|
521 } |
|
522 } |
|
523 } |
|
524 |
|
525 CleanupStack::PopAndDestroy(); // buf |
|
526 iOperation = EOperationNone; |
|
527 |
|
528 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::GetCertificateL 2" ); |
|
529 return status; |
|
530 } |
|
531 |
|
532 |
|
533 // ----------------------------------------------------------------------------- |
|
534 // CCertManUISyncWrapper::DeleteCertL |
|
535 // ----------------------------------------------------------------------------- |
|
536 // |
|
537 TInt CCertManUISyncWrapper::DeleteCertL( CUnifiedCertStore*& aStore, |
|
538 const CCTCertInfo& aCertInfo ) |
|
539 { |
|
540 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::DeleteCertL 1" ); |
|
541 |
|
542 aStore->Remove( aCertInfo, iStatus ); |
|
543 iOperation = EOperationDelete; |
|
544 iStore = aStore; |
|
545 SetActive(); |
|
546 iWait.Start(); |
|
547 HandleErrorL(); |
|
548 iOperation = EOperationNone; |
|
549 |
|
550 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::DeleteCertL 1" ); |
|
551 return iStatus.Int(); |
|
552 } |
|
553 |
|
554 // ----------------------------------------------------------------------------- |
|
555 // CCertManUISyncWrapper::DeleteCertL |
|
556 // ----------------------------------------------------------------------------- |
|
557 // |
|
558 TInt CCertManUISyncWrapper::DeleteCertL( CUnifiedCertStore*& aStore, |
|
559 const CCTCertInfo& aCertInfo, |
|
560 TUid aTokenUid ) |
|
561 { |
|
562 TInt status( KErrNone ); |
|
563 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::DeleteCertL 2" ); |
|
564 |
|
565 TInt count = aStore->WritableCertStoreCount(); |
|
566 for (TInt i = 0; i < count; i++) |
|
567 { |
|
568 MCTWritableCertStore& writablestore = aStore->WritableCertStore( i ); |
|
569 MCTToken& token = writablestore.Token(); |
|
570 TUid tokenuid = token.Handle().iTokenTypeUid; |
|
571 if ( tokenuid == aTokenUid ) |
|
572 { |
|
573 writablestore.Remove( aCertInfo, iStatus ); |
|
574 iOperation = EOperationDelete; |
|
575 iStore = aStore; |
|
576 SetActive(); |
|
577 iWait.Start(); |
|
578 HandleErrorL(); |
|
579 status = iStatus.Int(); |
|
580 break; |
|
581 } |
|
582 } |
|
583 |
|
584 iOperation = EOperationNone; |
|
585 |
|
586 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::DeleteCertL 2" ); |
|
587 return status; |
|
588 } |
|
589 |
|
590 // ----------------------------------------------------------------------------- |
|
591 // CCertManUISyncWrapper::GetApplicationsL |
|
592 // ----------------------------------------------------------------------------- |
|
593 // |
|
594 TInt CCertManUISyncWrapper::GetApplicationsL( CUnifiedCertStore*& aStore, |
|
595 const CCTCertInfo& aCertInfo, RArray<TUid>& aApps ) |
|
596 { |
|
597 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::GetApplicationsL" ); |
|
598 |
|
599 aStore->Applications( aCertInfo, aApps, iStatus ); |
|
600 iOperation = EOperationGetApps; |
|
601 iStore = aStore; |
|
602 SetActive(); |
|
603 iWait.Start(); |
|
604 HandleErrorL(); |
|
605 iOperation = EOperationNone; |
|
606 |
|
607 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::GetApplicationsL" ); |
|
608 return iStatus.Int(); |
|
609 } |
|
610 |
|
611 // ----------------------------------------------------------------------------- |
|
612 // CCertManUISyncWrapper::IsApplicableL |
|
613 // ----------------------------------------------------------------------------- |
|
614 // |
|
615 TInt CCertManUISyncWrapper::IsApplicableL( CUnifiedCertStore*& aStore, |
|
616 const CCTCertInfo& aCertInfo, TUid aApplication, |
|
617 TBool& aIsApplicable ) |
|
618 { |
|
619 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::IsApplicableL" ); |
|
620 |
|
621 aStore->IsApplicable( aCertInfo, aApplication, aIsApplicable, iStatus ); |
|
622 iOperation = EOperationIsApplicable; |
|
623 iStore = aStore; |
|
624 SetActive(); |
|
625 iWait.Start(); |
|
626 HandleErrorL(); |
|
627 iOperation = EOperationNone; |
|
628 |
|
629 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::IsApplicableL" ); |
|
630 return iStatus.Int(); |
|
631 } |
|
632 |
|
633 // ----------------------------------------------------------------------------- |
|
634 // CCertManUISyncWrapper::IsTrustedL |
|
635 // ----------------------------------------------------------------------------- |
|
636 // |
|
637 TInt CCertManUISyncWrapper::IsTrustedL( CUnifiedCertStore*& aStore, |
|
638 const CCTCertInfo& aCertInfo, TBool& aTrusted ) |
|
639 { |
|
640 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::IsTrustedL" ); |
|
641 |
|
642 aStore->Trusted( aCertInfo, aTrusted, iStatus ); |
|
643 iOperation = EOperationIsTrusted; |
|
644 iStore = aStore; |
|
645 SetActive(); |
|
646 iWait.Start(); |
|
647 HandleErrorL(); |
|
648 iOperation = EOperationNone; |
|
649 |
|
650 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::IsTrustedL" ); |
|
651 return iStatus.Int(); |
|
652 } |
|
653 |
|
654 // ----------------------------------------------------------------------------- |
|
655 // CCertManUISyncWrapper::SetApplicabilityL |
|
656 // ----------------------------------------------------------------------------- |
|
657 // |
|
658 TInt CCertManUISyncWrapper::SetApplicabilityL( CUnifiedCertStore*& aStore, |
|
659 const CCTCertInfo& aCertInfo, |
|
660 RArray<TUid>& aApplications ) |
|
661 { |
|
662 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::SetApplicabilityL" ); |
|
663 |
|
664 aStore->SetApplicability( aCertInfo, aApplications, iStatus ); |
|
665 iOperation = EOperationSetApplicability; |
|
666 iStore = aStore; |
|
667 SetActive(); |
|
668 iWait.Start(); |
|
669 |
|
670 if ( !(iStatus.Int()) ) |
|
671 { |
|
672 aStore->SetTrust( aCertInfo, ETrue, iStatus ); |
|
673 iOperation = EOperationSetToTrusted; |
|
674 SetActive(); |
|
675 iWait.Start(); |
|
676 } |
|
677 HandleErrorL(); |
|
678 iOperation = EOperationNone; |
|
679 |
|
680 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::SetApplicabilityL" ); |
|
681 return iStatus.Int(); |
|
682 } |
|
683 |
|
684 // ----------------------------------------------------------------------------- |
|
685 // CCertManUISyncWrapper::MoveKeyL |
|
686 // ----------------------------------------------------------------------------- |
|
687 // |
|
688 void CCertManUISyncWrapper::MoveKeyL( |
|
689 CUnifiedKeyStore*& aStore, |
|
690 const TCTKeyAttributeFilter& aFilter, |
|
691 const TUid aSourceTokenId, |
|
692 const TUid aTargetTokenId ) |
|
693 { |
|
694 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::MoveKeyL" ); |
|
695 |
|
696 TInt sourceIndex(-1); |
|
697 TInt targetIndex(-1); |
|
698 |
|
699 // Find the index of key stores |
|
700 TInt count = aStore->KeyStoreManagerCount(); |
|
701 |
|
702 for (TInt ii = 0; ii < count; ii++) |
|
703 { |
|
704 MCTKeyStoreManager& keystoremanager = aStore->KeyStoreManager( ii ); |
|
705 MCTToken& token = keystoremanager.Token(); |
|
706 TUid tokenuid = token.Handle().iTokenTypeUid; |
|
707 |
|
708 if ( tokenuid == aSourceTokenId ) |
|
709 { |
|
710 sourceIndex = ii; |
|
711 } |
|
712 |
|
713 if ( tokenuid == aTargetTokenId ) |
|
714 { |
|
715 targetIndex = ii; |
|
716 } |
|
717 } |
|
718 |
|
719 if (( sourceIndex == -1 ) || ( targetIndex == -1 )) |
|
720 { |
|
721 // Key store(s) doesn't exist |
|
722 User::Leave( KErrNotFound ); |
|
723 } |
|
724 |
|
725 RMPointerArray<CCTKeyInfo> keyEntries; |
|
726 |
|
727 MCTKeyStoreManager& sourcekeystore = |
|
728 aStore->KeyStoreManager( sourceIndex ); |
|
729 |
|
730 MCTKeyStoreManager& targetkeystore = |
|
731 aStore->KeyStoreManager( targetIndex ); |
|
732 |
|
733 |
|
734 ListL( aStore, &keyEntries, aFilter, aSourceTokenId ); |
|
735 |
|
736 // Go through all matching keys and move them to |
|
737 // target store |
|
738 for ( TInt ii = 0; ii < keyEntries.Count(); ii++ ) |
|
739 { |
|
740 HBufC8* keyData = HBufC8::NewLC( KMaxKeyLength ); |
|
741 |
|
742 // Retrieve key from source key store |
|
743 sourcekeystore.ExportKey( (*keyEntries[ii]).Handle(), keyData, iStatus ); |
|
744 iOperation = EOperationExportKey; |
|
745 SetActive(); |
|
746 iWait.Start(); |
|
747 User::LeaveIfError( iStatus.Int() ); |
|
748 |
|
749 TCTTokenObjectHandle sourceKeyHandle = (*keyEntries[ii]).Handle(); |
|
750 |
|
751 // Import key to target key store |
|
752 |
|
753 // If key info access type indicates that key is local, then importing is |
|
754 // not possible. The following is the workarround. Almost identical |
|
755 // copy of keyinfo is created without CCTKeyInfo::ELocal access type flag. |
|
756 // UsePolicy is also updated |
|
757 TInt accessType = (*keyEntries[ii]).AccessType(); |
|
758 if ( accessType & CCTKeyInfo::ELocal ) |
|
759 { |
|
760 // CCTKeyInfo::ELocal is set in key info |
|
761 HBufC* label = (*keyEntries[ii]).Label().AllocLC(); |
|
762 |
|
763 // The following XOR operation will clear local bit if it is on. |
|
764 accessType ^= CCTKeyInfo::ELocal; |
|
765 |
|
766 CCTKeyInfo* keyInfo = CCTKeyInfo::NewL( (*keyEntries[ii]).ID(), |
|
767 (*keyEntries[ii]).Usage(), |
|
768 (*keyEntries[ii]).Size(), |
|
769 NULL, |
|
770 label, |
|
771 (*keyEntries[ii]).Token(), |
|
772 (*keyEntries[ii]).HandleID(), |
|
773 KKeyStoreUsePolicy, |
|
774 (*keyEntries[ii]).ManagementPolicy(), |
|
775 (*keyEntries[ii]).Algorithm(), |
|
776 accessType, |
|
777 (*keyEntries[ii]).Native(), |
|
778 (*keyEntries[ii]).StartDate(), |
|
779 (*keyEntries[ii]).EndDate() ); |
|
780 |
|
781 CleanupStack::Pop(label); |
|
782 targetkeystore.ImportKey( *keyData, keyInfo, iStatus ); |
|
783 } |
|
784 else |
|
785 { |
|
786 targetkeystore.ImportKey( *keyData, keyEntries[ii], iStatus ); |
|
787 } |
|
788 |
|
789 iOperation = EOperationImportKey; |
|
790 SetActive(); |
|
791 iWait.Start(); |
|
792 User::LeaveIfError( iStatus.Int() ); |
|
793 |
|
794 // Delete key from source key store |
|
795 sourcekeystore.DeleteKey( sourceKeyHandle, iStatus ); |
|
796 iOperation = EOperationDeleteKey; |
|
797 SetActive(); |
|
798 iWait.Start(); |
|
799 User::LeaveIfError( iStatus.Int() ); |
|
800 |
|
801 CleanupStack::PopAndDestroy(); // keyData |
|
802 } |
|
803 |
|
804 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::MoveKeyL" ); |
|
805 } |
|
806 |
|
807 |
|
808 // ----------------------------------------------------------------------------- |
|
809 // CCertManUISyncWrapper::MoveCertL |
|
810 // ----------------------------------------------------------------------------- |
|
811 // |
|
812 TInt CCertManUISyncWrapper::MoveCertL( |
|
813 CUnifiedCertStore*& aStore, |
|
814 const CCTCertInfo& aCertInfo, |
|
815 const TUid aSourceTokenId, |
|
816 const TUid aTargetTokenId ) |
|
817 { |
|
818 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::MoveCertL" ); |
|
819 |
|
820 TInt sourceIndex(-1); |
|
821 TInt targetIndex(-1); |
|
822 TInt certCount (0); |
|
823 |
|
824 // Find the index of certificate stores |
|
825 TInt count = aStore->WritableCertStoreCount(); |
|
826 for (TInt ii = 0; ii < count; ii++) |
|
827 { |
|
828 MCTWritableCertStore& writablestore = aStore->WritableCertStore( ii ); |
|
829 MCTToken& token = writablestore.Token(); |
|
830 TUid tokenuid = token.Handle().iTokenTypeUid; |
|
831 |
|
832 if ( tokenuid == aSourceTokenId ) |
|
833 { |
|
834 sourceIndex = ii; |
|
835 } |
|
836 |
|
837 if ( tokenuid == aTargetTokenId ) |
|
838 { |
|
839 targetIndex = ii; |
|
840 } |
|
841 } |
|
842 |
|
843 if (( sourceIndex == -1 ) || ( targetIndex == -1 )) |
|
844 { |
|
845 // Certificate store(s) doesn't exist |
|
846 User::Leave( KErrNotFound ); |
|
847 } |
|
848 |
|
849 |
|
850 MCTWritableCertStore& sourcewritablestore = |
|
851 aStore->WritableCertStore( sourceIndex ); |
|
852 |
|
853 // All of the certificates that are associated with same |
|
854 // private key will be moved to target certificate store. |
|
855 CCertAttributeFilter* filter = CCertAttributeFilter::NewL(); |
|
856 filter->SetOwnerType( EUserCertificate ); |
|
857 filter->SetSubjectKeyId( aCertInfo.SubjectKeyId() ); |
|
858 RMPointerArray<CCTCertInfo> certEntries; |
|
859 |
|
860 // List certificates from source certificate store |
|
861 ListL( aStore, &certEntries, *filter, aSourceTokenId ); |
|
862 |
|
863 delete filter; |
|
864 |
|
865 for ( TInt ii = 0; ii < certEntries.Count(); ii++ ) |
|
866 { |
|
867 // Retrieve certificate from source certificate store |
|
868 HBufC8* buf = HBufC8::NewLC( KMaxCertificateLength ); |
|
869 iCertPtr.Set( buf->Des() ); |
|
870 sourcewritablestore.Retrieve( *certEntries[ii], iCertPtr, iStatus ); |
|
871 iOperation = EGetCertificate; |
|
872 SetActive(); |
|
873 iWait.Start(); |
|
874 User::LeaveIfError( iStatus.Int() ); |
|
875 |
|
876 // Add certificate to target certificate store |
|
877 MCTWritableCertStore& targetwritablestore = |
|
878 aStore->WritableCertStore( targetIndex ); |
|
879 |
|
880 targetwritablestore.Add( (*certEntries[ii]).Label(), EX509Certificate, |
|
881 EUserCertificate, &((*certEntries[ii]).SubjectKeyId()), |
|
882 &((*certEntries[ii]).IssuerKeyId()), *buf, iStatus ); |
|
883 |
|
884 iOperation = EAddCertificate; |
|
885 SetActive(); |
|
886 iWait.Start(); |
|
887 User::LeaveIfError( iStatus.Int() ); |
|
888 |
|
889 // Delete certificate from source certificate store |
|
890 sourcewritablestore.Remove( *certEntries[ii], iStatus ); |
|
891 iOperation = EOperationDelete; |
|
892 iStore = aStore; |
|
893 SetActive(); |
|
894 iWait.Start(); |
|
895 HandleErrorL(); |
|
896 iOperation = EOperationNone; |
|
897 User::LeaveIfError( iStatus.Int() ); |
|
898 certCount++; |
|
899 |
|
900 CleanupStack::PopAndDestroy(); // buf |
|
901 } |
|
902 |
|
903 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::MoveCertL" ); |
|
904 return certCount; |
|
905 } |
|
906 |
|
907 // ----------------------------------------------------------------------------- |
|
908 // CCertManUISyncWrapper::ValidateX509RootCertificateL |
|
909 // ----------------------------------------------------------------------------- |
|
910 // |
|
911 TInt CCertManUISyncWrapper::ValidateX509RootCertificateL( |
|
912 CPKIXValidationResult*& aValidationResult, |
|
913 const TTime& aValidationTime, CPKIXCertChain* aChain ) |
|
914 { |
|
915 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::ValidateX509RootCertificateL" ); |
|
916 |
|
917 aChain->ValidateL( *aValidationResult, aValidationTime, iStatus ); |
|
918 iOperation = EOperationValidateX509Root; |
|
919 iChain = aChain; |
|
920 SetActive(); |
|
921 iWait.Start(); |
|
922 iOperation = EOperationNone; |
|
923 |
|
924 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::ValidateX509RootCertificateL" ); |
|
925 return iStatus.Int(); |
|
926 } |
|
927 |
|
928 // ----------------------------------------------------------------------------- |
|
929 // CCertManUISyncWrapper::GetInterface |
|
930 // ----------------------------------------------------------------------------- |
|
931 // |
|
932 TInt CCertManUISyncWrapper::GetInterface( |
|
933 TUid aRequiredInterface, MCTToken& aToken, |
|
934 MCTTokenInterface*& aReturnedInterface) |
|
935 { |
|
936 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::GetInterface" ); |
|
937 |
|
938 iToken = &aToken; |
|
939 aToken.GetInterface( aRequiredInterface, aReturnedInterface, iStatus ); |
|
940 iOperation = EOperationGetInterface; |
|
941 SetActive(); |
|
942 iWait.Start(); |
|
943 iOperation = EOperationNone; |
|
944 |
|
945 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::GetInterface" ); |
|
946 return iStatus.Int(); |
|
947 } |
|
948 |
|
949 // ----------------------------------------------------------------------------- |
|
950 // CCertManUISyncWrapper::RunL |
|
951 // If no errors happened, stop. Show an error note if needed. |
|
952 // ----------------------------------------------------------------------------- |
|
953 // |
|
954 |
|
955 void CCertManUISyncWrapper::RunL() |
|
956 { |
|
957 CERTMANUILOGGER_ENTERFN("CCertManUISyncWrapper::RunL"); |
|
958 |
|
959 if ( iWait.IsStarted() ) |
|
960 { |
|
961 iWait.AsyncStop(); |
|
962 } |
|
963 |
|
964 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::RunL" ); |
|
965 } |
|
966 |
|
967 // ----------------------------------------------------------------------------- |
|
968 // CCertManUISyncWrapper::HandleErrorL |
|
969 // Shows an error note according to status of operation, |
|
970 // ----------------------------------------------------------------------------- |
|
971 // |
|
972 void CCertManUISyncWrapper::HandleErrorL() |
|
973 { |
|
974 CERTMANUILOGGER_ENTERFN( "CCertManUISyncWrapper::HandleErrorL" ); |
|
975 |
|
976 TInt status = iStatus.Int(); |
|
977 switch ( status ) |
|
978 { |
|
979 case KErrNone: |
|
980 { |
|
981 LOG_WRITE( "No error" ); |
|
982 break; |
|
983 } |
|
984 case KErrCancel: |
|
985 { |
|
986 LOG_WRITE( "HandleErrorL : KErrCancel" ); |
|
987 // Up to caller decide if note is needed. No error note shown. |
|
988 break; |
|
989 } |
|
990 case KErrNoMemory: |
|
991 case KErrBadHandle: |
|
992 case KErrAlreadyExists: |
|
993 case KErrNotSupported: |
|
994 case EShowErrorNote: |
|
995 { |
|
996 LOG_WRITE_FORMAT( "HandleErrorL LEAVE : error code %i", status ); |
|
997 User::Leave( iStatus.Int() ); |
|
998 break; |
|
999 } |
|
1000 default: |
|
1001 { |
|
1002 LOG_WRITE_FORMAT( "HandleErrorL LEAVE (default) : error code %i", status ); |
|
1003 break; |
|
1004 } |
|
1005 } |
|
1006 |
|
1007 CERTMANUILOGGER_LEAVEFN( "CCertManUISyncWrapper::HandleErrorL" ); |
|
1008 } |
|
1009 |
|
1010 |
|
1011 // End of File |
|
1012 |