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 // 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 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 // any time. | 635 // any time. |
| 636 const HandshakeState& state() const { return network_handshake_state_; } | 636 const HandshakeState& state() const { return network_handshake_state_; } |
| 637 | 637 |
| 638 // Called on the network task runner. | 638 // Called on the network task runner. |
| 639 // Read() and Write() mirror the net::Socket functions of the same name. | 639 // Read() and Write() mirror the net::Socket functions of the same name. |
| 640 // If ERR_IO_PENDING is returned, |callback| will be invoked on the network | 640 // If ERR_IO_PENDING is returned, |callback| will be invoked on the network |
| 641 // task runner at a later point, unless the caller calls Detach(). | 641 // task runner at a later point, unless the caller calls Detach(). |
| 642 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); | 642 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| 643 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); | 643 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| 644 | 644 |
| 645 // Called on the network task runner. | |
| 646 bool IsConnected(); | |
| 647 bool HasPendingAsyncOperation(); | |
| 648 bool HasUnhandledReceivedData(); | |
| 649 | |
| 645 private: | 650 private: |
| 646 friend class base::RefCountedThreadSafe<Core>; | 651 friend class base::RefCountedThreadSafe<Core>; |
| 647 ~Core(); | 652 ~Core(); |
| 648 | 653 |
| 649 enum State { | 654 enum State { |
| 650 STATE_NONE, | 655 STATE_NONE, |
| 651 STATE_HANDSHAKE, | 656 STATE_HANDSHAKE, |
| 652 STATE_GET_DOMAIN_BOUND_CERT_COMPLETE, | 657 STATE_GET_DOMAIN_BOUND_CERT_COMPLETE, |
| 653 }; | 658 }; |
| 654 | 659 |
| 660 enum Operation { | |
| 661 OPERATION_READ, | |
| 662 OPERATION_WRITE, | |
| 663 OPERATION_UPDATE, | |
| 664 }; | |
| 665 | |
| 655 bool OnNSSTaskRunner() const; | 666 bool OnNSSTaskRunner() const; |
| 656 bool OnNetworkTaskRunner() const; | 667 bool OnNetworkTaskRunner() const; |
| 657 | 668 |
| 658 //////////////////////////////////////////////////////////////////////////// | 669 //////////////////////////////////////////////////////////////////////////// |
| 659 // Methods that are ONLY called on the NSS task runner: | 670 // Methods that are ONLY called on the NSS task runner: |
| 660 //////////////////////////////////////////////////////////////////////////// | 671 //////////////////////////////////////////////////////////////////////////// |
| 661 | 672 |
| 662 // Called by NSS during full handshakes to allow the application to | 673 // Called by NSS during full handshakes to allow the application to |
| 663 // verify the certificate. Instead of verifying the certificate in the midst | 674 // verify the certificate. Instead of verifying the certificate in the midst |
| 664 // of the handshake, SECSuccess is always returned and the peer's certificate | 675 // of the handshake, SECSuccess is always returned and the peer's certificate |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 733 bool DoTransportIO(); | 744 bool DoTransportIO(); |
| 734 int BufferRecv(); | 745 int BufferRecv(); |
| 735 int BufferSend(); | 746 int BufferSend(); |
| 736 | 747 |
| 737 void OnRecvComplete(int result); | 748 void OnRecvComplete(int result); |
| 738 void OnSendComplete(int result); | 749 void OnSendComplete(int result); |
| 739 | 750 |
| 740 void DoConnectCallback(int result); | 751 void DoConnectCallback(int result); |
| 741 void DoReadCallback(int result); | 752 void DoReadCallback(int result); |
| 742 void DoWriteCallback(int result); | 753 void DoWriteCallback(int result); |
| 754 void UpdateNSSTaskRunnerStatus(int amount_in_read_buffer, | |
| 755 bool closed, | |
| 756 Operation operation, | |
| 757 const base::Closure& callback); | |
| 743 | 758 |
| 744 // Client channel ID handler. | 759 // Client channel ID handler. |
| 745 static SECStatus ClientChannelIDHandler( | 760 static SECStatus ClientChannelIDHandler( |
| 746 void* arg, | 761 void* arg, |
| 747 PRFileDesc* socket, | 762 PRFileDesc* socket, |
| 748 SECKEYPublicKey **out_public_key, | 763 SECKEYPublicKey **out_public_key, |
| 749 SECKEYPrivateKey **out_private_key); | 764 SECKEYPrivateKey **out_private_key); |
| 750 | 765 |
| 751 // ImportChannelIDKeys is a helper function for turning a DER-encoded cert and | 766 // ImportChannelIDKeys is a helper function for turning a DER-encoded cert and |
| 752 // key into a SECKEYPublicKey and SECKEYPrivateKey. Returns OK upon success | 767 // key into a SECKEYPublicKey and SECKEYPrivateKey. Returns OK upon success |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 810 ClientSocketHandle* transport_; | 825 ClientSocketHandle* transport_; |
| 811 base::WeakPtrFactory<BoundNetLog> weak_net_log_factory_; | 826 base::WeakPtrFactory<BoundNetLog> weak_net_log_factory_; |
| 812 | 827 |
| 813 // The current handshake state. Mirrors |nss_handshake_state_|. | 828 // The current handshake state. Mirrors |nss_handshake_state_|. |
| 814 HandshakeState network_handshake_state_; | 829 HandshakeState network_handshake_state_; |
| 815 | 830 |
| 816 // The service for retrieving Channel ID keys. May be NULL. | 831 // The service for retrieving Channel ID keys. May be NULL. |
| 817 ServerBoundCertService* server_bound_cert_service_; | 832 ServerBoundCertService* server_bound_cert_service_; |
| 818 ServerBoundCertService::RequestHandle domain_bound_cert_request_handle_; | 833 ServerBoundCertService::RequestHandle domain_bound_cert_request_handle_; |
| 819 | 834 |
| 835 // The information about NSS task runner. | |
| 836 int unhandled_buffer_size_; | |
| 837 bool nss_waiting_read_; | |
| 838 bool nss_waiting_write_; | |
| 839 bool nss_is_closed_; | |
| 840 | |
| 820 //////////////////////////////////////////////////////////////////////////// | 841 //////////////////////////////////////////////////////////////////////////// |
| 821 // Members that are ONLY accessed on the NSS task runner: | 842 // Members that are ONLY accessed on the NSS task runner: |
| 822 //////////////////////////////////////////////////////////////////////////// | 843 //////////////////////////////////////////////////////////////////////////// |
| 823 HostPortPair host_and_port_; | 844 HostPortPair host_and_port_; |
| 824 SSLConfig ssl_config_; | 845 SSLConfig ssl_config_; |
| 825 | 846 |
| 826 // NSS SSL socket. | 847 // NSS SSL socket. |
| 827 PRFileDesc* nss_fd_; | 848 PRFileDesc* nss_fd_; |
| 828 | 849 |
| 829 // Buffers for the network end of the SSL state machine | 850 // Buffers for the network end of the SSL state machine |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 base::SequencedTaskRunner* nss_task_runner, | 910 base::SequencedTaskRunner* nss_task_runner, |
| 890 ClientSocketHandle* transport, | 911 ClientSocketHandle* transport, |
| 891 const HostPortPair& host_and_port, | 912 const HostPortPair& host_and_port, |
| 892 const SSLConfig& ssl_config, | 913 const SSLConfig& ssl_config, |
| 893 BoundNetLog* net_log, | 914 BoundNetLog* net_log, |
| 894 ServerBoundCertService* server_bound_cert_service) | 915 ServerBoundCertService* server_bound_cert_service) |
| 895 : detached_(false), | 916 : detached_(false), |
| 896 transport_(transport), | 917 transport_(transport), |
| 897 weak_net_log_factory_(net_log), | 918 weak_net_log_factory_(net_log), |
| 898 server_bound_cert_service_(server_bound_cert_service), | 919 server_bound_cert_service_(server_bound_cert_service), |
| 920 unhandled_buffer_size_(0), | |
| 921 nss_waiting_read_(false), | |
| 922 nss_waiting_write_(false), | |
| 923 nss_is_closed_(false), | |
| 899 host_and_port_(host_and_port), | 924 host_and_port_(host_and_port), |
| 900 ssl_config_(ssl_config), | 925 ssl_config_(ssl_config), |
| 901 nss_fd_(NULL), | 926 nss_fd_(NULL), |
| 902 nss_bufs_(NULL), | 927 nss_bufs_(NULL), |
| 903 next_handshake_state_(STATE_NONE), | 928 next_handshake_state_(STATE_NONE), |
| 904 channel_id_xtn_negotiated_(false), | 929 channel_id_xtn_negotiated_(false), |
| 905 channel_id_needed_(false), | 930 channel_id_needed_(false), |
| 906 client_auth_cert_needed_(false), | 931 client_auth_cert_needed_(false), |
| 907 handshake_callback_called_(false), | 932 handshake_callback_called_(false), |
| 908 transport_recv_busy_(false), | 933 transport_recv_busy_(false), |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1087 const CompletionCallback& callback) { | 1112 const CompletionCallback& callback) { |
| 1088 if (!OnNSSTaskRunner()) { | 1113 if (!OnNSSTaskRunner()) { |
| 1089 DCHECK(OnNetworkTaskRunner()); | 1114 DCHECK(OnNetworkTaskRunner()); |
| 1090 DCHECK(!detached_); | 1115 DCHECK(!detached_); |
| 1091 DCHECK(transport_); | 1116 DCHECK(transport_); |
| 1092 | 1117 |
| 1093 bool posted = nss_task_runner_->PostTask( | 1118 bool posted = nss_task_runner_->PostTask( |
| 1094 FROM_HERE, | 1119 FROM_HERE, |
| 1095 base::Bind(IgnoreResult(&Core::Read), this, make_scoped_refptr(buf), | 1120 base::Bind(IgnoreResult(&Core::Read), this, make_scoped_refptr(buf), |
| 1096 buf_len, callback)); | 1121 buf_len, callback)); |
| 1122 if (!posted) | |
| 1123 nss_is_closed_ = true; | |
|
Ryan Sleevi
2013/01/21 16:33:29
BUG: Wrong thread here
Ryan Sleevi
2013/01/22 02:48:05
Er, this one was right
| |
| 1097 return posted ? ERR_IO_PENDING : ERR_ABORTED; | 1124 return posted ? ERR_IO_PENDING : ERR_ABORTED; |
| 1098 } | 1125 } |
| 1099 | 1126 |
| 1100 DCHECK(OnNSSTaskRunner()); | 1127 DCHECK(OnNSSTaskRunner()); |
| 1101 DCHECK(handshake_callback_called_); | 1128 DCHECK(handshake_callback_called_); |
| 1102 DCHECK_EQ(STATE_NONE, next_handshake_state_); | 1129 DCHECK_EQ(STATE_NONE, next_handshake_state_); |
| 1103 DCHECK(user_read_callback_.is_null()); | 1130 DCHECK(user_read_callback_.is_null()); |
| 1104 DCHECK(user_connect_callback_.is_null()); | 1131 DCHECK(user_connect_callback_.is_null()); |
| 1105 DCHECK(!user_read_buf_); | 1132 DCHECK(!user_read_buf_); |
| 1106 DCHECK(nss_bufs_); | 1133 DCHECK(nss_bufs_); |
| 1134 DCHECK(!nss_waiting_read_); | |
|
Ryan Sleevi
2013/01/21 16:33:29
BUG: Wrong thread here
Takashi Toyoshima
2013/01/22 14:16:50
Done.
| |
| 1107 | 1135 |
| 1108 user_read_buf_ = buf; | 1136 user_read_buf_ = buf; |
| 1109 user_read_buf_len_ = buf_len; | 1137 user_read_buf_len_ = buf_len; |
| 1110 | 1138 |
| 1111 int rv = DoReadLoop(OK); | 1139 int rv = DoReadLoop(OK); |
| 1112 if (rv == ERR_IO_PENDING) { | 1140 if (rv == ERR_IO_PENDING) { |
| 1113 user_read_callback_ = callback; | 1141 user_read_callback_ = callback; |
| 1142 nss_waiting_read_ = true; | |
|
Ryan Sleevi
2013/01/21 16:33:29
BUG: Wrong thread here
Takashi Toyoshima
2013/01/22 14:16:50
Done.
| |
| 1114 } else { | 1143 } else { |
| 1115 user_read_buf_ = NULL; | 1144 user_read_buf_ = NULL; |
| 1116 user_read_buf_len_ = 0; | 1145 user_read_buf_len_ = 0; |
| 1117 | 1146 |
| 1118 if (!OnNetworkTaskRunner()) { | 1147 if (!OnNetworkTaskRunner()) { |
| 1119 PostOrRunCallback(FROM_HERE, base::Bind(callback, rv)); | 1148 PostOrRunCallback(FROM_HERE, base::Bind(callback, rv)); |
| 1120 return ERR_IO_PENDING; | 1149 return ERR_IO_PENDING; |
| 1121 } | 1150 } |
| 1151 | |
| 1152 if (rv <= 0) | |
| 1153 nss_is_closed_ = true; | |
|
Ryan Sleevi
2013/01/21 16:33:29
BUG: Wrong thread here
Takashi Toyoshima
2013/01/22 14:16:50
Done.
| |
| 1122 } | 1154 } |
| 1123 | 1155 |
| 1124 return rv; | 1156 return rv; |
| 1125 } | 1157 } |
| 1126 | 1158 |
| 1127 int SSLClientSocketNSS::Core::Write(IOBuffer* buf, int buf_len, | 1159 int SSLClientSocketNSS::Core::Write(IOBuffer* buf, int buf_len, |
| 1128 const CompletionCallback& callback) { | 1160 const CompletionCallback& callback) { |
| 1129 if (!OnNSSTaskRunner()) { | 1161 if (!OnNSSTaskRunner()) { |
| 1130 DCHECK(OnNetworkTaskRunner()); | 1162 DCHECK(OnNetworkTaskRunner()); |
| 1131 DCHECK(!detached_); | 1163 DCHECK(!detached_); |
| 1132 DCHECK(transport_); | 1164 DCHECK(transport_); |
| 1133 | 1165 |
| 1134 bool posted = nss_task_runner_->PostTask( | 1166 bool posted = nss_task_runner_->PostTask( |
| 1135 FROM_HERE, | 1167 FROM_HERE, |
| 1136 base::Bind(IgnoreResult(&Core::Write), this, make_scoped_refptr(buf), | 1168 base::Bind(IgnoreResult(&Core::Write), this, make_scoped_refptr(buf), |
| 1137 buf_len, callback)); | 1169 buf_len, callback)); |
| 1138 int rv = posted ? ERR_IO_PENDING : ERR_ABORTED; | 1170 int rv = posted ? ERR_IO_PENDING : ERR_ABORTED; |
| 1171 if (!posted) | |
| 1172 nss_is_closed_ = true; | |
|
Ryan Sleevi
2013/01/21 16:33:29
BUG: Wrong thread here
Ryan Sleevi
2013/01/22 02:48:05
as was this one
Takashi Toyoshima
2013/01/22 14:16:50
Done.
| |
| 1139 return rv; | 1173 return rv; |
| 1140 } | 1174 } |
| 1141 | 1175 |
| 1142 DCHECK(OnNSSTaskRunner()); | 1176 DCHECK(OnNSSTaskRunner()); |
| 1143 DCHECK(handshake_callback_called_); | 1177 DCHECK(handshake_callback_called_); |
| 1144 DCHECK_EQ(STATE_NONE, next_handshake_state_); | 1178 DCHECK_EQ(STATE_NONE, next_handshake_state_); |
| 1145 DCHECK(user_write_callback_.is_null()); | 1179 DCHECK(user_write_callback_.is_null()); |
| 1146 DCHECK(user_connect_callback_.is_null()); | 1180 DCHECK(user_connect_callback_.is_null()); |
| 1147 DCHECK(!user_write_buf_); | 1181 DCHECK(!user_write_buf_); |
| 1148 DCHECK(nss_bufs_); | 1182 DCHECK(nss_bufs_); |
| 1183 DCHECK(!nss_waiting_write_); | |
|
Ryan Sleevi
2013/01/21 16:33:29
BUG: Wrong thread here
Takashi Toyoshima
2013/01/22 14:16:50
Done.
| |
| 1149 | 1184 |
| 1150 user_write_buf_ = buf; | 1185 user_write_buf_ = buf; |
| 1151 user_write_buf_len_ = buf_len; | 1186 user_write_buf_len_ = buf_len; |
| 1152 | 1187 |
| 1153 int rv = DoWriteLoop(OK); | 1188 int rv = DoWriteLoop(OK); |
| 1154 if (rv == ERR_IO_PENDING) { | 1189 if (rv == ERR_IO_PENDING) { |
| 1155 user_write_callback_ = callback; | 1190 user_write_callback_ = callback; |
| 1191 nss_waiting_write_ = true; | |
|
Ryan Sleevi
2013/01/21 16:33:29
BUG: Wrong thread here
Takashi Toyoshima
2013/01/22 14:16:50
Done.
| |
| 1156 } else { | 1192 } else { |
| 1157 user_write_buf_ = NULL; | 1193 user_write_buf_ = NULL; |
| 1158 user_write_buf_len_ = 0; | 1194 user_write_buf_len_ = 0; |
| 1159 | 1195 |
| 1160 if (!OnNetworkTaskRunner()) { | 1196 if (!OnNetworkTaskRunner()) { |
| 1161 PostOrRunCallback(FROM_HERE, base::Bind(callback, rv)); | 1197 PostOrRunCallback(FROM_HERE, base::Bind(callback, rv)); |
| 1162 return ERR_IO_PENDING; | 1198 return ERR_IO_PENDING; |
| 1163 } | 1199 } |
| 1200 | |
| 1201 if (rv < 0) | |
| 1202 nss_is_closed_ = true; | |
|
Ryan Sleevi
2013/01/21 16:33:29
BUG: Wrong thread here
Takashi Toyoshima
2013/01/22 14:16:50
Done.
| |
| 1164 } | 1203 } |
| 1165 | 1204 |
| 1166 return rv; | 1205 return rv; |
| 1167 } | 1206 } |
| 1168 | 1207 |
| 1208 bool SSLClientSocketNSS::Core::IsConnected() { | |
| 1209 return !nss_is_closed_; | |
| 1210 } | |
| 1211 | |
| 1212 bool SSLClientSocketNSS::Core::HasPendingAsyncOperation() { | |
| 1213 DCHECK(OnNetworkTaskRunner()); | |
| 1214 return nss_waiting_read_ || nss_waiting_write_; | |
| 1215 } | |
| 1216 | |
| 1217 bool SSLClientSocketNSS::Core::HasUnhandledReceivedData() { | |
| 1218 DCHECK(OnNetworkTaskRunner()); | |
| 1219 return unhandled_buffer_size_ != 0; | |
| 1220 } | |
| 1221 | |
| 1169 bool SSLClientSocketNSS::Core::OnNSSTaskRunner() const { | 1222 bool SSLClientSocketNSS::Core::OnNSSTaskRunner() const { |
| 1170 return nss_task_runner_->RunsTasksOnCurrentThread(); | 1223 return nss_task_runner_->RunsTasksOnCurrentThread(); |
| 1171 } | 1224 } |
| 1172 | 1225 |
| 1173 bool SSLClientSocketNSS::Core::OnNetworkTaskRunner() const { | 1226 bool SSLClientSocketNSS::Core::OnNetworkTaskRunner() const { |
| 1174 return network_task_runner_->RunsTasksOnCurrentThread(); | 1227 return network_task_runner_->RunsTasksOnCurrentThread(); |
| 1175 } | 1228 } |
| 1176 | 1229 |
| 1177 // static | 1230 // static |
| 1178 SECStatus SSLClientSocketNSS::Core::OwnAuthCertHandler( | 1231 SECStatus SSLClientSocketNSS::Core::OwnAuthCertHandler( |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2037 GotoState(STATE_HANDSHAKE); | 2090 GotoState(STATE_HANDSHAKE); |
| 2038 return OK; | 2091 return OK; |
| 2039 } | 2092 } |
| 2040 | 2093 |
| 2041 int SSLClientSocketNSS::Core::DoPayloadRead() { | 2094 int SSLClientSocketNSS::Core::DoPayloadRead() { |
| 2042 DCHECK(OnNSSTaskRunner()); | 2095 DCHECK(OnNSSTaskRunner()); |
| 2043 DCHECK(user_read_buf_); | 2096 DCHECK(user_read_buf_); |
| 2044 DCHECK_GT(user_read_buf_len_, 0); | 2097 DCHECK_GT(user_read_buf_len_, 0); |
| 2045 | 2098 |
| 2046 int rv = PR_Read(nss_fd_, user_read_buf_->data(), user_read_buf_len_); | 2099 int rv = PR_Read(nss_fd_, user_read_buf_->data(), user_read_buf_len_); |
| 2100 // Update NSSTaskRunner status because PR_Read may consume |nss_bufs_|, then | |
| 2101 // following |amount_in_read_buffer| may be changed here. | |
| 2102 int amount_in_read_buffer = memio_GetReadableBufferSize(nss_bufs_); | |
| 2103 base::Closure task = base::Bind( | |
| 2104 &Core::UpdateNSSTaskRunnerStatus, | |
| 2105 this, | |
| 2106 amount_in_read_buffer, | |
| 2107 rv <= 0 && rv != ERR_IO_PENDING, | |
| 2108 OPERATION_UPDATE, | |
| 2109 base::Closure()); | |
| 2110 | |
| 2047 if (client_auth_cert_needed_) { | 2111 if (client_auth_cert_needed_) { |
| 2048 // We don't need to invalidate the non-client-authenticated SSL session | 2112 // We don't need to invalidate the non-client-authenticated SSL session |
| 2049 // because the server will renegotiate anyway. | 2113 // because the server will renegotiate anyway. |
| 2050 rv = ERR_SSL_CLIENT_AUTH_CERT_NEEDED; | 2114 rv = ERR_SSL_CLIENT_AUTH_CERT_NEEDED; |
| 2051 PostOrRunCallback( | 2115 PostOrRunCallback( |
| 2052 FROM_HERE, | 2116 FROM_HERE, |
| 2053 base::Bind(&AddLogEventWithCallback, weak_net_log_, | 2117 base::Bind(&AddLogEventWithCallback, weak_net_log_, |
| 2054 NetLog::TYPE_SSL_READ_ERROR, | 2118 NetLog::TYPE_SSL_READ_ERROR, |
| 2055 CreateNetLogSSLErrorCallback(rv, 0))); | 2119 CreateNetLogSSLErrorCallback(rv, 0))); |
| 2056 return rv; | 2120 return rv; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2074 NetLog::TYPE_SSL_READ_ERROR, | 2138 NetLog::TYPE_SSL_READ_ERROR, |
| 2075 CreateNetLogSSLErrorCallback(rv, prerr))); | 2139 CreateNetLogSSLErrorCallback(rv, prerr))); |
| 2076 return rv; | 2140 return rv; |
| 2077 } | 2141 } |
| 2078 | 2142 |
| 2079 int SSLClientSocketNSS::Core::DoPayloadWrite() { | 2143 int SSLClientSocketNSS::Core::DoPayloadWrite() { |
| 2080 DCHECK(OnNSSTaskRunner()); | 2144 DCHECK(OnNSSTaskRunner()); |
| 2081 | 2145 |
| 2082 DCHECK(user_write_buf_); | 2146 DCHECK(user_write_buf_); |
| 2083 | 2147 |
| 2148 int old_amount_in_read_buffer = memio_GetReadableBufferSize(nss_bufs_); | |
| 2084 int rv = PR_Write(nss_fd_, user_write_buf_->data(), user_write_buf_len_); | 2149 int rv = PR_Write(nss_fd_, user_write_buf_->data(), user_write_buf_len_); |
| 2150 int new_amount_in_read_buffer = memio_GetReadableBufferSize(nss_bufs_); | |
| 2151 // PR_Write could potentially consume the unhandled data in the memio read | |
| 2152 // buffer if a renegotiation is in progress. If the buffer is consumed, | |
| 2153 // notify the latest buffer size to NetworkRunner. | |
| 2154 if (old_amount_in_read_buffer != new_amount_in_read_buffer) { | |
| 2155 base::Closure task = base::Bind( | |
| 2156 &Core::UpdateNSSTaskRunnerStatus, | |
| 2157 this, | |
| 2158 new_amount_in_read_buffer, | |
| 2159 false, | |
| 2160 OPERATION_UPDATE, | |
| 2161 base::Closure()); | |
| 2162 } | |
| 2085 if (rv >= 0) { | 2163 if (rv >= 0) { |
| 2086 PostOrRunCallback( | 2164 PostOrRunCallback( |
| 2087 FROM_HERE, | 2165 FROM_HERE, |
| 2088 base::Bind(&LogByteTransferEvent, weak_net_log_, | 2166 base::Bind(&LogByteTransferEvent, weak_net_log_, |
| 2089 NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, | 2167 NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, |
| 2090 scoped_refptr<IOBuffer>(user_write_buf_))); | 2168 scoped_refptr<IOBuffer>(user_write_buf_))); |
| 2091 return rv; | 2169 return rv; |
| 2092 } | 2170 } |
| 2093 PRErrorCode prerr = PR_GetError(); | 2171 PRErrorCode prerr = PR_GetError(); |
| 2094 if (prerr == PR_WOULD_BLOCK_ERROR) | 2172 if (prerr == PR_WOULD_BLOCK_ERROR) |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2280 PostOrRunCallback(FROM_HERE, c); | 2358 PostOrRunCallback(FROM_HERE, c); |
| 2281 } | 2359 } |
| 2282 | 2360 |
| 2283 void SSLClientSocketNSS::Core::DoReadCallback(int rv) { | 2361 void SSLClientSocketNSS::Core::DoReadCallback(int rv) { |
| 2284 DCHECK(OnNSSTaskRunner()); | 2362 DCHECK(OnNSSTaskRunner()); |
| 2285 DCHECK_NE(ERR_IO_PENDING, rv); | 2363 DCHECK_NE(ERR_IO_PENDING, rv); |
| 2286 DCHECK(!user_read_callback_.is_null()); | 2364 DCHECK(!user_read_callback_.is_null()); |
| 2287 | 2365 |
| 2288 user_read_buf_ = NULL; | 2366 user_read_buf_ = NULL; |
| 2289 user_read_buf_len_ = 0; | 2367 user_read_buf_len_ = 0; |
| 2290 base::Closure c = base::Bind( | 2368 int amount_in_read_buffer = memio_GetReadableBufferSize(nss_bufs_); |
| 2291 base::ResetAndReturn(&user_read_callback_), | 2369 // This will invoke the user callback with |rv| as result. |
| 2292 rv); | 2370 base::Closure user_cb = base::Bind( |
| 2293 PostOrRunCallback(FROM_HERE, c); | 2371 base::ResetAndReturn(&user_read_callback_), rv); |
| 2372 // This is used to curry the |amount_int_read_buffer| and |user_cb| back to | |
| 2373 // the network task runner. | |
| 2374 base::Closure task = base::Bind( | |
| 2375 &Core::UpdateNSSTaskRunnerStatus, | |
| 2376 this, | |
| 2377 amount_in_read_buffer, | |
| 2378 rv <= 0, // EOF or errors. | |
| 2379 OPERATION_READ, | |
| 2380 user_cb); | |
| 2381 PostOrRunCallback(FROM_HERE, task); | |
| 2294 } | 2382 } |
| 2295 | 2383 |
| 2296 void SSLClientSocketNSS::Core::DoWriteCallback(int rv) { | 2384 void SSLClientSocketNSS::Core::DoWriteCallback(int rv) { |
| 2297 DCHECK(OnNSSTaskRunner()); | 2385 DCHECK(OnNSSTaskRunner()); |
| 2298 DCHECK_NE(ERR_IO_PENDING, rv); | 2386 DCHECK_NE(ERR_IO_PENDING, rv); |
| 2299 DCHECK(!user_write_callback_.is_null()); | 2387 DCHECK(!user_write_callback_.is_null()); |
| 2300 | 2388 |
| 2301 // Since Run may result in Write being called, clear |user_write_callback_| | 2389 // Since Run may result in Write being called, clear |user_write_callback_| |
| 2302 // up front. | 2390 // up front. |
| 2303 user_write_buf_ = NULL; | 2391 user_write_buf_ = NULL; |
| 2304 user_write_buf_len_ = 0; | 2392 user_write_buf_len_ = 0; |
| 2305 base::Closure c = base::Bind( | 2393 // Update buffer status because DoWriteLoop called DoTransportIO which may |
| 2306 base::ResetAndReturn(&user_write_callback_), | 2394 // perform read operations. |
| 2307 rv); | 2395 int amount_in_read_buffer = memio_GetReadableBufferSize(nss_bufs_); |
| 2308 PostOrRunCallback(FROM_HERE, c); | 2396 // This will invoke the user callback with |rv| as result. |
| 2397 base::Closure user_cb = base::Bind( | |
| 2398 base::ResetAndReturn(&user_write_callback_), rv); | |
| 2399 // This is used to curry the |amount_int_read_buffer| and |user_cb| back to | |
| 2400 // the network task runner. | |
| 2401 base::Closure task = base::Bind( | |
| 2402 &Core::UpdateNSSTaskRunnerStatus, | |
| 2403 this, | |
| 2404 amount_in_read_buffer, | |
| 2405 rv < 0, // Errors. | |
| 2406 OPERATION_WRITE, | |
| 2407 user_cb); | |
| 2408 PostOrRunCallback(FROM_HERE, task); | |
| 2409 } | |
| 2410 | |
| 2411 void SSLClientSocketNSS::Core::UpdateNSSTaskRunnerStatus( | |
|
Takashi Toyoshima
2013/01/22 14:16:50
I renamed it as OnNSSTaskRunnerStateUpdated() to f
| |
| 2412 int amount_in_read_buffer, | |
| 2413 bool closed, | |
| 2414 Operation operation, | |
| 2415 const base::Closure& callback) { | |
| 2416 DCHECK(OnNetworkTaskRunner()); | |
| 2417 DCHECK(operation == OPERATION_UPDATE || !callback.is_null()); | |
| 2418 DCHECK((operation == OPERATION_READ && nss_waiting_read_) || | |
| 2419 (operation == OPERATION_WRITE && nss_waiting_write_) || | |
| 2420 operation == OPERATION_UPDATE); | |
| 2421 | |
| 2422 unhandled_buffer_size_ = amount_in_read_buffer; | |
| 2423 if (closed) | |
| 2424 nss_is_closed_ = true; | |
| 2425 if (operation == OPERATION_READ) | |
| 2426 nss_waiting_read_ = false; | |
| 2427 else if (operation == OPERATION_WRITE) | |
| 2428 nss_waiting_write_ = false; | |
| 2429 | |
| 2430 if (operation != OPERATION_UPDATE) | |
| 2431 callback.Run(); | |
| 2309 } | 2432 } |
| 2310 | 2433 |
| 2311 SECStatus SSLClientSocketNSS::Core::ClientChannelIDHandler( | 2434 SECStatus SSLClientSocketNSS::Core::ClientChannelIDHandler( |
| 2312 void* arg, | 2435 void* arg, |
| 2313 PRFileDesc* socket, | 2436 PRFileDesc* socket, |
| 2314 SECKEYPublicKey **out_public_key, | 2437 SECKEYPublicKey **out_public_key, |
| 2315 SECKEYPrivateKey **out_private_key) { | 2438 SECKEYPrivateKey **out_private_key) { |
| 2316 Core* core = reinterpret_cast<Core*>(arg); | 2439 Core* core = reinterpret_cast<Core*>(arg); |
| 2317 DCHECK(core->OnNSSTaskRunner()); | 2440 DCHECK(core->OnNSSTaskRunner()); |
| 2318 | 2441 |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2915 user_connect_callback_.Reset(); | 3038 user_connect_callback_.Reset(); |
| 2916 server_cert_verify_result_.Reset(); | 3039 server_cert_verify_result_.Reset(); |
| 2917 completed_handshake_ = false; | 3040 completed_handshake_ = false; |
| 2918 start_cert_verification_time_ = base::TimeTicks(); | 3041 start_cert_verification_time_ = base::TimeTicks(); |
| 2919 InitCore(); | 3042 InitCore(); |
| 2920 | 3043 |
| 2921 LeaveFunction(""); | 3044 LeaveFunction(""); |
| 2922 } | 3045 } |
| 2923 | 3046 |
| 2924 bool SSLClientSocketNSS::IsConnected() const { | 3047 bool SSLClientSocketNSS::IsConnected() const { |
| 2925 // Ideally, we should also check if we have received the close_notify alert | |
| 2926 // message from the server, and return false in that case. We're not doing | |
| 2927 // that, so this function may return a false positive. Since the upper | |
| 2928 // layer (HttpNetworkTransaction) needs to handle a persistent connection | |
| 2929 // closed by the server when we send a request anyway, a false positive in | |
| 2930 // exchange for simpler code is a good trade-off. | |
| 2931 EnterFunction(""); | 3048 EnterFunction(""); |
| 2932 bool ret = completed_handshake_ && transport_->socket()->IsConnected(); | 3049 bool ret = completed_handshake_ && |
| 3050 (core_->HasPendingAsyncOperation() || | |
| 3051 core_->HasUnhandledReceivedData() || | |
| 3052 core_->IsConnected() || | |
|
Ryan Sleevi
2013/01/21 16:33:29
This logic change isn't correct. You're short-circ
Takashi Toyoshima
2013/01/22 14:16:50
Thank you.
I was confused on how to handle transpo
| |
| 3053 transport_->socket()->IsConnected()); | |
| 2933 LeaveFunction(""); | 3054 LeaveFunction(""); |
| 2934 return ret; | 3055 return ret; |
| 2935 } | 3056 } |
| 2936 | 3057 |
| 2937 bool SSLClientSocketNSS::IsConnectedAndIdle() const { | 3058 bool SSLClientSocketNSS::IsConnectedAndIdle() const { |
| 2938 // Unlike IsConnected, this method doesn't return a false positive. | |
| 2939 // | |
| 2940 // Strictly speaking, we should check if we have received the close_notify | |
| 2941 // alert message from the server, and return false in that case. Although | |
| 2942 // the close_notify alert message means EOF in the SSL layer, it is just | |
| 2943 // bytes to the transport layer below, so | |
| 2944 // transport_->socket()->IsConnectedAndIdle() returns the desired false | |
| 2945 // when we receive close_notify. | |
| 2946 EnterFunction(""); | 3059 EnterFunction(""); |
| 2947 bool ret = completed_handshake_ && transport_->socket()->IsConnectedAndIdle(); | 3060 bool ret = IsConnected() && |
| 3061 !(core_->IsConnected() && core_->HasUnhandledReceivedData()) && | |
| 3062 transport_->socket()->IsConnectedAndIdle(); | |
| 2948 LeaveFunction(""); | 3063 LeaveFunction(""); |
| 2949 return ret; | 3064 return ret; |
| 2950 } | 3065 } |
| 2951 | 3066 |
| 2952 int SSLClientSocketNSS::GetPeerAddress(IPEndPoint* address) const { | 3067 int SSLClientSocketNSS::GetPeerAddress(IPEndPoint* address) const { |
| 2953 return transport_->socket()->GetPeerAddress(address); | 3068 return transport_->socket()->GetPeerAddress(address); |
| 2954 } | 3069 } |
| 2955 | 3070 |
| 2956 int SSLClientSocketNSS::GetLocalAddress(IPEndPoint* address) const { | 3071 int SSLClientSocketNSS::GetLocalAddress(IPEndPoint* address) const { |
| 2957 return transport_->socket()->GetLocalAddress(address); | 3072 return transport_->socket()->GetLocalAddress(address); |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3491 EnsureThreadIdAssigned(); | 3606 EnsureThreadIdAssigned(); |
| 3492 base::AutoLock auto_lock(lock_); | 3607 base::AutoLock auto_lock(lock_); |
| 3493 return valid_thread_id_ == base::PlatformThread::CurrentId(); | 3608 return valid_thread_id_ == base::PlatformThread::CurrentId(); |
| 3494 } | 3609 } |
| 3495 | 3610 |
| 3496 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { | 3611 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { |
| 3497 return server_bound_cert_service_; | 3612 return server_bound_cert_service_; |
| 3498 } | 3613 } |
| 3499 | 3614 |
| 3500 } // namespace net | 3615 } // namespace net |
| OLD | NEW |