1 /* |
|
2 * Copyright (c) 2010 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 <unifiedcertstore.h> |
|
23 #include <unifiedkeystore.h> |
|
24 #include <mctwritablecertstore.h> |
|
25 #include <X509CertNameParser.h> |
|
26 |
|
27 #include <HbMessageBox> |
|
28 |
|
29 #include <QErrorMessage> |
|
30 #include <../../inc/cpsecplugins.h> |
|
31 #include "cpcertdatacontainer.h" |
|
32 #include "cpcertmanuisyncwrapper.h" |
|
33 |
|
34 // CONSTANTS |
|
35 _LIT( KNameSeparator, " " ); |
|
36 |
|
37 // ============================= LOCAL FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // TInt CompareCALabels( const CCTCertInfo& cert1, const CCTCertInfo& cert2 ) |
|
41 // Compares two labels. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 TInt CompareCALabels( |
|
45 const CpCertManUICertData& cert1, |
|
46 const CpCertManUICertData& cert2 ) |
|
47 { |
|
48 return ( (cert1.iCAEntryLabel->Des()). |
|
49 CompareF( cert2.iCAEntryLabel->Des() ) ); |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // TInt CompareUserLabels( const CCTCertInfo& cert1, const CCTCertInfo& cert2 ) |
|
54 // Compares two labels. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 TInt CompareUserLabels( |
|
58 const CpCertManUICertData& cert1, |
|
59 const CpCertManUICertData& cert2 ) |
|
60 { |
|
61 return ( (cert1.iUserEntryLabel->Des()). |
|
62 CompareF( cert2.iUserEntryLabel->Des() ) ); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // TInt ComparePeerLabels( const CCTCertInfo& cert1, const CCTCertInfo& cert2 ) |
|
67 // Compares two labels. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 TInt ComparePeerLabels( |
|
71 const CpCertManUICertData& cert1, |
|
72 const CpCertManUICertData& cert2 ) |
|
73 { |
|
74 return ( (cert1.iPeerEntryLabel->Des()). |
|
75 CompareF( cert2.iPeerEntryLabel->Des() ) ); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // TInt CompareDeviceLabels( const CCTCertInfo& cert1, const CCTCertInfo& cert2 ) |
|
80 // Compares two labels. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 TInt CompareDeviceLabels( |
|
84 const CpCertManUICertData& cert1, |
|
85 const CpCertManUICertData& cert2 ) |
|
86 { |
|
87 return ( (cert1.iDeviceEntryLabel->Des()). |
|
88 CompareF( cert2.iDeviceEntryLabel->Des() ) ); |
|
89 } |
|
90 |
|
91 |
|
92 // ================= HELPER CLASS =========================== |
|
93 |
|
94 // Constructor. |
|
95 CpCertManUICertData::CpCertManUICertData() |
|
96 { |
|
97 } |
|
98 |
|
99 // Destructor. |
|
100 CpCertManUICertData::~CpCertManUICertData() |
|
101 { |
|
102 delete iCAEntryLabel; |
|
103 delete iUserEntryLabel; |
|
104 delete iPeerEntryLabel; |
|
105 delete iDeviceEntryLabel; |
|
106 } |
|
107 |
|
108 // Releases Certificate entries. |
|
109 void CpCertManUICertData::Release() |
|
110 { |
|
111 RDEBUG("0", 0); |
|
112 if ( iCAEntry ) |
|
113 { |
|
114 iCAEntry->Release(); |
|
115 } |
|
116 |
|
117 if ( iUserEntry ) |
|
118 { |
|
119 iUserEntry->Release(); |
|
120 } |
|
121 |
|
122 if ( iPeerEntry ) |
|
123 { |
|
124 iPeerEntry->Release(); |
|
125 } |
|
126 |
|
127 if ( iDeviceEntry ) |
|
128 { |
|
129 iDeviceEntry->Release(); |
|
130 } |
|
131 |
|
132 delete this; |
|
133 } |
|
134 |
|
135 // ================= MEMBER FUNCTIONS ======================= |
|
136 |
|
137 // --------------------------------------------------------- |
|
138 // CCertManUIKeeper::CCertManUIKeeper() |
|
139 // Constructor with parent |
|
140 // --------------------------------------------------------- |
|
141 // |
|
142 CpCertDataContainer::CpCertDataContainer() |
|
143 { |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------- |
|
147 // CCertManUIKeeper::~CCertManUIKeeper() |
|
148 // Destructor |
|
149 // --------------------------------------------------------- |
|
150 // |
|
151 CpCertDataContainer::~CpCertDataContainer() |
|
152 { |
|
153 iCALabelEntries.Close(); |
|
154 iUserLabelEntries.Close(); |
|
155 iPeerLabelEntries.Close(); |
|
156 iDeviceLabelEntries.Close(); |
|
157 |
|
158 if ( iWrapper ) |
|
159 { |
|
160 iWrapper->Cancel(); |
|
161 } |
|
162 delete iWrapper; |
|
163 |
|
164 delete iFilter; |
|
165 delete iKeyFilter; |
|
166 delete iStore; |
|
167 delete iKeyStore; |
|
168 |
|
169 iCAEntries.Close(); |
|
170 iUserEntries.Close(); |
|
171 iPeerEntries.Close(); |
|
172 iDeviceEntries.Close(); |
|
173 iKeyEntries.Close(); |
|
174 |
|
175 iRfs.Close(); |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------- |
|
179 // CCertManUIKeeper* CCertManUIKeeper::NewL(const TRect& aRect, TUid aViewId) |
|
180 // --------------------------------------------------------- |
|
181 // |
|
182 |
|
183 CpCertDataContainer* CpCertDataContainer::NewL() |
|
184 { |
|
185 CpCertDataContainer* self = new ( ELeave ) CpCertDataContainer; |
|
186 CleanupStack::PushL( self ); |
|
187 self->ConstructL(); |
|
188 CleanupStack::Pop(self); |
|
189 return self; |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------- |
|
193 // CCertManUIKeeper* CCertManUIKeeper::NewLC( |
|
194 // const TRect& aRect, TUid aViewId) |
|
195 // --------------------------------------------------------- |
|
196 // |
|
197 CpCertDataContainer* CpCertDataContainer::NewLC() |
|
198 { |
|
199 CpCertDataContainer* self = new ( ELeave ) CpCertDataContainer; |
|
200 CleanupStack::PushL( self ); |
|
201 self->ConstructL(); |
|
202 return self; |
|
203 } |
|
204 |
|
205 |
|
206 // --------------------------------------------------------- |
|
207 // CCertManUIKeeper::ConstructL( |
|
208 // const TRect& aRect, TUid aViewId |
|
209 // |
|
210 // --------------------------------------------------------- |
|
211 // |
|
212 void CpCertDataContainer::ConstructL() |
|
213 { |
|
214 RDEBUG("0", 0); |
|
215 // Ensure that file server session is succesfully created |
|
216 User::LeaveIfError( iRfs.Connect() ); |
|
217 |
|
218 TRAPD ( error, iStore = CUnifiedCertStore::NewL( iRfs, ETrue ) ); |
|
219 |
|
220 if ( error == KErrNotSupported || error == KErrNotReady |
|
221 || error == KErrArgument || error == KErrNotFound ) |
|
222 { |
|
223 // Something may be wrong with the databases |
|
224 ShowErrorNoteL( error ); |
|
225 } |
|
226 |
|
227 User::LeaveIfError( error ); |
|
228 |
|
229 iWrapper = CpCertManUISyncWrapper::NewL(); |
|
230 iWrapper->InitStoreL( iStore ); |
|
231 |
|
232 iFilter = CCertAttributeFilter::NewL(); |
|
233 |
|
234 TRAP( error, iKeyStore = CUnifiedKeyStore::NewL( iRfs ) ); |
|
235 |
|
236 if (error == KErrNotSupported || error == KErrNotReady |
|
237 || error == KErrArgument || error == KErrNotFound) |
|
238 { |
|
239 // Something is wrong with key stores |
|
240 ShowErrorNoteL( error ); |
|
241 } |
|
242 |
|
243 User::LeaveIfError( error ); |
|
244 |
|
245 iWrapper->InitStoreL( iKeyStore ); |
|
246 iKeyEntries.Close(); |
|
247 |
|
248 } |
|
249 |
|
250 |
|
251 // --------------------------------------------------------- |
|
252 // CCertManUIKeeper::CertManager() |
|
253 // --------------------------------------------------------- |
|
254 // |
|
255 CUnifiedCertStore*& CpCertDataContainer::CertManager() |
|
256 { |
|
257 return iStore; |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------- |
|
261 // CCertManUIKeeper::KeyManager() |
|
262 // --------------------------------------------------------- |
|
263 // |
|
264 CUnifiedKeyStore*& CpCertDataContainer::KeyManager() |
|
265 { |
|
266 return iKeyStore; |
|
267 } |
|
268 |
|
269 // --------------------------------------------------------- |
|
270 // CCertManUIKeeper::RefreshCAEntriesL() |
|
271 // Checks that cacerts.dat file is not corrupted and |
|
272 // returns CA certificates from it |
|
273 // --------------------------------------------------------- |
|
274 // |
|
275 void CpCertDataContainer::RefreshCAEntriesL() |
|
276 { |
|
277 RDEBUG("0", 0); |
|
278 iFilter->SetOwnerType( ECACertificate ); |
|
279 iCAEntries.Close(); |
|
280 CUnifiedCertStore*& store = CertManager(); |
|
281 iWrapper->ListL( store, &iCAEntries, *iFilter ); |
|
282 |
|
283 iCALabelEntries.Close(); |
|
284 for ( TInt ii = 0; ii < iCAEntries.Count(); ii++ ) |
|
285 { |
|
286 switch ( iCAEntries[ii]->CertificateFormat() ) |
|
287 { |
|
288 case EX509Certificate: |
|
289 { |
|
290 CpCertManUICertData* data = new ( ELeave ) CpCertManUICertData(); |
|
291 CleanupStack::PushL( data ); |
|
292 data->iCAEntry = CCTCertInfo::NewL( *iCAEntries[ii] ); |
|
293 |
|
294 HBufC* pri = NULL; |
|
295 HBufC* sec = NULL; |
|
296 |
|
297 CCertificate* cert; |
|
298 |
|
299 TRAPD(err, iWrapper->GetCertificateL( CertManager(), *iCAEntries[ii], cert )); |
|
300 if (( err == KErrArgument ) || ( err == KErrCorrupt )) |
|
301 { |
|
302 // This indicates that certificate is not according to X509 |
|
303 // specification or it is corrupted. Ignore certificate |
|
304 if(data->iCAEntry) |
|
305 { |
|
306 data->iCAEntry->Release(); |
|
307 } |
|
308 CleanupStack::PopAndDestroy( data ); // data |
|
309 continue; |
|
310 } |
|
311 else |
|
312 { |
|
313 User::LeaveIfError( err ); |
|
314 } |
|
315 |
|
316 CleanupStack::PushL( cert ); |
|
317 |
|
318 X509CertNameParser::PrimaryAndSecondaryNameL |
|
319 ( *((CX509Certificate*)cert), pri, sec, iCAEntries[ii]->Label()); |
|
320 |
|
321 CleanupStack::PushL( pri ); |
|
322 CleanupStack::PushL( sec ); |
|
323 |
|
324 TInt lenght = 0; |
|
325 |
|
326 lenght += iCAEntries[ii]->Label().Length(); |
|
327 |
|
328 if ( pri ) |
|
329 { |
|
330 lenght += pri->Length(); |
|
331 } |
|
332 if ( sec && !(iCAEntries[ii]->Label().Length()) ) |
|
333 { |
|
334 lenght += sec->Length(); |
|
335 } |
|
336 lenght += KNameSeparator.iTypeLength; |
|
337 |
|
338 HBufC* label = HBufC::NewL( lenght ); |
|
339 label->Des().Append( iCAEntries[ii]->Label() ); |
|
340 |
|
341 if ( pri ) |
|
342 { |
|
343 label->Des().Append( KNameSeparator ); |
|
344 label->Des().Append( pri->Des() ); |
|
345 } |
|
346 if ( sec && !(iCAEntries[ii]->Label().Length()) ) |
|
347 { |
|
348 label->Des().Append( sec->Des() ); |
|
349 } |
|
350 |
|
351 data->iCAEntryLabel = label; |
|
352 iCALabelEntries.Append( data ); |
|
353 |
|
354 CleanupStack::PopAndDestroy( 3, cert ); // pri, sec |
|
355 CleanupStack::Pop( data ); |
|
356 break; |
|
357 } // EX509Certificate |
|
358 |
|
359 case EWTLSCertificate: |
|
360 // Do nothing for wtls certificates |
|
361 break; |
|
362 default: |
|
363 { |
|
364 User::Leave( KErrNotSupported ); |
|
365 } |
|
366 } // switch |
|
367 |
|
368 } // for |
|
369 |
|
370 // Sort the certificates. |
|
371 TLinearOrder<CpCertManUICertData> order( CompareCALabels ); |
|
372 iCALabelEntries.Sort( order ); |
|
373 |
|
374 } |
|
375 |
|
376 // --------------------------------------------------------- |
|
377 // CCertManUIKeeper::RefreshPeerCertEntriesL() |
|
378 // Checks that Trusted site certificate store is |
|
379 // not corrupted and returns Peer certificates from it |
|
380 // --------------------------------------------------------- |
|
381 // |
|
382 void CpCertDataContainer::RefreshPeerCertEntriesL() |
|
383 { |
|
384 RDEBUG("0", 0); |
|
385 iFilter->SetOwnerType( EPeerCertificate ); |
|
386 iPeerEntries.Close(); |
|
387 CUnifiedCertStore*& store = CertManager(); |
|
388 |
|
389 iWrapper->ListL( store, &iPeerEntries, *iFilter, KCMTrustedServerTokenUid ); |
|
390 |
|
391 iPeerLabelEntries.Close(); |
|
392 |
|
393 for ( TInt ii = 0; ii < iPeerEntries.Count(); ii++ ) |
|
394 { |
|
395 switch ( iPeerEntries[ii]->CertificateFormat() ) |
|
396 { |
|
397 case EX509Certificate: |
|
398 { |
|
399 CpCertManUICertData* data = new (ELeave) CpCertManUICertData(); |
|
400 CleanupStack::PushL( data ); |
|
401 data->iPeerEntry = CCTCertInfo::NewL( *iPeerEntries[ii] ); |
|
402 |
|
403 CCertificate* cert; |
|
404 |
|
405 TRAPD( err, iWrapper->GetCertificateL( CertManager(), *iPeerEntries[ii], cert, KCMTrustedServerTokenUid )); |
|
406 if (( err == KErrArgument ) || ( err == KErrCorrupt )) |
|
407 { |
|
408 // This indicates that certificate is not according to X509 |
|
409 // specification or it is corrupted. Ignore certificate |
|
410 if( data->iPeerEntry ) |
|
411 { |
|
412 data->iPeerEntry->Release(); |
|
413 } |
|
414 CleanupStack::PopAndDestroy( data ); // data |
|
415 continue; |
|
416 } |
|
417 else |
|
418 { |
|
419 User::LeaveIfError( err ); |
|
420 } |
|
421 |
|
422 CleanupStack::PushL( cert ); |
|
423 |
|
424 TInt lenght = 0; |
|
425 |
|
426 lenght += iPeerEntries[ii]->Label().Length(); |
|
427 |
|
428 HBufC* label = HBufC::NewL( lenght ); |
|
429 label->Des().Append( iPeerEntries[ii]->Label() ); |
|
430 |
|
431 data->iPeerEntryLabel = label; |
|
432 iPeerLabelEntries.Append( data ); |
|
433 |
|
434 CleanupStack::PopAndDestroy( cert ); // cert |
|
435 CleanupStack::Pop( data ); // data |
|
436 break; |
|
437 } // EX509Certificate |
|
438 |
|
439 case EWTLSCertificate: |
|
440 // Do nothing for wtls certificates |
|
441 break; |
|
442 default: |
|
443 { |
|
444 User::Leave( KErrNotSupported ); |
|
445 } |
|
446 } // switch |
|
447 |
|
448 } // for |
|
449 |
|
450 // Sort the certificates. |
|
451 TLinearOrder<CpCertManUICertData> order( ComparePeerLabels ); |
|
452 iPeerLabelEntries.Sort( order ); |
|
453 |
|
454 } |
|
455 |
|
456 |
|
457 // --------------------------------------------------------- |
|
458 // CCertManUIKeeper::RefreshUserCertEntriesL() |
|
459 // Checks that cacerts.dat file is not corrupted and |
|
460 // returns User certificates from it |
|
461 // --------------------------------------------------------- |
|
462 // |
|
463 void CpCertDataContainer::RefreshUserCertEntriesL() |
|
464 { |
|
465 RDEBUG("0", 0); |
|
466 iFilter->SetOwnerType( EUserCertificate ); |
|
467 iUserEntries.Close(); |
|
468 CUnifiedCertStore*& store = CertManager(); |
|
469 iWrapper->ListL( store, &iUserEntries, *iFilter ); |
|
470 |
|
471 iUserLabelEntries.Close(); |
|
472 |
|
473 for ( TInt i = 0; i < iUserEntries.Count(); i++ ) |
|
474 { |
|
475 |
|
476 if ( iUserEntries[i]->Handle().iTokenHandle.iTokenTypeUid == KCMDeviceCertStoreTokenUid ) |
|
477 { |
|
478 // User certificates from DeviceCertStore are not |
|
479 // shown in Personal certificate view. Ignore this certificate. |
|
480 break; |
|
481 } |
|
482 |
|
483 switch ( iUserEntries[i]->CertificateFormat() ) |
|
484 { |
|
485 case EX509Certificate: |
|
486 { |
|
487 CpCertManUICertData* data = new (ELeave) CpCertManUICertData(); |
|
488 CleanupStack::PushL( data ); |
|
489 data->iUserEntry = CCTCertInfo::NewL( *iUserEntries[i] ); |
|
490 |
|
491 HBufC* pri = NULL; |
|
492 HBufC* sec = NULL; |
|
493 |
|
494 CCertificate* cert = NULL; |
|
495 TRAPD(error, iWrapper->GetCertificateL( CertManager(), *iUserEntries[i], cert )); |
|
496 |
|
497 if( error == KErrArgument) |
|
498 { |
|
499 CleanupStack::PopAndDestroy( data ); |
|
500 break; |
|
501 } |
|
502 else if ( error != KErrNone ) |
|
503 { |
|
504 User::Leave( error ); |
|
505 } |
|
506 else |
|
507 { |
|
508 CleanupStack::PushL( cert ); |
|
509 } |
|
510 |
|
511 X509CertNameParser::PrimaryAndSecondaryNameL |
|
512 ( *((CX509Certificate*)cert), pri, sec, iUserEntries[i]->Label()); |
|
513 |
|
514 CleanupStack::PushL( pri ); |
|
515 CleanupStack::PushL( sec ); |
|
516 |
|
517 TInt lenght = 0; |
|
518 |
|
519 lenght += iUserEntries[i]->Label().Length(); |
|
520 |
|
521 if ( pri ) |
|
522 { |
|
523 lenght += pri->Length(); |
|
524 } |
|
525 if ( sec && !(iUserEntries[i]->Label().Length()) ) |
|
526 { |
|
527 lenght += sec->Length(); |
|
528 } |
|
529 lenght += KNameSeparator.iTypeLength; |
|
530 |
|
531 HBufC* label = HBufC::NewL( lenght ); |
|
532 label->Des().Append( iUserEntries[i]->Label() ); |
|
533 |
|
534 if ( pri ) |
|
535 { |
|
536 label->Des().Append( KNameSeparator ); |
|
537 label->Des().Append( pri->Des() ); |
|
538 } |
|
539 if ( sec && !(iUserEntries[i]->Label().Length()) ) |
|
540 { |
|
541 label->Des().Append( sec->Des() ); |
|
542 } |
|
543 |
|
544 data->iUserEntryLabel = label; |
|
545 iUserLabelEntries.Append( data ); |
|
546 |
|
547 CleanupStack::PopAndDestroy( 3, cert ); // pri, sec |
|
548 CleanupStack::Pop( data ); // data |
|
549 break; |
|
550 } // EX509Certificate |
|
551 |
|
552 case EX509CertificateUrl: |
|
553 { |
|
554 CpCertManUICertData* urlCertData = new (ELeave) CpCertManUICertData(); |
|
555 CleanupStack::PushL( urlCertData ); |
|
556 urlCertData->iUserEntry = CCTCertInfo::NewL( *iUserEntries[i] ); |
|
557 |
|
558 CCertificate* cert = NULL; |
|
559 TRAPD(error, iWrapper->GetCertificateL( CertManager(), *iUserEntries[i], cert )); |
|
560 if( error == KErrArgument ) |
|
561 { |
|
562 CleanupStack::PopAndDestroy( urlCertData ); // urlCertData |
|
563 break; |
|
564 } |
|
565 else if ( error != KErrNone ) |
|
566 { |
|
567 User::Leave(error); |
|
568 } |
|
569 else |
|
570 { |
|
571 CleanupStack::PushL( cert ); |
|
572 } |
|
573 |
|
574 _LIT(KUrlUserCert, "URL UserCert"); |
|
575 HBufC* UrlLabel = HBufC::NewL( KUrlUserCert().Length() ); |
|
576 UrlLabel->Des().Append( KUrlUserCert()); |
|
577 |
|
578 urlCertData->iUserEntryLabel = UrlLabel; |
|
579 iUserLabelEntries.Append( urlCertData ); |
|
580 |
|
581 CleanupStack::PopAndDestroy( cert ); // cert |
|
582 CleanupStack::Pop( urlCertData ); // data |
|
583 break; |
|
584 } |
|
585 } // switch |
|
586 |
|
587 } // for |
|
588 |
|
589 // Sort the certificates. |
|
590 TLinearOrder<CpCertManUICertData> order( CompareUserLabels ); |
|
591 iUserLabelEntries.Sort( order ); |
|
592 |
|
593 } |
|
594 |
|
595 // --------------------------------------------------------- |
|
596 // CCertManUIKeeper::RefreshDeviceCertEntriesL() |
|
597 // returns device certificates |
|
598 // --------------------------------------------------------- |
|
599 // |
|
600 void CpCertDataContainer::RefreshDeviceCertEntriesL() |
|
601 { |
|
602 RDEBUG("0", 0); |
|
603 iFilter->SetOwnerType( EUserCertificate ); |
|
604 iDeviceEntries.Close(); |
|
605 CUnifiedCertStore*& store = CertManager(); |
|
606 |
|
607 iWrapper->ListL( store, &iDeviceEntries, *iFilter, KCMDeviceCertStoreTokenUid ); |
|
608 |
|
609 iDeviceLabelEntries.Close(); |
|
610 for ( TInt i = 0; i < iDeviceEntries.Count(); i++ ) |
|
611 { |
|
612 switch ( iDeviceEntries[i]->CertificateFormat() ) |
|
613 { |
|
614 case EX509Certificate: |
|
615 { |
|
616 CpCertManUICertData* data = new (ELeave) CpCertManUICertData(); |
|
617 CleanupStack::PushL( data ); |
|
618 data->iDeviceEntry = CCTCertInfo::NewL( *iDeviceEntries[i] ); |
|
619 |
|
620 HBufC* pri = NULL; |
|
621 HBufC* sec = NULL; |
|
622 |
|
623 CCertificate* cert = NULL; |
|
624 TRAPD(error, iWrapper->GetCertificateL( CertManager(), *iDeviceEntries[i], cert, KCMDeviceCertStoreTokenUid )); |
|
625 |
|
626 if( error == KErrArgument) |
|
627 { |
|
628 CleanupStack::PopAndDestroy( data ); |
|
629 break; |
|
630 } |
|
631 else if ( error != KErrNone ) |
|
632 { |
|
633 User::Leave( error ); |
|
634 } |
|
635 else |
|
636 { |
|
637 CleanupStack::PushL( cert ); |
|
638 } |
|
639 |
|
640 X509CertNameParser::PrimaryAndSecondaryNameL |
|
641 ( *((CX509Certificate*)cert), pri, sec, iDeviceEntries[i]->Label()); |
|
642 |
|
643 CleanupStack::PushL( pri ); |
|
644 CleanupStack::PushL( sec ); |
|
645 |
|
646 TInt lenght = 0; |
|
647 |
|
648 lenght += iDeviceEntries[i]->Label().Length(); |
|
649 |
|
650 if ( pri ) |
|
651 { |
|
652 lenght += pri->Length(); |
|
653 } |
|
654 if ( sec && !(iDeviceEntries[i]->Label().Length()) ) |
|
655 { |
|
656 lenght += sec->Length(); |
|
657 } |
|
658 lenght += KNameSeparator.iTypeLength; |
|
659 |
|
660 HBufC* label = HBufC::NewL( lenght ); |
|
661 label->Des().Append( iDeviceEntries[i]->Label() ); |
|
662 |
|
663 if ( pri ) |
|
664 { |
|
665 label->Des().Append( KNameSeparator ); |
|
666 label->Des().Append( pri->Des() ); |
|
667 } |
|
668 if ( sec && !(iDeviceEntries[i]->Label().Length()) ) |
|
669 { |
|
670 label->Des().Append( sec->Des() ); |
|
671 } |
|
672 |
|
673 data->iDeviceEntryLabel = label; |
|
674 iDeviceLabelEntries.Append( data ); |
|
675 |
|
676 CleanupStack::PopAndDestroy( 3, cert ); // pri, sec |
|
677 CleanupStack::Pop( data ); // data |
|
678 break; |
|
679 } // EX509Certificate |
|
680 |
|
681 case EX509CertificateUrl: |
|
682 { |
|
683 CpCertManUICertData* urlCertData = new (ELeave) CpCertManUICertData(); |
|
684 CleanupStack::PushL( urlCertData ); |
|
685 urlCertData->iDeviceEntry = CCTCertInfo::NewL( *iDeviceEntries[i] ); |
|
686 |
|
687 CCertificate* cert = NULL; |
|
688 TRAPD(error, iWrapper->GetCertificateL( CertManager(), *iDeviceEntries[i], cert, KCMDeviceCertStoreTokenUid )); |
|
689 if( error == KErrArgument) |
|
690 { |
|
691 CleanupStack::PopAndDestroy( urlCertData ); // urlCertData |
|
692 break; |
|
693 } |
|
694 else if ( error != KErrNone ) |
|
695 { |
|
696 User::Leave(error); |
|
697 } |
|
698 else |
|
699 { |
|
700 CleanupStack::PushL( cert ); |
|
701 } |
|
702 |
|
703 _LIT(KUrlUserCert, "URL UserCert"); |
|
704 HBufC* UrlLabel = HBufC::NewL( KUrlUserCert().Length() ); |
|
705 UrlLabel->Des().Append( KUrlUserCert()); |
|
706 |
|
707 |
|
708 urlCertData->iDeviceEntryLabel = UrlLabel; |
|
709 iDeviceLabelEntries.Append( urlCertData ); |
|
710 |
|
711 CleanupStack::PopAndDestroy( cert ); // cert |
|
712 CleanupStack::Pop( urlCertData ); // data |
|
713 break; |
|
714 } |
|
715 } // switch |
|
716 |
|
717 } // for |
|
718 |
|
719 // Sort the certificates. |
|
720 TLinearOrder<CpCertManUICertData> order( CompareDeviceLabels ); |
|
721 iDeviceLabelEntries.Sort( order ); |
|
722 |
|
723 } |
|
724 |
|
725 // --------------------------------------------------------- |
|
726 // CCertManUIKeeper::ShowErrorNoteL( TInt aError ) |
|
727 // Shows error note |
|
728 // --------------------------------------------------------- |
|
729 // |
|
730 void CpCertDataContainer::ShowErrorNoteL( TInt aError ) |
|
731 { |
|
732 QString sError; |
|
733 switch ( aError ) |
|
734 { |
|
735 case KErrCorrupt: |
|
736 { |
|
737 sError = "Database corrupted. Some data might have been lost."; |
|
738 break; |
|
739 } |
|
740 case KErrCancel: |
|
741 { |
|
742 // Show nothing |
|
743 break; |
|
744 } |
|
745 default: |
|
746 { |
|
747 sError = "Internal error"; |
|
748 break; |
|
749 } |
|
750 } |
|
751 |
|
752 if ( sError.length() != 0 ) |
|
753 { |
|
754 HbMessageBox::information(sError); |
|
755 } |
|
756 } |
|
757 |
|