OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived | 5 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived |
6 // from AuthCertificateCallback() in | 6 // from AuthCertificateCallback() in |
7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. | 7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. |
8 | 8 |
9 /* ***** BEGIN LICENSE BLOCK ***** | 9 /* ***** BEGIN LICENSE BLOCK ***** |
10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 #include "crypto/nss_util.h" | 84 #include "crypto/nss_util.h" |
85 #include "crypto/nss_util_internal.h" | 85 #include "crypto/nss_util_internal.h" |
86 #include "crypto/rsa_private_key.h" | 86 #include "crypto/rsa_private_key.h" |
87 #include "crypto/scoped_nss_types.h" | 87 #include "crypto/scoped_nss_types.h" |
88 #include "net/base/address_list.h" | 88 #include "net/base/address_list.h" |
89 #include "net/base/dns_util.h" | 89 #include "net/base/dns_util.h" |
90 #include "net/base/io_buffer.h" | 90 #include "net/base/io_buffer.h" |
91 #include "net/base/net_errors.h" | 91 #include "net/base/net_errors.h" |
92 #include "net/base/net_log.h" | 92 #include "net/base/net_log.h" |
93 #include "net/cert/asn1_util.h" | 93 #include "net/cert/asn1_util.h" |
| 94 #include "net/cert/cert_policy_enforcer.h" |
94 #include "net/cert/cert_status_flags.h" | 95 #include "net/cert/cert_status_flags.h" |
95 #include "net/cert/cert_verifier.h" | 96 #include "net/cert/cert_verifier.h" |
96 #include "net/cert/ct_ev_whitelist.h" | 97 #include "net/cert/ct_ev_whitelist.h" |
97 #include "net/cert/ct_verifier.h" | 98 #include "net/cert/ct_verifier.h" |
98 #include "net/cert/ct_verify_result.h" | 99 #include "net/cert/ct_verify_result.h" |
99 #include "net/cert/scoped_nss_types.h" | 100 #include "net/cert/scoped_nss_types.h" |
100 #include "net/cert/sct_status_flags.h" | 101 #include "net/cert/sct_status_flags.h" |
101 #include "net/cert/single_request_cert_verifier.h" | 102 #include "net/cert/single_request_cert_verifier.h" |
102 #include "net/cert/x509_certificate_net_log_param.h" | 103 #include "net/cert/x509_certificate_net_log_param.h" |
103 #include "net/cert/x509_util.h" | 104 #include "net/cert/x509_util.h" |
(...skipping 2362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2466 // Note: This function may be called multiple times for a single connection | 2467 // Note: This function may be called multiple times for a single connection |
2467 // if renegotiations occur. | 2468 // if renegotiations occur. |
2468 nss_handshake_state_.ssl_connection_status = 0; | 2469 nss_handshake_state_.ssl_connection_status = 0; |
2469 | 2470 |
2470 SSLChannelInfo channel_info; | 2471 SSLChannelInfo channel_info; |
2471 SECStatus ok = SSL_GetChannelInfo(nss_fd_, | 2472 SECStatus ok = SSL_GetChannelInfo(nss_fd_, |
2472 &channel_info, sizeof(channel_info)); | 2473 &channel_info, sizeof(channel_info)); |
2473 if (ok == SECSuccess && | 2474 if (ok == SECSuccess && |
2474 channel_info.length == sizeof(channel_info) && | 2475 channel_info.length == sizeof(channel_info) && |
2475 channel_info.cipherSuite) { | 2476 channel_info.cipherSuite) { |
2476 nss_handshake_state_.ssl_connection_status |= | 2477 nss_handshake_state_.ssl_connection_status |= channel_info.cipherSuite; |
2477 (static_cast<int>(channel_info.cipherSuite) & | |
2478 SSL_CONNECTION_CIPHERSUITE_MASK) << | |
2479 SSL_CONNECTION_CIPHERSUITE_SHIFT; | |
2480 | 2478 |
2481 nss_handshake_state_.ssl_connection_status |= | 2479 nss_handshake_state_.ssl_connection_status |= |
2482 (static_cast<int>(channel_info.compressionMethod) & | 2480 (static_cast<int>(channel_info.compressionMethod) & |
2483 SSL_CONNECTION_COMPRESSION_MASK) << | 2481 SSL_CONNECTION_COMPRESSION_MASK) << |
2484 SSL_CONNECTION_COMPRESSION_SHIFT; | 2482 SSL_CONNECTION_COMPRESSION_SHIFT; |
2485 | 2483 |
2486 int version = SSL_CONNECTION_VERSION_UNKNOWN; | 2484 int version = SSL_CONNECTION_VERSION_UNKNOWN; |
2487 if (channel_info.protocolVersion < SSL_LIBRARY_VERSION_3_0) { | 2485 if (channel_info.protocolVersion < SSL_LIBRARY_VERSION_3_0) { |
2488 // All versions less than SSL_LIBRARY_VERSION_3_0 are treated as SSL | 2486 // All versions less than SSL_LIBRARY_VERSION_3_0 are treated as SSL |
2489 // version 2. | 2487 // version 2. |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2827 ssl_config_(ssl_config), | 2825 ssl_config_(ssl_config), |
2828 cert_verifier_(context.cert_verifier), | 2826 cert_verifier_(context.cert_verifier), |
2829 cert_transparency_verifier_(context.cert_transparency_verifier), | 2827 cert_transparency_verifier_(context.cert_transparency_verifier), |
2830 channel_id_service_(context.channel_id_service), | 2828 channel_id_service_(context.channel_id_service), |
2831 ssl_session_cache_shard_(context.ssl_session_cache_shard), | 2829 ssl_session_cache_shard_(context.ssl_session_cache_shard), |
2832 completed_handshake_(false), | 2830 completed_handshake_(false), |
2833 next_handshake_state_(STATE_NONE), | 2831 next_handshake_state_(STATE_NONE), |
2834 nss_fd_(NULL), | 2832 nss_fd_(NULL), |
2835 net_log_(transport_->socket()->NetLog()), | 2833 net_log_(transport_->socket()->NetLog()), |
2836 transport_security_state_(context.transport_security_state), | 2834 transport_security_state_(context.transport_security_state), |
| 2835 policy_enforcer_(context.cert_policy_enforcer), |
2837 valid_thread_id_(base::kInvalidThreadId) { | 2836 valid_thread_id_(base::kInvalidThreadId) { |
2838 EnterFunction(""); | 2837 EnterFunction(""); |
2839 InitCore(); | 2838 InitCore(); |
2840 LeaveFunction(""); | 2839 LeaveFunction(""); |
2841 } | 2840 } |
2842 | 2841 |
2843 SSLClientSocketNSS::~SSLClientSocketNSS() { | 2842 SSLClientSocketNSS::~SSLClientSocketNSS() { |
2844 EnterFunction(""); | 2843 EnterFunction(""); |
2845 Disconnect(); | 2844 Disconnect(); |
2846 LeaveFunction(""); | 2845 LeaveFunction(""); |
2847 } | 2846 } |
2848 | 2847 |
2849 // static | 2848 // static |
2850 void SSLClientSocket::ClearSessionCache() { | 2849 void SSLClientSocket::ClearSessionCache() { |
2851 // SSL_ClearSessionCache can't be called before NSS is initialized. Don't | 2850 // SSL_ClearSessionCache can't be called before NSS is initialized. Don't |
2852 // bother initializing NSS just to clear an empty SSL session cache. | 2851 // bother initializing NSS just to clear an empty SSL session cache. |
2853 if (!NSS_IsInitialized()) | 2852 if (!NSS_IsInitialized()) |
2854 return; | 2853 return; |
2855 | 2854 |
2856 SSL_ClearSessionCache(); | 2855 SSL_ClearSessionCache(); |
2857 } | 2856 } |
2858 | 2857 |
| 2858 #if !defined(CKM_NSS_TLS_MASTER_KEY_DERIVE_DH_SHA256) |
| 2859 #define CKM_NSS_TLS_MASTER_KEY_DERIVE_DH_SHA256 (CKM_NSS + 24) |
| 2860 #endif |
| 2861 |
| 2862 // static |
| 2863 uint16 SSLClientSocket::GetMaxSupportedSSLVersion() { |
| 2864 if (PK11_TokenExists(CKM_NSS_TLS_MASTER_KEY_DERIVE_DH_SHA256)) { |
| 2865 return SSL_PROTOCOL_VERSION_TLS1_2; |
| 2866 } else { |
| 2867 return SSL_PROTOCOL_VERSION_TLS1_1; |
| 2868 } |
| 2869 } |
| 2870 |
2859 bool SSLClientSocketNSS::GetSSLInfo(SSLInfo* ssl_info) { | 2871 bool SSLClientSocketNSS::GetSSLInfo(SSLInfo* ssl_info) { |
2860 EnterFunction(""); | 2872 EnterFunction(""); |
2861 ssl_info->Reset(); | 2873 ssl_info->Reset(); |
2862 if (core_->state().server_cert_chain.empty() || | 2874 if (core_->state().server_cert_chain.empty() || |
2863 !core_->state().server_cert_chain[0]) { | 2875 !core_->state().server_cert_chain[0]) { |
2864 return false; | 2876 return false; |
2865 } | 2877 } |
2866 | 2878 |
2867 ssl_info->cert_status = server_cert_verify_result_.cert_status; | 2879 ssl_info->cert_status = server_cert_verify_result_.cert_status; |
2868 ssl_info->cert = server_cert_verify_result_.verified_cert; | 2880 ssl_info->cert = server_cert_verify_result_.verified_cert; |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3511 (result == OK || | 3523 (result == OK || |
3512 (IsCertificateError(result) && IsCertStatusMinorError(cert_status))) && | 3524 (IsCertificateError(result) && IsCertStatusMinorError(cert_status))) && |
3513 !transport_security_state_->CheckPublicKeyPins( | 3525 !transport_security_state_->CheckPublicKeyPins( |
3514 host_and_port_.host(), | 3526 host_and_port_.host(), |
3515 server_cert_verify_result_.is_issued_by_known_root, | 3527 server_cert_verify_result_.is_issued_by_known_root, |
3516 server_cert_verify_result_.public_key_hashes, | 3528 server_cert_verify_result_.public_key_hashes, |
3517 &pinning_failure_log_)) { | 3529 &pinning_failure_log_)) { |
3518 result = ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN; | 3530 result = ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN; |
3519 } | 3531 } |
3520 | 3532 |
3521 scoped_refptr<ct::EVCertsWhitelist> ev_whitelist = | |
3522 SSLConfigService::GetEVCertsWhitelist(); | |
3523 if (server_cert_verify_result_.cert_status & CERT_STATUS_IS_EV) { | |
3524 if (ev_whitelist.get() && ev_whitelist->IsValid()) { | |
3525 const SHA256HashValue fingerprint( | |
3526 X509Certificate::CalculateFingerprint256( | |
3527 server_cert_verify_result_.verified_cert->os_cert_handle())); | |
3528 | |
3529 UMA_HISTOGRAM_BOOLEAN( | |
3530 "Net.SSL_EVCertificateInWhitelist", | |
3531 ev_whitelist->ContainsCertificateHash( | |
3532 std::string(reinterpret_cast<const char*>(fingerprint.data), 8))); | |
3533 } | |
3534 } | |
3535 | |
3536 if (result == OK) { | 3533 if (result == OK) { |
3537 // Only check Certificate Transparency if there were no other errors with | 3534 // Only check Certificate Transparency if there were no other errors with |
3538 // the connection. | 3535 // the connection. |
3539 VerifyCT(); | 3536 VerifyCT(); |
3540 | 3537 |
3541 // Only cache the session if the certificate verified successfully. | 3538 // Only cache the session if the certificate verified successfully. |
3542 core_->CacheSessionIfNecessary(); | 3539 core_->CacheSessionIfNecessary(); |
3543 } | 3540 } |
3544 | 3541 |
3545 completed_handshake_ = true; | 3542 completed_handshake_ = true; |
3546 | 3543 |
3547 // Exit DoHandshakeLoop and return the result to the caller to Connect. | 3544 // Exit DoHandshakeLoop and return the result to the caller to Connect. |
3548 DCHECK_EQ(STATE_NONE, next_handshake_state_); | 3545 DCHECK_EQ(STATE_NONE, next_handshake_state_); |
3549 return result; | 3546 return result; |
3550 } | 3547 } |
3551 | 3548 |
3552 void SSLClientSocketNSS::VerifyCT() { | 3549 void SSLClientSocketNSS::VerifyCT() { |
3553 if (!cert_transparency_verifier_) | 3550 if (!cert_transparency_verifier_) |
3554 return; | 3551 return; |
3555 | 3552 |
3556 // Note that this is a completely synchronous operation: The CT Log Verifier | 3553 // Note that this is a completely synchronous operation: The CT Log Verifier |
3557 // gets all the data it needs for SCT verification and does not do any | 3554 // gets all the data it needs for SCT verification and does not do any |
3558 // external communication. | 3555 // external communication. |
3559 int result = cert_transparency_verifier_->Verify( | 3556 cert_transparency_verifier_->Verify( |
3560 server_cert_verify_result_.verified_cert.get(), | 3557 server_cert_verify_result_.verified_cert.get(), |
3561 core_->state().stapled_ocsp_response, | 3558 core_->state().stapled_ocsp_response, |
3562 core_->state().sct_list_from_tls_extension, | 3559 core_->state().sct_list_from_tls_extension, &ct_verify_result_, net_log_); |
3563 &ct_verify_result_, | |
3564 net_log_); | |
3565 // TODO(ekasper): wipe stapled_ocsp_response and sct_list_from_tls_extension | 3560 // TODO(ekasper): wipe stapled_ocsp_response and sct_list_from_tls_extension |
3566 // from the state after verification is complete, to conserve memory. | 3561 // from the state after verification is complete, to conserve memory. |
3567 | 3562 |
3568 VLOG(1) << "CT Verification complete: result " << result | 3563 if (!policy_enforcer_) { |
3569 << " Invalid scts: " << ct_verify_result_.invalid_scts.size() | 3564 server_cert_verify_result_.cert_status &= ~CERT_STATUS_IS_EV; |
3570 << " Verified scts: " << ct_verify_result_.verified_scts.size() | 3565 } else { |
3571 << " scts from unknown logs: " | 3566 if (server_cert_verify_result_.cert_status & CERT_STATUS_IS_EV) { |
3572 << ct_verify_result_.unknown_logs_scts.size(); | 3567 scoped_refptr<ct::EVCertsWhitelist> ev_whitelist = |
| 3568 SSLConfigService::GetEVCertsWhitelist(); |
| 3569 if (!policy_enforcer_->DoesConformToCTEVPolicy( |
| 3570 server_cert_verify_result_.verified_cert.get(), |
| 3571 ev_whitelist.get(), ct_verify_result_)) { |
| 3572 // TODO(eranm): Log via the BoundNetLog, see crbug.com/437766 |
| 3573 VLOG(1) << "EV certificate for " |
| 3574 << server_cert_verify_result_.verified_cert->subject() |
| 3575 .GetDisplayName() |
| 3576 << " does not conform to CT policy, removing EV status."; |
| 3577 server_cert_verify_result_.cert_status &= ~CERT_STATUS_IS_EV; |
| 3578 } |
| 3579 } |
| 3580 } |
3573 } | 3581 } |
3574 | 3582 |
3575 void SSLClientSocketNSS::EnsureThreadIdAssigned() const { | 3583 void SSLClientSocketNSS::EnsureThreadIdAssigned() const { |
3576 base::AutoLock auto_lock(lock_); | 3584 base::AutoLock auto_lock(lock_); |
3577 if (valid_thread_id_ != base::kInvalidThreadId) | 3585 if (valid_thread_id_ != base::kInvalidThreadId) |
3578 return; | 3586 return; |
3579 valid_thread_id_ = base::PlatformThread::CurrentId(); | 3587 valid_thread_id_ = base::PlatformThread::CurrentId(); |
3580 } | 3588 } |
3581 | 3589 |
3582 bool SSLClientSocketNSS::CalledOnValidThread() const { | 3590 bool SSLClientSocketNSS::CalledOnValidThread() const { |
(...skipping 27 matching lines...) Expand all Loading... |
3610 scoped_refptr<X509Certificate> | 3618 scoped_refptr<X509Certificate> |
3611 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { | 3619 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { |
3612 return core_->state().server_cert.get(); | 3620 return core_->state().server_cert.get(); |
3613 } | 3621 } |
3614 | 3622 |
3615 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { | 3623 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { |
3616 return channel_id_service_; | 3624 return channel_id_service_; |
3617 } | 3625 } |
3618 | 3626 |
3619 } // namespace net | 3627 } // namespace net |
OLD | NEW |