| 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 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 CERTDistNames* ca_names, | 563 CERTDistNames* ca_names, |
| 564 CERTCertificate** result_certificate, | 564 CERTCertificate** result_certificate, |
| 565 SECKEYPrivateKey** result_private_key); | 565 SECKEYPrivateKey** result_private_key); |
| 566 | 566 |
| 567 // Called by NSS to determine if we can False Start. | 567 // Called by NSS to determine if we can False Start. |
| 568 // |arg| contains a pointer to the current SSLClientSocketNSS::Core. | 568 // |arg| contains a pointer to the current SSLClientSocketNSS::Core. |
| 569 static SECStatus CanFalseStartCallback(PRFileDesc* socket, | 569 static SECStatus CanFalseStartCallback(PRFileDesc* socket, |
| 570 void* arg, | 570 void* arg, |
| 571 PRBool* can_false_start); | 571 PRBool* can_false_start); |
| 572 | 572 |
| 573 // Called by NSS once the handshake has completed. | 573 // Called by NSS each time a handshake completely finishes. |
| 574 // |arg| contains a pointer to the current SSLClientSocketNSS::Core. | 574 // |arg| contains a pointer to the current SSLClientSocketNSS::Core. |
| 575 static void HandshakeCallback(PRFileDesc* socket, void* arg); | 575 static void HandshakeCallback(PRFileDesc* socket, void* arg); |
| 576 | 576 |
| 577 // Called once the handshake has succeeded. | 577 // Called once for each successful handshake. If the initial handshake false |
| 578 // starts, it is called when it false starts and not when it completely |
| 579 // finishes. |
| 578 void HandshakeSucceeded(); | 580 void HandshakeSucceeded(); |
| 579 | 581 |
| 580 // Handles an NSS error generated while handshaking or performing IO. | 582 // Handles an NSS error generated while handshaking or performing IO. |
| 581 // Returns a network error code mapped from the original NSS error. | 583 // Returns a network error code mapped from the original NSS error. |
| 582 int HandleNSSError(PRErrorCode error); | 584 int HandleNSSError(PRErrorCode error); |
| 583 | 585 |
| 584 int DoHandshakeLoop(int last_io_result); | 586 int DoHandshakeLoop(int last_io_result); |
| 585 int DoReadLoop(int result); | 587 int DoReadLoop(int result); |
| 586 int DoWriteLoop(int result); | 588 int DoWriteLoop(int result); |
| 587 | 589 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 void UpdateConnectionStatus(); | 632 void UpdateConnectionStatus(); |
| 631 // Record histograms for channel id support during full handshakes - resumed | 633 // Record histograms for channel id support during full handshakes - resumed |
| 632 // handshakes are ignored. | 634 // handshakes are ignored. |
| 633 void RecordChannelIDSupportOnNSSTaskRunner(); | 635 void RecordChannelIDSupportOnNSSTaskRunner(); |
| 634 // UpdateNextProto gets any application-layer protocol that may have been | 636 // UpdateNextProto gets any application-layer protocol that may have been |
| 635 // negotiated by the TLS connection. | 637 // negotiated by the TLS connection. |
| 636 void UpdateNextProto(); | 638 void UpdateNextProto(); |
| 637 // Record TLS extension used for protocol negotiation (NPN or ALPN). | 639 // Record TLS extension used for protocol negotiation (NPN or ALPN). |
| 638 void UpdateExtensionUsed(); | 640 void UpdateExtensionUsed(); |
| 639 | 641 |
| 642 // Returns true if renegotiations are allowed. |
| 643 bool IsRenegotiationAllowed() const; |
| 644 |
| 640 //////////////////////////////////////////////////////////////////////////// | 645 //////////////////////////////////////////////////////////////////////////// |
| 641 // Methods that are ONLY called on the network task runner: | 646 // Methods that are ONLY called on the network task runner: |
| 642 //////////////////////////////////////////////////////////////////////////// | 647 //////////////////////////////////////////////////////////////////////////// |
| 643 int DoBufferRecv(IOBuffer* buffer, int len); | 648 int DoBufferRecv(IOBuffer* buffer, int len); |
| 644 int DoBufferSend(IOBuffer* buffer, int len); | 649 int DoBufferSend(IOBuffer* buffer, int len); |
| 645 int DoGetChannelID(const std::string& host); | 650 int DoGetChannelID(const std::string& host); |
| 646 | 651 |
| 647 void OnGetChannelIDComplete(int result); | 652 void OnGetChannelIDComplete(int result); |
| 648 void OnHandshakeStateUpdated(const HandshakeState& state); | 653 void OnHandshakeStateUpdated(const HandshakeState& state); |
| 649 void OnNSSBufferUpdated(int amount_in_read_buffer); | 654 void OnNSSBufferUpdated(int amount_in_read_buffer); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 std::vector<std::string> predicted_certs_; | 739 std::vector<std::string> predicted_certs_; |
| 735 | 740 |
| 736 State next_handshake_state_; | 741 State next_handshake_state_; |
| 737 | 742 |
| 738 // True if channel ID extension was negotiated. | 743 // True if channel ID extension was negotiated. |
| 739 bool channel_id_xtn_negotiated_; | 744 bool channel_id_xtn_negotiated_; |
| 740 // True if the handshake state machine was interrupted for channel ID. | 745 // True if the handshake state machine was interrupted for channel ID. |
| 741 bool channel_id_needed_; | 746 bool channel_id_needed_; |
| 742 // True if the handshake state machine was interrupted for client auth. | 747 // True if the handshake state machine was interrupted for client auth. |
| 743 bool client_auth_cert_needed_; | 748 bool client_auth_cert_needed_; |
| 744 // True if NSS has False Started. | 749 // True if NSS has False Started in the initial handshake, but the initial |
| 750 // handshake has not yet completely finished.. |
| 745 bool false_started_; | 751 bool false_started_; |
| 746 // True if NSS has called HandshakeCallback. | 752 // True if NSS has called HandshakeCallback. |
| 747 bool handshake_callback_called_; | 753 bool handshake_callback_called_; |
| 748 | 754 |
| 749 HandshakeState nss_handshake_state_; | 755 HandshakeState nss_handshake_state_; |
| 750 | 756 |
| 751 bool transport_recv_busy_; | 757 bool transport_recv_busy_; |
| 752 bool transport_recv_eof_; | 758 bool transport_recv_eof_; |
| 753 bool transport_send_busy_; | 759 bool transport_send_busy_; |
| 754 | 760 |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 PostOrRunCallback( | 1449 PostOrRunCallback( |
| 1444 FROM_HERE, | 1450 FROM_HERE, |
| 1445 base::Bind(&AddLogEventWithCallback, weak_net_log_, | 1451 base::Bind(&AddLogEventWithCallback, weak_net_log_, |
| 1446 NetLog::TYPE_SSL_HANDSHAKE_ERROR, | 1452 NetLog::TYPE_SSL_HANDSHAKE_ERROR, |
| 1447 CreateNetLogSSLErrorCallback(net_error, 0))); | 1453 CreateNetLogSSLErrorCallback(net_error, 0))); |
| 1448 } else if (rv == SECSuccess) { | 1454 } else if (rv == SECSuccess) { |
| 1449 if (!handshake_callback_called_) { | 1455 if (!handshake_callback_called_) { |
| 1450 false_started_ = true; | 1456 false_started_ = true; |
| 1451 HandshakeSucceeded(); | 1457 HandshakeSucceeded(); |
| 1452 } | 1458 } |
| 1459 |
| 1460 if (IsRenegotiationAllowed()) { |
| 1461 // For compatibility, do not enforce RFC 5746 support. Per section 4.1, |
| 1462 // enforcement falls largely on the server. |
| 1463 SECStatus rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_RENEGOTIATION, |
| 1464 SSL_RENEGOTIATE_TRANSITIONAL); |
| 1465 DCHECK_EQ(SECSuccess, rv); |
| 1466 } |
| 1453 } else { | 1467 } else { |
| 1454 PRErrorCode prerr = PR_GetError(); | 1468 PRErrorCode prerr = PR_GetError(); |
| 1455 net_error = HandleNSSError(prerr); | 1469 net_error = HandleNSSError(prerr); |
| 1456 | 1470 |
| 1457 // If not done, stay in this state | 1471 // If not done, stay in this state |
| 1458 if (net_error == ERR_IO_PENDING) { | 1472 if (net_error == ERR_IO_PENDING) { |
| 1459 GotoState(STATE_HANDSHAKE); | 1473 GotoState(STATE_HANDSHAKE); |
| 1460 } else { | 1474 } else { |
| 1461 PostOrRunCallback( | 1475 PostOrRunCallback( |
| 1462 FROM_HERE, | 1476 FROM_HERE, |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2114 } else { | 2128 } else { |
| 2115 rv = SSL_HandshakeNegotiatedExtension(nss_fd_, | 2129 rv = SSL_HandshakeNegotiatedExtension(nss_fd_, |
| 2116 ssl_next_proto_nego_xtn, | 2130 ssl_next_proto_nego_xtn, |
| 2117 &negotiated_extension); | 2131 &negotiated_extension); |
| 2118 if (rv == SECSuccess && negotiated_extension) { | 2132 if (rv == SECSuccess && negotiated_extension) { |
| 2119 nss_handshake_state_.negotiation_extension_ = kExtensionNPN; | 2133 nss_handshake_state_.negotiation_extension_ = kExtensionNPN; |
| 2120 } | 2134 } |
| 2121 } | 2135 } |
| 2122 } | 2136 } |
| 2123 | 2137 |
| 2138 bool SSLClientSocketNSS::Core::IsRenegotiationAllowed() const { |
| 2139 DCHECK(OnNSSTaskRunner()); |
| 2140 |
| 2141 if (nss_handshake_state_.next_proto_status == kNextProtoUnsupported) |
| 2142 return ssl_config_.renego_allowed_default; |
| 2143 |
| 2144 NextProto next_proto = NextProtoFromString(nss_handshake_state_.next_proto); |
| 2145 for (NextProto allowed : ssl_config_.renego_allowed_for_protos) { |
| 2146 if (next_proto == allowed) |
| 2147 return true; |
| 2148 } |
| 2149 return false; |
| 2150 } |
| 2151 |
| 2124 void SSLClientSocketNSS::Core::RecordChannelIDSupportOnNSSTaskRunner() { | 2152 void SSLClientSocketNSS::Core::RecordChannelIDSupportOnNSSTaskRunner() { |
| 2125 DCHECK(OnNSSTaskRunner()); | 2153 DCHECK(OnNSSTaskRunner()); |
| 2126 if (nss_handshake_state_.resumed_handshake) | 2154 if (nss_handshake_state_.resumed_handshake) |
| 2127 return; | 2155 return; |
| 2128 | 2156 |
| 2129 // Copy the NSS task runner-only state to the network task runner and | 2157 // Copy the NSS task runner-only state to the network task runner and |
| 2130 // log histograms from there, since the histograms also need access to the | 2158 // log histograms from there, since the histograms also need access to the |
| 2131 // network task runner state. | 2159 // network task runner state. |
| 2132 PostOrRunCallback( | 2160 PostOrRunCallback( |
| 2133 FROM_HERE, | 2161 FROM_HERE, |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2785 if (rv != SECSuccess) { | 2813 if (rv != SECSuccess) { |
| 2786 LogFailedNSSFunction( | 2814 LogFailedNSSFunction( |
| 2787 net_log_, "SSL_OptionSet", "SSL_ENABLE_SESSION_TICKETS"); | 2815 net_log_, "SSL_OptionSet", "SSL_ENABLE_SESSION_TICKETS"); |
| 2788 } | 2816 } |
| 2789 | 2817 |
| 2790 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_FALSE_START, | 2818 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_FALSE_START, |
| 2791 ssl_config_.false_start_enabled); | 2819 ssl_config_.false_start_enabled); |
| 2792 if (rv != SECSuccess) | 2820 if (rv != SECSuccess) |
| 2793 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_FALSE_START"); | 2821 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_ENABLE_FALSE_START"); |
| 2794 | 2822 |
| 2795 // We allow servers to request renegotiation. Since we're a client, | 2823 // By default, renegotiations are rejected. After the initial handshake |
| 2796 // prohibiting this is rather a waste of time. Only servers are in a | 2824 // completes, some application protocols may re-enable it. |
| 2797 // position to prevent renegotiation attacks. | 2825 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_RENEGOTIATION, SSL_RENEGOTIATE_NEVER); |
| 2798 // http://extendedsubset.com/?p=8 | |
| 2799 | |
| 2800 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_RENEGOTIATION, | |
| 2801 SSL_RENEGOTIATE_TRANSITIONAL); | |
| 2802 if (rv != SECSuccess) { | 2826 if (rv != SECSuccess) { |
| 2803 LogFailedNSSFunction( | 2827 LogFailedNSSFunction( |
| 2804 net_log_, "SSL_OptionSet", "SSL_ENABLE_RENEGOTIATION"); | 2828 net_log_, "SSL_OptionSet", "SSL_ENABLE_RENEGOTIATION"); |
| 2805 } | 2829 } |
| 2806 | 2830 |
| 2807 rv = SSL_OptionSet(nss_fd_, SSL_CBC_RANDOM_IV, PR_TRUE); | 2831 rv = SSL_OptionSet(nss_fd_, SSL_CBC_RANDOM_IV, PR_TRUE); |
| 2808 if (rv != SECSuccess) | 2832 if (rv != SECSuccess) |
| 2809 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_CBC_RANDOM_IV"); | 2833 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_CBC_RANDOM_IV"); |
| 2810 | 2834 |
| 2811 // Added in NSS 3.15 | 2835 // Added in NSS 3.15 |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3175 scoped_refptr<X509Certificate> | 3199 scoped_refptr<X509Certificate> |
| 3176 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { | 3200 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { |
| 3177 return core_->state().server_cert.get(); | 3201 return core_->state().server_cert.get(); |
| 3178 } | 3202 } |
| 3179 | 3203 |
| 3180 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { | 3204 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { |
| 3181 return channel_id_service_; | 3205 return channel_id_service_; |
| 3182 } | 3206 } |
| 3183 | 3207 |
| 3184 } // namespace net | 3208 } // namespace net |
| OLD | NEW |