42 #include "CertSaverAppUi.h" |
44 #include "CertSaverAppUi.h" |
43 #include "CertSaverSyncWrapper.h" |
45 #include "CertSaverSyncWrapper.h" |
44 #include "certsaver.hrh" |
46 #include "certsaver.hrh" |
45 #include "securityuisvariant.hrh" |
47 #include "securityuisvariant.hrh" |
46 |
48 |
|
49 #include <hbdevicemessageboxsymbian.h> |
|
50 #include <hbdevicenotificationdialogsymbian.h> |
|
51 #include <hbsymbianvariant.h> |
|
52 |
|
53 #include "SecQueryUi.h" // needed for label dialog |
|
54 |
47 // CONSTANTS |
55 // CONSTANTS |
|
56 |
48 const TInt32 KWTLSTrusterUID( 268479059 ); |
57 const TInt32 KWTLSTrusterUID( 268479059 ); |
49 const TInt32 KInternetTrusterUID( 268441661 ); |
58 const TInt32 KInternetTrusterUID( 268441661 ); |
50 const TInt32 KApplicationControllerTrusterUID( 268452523 ); |
59 const TInt32 KApplicationControllerTrusterUID( 268452523 ); |
51 const TInt32 KJavaInstallTrusterUID( 270506792 ); |
60 const TInt32 KJavaInstallTrusterUID( 270506792 ); |
52 const TInt32 KOCSPTrusterUID( 268478646 ); |
61 const TInt32 KOCSPTrusterUID( 268478646 ); |
54 |
63 |
55 const TInt KTrusterArrayInitSize( 2 ); |
64 const TInt KTrusterArrayInitSize( 2 ); |
56 |
65 |
57 const TInt KMaxLengthTextMeassageBody( 5000 ); |
66 const TInt KMaxLengthTextMeassageBody( 5000 ); |
58 const TInt KMaxLengthTextDateString( 11 ); // "dd/mm/yyyy0" |
67 const TInt KMaxLengthTextDateString( 11 ); // "dd/mm/yyyy0" |
|
68 const TInt KMaxLengthTextCheckBoxData( 255 ); // "dd/mm/yyyy0" |
59 |
69 |
60 //Issuer and Owner max visible length |
70 //Issuer and Owner max visible length |
61 const TInt KMaxLengthTextCertIdentifierVisible( 1000 ); |
71 const TInt KMaxLengthTextCertIdentifierVisible( 1000 ); |
62 const TInt KAttempts( 3 ); |
72 const TInt KAttempts( 3 ); |
63 |
73 |
64 const TInt KFingerprintLength( 50 ); |
74 const TInt KFingerprintLength( 50 ); |
|
75 const TInt KTokenLength( 32 ); |
65 |
76 |
66 _LIT( KCertSaverListBoxItemPrefix, "1\t" ); |
77 _LIT( KCertSaverListBoxItemPrefix, "1\t" ); |
67 const TInt KItemBufLen = 2 + KMaxName; |
78 const TInt KItemBufLen = 2 + KMaxName; |
68 |
79 |
69 _LIT( KPrivateKeyLabel, "PrivateKey " ); |
80 _LIT( KPrivateKeyLabel, "PrivateKey " ); |
194 break; |
208 break; |
195 } |
209 } |
196 case KErrKeySize: |
210 case KErrKeySize: |
197 case KErrArgument: |
211 case KErrArgument: |
198 { |
212 { |
199 ShowErrorNoteL( R_CERTSAVER_KEY_TYPE_NOT_SUPPORTED ); |
213 ShowInformationNoteL( R_CERTSAVER_KEY_TYPE_NOT_SUPPORTED ); |
200 User::Leave( KErrCancel ); |
214 User::Leave( KErrCancel ); |
201 break; |
215 break; |
202 } |
216 } |
203 case KErrKeyValidity: |
217 case KErrKeyValidity: |
204 { |
218 { |
205 ShowInformationNoteL( R_CERTSAVER_QTN_CM_PKCS12_EXPIRED ); |
219 ShowInformationNoteL( R_CERTSAVER_QTN_CM_PKCS12_EXPIRED ); |
206 User::Leave( KErrCancel ); |
220 User::Leave( KErrCancel ); |
207 } |
221 } |
208 case KErrKeyUsage: |
222 case KErrKeyUsage: |
209 { |
223 { |
210 ShowErrorNoteL( R_CERTSAVER_PRIVATE_KEY_CORRUPTED ); |
224 ShowInformationNoteL( R_CERTSAVER_PRIVATE_KEY_CORRUPTED ); |
211 User::Leave( KErrCancel ); |
225 User::Leave( KErrCancel ); |
212 break; |
226 break; |
213 } |
227 } |
214 case KErrCancel: |
228 case KErrCancel: |
215 case KErrPermissionDenied: |
229 case KErrPermissionDenied: |
216 { |
230 { |
217 ShowErrorNoteL( R_CERTSAVER_PKCS12_DISCARDED ); |
231 ShowInformationNoteL( R_CERTSAVER_PKCS12_DISCARDED ); |
218 User::Leave( KErrCancel ); |
232 User::Leave( KErrCancel ); |
219 break; |
233 break; |
220 } |
234 } |
221 case KErrCorrupt: |
235 case KErrCorrupt: |
222 case KErrEof: |
236 case KErrEof: |
223 { |
237 { |
224 ShowErrorNoteL( R_CERTSAVER_KEYSTORE_CORRUPTED ); |
238 ShowInformationNoteL( R_CERTSAVER_KEYSTORE_CORRUPTED ); |
225 User::Leave( KErrCancel ); |
239 User::Leave( KErrCancel ); |
226 break; |
240 break; |
227 } |
241 } |
228 case KErrAlreadyExists: |
242 case KErrAlreadyExists: |
229 { |
243 { |
483 // const TDesC8& aDataToSave) |
502 // const TDesC8& aDataToSave) |
484 // ---------------------------------------------------------- |
503 // ---------------------------------------------------------- |
485 // |
504 // |
486 void CCertSaverModel::CheckFSSpaceL( const TDesC8& aDataToSave ) |
505 void CCertSaverModel::CheckFSSpaceL( const TDesC8& aDataToSave ) |
487 { |
506 { |
|
507 |
488 if (SysUtil::FFSSpaceBelowCriticalLevelL( &iFs, aDataToSave.Size() )) |
508 if (SysUtil::FFSSpaceBelowCriticalLevelL( &iFs, aDataToSave.Size() )) |
489 { |
509 { |
490 HBufC* p = StringLoader::LoadLC( R_CERTSAVER_MEMORY ); |
510 ShowInformationNoteL(R_CERTSAVER_MEMORY); |
491 CAknErrorNote* note = new (ELeave) CAknErrorNote( ETrue ); |
|
492 note->ExecuteLD( p->Des() ); |
|
493 CleanupStack::PopAndDestroy( p ); |
|
494 User::Leave( KErrExitApp ); |
511 User::Leave( KErrExitApp ); |
495 } |
512 } |
496 } |
513 } |
497 |
|
498 // ---------------------------------------------------------- |
514 // ---------------------------------------------------------- |
499 // CCertSaverModel::SaveCertL() |
515 // CCertSaverModel::SaveCertL() |
500 // Saves certificate |
516 // Saves certificate |
501 // ---------------------------------------------------------- |
517 // ---------------------------------------------------------- |
502 // |
518 // |
503 void CCertSaverModel::SaveCertL() |
519 void CCertSaverModel::SaveCertL() |
504 { |
520 { |
|
521 |
505 if ( !CertificateOkL() ) |
522 if ( !CertificateOkL() ) |
506 { |
523 { |
507 User::Leave( KErrCancel ); |
524 User::Leave( KErrCancel ); |
508 } |
525 } |
509 |
526 |
510 HBufC* message = HBufC::NewLC( KMaxLengthTextMeassageBody ); |
527 HBufC* message = HBufC::NewLC( KMaxLengthTextMeassageBody ); |
511 TPtr msgPtr = message->Des(); |
528 TPtr msgPtr = message->Des(); |
512 ConstructMessageL( msgPtr ); |
529 ConstructMessageL( msgPtr ); |
513 CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *message ); |
530 CHbDeviceMessageBoxSymbian::TButtonId selection = |
514 CleanupStack::PopAndDestroy( message ); |
531 CHbDeviceMessageBoxSymbian::QuestionL(msgPtr, KNullDesC, KNullDesC); |
515 CleanupStack::PushL( dlg ); |
532 TBool doSave= (selection == CHbDeviceMessageBoxSymbian::EAcceptButton); |
516 |
533 CleanupStack::PopAndDestroy(message); |
517 |
534 /* |
518 dlg->PrepareLC( R_MESSAGE_QUERY_DOSAVE ); |
|
519 |
|
520 HBufC* header = StringLoader::LoadLC( R_CERTSAVER_DETAILS_HEADING ); |
|
521 dlg->QueryHeading()->SetTextL( header->Des() ); |
|
522 CleanupStack::PopAndDestroy( header ); |
|
523 CleanupStack::Pop( dlg ); |
|
524 TBool doSave = dlg->RunLD(); |
|
525 |
|
526 if ( doSave && iCertOwnerType == ECACertificate ) |
535 if ( doSave && iCertOwnerType == ECACertificate ) |
527 { |
536 { |
528 // warn user about security risk |
537 // warn user about security risk |
529 CAknQueryDialog* warningDialog = CAknQueryDialog::NewL(); |
538 HBufC* stringHolder = StringLoader::LoadLC( R_CERTSAVER_WARNING_NOTE ); |
530 doSave = warningDialog->ExecuteLD( R_CERTSAVER_WARNING_NOTE ); |
539 CHbDeviceMessageBoxSymbian::TButtonId selection = |
531 } |
540 CHbDeviceMessageBoxSymbian::QuestionL(stringHolder->Des(),KNullDesC, KNullDesC); |
532 |
541 CleanupStack::PopAndDestroy(stringHolder); |
|
542 doSave=(selection == CHbDeviceMessageBoxSymbian::EAcceptButton); |
|
543 } |
|
544 */ |
533 if ( doSave ) |
545 if ( doSave ) |
534 { |
546 { |
535 //Check that there still is enough space to store the |
547 //Check that there still is enough space to store the certificate. |
536 //certificate. |
|
537 CheckFSSpaceL( iNewCert->Encoding() ); |
548 CheckFSSpaceL( iNewCert->Encoding() ); |
538 DoSaveCertL(); |
549 DoSaveCertL(); |
539 } |
550 } |
540 else |
551 else |
541 { |
552 { |
542 ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED ); |
553 ShowInformationNoteL(R_CERTSAVER_CERT_DISCARDED); |
543 User::Leave( KErrCancel ); |
554 User::Leave( KErrCancel ); |
544 } |
555 } |
545 } |
556 } |
546 |
557 |
|
558 |
547 // ---------------------------------------------------------- |
559 // ---------------------------------------------------------- |
548 // CCertSaverModel::InitCertStoreL() |
560 // CCertSaverModel::InitCertStoreL() |
549 // |
561 // |
550 // ---------------------------------------------------------- |
562 // ---------------------------------------------------------- |
551 // |
563 // |
552 void CCertSaverModel::InitCertStoreL() |
564 void CCertSaverModel::InitCertStoreL() |
553 { |
565 { |
|
566 |
554 if ( !iUnifiedCertStore ) |
567 if ( !iUnifiedCertStore ) |
555 { |
568 { |
556 TRAPD( status, iUnifiedCertStore = CUnifiedCertStore::NewL( iFs, ETrue ) ); |
569 TRAPD( status, iUnifiedCertStore = CUnifiedCertStore::NewL( iFs, ETrue ) ); |
557 if ( status != KErrNone ) |
570 if ( status != KErrNone ) |
558 { |
571 { |
559 ShowErrorNoteL( R_CERTSAVER_ERROR_CACERTS_DB_CORRUPTED ); |
572 ShowInformationNoteL( R_CERTSAVER_ERROR_CACERTS_DB_CORRUPTED ); |
560 User::Leave( KErrExitApp ); |
573 User::Leave( KErrExitApp ); |
561 } |
574 } |
562 // initialize unified cert store |
575 // initialize unified cert store |
563 status = iWrapper->InitializeCertStore( *iUnifiedCertStore ); |
576 status = iWrapper->InitializeCertStore( *iUnifiedCertStore ); |
564 if ( status ) |
577 if ( status ) |
784 // already exist. |
799 // already exist. |
785 // ---------------------------------------------------------- |
800 // ---------------------------------------------------------- |
786 // |
801 // |
787 TInt CCertSaverModel::QueryLabelL( TCertLabel& aLabel, CUnifiedCertStore& aStore ) |
802 TInt CCertSaverModel::QueryLabelL( TCertLabel& aLabel, CUnifiedCertStore& aStore ) |
788 { |
803 { |
|
804 |
789 CCertAttributeFilter* filter = NULL; |
805 CCertAttributeFilter* filter = NULL; |
790 TInt status = KErrNone; |
806 TInt status = KErrNone; |
791 RMPointerArray<CCTCertInfo> entries; |
807 RMPointerArray<CCTCertInfo> entries; |
792 TBool loop = ETrue; |
808 TBool loop = ETrue; |
793 |
809 |
794 while ( loop ) |
810 while ( loop ) |
795 { |
811 { |
796 CAknTextQueryDialog* dialog = CAknTextQueryDialog::NewL( aLabel ); |
812 HBufC* labelprompt = CEikonEnv::Static()->AllocReadResourceLC( R_CERTSAVER_ENTER_LABEL ); |
797 if ( !dialog->ExecuteLD( R_CERTSAVER_LABEL_QUERY ) ) |
813 CSecQueryUi* SecQueryUi = CSecQueryUi::NewL(); |
|
814 TInt queryAccepted = SecQueryUi->SecQueryDialog(labelprompt->Des(), aLabel, |
|
815 1,KMaxCertLabelLength, |
|
816 ESecUiAlphaSupported | |
|
817 ESecUiCancelSupported | |
|
818 ESecUiEmergencyNotSupported); |
|
819 CleanupStack::PopAndDestroy( labelprompt ); |
|
820 delete SecQueryUi; |
|
821 SecQueryUi=NULL; |
|
822 |
|
823 if ( queryAccepted!=KErrNone ) |
798 { |
824 { |
799 // cancel |
825 // cancel |
800 ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED ); |
826 ShowInformationNoteL(R_CERTSAVER_CERT_DISCARDED); |
801 return KErrCancel; |
827 return KErrCancel; |
802 } |
828 } |
803 // Create filter to confirm that label doesn't already exist. |
829 // Create filter to confirm that label doesn't already exist. |
804 filter = CCertAttributeFilter::NewL(); |
830 filter = CCertAttributeFilter::NewL(); |
805 filter->SetLabel( aLabel ); |
831 filter->SetLabel( aLabel ); |
838 // of the save operation. |
864 // of the save operation. |
839 // ---------------------------------------------------------- |
865 // ---------------------------------------------------------- |
840 // |
866 // |
841 void CCertSaverModel::HandleSaveErrorL( TInt aStatus ) const |
867 void CCertSaverModel::HandleSaveErrorL( TInt aStatus ) const |
842 { |
868 { |
|
869 |
843 switch ( aStatus ) |
870 switch ( aStatus ) |
844 { |
871 { |
845 case KErrNone: |
872 case KErrNone: |
846 { |
873 { |
847 ShowConfirmationNoteL( R_CERTSAVER_ERROR_SAVEOK ); |
874 ShowInformationNoteL(R_CERTSAVER_ERROR_SAVEOK); |
848 break; |
875 break; |
849 } |
876 } |
850 case KErrNotSupported: |
877 case KErrNotSupported: |
851 { |
878 { |
852 ShowErrorNoteL( R_CERTSAVER_ERROR_UNSUPPORTED_CERT ); |
879 ShowInformationNoteL(R_CERTSAVER_ERROR_UNSUPPORTED_CERT); |
853 break; |
880 break; |
854 } |
881 } |
855 case KErrBadName: |
882 case KErrBadName: |
856 { |
883 { |
857 ShowErrorNoteL( R_CERTSAVER_ERROR_LABEL_ALREADY_EXISTS ); |
884 ShowInformationNoteL(R_CERTSAVER_ERROR_LABEL_ALREADY_EXISTS); |
858 break; |
885 break; |
859 } |
886 } |
860 case KErrAlreadyExists: |
887 case KErrAlreadyExists: |
861 { |
888 { |
862 ShowErrorNoteL( R_CERTSAVER_ERROR_ALREADY_EXISTS ); |
889 ShowInformationNoteL(R_CERTSAVER_ERROR_ALREADY_EXISTS); |
863 break; |
890 break; |
864 } |
891 } |
865 case KErrArgument: |
892 case KErrArgument: |
866 { |
893 { |
867 ShowErrorNoteL( R_CERTSAVER_ERROR_CACERTS_DB_CORRUPTED ); |
894 ShowInformationNoteL(R_CERTSAVER_ERROR_CACERTS_DB_CORRUPTED); |
868 break; |
895 break; |
869 } |
896 } |
870 default: |
897 default: |
871 { |
898 { |
872 //No error note defined for unknown error. |
899 //No error note defined for unknown error. |
1106 dateFormatString = iAppUi->CoeEnv()->AllocReadResourceLC( |
1139 dateFormatString = iAppUi->CoeEnv()->AllocReadResourceLC( |
1107 R_QTN_DATE_USUAL_WITH_ZERO ); |
1140 R_QTN_DATE_USUAL_WITH_ZERO ); |
1108 // format the date to user readable format. The format is locale dependent |
1141 // format the date to user readable format. The format is locale dependent |
1109 finishValue.FormatL( finishString, *dateFormatString ); |
1142 finishValue.FormatL( finishString, *dateFormatString ); |
1110 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( finishString ); |
1143 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( finishString ); |
1111 CleanupStack::PopAndDestroy(); // dateFormatString |
1144 CleanupStack::PopAndDestroy(dateFormatString); // dateFormatString |
1112 aMessage.Append( finishString ); |
1145 aMessage.Append( finishString ); |
1113 AddNewlinesToMessage( aMessage ); |
1146 AddNewlinesToMessage( aMessage ); |
1114 } |
1147 } |
1115 |
1148 |
1116 // ---------------------------------------------------------- |
1149 // ---------------------------------------------------------- |
1118 // Adds two new lines to message. |
1151 // Adds two new lines to message. |
1119 // ---------------------------------------------------------- |
1152 // ---------------------------------------------------------- |
1120 // |
1153 // |
1121 void CCertSaverModel::AddNewlinesToMessage( TDes& aMessage ) const |
1154 void CCertSaverModel::AddNewlinesToMessage( TDes& aMessage ) const |
1122 { |
1155 { |
|
1156 |
1123 aMessage.Append( KDoubleEnter ); |
1157 aMessage.Append( KDoubleEnter ); |
1124 } |
1158 } |
1125 |
1159 |
1126 // ---------------------------------------------------------- |
1160 // ---------------------------------------------------------- |
1127 // CCertSaverModel::CertificateSupported() const |
1161 // CCertSaverModel::CertificateSupported() const |
1128 // Checks that cert is of supported type. |
1162 // Checks that cert is of supported type. |
1129 // ---------------------------------------------------------- |
1163 // ---------------------------------------------------------- |
1130 // |
1164 // |
1131 TBool CCertSaverModel::CertificateSupported() const |
1165 TBool CCertSaverModel::CertificateSupported() const |
1132 { |
1166 { |
|
1167 |
1133 if ( iCertFormat == EX509Certificate && |
1168 if ( iCertFormat == EX509Certificate && |
1134 ( iCertOwnerType == ECACertificate || |
1169 ( iCertOwnerType == ECACertificate || |
1135 iCertOwnerType == EPeerCertificate || |
1170 iCertOwnerType == EPeerCertificate || |
1136 iCertOwnerType == EUserCertificate)) |
1171 iCertOwnerType == EUserCertificate)) |
1137 { |
1172 { |
1205 // Creates and shows a confirmation note. |
1243 // Creates and shows a confirmation note. |
1206 // ---------------------------------------------------------- |
1244 // ---------------------------------------------------------- |
1207 // |
1245 // |
1208 void CCertSaverModel::ShowInformationNoteL( TInt aResourceID ) const |
1246 void CCertSaverModel::ShowInformationNoteL( TInt aResourceID ) const |
1209 { |
1247 { |
|
1248 |
1210 HBufC* buffer = iAppUi->CoeEnv()->AllocReadResourceLC( aResourceID ); |
1249 HBufC* buffer = iAppUi->CoeEnv()->AllocReadResourceLC( aResourceID ); |
1211 CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue ); |
1250 CHbDeviceMessageBoxSymbian* iMessageBox = CHbDeviceMessageBoxSymbian::NewL(CHbDeviceMessageBoxSymbian::EInformation); |
1212 note->ExecuteLD( buffer->Des() ); |
1251 CleanupStack::PushL(iMessageBox); |
1213 CleanupStack::PopAndDestroy( buffer ); |
1252 iMessageBox->SetTextL(buffer->Des()); |
1214 } |
1253 iMessageBox->SetTimeout(6000); |
1215 // ---------------------------------------------------------- |
1254 iMessageBox->ExecL(); |
1216 // CCertSaverModel::ShowConfirmationNoteL() const |
1255 CleanupStack::PopAndDestroy(iMessageBox); |
1217 // Creates and shows a confirmation note. |
1256 CleanupStack::PopAndDestroy( buffer ); |
1218 // ---------------------------------------------------------- |
|
1219 // |
|
1220 void CCertSaverModel::ShowConfirmationNoteL( TInt aResourceID ) const |
|
1221 { |
|
1222 HBufC* buffer = iAppUi->CoeEnv()->AllocReadResourceLC( aResourceID ); |
|
1223 CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote( ETrue ); |
|
1224 note->ExecuteLD( buffer->Des() ); |
|
1225 CleanupStack::PopAndDestroy( buffer ); |
|
1226 } |
|
1227 |
|
1228 // ---------------------------------------------------------- |
|
1229 // CCertSaverModel::ShowErrorNoteL() const |
|
1230 // Creates and shows an error note. |
|
1231 // ---------------------------------------------------------- |
|
1232 // |
|
1233 void CCertSaverModel::ShowErrorNoteL( TInt aResourceID ) const |
|
1234 { |
|
1235 HBufC* buffer = iAppUi->CoeEnv()->AllocReadResourceLC( aResourceID ); |
|
1236 CAknErrorNote* note = new (ELeave) CAknErrorNote( ETrue ); |
|
1237 note->ExecuteLD(buffer->Des()); |
|
1238 CleanupStack::PopAndDestroy( buffer ); |
|
1239 } |
1257 } |
1240 |
1258 |
1241 // ---------------------------------------------------------- |
1259 // ---------------------------------------------------------- |
1242 // CCertSaverModel::TrimCertificateFields() const |
1260 // CCertSaverModel::TrimCertificateFields() const |
1243 // Trims given descriptor so that everything after and |
1261 // Trims given descriptor so that everything after and |
1312 // Does needed tasks to exit. |
1332 // Does needed tasks to exit. |
1313 // ---------------------------------------------------------- |
1333 // ---------------------------------------------------------- |
1314 // |
1334 // |
1315 TInt CCertSaverModel::QueryTrusterUidsL( RArray<TUid>& aUids ) |
1335 TInt CCertSaverModel::QueryTrusterUidsL( RArray<TUid>& aUids ) |
1316 { |
1336 { |
|
1337 |
1317 TInt ret = KErrCancel; |
1338 TInt ret = KErrCancel; |
1318 CArrayFixFlat<TInt>* selectionArray = |
|
1319 new (ELeave) CArrayFixFlat<TInt>( KTrusterArrayInitSize ); |
|
1320 CleanupStack::PushL( selectionArray ); |
|
1321 CDesCArray* itemsArray = new (ELeave) CDesCArrayFlat( KTrusterArrayInitSize ); |
1339 CDesCArray* itemsArray = new (ELeave) CDesCArrayFlat( KTrusterArrayInitSize ); |
1322 CleanupStack::PushL( itemsArray ); |
1340 CleanupStack::PushL( itemsArray ); |
1323 |
1341 |
1324 CCertificateAppInfoManager* appInfoManager = |
1342 CCertificateAppInfoManager* appInfoManager = |
1325 CCertificateAppInfoManager::NewL( iFs, EFalse ); |
1343 CCertificateAppInfoManager::NewL( iFs, EFalse ); |
1328 const RArray<TCertificateAppInfo>& apps = appInfoManager->Applications(); |
1346 const RArray<TCertificateAppInfo>& apps = appInfoManager->Applications(); |
1329 RArray<TCertificateAppInfo> appsInItemArray( KTrusterArrayInitSize ); |
1347 RArray<TCertificateAppInfo> appsInItemArray( KTrusterArrayInitSize ); |
1330 CleanupClosePushL( appsInItemArray ); |
1348 CleanupClosePushL( appsInItemArray ); |
1331 UpdateTrustListboxItemL( apps, appsInItemArray, *itemsArray ); |
1349 UpdateTrustListboxItemL( apps, appsInItemArray, *itemsArray ); |
1332 |
1350 |
1333 CAknListQueryDialog* dlg = new (ELeave) CAknListQueryDialog( selectionArray ); |
1351 HBufC* title = CEikonEnv::Static()->AllocReadResourceLC( R_CERTSAVER_SELECT_TRUSTED_APPS); |
1334 CleanupStack::PushL( dlg ); |
1352 |
1335 dlg->PrepareLC( R_CERTSAVER_TRUST_SETTINGS_QUERY ); |
1353 RBuf rBuf; // buffer for items with big enough space |
1336 dlg->SetItemTextArray( itemsArray ); |
1354 rBuf.CreateL(KMaxLengthTextMeassageBody); |
1337 dlg->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
1355 CleanupClosePushL(rBuf); |
1338 if ( dlg->RunLD() ) |
1356 for(TInt i = 0; i<itemsArray->Count(); i++) |
1339 { |
1357 rBuf.Append( (*itemsArray)[i] ); |
1340 for ( TInt i = 0; i < selectionArray->Count(); ++i ) |
1358 |
1341 { |
1359 CSecQueryUi* SecQueryUi = CSecQueryUi::NewL(); |
1342 TInt ii = (*selectionArray)[ i ]; |
1360 TInt saved = SecQueryUi->SecQueryDialog(*title, rBuf,1,KTokenLength, |
1343 aUids.Append( appsInItemArray[ ii ].Id() ); |
1361 ESecUiAlphaSupported | ESecUiCancelSupported | |
1344 } |
1362 ESecUiBasicTypeMultiCheck | |
|
1363 ESecUiEmergencyNotSupported); |
|
1364 delete SecQueryUi; |
|
1365 SecQueryUi=NULL; |
|
1366 |
|
1367 if (saved==KErrNone) |
|
1368 { |
|
1369 TLex16 lex(rBuf); |
|
1370 TChar ch; |
|
1371 TBuf16<KTokenLength> token; |
|
1372 TInt val; |
|
1373 while((ch = lex.Get()) != 0 ){ |
|
1374 while ((ch = lex.Peek()) != '|' && ch!=0) lex.Inc(); |
|
1375 token.Copy(lex.MarkedToken()); |
|
1376 TLex lexc(token); |
|
1377 if(lexc.Val(val)!=KErrNone) val=0; |
|
1378 if(val<=appsInItemArray.Count()-1) |
|
1379 aUids.Append( appsInItemArray[ val ].Id() ); |
|
1380 lex.Inc(); |
|
1381 lex.Mark(); |
|
1382 } |
1345 ret = KErrNone; |
1383 ret = KErrNone; |
1346 } |
1384 } |
1347 else |
1385 else |
1348 { |
1386 { |
1349 ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED ); |
1387 ShowInformationNoteL(R_CERTSAVER_CERT_DISCARDED); |
1350 ret = KErrCancel; |
1388 ret = KErrCancel; |
1351 } |
1389 } |
1352 CleanupStack::Pop( dlg ); |
1390 |
1353 CleanupStack::PopAndDestroy( 4, selectionArray ); |
1391 rBuf.Close(); |
|
1392 CleanupStack::PopAndDestroy(&rBuf); |
|
1393 CleanupStack::PopAndDestroy(title); |
|
1394 CleanupStack::PopAndDestroy(&appsInItemArray); |
|
1395 CleanupStack::PopAndDestroy(appInfoManager); |
|
1396 CleanupStack::PopAndDestroy(itemsArray); |
1354 return ret; |
1397 return ret; |
1355 } |
1398 } |
1356 |
1399 |
1357 // ---------------------------------------------------------- |
1400 // ---------------------------------------------------------- |
1358 // CCertSaverModel::QueryTrustedSiteL() |
1401 // CCertSaverModel::QueryTrustedSiteL() |
1359 // Shows query for trusted site certificate |
1402 // Shows query for trusted site certificate |
1360 // ---------------------------------------------------------- |
1403 // ---------------------------------------------------------- |
1361 // |
1404 // |
1362 TInt CCertSaverModel::QueryTrustedSiteL() |
1405 TInt CCertSaverModel::QueryTrustedSiteL() |
1363 { |
1406 { |
|
1407 |
1364 TInt ret = KErrCancel; |
1408 TInt ret = KErrCancel; |
1365 HBufC* label = NULL; |
1409 HBufC* label = NULL; |
1366 HBufC* secondaryName = NULL; |
1410 HBufC* secondaryName = NULL; |
1367 TCertLabel labelBuf; |
1411 TCertLabel labelBuf; |
1368 |
1412 |
1370 (*(CX509Certificate*)iNewCert), label, secondaryName ); |
1414 (*(CX509Certificate*)iNewCert), label, secondaryName ); |
1371 CleanupStack::PushL( label ); |
1415 CleanupStack::PushL( label ); |
1372 delete secondaryName; |
1416 delete secondaryName; |
1373 secondaryName = NULL; |
1417 secondaryName = NULL; |
1374 labelBuf = label->Des().Left( CERTSAVER_MAX_LABEL_LEN ); |
1418 labelBuf = label->Des().Left( CERTSAVER_MAX_LABEL_LEN ); |
1375 |
|
1376 |
|
1377 HBufC* prompt = StringLoader::LoadLC( R_CERTSAVER_TRUSTEDSITE_WARNING, labelBuf ); |
1419 HBufC* prompt = StringLoader::LoadLC( R_CERTSAVER_TRUSTEDSITE_WARNING, labelBuf ); |
1378 |
1420 CHbDeviceMessageBoxSymbian::TButtonId selection = |
1379 CAknMessageQueryDialog* note = CAknMessageQueryDialog::NewL( *prompt ); |
1421 CHbDeviceMessageBoxSymbian::QuestionL(prompt->Des(), KNullDesC, KNullDesC); |
1380 |
1422 if ( selection == CHbDeviceMessageBoxSymbian::EAcceptButton) |
1381 note->PrepareLC( R_CERTSAVER_TRUSTED_SITE_QUERY ); |
|
1382 note->SetPromptL( *prompt ); |
|
1383 |
|
1384 if ( note->RunLD() ) |
|
1385 { |
1423 { |
1386 ret = KErrNone; |
1424 ret = KErrNone; |
1387 } |
1425 } |
1388 else |
1426 else |
1389 { |
1427 { |
1390 ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED ); |
1428 ShowInformationNoteL(R_CERTSAVER_CERT_DISCARDED); |
1391 ret = KErrCancel; |
1429 ret = KErrCancel; |
1392 } |
1430 } |
1393 |
|
1394 CleanupStack::PopAndDestroy( prompt ); |
1431 CleanupStack::PopAndDestroy( prompt ); |
1395 |
|
1396 CleanupStack::PopAndDestroy( label ); |
1432 CleanupStack::PopAndDestroy( label ); |
1397 return ret; |
1433 return ret; |
1398 } |
1434 } |
1399 |
1435 |
1400 // ---------------------------------------------------------- |
1436 // ---------------------------------------------------------- |
1489 // Saves content of the PKCS#12 file |
1527 // Saves content of the PKCS#12 file |
1490 // ---------------------------------------------------- |
1528 // ---------------------------------------------------- |
1491 // |
1529 // |
1492 void CCertSaverModel::SavePKCS12L() |
1530 void CCertSaverModel::SavePKCS12L() |
1493 { |
1531 { |
|
1532 |
1494 HBufC* message = HBufC::NewLC( KMaxLengthTextMeassageBody ); |
1533 HBufC* message = HBufC::NewLC( KMaxLengthTextMeassageBody ); |
1495 TPtr msgPtr = message->Des(); |
1534 TPtr msgPtr = message->Des(); |
1496 ConstructPKCS12QueryMsgL(msgPtr, iParser.Keys().Count(), |
1535 ConstructPKCS12QueryMsgL(msgPtr, iParser.Keys().Count(), |
1497 iParser.UserCertificates().Count(), |
1536 iParser.UserCertificates().Count(), |
1498 iParser.CACertificates().Count() ); |
1537 iParser.CACertificates().Count() ); |
1499 TBool save = DoMessageQueryL( |
1538 |
1500 R_MESSAGE_QUERY_DOSAVE, R_CERTSAVER_HEADER_PKCS12_FILE_CONTAINS, |
1539 //TODO: Should be in loc file but hardcoded now |
1501 *message ); |
1540 _LIT(KCheckBoxCaption,"Protect with Password|1"); |
1502 CleanupStack::PopAndDestroy( message ); |
1541 TBuf<KMaxLengthTextCheckBoxData> CheckeBoxData(KCheckBoxCaption); |
|
1542 |
|
1543 CSecQueryUi* SecQueryUi = CSecQueryUi::NewL(); |
|
1544 TInt save = SecQueryUi->SecQueryDialog(*message, CheckeBoxData,1,1, |
|
1545 ESecUiAlphaSupported | ESecUiCancelSupported | |
|
1546 ESecUiBasicTypeCheck | ESecUiEmergencyNotSupported); |
|
1547 CleanupStack::Pop(message); |
1503 message = NULL; |
1548 message = NULL; |
1504 if ( !save ) |
1549 delete SecQueryUi; |
|
1550 SecQueryUi=NULL; |
|
1551 |
|
1552 if ( save!=KErrNone ) |
1505 { |
1553 { |
1506 ShowInformationNoteL( R_CERTSAVER_PKCS12_DISCARDED ); |
1554 ShowInformationNoteL( R_CERTSAVER_PKCS12_DISCARDED ); |
1507 User::Leave( KErrExitApp ); |
1555 User::Leave( KErrExitApp ); |
1508 } |
1556 } |
1509 TInt status = KErrNone; |
1557 TInt status = KErrNone; |
1510 // save private keys |
1558 // save private keys |
1511 TRAP( status, SavePrivateKeyL() ); |
1559 if(CheckeBoxData.Compare(_L("1"))==0) |
1512 |
1560 { |
|
1561 TRAP( status, SavePrivateKeyL() ); |
|
1562 } |
1513 // save user certificates if private key was saved. |
1563 // save user certificates if private key was saved. |
1514 if ( ( iSavedKeysCount > 0 || iKeyAlreadyExists ) && iParser.UserCertificates().Count() > 0 ) |
1564 if ( ( iSavedKeysCount > 0 || iKeyAlreadyExists ) && iParser.UserCertificates().Count() > 0 ) |
1515 { |
1565 { |
1516 for ( TInt i = 0; i < iParser.UserCertificates().Count(); i++ ) |
1566 for ( TInt i = 0; i < iParser.UserCertificates().Count(); i++ ) |
1517 { |
1567 { |
1540 { |
1590 { |
1541 User::Leave( KErrExitApp ); |
1591 User::Leave( KErrExitApp ); |
1542 } |
1592 } |
1543 } |
1593 } |
1544 } |
1594 } |
|
1595 /* |
1545 if ( iSavedCACertsCount != 0 || iSavedKeysCount != 0 |
1596 if ( iSavedCACertsCount != 0 || iSavedKeysCount != 0 |
1546 || iSavedUserCertsCount != 0 ) |
1597 || iSavedUserCertsCount != 0 ) |
1547 { |
1598 { |
1548 message = HBufC::NewLC( KMaxLengthTextMeassageBody ); |
1599 // show how many have been saved |
1549 TPtr msgPtr2 = message->Des(); |
1600 HBufC* p = StringLoader::LoadLC( R_CERTSAVER_HEADER_SAVED ); |
1550 ConstructPKCS12QueryMsgL( |
1601 message = HBufC::NewLC( KMaxLengthTextMeassageBody ); |
|
1602 message->Des().Append(p->Des()); |
|
1603 TPtr msgPtr2 = message->Des(); |
|
1604 ConstructPKCS12QueryMsgL( |
1551 msgPtr2, iSavedKeysCount, iSavedUserCertsCount, iSavedCACertsCount ); |
1605 msgPtr2, iSavedKeysCount, iSavedUserCertsCount, iSavedCACertsCount ); |
1552 DoMessageQueryL( |
1606 CHbDeviceMessageBoxSymbian::InformationL(message->Des()); |
1553 R_MESSAGE_QUERY_SAVED, R_CERTSAVER_HEADER_SAVED, *message ); |
1607 CleanupStack::PopAndDestroy( message ); |
|
1608 CleanupStack::PopAndDestroy( p ); |
|
1609 } |
|
1610 else |
|
1611 { |
|
1612 // the contents could not be saved is dropped |
|
1613 ShowInformationNoteL( R_QTN_CM_PKCS12_SAVING_FAILED ); |
1554 CleanupStack::PopAndDestroy( message ); |
1614 CleanupStack::PopAndDestroy( message ); |
1555 } |
1615 } |
1556 else |
1616 */ |
1557 { |
|
1558 ShowInformationNoteL( R_QTN_CM_PKCS12_SAVING_FAILED ); |
|
1559 } |
|
1560 } |
|
1561 |
|
1562 // ---------------------------------------------------------- |
|
1563 // CCertSaverModel::DoMessageQuery() |
|
1564 // Displays message query dialog for user. |
|
1565 // ---------------------------------------------------------- |
|
1566 // |
|
1567 TBool CCertSaverModel::DoMessageQueryL( |
|
1568 TInt aDialogResId, |
|
1569 TInt aHeadingResId, |
|
1570 TDesC& aMessage ) |
|
1571 { |
|
1572 CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( aMessage ); |
|
1573 CleanupStack::PushL( dlg ); |
|
1574 dlg->PrepareLC( aDialogResId ); |
|
1575 |
|
1576 HBufC* header = StringLoader::LoadLC( aHeadingResId ); |
|
1577 dlg->QueryHeading()->SetTextL( header->Des() ); |
|
1578 CleanupStack::PopAndDestroy( header ); |
|
1579 CleanupStack::Pop( dlg ); |
|
1580 return dlg->RunLD(); |
|
1581 } |
1617 } |
1582 |
1618 |
1583 // ---------------------------------------------------------- |
1619 // ---------------------------------------------------------- |
1584 // CCertSaverModel::ConstructPKCS12QueryMsgL() const |
1620 // CCertSaverModel::ConstructPKCS12QueryMsgL() const |
1585 // Creates the certificate details message shown to the user. |
1621 // Creates the certificate details message shown to the user. |