Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: net/socket/ssl_client_socket_nss.cc

Issue 706203003: Update from https://crrev.com/303153 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/socket/ssl_client_socket_nss.h ('k') | net/socket/ssl_client_socket_openssl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 #include "base/strings/stringprintf.h" 79 #include "base/strings/stringprintf.h"
80 #include "base/thread_task_runner_handle.h" 80 #include "base/thread_task_runner_handle.h"
81 #include "base/threading/thread_restrictions.h" 81 #include "base/threading/thread_restrictions.h"
82 #include "base/values.h" 82 #include "base/values.h"
83 #include "crypto/ec_private_key.h" 83 #include "crypto/ec_private_key.h"
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/connection_type_histograms.h"
90 #include "net/base/dns_util.h" 89 #include "net/base/dns_util.h"
91 #include "net/base/io_buffer.h" 90 #include "net/base/io_buffer.h"
92 #include "net/base/net_errors.h" 91 #include "net/base/net_errors.h"
93 #include "net/base/net_log.h" 92 #include "net/base/net_log.h"
94 #include "net/cert/asn1_util.h" 93 #include "net/cert/asn1_util.h"
95 #include "net/cert/cert_status_flags.h" 94 #include "net/cert/cert_status_flags.h"
96 #include "net/cert/cert_verifier.h" 95 #include "net/cert/cert_verifier.h"
97 #include "net/cert/ct_ev_whitelist.h" 96 #include "net/cert/ct_ev_whitelist.h"
98 #include "net/cert/ct_verifier.h" 97 #include "net/cert/ct_verifier.h"
99 #include "net/cert/ct_verify_result.h" 98 #include "net/cert/ct_verify_result.h"
(...skipping 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 SSL_CacheSessionUnlocked(socket); 1623 SSL_CacheSessionUnlocked(socket);
1625 1624
1626 // Additionally, when False Starting, DoHandshake() will have already 1625 // Additionally, when False Starting, DoHandshake() will have already
1627 // called HandshakeSucceeded(), so return now. 1626 // called HandshakeSucceeded(), so return now.
1628 return; 1627 return;
1629 } 1628 }
1630 core->HandshakeSucceeded(); 1629 core->HandshakeSucceeded();
1631 } 1630 }
1632 1631
1633 void SSLClientSocketNSS::Core::HandshakeSucceeded() { 1632 void SSLClientSocketNSS::Core::HandshakeSucceeded() {
1633 // TODO(vadimt): Remove ScopedProfile below once crbug.com/424386 is fixed.
1634 tracked_objects::ScopedProfile tracking_profile(
1635 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1636 "424386 SSLClientSocketNSS::Core::HandshakeSucceeded"));
1637
1634 DCHECK(OnNSSTaskRunner()); 1638 DCHECK(OnNSSTaskRunner());
1635 1639
1636 PRBool last_handshake_resumed; 1640 PRBool last_handshake_resumed;
1637 SECStatus rv = SSL_HandshakeResumedSession(nss_fd_, &last_handshake_resumed); 1641 SECStatus rv = SSL_HandshakeResumedSession(nss_fd_, &last_handshake_resumed);
1638 if (rv == SECSuccess && last_handshake_resumed) { 1642 if (rv == SECSuccess && last_handshake_resumed) {
1639 nss_handshake_state_.resumed_handshake = true; 1643 nss_handshake_state_.resumed_handshake = true;
1640 } else { 1644 } else {
1641 nss_handshake_state_.resumed_handshake = false; 1645 nss_handshake_state_.resumed_handshake = false;
1642 } 1646 }
1643 1647
1644 RecordChannelIDSupportOnNSSTaskRunner(); 1648 RecordChannelIDSupportOnNSSTaskRunner();
1645 UpdateServerCert(); 1649 UpdateServerCert();
1646 UpdateSignedCertTimestamps(); 1650 UpdateSignedCertTimestamps();
1647 UpdateStapledOCSPResponse(); 1651 UpdateStapledOCSPResponse();
1648 UpdateConnectionStatus(); 1652 UpdateConnectionStatus();
1649 UpdateNextProto(); 1653 UpdateNextProto();
1650 UpdateExtensionUsed(); 1654 UpdateExtensionUsed();
1651 1655
1652 // Update the network task runners view of the handshake state whenever 1656 // Update the network task runners view of the handshake state whenever
1653 // a handshake has completed. 1657 // a handshake has completed.
1654 PostOrRunCallback( 1658 PostOrRunCallback(
1655 FROM_HERE, base::Bind(&Core::OnHandshakeStateUpdated, this, 1659 FROM_HERE, base::Bind(&Core::OnHandshakeStateUpdated, this,
1656 nss_handshake_state_)); 1660 nss_handshake_state_));
1657 } 1661 }
1658 1662
1659 int SSLClientSocketNSS::Core::HandleNSSError(PRErrorCode nss_error) { 1663 int SSLClientSocketNSS::Core::HandleNSSError(PRErrorCode nss_error) {
1664 // TODO(vadimt): Remove ScopedProfile below once crbug.com/424386 is fixed.
1665 tracked_objects::ScopedProfile tracking_profile(
1666 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1667 "424386 SSLClientSocketNSS::Core::HandleNSSError"));
1668
1660 DCHECK(OnNSSTaskRunner()); 1669 DCHECK(OnNSSTaskRunner());
1661 1670
1662 int net_error = MapNSSClientError(nss_error); 1671 int net_error = MapNSSClientError(nss_error);
1663 1672
1664 #if defined(OS_WIN) 1673 #if defined(OS_WIN)
1665 // On Windows, a handle to the HCRYPTPROV is cached in the X509Certificate 1674 // On Windows, a handle to the HCRYPTPROV is cached in the X509Certificate
1666 // os_cert_handle() as an optimization. However, if the certificate 1675 // os_cert_handle() as an optimization. However, if the certificate
1667 // private key is stored on a smart card, and the smart card is removed, 1676 // private key is stored on a smart card, and the smart card is removed,
1668 // the cached HCRYPTPROV will not be able to obtain the HCRYPTKEY again, 1677 // the cached HCRYPTPROV will not be able to obtain the HCRYPTKEY again,
1669 // preventing client certificate authentication. Because the 1678 // preventing client certificate authentication. Because the
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1797 // TODO(vadimt): Remove ScopedTracker below once crbug.com/424386 is fixed. 1806 // TODO(vadimt): Remove ScopedTracker below once crbug.com/424386 is fixed.
1798 tracked_objects::ScopedTracker tracking_profile( 1807 tracked_objects::ScopedTracker tracking_profile(
1799 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1808 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1800 "424386 SSLClientSocketNSS::Core::DoHandshake")); 1809 "424386 SSLClientSocketNSS::Core::DoHandshake"));
1801 1810
1802 DCHECK(OnNSSTaskRunner()); 1811 DCHECK(OnNSSTaskRunner());
1803 1812
1804 int net_error = OK; 1813 int net_error = OK;
1805 SECStatus rv = SSL_ForceHandshake(nss_fd_); 1814 SECStatus rv = SSL_ForceHandshake(nss_fd_);
1806 1815
1816 // TODO(vadimt): Remove ScopedProfile below once crbug.com/424386 is fixed.
1817 tracked_objects::ScopedProfile tracking_profile1(
1818 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1819 "424386 SSLClientSocketNSS::Core::DoHandshake 1"));
1820
1807 // Note: this function may be called multiple times during the handshake, so 1821 // Note: this function may be called multiple times during the handshake, so
1808 // even though channel id and client auth are separate else cases, they can 1822 // even though channel id and client auth are separate else cases, they can
1809 // both be used during a single SSL handshake. 1823 // both be used during a single SSL handshake.
1810 if (channel_id_needed_) { 1824 if (channel_id_needed_) {
1811 GotoState(STATE_GET_DOMAIN_BOUND_CERT_COMPLETE); 1825 GotoState(STATE_GET_DOMAIN_BOUND_CERT_COMPLETE);
1812 net_error = ERR_IO_PENDING; 1826 net_error = ERR_IO_PENDING;
1813 } else if (client_auth_cert_needed_) { 1827 } else if (client_auth_cert_needed_) {
1814 net_error = ERR_SSL_CLIENT_AUTH_CERT_NEEDED; 1828 net_error = ERR_SSL_CLIENT_AUTH_CERT_NEEDED;
1815 PostOrRunCallback( 1829 PostOrRunCallback(
1816 FROM_HERE, 1830 FROM_HERE,
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
2466 nss_handshake_state_.ssl_connection_status |= 2480 nss_handshake_state_.ssl_connection_status |=
2467 (static_cast<int>(channel_info.cipherSuite) & 2481 (static_cast<int>(channel_info.cipherSuite) &
2468 SSL_CONNECTION_CIPHERSUITE_MASK) << 2482 SSL_CONNECTION_CIPHERSUITE_MASK) <<
2469 SSL_CONNECTION_CIPHERSUITE_SHIFT; 2483 SSL_CONNECTION_CIPHERSUITE_SHIFT;
2470 2484
2471 nss_handshake_state_.ssl_connection_status |= 2485 nss_handshake_state_.ssl_connection_status |=
2472 (static_cast<int>(channel_info.compressionMethod) & 2486 (static_cast<int>(channel_info.compressionMethod) &
2473 SSL_CONNECTION_COMPRESSION_MASK) << 2487 SSL_CONNECTION_COMPRESSION_MASK) <<
2474 SSL_CONNECTION_COMPRESSION_SHIFT; 2488 SSL_CONNECTION_COMPRESSION_SHIFT;
2475 2489
2476 // NSS 3.14.x doesn't have a version macro for TLS 1.2 (because NSS didn't
2477 // support it yet), so use 0x0303 directly.
2478 int version = SSL_CONNECTION_VERSION_UNKNOWN; 2490 int version = SSL_CONNECTION_VERSION_UNKNOWN;
2479 if (channel_info.protocolVersion < SSL_LIBRARY_VERSION_3_0) { 2491 if (channel_info.protocolVersion < SSL_LIBRARY_VERSION_3_0) {
2480 // All versions less than SSL_LIBRARY_VERSION_3_0 are treated as SSL 2492 // All versions less than SSL_LIBRARY_VERSION_3_0 are treated as SSL
2481 // version 2. 2493 // version 2.
2482 version = SSL_CONNECTION_VERSION_SSL2; 2494 version = SSL_CONNECTION_VERSION_SSL2;
2483 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_0) { 2495 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_0) {
2484 version = SSL_CONNECTION_VERSION_SSL3; 2496 version = SSL_CONNECTION_VERSION_SSL3;
2485 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_3_1_TLS) { 2497 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_TLS_1_0) {
2486 version = SSL_CONNECTION_VERSION_TLS1; 2498 version = SSL_CONNECTION_VERSION_TLS1;
2487 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_TLS_1_1) { 2499 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_TLS_1_1) {
2488 version = SSL_CONNECTION_VERSION_TLS1_1; 2500 version = SSL_CONNECTION_VERSION_TLS1_1;
2489 } else if (channel_info.protocolVersion == 0x0303) { 2501 } else if (channel_info.protocolVersion == SSL_LIBRARY_VERSION_TLS_1_2) {
2490 version = SSL_CONNECTION_VERSION_TLS1_2; 2502 version = SSL_CONNECTION_VERSION_TLS1_2;
2491 } 2503 }
2492 nss_handshake_state_.ssl_connection_status |= 2504 nss_handshake_state_.ssl_connection_status |=
2493 (version & SSL_CONNECTION_VERSION_MASK) << 2505 (version & SSL_CONNECTION_VERSION_MASK) <<
2494 SSL_CONNECTION_VERSION_SHIFT; 2506 SSL_CONNECTION_VERSION_SHIFT;
2495 } 2507 }
2496 2508
2497 PRBool peer_supports_renego_ext; 2509 PRBool peer_supports_renego_ext;
2498 ok = SSL_HandshakeNegotiatedExtension(nss_fd_, ssl_renegotiation_info_xtn, 2510 ok = SSL_HandshakeNegotiatedExtension(nss_fd_, ssl_renegotiation_info_xtn,
2499 &peer_supports_renego_ext); 2511 &peer_supports_renego_ext);
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
3485 // shuts down. If the file system where the database resides is gone, 3497 // shuts down. If the file system where the database resides is gone,
3486 // the database connection goes bad. What's worse, the connection won't 3498 // the database connection goes bad. What's worse, the connection won't
3487 // recover when the file system comes back. Until this NSS or SQLite bug 3499 // recover when the file system comes back. Until this NSS or SQLite bug
3488 // is fixed, we need to avoid using the NSS database for non-essential 3500 // is fixed, we need to avoid using the NSS database for non-essential
3489 // purposes. See https://bugzilla.mozilla.org/show_bug.cgi?id=508081 and 3501 // purposes. See https://bugzilla.mozilla.org/show_bug.cgi?id=508081 and
3490 // http://crbug.com/15630 for more info. 3502 // http://crbug.com/15630 for more info.
3491 3503
3492 // TODO(hclam): Skip logging if server cert was expected to be bad because 3504 // TODO(hclam): Skip logging if server cert was expected to be bad because
3493 // |server_cert_verify_result_| doesn't contain all the information about 3505 // |server_cert_verify_result_| doesn't contain all the information about
3494 // the cert. 3506 // the cert.
3495 if (result == OK) 3507 if (result == OK) {
3496 LogConnectionTypeMetrics(); 3508 int ssl_version =
3509 SSLConnectionStatusToVersion(core_->state().ssl_connection_status);
3510 RecordConnectionTypeMetrics(ssl_version);
3511 }
3497 3512
3498 const CertStatus cert_status = server_cert_verify_result_.cert_status; 3513 const CertStatus cert_status = server_cert_verify_result_.cert_status;
3499 if (transport_security_state_ && 3514 if (transport_security_state_ &&
3500 (result == OK || 3515 (result == OK ||
3501 (IsCertificateError(result) && IsCertStatusMinorError(cert_status))) && 3516 (IsCertificateError(result) && IsCertStatusMinorError(cert_status))) &&
3502 !transport_security_state_->CheckPublicKeyPins( 3517 !transport_security_state_->CheckPublicKeyPins(
3503 host_and_port_.host(), 3518 host_and_port_.host(),
3504 server_cert_verify_result_.is_issued_by_known_root, 3519 server_cert_verify_result_.is_issued_by_known_root,
3505 server_cert_verify_result_.public_key_hashes, 3520 server_cert_verify_result_.public_key_hashes,
3506 &pinning_failure_log_)) { 3521 &pinning_failure_log_)) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3554 // TODO(ekasper): wipe stapled_ocsp_response and sct_list_from_tls_extension 3569 // TODO(ekasper): wipe stapled_ocsp_response and sct_list_from_tls_extension
3555 // from the state after verification is complete, to conserve memory. 3570 // from the state after verification is complete, to conserve memory.
3556 3571
3557 VLOG(1) << "CT Verification complete: result " << result 3572 VLOG(1) << "CT Verification complete: result " << result
3558 << " Invalid scts: " << ct_verify_result_.invalid_scts.size() 3573 << " Invalid scts: " << ct_verify_result_.invalid_scts.size()
3559 << " Verified scts: " << ct_verify_result_.verified_scts.size() 3574 << " Verified scts: " << ct_verify_result_.verified_scts.size()
3560 << " scts from unknown logs: " 3575 << " scts from unknown logs: "
3561 << ct_verify_result_.unknown_logs_scts.size(); 3576 << ct_verify_result_.unknown_logs_scts.size();
3562 } 3577 }
3563 3578
3564 void SSLClientSocketNSS::LogConnectionTypeMetrics() const {
3565 UpdateConnectionTypeHistograms(CONNECTION_SSL);
3566 int ssl_version = SSLConnectionStatusToVersion(
3567 core_->state().ssl_connection_status);
3568 switch (ssl_version) {
3569 case SSL_CONNECTION_VERSION_SSL2:
3570 UpdateConnectionTypeHistograms(CONNECTION_SSL_SSL2);
3571 break;
3572 case SSL_CONNECTION_VERSION_SSL3:
3573 UpdateConnectionTypeHistograms(CONNECTION_SSL_SSL3);
3574 break;
3575 case SSL_CONNECTION_VERSION_TLS1:
3576 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1);
3577 break;
3578 case SSL_CONNECTION_VERSION_TLS1_1:
3579 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_1);
3580 break;
3581 case SSL_CONNECTION_VERSION_TLS1_2:
3582 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_2);
3583 break;
3584 };
3585 }
3586
3587 void SSLClientSocketNSS::EnsureThreadIdAssigned() const { 3579 void SSLClientSocketNSS::EnsureThreadIdAssigned() const {
3588 base::AutoLock auto_lock(lock_); 3580 base::AutoLock auto_lock(lock_);
3589 if (valid_thread_id_ != base::kInvalidThreadId) 3581 if (valid_thread_id_ != base::kInvalidThreadId)
3590 return; 3582 return;
3591 valid_thread_id_ = base::PlatformThread::CurrentId(); 3583 valid_thread_id_ = base::PlatformThread::CurrentId();
3592 } 3584 }
3593 3585
3594 bool SSLClientSocketNSS::CalledOnValidThread() const { 3586 bool SSLClientSocketNSS::CalledOnValidThread() const {
3595 EnsureThreadIdAssigned(); 3587 EnsureThreadIdAssigned();
3596 base::AutoLock auto_lock(lock_); 3588 base::AutoLock auto_lock(lock_);
(...skipping 25 matching lines...) Expand all
3622 scoped_refptr<X509Certificate> 3614 scoped_refptr<X509Certificate>
3623 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { 3615 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const {
3624 return core_->state().server_cert.get(); 3616 return core_->state().server_cert.get();
3625 } 3617 }
3626 3618
3627 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { 3619 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const {
3628 return channel_id_service_; 3620 return channel_id_service_;
3629 } 3621 }
3630 3622
3631 } // namespace net 3623 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_nss.h ('k') | net/socket/ssl_client_socket_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698