44 #include <hash.h> |
44 #include <hash.h> |
45 #include <x509certext.h> |
45 #include <x509certext.h> |
46 #include <TrustedSitesStore.h> |
46 #include <TrustedSitesStore.h> |
47 #include <mctwritablecertstore.h> |
47 #include <mctwritablecertstore.h> |
48 |
48 |
|
49 #include "SecQueryUi.h" // needed for password dialog |
|
50 |
|
51 #include <hbdevicemessageboxsymbian.h> // needed for Note dialogs |
|
52 #include <hbdevicenotificationdialogsymbian.h> |
|
53 |
49 // LOCAL CONSTANTS AND MACROS |
54 // LOCAL CONSTANTS AND MACROS |
50 const TInt KCertArrayGranularity = 3; |
55 const TInt KCertArrayGranularity = 3; |
51 const TInt KMaxLengthTextDetailsBody = 5000; |
56 const TInt KMaxLengthTextDetailsBody = 5000; |
52 // CertLabel, Issuer, Owner max visible length |
57 // CertLabel, Issuer, Owner max visible length |
53 const TInt KMaxLengthTextCertLabelVisible = 200; |
58 const TInt KMaxLengthTextCertLabelVisible = 200; |
54 // "dd/mm/yyyy0" |
59 // "dd/mm/yyyy0" |
55 const TInt KMaxLengthTextDateString = 20; |
60 const TInt KMaxLengthTextDateString = 20; |
56 // HH0 |
|
57 const TInt KMaxLengthTextSerialNumberFormatting = 3; |
|
58 // Maximum length of a certificate |
61 // Maximum length of a certificate |
59 const TInt KMaxCertificateLength = 5000; |
62 const TInt KMaxCertificateLength = 5000; |
60 |
63 |
61 // Maximum length of key store password |
64 // Maximum length of key store password |
62 const TInt KMaxKeystorePwLength = 6; |
65 const TInt KMaxKeystorePwLength = 6; |
63 |
66 |
64 const TInt KMinImportKeyPwLen = 1; |
67 const TInt KMinImportKeyPwLen = 1; |
65 |
68 |
66 const TInt KMaxCNLength = 64; |
69 const TInt KMaxCommonNameLength = 64; |
67 |
70 |
68 _LIT(KCertManUIDetailsViewHexFormat, "%02X"); |
|
69 |
|
70 const TInt KFileCertStoreUid( 0x101F501A ); |
|
71 const TInt KWIMCertStoreUid ( 0x101F79D9 ); |
|
72 const TUid KTrustedServerTokenUid = { 0x101FB66F }; |
71 const TUid KTrustedServerTokenUid = { 0x101FB66F }; |
73 const TUid KDeviceCertStoreTokenUid = { 0x101FB668 }; |
72 const TUid KDeviceCertStoreTokenUid = { 0x101FB668 }; |
74 |
73 |
75 _LIT( KBlockSeparator, " " ); |
74 _LIT( KBlockSeparator, " " ); |
76 _LIT( KEnter, "\n" ); |
75 _LIT( KEnter, "\n" ); |
79 _LIT( KKeyStoreCreatePwLabel, "New key store passphrase" ); |
78 _LIT( KKeyStoreCreatePwLabel, "New key store passphrase" ); |
80 _LIT( KKeyStoreImportKeyLabel, "Passphrase of the imported key file" ); |
79 _LIT( KKeyStoreImportKeyLabel, "Passphrase of the imported key file" ); |
81 _LIT( KKeyStoreExportKeyLabel, "Passphrase of the exported key file" ); |
80 _LIT( KKeyStoreExportKeyLabel, "Passphrase of the exported key file" ); |
82 _LIT( KPKCS12TokenLabel, "PKCS12"); |
81 _LIT( KPKCS12TokenLabel, "PKCS12"); |
83 |
82 |
|
83 |
|
84 // TODO: replace with OST tracing |
|
85 #ifdef _DEBUG |
|
86 #include <e32debug.h> |
|
87 #define TRACE(x) RDebug::Printf(x) |
|
88 #define TRACE1(x,y) RDebug::Printf(x,y) |
|
89 #else |
|
90 #define TRACE(x) |
|
91 #define TRACE1(x,y) |
|
92 #endif |
|
93 |
|
94 |
84 // ============================ MEMBER FUNCTIONS =============================== |
95 // ============================ MEMBER FUNCTIONS =============================== |
85 |
96 |
86 // ----------------------------------------------------------------------------- |
97 // ----------------------------------------------------------------------------- |
87 // CCTSecurityDialogsAO::CCTSecurityDialogsAO |
98 // CCTSecurityDialogsAO::CCTSecurityDialogsAO |
88 // C++ default constructor can NOT contain any code, that |
99 // C++ default constructor can NOT contain any code, that |
348 iAuthFailReason = srvAuthFail->FailureReason(); |
359 iAuthFailReason = srvAuthFail->FailureReason(); |
349 CleanupStack::PopAndDestroy( srvAuthFail ); |
360 CleanupStack::PopAndDestroy( srvAuthFail ); |
350 |
361 |
351 iServerName = HBufC::NewL( serverName.Length() ); |
362 iServerName = HBufC::NewL( serverName.Length() ); |
352 iServerName->Des().Copy( serverName ); |
363 iServerName->Des().Copy( serverName ); |
353 |
|
354 HBufC* cn = NULL; |
|
355 iCertLabel = NULL; |
364 iCertLabel = NULL; |
|
365 |
356 // Site will be checked later. For now it is not trusted |
366 // Site will be checked later. For now it is not trusted |
357 iTrustedSite = EFalse; |
367 iTrustedSite = EFalse; |
358 |
368 |
359 |
|
360 CX509Certificate* serverCert = CX509Certificate::NewLC( cert ); |
369 CX509Certificate* serverCert = CX509Certificate::NewLC( cert ); |
361 // Retrieve subject name |
|
362 const CX500DistinguishedName& dName = serverCert->SubjectName(); |
370 const CX500DistinguishedName& dName = serverCert->SubjectName(); |
363 // Retrieve CN |
371 |
364 cn = dName.ExtractFieldL( KX520CommonName ); |
372 HBufC* commonName = dName.ExtractFieldL( KX520CommonName ); |
365 if ( cn != NULL ) |
373 CleanupStack::PushL( commonName ); |
366 { |
374 if( commonName != NULL ) |
367 // commonName exist in the certificate. |
375 { |
368 // Check the length of CN. RFC 3280 states |
376 // Check the length of CN. RFC 3280 states |
369 // that max length of CN is 64. |
377 // that max length of CN is 64. |
370 if ( cn->Length() <= KMaxCNLength ) |
378 if( commonName->Length() <= KMaxCommonNameLength ) |
371 { |
379 { |
372 iCertLabel = HBufC::NewL( cn->Length() ); |
380 iCertLabel = HBufC::NewL( commonName->Length() ); |
373 iCertLabel->Des().Append( cn->Des() ); |
381 iCertLabel->Des().Append( commonName->Des() ); |
374 } |
382 } |
375 } |
383 } |
376 |
384 CleanupStack::PopAndDestroy( commonName ); |
377 if ( iCertLabel == NULL ) |
385 |
378 { |
386 if( iCertLabel == NULL ) |
379 // No or invalid commonName. Use domain name as label |
387 { |
|
388 // No or invalid commonName. Use domain name as label. |
380 iCertLabel = HBufC::NewL( iServerName->Length() ); |
389 iCertLabel = HBufC::NewL( iServerName->Length() ); |
381 iCertLabel->Des().Append( iServerName->Des() ); |
390 iCertLabel->Des().Append( iServerName->Des() ); |
382 } |
391 } |
383 |
392 |
384 CleanupStack::PopAndDestroy( serverCert ); |
393 CleanupStack::PopAndDestroy( serverCert ); |
556 void CCTSecurityDialogsAO::DoHandlePinOperationL() |
565 void CCTSecurityDialogsAO::DoHandlePinOperationL() |
557 { |
566 { |
558 if ( iRetry ) // Is this new try? |
567 if ( iRetry ) // Is this new try? |
559 { |
568 { |
560 // Previous attempt was failed |
569 // Previous attempt was failed |
|
570 // incorrect pin code |
561 DoHandleMessageL( EErrorPinCodeIncorrect, KNullDesC, KNullDesC, 0, 0 ); |
571 DoHandleMessageL( EErrorPinCodeIncorrect, KNullDesC, KNullDesC, 0, 0 ); |
562 } |
572 } |
563 // Ask the PIN code or PUK code |
573 // Ask the PIN code or PUK code |
564 if ( iPIN.iPINLabel == KKeyStoreEnterPwLabel ) |
574 if ( iPIN.iPINLabel == KKeyStoreEnterPwLabel ) |
565 { |
575 { |
566 HBufC* header = StringLoader::LoadLC( |
576 HBufC* header = StringLoader::LoadLC( |
567 R_QTN_CM_HEADING_PHONE_KEYSTORE, CEikonEnv::Static() ); |
577 R_QTN_CM_HEADING_PHONE_KEYSTORE, CEikonEnv::Static() ); |
568 iPIN.iMinLength = KMaxKeystorePwLength; |
578 iPIN.iMinLength = KMaxKeystorePwLength; |
569 DoHandleMessageL( EEnterKeyStorePw, KNullDesC, *header, |
579 DoHandleMessageL( EEnterKeyStorePw, KNullDesC, *header, |
570 iPIN.iMinLength, iPIN.iMaxLength ); |
580 iPIN.iMinLength, iPIN.iMaxLength ); |
571 iMultiLineDlgType = EEnterNewKeyStorePw; |
581 iMultiLineDlgType = EEnterNewKeyStorePw; |
572 CleanupStack::PopAndDestroy( header ); |
582 CleanupStack::PopAndDestroy( header ); |
|
583 RunL(); |
|
584 |
573 } |
585 } |
574 else if ( iPIN.iPINLabel == KKeyStoreImportKeyLabel ) |
586 else if ( iPIN.iPINLabel == KKeyStoreImportKeyLabel ) |
575 { |
587 { |
576 iPIN.iMinLength = KMaxKeystorePwLength; |
588 iPIN.iMinLength = KMaxKeystorePwLength; |
577 DoHandleMessageL( EImportKeyPw, KNullDesC, KNullDesC, |
589 DoHandleMessageL( EImportKeyPw, KNullDesC, KNullDesC, |
618 HBufC* dlgText2 = NULL; |
630 HBufC* dlgText2 = NULL; |
619 CCTPinPinQueryDialog* dlg = NULL; |
631 CCTPinPinQueryDialog* dlg = NULL; |
620 TDialogType dlgType = ( TDialogType )aDlgType; |
632 TDialogType dlgType = ( TDialogType )aDlgType; |
621 if ( EEnterNewKeyStorePw == dlgType ) |
633 if ( EEnterNewKeyStorePw == dlgType ) |
622 { |
634 { |
623 dlgText1 = iNotifier->LoadResourceStringLC( dlgType, KNullDesC ); |
635 /* |
|
636 dlgText1 = iNotifier->LoadResourceStringLC( dlgType, KNullDesC ); |
624 dlgText2 = iNotifier->LoadResourceStringLC( EVerifyKeyStorePw, KNullDesC ); |
637 dlgText2 = iNotifier->LoadResourceStringLC( EVerifyKeyStorePw, KNullDesC ); |
625 dlg = CCTPinPinQueryDialog::NewL( *dlgText1, *dlgText2, iPINValue2, |
638 dlg = CCTPinPinQueryDialog::NewL( *dlgText1, *dlgText2, iPINValue2, |
626 iPINValueVerify, iPIN.iMinLength, iPIN.iMaxLength, iRetValue ); |
639 iPINValueVerify, iPIN.iMinLength, iPIN.iMaxLength, iRetValue ); |
627 dlg->RunDlgLD( iStatus, R_WIM_PWPW_QUERY_DIALOG ); |
640 dlg->RunDlgLD( iStatus, R_WIM_PWPW_QUERY_DIALOG ); |
628 CleanupStack::PopAndDestroy( 2, dlgText1 ); // dlgText1, dlgText2 |
641 CleanupStack::PopAndDestroy( 2, dlgText1 ); // dlgText1, dlgText2 |
|
642 */ |
|
643 dlgText1 = StringLoader::LoadLC( R_QTN_SN_NEW_PHONE_KEYSTORE ); |
|
644 dlgText2 = StringLoader::LoadLC( R_QTN_WIM_VERIFY_PIN ); |
|
645 HBufC* message = HBufC::NewLC( KMaxLengthTextCertLabelVisible ); |
|
646 message->Des().Append(dlgText1->Des()); |
|
647 message->Des().Append(_L("|")); |
|
648 message->Des().Append(dlgText2->Des()); |
|
649 CSecQueryUi* SecQueryUi = CSecQueryUi::NewL(); |
|
650 TInt queryAccepted = SecQueryUi->SecQueryDialog(message->Des(), iPINValueVerify, |
|
651 iPIN.iMinLength,iPIN.iMaxLength, |
|
652 ESecUiAlphaSupported | |
|
653 ESecUiCancelSupported | |
|
654 ESecUiSecretSupported | |
|
655 ESecUiEmergencyNotSupported); |
|
656 iRetValue=(queryAccepted==KErrNone); |
|
657 if(iRetValue) |
|
658 iPINValue2.Copy(iPINValueVerify); // dialog already does not OK with different pin codes |
|
659 delete SecQueryUi; |
|
660 SecQueryUi=NULL; |
|
661 CleanupStack::PopAndDestroy( message ); |
|
662 CleanupStack::PopAndDestroy( dlgText2 ); |
|
663 CleanupStack::PopAndDestroy( dlgText1 ); |
|
664 RunL(); // had to call it this way |
629 } |
665 } |
630 else if ( EExportKeyPw == dlgType ) |
666 else if ( EExportKeyPw == dlgType ) |
631 { |
667 { |
632 dlgText1 = iNotifier->LoadResourceStringLC( dlgType, KNullDesC ); |
668 dlgText1 = iNotifier->LoadResourceStringLC( dlgType, KNullDesC ); |
633 dlgText2 = iNotifier->LoadResourceStringLC( EVerifyKeyStorePw, KNullDesC ); |
669 dlgText2 = iNotifier->LoadResourceStringLC( EVerifyKeyStorePw, KNullDesC ); |
752 { |
788 { |
753 User::Panic(_L("CSecDlgNotifier"), 0); |
789 User::Panic(_L("CSecDlgNotifier"), 0); |
754 } |
790 } |
755 } |
791 } |
756 iPinQueryDialogDeleted = EFalse; |
792 iPinQueryDialogDeleted = EFalse; |
757 CCTPinQueryDialog::RunDlgLD( iStatus, |
793 if(aDlgType!=EEnterKeyStorePw) { |
758 *dlgText, |
794 CCTPinQueryDialog::RunDlgLD( iStatus, |
759 *pinValue, |
795 *dlgText, |
760 aMinLength, |
796 *pinValue, |
761 aMaxLength, |
797 aMinLength, |
762 iRetValue, |
798 aMaxLength, |
763 resource, |
799 iRetValue, |
764 iPinQueryDialog, |
800 resource, |
765 iPinQueryDialogDeleted ); |
801 iPinQueryDialog, |
|
802 iPinQueryDialogDeleted ); |
|
803 break; |
|
804 } |
|
805 else |
|
806 { |
|
807 iPIN.iMinLength = KMaxKeystorePwLength; |
|
808 CSecQueryUi* SecQueryUi = CSecQueryUi::NewL(); |
|
809 HBufC* header =StringLoader::LoadLC( R_QTN_SN_ENTER_PHONE_KEYSTORE); |
|
810 TInt queryAccepted = SecQueryUi->SecQueryDialog(header->Des(), *pinValue, |
|
811 aMinLength,aMaxLength, |
|
812 ESecUiAlphaSupported | |
|
813 ESecUiCancelSupported | |
|
814 ESecUiSecretSupported | |
|
815 ESecUiEmergencyNotSupported); |
|
816 delete SecQueryUi; |
|
817 SecQueryUi=NULL; |
|
818 iRetValue=(queryAccepted==KErrNone); |
|
819 CleanupStack::PopAndDestroy( header ); |
766 break; |
820 break; |
|
821 } |
767 } |
822 } |
768 default: |
823 default: |
769 { |
824 { |
770 break; |
825 break; |
771 } |
826 } |
772 |
827 |
773 } |
828 } |
774 |
829 if ( dlg && aDlgType!=EEnterKeyStorePw) |
775 if ( dlg ) |
830 { |
776 { |
831 |
777 dlg->ExecuteLD( *dlgText ); |
832 dlg->ExecuteLD( *dlgText ); |
778 dlg = NULL; |
833 dlg = NULL; |
779 } |
834 } |
780 |
835 |
781 CleanupStack::PopAndDestroy( dlgText ); // dlgText |
836 CleanupStack::PopAndDestroy( dlgText ); // dlgText |
782 } |
837 } |
783 |
838 |
784 // ----------------------------------------------------------------------------- |
839 // ----------------------------------------------------------------------------- |
934 // |
991 // |
935 void CCTSecurityDialogsAO::RunL() |
992 void CCTSecurityDialogsAO::RunL() |
936 { |
993 { |
937 WIMSECURITYDIALOGS_WRITE_FORMAT( "CCTSecurityDialogsAO::RunL, iStatus %d", iStatus.Int() ); |
994 WIMSECURITYDIALOGS_WRITE_FORMAT( "CCTSecurityDialogsAO::RunL, iStatus %d", iStatus.Int() ); |
938 WIMSECURITYDIALOGS_WRITE_FORMAT( " iNextStep %d", iNextStep ); |
995 WIMSECURITYDIALOGS_WRITE_FORMAT( " iNextStep %d", iNextStep ); |
939 |
996 TRACE1( "CCTSecurityDialogsAO::RunL, iStatus.Int()=%d", iStatus.Int() ); |
940 if ( iStatus != KErrNone ) |
997 |
|
998 if( iStatus != KErrNone ) |
941 { |
999 { |
942 User::Leave( iStatus.Int() ); |
1000 User::Leave( iStatus.Int() ); |
943 } // if |
1001 } |
944 |
1002 |
945 switch ( iNextStep ) |
1003 TRACE1( "CCTSecurityDialogsAO::RunL, iNextStep=%d", iNextStep ); |
|
1004 switch( iNextStep ) |
946 { |
1005 { |
947 case EOperationCompleted: |
1006 case EOperationCompleted: |
948 { |
1007 { |
949 WIMSECURITYDIALOGS_WRITE( "EOperationCompleted" ); |
1008 WIMSECURITYDIALOGS_WRITE( "EOperationCompleted" ); |
950 HandleResponseAndCompleteL(); |
1009 HandleResponseAndCompleteL(); |
951 break; |
1010 break; |
952 } |
1011 } |
|
1012 |
953 case ECheckServerCerts: |
1013 case ECheckServerCerts: |
954 { |
1014 { |
955 WIMSECURITYDIALOGS_WRITE( "ECheckServerCerts" ); |
1015 WIMSECURITYDIALOGS_WRITE( "ECheckServerCerts" ); |
956 |
1016 |
957 TBool foundCert( EFalse ); |
1017 TBool foundCert( EFalse ); |
958 |
1018 |
959 if ( iServerCerts.Count() ) |
1019 if( iServerCerts.Count() ) |
960 { |
1020 { |
961 // Found certificates in the trusted site certificate storage. |
1021 // Found certificates in the trusted site certificate storage. |
962 // Compare them with the one received from TlsProvider |
1022 // Compare them with the one received from TlsProvider |
963 iCertPtr.Set( iCertBuf->Des() ); |
1023 iCertPtr.Set( iCertBuf->Des() ); |
964 CX509Certificate* serverCert = CX509Certificate::NewLC( iCertPtr ); |
1024 CX509Certificate* serverCert = CX509Certificate::NewLC( iCertPtr ); |
965 |
1025 |
966 for (TInt i=0; i<iServerCerts.Count(); i++ ) |
1026 for( TInt i = 0; i < iServerCerts.Count(); i++ ) |
967 { |
1027 { |
968 TPtr8 certPtr( iServerCerts[i]->Des() ); |
1028 TPtr8 certPtr( iServerCerts[i]->Des() ); |
969 |
|
970 CX509Certificate* cert = CX509Certificate::NewLC( certPtr ); |
1029 CX509Certificate* cert = CX509Certificate::NewLC( certPtr ); |
971 |
1030 if( cert->Fingerprint() == serverCert->Fingerprint() ) |
972 // Compare fingerprints |
|
973 if ( cert->Fingerprint() == serverCert->Fingerprint() ) |
|
974 { |
1031 { |
975 // Fingerprints match |
|
976 foundCert = ETrue; |
1032 foundCert = ETrue; |
977 } |
1033 } |
978 CleanupStack::PopAndDestroy( cert ); |
1034 CleanupStack::PopAndDestroy( cert ); |
979 } |
1035 } |
|
1036 |
980 CleanupStack::PopAndDestroy( serverCert ); |
1037 CleanupStack::PopAndDestroy( serverCert ); |
981 if ( foundCert ) |
1038 |
|
1039 if( foundCert ) |
982 { |
1040 { |
983 // Found matching certificate. Complete the operation |
1041 // Found matching certificate. Complete the operation |
984 iRetValue = EServerCertAcceptedPermanently; |
1042 iRetValue = EServerCertAcceptedPermanently; |
985 iNextStep = EOperationCompleted; |
1043 iNextStep = EOperationCompleted; |
986 HandleResponseAndCompleteL(); |
1044 HandleResponseAndCompleteL(); |
987 } |
1045 } |
988 } |
1046 } |
989 |
1047 |
990 if ( !foundCert ) |
1048 if ( !foundCert ) |
991 { |
1049 { |
992 // Couldn't find matching certificate. Prompt user |
1050 // Couldn't find matching certificate. Prompt user |
993 ShowNoTrustDialogL(); |
1051 ShowNoTrustDialogL(); |
994 } |
1052 } |
995 |
|
996 break; |
1053 break; |
997 } |
1054 } |
|
1055 |
998 case EProcessTrustedSite: |
1056 case EProcessTrustedSite: |
999 { |
1057 { |
1000 WIMSECURITYDIALOGS_WRITE( "EProcessTrustedSite" ); |
1058 WIMSECURITYDIALOGS_WRITE( "EProcessTrustedSite" ); |
|
1059 TRACE( "CCTSecurityDialogsAO::RunL, EProcessTrustedSite" ); |
|
1060 |
1001 TInt count = iCertStore->WritableCertStoreCount(); |
1061 TInt count = iCertStore->WritableCertStoreCount(); |
1002 for ( TInt i = 0; i < count; i++ ) |
1062 for( TInt i = 0; i < count; i++ ) |
1003 { |
1063 { |
1004 MCTWritableCertStore *certstore = &iCertStore->WritableCertStore( i ); |
1064 MCTWritableCertStore *certstore = &iCertStore->WritableCertStore( i ); |
1005 MCTToken& token = certstore->Token(); |
1065 MCTToken& token = certstore->Token(); |
1006 TUid tokenuid = token.Handle().iTokenTypeUid; |
1066 TUid tokenuid = token.Handle().iTokenTypeUid; |
1007 if ( tokenuid == KTrustedServerTokenUid ) |
1067 if( tokenuid == KTrustedServerTokenUid ) |
1008 { |
1068 { |
1009 iTrustedSiteCertStore = certstore; |
1069 iTrustedSiteCertStore = certstore; |
1010 } |
1070 } |
1011 } |
1071 } |
1012 |
1072 |
1014 CleanupStack::PushL( trustedSitesStore ); |
1074 CleanupStack::PushL( trustedSitesStore ); |
1015 |
1075 |
1016 // Find out whether or not site associated with certificate is trusted |
1076 // Find out whether or not site associated with certificate is trusted |
1017 iTrustedSite = trustedSitesStore->IsTrustedSiteL( *iCertBuf, *iServerName ); |
1077 iTrustedSite = trustedSitesStore->IsTrustedSiteL( *iCertBuf, *iServerName ); |
1018 |
1078 |
1019 if ( iTrustedSite ) |
1079 if( iTrustedSite ) |
1020 { |
1080 { |
1021 TBool allowOutOfDate = trustedSitesStore->IsOutOfDateAllowedL(*iCertBuf, *iServerName); |
1081 TBool allowOutOfDate = trustedSitesStore->IsOutOfDateAllowedL(*iCertBuf, *iServerName); |
1022 |
1082 |
1023 if (!allowOutOfDate) |
1083 if( !allowOutOfDate ) |
1024 { |
1084 { |
1025 CX509Certificate* cert = CX509Certificate::NewLC( iCertBuf->Des() ); |
1085 CX509Certificate* cert = CX509Certificate::NewLC( iCertBuf->Des() ); |
1026 |
1086 |
1027 const CValidityPeriod& validityPeriod = cert->ValidityPeriod(); |
1087 const CValidityPeriod& validityPeriod = cert->ValidityPeriod(); |
1028 const TTime& startValue = validityPeriod.Start(); |
1088 const TTime& startValue = validityPeriod.Start(); |
1106 TRequestStatus* status = &iStatus; |
1166 TRequestStatus* status = &iStatus; |
1107 User::RequestComplete( status, KErrNone ); |
1167 User::RequestComplete( status, KErrNone ); |
1108 } |
1168 } |
1109 break; |
1169 break; |
1110 } |
1170 } |
|
1171 |
1111 case EAddTrustedSite: |
1172 case EAddTrustedSite: |
1112 { |
1173 { |
1113 if ( iStatus.Int() == KErrNone ) |
1174 TRACE( "CCTSecurityDialogsAO::RunL, EAddTrustedSite" ); |
|
1175 if( iStatus.Int() == KErrNone ) |
1114 { |
1176 { |
1115 //Added server certificate succesfully |
1177 //Added server certificate succesfully |
1116 CTrustSitesStore* trustedSitesStore = CTrustSitesStore::NewL(); |
1178 CTrustSitesStore* trustedSitesStore = CTrustSitesStore::NewL(); |
1117 CleanupStack::PushL( trustedSitesStore ); |
1179 CleanupStack::PushL( trustedSitesStore ); |
1118 |
1180 |
1119 TInt status = trustedSitesStore->AddL( *iCertBuf, *iServerName ); |
1181 TInt status = trustedSitesStore->AddL( *iCertBuf, *iServerName ); |
1120 |
1182 |
1121 CleanupStack::PopAndDestroy( trustedSitesStore ); |
1183 CleanupStack::PopAndDestroy( trustedSitesStore ); |
1122 if ( status == KErrNone ) |
1184 if( status == KErrNone ) |
1123 { |
1185 { |
1124 iRetValue = EServerCertAcceptedPermanently; |
1186 iRetValue = EServerCertAcceptedPermanently; |
1125 } |
1187 } |
1126 else |
1188 else |
1127 { |
1189 { |
1132 HandleResponseAndCompleteL(); |
1194 HandleResponseAndCompleteL(); |
1133 } |
1195 } |
1134 else |
1196 else |
1135 { |
1197 { |
1136 //Adding server certificate failed |
1198 //Adding server certificate failed |
|
1199 // TODO: unreached code? |
1137 iNextStep = EOperationCompleted; |
1200 iNextStep = EOperationCompleted; |
1138 iRetValue = EServerCertNotAccepted; |
1201 iRetValue = EServerCertNotAccepted; |
1139 HandleResponseAndCompleteL(); |
1202 HandleResponseAndCompleteL(); |
1140 } |
1203 } |
1141 break; |
1204 break; |
1142 } |
1205 } |
1143 |
1206 |
1144 case ESaveServerCert: |
1207 case ESaveServerCert: |
1145 { |
1208 { |
1146 WIMSECURITYDIALOGS_WRITE( "ESaveServerCert" ); |
1209 WIMSECURITYDIALOGS_WRITE( "ESaveServerCert" ); |
|
1210 TRACE( "CCTSecurityDialogsAO::RunL, ESaveServerCert" ); |
1147 DoHandleSaveServerCertL(); |
1211 DoHandleSaveServerCertL(); |
1148 break; |
1212 break; |
1149 } |
1213 } |
|
1214 |
1150 case EServerCertCheckUserResp: |
1215 case EServerCertCheckUserResp: |
1151 { |
1216 { |
1152 WIMSECURITYDIALOGS_WRITE( "EServerCertCheckUserResp" ); |
1217 WIMSECURITYDIALOGS_WRITE( "EServerCertCheckUserResp" ); |
1153 if ( iRetValue == EServerCertAcceptedPermanently ) |
1218 TRACE( "CCTSecurityDialogsAO::RunL, EServerCertCheckUserResp" ); |
|
1219 if( iRetValue == EServerCertAcceptedPermanently ) |
1154 { |
1220 { |
1155 // User accepted to select certificate permanently. |
1221 // User accepted to select certificate permanently. |
1156 // First add server certificate |
1222 // First add server certificate |
1157 iNextStep = ESaveServerCert; |
1223 iNextStep = ESaveServerCert; |
1158 iStatus = KRequestPending; |
1224 iStatus = KRequestPending; |
1266 User::RequestComplete( status, KErrNone ); |
1338 User::RequestComplete( status, KErrNone ); |
1267 } |
1339 } |
1268 iNextStep = EInitKeyStore; |
1340 iNextStep = EInitKeyStore; |
1269 break; |
1341 break; |
1270 } |
1342 } |
|
1343 |
1271 case EInitKeyStore: |
1344 case EInitKeyStore: |
1272 { |
1345 { |
1273 InitKeyStoreL(); |
1346 InitKeyStoreL(); |
1274 iNextStep = EGetKeyInfos; |
1347 iNextStep = EGetKeyInfos; |
1275 break; |
1348 break; |
1276 } |
1349 } |
|
1350 |
1277 case EGetKeyInfos: |
1351 case EGetKeyInfos: |
1278 { |
1352 { |
1279 GetKeyInfosL(); |
1353 GetKeyInfosL(); |
1280 iNextStep = EShowCertDialog; |
1354 iNextStep = EShowCertDialog; |
1281 break; |
1355 break; |
1282 } |
1356 } |
|
1357 |
1283 case EGetKeyInfoByHandle: |
1358 case EGetKeyInfoByHandle: |
1284 { |
1359 { |
1285 GetKeyInfoByHandleL(); |
1360 GetKeyInfoByHandleL(); |
1286 iNextStep = EShowCSRDialog; |
1361 iNextStep = EShowCSRDialog; |
1287 break; |
1362 break; |
1288 } |
1363 } |
|
1364 |
1289 case EShowCSRDialog: |
1365 case EShowCSRDialog: |
1290 { |
1366 { |
1291 ShowCSRDialogL(); |
1367 ShowCSRDialogL(); |
1292 iNextStep = EOperationCompleted; |
1368 iNextStep = EOperationCompleted; |
1293 break; |
1369 break; |
1294 } |
1370 } |
|
1371 |
1295 case EShowCertDialog: |
1372 case EShowCertDialog: |
1296 { |
1373 { |
1297 ShowCertDialogL(); |
1374 ShowCertDialogL(); |
1298 iNextStep = EOperationCompleted; |
1375 iNextStep = EOperationCompleted; |
1299 break; |
1376 break; |
1300 } |
1377 } |
|
1378 |
1301 ///////////// |
1379 ///////////// |
1302 // PIN steps |
1380 // PIN steps |
1303 ///////////// |
1381 ///////////// |
1304 case EEnterNewPIN: |
1382 case EEnterNewPIN: |
1305 { |
1383 { |
1432 // CCTSecurityDialogsAO::ShowNoTrustDialogL() |
1512 // CCTSecurityDialogsAO::ShowNoTrustDialogL() |
1433 // ----------------------------------------------------------------------------- |
1513 // ----------------------------------------------------------------------------- |
1434 // |
1514 // |
1435 void CCTSecurityDialogsAO::ShowNoTrustDialogL() |
1515 void CCTSecurityDialogsAO::ShowNoTrustDialogL() |
1436 { |
1516 { |
1437 CX509Certificate* cert = CX509Certificate::NewLC( iCertBuf->Des() ); |
1517 TRACE( "CCTSecurityDialogsAO::ShowNoTrustDialogL, begin" ); |
1438 TInt resourceid = R_WIM_NO_TRUST_QUERY_UNTRUSTED; |
1518 |
1439 TBool showPermAccept = ETrue; |
1519 // If trusted site certstore open has failed, then it is not possible to save |
1440 |
1520 // the host name for permanent use. Hence, choice for permanent accept is not |
1441 if( iAuthFailReason == ESignatureInvalid || iAuthFailReason == ECertificateRevoked ) |
1521 // displayed if trusted site certstore open has failed. Other restrictions for |
1442 { |
1522 // permanent accept are defined in device dialog (UntrustedCertificateWidget). |
1443 // Invalid or revoked certificate |
1523 TBool isTrustedSiteCertStoreOpened = ( iTrustedSiteCertStore != NULL ); |
1444 CCTInvalidCertificateNote* note = |
1524 CCTUntrustedCertQuery *untrustedCertDlg = CCTUntrustedCertQuery::NewLC( |
1445 new( ELeave ) CCTInvalidCertificateNote( *this, iStatus ); |
1525 iAuthFailReason, *iCertBuf, *iServerName, isTrustedSiteCertStoreOpened ); |
1446 note->ExecuteLD( R_WIM_INVALID_CERTIFICATE_INFORMATION_NOTE ); |
1526 |
1447 iRetValue = EServerCertNotAccepted; |
1527 CCTUntrustedCertQuery::TResponse response = CCTUntrustedCertQuery::EQueryRejected; |
1448 } |
1528 untrustedCertDlg->ShowQueryAndWaitForResponseL( response ); |
1449 else |
1529 switch( response ) |
1450 { |
1530 { |
1451 if( iAuthFailReason == EValidatedOK || iAuthFailReason == EDateOutOfRange ) |
1531 case CCTUntrustedCertQuery::EQueryAccepted: |
1452 { |
1532 iRetValue = EServerCertAcceptedTemporarily; |
1453 // Trusted certificate, but problems with CN or date |
1533 break; |
1454 |
1534 case CCTUntrustedCertQuery::EQueryAcceptedPermanently: |
1455 // Retrieve subject name |
1535 // TODO: show confirmation note, qtn_httpsec_query_perm_accept_text |
1456 const CX500DistinguishedName& dName = cert->SubjectName(); |
1536 // "Connection to site %U will be made in future without any warnings. Continue?"" |
1457 |
1537 iRetValue = EServerCertAcceptedPermanently; |
1458 // Retrieve common name |
1538 break; |
1459 HBufC* cn = dName.ExtractFieldL( KX520CommonName ); |
1539 case CCTUntrustedCertQuery::EQueryRejected: |
1460 |
1540 default: |
1461 // Check common name first and then date |
1541 iRetValue = EServerCertNotAccepted; |
1462 if( !cn ) |
1542 break; |
1463 { |
1543 } |
1464 // Couldn't retrieve CN from certificate |
1544 CleanupStack::PopAndDestroy( untrustedCertDlg ); |
1465 resourceid = R_WIM_NO_TRUST_QUERY_UNTRUSTED; |
1545 TRACE1( "CCTSecurityDialogsAO::ShowNoTrustDialogL, iRetValue=%d", iRetValue ); |
1466 } |
|
1467 else if( iServerName->Des() != cn->Des() ) |
|
1468 { |
|
1469 // Domain name doesn't match with CN |
|
1470 resourceid = R_WIM_NO_TRUST_QUERY_SITE; |
|
1471 } |
|
1472 else if( iAuthFailReason == EDateOutOfRange ) |
|
1473 { |
|
1474 // Certificate is out of date |
|
1475 resourceid = R_WIM_NO_TRUST_QUERY_OOD; |
|
1476 showPermAccept = EFalse; |
|
1477 } |
|
1478 else |
|
1479 { |
|
1480 // Otherwise show general untrusted note |
|
1481 resourceid = R_WIM_NO_TRUST_QUERY_UNTRUSTED; |
|
1482 } |
|
1483 } |
|
1484 else |
|
1485 { |
|
1486 // Untrusted certificate |
|
1487 resourceid = R_WIM_NO_TRUST_QUERY_UNTRUSTED; |
|
1488 } |
|
1489 |
|
1490 // No "Accept Permanently" option if certificate is out of date, or |
|
1491 // if domain name is not defined, or if trusted site store failed to |
|
1492 // open (and it's not possible to save the server certificate). |
|
1493 const CValidityPeriod& validityPeriod = cert->ValidityPeriod(); |
|
1494 const TTime& startValue = validityPeriod.Start(); |
|
1495 const TTime& finishValue = validityPeriod.Finish(); |
|
1496 TTime current; |
|
1497 current.UniversalTime(); |
|
1498 |
|
1499 if( (( startValue > current ) || ( finishValue < current )) || |
|
1500 ( iServerName->Des().Length() == 0 ) || |
|
1501 ( !iTrustedSiteCertStore ) ) |
|
1502 { |
|
1503 showPermAccept = EFalse; |
|
1504 } |
|
1505 |
|
1506 iQueryDialog = new( ELeave ) CCTNoTrustQuery( *this, iRetValue, iStatus, iServerName, |
|
1507 showPermAccept, iQueryDialogDeleted ); |
|
1508 iQueryDialog->ExecuteLD( resourceid ); |
|
1509 } |
|
1510 |
|
1511 CleanupStack::PopAndDestroy( cert ); |
|
1512 |
1546 |
1513 iNextStep = EServerCertCheckUserResp; |
1547 iNextStep = EServerCertCheckUserResp; |
1514 iStatus = KRequestPending; |
1548 iStatus = KRequestPending; |
|
1549 TRequestStatus* status = &iStatus; |
|
1550 User::RequestComplete( status, KErrNone ); |
1515 SetActive(); |
1551 SetActive(); |
1516 } |
1552 } |
1517 |
1553 |
1518 // ----------------------------------------------------------------------------- |
1554 // ----------------------------------------------------------------------------- |
1519 // CCTSecurityDialogsAO::ShowCSRDialogL() |
1555 // CCTSecurityDialogsAO::ShowCSRDialogL() |
2310 pinValueBufPtr = iPINValue1; |
2346 pinValueBufPtr = iPINValue1; |
2311 } |
2347 } |
2312 iMessagePtr.WriteL( iReplySlot, pinValueBufPtr ); |
2348 iMessagePtr.WriteL( iReplySlot, pinValueBufPtr ); |
2313 break; |
2349 break; |
2314 } |
2350 } |
|
2351 |
2315 case EChangePIN: |
2352 case EChangePIN: |
2316 case EUnblockPIN: |
2353 case EUnblockPIN: |
2317 { |
2354 { |
2318 TTwoPINOutput twoPINOutput; |
2355 TTwoPINOutput twoPINOutput; |
2319 twoPINOutput.iPINValueToCheck = iPINValue1; |
2356 twoPINOutput.iPINValueToCheck = iPINValue1; |
2320 twoPINOutput.iNewPINValue = iPINValue2; |
2357 twoPINOutput.iNewPINValue = iPINValue2; |
2321 TTwoPINOutputBuf twoPINOutputBuf( twoPINOutput ); |
2358 TTwoPINOutputBuf twoPINOutputBuf( twoPINOutput ); |
2322 iMessagePtr.WriteL( iReplySlot, twoPINOutputBuf ); |
2359 iMessagePtr.WriteL( iReplySlot, twoPINOutputBuf ); |
2323 break; |
2360 break; |
2324 } |
2361 } |
|
2362 |
2325 case ESignText: // flow thru |
2363 case ESignText: // flow thru |
2326 case EUserAuthenticationText: // flow thru |
2364 case EUserAuthenticationText: // flow thru |
2327 case EUserAuthentication: |
2365 case EUserAuthentication: |
2328 { |
2366 { |
2329 TCTTokenObjectHandleBuf tokenObjectHandleBuf( iTokenHandle ); |
2367 TCTTokenObjectHandleBuf tokenObjectHandleBuf( iTokenHandle ); |
2330 iMessagePtr.WriteL( iReplySlot, tokenObjectHandleBuf ); |
2368 iMessagePtr.WriteL( iReplySlot, tokenObjectHandleBuf ); |
2331 break; |
2369 break; |
2332 } |
2370 } |
|
2371 |
2333 case EServerAuthenticationFailure: |
2372 case EServerAuthenticationFailure: |
2334 { |
2373 { |
2335 TServerAuthenticationFailureDialogResult result = EStop; |
2374 TServerAuthenticationFailureDialogResult result = EStop; |
2336 |
2375 |
2337 if ( iRetValue != EServerCertAcceptedPermanently ) |
2376 if( iRetValue != EServerCertAcceptedPermanently ) |
2338 { |
2377 { |
2339 if ( iRetValue == EServerCertAcceptedTemporarily ) |
2378 if( iRetValue == EServerCertAcceptedTemporarily ) |
2340 { |
2379 { |
2341 result = EContinue; |
2380 result = EContinue; |
2342 } |
2381 } |
2343 else |
2382 else |
2344 { |
2383 { |
2423 // ----------------------------------------------------------------------------- |
2465 // ----------------------------------------------------------------------------- |
2424 // |
2466 // |
2425 void CCTSecurityDialogsAO::DoCancel() |
2467 void CCTSecurityDialogsAO::DoCancel() |
2426 { |
2468 { |
2427 WIMSECURITYDIALOGS_WRITE( "CCTSecurityDialogsAO::DoCancel" ); |
2469 WIMSECURITYDIALOGS_WRITE( "CCTSecurityDialogsAO::DoCancel" ); |
2428 |
2470 if( !iPinQueryDialogDeleted ) |
2429 // Note that iQueryDialog may point to already deleted memory. |
|
2430 // Dialogs need to set and reset iQueryDialogDeleted flag to |
|
2431 // allow deleting the dialog from CCTSecurityDialogsAO. |
|
2432 if( !iQueryDialogDeleted ) |
|
2433 { |
|
2434 delete iQueryDialog; |
|
2435 iQueryDialogDeleted = ETrue; |
|
2436 } |
|
2437 iQueryDialog = NULL; |
|
2438 |
|
2439 if ( !iPinQueryDialogDeleted ) |
|
2440 { |
2471 { |
2441 delete iPinQueryDialog; |
2472 delete iPinQueryDialog; |
2442 iPinQueryDialogDeleted = ETrue; |
2473 iPinQueryDialogDeleted = ETrue; |
2443 } |
2474 } |
2444 iPinQueryDialog = NULL; |
2475 iPinQueryDialog = NULL; |
2467 // CCTSecurityDialogsAO::DoHandleSaveServerCertL() |
2498 // CCTSecurityDialogsAO::DoHandleSaveServerCertL() |
2468 // ----------------------------------------------------------------------------- |
2499 // ----------------------------------------------------------------------------- |
2469 // |
2500 // |
2470 void CCTSecurityDialogsAO::DoHandleSaveServerCertL() |
2501 void CCTSecurityDialogsAO::DoHandleSaveServerCertL() |
2471 { |
2502 { |
|
2503 TRACE( "CCTSecurityDialogsAO::DoHandleSaveServerCertL" ); |
|
2504 |
2472 if ( iTrustedSiteCertStore ) |
2505 if ( iTrustedSiteCertStore ) |
2473 { |
2506 { |
2474 iTrustedSiteCertStore->Add( *iCertLabel, EX509Certificate, |
2507 iTrustedSiteCertStore->Add( *iCertLabel, EX509Certificate, |
2475 EPeerCertificate, NULL, NULL, *iCertBuf, iStatus ); |
2508 EPeerCertificate, NULL, NULL, *iCertBuf, iStatus ); |
2476 |
2509 |
2477 // Next step is to update trust site db |
2510 // Next step is to update trust site db |
2478 iNextStep = EAddTrustedSite; |
2511 iNextStep = EAddTrustedSite; |
2479 iStatus = KRequestPending; |
2512 iStatus = KRequestPending; |
2480 SetActive(); |
2513 SetActive(); |