| 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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 // but which also need to be read from the network task runner. The NSS task | 400 // but which also need to be read from the network task runner. The NSS task |
| 401 // runner will notify the network task runner whenever this state changes, so | 401 // runner will notify the network task runner whenever this state changes, so |
| 402 // that the network task runner can safely make a copy, which avoids the need | 402 // that the network task runner can safely make a copy, which avoids the need |
| 403 // for locking. | 403 // for locking. |
| 404 struct HandshakeState { | 404 struct HandshakeState { |
| 405 HandshakeState() { Reset(); } | 405 HandshakeState() { Reset(); } |
| 406 | 406 |
| 407 void Reset() { | 407 void Reset() { |
| 408 next_proto_status = SSLClientSocket::kNextProtoUnsupported; | 408 next_proto_status = SSLClientSocket::kNextProtoUnsupported; |
| 409 next_proto.clear(); | 409 next_proto.clear(); |
| 410 negotiation_extension_ = SSLClientSocket::kExtensionUnknown; |
| 410 channel_id_sent = false; | 411 channel_id_sent = false; |
| 411 server_cert_chain.Reset(NULL); | 412 server_cert_chain.Reset(NULL); |
| 412 server_cert = NULL; | 413 server_cert = NULL; |
| 413 sct_list_from_tls_extension.clear(); | 414 sct_list_from_tls_extension.clear(); |
| 414 stapled_ocsp_response.clear(); | 415 stapled_ocsp_response.clear(); |
| 415 resumed_handshake = false; | 416 resumed_handshake = false; |
| 416 ssl_connection_status = 0; | 417 ssl_connection_status = 0; |
| 417 } | 418 } |
| 418 | 419 |
| 419 // Set to kNextProtoNegotiated if NPN was successfully negotiated, with the | 420 // Set to kNextProtoNegotiated if NPN was successfully negotiated, with the |
| 420 // negotiated protocol stored in |next_proto|. | 421 // negotiated protocol stored in |next_proto|. |
| 421 SSLClientSocket::NextProtoStatus next_proto_status; | 422 SSLClientSocket::NextProtoStatus next_proto_status; |
| 422 std::string next_proto; | 423 std::string next_proto; |
| 423 | 424 |
| 425 // TLS extension used for protocol negotiation. |
| 426 SSLClientSocket::SSLNegotiationExtension negotiation_extension_; |
| 427 |
| 424 // True if a channel ID was sent. | 428 // True if a channel ID was sent. |
| 425 bool channel_id_sent; | 429 bool channel_id_sent; |
| 426 | 430 |
| 427 // List of DER-encoded X.509 DistinguishedName of certificate authorities | 431 // List of DER-encoded X.509 DistinguishedName of certificate authorities |
| 428 // allowed by the server. | 432 // allowed by the server. |
| 429 std::vector<std::string> cert_authorities; | 433 std::vector<std::string> cert_authorities; |
| 430 | 434 |
| 431 // Set when the handshake fully completes. | 435 // Set when the handshake fully completes. |
| 432 // | 436 // |
| 433 // The server certificate is first received from NSS as an NSS certificate | 437 // The server certificate is first received from NSS as an NSS certificate |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 // the SignedCertificateTimestampList received in the stapled OCSP response. | 756 // the SignedCertificateTimestampList received in the stapled OCSP response. |
| 753 void UpdateStapledOCSPResponse(); | 757 void UpdateStapledOCSPResponse(); |
| 754 // Updates the nss_handshake_state_ with the negotiated security parameters. | 758 // Updates the nss_handshake_state_ with the negotiated security parameters. |
| 755 void UpdateConnectionStatus(); | 759 void UpdateConnectionStatus(); |
| 756 // Record histograms for channel id support during full handshakes - resumed | 760 // Record histograms for channel id support during full handshakes - resumed |
| 757 // handshakes are ignored. | 761 // handshakes are ignored. |
| 758 void RecordChannelIDSupportOnNSSTaskRunner(); | 762 void RecordChannelIDSupportOnNSSTaskRunner(); |
| 759 // UpdateNextProto gets any application-layer protocol that may have been | 763 // UpdateNextProto gets any application-layer protocol that may have been |
| 760 // negotiated by the TLS connection. | 764 // negotiated by the TLS connection. |
| 761 void UpdateNextProto(); | 765 void UpdateNextProto(); |
| 766 // Record TLS extension used for protocol negotiation (NPN or ALPN). |
| 767 void UpdateExtensionUsed(); |
| 762 | 768 |
| 763 //////////////////////////////////////////////////////////////////////////// | 769 //////////////////////////////////////////////////////////////////////////// |
| 764 // Methods that are ONLY called on the network task runner: | 770 // Methods that are ONLY called on the network task runner: |
| 765 //////////////////////////////////////////////////////////////////////////// | 771 //////////////////////////////////////////////////////////////////////////// |
| 766 int DoBufferRecv(IOBuffer* buffer, int len); | 772 int DoBufferRecv(IOBuffer* buffer, int len); |
| 767 int DoBufferSend(IOBuffer* buffer, int len); | 773 int DoBufferSend(IOBuffer* buffer, int len); |
| 768 int DoGetChannelID(const std::string& host); | 774 int DoGetChannelID(const std::string& host); |
| 769 | 775 |
| 770 void OnGetChannelIDComplete(int result); | 776 void OnGetChannelIDComplete(int result); |
| 771 void OnHandshakeStateUpdated(const HandshakeState& state); | 777 void OnHandshakeStateUpdated(const HandshakeState& state); |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 } else { | 1639 } else { |
| 1634 nss_handshake_state_.resumed_handshake = false; | 1640 nss_handshake_state_.resumed_handshake = false; |
| 1635 } | 1641 } |
| 1636 | 1642 |
| 1637 RecordChannelIDSupportOnNSSTaskRunner(); | 1643 RecordChannelIDSupportOnNSSTaskRunner(); |
| 1638 UpdateServerCert(); | 1644 UpdateServerCert(); |
| 1639 UpdateSignedCertTimestamps(); | 1645 UpdateSignedCertTimestamps(); |
| 1640 UpdateStapledOCSPResponse(); | 1646 UpdateStapledOCSPResponse(); |
| 1641 UpdateConnectionStatus(); | 1647 UpdateConnectionStatus(); |
| 1642 UpdateNextProto(); | 1648 UpdateNextProto(); |
| 1649 UpdateExtensionUsed(); |
| 1643 | 1650 |
| 1644 // Update the network task runners view of the handshake state whenever | 1651 // Update the network task runners view of the handshake state whenever |
| 1645 // a handshake has completed. | 1652 // a handshake has completed. |
| 1646 PostOrRunCallback( | 1653 PostOrRunCallback( |
| 1647 FROM_HERE, base::Bind(&Core::OnHandshakeStateUpdated, this, | 1654 FROM_HERE, base::Bind(&Core::OnHandshakeStateUpdated, this, |
| 1648 nss_handshake_state_)); | 1655 nss_handshake_state_)); |
| 1649 } | 1656 } |
| 1650 | 1657 |
| 1651 int SSLClientSocketNSS::Core::HandleNSSError(PRErrorCode nss_error) { | 1658 int SSLClientSocketNSS::Core::HandleNSSError(PRErrorCode nss_error) { |
| 1652 DCHECK(OnNSSTaskRunner()); | 1659 DCHECK(OnNSSTaskRunner()); |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2484 break; | 2491 break; |
| 2485 case SSL_NEXT_PROTO_NO_SUPPORT: | 2492 case SSL_NEXT_PROTO_NO_SUPPORT: |
| 2486 nss_handshake_state_.next_proto_status = kNextProtoUnsupported; | 2493 nss_handshake_state_.next_proto_status = kNextProtoUnsupported; |
| 2487 break; | 2494 break; |
| 2488 default: | 2495 default: |
| 2489 NOTREACHED(); | 2496 NOTREACHED(); |
| 2490 break; | 2497 break; |
| 2491 } | 2498 } |
| 2492 } | 2499 } |
| 2493 | 2500 |
| 2501 void SSLClientSocketNSS::Core::UpdateExtensionUsed() { |
| 2502 PRBool negotiated_extension; |
| 2503 SECStatus rv = SSL_HandshakeNegotiatedExtension(nss_fd_, |
| 2504 ssl_app_layer_protocol_xtn, |
| 2505 &negotiated_extension); |
| 2506 if (rv == SECSuccess && negotiated_extension) { |
| 2507 nss_handshake_state_.negotiation_extension_ = kExtensionALPN; |
| 2508 } else { |
| 2509 rv = SSL_HandshakeNegotiatedExtension(nss_fd_, |
| 2510 ssl_next_proto_nego_xtn, |
| 2511 &negotiated_extension); |
| 2512 if (rv == SECSuccess && negotiated_extension) { |
| 2513 nss_handshake_state_.negotiation_extension_ = kExtensionNPN; |
| 2514 } |
| 2515 } |
| 2516 } |
| 2517 |
| 2494 void SSLClientSocketNSS::Core::RecordChannelIDSupportOnNSSTaskRunner() { | 2518 void SSLClientSocketNSS::Core::RecordChannelIDSupportOnNSSTaskRunner() { |
| 2495 DCHECK(OnNSSTaskRunner()); | 2519 DCHECK(OnNSSTaskRunner()); |
| 2496 if (nss_handshake_state_.resumed_handshake) | 2520 if (nss_handshake_state_.resumed_handshake) |
| 2497 return; | 2521 return; |
| 2498 | 2522 |
| 2499 // Copy the NSS task runner-only state to the network task runner and | 2523 // Copy the NSS task runner-only state to the network task runner and |
| 2500 // log histograms from there, since the histograms also need access to the | 2524 // log histograms from there, since the histograms also need access to the |
| 2501 // network task runner state. | 2525 // network task runner state. |
| 2502 PostOrRunCallback( | 2526 PostOrRunCallback( |
| 2503 FROM_HERE, | 2527 FROM_HERE, |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3316 if (result == OK) { | 3340 if (result == OK) { |
| 3317 // SSL handshake is completed. Let's verify the certificate. | 3341 // SSL handshake is completed. Let's verify the certificate. |
| 3318 GotoState(STATE_VERIFY_CERT); | 3342 GotoState(STATE_VERIFY_CERT); |
| 3319 // Done! | 3343 // Done! |
| 3320 } | 3344 } |
| 3321 set_channel_id_sent(core_->state().channel_id_sent); | 3345 set_channel_id_sent(core_->state().channel_id_sent); |
| 3322 set_signed_cert_timestamps_received( | 3346 set_signed_cert_timestamps_received( |
| 3323 !core_->state().sct_list_from_tls_extension.empty()); | 3347 !core_->state().sct_list_from_tls_extension.empty()); |
| 3324 set_stapled_ocsp_response_received( | 3348 set_stapled_ocsp_response_received( |
| 3325 !core_->state().stapled_ocsp_response.empty()); | 3349 !core_->state().stapled_ocsp_response.empty()); |
| 3350 set_negotiation_extension(core_->state().negotiation_extension_); |
| 3326 | 3351 |
| 3327 LeaveFunction(result); | 3352 LeaveFunction(result); |
| 3328 return result; | 3353 return result; |
| 3329 } | 3354 } |
| 3330 | 3355 |
| 3331 int SSLClientSocketNSS::DoVerifyCert(int result) { | 3356 int SSLClientSocketNSS::DoVerifyCert(int result) { |
| 3332 DCHECK(!core_->state().server_cert_chain.empty()); | 3357 DCHECK(!core_->state().server_cert_chain.empty()); |
| 3333 DCHECK(core_->state().server_cert_chain[0]); | 3358 DCHECK(core_->state().server_cert_chain[0]); |
| 3334 | 3359 |
| 3335 GotoState(STATE_VERIFY_CERT_COMPLETE); | 3360 GotoState(STATE_VERIFY_CERT_COMPLETE); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3523 scoped_refptr<X509Certificate> | 3548 scoped_refptr<X509Certificate> |
| 3524 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { | 3549 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { |
| 3525 return core_->state().server_cert.get(); | 3550 return core_->state().server_cert.get(); |
| 3526 } | 3551 } |
| 3527 | 3552 |
| 3528 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { | 3553 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { |
| 3529 return channel_id_service_; | 3554 return channel_id_service_; |
| 3530 } | 3555 } |
| 3531 | 3556 |
| 3532 } // namespace net | 3557 } // namespace net |
| OLD | NEW |