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