|
1 /* |
|
2 * Copyright (c) 2003-2009 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: Implementation of class CCertManUIKeeper |
|
15 * Creates and destroys all the views CertManUI uses. |
|
16 * Handles changing CertManUI views. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <aknnotewrappers.h> // for warning & information notes |
|
23 #include <unifiedcertstore.h> |
|
24 #include <unifiedkeystore.h> |
|
25 #include <mctwritablecertstore.h> |
|
26 #include <X509CertNameParser.h> |
|
27 #include <certmanui.rsg> |
|
28 #include <data_caging_path_literals.hrh> |
|
29 #include "CertmanuiSyncWrapper.h" |
|
30 #include "CertmanuiCertificateHelper.h" |
|
31 #include "Certmanuidialogs.h" |
|
32 #include "CertmanuiKeeper.h" |
|
33 #include "CertmanuiviewTrust.h" |
|
34 #include "CertmanuiviewPersonal.h" |
|
35 #include "CertmanuicontainerAuthority.h" |
|
36 #include "CertmanuiCommon.h" |
|
37 #include "CertManUILogger.h" |
|
38 #include "securityuisvariant.hrh" |
|
39 |
|
40 // CONSTANTS |
|
41 _LIT( KNameSeparator, " " ); |
|
42 _LIT( KResourceFile, "z:CertManUi.rsc" ); |
|
43 |
|
44 |
|
45 // ============================= GLOBAL FUNCTIONS ============================== |
|
46 |
|
47 //--------------------------------------------------------------- |
|
48 // CloseWaitDialogOnLeave( TAny* aPtr ) |
|
49 // Closes wait dialog when leave happens. |
|
50 //--------------------------------------------------------------- |
|
51 void CloseWaitDialogOnLeave( TAny* aPtr ) |
|
52 { |
|
53 CCertManUIKeeper* keeper = reinterpret_cast< CCertManUIKeeper* >( aPtr ); |
|
54 if( keeper ) |
|
55 { |
|
56 TRAP_IGNORE( keeper->CloseWaitDialogL() ); |
|
57 } |
|
58 } |
|
59 |
|
60 //--------------------------------------------------------------- |
|
61 // CleanupCloseWaitDialogPushL( CCertManUIKeeper& aKeeper ) |
|
62 // Helper function for to close wait dialog if leave happens. |
|
63 //--------------------------------------------------------------- |
|
64 void CleanupCloseWaitDialogPushL( CCertManUIKeeper& aKeeper ) |
|
65 { |
|
66 CleanupStack::PushL( TCleanupItem( CloseWaitDialogOnLeave, &aKeeper ) ); |
|
67 } |
|
68 |
|
69 |
|
70 // ============================= LOCAL FUNCTIONS =============================== |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // TInt CompareCALabels( const CCTCertInfo& cert1, const CCTCertInfo& cert2 ) |
|
74 // Compares two labels. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 TInt CompareCALabels( |
|
78 const CCertManUICertData& cert1, |
|
79 const CCertManUICertData& cert2 ) |
|
80 { |
|
81 return ( (cert1.iCAEntryLabel->Des()). |
|
82 CompareF( cert2.iCAEntryLabel->Des() ) ); |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // TInt CompareUserLabels( const CCTCertInfo& cert1, const CCTCertInfo& cert2 ) |
|
87 // Compares two labels. |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 TInt CompareUserLabels( |
|
91 const CCertManUICertData& cert1, |
|
92 const CCertManUICertData& cert2 ) |
|
93 { |
|
94 return ( (cert1.iUserEntryLabel->Des()). |
|
95 CompareF( cert2.iUserEntryLabel->Des() ) ); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // TInt ComparePeerLabels( const CCTCertInfo& cert1, const CCTCertInfo& cert2 ) |
|
100 // Compares two labels. |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 TInt ComparePeerLabels( |
|
104 const CCertManUICertData& cert1, |
|
105 const CCertManUICertData& cert2 ) |
|
106 { |
|
107 return ( (cert1.iPeerEntryLabel->Des()). |
|
108 CompareF( cert2.iPeerEntryLabel->Des() ) ); |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // TInt CompareDeviceLabels( const CCTCertInfo& cert1, const CCTCertInfo& cert2 ) |
|
113 // Compares two labels. |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 TInt CompareDeviceLabels( |
|
117 const CCertManUICertData& cert1, |
|
118 const CCertManUICertData& cert2 ) |
|
119 { |
|
120 return ( (cert1.iDeviceEntryLabel->Des()). |
|
121 CompareF( cert2.iDeviceEntryLabel->Des() ) ); |
|
122 } |
|
123 |
|
124 // ================= HELPER CLASS =========================== |
|
125 |
|
126 // Constructor. |
|
127 CCertManUICertData::CCertManUICertData() |
|
128 { |
|
129 } |
|
130 |
|
131 // Destructor. |
|
132 CCertManUICertData::~CCertManUICertData() |
|
133 { |
|
134 delete iCAEntryLabel; |
|
135 delete iUserEntryLabel; |
|
136 delete iPeerEntryLabel; |
|
137 delete iDeviceEntryLabel; |
|
138 } |
|
139 |
|
140 // Releases Certificate entries. |
|
141 void CCertManUICertData::Release() |
|
142 { |
|
143 if ( iCAEntry ) |
|
144 { |
|
145 iCAEntry->Release(); |
|
146 } |
|
147 |
|
148 if ( iUserEntry ) |
|
149 { |
|
150 iUserEntry->Release(); |
|
151 } |
|
152 |
|
153 if ( iPeerEntry ) |
|
154 { |
|
155 iPeerEntry->Release(); |
|
156 } |
|
157 |
|
158 if ( iDeviceEntry ) |
|
159 { |
|
160 iDeviceEntry->Release(); |
|
161 } |
|
162 |
|
163 delete this; |
|
164 } |
|
165 |
|
166 // ================= MEMBER FUNCTIONS ======================= |
|
167 |
|
168 // --------------------------------------------------------- |
|
169 // CCertManUIKeeper::CCertManUIKeeper() |
|
170 // Constructor with parent |
|
171 // --------------------------------------------------------- |
|
172 // |
|
173 CCertManUIKeeper::CCertManUIKeeper(): iResourceLoader( *iCoeEnv ) |
|
174 { |
|
175 CERTMANUILOGGER_CREATE; //lint !e960 |
|
176 CERTMANUILOGGER_WRITE_TIMESTAMP( "CCertManUIKeeper::CCertManUIKeeper" ); |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------- |
|
180 // CCertManUIKeeper::~CCertManUIKeeper() |
|
181 // Destructor |
|
182 // --------------------------------------------------------- |
|
183 // |
|
184 CCertManUIKeeper::~CCertManUIKeeper() |
|
185 { |
|
186 CERTMANUILOGGER_WRITE_TIMESTAMP( "CCertManUIKeeper::~CCertManUIKeeper" ); |
|
187 if ( iWrapper ) |
|
188 { |
|
189 iWrapper->Cancel(); |
|
190 } |
|
191 delete iFilter; |
|
192 delete iKeyFilter; |
|
193 delete iStore; |
|
194 delete iKeyStore; |
|
195 delete iWrapper; |
|
196 delete iCertificateHelper; |
|
197 delete iCertmanUIDialog; |
|
198 |
|
199 iCAEntries.Close(); |
|
200 iCALabelEntries.Close(); |
|
201 |
|
202 iUserEntries.Close(); |
|
203 iUserLabelEntries.Close(); |
|
204 |
|
205 iPeerEntries.Close(); |
|
206 iPeerLabelEntries.Close(); |
|
207 |
|
208 iDeviceEntries.Close(); |
|
209 iDeviceLabelEntries.Close(); |
|
210 |
|
211 iKeyEntries.Close(); |
|
212 |
|
213 iRfs.Close(); |
|
214 |
|
215 CERTMANUILOGGER_DELETE; //lint !e960 |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------- |
|
219 // CCertManUIKeeper* CCertManUIKeeper::NewL(const TRect& aRect, TUid aViewId) |
|
220 // --------------------------------------------------------- |
|
221 // |
|
222 |
|
223 CCertManUIKeeper* CCertManUIKeeper::NewL( |
|
224 const TRect& aRect, TUid aViewId ) |
|
225 { |
|
226 CCertManUIKeeper* self = new ( ELeave ) CCertManUIKeeper; |
|
227 CleanupStack::PushL( self ); |
|
228 self->ConstructL( aRect, aViewId ); |
|
229 CleanupStack::Pop(); |
|
230 return self; |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------- |
|
234 // CCertManUIKeeper* CCertManUIKeeper::NewLC( |
|
235 // const TRect& aRect, TUid aViewId) |
|
236 // --------------------------------------------------------- |
|
237 // |
|
238 CCertManUIKeeper* CCertManUIKeeper::NewLC( |
|
239 const TRect& aRect, TUid aViewId ) |
|
240 { |
|
241 CCertManUIKeeper* self = new ( ELeave ) CCertManUIKeeper; |
|
242 CleanupStack::PushL( self ); |
|
243 self->ConstructL( aRect, aViewId ); |
|
244 return self; |
|
245 } |
|
246 |
|
247 |
|
248 // --------------------------------------------------------- |
|
249 // CCertManUIKeeper::ConstructL( |
|
250 // const TRect& aRect, TUid aViewId |
|
251 // |
|
252 // --------------------------------------------------------- |
|
253 // |
|
254 void CCertManUIKeeper::ConstructL( const TRect& aRect, TUid aViewId ) |
|
255 { |
|
256 CERTMANUILOGGER_ENTERFN( "CCertManUIKeeper::ConstructL" ); |
|
257 |
|
258 AddResourceFileL(); |
|
259 |
|
260 InitializeL( aRect, aViewId ); |
|
261 |
|
262 CERTMANUILOGGER_LEAVEFN( "CCertManUIKeeper::ConstructL" ); |
|
263 } |
|
264 |
|
265 |
|
266 // --------------------------------------------------------- |
|
267 // CCertManUIKeeper::InitializeL( |
|
268 // const TRect& aRect, TUid aViewId |
|
269 // |
|
270 // --------------------------------------------------------- |
|
271 // |
|
272 void CCertManUIKeeper::InitializeL( const TRect& /*aRect*/, TUid /*aViewId*/) |
|
273 { |
|
274 CERTMANUILOGGER_ENTERFN( "CCertManUIKeeper::InitializeL" ); |
|
275 iCertmanUIDialog = new ( ELeave ) CCertManUIWaitDialog(); |
|
276 |
|
277 // Ensure that file server session is succesfully created |
|
278 User::LeaveIfError( iRfs.Connect() ); |
|
279 |
|
280 iCertsDatOK = EFalse; |
|
281 |
|
282 // Is this the place where these errors can be handled? |
|
283 // iCertsDatOK is set when cert entries are refreshed. |
|
284 // Create a R/W interface. Symbian has promised to support |
|
285 // up to two simultaneous R/W interfaces. |
|
286 TRAPD ( error, iStore = CUnifiedCertStore::NewL( iRfs, ETrue ) ); |
|
287 if ( error != KErrNone ) |
|
288 { |
|
289 if ( error == KErrNotSupported |
|
290 || error == KErrNotReady |
|
291 || error == KErrArgument |
|
292 || error == KErrNotFound ) |
|
293 { |
|
294 // Something may be wrong with the databases |
|
295 iCertsDatOK = EFalse; |
|
296 ShowErrorNoteL( error ); |
|
297 User::Leave( KErrNone ); |
|
298 } |
|
299 else |
|
300 { |
|
301 User::Leave( error ); |
|
302 } |
|
303 } |
|
304 else |
|
305 { |
|
306 // cacerts.dat file is ok |
|
307 iCertsDatOK = ETrue; |
|
308 } |
|
309 |
|
310 iCertificateHelper = new ( ELeave ) CCertManUICertificateHelper( *this ); |
|
311 |
|
312 iWrapper = CCertManUISyncWrapper::NewL(); |
|
313 error = iWrapper->InitStoreL( iStore ); |
|
314 |
|
315 if ( error ) |
|
316 { |
|
317 LOG_WRITE_FORMAT("InitStoreL returned %i", error); |
|
318 } |
|
319 |
|
320 |
|
321 iFilter = CCertAttributeFilter::NewL(); |
|
322 |
|
323 TRAP( error, iKeyStore = CUnifiedKeyStore::NewL( iRfs ) ); |
|
324 if ( error != KErrNone ) |
|
325 { |
|
326 if (error == KErrNotSupported |
|
327 || error == KErrNotReady |
|
328 || error == KErrArgument |
|
329 || error == KErrNotFound) |
|
330 { |
|
331 // Something is wrong with key stores |
|
332 LOG_WRITE( "Keystore corrupt" ); |
|
333 |
|
334 ShowErrorNoteL( error ); |
|
335 User::Leave( KErrNone ); |
|
336 } |
|
337 else |
|
338 { |
|
339 User::Leave( error ); |
|
340 } |
|
341 } |
|
342 |
|
343 LOG_WRITE("Init keystore"); |
|
344 iWrapper->InitStoreL( iKeyStore ); |
|
345 iKeyEntries.Close(); |
|
346 LOG_WRITE_FORMAT("Keys available : %i", iKeyEntries.Count()); |
|
347 |
|
348 if ( iCertsDatOK ) // == ETrue |
|
349 { |
|
350 iStartup = ETrue; |
|
351 } |
|
352 |
|
353 |
|
354 CERTMANUILOGGER_LEAVEFN( "CCertManUIKeeper::InitializeL" ); |
|
355 } |
|
356 |
|
357 // --------------------------------------------------------- |
|
358 // CCertManUIKeeper::AddResourceFileL() |
|
359 // |
|
360 // --------------------------------------------------------- |
|
361 // |
|
362 void CCertManUIKeeper::AddResourceFileL() |
|
363 { |
|
364 TFileName fileName; |
|
365 TParse parse; |
|
366 parse.Set( KResourceFile, &KDC_RESOURCE_FILES_DIR, NULL ); |
|
367 |
|
368 fileName = parse.FullName(); |
|
369 iResourceLoader.OpenL( fileName ); |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------- |
|
373 // CCertManUIKeeper::FocusChanged(TDrawNow aDrawNow) |
|
374 // Added here because FocusChanged need to be included |
|
375 // in every control derived from CCoeControl that can have listbox |
|
376 // --------------------------------------------------------- |
|
377 // |
|
378 void CCertManUIKeeper::FocusChanged(TDrawNow aDrawNow) |
|
379 { |
|
380 if (iListBox) |
|
381 { |
|
382 iListBox->SetFocus( IsFocused(), aDrawNow ); |
|
383 } |
|
384 } |
|
385 |
|
386 |
|
387 // ---------------------------------------------------- |
|
388 // CCertManUIKeeper::ActivateTitleL(TInt aCurrentTitle) |
|
389 // Activates the WimTitle and CertManUI Trust Settings title |
|
390 // ---------------------------------------------------- |
|
391 // |
|
392 void CCertManUIKeeper::ActivateTitleL( TInt aCurrentTitle ) |
|
393 { |
|
394 CERTMANUILOGGER_ENTERFN("CCertManUIKeeper::ActivateTitleL" ); |
|
395 |
|
396 CEikStatusPane* sp = STATIC_CAST( |
|
397 CAknAppUi*, iEikonEnv->EikAppUi())->StatusPane(); |
|
398 // Fetch pointer to the default title pane control |
|
399 CAknTitlePane* title = STATIC_CAST( |
|
400 CAknTitlePane*, sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) )); |
|
401 TResourceReader reader; |
|
402 |
|
403 if ( aCurrentTitle == KViewTitleCertManUI ) |
|
404 { |
|
405 iCoeEnv->CreateResourceReaderLC( reader, R_CERTMANUI_VIEW_TITLE ); |
|
406 } |
|
407 else if ( aCurrentTitle == KViewTitleCertManUIAuthority ) |
|
408 { |
|
409 iCoeEnv->CreateResourceReaderLC( reader, R_CERTMANUI_VIEW_TITLE_AUTHORITY ); |
|
410 } |
|
411 else if ( aCurrentTitle == KViewTitleCertManUITrustedSite ) |
|
412 { |
|
413 iCoeEnv->CreateResourceReaderLC( reader, R_CERTMANUI_VIEW_TITLE_TRUSTED_SITE ); |
|
414 } |
|
415 else if ( aCurrentTitle == KViewTitleCertManUIPersonal ) |
|
416 { |
|
417 iCoeEnv->CreateResourceReaderLC( reader, R_CERTMANUI_VIEW_TITLE_PERSONAL ); |
|
418 } |
|
419 else if ( aCurrentTitle == KViewTitleCertManUIDevice ) |
|
420 { |
|
421 iCoeEnv->CreateResourceReaderLC( reader, R_CERTMANUI_VIEW_TITLE_DEVICE ); |
|
422 } |
|
423 else // for lint |
|
424 { |
|
425 } |
|
426 |
|
427 title->SetFromResourceL( reader ); |
|
428 CleanupStack::PopAndDestroy(); // reader |
|
429 |
|
430 CERTMANUILOGGER_LEAVEFN( "CCertManUIKeeper::ActivateTitleL" ); |
|
431 } |
|
432 |
|
433 // --------------------------------------------------------- |
|
434 // CCertManUIKeeper::HandleControlEventL( |
|
435 // CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) |
|
436 // Cannot be changed to non-leaving function. |
|
437 // L-function is required by the class definition, even if empty. |
|
438 // --------------------------------------------------------- |
|
439 // |
|
440 void CCertManUIKeeper::HandleControlEventL( |
|
441 CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) |
|
442 { |
|
443 } |
|
444 |
|
445 // --------------------------------------------------------- |
|
446 // CCertManUIKeeper::OfferKeyEventL( |
|
447 // const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/) |
|
448 // Called when a key is pressed. |
|
449 // Cannot be changed to non-leaving function. |
|
450 // L-function is required by the class definition, even if empty. |
|
451 // --------------------------------------------------------- |
|
452 // |
|
453 TKeyResponse CCertManUIKeeper::OfferKeyEventL( |
|
454 const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/) |
|
455 { |
|
456 // Listbox takes all event even if it doesn't use them |
|
457 return EKeyWasNotConsumed; |
|
458 } |
|
459 |
|
460 // --------------------------------------------------------- |
|
461 // CCertManUIKeeper::CertManager() |
|
462 // --------------------------------------------------------- |
|
463 // |
|
464 CUnifiedCertStore*& CCertManUIKeeper::CertManager() |
|
465 { |
|
466 return iStore; |
|
467 } |
|
468 |
|
469 // --------------------------------------------------------- |
|
470 // CCertManUIKeeper::KeyManager() |
|
471 // --------------------------------------------------------- |
|
472 // |
|
473 CUnifiedKeyStore*& CCertManUIKeeper::KeyManager() |
|
474 { |
|
475 return iKeyStore; |
|
476 } |
|
477 |
|
478 // --------------------------------------------------------- |
|
479 // CCertManUIKeeper::RefreshCAEntriesL() |
|
480 // Checks that cacerts.dat file is not corrupted and |
|
481 // returns CA certificates from it |
|
482 // --------------------------------------------------------- |
|
483 // |
|
484 void CCertManUIKeeper::RefreshCAEntriesL() |
|
485 { |
|
486 CERTMANUILOGGER_ENTERFN( "CCertManUIKeeper::RefreshCAEntriesL" ); |
|
487 iFilter->SetOwnerType( ECACertificate ); |
|
488 iCAEntries.Close(); |
|
489 CUnifiedCertStore*& store = CertManager(); |
|
490 iWrapper->ListL( store, &iCAEntries, *iFilter ); |
|
491 |
|
492 iCALabelEntries.Close(); |
|
493 LOG_WRITE_FORMAT("CA entries found: %i", iCAEntries.Count()); |
|
494 for ( TInt ii = 0; ii < iCAEntries.Count(); ii++ ) |
|
495 { |
|
496 switch ( iCAEntries[ii]->CertificateFormat() ) |
|
497 { |
|
498 case EX509Certificate: |
|
499 { |
|
500 CCertManUICertData* data = new ( ELeave ) CCertManUICertData(); |
|
501 data->iCAEntry = CCTCertInfo::NewL( *iCAEntries[ii] ); |
|
502 CleanupStack::PushL( data ); |
|
503 HBufC* pri = NULL; |
|
504 HBufC* sec = NULL; |
|
505 |
|
506 CCertificate* cert; |
|
507 |
|
508 TRAPD(err, iWrapper->GetCertificateL( CertManager(), *iCAEntries[ii], cert )); |
|
509 if (( err == KErrArgument ) || ( err == KErrCorrupt )) |
|
510 { |
|
511 // This indicates that certificate is not according to X509 |
|
512 // specification or it is corrupted. Ignore certificate |
|
513 if(data->iCAEntry) |
|
514 { |
|
515 data->iCAEntry->Release(); |
|
516 } |
|
517 CleanupStack::PopAndDestroy( data ); // data |
|
518 continue; |
|
519 } |
|
520 else |
|
521 { |
|
522 User::LeaveIfError( err ); |
|
523 } |
|
524 |
|
525 CleanupStack::PushL( cert ); |
|
526 |
|
527 X509CertNameParser::PrimaryAndSecondaryNameL |
|
528 ( *((CX509Certificate*)cert), pri, sec, iCAEntries[ii]->Label()); |
|
529 |
|
530 CleanupStack::PushL( pri ); |
|
531 CleanupStack::PushL( sec ); |
|
532 |
|
533 TInt lenght = 0; |
|
534 |
|
535 lenght += iCAEntries[ii]->Label().Length(); |
|
536 |
|
537 if ( pri ) |
|
538 { |
|
539 lenght += pri->Length(); |
|
540 } |
|
541 if ( sec && !(iCAEntries[ii]->Label().Length()) ) |
|
542 { |
|
543 lenght += sec->Length(); |
|
544 } |
|
545 lenght += KNameSeparator.iTypeLength; |
|
546 |
|
547 HBufC* label = HBufC::NewL( lenght ); |
|
548 label->Des().Append( iCAEntries[ii]->Label() ); |
|
549 |
|
550 if ( pri ) |
|
551 { |
|
552 label->Des().Append( KNameSeparator ); |
|
553 label->Des().Append( pri->Des() ); |
|
554 } |
|
555 if ( sec && !(iCAEntries[ii]->Label().Length()) ) |
|
556 { |
|
557 label->Des().Append( sec->Des() ); |
|
558 } |
|
559 |
|
560 data->iCAEntryLabel = label; |
|
561 iCALabelEntries.Append( data ); |
|
562 |
|
563 CleanupStack::PopAndDestroy( 3 ); // cert, pri, sec |
|
564 CleanupStack::Pop( data ); // data |
|
565 break; |
|
566 } // EX509Certificate |
|
567 |
|
568 case EWTLSCertificate: |
|
569 // Do nothing for wtls certificates |
|
570 break; |
|
571 default: |
|
572 { |
|
573 User::Leave( KErrNotSupported ); |
|
574 } |
|
575 } // switch |
|
576 |
|
577 } // for |
|
578 |
|
579 // Sort the certificates. |
|
580 TLinearOrder<CCertManUICertData> order( CompareCALabels ); |
|
581 iCALabelEntries.Sort( order ); |
|
582 |
|
583 CERTMANUILOGGER_LEAVEFN("CCertManUIKeeper::RefreshCAEntriesL" ); |
|
584 } |
|
585 |
|
586 // --------------------------------------------------------- |
|
587 // CCertManUIKeeper::RefreshUserCertEntriesL() |
|
588 // Checks that cacerts.dat file is not corrupted and |
|
589 // returns User certificates from it |
|
590 // --------------------------------------------------------- |
|
591 // |
|
592 void CCertManUIKeeper::RefreshUserCertEntriesL() |
|
593 { |
|
594 CERTMANUILOGGER_ENTERFN( |
|
595 "CCertManUIKeeper::RefreshUserCertEntriesL" ); |
|
596 |
|
597 iFilter->SetOwnerType( EUserCertificate ); |
|
598 iUserEntries.Close(); |
|
599 CUnifiedCertStore*& store = CertManager(); |
|
600 iWrapper->ListL( store, &iUserEntries, *iFilter ); |
|
601 |
|
602 iUserLabelEntries.Close(); |
|
603 LOG_WRITE_FORMAT(" Userentries found %i", iUserEntries.Count()); |
|
604 for ( TInt i = 0; i < iUserEntries.Count(); i++ ) |
|
605 { |
|
606 |
|
607 if ( iUserEntries[i]->Handle().iTokenHandle.iTokenTypeUid == KCMDeviceCertStoreTokenUid ) |
|
608 { |
|
609 // User certificates from DeviceCertStore are not |
|
610 // shown in Personal certificate view. Ignore this certificate. |
|
611 break; |
|
612 } |
|
613 |
|
614 switch ( iUserEntries[i]->CertificateFormat() ) |
|
615 { |
|
616 case EX509Certificate: |
|
617 { |
|
618 LOG_WRITE_FORMAT(" User X509 certificate, index %i", i); |
|
619 CCertManUICertData* data = new (ELeave) CCertManUICertData(); |
|
620 data->iUserEntry = CCTCertInfo::NewL( *iUserEntries[i] ); |
|
621 CleanupStack::PushL( data ); |
|
622 HBufC* pri = NULL; |
|
623 HBufC* sec = NULL; |
|
624 |
|
625 CCertificate* cert = NULL; |
|
626 TRAPD(error, iWrapper->GetCertificateL( CertManager(), *iUserEntries[i], cert )); |
|
627 |
|
628 if( error == KErrArgument) |
|
629 { |
|
630 LOG_WRITE("Corrupted user certificate detected"); |
|
631 CleanupStack::PopAndDestroy( data ); |
|
632 break; |
|
633 } |
|
634 else if ( error != KErrNone ) |
|
635 { |
|
636 LOG_WRITE_FORMAT( " GetCertificateL leaves, error code %i", error ); |
|
637 User::Leave( error ); |
|
638 } |
|
639 else |
|
640 { |
|
641 CleanupStack::PushL( cert ); |
|
642 } |
|
643 |
|
644 X509CertNameParser::PrimaryAndSecondaryNameL |
|
645 ( *((CX509Certificate*)cert), pri, sec, iUserEntries[i]->Label()); |
|
646 |
|
647 CleanupStack::PushL( pri ); |
|
648 CleanupStack::PushL( sec ); |
|
649 |
|
650 TInt lenght = 0; |
|
651 |
|
652 lenght += iUserEntries[i]->Label().Length(); |
|
653 |
|
654 if ( pri ) |
|
655 { |
|
656 lenght += pri->Length(); |
|
657 } |
|
658 if ( sec && !(iUserEntries[i]->Label().Length()) ) |
|
659 { |
|
660 lenght += sec->Length(); |
|
661 } |
|
662 lenght += KNameSeparator.iTypeLength; |
|
663 |
|
664 HBufC* label = HBufC::NewL( lenght ); |
|
665 label->Des().Append( iUserEntries[i]->Label() ); |
|
666 |
|
667 if ( pri ) |
|
668 { |
|
669 label->Des().Append( KNameSeparator ); |
|
670 label->Des().Append( pri->Des() ); |
|
671 } |
|
672 if ( sec && !(iUserEntries[i]->Label().Length()) ) |
|
673 { |
|
674 label->Des().Append( sec->Des() ); |
|
675 } |
|
676 |
|
677 data->iUserEntryLabel = label; |
|
678 iUserLabelEntries.Append( data ); |
|
679 |
|
680 CleanupStack::PopAndDestroy( 3 ); // cert, pri, sec |
|
681 CleanupStack::Pop( data ); // data |
|
682 break; |
|
683 } // EX509Certificate |
|
684 |
|
685 case EX509CertificateUrl: |
|
686 { |
|
687 LOG_WRITE_FORMAT(" User X509URL certificate, index %i", i); |
|
688 CCertManUICertData* urlCertData = new (ELeave) CCertManUICertData(); |
|
689 urlCertData->iUserEntry = CCTCertInfo::NewL( *iUserEntries[i] ); |
|
690 CleanupStack::PushL( urlCertData ); |
|
691 |
|
692 CCertificate* cert = NULL; |
|
693 TRAPD(error, iWrapper->GetCertificateL( CertManager(), *iUserEntries[i], cert )); |
|
694 if( error == KErrArgument ) |
|
695 { |
|
696 LOG_WRITE("Corrupted user certificate detected"); |
|
697 CleanupStack::PopAndDestroy( urlCertData ); // urlCertData |
|
698 break; |
|
699 } |
|
700 else if ( error != KErrNone ) |
|
701 { |
|
702 LOG_WRITE_FORMAT( " GetCertificateL leaves, error code %i", error ); |
|
703 User::Leave(error); |
|
704 } |
|
705 else |
|
706 { |
|
707 CleanupStack::PushL( cert ); |
|
708 } |
|
709 |
|
710 |
|
711 HBufC* UrlLabel = HBufC::NewL( 20 ); |
|
712 UrlLabel->Des().Append( _L("URL UserCert")); |
|
713 |
|
714 urlCertData->iUserEntryLabel = UrlLabel; |
|
715 iUserLabelEntries.Append( urlCertData ); |
|
716 |
|
717 CleanupStack::PopAndDestroy( cert ); // cert |
|
718 CleanupStack::Pop( urlCertData ); // data |
|
719 break; |
|
720 } |
|
721 default: |
|
722 { |
|
723 LOG_WRITE_FORMAT( "Unsupported certificate format 0x%x", |
|
724 iUserEntries[i]->CertificateFormat() ); |
|
725 } |
|
726 } // switch |
|
727 |
|
728 } // for |
|
729 |
|
730 // Sort the certificates. |
|
731 TLinearOrder<CCertManUICertData> order( CompareUserLabels ); |
|
732 iUserLabelEntries.Sort( order ); |
|
733 |
|
734 CERTMANUILOGGER_LEAVEFN( |
|
735 "CCertManUIKeeper::RefreshUserCertEntriesL" ); |
|
736 } |
|
737 |
|
738 // --------------------------------------------------------- |
|
739 // CCertManUIKeeper::RefreshPeerCertEntriesL() |
|
740 // Checks that Trusted site certificate store is |
|
741 // not corrupted and returns Peer certificates from it |
|
742 // --------------------------------------------------------- |
|
743 // |
|
744 void CCertManUIKeeper::RefreshPeerCertEntriesL() |
|
745 { |
|
746 CERTMANUILOGGER_ENTERFN( "CCertManUIKeeper::RefreshPeerEntriesL" ); |
|
747 |
|
748 |
|
749 |
|
750 iFilter->SetOwnerType( EPeerCertificate ); |
|
751 iPeerEntries.Close(); |
|
752 CUnifiedCertStore*& store = CertManager(); |
|
753 |
|
754 iWrapper->ListL( store, &iPeerEntries, *iFilter, KCMTrustedServerTokenUid ); |
|
755 |
|
756 iPeerLabelEntries.Close(); |
|
757 LOG_WRITE_FORMAT("Peer entries found: %i", iPeerEntries.Count()); |
|
758 for ( TInt ii = 0; ii < iPeerEntries.Count(); ii++ ) |
|
759 { |
|
760 switch ( iPeerEntries[ii]->CertificateFormat() ) |
|
761 { |
|
762 case EX509Certificate: |
|
763 { |
|
764 CCertManUICertData* data = new (ELeave) CCertManUICertData(); |
|
765 data->iPeerEntry = CCTCertInfo::NewL( *iPeerEntries[ii] ); |
|
766 CleanupStack::PushL( data ); |
|
767 |
|
768 CCertificate* cert; |
|
769 |
|
770 TRAPD( err, iWrapper->GetCertificateL( CertManager(), *iPeerEntries[ii], cert, KCMTrustedServerTokenUid )); |
|
771 if (( err == KErrArgument ) || ( err == KErrCorrupt )) |
|
772 { |
|
773 // This indicates that certificate is not according to X509 |
|
774 // specification or it is corrupted. Ignore certificate |
|
775 if( data->iPeerEntry ) |
|
776 { |
|
777 data->iPeerEntry->Release(); |
|
778 } |
|
779 CleanupStack::PopAndDestroy( data ); // data |
|
780 continue; |
|
781 } |
|
782 else |
|
783 { |
|
784 User::LeaveIfError( err ); |
|
785 } |
|
786 |
|
787 CleanupStack::PushL( cert ); |
|
788 |
|
789 TInt lenght = 0; |
|
790 |
|
791 lenght += iPeerEntries[ii]->Label().Length(); |
|
792 |
|
793 HBufC* label = HBufC::NewL( lenght ); |
|
794 label->Des().Append( iPeerEntries[ii]->Label() ); |
|
795 |
|
796 data->iPeerEntryLabel = label; |
|
797 iPeerLabelEntries.Append( data ); |
|
798 |
|
799 CleanupStack::PopAndDestroy( cert ); // cert |
|
800 CleanupStack::Pop( data ); // data |
|
801 break; |
|
802 } // EX509Certificate |
|
803 |
|
804 case EWTLSCertificate: |
|
805 // Do nothing for wtls certificates |
|
806 break; |
|
807 default: |
|
808 { |
|
809 User::Leave( KErrNotSupported ); |
|
810 } |
|
811 } // switch |
|
812 |
|
813 } // for |
|
814 |
|
815 // Sort the certificates. |
|
816 TLinearOrder<CCertManUICertData> order( ComparePeerLabels ); |
|
817 iPeerLabelEntries.Sort( order ); |
|
818 |
|
819 CERTMANUILOGGER_LEAVEFN("CCertManUIKeeper::RefreshPeerEntriesL" ); |
|
820 } |
|
821 |
|
822 |
|
823 // --------------------------------------------------------- |
|
824 // CCertManUIKeeper::RefreshDeviceCertEntriesL() |
|
825 // returns device certificates |
|
826 // --------------------------------------------------------- |
|
827 // |
|
828 void CCertManUIKeeper::RefreshDeviceCertEntriesL() |
|
829 { |
|
830 CERTMANUILOGGER_ENTERFN( |
|
831 "CCertManUIKeeper::RefreshUserCertEntriesL" ); |
|
832 |
|
833 iFilter->SetOwnerType( EUserCertificate ); |
|
834 iDeviceEntries.Close(); |
|
835 CUnifiedCertStore*& store = CertManager(); |
|
836 |
|
837 iWrapper->ListL( store, &iDeviceEntries, *iFilter, KCMDeviceCertStoreTokenUid ); |
|
838 |
|
839 iDeviceLabelEntries.Close(); |
|
840 LOG_WRITE_FORMAT(" Device entries found %i", iDeviceEntries.Count()); |
|
841 for ( TInt i = 0; i < iDeviceEntries.Count(); i++ ) |
|
842 { |
|
843 switch ( iDeviceEntries[i]->CertificateFormat() ) |
|
844 { |
|
845 case EX509Certificate: |
|
846 { |
|
847 LOG_WRITE_FORMAT(" User X509 certificate, index %i", i); |
|
848 CCertManUICertData* data = new (ELeave) CCertManUICertData(); |
|
849 data->iDeviceEntry = CCTCertInfo::NewL( *iDeviceEntries[i] ); |
|
850 CleanupStack::PushL( data ); |
|
851 HBufC* pri = NULL; |
|
852 HBufC* sec = NULL; |
|
853 |
|
854 CCertificate* cert = NULL; |
|
855 TRAPD(error, iWrapper->GetCertificateL( CertManager(), *iDeviceEntries[i], cert, KCMDeviceCertStoreTokenUid )); |
|
856 |
|
857 if( error == KErrArgument) |
|
858 { |
|
859 LOG_WRITE("Corrupted Device certificate detected"); |
|
860 CleanupStack::PopAndDestroy( data ); |
|
861 break; |
|
862 } |
|
863 else if ( error != KErrNone ) |
|
864 { |
|
865 LOG_WRITE_FORMAT(" GetCertificateL leaves, error code %i", error); |
|
866 User::Leave( error ); |
|
867 } |
|
868 else |
|
869 { |
|
870 CleanupStack::PushL( cert ); |
|
871 } |
|
872 |
|
873 X509CertNameParser::PrimaryAndSecondaryNameL |
|
874 ( *((CX509Certificate*)cert), pri, sec, iDeviceEntries[i]->Label()); |
|
875 |
|
876 CleanupStack::PushL( pri ); |
|
877 CleanupStack::PushL( sec ); |
|
878 |
|
879 TInt lenght = 0; |
|
880 |
|
881 lenght += iDeviceEntries[i]->Label().Length(); |
|
882 |
|
883 if ( pri ) |
|
884 { |
|
885 lenght += pri->Length(); |
|
886 } |
|
887 if ( sec && !(iDeviceEntries[i]->Label().Length()) ) |
|
888 { |
|
889 lenght += sec->Length(); |
|
890 } |
|
891 lenght += KNameSeparator.iTypeLength; |
|
892 |
|
893 HBufC* label = HBufC::NewL( lenght ); |
|
894 label->Des().Append( iDeviceEntries[i]->Label() ); |
|
895 |
|
896 if ( pri ) |
|
897 { |
|
898 label->Des().Append( KNameSeparator ); |
|
899 label->Des().Append( pri->Des() ); |
|
900 } |
|
901 if ( sec && !(iDeviceEntries[i]->Label().Length()) ) |
|
902 { |
|
903 label->Des().Append( sec->Des() ); |
|
904 } |
|
905 |
|
906 data->iDeviceEntryLabel = label; |
|
907 iDeviceLabelEntries.Append( data ); |
|
908 |
|
909 CleanupStack::PopAndDestroy( 3 ); // cert, pri, sec |
|
910 CleanupStack::Pop( data ); // data |
|
911 break; |
|
912 } // EX509Certificate |
|
913 |
|
914 case EX509CertificateUrl: |
|
915 { |
|
916 LOG_WRITE_FORMAT(" User X509URL certificate, index %i", i); |
|
917 CCertManUICertData* urlCertData = new (ELeave) CCertManUICertData(); |
|
918 urlCertData->iDeviceEntry = CCTCertInfo::NewL( *iDeviceEntries[i] ); |
|
919 CleanupStack::PushL( urlCertData ); |
|
920 |
|
921 CCertificate* cert = NULL; |
|
922 TRAPD(error, iWrapper->GetCertificateL( CertManager(), *iDeviceEntries[i], cert, KCMDeviceCertStoreTokenUid )); |
|
923 if( error == KErrArgument) |
|
924 { |
|
925 LOG_WRITE("Corrupted user certificate detected"); |
|
926 CleanupStack::PopAndDestroy( urlCertData ); // urlCertData |
|
927 break; |
|
928 } |
|
929 else if ( error != KErrNone ) |
|
930 { |
|
931 LOG_WRITE_FORMAT(" GetCertificateL leaves, error code %i", error); |
|
932 User::Leave(error); |
|
933 } |
|
934 else |
|
935 { |
|
936 CleanupStack::PushL( cert ); |
|
937 } |
|
938 |
|
939 |
|
940 HBufC* UrlLabel = HBufC::NewL( 20 ); |
|
941 UrlLabel->Des().Append( _L("URL UserCert")); |
|
942 |
|
943 urlCertData->iDeviceEntryLabel = UrlLabel; |
|
944 iDeviceLabelEntries.Append( urlCertData ); |
|
945 |
|
946 CleanupStack::PopAndDestroy( cert ); // cert |
|
947 CleanupStack::Pop( urlCertData ); // data |
|
948 break; |
|
949 } |
|
950 default: |
|
951 { |
|
952 LOG_WRITE_FORMAT( "Unsupported certificate format 0x%x", |
|
953 iDeviceEntries[i]->CertificateFormat() ); |
|
954 } |
|
955 } // switch |
|
956 |
|
957 } // for |
|
958 |
|
959 // Sort the certificates. |
|
960 TLinearOrder<CCertManUICertData> order( CompareDeviceLabels ); |
|
961 iDeviceLabelEntries.Sort( order ); |
|
962 |
|
963 CERTMANUILOGGER_LEAVEFN( |
|
964 "CCertManUIKeeper::RefreshDeviceCertEntriesL" ); |
|
965 } |
|
966 |
|
967 |
|
968 |
|
969 // --------------------------------------------------------- |
|
970 // CCertManUIKeeper::ShowErrorNoteL( TInt aError ) |
|
971 // Shows error note |
|
972 // --------------------------------------------------------- |
|
973 // |
|
974 void CCertManUIKeeper::ShowErrorNoteL( TInt aError ) |
|
975 { |
|
976 CERTMANUILOGGER_ENTERFN( "CCertManUIKeeper::ShowErrorNoteL" ); |
|
977 // Make sure wait dialog isn't running |
|
978 CloseWaitDialogL(); |
|
979 // Display error note |
|
980 TInt resourceid(0); |
|
981 |
|
982 switch ( aError ) |
|
983 { |
|
984 case KErrCorrupt: |
|
985 { |
|
986 resourceid = R_ERROR_NOTE_TEXT_CACERTS_DB_CORRUPTED; |
|
987 break; |
|
988 } |
|
989 case KErrCancel: |
|
990 { |
|
991 // Show nothing |
|
992 break; |
|
993 } |
|
994 default: |
|
995 { |
|
996 resourceid = R_ERROR_NOTE_TEXT_INTERNAL_ERROR; |
|
997 break; |
|
998 } |
|
999 } |
|
1000 |
|
1001 if ( resourceid != 0 ) |
|
1002 { |
|
1003 HBufC* string = StringLoader::LoadLC( resourceid ); |
|
1004 CAknErrorNote* note = new ( ELeave ) CAknErrorNote( ETrue ); |
|
1005 note->ExecuteLD( *string ); |
|
1006 CleanupStack::PopAndDestroy(); // string |
|
1007 } |
|
1008 |
|
1009 CERTMANUILOGGER_LEAVEFN( "CCertManUIKeeper::ShowErrorNoteL" ); |
|
1010 } |
|
1011 |
|
1012 // --------------------------------------------------------- |
|
1013 // CCertManUIKeeper::StartWaitDialogL( TInt aDialogSelector ) |
|
1014 // Displays wait dialog |
|
1015 // --------------------------------------------------------- |
|
1016 // |
|
1017 void CCertManUIKeeper::StartWaitDialogL( TInt aDialogSelector ) |
|
1018 { |
|
1019 iCertmanUIDialog->StartWaitDialogL( aDialogSelector ); |
|
1020 } |
|
1021 |
|
1022 // --------------------------------------------------------- |
|
1023 // CCertManUIKeeper::CloseWaitDialogL( TInt aDialogSelector ) |
|
1024 // Closes wait dialog |
|
1025 // --------------------------------------------------------- |
|
1026 // |
|
1027 void CCertManUIKeeper::CloseWaitDialogL() |
|
1028 { |
|
1029 iCertmanUIDialog->CloseWaitDialogL(); |
|
1030 } |
|
1031 |
|
1032 //--------------------------------------------------------------- |
|
1033 // CCertManUIKeeper::ReadLocalVariationL |
|
1034 // Reads local variation settings |
|
1035 //--------------------------------------------------------------- |
|
1036 void CCertManUIKeeper::ReadLocalVariationL() |
|
1037 { |
|
1038 iLocalFeaturesMask |= KSecurityUIsNoNativeAppTrustSettingChange; |
|
1039 } |
|
1040 |
|
1041 //--------------------------------------------------------------- |
|
1042 // CCertManUIKeeper::IsLocalFeatureSupported |
|
1043 // Check whether local variation setting is defined |
|
1044 //--------------------------------------------------------------- |
|
1045 TBool CCertManUIKeeper::IsLocalFeatureSupported( const TInt aFeature ) const |
|
1046 { |
|
1047 return ( iLocalFeaturesMask & aFeature ); |
|
1048 } |
|
1049 |
|
1050 // End of File |