47 #include <mctwritablecertstore.h> |
47 #include <mctwritablecertstore.h> |
48 |
48 |
49 // LOCAL CONSTANTS AND MACROS |
49 // LOCAL CONSTANTS AND MACROS |
50 const TInt KCertArrayGranularity = 3; |
50 const TInt KCertArrayGranularity = 3; |
51 const TInt KMaxLengthTextDetailsBody = 5000; |
51 const TInt KMaxLengthTextDetailsBody = 5000; |
52 // CertLabel, Issuer, Owner max length 510 bytes |
|
53 const TInt KMaxLengthTextCertLabel = 510; |
|
54 // CertLabel, Issuer, Owner max visible length |
52 // CertLabel, Issuer, Owner max visible length |
55 const TInt KMaxLengthTextCertLabelVisible = 200; |
53 const TInt KMaxLengthTextCertLabelVisible = 200; |
56 // "dd/mm/yyyy0" |
54 // "dd/mm/yyyy0" |
57 const TInt KMaxLengthTextDateString = 20; |
55 const TInt KMaxLengthTextDateString = 20; |
58 // HH0 |
56 // HH0 |
184 iRetry = *reinterpret_cast<const TInt *>( aBuffer.Ptr() ) & EPINValueIncorrect; |
182 iRetry = *reinterpret_cast<const TInt *>( aBuffer.Ptr() ) & EPINValueIncorrect; |
185 iReplySlot = aReplySlot; |
183 iReplySlot = aReplySlot; |
186 iMessagePtr = aMessage; |
184 iMessagePtr = aMessage; |
187 |
185 |
188 WIMSECURITYDIALOGS_WRITE_FORMAT( "CCTSecurityDialogsAO::StartLD iOperation=%d", iOperation ); |
186 WIMSECURITYDIALOGS_WRITE_FORMAT( "CCTSecurityDialogsAO::StartLD iOperation=%d", iOperation ); |
189 |
187 |
190 MapTlsProviderOperation( iOperation ); |
188 MapTlsProviderOperation( iOperation ); |
191 |
189 |
192 switch ( iOperation ) |
190 switch ( iOperation ) |
193 { |
191 { |
194 case EEnablePIN: // flow thru |
192 case EEnablePIN: // flow thru |
324 } |
322 } |
325 default: |
323 default: |
326 User::Panic( _L("CTestSecDlgNotifier"), 0 ); |
324 User::Panic( _L("CTestSecDlgNotifier"), 0 ); |
327 break; |
325 break; |
328 } |
326 } |
329 |
327 |
330 // Note that CCTSecurityDialogsAO::StartLD() must complete the given message and |
328 // Note that CCTSecurityDialogsAO::StartLD() must complete the given message and |
331 // delete itself when ready. However, there may be several steps before it can be |
329 // delete itself when ready. However, there may be several steps before it can be |
332 // deleted. CCTSecurityDialogsAO::HandleResponseAndCompleteL() completes the given |
330 // deleted. CCTSecurityDialogsAO::HandleResponseAndCompleteL() completes the given |
333 // message and deletes CCTSecurityDialogsAO object. Hence, every operation handling |
331 // message and deletes CCTSecurityDialogsAO object. Hence, every operation handling |
334 // function called above must call HandleResponseAndCompleteL() when it is ready. |
332 // function called above must call HandleResponseAndCompleteL() when it is ready. |
541 { |
539 { |
542 // Previous attempt was failed |
540 // Previous attempt was failed |
543 DoHandleMessageL( EErrorPukCodeIncorrect, KNullDesC, KNullDesC, 0, 0 ); |
541 DoHandleMessageL( EErrorPukCodeIncorrect, KNullDesC, KNullDesC, 0, 0 ); |
544 } |
542 } |
545 // Ask the PUK code |
543 // Ask the PUK code |
546 // The label is iPIN instead of iUnblockPIN, since we need to show to |
544 // The label is iPIN instead of iUnblockPIN, since we need to show to |
547 // the user which PIN to unblock |
545 // the user which PIN to unblock |
548 DoHandleMessageL( EEnterPukNR, iPIN.iPINLabel, |
546 DoHandleMessageL( EEnterPukNR, iPIN.iPINLabel, |
549 iPIN.iTokenLabel, iUnblockPIN.iMinLength, iUnblockPIN.iMaxLength ); |
547 iPIN.iTokenLabel, iUnblockPIN.iMinLength, iUnblockPIN.iMaxLength ); |
550 iNextStep = EEnterNewPIN; |
548 iNextStep = EEnterNewPIN; |
551 iMultiLineDlgType = EEnterNewPinNR; |
549 iMultiLineDlgType = EEnterNewPinNR; |
998 break; |
996 break; |
999 } |
997 } |
1000 case EProcessTrustedSite: |
998 case EProcessTrustedSite: |
1001 { |
999 { |
1002 WIMSECURITYDIALOGS_WRITE( "EProcessTrustedSite" ); |
1000 WIMSECURITYDIALOGS_WRITE( "EProcessTrustedSite" ); |
1003 TInt count = iCertStore->WritableCertStoreCount(); |
1001 TInt count = iCertStore->WritableCertStoreCount(); |
1004 for ( TInt i = 0; i < count; i++ ) |
1002 for ( TInt i = 0; i < count; i++ ) |
|
1003 { |
|
1004 MCTWritableCertStore *certstore = &iCertStore->WritableCertStore( i ); |
|
1005 MCTToken& token = certstore->Token(); |
|
1006 TUid tokenuid = token.Handle().iTokenTypeUid; |
|
1007 if ( tokenuid == KTrustedServerTokenUid ) |
1005 { |
1008 { |
1006 MCTWritableCertStore *certstore = &iCertStore->WritableCertStore( i ); |
1009 iTrustedSiteCertStore = certstore; |
1007 MCTToken& token = certstore->Token(); |
1010 } |
1008 TUid tokenuid = token.Handle().iTokenTypeUid; |
1011 } |
1009 if ( tokenuid == KTrustedServerTokenUid ) |
1012 |
|
1013 CTrustSitesStore* trustedSitesStore = CTrustSitesStore::NewL(); |
|
1014 CleanupStack::PushL( trustedSitesStore ); |
|
1015 |
|
1016 // Find out whether or not site associated with certificate is trusted |
|
1017 iTrustedSite = trustedSitesStore->IsTrustedSiteL( *iCertBuf, *iServerName ); |
|
1018 |
|
1019 if ( iTrustedSite ) |
|
1020 { |
|
1021 TBool allowOutOfDate = trustedSitesStore->IsOutOfDateAllowedL(*iCertBuf, *iServerName); |
|
1022 |
|
1023 if (!allowOutOfDate) |
|
1024 { |
|
1025 CX509Certificate* cert = CX509Certificate::NewLC( iCertBuf->Des() ); |
|
1026 |
|
1027 const CValidityPeriod& validityPeriod = cert->ValidityPeriod(); |
|
1028 const TTime& startValue = validityPeriod.Start(); |
|
1029 const TTime& finishValue = validityPeriod.Finish(); |
|
1030 TTime current; |
|
1031 current.UniversalTime(); |
|
1032 |
|
1033 // First check certificate validity period |
|
1034 if ( ( startValue > current ) || ( finishValue < current ) ) |
1010 { |
1035 { |
1011 iTrustedSiteCertStore = certstore; |
1036 iTrustedSite = EFalse; |
1012 } |
1037 } |
|
1038 |
|
1039 CleanupStack::PopAndDestroy( cert ); |
1013 } |
1040 } |
1014 |
1041 } |
1015 CTrustSitesStore* trustedSitesStore = CTrustSitesStore::NewL(); |
1042 CleanupStack::PopAndDestroy( trustedSitesStore ); |
1016 CleanupStack::PushL( trustedSitesStore ); |
1043 |
1017 |
1044 if ( iTrustedSite ) |
1018 // Find out whether or not site associated with certificate is trusted |
1045 { |
1019 iTrustedSite = trustedSitesStore->IsTrustedSiteL( *iCertBuf, *iServerName ); |
1046 // Site is trusted. Next step is to check that server |
1020 |
1047 // certificate is in the trusted site certificate storage |
1021 if ( iTrustedSite ) |
1048 iNextStep = ERetrieveServerCerts; |
1022 { |
1049 iStatus = KRequestPending; |
1023 TBool allowOutOfDate = trustedSitesStore->IsOutOfDateAllowedL(*iCertBuf, *iServerName ); |
1050 SetActive(); |
1024 |
1051 TRequestStatus* status = &iStatus; |
1025 if (!allowOutOfDate) |
1052 User::RequestComplete( status, KErrNone ); |
1026 { |
1053 } |
1027 CX509Certificate* cert = CX509Certificate::NewLC( iCertBuf->Des() ); |
1054 else |
1028 |
1055 { |
1029 const CValidityPeriod& validityPeriod = cert->ValidityPeriod(); |
1056 // Site is not trusted. Prompt user |
1030 const TTime& startValue = validityPeriod.Start(); |
1057 ShowNoTrustDialogL(); |
1031 const TTime& finishValue = validityPeriod.Finish(); |
1058 } |
1032 TTime current; |
|
1033 current.UniversalTime(); |
|
1034 |
|
1035 // First check certificate validity period |
|
1036 if ( ( startValue > current ) || ( finishValue < current ) ) |
|
1037 { |
|
1038 iTrustedSite = EFalse; |
|
1039 } |
|
1040 |
|
1041 CleanupStack::PopAndDestroy(); //cert |
|
1042 } |
|
1043 } |
|
1044 CleanupStack::PopAndDestroy( trustedSitesStore ); // trustedSitesStore |
|
1045 |
|
1046 if ( iTrustedSite ) |
|
1047 { |
|
1048 // Site is trusted. Next step is to check that server |
|
1049 // certificate is in the trusted site certificate storage |
|
1050 iNextStep = ERetrieveServerCerts; |
|
1051 iStatus = KRequestPending; |
|
1052 SetActive(); |
|
1053 TRequestStatus* status = &iStatus; |
|
1054 User::RequestComplete( status, KErrNone ); |
|
1055 } |
|
1056 else |
|
1057 { |
|
1058 // Site is not trusted. Prompt user |
|
1059 ShowNoTrustDialogL(); |
|
1060 } |
|
1061 |
1059 |
1062 break; |
1060 break; |
1063 } |
1061 } |
1064 |
1062 |
1065 case ERetrieveServerCerts: |
1063 case ERetrieveServerCerts: |
1392 // ----------------------------------------------------------------------------- |
1390 // ----------------------------------------------------------------------------- |
1393 // |
1391 // |
1394 void CCTSecurityDialogsAO::DoHandleSelectCertificateL() |
1392 void CCTSecurityDialogsAO::DoHandleSelectCertificateL() |
1395 { |
1393 { |
1396 TBool foundDevCert = EFalse; |
1394 TBool foundDevCert = EFalse; |
1397 |
1395 |
1398 // Check certificate list to find out if there is certificate from |
1396 // Check certificate list to find out if there is certificate from |
1399 // Device Certificate Store. |
1397 // Device Certificate Store. |
1400 for ( TInt ii = 0; ii < iCertHandleList.Count(); ii++) |
1398 for ( TInt ii = 0; ii < iCertHandleList.Count(); ii++) |
1401 { |
1399 { |
1402 TCTTokenObjectHandle handle = iCertHandleList[ii]; |
1400 TCTTokenObjectHandle handle = iCertHandleList[ii]; |
1403 if ( handle.iTokenHandle.iTokenTypeUid == KDeviceCertStoreTokenUid ) |
1401 if ( handle.iTokenHandle.iTokenTypeUid == KDeviceCertStoreTokenUid ) |
1404 { |
1402 { |
1405 // Found a certificate from Device Certificate Store. |
1403 // Found a certificate from Device Certificate Store. |
1406 foundDevCert = ETrue; |
1404 foundDevCert = ETrue; |
1407 iTokenHandle = handle; |
1405 iTokenHandle = handle; |
1408 iRetValue = ETrue; |
1406 iRetValue = ETrue; |
1409 iNextStep = EOperationCompleted; |
1407 iNextStep = EOperationCompleted; |
1410 iStatus = KRequestPending; |
1408 iStatus = KRequestPending; |
1411 SetActive(); |
1409 SetActive(); |
1412 TRequestStatus* status = &iStatus; |
1410 TRequestStatus* status = &iStatus; |
1413 User::RequestComplete( status, KErrNone ); |
1411 User::RequestComplete( status, KErrNone ); |
1414 break; |
1412 break; |
1415 } |
1413 } |
1416 |
1414 |
1417 } |
1415 } |
1418 |
1416 |
1419 if ( !foundDevCert ) |
1417 if ( !foundDevCert ) |
1420 { |
1418 { |
1421 // No certificate from Device Certificate Store. Prompt user |
1419 // No certificate from Device Certificate Store. Prompt user |
1422 // for certificate selection |
1420 // for certificate selection |
1423 CCTSelectCertificateDialog::RunDlgLD( |
1421 CCTSelectCertificateDialog::RunDlgLD( |
1424 iCertArray, iCertHandleList, iTokenHandle, |
1422 iCertArray, iCertHandleList, iTokenHandle, |
1425 iStatus, iRetValue ); // Takes ownerhip of array |
1423 iStatus, iRetValue ); // Takes ownerhip of array |
1426 |
1424 |
1427 iNextStep = EOperationCompleted; |
1425 iNextStep = EOperationCompleted; |
1428 iStatus = KRequestPending; |
1426 iStatus = KRequestPending; |
1429 SetActive(); |
1427 SetActive(); |
1430 } |
1428 } |
1431 } |
1429 } |
1437 void CCTSecurityDialogsAO::ShowNoTrustDialogL() |
1435 void CCTSecurityDialogsAO::ShowNoTrustDialogL() |
1438 { |
1436 { |
1439 CX509Certificate* cert = CX509Certificate::NewLC( iCertBuf->Des() ); |
1437 CX509Certificate* cert = CX509Certificate::NewLC( iCertBuf->Des() ); |
1440 TInt resourceid = R_WIM_NO_TRUST_QUERY_UNTRUSTED; |
1438 TInt resourceid = R_WIM_NO_TRUST_QUERY_UNTRUSTED; |
1441 TBool showPermAccept = ETrue; |
1439 TBool showPermAccept = ETrue; |
1442 |
1440 |
1443 if( iAuthFailReason == ESignatureInvalid || iAuthFailReason == ECertificateRevoked ) |
1441 if( iAuthFailReason == ESignatureInvalid || iAuthFailReason == ECertificateRevoked ) |
1444 { |
1442 { |
1445 // Invalid or revoked certificate |
1443 // Invalid or revoked certificate |
1446 CCTInvalidCertificateNote* note = |
1444 CCTInvalidCertificateNote* note = |
1447 new( ELeave ) CCTInvalidCertificateNote( *this, iStatus ); |
1445 new( ELeave ) CCTInvalidCertificateNote( *this, iStatus ); |
1451 else |
1449 else |
1452 { |
1450 { |
1453 if( iAuthFailReason == EValidatedOK || iAuthFailReason == EDateOutOfRange ) |
1451 if( iAuthFailReason == EValidatedOK || iAuthFailReason == EDateOutOfRange ) |
1454 { |
1452 { |
1455 // Trusted certificate, but problems with CN or date |
1453 // Trusted certificate, but problems with CN or date |
1456 |
1454 |
1457 // Retrieve subject name |
1455 // Retrieve subject name |
1458 const CX500DistinguishedName& dName = cert->SubjectName(); |
1456 const CX500DistinguishedName& dName = cert->SubjectName(); |
1459 |
1457 |
1460 // Retrieve common name |
1458 // Retrieve common name |
1461 HBufC* cn = dName.ExtractFieldL( KX520CommonName ); |
1459 HBufC* cn = dName.ExtractFieldL( KX520CommonName ); |
1462 |
1460 |
1463 // Check common name first and then date |
1461 // Check common name first and then date |
1464 if( !cn ) |
1462 if( !cn ) |
1465 { |
1463 { |
1466 // Couldn't retrieve CN from certificate |
1464 // Couldn't retrieve CN from certificate |
1467 resourceid = R_WIM_NO_TRUST_QUERY_UNTRUSTED; |
1465 resourceid = R_WIM_NO_TRUST_QUERY_UNTRUSTED; |
1494 const CValidityPeriod& validityPeriod = cert->ValidityPeriod(); |
1492 const CValidityPeriod& validityPeriod = cert->ValidityPeriod(); |
1495 const TTime& startValue = validityPeriod.Start(); |
1493 const TTime& startValue = validityPeriod.Start(); |
1496 const TTime& finishValue = validityPeriod.Finish(); |
1494 const TTime& finishValue = validityPeriod.Finish(); |
1497 TTime current; |
1495 TTime current; |
1498 current.UniversalTime(); |
1496 current.UniversalTime(); |
1499 |
1497 |
1500 if( (( startValue > current ) || ( finishValue < current )) || |
1498 if( (( startValue > current ) || ( finishValue < current )) || |
1501 ( iServerName->Des().Length() == 0 ) ) |
1499 ( iServerName->Des().Length() == 0 ) ) |
1502 { |
1500 { |
1503 showPermAccept = EFalse; |
1501 showPermAccept = EFalse; |
1504 } |
1502 } |
2232 // --------------------------------------------------------- |
2230 // --------------------------------------------------------- |
2233 // CCTSecurityDialogsAO::DetailsDynamicL( |
2231 // CCTSecurityDialogsAO::DetailsDynamicL( |
2234 // HBufC& aMessage, TPtrC aValue, TInt aResourceOne) |
2232 // HBufC& aMessage, TPtrC aValue, TInt aResourceOne) |
2235 // Reads dynamic text, if the string is empty |
2233 // Reads dynamic text, if the string is empty |
2236 // put a not defined text from the resource in its place |
2234 // put a not defined text from the resource in its place |
2237 // KMaxLengthTextCertLabel = 510, used by CertLabel(), Issuer(), Owner() |
|
2238 // --------------------------------------------------------- |
2235 // --------------------------------------------------------- |
2239 // |
2236 // |
2240 void CCTSecurityDialogsAO::DetailsDynamicL( |
2237 void CCTSecurityDialogsAO::DetailsDynamicL( |
2241 TDes& aMessage, const TDesC& aValue, TInt aResource) |
2238 TDes& aMessage, const TDesC& aValue, TInt aResource) |
2242 { |
2239 { |
2243 HBufC* buf = HBufC::NewLC( KMaxLengthTextCertLabel ); |
2240 HBufC* buf = aValue.AllocLC(); |
2244 buf->Des() = aValue; |
2241 TPtr trimmedValue( buf->Des() ); |
2245 buf->Des().TrimLeft(); |
2242 trimmedValue.TrimLeft(); |
2246 // Cut CertLabel after fourth semi colon |
2243 |
2247 TPtrC trimmedCertLabel = CutCertificateField( buf->Des() ); |
2244 if( trimmedValue.Length() > KMaxLengthTextCertLabelVisible ) |
2248 buf->Des().Copy( trimmedCertLabel ); |
2245 { |
2249 TInt length = buf->Des().Length(); |
2246 trimmedValue.SetLength( KMaxLengthTextCertLabelVisible - 1 ); |
2250 if (length == 0 ) |
2247 trimmedValue.Append( KTextUtilClipEndChar ); |
|
2248 } |
|
2249 |
|
2250 if( trimmedValue.Length() == 0 ) |
2251 { |
2251 { |
2252 DetailsResourceL( aMessage, aResource ); |
2252 DetailsResourceL( aMessage, aResource ); |
2253 } |
2253 } |
2254 else |
2254 else |
2255 { |
2255 { |
2256 aMessage.Append( buf->Des() ); |
2256 aMessage.Append( trimmedValue ); |
2257 aMessage.Append( KEnter ); |
2257 aMessage.Append( KEnter ); |
2258 } |
2258 } |
2259 CleanupStack::PopAndDestroy(); // buf |
2259 |
2260 } |
2260 CleanupStack::PopAndDestroy( buf ); |
2261 |
|
2262 // --------------------------------------------------------- |
|
2263 // CCTSecurityDialogsAO::CutCertificateField(TPtrC aField) |
|
2264 // If CertLabel, Issuer and Owner length is over 80 characters, |
|
2265 // cut it down to 80 |
|
2266 // Returns the cut certificate field. |
|
2267 // --------------------------------------------------------- |
|
2268 // |
|
2269 TPtrC CCTSecurityDialogsAO::CutCertificateField( const TDesC& aField ) |
|
2270 { |
|
2271 TInt fieldLength = aField.Length(); |
|
2272 if ( fieldLength >= KMaxLengthTextCertLabelVisible ) |
|
2273 { |
|
2274 TPtrC cutCertLabel = aField.Mid( 0, KMaxLengthTextCertLabelVisible ); |
|
2275 return cutCertLabel; |
|
2276 } |
|
2277 return aField; |
|
2278 } |
2261 } |
2279 |
2262 |
2280 // ----------------------------------------------------------------------------- |
2263 // ----------------------------------------------------------------------------- |
2281 // CCTSecurityDialogsAO::HandleResponseAndCompleteL() |
2264 // CCTSecurityDialogsAO::HandleResponseAndCompleteL() |
2282 // ----------------------------------------------------------------------------- |
2265 // ----------------------------------------------------------------------------- |
2427 { |
2410 { |
2428 delete iQueryDialog; |
2411 delete iQueryDialog; |
2429 iQueryDialogDeleted = ETrue; |
2412 iQueryDialogDeleted = ETrue; |
2430 } |
2413 } |
2431 iQueryDialog = NULL; |
2414 iQueryDialog = NULL; |
2432 |
2415 |
2433 if ( !iPinQueryDialogDeleted ) |
2416 if ( !iPinQueryDialogDeleted ) |
2434 { |
2417 { |
2435 delete iPinQueryDialog; |
2418 delete iPinQueryDialog; |
2436 iPinQueryDialogDeleted = ETrue; |
2419 iPinQueryDialogDeleted = ETrue; |
2437 } |
2420 } |
2438 iPinQueryDialog = NULL; |
2421 iPinQueryDialog = NULL; |
2439 |
2422 |
2440 // Complete message if it has not been completed earlier. |
2423 // Complete message if it has not been completed earlier. |
2441 if( !iMessagePtr.IsNull() ) |
2424 if( !iMessagePtr.IsNull() ) |
2442 { |
2425 { |
2443 iMessagePtr.Complete( KErrCancel ); |
2426 iMessagePtr.Complete( KErrCancel ); |
2444 } |
2427 } |