|
1 /* |
|
2 * Copyright (c) 2005-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 the CSecModUIModel class |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <unifiedkeystore.h> |
|
19 #include <mctauthobject.h> |
|
20 #include <mctkeystore.h> |
|
21 #include <securityerr.h> |
|
22 |
|
23 #include <qvector.h> |
|
24 #include <qpair.h> |
|
25 #include <qlabel.h> |
|
26 #include <qerrormessage.h> |
|
27 #include <qstring.h> |
|
28 |
|
29 #include <hbmessagebox.h> |
|
30 |
|
31 #include "cpsecmodmodel.h" |
|
32 #include "cpsecmodsyncwrapper.h" |
|
33 |
|
34 const TInt KWIMStoreUid ( 0x101F79D9 ); |
|
35 _LIT(KSecModUIPanic, "Security Module UI panic"); |
|
36 |
|
37 // ============================= LOCAL FUNCTIONS =============================== |
|
38 GLDEF_C void Panic(TInt aPanic) |
|
39 { |
|
40 User::Panic(KSecModUIPanic, aPanic); |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CSecModUIModel::NewL() |
|
45 // Two-phased constructor. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CSecModUIModel* CSecModUIModel::NewL() |
|
49 { |
|
50 CSecModUIModel* self = new( ELeave ) CSecModUIModel(); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 CleanupStack::Pop(self); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CSecModUIModel::CSecModUIModel |
|
59 // C++ default constructor can NOT contain any code, that might leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CSecModUIModel::CSecModUIModel() |
|
63 {} |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CSecModUIModel::~CSecModUIModel |
|
67 // C++ destructor |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 |
|
71 CSecModUIModel::~CSecModUIModel() |
|
72 { |
|
73 delete iWrapper; |
|
74 ResetAndDestroyCTObjects(); |
|
75 } |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CSecModUIModel::ResetAndDestroyCTObjects(): Cleans up all objects referenced |
|
78 // through the crypto token framework. |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 void CSecModUIModel::ResetAndDestroyCTObjects() |
|
82 { |
|
83 ResetAndDestroyAOs(); |
|
84 iAOKeyStores.Reset(); |
|
85 delete iUnifiedKeyStore; |
|
86 iUnifiedKeyStore = NULL; |
|
87 iKeyStore = NULL; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CSecModUIModel::ResetAndDestroyAOs(): Cleans up the list of auth objects. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CSecModUIModel::ResetAndDestroyAOs() |
|
95 { |
|
96 if (iAOList) |
|
97 { |
|
98 iAOList->Release(); |
|
99 iAOList = NULL; |
|
100 } |
|
101 if (iAOArray.Count() > 0 && |
|
102 iAOArray[0]->Token().TokenType().Type().iUid == KTokenTypeFileKeystore) |
|
103 { |
|
104 iAOArray.Reset(); |
|
105 } |
|
106 else |
|
107 { |
|
108 iAOArray.Close(); |
|
109 } |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CSecModUIModel::ConstructL() |
|
114 // Symbian 2nd phase constructor can leave. |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void CSecModUIModel::ConstructL() |
|
118 { |
|
119 InitializeKeyStoreL(); |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CSecModUIModel::InitializeKeyStoreL() |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CSecModUIModel::InitializeKeyStoreL() |
|
127 { |
|
128 ResetAndDestroyCTObjects(); |
|
129 |
|
130 // Ensure that file server session is succesfully created |
|
131 User::LeaveIfError( iRfs.Connect() ); |
|
132 |
|
133 iUnifiedKeyStore = CUnifiedKeyStore::NewL(iRfs); |
|
134 |
|
135 if (iWrapper == NULL) |
|
136 { |
|
137 iWrapper = CSecModUISyncWrapper::NewL(); |
|
138 } |
|
139 |
|
140 TInt err = iWrapper->Initialize(*iUnifiedKeyStore); |
|
141 |
|
142 ShowErrorNote(err); |
|
143 if (KErrNone != err && KErrHardwareNotAvailable != err) |
|
144 { |
|
145 User::Leave(err); |
|
146 } |
|
147 TInt keyStoreCount = iUnifiedKeyStore->KeyStoreCount(); |
|
148 if (0 >= keyStoreCount) |
|
149 { |
|
150 return; |
|
151 } |
|
152 |
|
153 RMPointerArray<CCTKeyInfo> keyInfos; |
|
154 CleanupClosePushL(keyInfos); |
|
155 TCTKeyAttributeFilter filter; |
|
156 TInt keyInfoCount = 0; |
|
157 filter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys; |
|
158 |
|
159 for (TInt i = 0; i < keyStoreCount; i++) |
|
160 { |
|
161 err = iWrapper->ListKeys(iUnifiedKeyStore->KeyStore(i), keyInfos, filter); |
|
162 User::LeaveIfError(err); |
|
163 //If list ok, append the AO, otherwise go next |
|
164 keyInfoCount = keyInfos.Count(); |
|
165 for (TInt j = 0; j < keyInfoCount; j++) |
|
166 { |
|
167 // Check that keystore has at least one AO. |
|
168 if (NULL != keyInfos[j]->Protector()) |
|
169 { |
|
170 // If keystore has AO, add it to the array. |
|
171 User::LeaveIfError( |
|
172 iAOKeyStores.Append(&(iUnifiedKeyStore->KeyStore(i)))); |
|
173 break; |
|
174 } |
|
175 } |
|
176 } |
|
177 CleanupStack::PopAndDestroy(&keyInfos); |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CSecModUIModel::LoadTokenLabelsL() |
|
182 // Retrieves the description and location of all tokens. |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 QMap<QString,QString> CSecModUIModel::LoadTokenLabelsL() |
|
186 { |
|
187 |
|
188 TInt keyStoreCount = iAOKeyStores.Count(); |
|
189 QMap<QString, QString> labelList; |
|
190 |
|
191 if (0 == keyStoreCount) |
|
192 { |
|
193 return labelList; |
|
194 } |
|
195 |
|
196 for (TInt i = 0; i < keyStoreCount; i++) |
|
197 { |
|
198 QString keystoreLabel = 0; |
|
199 if (iAOKeyStores[i]->Token().TokenType().Type().iUid == KTokenTypeFileKeystore ) |
|
200 { |
|
201 keystoreLabel = "Phone keystore"; |
|
202 } |
|
203 else if(iAOKeyStores[i]->Token().TokenType().Type().iUid == KWIMStoreUid ) |
|
204 { |
|
205 const TDesC& label = iAOKeyStores[i]->Token().Label(); |
|
206 keystoreLabel = QString( (QChar*) label.Ptr(), label.Length()); |
|
207 } |
|
208 else |
|
209 { |
|
210 continue; |
|
211 } |
|
212 QString location = Location(iAOKeyStores[i]->Token().TokenType().Type()); |
|
213 labelList.insert(keystoreLabel,location); |
|
214 } |
|
215 return labelList; |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CSecModUIModel::Location() |
|
220 // Identifies the location of the keystore based on the Uid. |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 QString CSecModUIModel::Location( TUid aUid ) const |
|
224 { |
|
225 QString location = 0; |
|
226 |
|
227 switch ( aUid.iUid ) |
|
228 { |
|
229 case KTokenTypeFileKeystore: |
|
230 { |
|
231 location = "\nPhone memory"; |
|
232 break; |
|
233 } |
|
234 case KWIMStoreUid: |
|
235 { |
|
236 location = "\nSmart card"; |
|
237 break; |
|
238 } |
|
239 default: |
|
240 { |
|
241 break; |
|
242 } |
|
243 } |
|
244 return location; |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CSecModUIModel::ShowErrorNote(TInt aError) const |
|
249 // Displays appropriate error message based on the error code. |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 void CSecModUIModel::ShowErrorNote(TInt aError) const |
|
253 { |
|
254 QString sError; |
|
255 |
|
256 switch (aError) |
|
257 { |
|
258 case KErrCancel: |
|
259 case KErrLocked: |
|
260 case KErrNone: |
|
261 { |
|
262 break; |
|
263 } |
|
264 case KErrInUse: |
|
265 { |
|
266 sError = "Key is currently in use. Unable to delete. Close applications and try again."; |
|
267 break; |
|
268 } |
|
269 case KErrBadPassphrase: |
|
270 { |
|
271 sError = "Code incorrect"; |
|
272 break; |
|
273 } |
|
274 case KErrHardwareNotAvailable: // flow thru |
|
275 default: |
|
276 { |
|
277 sError = "Security module internal error"; |
|
278 break; |
|
279 } |
|
280 } |
|
281 |
|
282 if ( sError.length() != 0 ) |
|
283 { |
|
284 HbMessageBox::information(sError); |
|
285 } |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CSecModUIModel::OpenTokenL(TInt aTokenIndex) |
|
290 // Retrieves the appropriate token based on the index. |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 void CSecModUIModel::OpenTokenL(TInt aTokenIndex) |
|
294 { |
|
295 ResetAndDestroyAOs(); |
|
296 iKeyStore = iAOKeyStores[aTokenIndex]; |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CSecModUIModel::CheckCodeViewStringsL() |
|
301 // Initialize the auth objects and return the total count. |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 TInt CSecModUIModel::CheckCodeViewStringsL() |
|
305 { |
|
306 InitAuthObjectsL(); |
|
307 ListAuthObjectsL(); |
|
308 return iAOArray.Count(); |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CSecModUIModel::InitAuthObjectsL() |
|
313 // Retrieve the authentication object associated with the appropriate key store |
|
314 // implementation. |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 void CSecModUIModel::InitAuthObjectsL() |
|
318 { |
|
319 TInt err = KErrNone; |
|
320 // Symbian's file key store does not support |
|
321 // MCTAuthenticationObjectList interface, so we need to use |
|
322 // other way to get AO. |
|
323 if (iKeyStore->Token().TokenType().Type().iUid == KTokenTypeFileKeystore) |
|
324 { |
|
325 if (iAOArray.Count()==0) |
|
326 { |
|
327 RMPointerArray<CCTKeyInfo> keyInfos; |
|
328 CleanupClosePushL(keyInfos); |
|
329 TCTKeyAttributeFilter filter; |
|
330 TInt keyInfoCount = 0; |
|
331 filter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys; |
|
332 err = iWrapper->ListKeys(*iKeyStore, keyInfos, filter); |
|
333 ShowErrorNote(err); |
|
334 User::LeaveIfError(err); |
|
335 keyInfoCount = keyInfos.Count(); |
|
336 for (TInt j = 0; j < keyInfoCount; j++) |
|
337 { |
|
338 // Check that keystore has at least one AO. |
|
339 if (NULL != keyInfos[j]->Protector()) |
|
340 { |
|
341 // If keystore has AO, add it to the array. |
|
342 User::LeaveIfError(iAOArray.Append(keyInfos[j]->Protector())); |
|
343 break; |
|
344 } |
|
345 } |
|
346 CleanupStack::PopAndDestroy(&keyInfos); //keyInfos |
|
347 } |
|
348 } |
|
349 else |
|
350 { |
|
351 if (NULL == iAOList) |
|
352 { |
|
353 MCTTokenInterface* tokenInterface = NULL; |
|
354 err = iWrapper->GetAuthObjectInterface( |
|
355 iKeyStore->Token(), tokenInterface); |
|
356 if ( KErrNone != err || NULL == tokenInterface ) |
|
357 { |
|
358 ShowErrorNote(err); |
|
359 User::Leave(err); |
|
360 } |
|
361 iAOList = (MCTAuthenticationObjectList*)tokenInterface; |
|
362 } |
|
363 } |
|
364 } |
|
365 // ----------------------------------------------------------------------------- |
|
366 // CSecModUIModel::ListAuthObjectsL() |
|
367 // list the auth objects. |
|
368 // ----------------------------------------------------------------------------- |
|
369 // |
|
370 void CSecModUIModel::ListAuthObjectsL() |
|
371 { |
|
372 if (0 >= iAOArray.Count()) |
|
373 { |
|
374 __ASSERT_ALWAYS(iAOList, Panic(EPanicNullPointer)); |
|
375 TInt err = iWrapper->ListAuthObjects(*iAOList, iAOArray); |
|
376 if (err) |
|
377 { |
|
378 ShowErrorNote(err); |
|
379 User::Leave(err); |
|
380 } |
|
381 } |
|
382 } |
|
383 |
|
384 // ----------------------------------------------------------------------------- |
|
385 // CSecModUIModel::TokenLabelForTitle() const |
|
386 // Retrieves description of the token based on UID of the current active keystore. |
|
387 // ----------------------------------------------------------------------------- |
|
388 // |
|
389 QString CSecModUIModel::TokenLabelForTitle() const |
|
390 { |
|
391 QString qLabel; |
|
392 if (iKeyStore->Token().TokenType().Type().iUid |
|
393 == KTokenTypeFileKeystore) |
|
394 { |
|
395 qLabel = "Phone keystore"; |
|
396 } |
|
397 else |
|
398 { |
|
399 const TDesC& label = iKeyStore->Token().Label(); |
|
400 qLabel = QString((QChar*)label.Ptr(),label.Length()); |
|
401 } |
|
402 return qLabel; |
|
403 } |
|
404 |
|
405 // ----------------------------------------------------------------------------- |
|
406 // CSecModUIModel::AuthStatus(TInt aIndex) const |
|
407 // Returns status of the selected auth object. |
|
408 // ----------------------------------------------------------------------------- |
|
409 // |
|
410 TUint32 CSecModUIModel::AuthStatus(TInt aIndex) const |
|
411 { |
|
412 return iAOArray[aIndex]->Status(); |
|
413 } |
|
414 |
|
415 // ----------------------------------------------------------------------------- |
|
416 // CSecModUIModel::PINStatus( TInt aIndex, TBool aShowBlockedNote ) const |
|
417 // Returns status of the auth object based on its persistent properties set |
|
418 // by security module implementation. |
|
419 // ----------------------------------------------------------------------------- |
|
420 // |
|
421 QString CSecModUIModel::PINStatus( TInt aIndex, TBool aShowBlockedNote ) const |
|
422 { |
|
423 __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange)); |
|
424 QString pinStatus; |
|
425 TUint32 status = iAOArray[aIndex]->Status(); |
|
426 |
|
427 if (status & EAuthObjectBlocked) |
|
428 { |
|
429 if (aShowBlockedNote) |
|
430 { |
|
431 QString information = 0; |
|
432 if (status & EUnblockDisabled) |
|
433 { |
|
434 information = " totalblocked, contact your module vendor."; |
|
435 } |
|
436 else |
|
437 { |
|
438 information = " is blocked. PUK code is needed to unblock the code"; |
|
439 } |
|
440 information.prepend(QString( (QChar*)(iAOArray[aIndex]->Label()).Ptr(),iAOArray[aIndex]->Label().Length() ) ); |
|
441 HbMessageBox::information(information); |
|
442 } |
|
443 pinStatus = "Blocked"; |
|
444 } |
|
445 else if ( PinOpen(aIndex) ) |
|
446 { |
|
447 pinStatus = "Open"; |
|
448 } |
|
449 else |
|
450 { |
|
451 pinStatus = "Closed"; |
|
452 } |
|
453 return pinStatus; |
|
454 } |
|
455 |
|
456 // ----------------------------------------------------------------------------- |
|
457 // CSecModUIModel::PinOpen(TInt aIndex) const |
|
458 // Checks whether the Pin is still available. |
|
459 // ----------------------------------------------------------------------------- |
|
460 // |
|
461 TBool CSecModUIModel::PinOpen(TInt aIndex) const |
|
462 { |
|
463 __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange)); |
|
464 TInt timeRemaining = 0; |
|
465 TInt err = iWrapper->TimeRemaining(*(iAOArray[aIndex]), timeRemaining); |
|
466 TBool ret = ETrue; |
|
467 if ( 0 < timeRemaining ) |
|
468 { |
|
469 ret = ETrue; |
|
470 } |
|
471 else if( timeRemaining == -1 ) |
|
472 { |
|
473 ret = ETrue; |
|
474 } |
|
475 else |
|
476 { |
|
477 ret = EFalse; |
|
478 } |
|
479 return ret; |
|
480 } |
|
481 |
|
482 // ----------------------------------------------------------------------------- |
|
483 // CSecModUIModel::ChangeOrUnblockPinL(TInt aIndex) |
|
484 // Based on the property of auth object the pin can be changed or unblocked. |
|
485 // ----------------------------------------------------------------------------- |
|
486 // |
|
487 void CSecModUIModel::ChangeOrUnblockPinL(TInt aIndex) |
|
488 { |
|
489 __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange)); |
|
490 TUint32 status = iAOArray[aIndex]->Status(); |
|
491 |
|
492 if ((status & EAuthObjectBlocked) && (status & EUnblockDisabled)) |
|
493 { |
|
494 return; // We cannot do anything. PIN is total bolcked. |
|
495 } |
|
496 else if (status & EAuthObjectBlocked) |
|
497 { |
|
498 // Let's unblock the PIN |
|
499 UnblockPinL(aIndex); |
|
500 } |
|
501 else if (status & EEnabled) |
|
502 { |
|
503 // PIN is enabled. Let's change the PIN. |
|
504 ChangePinL(aIndex); |
|
505 } |
|
506 } |
|
507 |
|
508 // ----------------------------------------------------------------------------- |
|
509 // CSecModUIModel::UnblockPinL(TInt aIndex) |
|
510 // Unblocks PIN. |
|
511 // ----------------------------------------------------------------------------- |
|
512 // |
|
513 void CSecModUIModel::UnblockPinL(TInt aIndex) |
|
514 { |
|
515 __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange)); |
|
516 TInt err = iWrapper->UnblockAuthObject(*(iAOArray[aIndex])); |
|
517 if (KErrNone == err) |
|
518 { |
|
519 HbMessageBox::information("Code unblocked"); |
|
520 } |
|
521 else |
|
522 { |
|
523 ShowErrorNote(err); |
|
524 } |
|
525 } |
|
526 |
|
527 // ----------------------------------------------------------------------------- |
|
528 // CSecModUIModel::ChangePinL(TInt aIndex) |
|
529 // Changes the value of the PIN. |
|
530 // ----------------------------------------------------------------------------- |
|
531 // |
|
532 void CSecModUIModel::ChangePinL(TInt aIndex) |
|
533 { |
|
534 __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange)); |
|
535 TInt err = KErrNone; |
|
536 |
|
537 err = iWrapper->ChangeReferenceData(*(iAOArray[aIndex])); |
|
538 if (err) |
|
539 { |
|
540 ShowErrorNote(err); |
|
541 } |
|
542 else |
|
543 { |
|
544 HbMessageBox::information("Code changed"); |
|
545 } |
|
546 } |
|
547 |
|
548 // ----------------------------------------------------------------------------- |
|
549 // CSecModUIModel::ChangeCodeRequestL(TInt aIndex) |
|
550 // Toggles the value of auth object if possible. |
|
551 // ----------------------------------------------------------------------------- |
|
552 // |
|
553 TInt CSecModUIModel::ChangeCodeRequest(TInt aIndex) |
|
554 { |
|
555 __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange)); |
|
556 TUint32 status = iAOArray[aIndex]->Status(); |
|
557 TInt err = KErrNone; |
|
558 if (status & EDisableAllowed && !(status & EAuthObjectBlocked)) |
|
559 { |
|
560 if ( status & EEnabled ) |
|
561 { |
|
562 err = iWrapper->DisableAuthObject(*(iAOArray[aIndex])); |
|
563 } |
|
564 else |
|
565 { |
|
566 err = iWrapper->EnableAuthObject(*(iAOArray[aIndex])); |
|
567 } |
|
568 ShowErrorNote(err); |
|
569 } |
|
570 return err; |
|
571 } |
|
572 |
|
573 // ----------------------------------------------------------------------------- |
|
574 // CSecModUIModel::CloseAuthObjL(TInt aIndex) |
|
575 // If the auth object is open then closes it. |
|
576 // ----------------------------------------------------------------------------- |
|
577 // |
|
578 void CSecModUIModel::CloseAuthObjL(TInt aIndex) |
|
579 { |
|
580 if (PinOpen(aIndex)) |
|
581 { |
|
582 __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange)); |
|
583 TInt err = iWrapper->CloseAuthObject(*(iAOArray[aIndex])); |
|
584 if (err) |
|
585 { |
|
586 ShowErrorNote(err); |
|
587 User::Leave(err); |
|
588 } |
|
589 } |
|
590 } |
|
591 |
|
592 // ----------------------------------------------------------------------------- |
|
593 // CSecModUIModel::DeleteKeysL(TInt aTokenIndex) |
|
594 // Deletes key from the appropriate keystore. |
|
595 // ----------------------------------------------------------------------------- |
|
596 // |
|
597 void CSecModUIModel::DeleteKeysL(TInt aTokenIndex) |
|
598 { |
|
599 __ASSERT_ALWAYS(aTokenIndex < iAOKeyStores.Count(), Panic(EPanicIndexOutOfRange)); |
|
600 RMPointerArray<CCTKeyInfo> keyInfos; |
|
601 CleanupClosePushL(keyInfos); |
|
602 TCTKeyAttributeFilter filter; |
|
603 filter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys; |
|
604 TInt err = iWrapper->ListKeys(*iAOKeyStores[aTokenIndex], keyInfos, filter); |
|
605 ShowErrorNote(err); |
|
606 User::LeaveIfError(err); |
|
607 for (TInt i = 0; i < keyInfos.Count(); ++i) |
|
608 { |
|
609 err = iWrapper->DeleteKey(*iUnifiedKeyStore, keyInfos[i]->Handle()); |
|
610 ShowErrorNote(err); |
|
611 |
|
612 if (KErrHardwareNotAvailable == err ) |
|
613 { |
|
614 break; // Break the loop, if keystore not available |
|
615 } |
|
616 } |
|
617 CleanupStack::PopAndDestroy(&keyInfos); //keyInfos |
|
618 ResetAndDestroyCTObjects(); |
|
619 InitializeKeyStoreL(); |
|
620 } |
|
621 |
|
622 // ----------------------------------------------------------------------------- |
|
623 // CSecModUIModel::SecModDetailsL(TInt aTokenIndex) |
|
624 // Retrieve security module details and cleansup all currently held auth objects. |
|
625 // ----------------------------------------------------------------------------- |
|
626 // |
|
627 QVector< QPair<QString,QString> > CSecModUIModel::SecModDetailsL(TInt aTokenIndex) |
|
628 { |
|
629 iKeyStore = iAOKeyStores[aTokenIndex]; |
|
630 InitAuthObjectsL(); |
|
631 ListAuthObjectsL(); |
|
632 QVector< QPair<QString,QString> > securityDetails = GetSecModDetailsL(); |
|
633 iKeyStore = NULL; // not owned |
|
634 if (iAOList) |
|
635 { |
|
636 iAOList->Release(); |
|
637 iAOList = NULL; |
|
638 } |
|
639 iAOArray.Reset(); |
|
640 return securityDetails; |
|
641 } |
|
642 |
|
643 // ----------------------------------------------------------------------------- |
|
644 // CSecModUIModel::GetSecModDetailsL() |
|
645 // Retrieve security module details. |
|
646 // ----------------------------------------------------------------------------- |
|
647 // |
|
648 QVector< QPair<QString,QString> > CSecModUIModel::GetSecModDetailsL() |
|
649 { |
|
650 MCTToken& token = iKeyStore->Token(); |
|
651 QVector< QPair<QString,QString> > securityModDetails; |
|
652 |
|
653 if (token.TokenType().Type().iUid == KTokenTypeFileKeystore) |
|
654 { |
|
655 QPair<QString,QString> name("Name:","Phone keystore"); |
|
656 securityModDetails.append(name); |
|
657 } |
|
658 else |
|
659 { |
|
660 QPair<QString,QString> name("Name:","(No label)"); |
|
661 securityModDetails.append(name); |
|
662 } |
|
663 |
|
664 AppendItem(securityModDetails, "Version:", token.Information( MCTToken::EVersion ), "(Not defined)" ); |
|
665 AppendLocation(securityModDetails, token.TokenType().Type(), QString("Security module location:")); |
|
666 |
|
667 if (token.TokenType().Type().iUid == KTokenTypeFileKeystore) |
|
668 { |
|
669 QPair<QString,QString> accessCode("Access code:","Phone keystore code"); |
|
670 securityModDetails.append(accessCode); |
|
671 } |
|
672 else |
|
673 { |
|
674 AppendItem(securityModDetails, "Access code:", iAOArray[0]->Label(), "Access code:" ); |
|
675 } |
|
676 |
|
677 AppendPinNRs(securityModDetails); |
|
678 |
|
679 AppendItem( securityModDetails, "Serial number:", |
|
680 token.Information( MCTToken::ESerialNo), |
|
681 "(Not defined)"); |
|
682 |
|
683 AppendItem( securityModDetails, "Manufacturer:", |
|
684 token.Information( MCTToken::EManufacturer), |
|
685 "(Not defined)"); |
|
686 return securityModDetails; |
|
687 } |
|
688 |
|
689 // ----------------------------------------------------------------------------- |
|
690 // CSecModUIModel::AppendLocation() |
|
691 // Appends the location of the keystore. |
|
692 // ----------------------------------------------------------------------------- |
|
693 // |
|
694 void CSecModUIModel::AppendLocation( QVector< QPair<QString,QString> >& aSecModDetails, |
|
695 TUid aLocUid, |
|
696 QString aCertDisplayDetails ) |
|
697 { |
|
698 QString locationDetails = "(Not defined)"; |
|
699 |
|
700 switch ( aLocUid.iUid ) |
|
701 { |
|
702 case KTokenTypeFileKeystore: |
|
703 locationDetails = "Phone memory"; |
|
704 break; |
|
705 |
|
706 case KWIMStoreUid: |
|
707 locationDetails = "Smart card"; |
|
708 break; |
|
709 |
|
710 default: |
|
711 break; |
|
712 } |
|
713 aSecModDetails.append(QPair<QString,QString>(aCertDisplayDetails, locationDetails)); |
|
714 } |
|
715 |
|
716 // ----------------------------------------------------------------------------- |
|
717 // CSecModUIModel::AppendItem() |
|
718 // Appends the value of a label if present otherwise appends empty descriotion. |
|
719 // ----------------------------------------------------------------------------- |
|
720 // |
|
721 void CSecModUIModel::AppendItem( QVector< QPair<QString,QString> >& aSecModDetails, |
|
722 QString aLabel, |
|
723 const TDesC& aValue, |
|
724 QString aNullDescription) |
|
725 { |
|
726 if( aValue.Length() == 0 ) |
|
727 { |
|
728 aSecModDetails.append(QPair<QString,QString>(aLabel, aNullDescription)); |
|
729 } |
|
730 else |
|
731 { |
|
732 QString value = QString((QChar*) aValue.Ptr(),aValue.Length()); |
|
733 aSecModDetails.append(QPair<QString,QString>(aLabel, value)); |
|
734 } |
|
735 } |
|
736 |
|
737 // ------------------------------------------------------------------------------- |
|
738 // CSecModUIModel::AppendPinNRs(QVector< QPair<QString,QString> >& aSecModDetails) |
|
739 // Generate details of signing security module. |
|
740 // ------------------------------------------------------------------------------- |
|
741 // |
|
742 void CSecModUIModel::AppendPinNRs(QVector< QPair<QString,QString> >& aSecModDetails) |
|
743 { |
|
744 TInt pinCount = iAOArray.Count(); |
|
745 TInt j = 0; |
|
746 |
|
747 for (TInt i=1; i<pinCount; i++) |
|
748 { |
|
749 QString noLabelDetails = "Signing code "; |
|
750 const TDesC& label = iAOArray[i]->Label(); |
|
751 if(label.Length() == 0) |
|
752 { |
|
753 noLabelDetails.append(++j); |
|
754 } |
|
755 QString signingCode = "Signing code:"; |
|
756 AppendItem(aSecModDetails, signingCode , iAOArray[i]->Label(), noLabelDetails); |
|
757 } |
|
758 } |
|
759 |
|
760 // ----------------------------------------------------------------------------- |
|
761 // CSecModUIModel::AuthDetails() const |
|
762 // Return the list of pair of description and status of each auth object. |
|
763 // ----------------------------------------------------------------------------- |
|
764 // |
|
765 QVector<QPair<QString, TUint32> > CSecModUIModel::AuthDetails() |
|
766 { |
|
767 QVector<QPair<QString, TUint32> > authDetails; |
|
768 |
|
769 // Here is assumed that the first AO is always PIN-G |
|
770 for (TInt i = 1; i < iAOArray.Count(); i++) |
|
771 { |
|
772 const TDesC& label = iAOArray[i]->Label(); |
|
773 TUint32 status = iAOArray[i]->Status(); |
|
774 QString sLabel = QString((QChar*) label.Ptr(), label.Length()); |
|
775 QPair<QString, TUint32> pair(sLabel, status); |
|
776 authDetails.append(pair); |
|
777 } |
|
778 return authDetails; |
|
779 } |
|
780 |
|
781 // ----------------------------------------------------------------------------- |
|
782 // CSecModUIModel::ChangePinNrL(TInt aIndex) |
|
783 // Change the pin value for the singing module. |
|
784 // ----------------------------------------------------------------------------- |
|
785 // |
|
786 void CSecModUIModel::ChangePinNrL(TInt aIndex) |
|
787 { |
|
788 ChangePinL(aIndex+1); |
|
789 } |
|
790 |
|
791 |
|
792 // ----------------------------------------------------------------------------- |
|
793 // CSecModUIModel::UnblockPinNrL(TInt aIndex) |
|
794 // Unblock the value for the signing code module. |
|
795 // ----------------------------------------------------------------------------- |
|
796 // |
|
797 void CSecModUIModel::UnblockPinNrL(TInt aIndex) |
|
798 { |
|
799 UnblockPinL(aIndex+1); |
|
800 } |
|
801 |
|
802 // ----------------------------------------------------------------------------- |
|
803 // CSecModUIModel::KeyStoreUID() |
|
804 // Retrieves the UID of the current active keystore. |
|
805 // ----------------------------------------------------------------------------- |
|
806 // |
|
807 TInt CSecModUIModel::KeyStoreUID() |
|
808 { |
|
809 return iKeyStore->Token().TokenType().Type().iUid; |
|
810 } |
|
811 |
|
812 // ----------------------------------------------------------------------------- |
|
813 // CSecModUIModel::AuthObj(TInt aIndex) |
|
814 // Retrieves the auth object at the speficied index. |
|
815 // ----------------------------------------------------------------------------- |
|
816 // |
|
817 const MCTAuthenticationObject& CSecModUIModel::AuthObj(TInt aIndex) |
|
818 { |
|
819 return *iAOArray[aIndex]; |
|
820 } |
|
821 |
|
822 // ----------------------------------------------------------------------------- |
|
823 // CSecModUIModel::PinChangeable(TInt aIndex) const |
|
824 // Returns the status accordingly if the pin is changeable or not. |
|
825 // ----------------------------------------------------------------------------- |
|
826 // |
|
827 TBool CSecModUIModel::PinChangeable(TInt aIndex) const |
|
828 { |
|
829 __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange)); |
|
830 TUint32 status = iAOArray[aIndex]->Status(); |
|
831 TBool ret = ETrue; |
|
832 if ( (status & EAuthObjectBlocked) || (status & EChangeDisabled) ) |
|
833 { |
|
834 ret = EFalse; |
|
835 } |
|
836 else if ( status & EEnabled ) |
|
837 { |
|
838 ret = ETrue; |
|
839 } |
|
840 else // PIN is disabled; |
|
841 { |
|
842 ret = EFalse; |
|
843 } |
|
844 return ret; |
|
845 } |
|
846 |
|
847 // ----------------------------------------------------------------------------- |
|
848 // CSecModUIModel::PinUnblockable(TInt aIndex) const |
|
849 // Returns the status accordingly if the pin is unblockable or not. |
|
850 // ----------------------------------------------------------------------------- |
|
851 // |
|
852 TBool CSecModUIModel::PinUnblockable(TInt aIndex) const |
|
853 { |
|
854 TUint32 status = iAOArray[aIndex]->Status(); |
|
855 TBool ret = ETrue; |
|
856 if ( status & EUnblockDisabled ) |
|
857 { |
|
858 ret = EFalse; |
|
859 } |
|
860 else if ( status & EAuthObjectBlocked ) |
|
861 { |
|
862 ret = ETrue; |
|
863 } |
|
864 else // PIN is not blocked; |
|
865 { |
|
866 ret = EFalse; |
|
867 } |
|
868 return ret; |
|
869 } |
|
870 |
|
871 // ----------------------------------------------------------------------------- |
|
872 // CSecModUIModel::PinRequestChangeable(TInt aIndex) const |
|
873 // Returns the status accordingly if the pin is changeable or not. |
|
874 // ----------------------------------------------------------------------------- |
|
875 // |
|
876 TBool CSecModUIModel::PinRequestChangeable(TInt aIndex) const |
|
877 { |
|
878 __ASSERT_ALWAYS(aIndex < iAOArray.Count(), Panic(EPanicIndexOutOfRange)); |
|
879 TUint32 status = iAOArray[aIndex]->Status(); |
|
880 TBool ret = EFalse; |
|
881 if ( status & EAuthObjectBlocked ) |
|
882 { |
|
883 ret = EFalse; |
|
884 } |
|
885 else if ( status & EDisableAllowed ) |
|
886 { |
|
887 ret = ETrue; |
|
888 } |
|
889 else // Disable not allowed; |
|
890 { |
|
891 ret = EFalse; |
|
892 } |
|
893 return ret; |
|
894 } |
|
895 |
|
896 // ----------------------------------------------------------------------------- |
|
897 // CSecModUIModel::IsTokenDeletable(TInt aTokenIndex) |
|
898 // Returns the status accordingly if the token is deletable or not. |
|
899 // ----------------------------------------------------------------------------- |
|
900 // |
|
901 TBool CSecModUIModel::IsTokenDeletable(TInt aTokenIndex) |
|
902 { |
|
903 __ASSERT_ALWAYS(aTokenIndex < iAOKeyStores.Count(), Panic(EPanicIndexOutOfRange)); |
|
904 TBool ret = EFalse; |
|
905 if (iAOKeyStores[aTokenIndex]->Token().TokenType().Type().iUid |
|
906 == KTokenTypeFileKeystore) |
|
907 { |
|
908 ret = ETrue; |
|
909 } |
|
910 else |
|
911 { |
|
912 ret = EFalse; |
|
913 } |
|
914 return ret; |
|
915 } |
|
916 |
|
917 // End of File |
|
918 |
|
919 |