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