Chromium Code Reviews| 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 // OpenSSL binding for SSLClientSocket. The class layout and general principle | 5 // OpenSSL binding for SSLClientSocket. The class layout and general principle |
| 6 // of operation is derived from SSLClientSocketNSS. | 6 // of operation is derived from SSLClientSocketNSS. |
| 7 | 7 |
| 8 #include "net/socket/ssl_client_socket_openssl.h" | 8 #include "net/socket/ssl_client_socket_openssl.h" |
| 9 | 9 |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 transport_read_error_ = OK; | 482 transport_read_error_ = OK; |
| 483 transport_write_error_ = OK; | 483 transport_write_error_ = OK; |
| 484 | 484 |
| 485 server_cert_verify_result_.Reset(); | 485 server_cert_verify_result_.Reset(); |
| 486 completed_connect_ = false; | 486 completed_connect_ = false; |
| 487 | 487 |
| 488 cert_authorities_.clear(); | 488 cert_authorities_.clear(); |
| 489 cert_key_types_.clear(); | 489 cert_key_types_.clear(); |
| 490 client_auth_cert_needed_ = false; | 490 client_auth_cert_needed_ = false; |
| 491 | 491 |
| 492 start_cert_verification_time_ = base::TimeTicks(); | |
| 493 | |
| 492 npn_status_ = kNextProtoUnsupported; | 494 npn_status_ = kNextProtoUnsupported; |
| 493 npn_proto_.clear(); | 495 npn_proto_.clear(); |
| 494 | 496 |
| 495 channel_id_xtn_negotiated_ = false; | 497 channel_id_xtn_negotiated_ = false; |
| 496 channel_id_request_handle_.Cancel(); | 498 channel_id_request_handle_.Cancel(); |
| 497 } | 499 } |
| 498 | 500 |
| 499 bool SSLClientSocketOpenSSL::IsConnected() const { | 501 bool SSLClientSocketOpenSSL::IsConnected() const { |
| 500 // If the handshake has not yet completed. | 502 // If the handshake has not yet completed. |
| 501 if (!completed_connect_) | 503 if (!completed_connect_) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 ssl_info->cert_status = server_cert_verify_result_.cert_status; | 575 ssl_info->cert_status = server_cert_verify_result_.cert_status; |
| 574 ssl_info->is_issued_by_known_root = | 576 ssl_info->is_issued_by_known_root = |
| 575 server_cert_verify_result_.is_issued_by_known_root; | 577 server_cert_verify_result_.is_issued_by_known_root; |
| 576 ssl_info->public_key_hashes = | 578 ssl_info->public_key_hashes = |
| 577 server_cert_verify_result_.public_key_hashes; | 579 server_cert_verify_result_.public_key_hashes; |
| 578 ssl_info->client_cert_sent = | 580 ssl_info->client_cert_sent = |
| 579 ssl_config_.send_client_cert && ssl_config_.client_cert.get(); | 581 ssl_config_.send_client_cert && ssl_config_.client_cert.get(); |
| 580 ssl_info->channel_id_sent = WasChannelIDSent(); | 582 ssl_info->channel_id_sent = WasChannelIDSent(); |
| 581 ssl_info->pinning_failure_log = pinning_failure_log_; | 583 ssl_info->pinning_failure_log = pinning_failure_log_; |
| 582 | 584 |
| 583 RecordChannelIDSupport(channel_id_service_, | |
| 584 channel_id_xtn_negotiated_, | |
| 585 ssl_config_.channel_id_enabled, | |
| 586 crypto::ECPrivateKey::IsSupported()); | |
| 587 | |
| 588 const SSL_CIPHER* cipher = SSL_get_current_cipher(ssl_); | 585 const SSL_CIPHER* cipher = SSL_get_current_cipher(ssl_); |
| 589 CHECK(cipher); | 586 CHECK(cipher); |
| 590 ssl_info->security_bits = SSL_CIPHER_get_bits(cipher, NULL); | 587 ssl_info->security_bits = SSL_CIPHER_get_bits(cipher, NULL); |
| 591 | 588 |
| 592 ssl_info->connection_status = EncodeSSLConnectionStatus( | 589 ssl_info->connection_status = EncodeSSLConnectionStatus( |
| 593 SSL_CIPHER_get_id(cipher), 0 /* no compression */, | 590 SSL_CIPHER_get_id(cipher), 0 /* no compression */, |
| 594 GetNetSSLVersion(ssl_)); | 591 GetNetSSLVersion(ssl_)); |
| 595 | 592 |
| 596 bool peer_supports_renego_ext = !!SSL_get_secure_renegotiation_support(ssl_); | 593 if (!SSL_get_secure_renegotiation_support(ssl_)) |
| 597 if (!peer_supports_renego_ext) | |
| 598 ssl_info->connection_status |= SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION; | 594 ssl_info->connection_status |= SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION; |
| 599 UMA_HISTOGRAM_ENUMERATION("Net.RenegotiationExtensionSupported", | |
| 600 implicit_cast<int>(peer_supports_renego_ext), 2); | |
| 601 | 595 |
| 602 if (ssl_config_.version_fallback) | 596 if (ssl_config_.version_fallback) |
| 603 ssl_info->connection_status |= SSL_CONNECTION_VERSION_FALLBACK; | 597 ssl_info->connection_status |= SSL_CONNECTION_VERSION_FALLBACK; |
| 604 | 598 |
| 605 ssl_info->handshake_type = SSL_session_reused(ssl_) ? | 599 ssl_info->handshake_type = SSL_session_reused(ssl_) ? |
| 606 SSLInfo::HANDSHAKE_RESUME : SSLInfo::HANDSHAKE_FULL; | 600 SSLInfo::HANDSHAKE_RESUME : SSLInfo::HANDSHAKE_FULL; |
| 607 | 601 |
| 608 DVLOG(3) << "Encoded connection status: cipher suite = " | 602 DVLOG(3) << "Encoded connection status: cipher suite = " |
| 609 << SSLConnectionStatusToCipherSuite(ssl_info->connection_status) | 603 << SSLConnectionStatusToCipherSuite(ssl_info->connection_status) |
| 610 << " version = " | 604 << " version = " |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 if (npn_status_ == kNextProtoUnsupported) { | 877 if (npn_status_ == kNextProtoUnsupported) { |
| 884 const uint8_t* alpn_proto = NULL; | 878 const uint8_t* alpn_proto = NULL; |
| 885 unsigned alpn_len = 0; | 879 unsigned alpn_len = 0; |
| 886 SSL_get0_alpn_selected(ssl_, &alpn_proto, &alpn_len); | 880 SSL_get0_alpn_selected(ssl_, &alpn_proto, &alpn_len); |
| 887 if (alpn_len > 0) { | 881 if (alpn_len > 0) { |
| 888 npn_proto_.assign(reinterpret_cast<const char*>(alpn_proto), alpn_len); | 882 npn_proto_.assign(reinterpret_cast<const char*>(alpn_proto), alpn_len); |
| 889 npn_status_ = kNextProtoNegotiated; | 883 npn_status_ = kNextProtoNegotiated; |
| 890 } | 884 } |
| 891 } | 885 } |
| 892 | 886 |
| 887 RecordChannelIDSupport(channel_id_service_, | |
| 888 channel_id_xtn_negotiated_, | |
| 889 ssl_config_.channel_id_enabled, | |
| 890 crypto::ECPrivateKey::IsSupported()); | |
| 891 | |
| 893 // Verify the certificate. | 892 // Verify the certificate. |
| 894 const bool got_cert = !!UpdateServerCert(); | 893 const bool got_cert = !!UpdateServerCert(); |
| 895 DCHECK(got_cert); | 894 DCHECK(got_cert); |
| 896 net_log_.AddEvent( | 895 net_log_.AddEvent( |
| 897 NetLog::TYPE_SSL_CERTIFICATES_RECEIVED, | 896 NetLog::TYPE_SSL_CERTIFICATES_RECEIVED, |
| 898 base::Bind(&NetLogX509CertificateCallback, | 897 base::Bind(&NetLogX509CertificateCallback, |
| 899 base::Unretained(server_cert_.get()))); | 898 base::Unretained(server_cert_.get()))); |
| 900 GotoState(STATE_VERIFY_CERT); | 899 GotoState(STATE_VERIFY_CERT); |
| 901 } else { | 900 } else { |
| 902 int ssl_error = SSL_get_error(ssl_, rv); | 901 int ssl_error = SSL_get_error(ssl_, rv); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 972 } | 971 } |
| 973 | 972 |
| 974 // Return to the handshake. | 973 // Return to the handshake. |
| 975 set_channel_id_sent(true); | 974 set_channel_id_sent(true); |
| 976 GotoState(STATE_HANDSHAKE); | 975 GotoState(STATE_HANDSHAKE); |
| 977 return OK; | 976 return OK; |
| 978 } | 977 } |
| 979 | 978 |
| 980 int SSLClientSocketOpenSSL::DoVerifyCert(int result) { | 979 int SSLClientSocketOpenSSL::DoVerifyCert(int result) { |
| 981 DCHECK(server_cert_.get()); | 980 DCHECK(server_cert_.get()); |
| 981 DCHECK(start_cert_verification_time_.is_null()); | |
| 982 GotoState(STATE_VERIFY_CERT_COMPLETE); | 982 GotoState(STATE_VERIFY_CERT_COMPLETE); |
| 983 | 983 |
| 984 CertStatus cert_status; | 984 CertStatus cert_status; |
| 985 if (ssl_config_.IsAllowedBadCert(server_cert_.get(), &cert_status)) { | 985 if (ssl_config_.IsAllowedBadCert(server_cert_.get(), &cert_status)) { |
| 986 VLOG(1) << "Received an expected bad cert with status: " << cert_status; | 986 VLOG(1) << "Received an expected bad cert with status: " << cert_status; |
| 987 server_cert_verify_result_.Reset(); | 987 server_cert_verify_result_.Reset(); |
| 988 server_cert_verify_result_.cert_status = cert_status; | 988 server_cert_verify_result_.cert_status = cert_status; |
| 989 server_cert_verify_result_.verified_cert = server_cert_; | 989 server_cert_verify_result_.verified_cert = server_cert_; |
| 990 return OK; | 990 return OK; |
| 991 } | 991 } |
| 992 | 992 |
| 993 start_cert_verification_time_ = base::TimeTicks::Now(); | |
| 994 | |
| 993 int flags = 0; | 995 int flags = 0; |
| 994 if (ssl_config_.rev_checking_enabled) | 996 if (ssl_config_.rev_checking_enabled) |
| 995 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED; | 997 flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED; |
| 996 if (ssl_config_.verify_ev_cert) | 998 if (ssl_config_.verify_ev_cert) |
| 997 flags |= CertVerifier::VERIFY_EV_CERT; | 999 flags |= CertVerifier::VERIFY_EV_CERT; |
| 998 if (ssl_config_.cert_io_enabled) | 1000 if (ssl_config_.cert_io_enabled) |
| 999 flags |= CertVerifier::VERIFY_CERT_IO_ENABLED; | 1001 flags |= CertVerifier::VERIFY_CERT_IO_ENABLED; |
| 1000 if (ssl_config_.rev_checking_required_local_anchors) | 1002 if (ssl_config_.rev_checking_required_local_anchors) |
| 1001 flags |= CertVerifier::VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS; | 1003 flags |= CertVerifier::VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS; |
| 1002 verifier_.reset(new SingleRequestCertVerifier(cert_verifier_)); | 1004 verifier_.reset(new SingleRequestCertVerifier(cert_verifier_)); |
| 1003 return verifier_->Verify( | 1005 return verifier_->Verify( |
| 1004 server_cert_.get(), | 1006 server_cert_.get(), |
| 1005 host_and_port_.host(), | 1007 host_and_port_.host(), |
| 1006 flags, | 1008 flags, |
| 1007 NULL /* no CRL set */, | 1009 NULL /* no CRL set */, |
| 1008 &server_cert_verify_result_, | 1010 &server_cert_verify_result_, |
| 1009 base::Bind(&SSLClientSocketOpenSSL::OnHandshakeIOComplete, | 1011 base::Bind(&SSLClientSocketOpenSSL::OnHandshakeIOComplete, |
| 1010 base::Unretained(this)), | 1012 base::Unretained(this)), |
| 1011 net_log_); | 1013 net_log_); |
| 1012 } | 1014 } |
| 1013 | 1015 |
| 1014 int SSLClientSocketOpenSSL::DoVerifyCertComplete(int result) { | 1016 int SSLClientSocketOpenSSL::DoVerifyCertComplete(int result) { |
| 1015 verifier_.reset(); | 1017 verifier_.reset(); |
| 1016 | 1018 |
| 1019 if (!start_cert_verification_time_.is_null()) { | |
| 1020 base::TimeDelta verify_time = | |
| 1021 base::TimeTicks::Now() - start_cert_verification_time_; | |
| 1022 if (result == OK) | |
| 1023 UMA_HISTOGRAM_TIMES("Net.SSLCertVerificationTime", verify_time); | |
|
Alexei Svitkine (slow)
2014/08/22 18:49:14
Nit: Bad indentation.
davidben
2014/08/22 23:03:20
Done.
| |
| 1024 else | |
| 1025 UMA_HISTOGRAM_TIMES("Net.SSLCertVerificationTimeError", verify_time); | |
| 1026 } | |
| 1027 | |
| 1017 bool sni_available = ssl_config_.version_max >= SSL_PROTOCOL_VERSION_TLS1 || | 1028 bool sni_available = ssl_config_.version_max >= SSL_PROTOCOL_VERSION_TLS1 || |
| 1018 ssl_config_.version_fallback; | 1029 ssl_config_.version_fallback; |
| 1019 const CertStatus cert_status = server_cert_verify_result_.cert_status; | 1030 const CertStatus cert_status = server_cert_verify_result_.cert_status; |
| 1020 if (transport_security_state_ && | 1031 if (transport_security_state_ && |
| 1021 (result == OK || | 1032 (result == OK || |
| 1022 (IsCertificateError(result) && IsCertStatusMinorError(cert_status))) && | 1033 (IsCertificateError(result) && IsCertStatusMinorError(cert_status))) && |
| 1023 !transport_security_state_->CheckPublicKeyPins( | 1034 !transport_security_state_->CheckPublicKeyPins( |
| 1024 host_and_port_.host(), | 1035 host_and_port_.host(), |
| 1025 sni_available, | 1036 sni_available, |
| 1026 server_cert_verify_result_.is_issued_by_known_root, | 1037 server_cert_verify_result_.is_issued_by_known_root, |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1619 if (handshake_succeeded_ && marked_session_as_good_) | 1630 if (handshake_succeeded_ && marked_session_as_good_) |
| 1620 OnHandshakeCompletion(); | 1631 OnHandshakeCompletion(); |
| 1621 } | 1632 } |
| 1622 | 1633 |
| 1623 scoped_refptr<X509Certificate> | 1634 scoped_refptr<X509Certificate> |
| 1624 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { | 1635 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { |
| 1625 return server_cert_; | 1636 return server_cert_; |
| 1626 } | 1637 } |
| 1627 | 1638 |
| 1628 } // namespace net | 1639 } // namespace net |
| OLD | NEW |