OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // TODO(ukai): code is similar with http_network_transaction.cc. We should | 5 // TODO(ukai): code is similar with http_network_transaction.cc. We should |
6 // think about ways to share code, if possible. | 6 // think about ways to share code, if possible. |
7 | 7 |
8 #include "net/socket_stream/socket_stream.h" | 8 #include "net/socket_stream/socket_stream.h" |
9 | 9 |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "net/base/auth.h" | 19 #include "net/base/auth.h" |
20 #include "net/base/host_resolver.h" | 20 #include "net/base/host_resolver.h" |
21 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
24 #include "net/base/ssl_cert_request_info.h" | |
24 #include "net/http/http_auth_handler_factory.h" | 25 #include "net/http/http_auth_handler_factory.h" |
26 #include "net/http/http_network_session.h" | |
25 #include "net/http/http_request_info.h" | 27 #include "net/http/http_request_info.h" |
26 #include "net/http/http_response_headers.h" | 28 #include "net/http/http_response_headers.h" |
29 #include "net/http/http_transaction_factory.h" | |
27 #include "net/http/http_util.h" | 30 #include "net/http/http_util.h" |
28 #include "net/socket/client_socket_factory.h" | 31 #include "net/socket/client_socket_factory.h" |
29 #include "net/socket/socks5_client_socket.h" | 32 #include "net/socket/socks5_client_socket.h" |
30 #include "net/socket/socks_client_socket.h" | 33 #include "net/socket/socks_client_socket.h" |
31 #include "net/socket/ssl_client_socket.h" | 34 #include "net/socket/ssl_client_socket.h" |
32 #include "net/socket/tcp_client_socket.h" | 35 #include "net/socket/tcp_client_socket.h" |
33 #include "net/socket_stream/socket_stream_metrics.h" | 36 #include "net/socket_stream/socket_stream_metrics.h" |
34 #include "net/url_request/url_request.h" | 37 #include "net/url_request/url_request.h" |
35 | 38 |
36 static const int kMaxPendingSendAllowed = 32768; // 32 kilobytes. | 39 static const int kMaxPendingSendAllowed = 32768; // 32 kilobytes. |
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
916 next_state_ = STATE_SECURE_PROXY_CONNECT_COMPLETE; | 919 next_state_ = STATE_SECURE_PROXY_CONNECT_COMPLETE; |
917 metrics_->OnCountConnectionType(SocketStreamMetrics::SECURE_PROXY_CONNECTION); | 920 metrics_->OnCountConnectionType(SocketStreamMetrics::SECURE_PROXY_CONNECTION); |
918 return socket_->Connect(&io_callback_); | 921 return socket_->Connect(&io_callback_); |
919 } | 922 } |
920 | 923 |
921 int SocketStream::DoSecureProxyConnectComplete(int result) { | 924 int SocketStream::DoSecureProxyConnectComplete(int result) { |
922 DCHECK_EQ(STATE_NONE, next_state_); | 925 DCHECK_EQ(STATE_NONE, next_state_); |
923 result = DidEstablishSSL(result); | 926 result = DidEstablishSSL(result); |
924 if (next_state_ != STATE_NONE) | 927 if (next_state_ != STATE_NONE) |
925 return result; | 928 return result; |
929 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) | |
930 return HandleCertificateRequest(result); | |
926 if (result == OK) | 931 if (result == OK) |
927 next_state_ = STATE_WRITE_TUNNEL_HEADERS; | 932 next_state_ = STATE_WRITE_TUNNEL_HEADERS; |
928 else | 933 else |
929 next_state_ = STATE_CLOSE; | 934 next_state_ = STATE_CLOSE; |
930 return result; | 935 return result; |
931 } | 936 } |
932 | 937 |
933 int SocketStream::DoSSLConnect() { | 938 int SocketStream::DoSSLConnect() { |
934 DCHECK(factory_); | 939 DCHECK(factory_); |
935 SSLClientSocketContext ssl_context; | 940 SSLClientSocketContext ssl_context; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1081 auth_identity_.password = entry->password(); | 1086 auth_identity_.password = entry->password(); |
1082 // Restart with auth info. | 1087 // Restart with auth info. |
1083 } | 1088 } |
1084 return ERR_PROXY_AUTH_UNSUPPORTED; | 1089 return ERR_PROXY_AUTH_UNSUPPORTED; |
1085 } else { | 1090 } else { |
1086 auth_identity_.invalid = false; | 1091 auth_identity_.invalid = false; |
1087 } | 1092 } |
1088 return ERR_TUNNEL_CONNECTION_FAILED; | 1093 return ERR_TUNNEL_CONNECTION_FAILED; |
1089 } | 1094 } |
1090 | 1095 |
1096 int SocketStream::HandleCertificateRequest(int result) { | |
1097 // TODO(toyoshim): We must support SSL client authentication for not only | |
1098 // secure proxy but also secure server. | |
1099 | |
1100 if (ssl_config_.send_client_cert) | |
ukai
2011/10/17 01:48:56
we might need to have 2 SSLConfig?
server_ssl_con
Takashi Toyoshima
2011/10/17 02:50:05
When we support client authentication for secure s
ukai
2011/10/17 04:18:08
even without client authentication, can we use the
Takashi Toyoshima
2011/10/17 04:42:30
Oops!
Sorry, now I see what was wrong
I fix it.
| |
1101 // We already have performed SSL client authentication once and failed. | |
1102 return result; | |
1103 | |
1104 DCHECK(socket_.get()); | |
1105 scoped_refptr<SSLCertRequestInfo> cert_request_info = new SSLCertRequestInfo; | |
1106 SSLClientSocket* ssl_socket = | |
1107 reinterpret_cast<SSLClientSocket*>(socket_.get()); | |
ukai
2011/10/17 01:48:56
static_cast ?
Takashi Toyoshima
2011/10/17 02:50:05
Right.
I fixed it and a same wrong cast in DidEsta
| |
1108 ssl_socket->GetSSLCertRequestInfo(cert_request_info); | |
1109 | |
1110 HttpTransactionFactory* factory = context_->http_transaction_factory(); | |
1111 if (!factory) | |
1112 return result; | |
1113 scoped_refptr<HttpNetworkSession> session = factory->GetSession(); | |
1114 if (!session.get()) | |
1115 return result; | |
1116 | |
1117 scoped_refptr<X509Certificate> client_cert; | |
1118 bool found_cached_cert = session->ssl_client_auth_cache()->Lookup( | |
1119 cert_request_info->host_and_port, &client_cert); | |
1120 if (!found_cached_cert) | |
1121 return result; | |
1122 if (!client_cert) | |
1123 return result; | |
1124 | |
1125 const std::vector<scoped_refptr<X509Certificate> >& client_certs = | |
1126 cert_request_info->client_certs; | |
1127 bool cert_still_valid = false; | |
1128 for (size_t i = 0; i < client_certs.size(); ++i) { | |
1129 if (client_cert->Equals(client_certs[i])) { | |
1130 cert_still_valid = true; | |
1131 break; | |
1132 } | |
1133 } | |
1134 if (!cert_still_valid) | |
1135 return result; | |
1136 | |
1137 ssl_config_.send_client_cert = true; | |
1138 ssl_config_.client_cert = client_cert; | |
1139 next_state_ = STATE_TCP_CONNECT; | |
1140 return OK; | |
1141 } | |
1142 | |
1091 void SocketStream::DoAuthRequired() { | 1143 void SocketStream::DoAuthRequired() { |
1092 if (delegate_ && auth_info_.get()) | 1144 if (delegate_ && auth_info_.get()) |
1093 delegate_->OnAuthRequired(this, auth_info_.get()); | 1145 delegate_->OnAuthRequired(this, auth_info_.get()); |
1094 else | 1146 else |
1095 DoLoop(ERR_UNEXPECTED); | 1147 DoLoop(ERR_UNEXPECTED); |
1096 } | 1148 } |
1097 | 1149 |
1098 void SocketStream::DoRestartWithAuth() { | 1150 void SocketStream::DoRestartWithAuth() { |
1099 DCHECK_EQ(next_state_, STATE_AUTH_REQUIRED); | 1151 DCHECK_EQ(next_state_, STATE_AUTH_REQUIRED); |
1100 auth_cache_.Add(ProxyAuthOrigin(), | 1152 auth_cache_.Add(ProxyAuthOrigin(), |
(...skipping 30 matching lines...) Expand all Loading... | |
1131 | 1183 |
1132 SSLConfigService* SocketStream::ssl_config_service() const { | 1184 SSLConfigService* SocketStream::ssl_config_service() const { |
1133 return context_->ssl_config_service(); | 1185 return context_->ssl_config_service(); |
1134 } | 1186 } |
1135 | 1187 |
1136 ProxyService* SocketStream::proxy_service() const { | 1188 ProxyService* SocketStream::proxy_service() const { |
1137 return context_->proxy_service(); | 1189 return context_->proxy_service(); |
1138 } | 1190 } |
1139 | 1191 |
1140 } // namespace net | 1192 } // namespace net |
OLD | NEW |