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 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 // Read() and Write() mirror the net::Socket functions of the same name. | 632 // Read() and Write() mirror the net::Socket functions of the same name. |
633 // If ERR_IO_PENDING is returned, |callback| will be invoked on the network | 633 // If ERR_IO_PENDING is returned, |callback| will be invoked on the network |
634 // task runner at a later point, unless the caller calls Detach(). | 634 // task runner at a later point, unless the caller calls Detach(). |
635 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); | 635 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
636 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); | 636 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
637 | 637 |
638 // Called on the network task runner. | 638 // Called on the network task runner. |
639 bool IsConnected(); | 639 bool IsConnected(); |
640 bool HasPendingAsyncOperation(); | 640 bool HasPendingAsyncOperation(); |
641 bool HasUnhandledReceivedData(); | 641 bool HasUnhandledReceivedData(); |
| 642 bool WasEverUsed(); |
642 | 643 |
643 // Called on the network task runner. | 644 // Called on the network task runner. |
644 // Causes the associated SSL/TLS session ID to be added to NSS's session | 645 // Causes the associated SSL/TLS session ID to be added to NSS's session |
645 // cache, but only if the connection has not been False Started. | 646 // cache, but only if the connection has not been False Started. |
646 // | 647 // |
647 // This should only be called after the server's certificate has been | 648 // This should only be called after the server's certificate has been |
648 // verified, and may not be called within an NSS callback. | 649 // verified, and may not be called within an NSS callback. |
649 void CacheSessionIfNecessary(); | 650 void CacheSessionIfNecessary(); |
650 | 651 |
651 private: | 652 private: |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 | 834 |
834 // The service for retrieving Channel ID keys. May be NULL. | 835 // The service for retrieving Channel ID keys. May be NULL. |
835 ServerBoundCertService* server_bound_cert_service_; | 836 ServerBoundCertService* server_bound_cert_service_; |
836 ServerBoundCertService::RequestHandle domain_bound_cert_request_handle_; | 837 ServerBoundCertService::RequestHandle domain_bound_cert_request_handle_; |
837 | 838 |
838 // The information about NSS task runner. | 839 // The information about NSS task runner. |
839 int unhandled_buffer_size_; | 840 int unhandled_buffer_size_; |
840 bool nss_waiting_read_; | 841 bool nss_waiting_read_; |
841 bool nss_waiting_write_; | 842 bool nss_waiting_write_; |
842 bool nss_is_closed_; | 843 bool nss_is_closed_; |
| 844 bool was_used_to_convey_data_; |
843 | 845 |
844 //////////////////////////////////////////////////////////////////////////// | 846 //////////////////////////////////////////////////////////////////////////// |
845 // Members that are ONLY accessed on the NSS task runner: | 847 // Members that are ONLY accessed on the NSS task runner: |
846 //////////////////////////////////////////////////////////////////////////// | 848 //////////////////////////////////////////////////////////////////////////// |
847 HostPortPair host_and_port_; | 849 HostPortPair host_and_port_; |
848 SSLConfig ssl_config_; | 850 SSLConfig ssl_config_; |
849 | 851 |
850 // NSS SSL socket. | 852 // NSS SSL socket. |
851 PRFileDesc* nss_fd_; | 853 PRFileDesc* nss_fd_; |
852 | 854 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 BoundNetLog* net_log, | 931 BoundNetLog* net_log, |
930 ServerBoundCertService* server_bound_cert_service) | 932 ServerBoundCertService* server_bound_cert_service) |
931 : detached_(false), | 933 : detached_(false), |
932 transport_(transport), | 934 transport_(transport), |
933 weak_net_log_factory_(net_log), | 935 weak_net_log_factory_(net_log), |
934 server_bound_cert_service_(server_bound_cert_service), | 936 server_bound_cert_service_(server_bound_cert_service), |
935 unhandled_buffer_size_(0), | 937 unhandled_buffer_size_(0), |
936 nss_waiting_read_(false), | 938 nss_waiting_read_(false), |
937 nss_waiting_write_(false), | 939 nss_waiting_write_(false), |
938 nss_is_closed_(false), | 940 nss_is_closed_(false), |
| 941 was_used_to_convey_data_(false), |
939 host_and_port_(host_and_port), | 942 host_and_port_(host_and_port), |
940 ssl_config_(ssl_config), | 943 ssl_config_(ssl_config), |
941 nss_fd_(NULL), | 944 nss_fd_(NULL), |
942 nss_bufs_(NULL), | 945 nss_bufs_(NULL), |
943 pending_read_result_(kNoPendingReadResult), | 946 pending_read_result_(kNoPendingReadResult), |
944 pending_read_nss_error_(0), | 947 pending_read_nss_error_(0), |
945 next_handshake_state_(STATE_NONE), | 948 next_handshake_state_(STATE_NONE), |
946 channel_id_xtn_negotiated_(false), | 949 channel_id_xtn_negotiated_(false), |
947 channel_id_needed_(false), | 950 channel_id_needed_(false), |
948 client_auth_cert_needed_(false), | 951 client_auth_cert_needed_(false), |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 } else { | 1144 } else { |
1142 user_read_buf_ = NULL; | 1145 user_read_buf_ = NULL; |
1143 user_read_buf_len_ = 0; | 1146 user_read_buf_len_ = 0; |
1144 | 1147 |
1145 if (!OnNetworkTaskRunner()) { | 1148 if (!OnNetworkTaskRunner()) { |
1146 PostOrRunCallback(FROM_HERE, base::Bind(&Core::DidNSSRead, this, rv)); | 1149 PostOrRunCallback(FROM_HERE, base::Bind(&Core::DidNSSRead, this, rv)); |
1147 PostOrRunCallback(FROM_HERE, base::Bind(callback, rv)); | 1150 PostOrRunCallback(FROM_HERE, base::Bind(callback, rv)); |
1148 return ERR_IO_PENDING; | 1151 return ERR_IO_PENDING; |
1149 } else { | 1152 } else { |
1150 DCHECK(!nss_waiting_read_); | 1153 DCHECK(!nss_waiting_read_); |
1151 if (rv <= 0) | 1154 if (rv <= 0) { |
1152 nss_is_closed_ = true; | 1155 nss_is_closed_ = true; |
| 1156 } else { |
| 1157 was_used_to_convey_data_ = true; |
| 1158 } |
1153 } | 1159 } |
1154 } | 1160 } |
1155 | 1161 |
1156 return rv; | 1162 return rv; |
1157 } | 1163 } |
1158 | 1164 |
1159 int SSLClientSocketNSS::Core::Write(IOBuffer* buf, int buf_len, | 1165 int SSLClientSocketNSS::Core::Write(IOBuffer* buf, int buf_len, |
1160 const CompletionCallback& callback) { | 1166 const CompletionCallback& callback) { |
1161 if (!OnNSSTaskRunner()) { | 1167 if (!OnNSSTaskRunner()) { |
1162 DCHECK(OnNetworkTaskRunner()); | 1168 DCHECK(OnNetworkTaskRunner()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 } else { | 1201 } else { |
1196 user_write_buf_ = NULL; | 1202 user_write_buf_ = NULL; |
1197 user_write_buf_len_ = 0; | 1203 user_write_buf_len_ = 0; |
1198 | 1204 |
1199 if (!OnNetworkTaskRunner()) { | 1205 if (!OnNetworkTaskRunner()) { |
1200 PostOrRunCallback(FROM_HERE, base::Bind(&Core::DidNSSWrite, this, rv)); | 1206 PostOrRunCallback(FROM_HERE, base::Bind(&Core::DidNSSWrite, this, rv)); |
1201 PostOrRunCallback(FROM_HERE, base::Bind(callback, rv)); | 1207 PostOrRunCallback(FROM_HERE, base::Bind(callback, rv)); |
1202 return ERR_IO_PENDING; | 1208 return ERR_IO_PENDING; |
1203 } else { | 1209 } else { |
1204 DCHECK(!nss_waiting_write_); | 1210 DCHECK(!nss_waiting_write_); |
1205 if (rv < 0) | 1211 if (rv < 0) { |
1206 nss_is_closed_ = true; | 1212 nss_is_closed_ = true; |
| 1213 } else { |
| 1214 was_used_to_convey_data_ = true; |
| 1215 } |
1207 } | 1216 } |
1208 } | 1217 } |
1209 | 1218 |
1210 return rv; | 1219 return rv; |
1211 } | 1220 } |
1212 | 1221 |
1213 bool SSLClientSocketNSS::Core::IsConnected() { | 1222 bool SSLClientSocketNSS::Core::IsConnected() { |
1214 DCHECK(OnNetworkTaskRunner()); | 1223 DCHECK(OnNetworkTaskRunner()); |
1215 return !nss_is_closed_; | 1224 return !nss_is_closed_; |
1216 } | 1225 } |
1217 | 1226 |
1218 bool SSLClientSocketNSS::Core::HasPendingAsyncOperation() { | 1227 bool SSLClientSocketNSS::Core::HasPendingAsyncOperation() { |
1219 DCHECK(OnNetworkTaskRunner()); | 1228 DCHECK(OnNetworkTaskRunner()); |
1220 return nss_waiting_read_ || nss_waiting_write_; | 1229 return nss_waiting_read_ || nss_waiting_write_; |
1221 } | 1230 } |
1222 | 1231 |
1223 bool SSLClientSocketNSS::Core::HasUnhandledReceivedData() { | 1232 bool SSLClientSocketNSS::Core::HasUnhandledReceivedData() { |
1224 DCHECK(OnNetworkTaskRunner()); | 1233 DCHECK(OnNetworkTaskRunner()); |
1225 return unhandled_buffer_size_ != 0; | 1234 return unhandled_buffer_size_ != 0; |
1226 } | 1235 } |
1227 | 1236 |
| 1237 bool SSLClientSocketNSS::Core::WasEverUsed() { |
| 1238 DCHECK(OnNetworkTaskRunner()); |
| 1239 return was_used_to_convey_data_; |
| 1240 } |
| 1241 |
1228 void SSLClientSocketNSS::Core::CacheSessionIfNecessary() { | 1242 void SSLClientSocketNSS::Core::CacheSessionIfNecessary() { |
1229 // TODO(rsleevi): This should occur on the NSS task runner, due to the use of | 1243 // TODO(rsleevi): This should occur on the NSS task runner, due to the use of |
1230 // nss_fd_. However, it happens on the network task runner in order to match | 1244 // nss_fd_. However, it happens on the network task runner in order to match |
1231 // the buggy behavior of ExportKeyingMaterial. | 1245 // the buggy behavior of ExportKeyingMaterial. |
1232 // | 1246 // |
1233 // Once http://crbug.com/330360 is fixed, this should be moved to an | 1247 // Once http://crbug.com/330360 is fixed, this should be moved to an |
1234 // implementation that exclusively does this work on the NSS TaskRunner. This | 1248 // implementation that exclusively does this work on the NSS TaskRunner. This |
1235 // is "safe" because it is only called during the certificate verification | 1249 // is "safe" because it is only called during the certificate verification |
1236 // state machine of the main socket, which is safe because no underlying | 1250 // state machine of the main socket, which is safe because no underlying |
1237 // transport IO will be occuring in that state, and NSS will not be blocking | 1251 // transport IO will be occuring in that state, and NSS will not be blocking |
(...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2644 | 2658 |
2645 void SSLClientSocketNSS::Core::OnNSSBufferUpdated(int amount_in_read_buffer) { | 2659 void SSLClientSocketNSS::Core::OnNSSBufferUpdated(int amount_in_read_buffer) { |
2646 DCHECK(OnNetworkTaskRunner()); | 2660 DCHECK(OnNetworkTaskRunner()); |
2647 unhandled_buffer_size_ = amount_in_read_buffer; | 2661 unhandled_buffer_size_ = amount_in_read_buffer; |
2648 } | 2662 } |
2649 | 2663 |
2650 void SSLClientSocketNSS::Core::DidNSSRead(int result) { | 2664 void SSLClientSocketNSS::Core::DidNSSRead(int result) { |
2651 DCHECK(OnNetworkTaskRunner()); | 2665 DCHECK(OnNetworkTaskRunner()); |
2652 DCHECK(nss_waiting_read_); | 2666 DCHECK(nss_waiting_read_); |
2653 nss_waiting_read_ = false; | 2667 nss_waiting_read_ = false; |
2654 if (result <= 0) | 2668 if (result <= 0) { |
2655 nss_is_closed_ = true; | 2669 nss_is_closed_ = true; |
| 2670 } else { |
| 2671 was_used_to_convey_data_ = true; |
| 2672 } |
2656 } | 2673 } |
2657 | 2674 |
2658 void SSLClientSocketNSS::Core::DidNSSWrite(int result) { | 2675 void SSLClientSocketNSS::Core::DidNSSWrite(int result) { |
2659 DCHECK(OnNetworkTaskRunner()); | 2676 DCHECK(OnNetworkTaskRunner()); |
2660 DCHECK(nss_waiting_write_); | 2677 DCHECK(nss_waiting_write_); |
2661 nss_waiting_write_ = false; | 2678 nss_waiting_write_ = false; |
2662 if (result < 0) | 2679 if (result < 0) { |
2663 nss_is_closed_ = true; | 2680 nss_is_closed_ = true; |
| 2681 } else { |
| 2682 was_used_to_convey_data_ = true; |
| 2683 } |
2664 } | 2684 } |
2665 | 2685 |
2666 void SSLClientSocketNSS::Core::BufferSendComplete(int result) { | 2686 void SSLClientSocketNSS::Core::BufferSendComplete(int result) { |
2667 if (!OnNSSTaskRunner()) { | 2687 if (!OnNSSTaskRunner()) { |
2668 if (detached_) | 2688 if (detached_) |
2669 return; | 2689 return; |
2670 | 2690 |
2671 nss_task_runner_->PostTask( | 2691 nss_task_runner_->PostTask( |
2672 FROM_HERE, base::Bind(&Core::BufferSendComplete, this, result)); | 2692 FROM_HERE, base::Bind(&Core::BufferSendComplete, this, result)); |
2673 return; | 2693 return; |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3013 | 3033 |
3014 void SSLClientSocketNSS::SetOmniboxSpeculation() { | 3034 void SSLClientSocketNSS::SetOmniboxSpeculation() { |
3015 if (transport_.get() && transport_->socket()) { | 3035 if (transport_.get() && transport_->socket()) { |
3016 transport_->socket()->SetOmniboxSpeculation(); | 3036 transport_->socket()->SetOmniboxSpeculation(); |
3017 } else { | 3037 } else { |
3018 NOTREACHED(); | 3038 NOTREACHED(); |
3019 } | 3039 } |
3020 } | 3040 } |
3021 | 3041 |
3022 bool SSLClientSocketNSS::WasEverUsed() const { | 3042 bool SSLClientSocketNSS::WasEverUsed() const { |
3023 if (transport_.get() && transport_->socket()) { | 3043 DCHECK(core_.get()); |
3024 return transport_->socket()->WasEverUsed(); | 3044 |
3025 } | 3045 return core_->WasEverUsed(); |
3026 NOTREACHED(); | |
3027 return false; | |
3028 } | 3046 } |
3029 | 3047 |
3030 bool SSLClientSocketNSS::UsingTCPFastOpen() const { | 3048 bool SSLClientSocketNSS::UsingTCPFastOpen() const { |
3031 if (transport_.get() && transport_->socket()) { | 3049 if (transport_.get() && transport_->socket()) { |
3032 return transport_->socket()->UsingTCPFastOpen(); | 3050 return transport_->socket()->UsingTCPFastOpen(); |
3033 } | 3051 } |
3034 NOTREACHED(); | 3052 NOTREACHED(); |
3035 return false; | 3053 return false; |
3036 } | 3054 } |
3037 | 3055 |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3582 SignedCertificateTimestampAndStatus(*iter, | 3600 SignedCertificateTimestampAndStatus(*iter, |
3583 ct::SCT_STATUS_LOG_UNKNOWN)); | 3601 ct::SCT_STATUS_LOG_UNKNOWN)); |
3584 } | 3602 } |
3585 } | 3603 } |
3586 | 3604 |
3587 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { | 3605 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { |
3588 return server_bound_cert_service_; | 3606 return server_bound_cert_service_; |
3589 } | 3607 } |
3590 | 3608 |
3591 } // namespace net | 3609 } // namespace net |
OLD | NEW |