OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "net/base/auth.h" | 16 #include "net/base/auth.h" |
17 #include "net/base/capturing_net_log.h" | 17 #include "net/base/capturing_net_log.h" |
18 #include "net/base/completion_callback.h" | 18 #include "net/base/completion_callback.h" |
19 #include "net/base/mock_host_resolver.h" | 19 #include "net/base/mock_host_resolver.h" |
20 #include "net/base/net_log.h" | 20 #include "net/base/net_log.h" |
21 #include "net/base/net_log_unittest.h" | 21 #include "net/base/net_log_unittest.h" |
22 #include "net/base/request_priority.h" | 22 #include "net/base/request_priority.h" |
23 #include "net/base/ssl_cert_request_info.h" | |
23 #include "net/base/ssl_config_service_defaults.h" | 24 #include "net/base/ssl_config_service_defaults.h" |
24 #include "net/base/ssl_info.h" | 25 #include "net/base/ssl_info.h" |
25 #include "net/base/test_completion_callback.h" | 26 #include "net/base/test_completion_callback.h" |
26 #include "net/base/upload_data.h" | 27 #include "net/base/upload_data.h" |
27 #include "net/http/http_auth_handler_digest.h" | 28 #include "net/http/http_auth_handler_digest.h" |
28 #include "net/http/http_auth_handler_mock.h" | 29 #include "net/http/http_auth_handler_mock.h" |
29 #include "net/http/http_auth_handler_ntlm.h" | 30 #include "net/http/http_auth_handler_ntlm.h" |
30 #include "net/http/http_basic_stream.h" | 31 #include "net/http/http_basic_stream.h" |
31 #include "net/http/http_net_log_params.h" | 32 #include "net/http/http_net_log_params.h" |
32 #include "net/http/http_network_session.h" | 33 #include "net/http/http_network_session.h" |
(...skipping 8167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8200 if (rv == net::ERR_IO_PENDING) | 8201 if (rv == net::ERR_IO_PENDING) |
8201 rv = callback.WaitForResult(); | 8202 rv = callback.WaitForResult(); |
8202 ASSERT_EQ(OK, rv); | 8203 ASSERT_EQ(OK, rv); |
8203 | 8204 |
8204 std::string contents; | 8205 std::string contents; |
8205 rv = ReadTransaction(trans.get(), &contents); | 8206 rv = ReadTransaction(trans.get(), &contents); |
8206 EXPECT_EQ(net::OK, rv); | 8207 EXPECT_EQ(net::OK, rv); |
8207 EXPECT_EQ("hello world", contents); | 8208 EXPECT_EQ("hello world", contents); |
8208 } | 8209 } |
8209 | 8210 |
8211 // Test that a "bad" client certificate is not cached when TLS False | |
8212 // Start is not being used. | |
8213 TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_NoFalseStart) { | |
8214 SessionDependencies session_deps; | |
8215 | |
8216 // When False Start is disabled, the result of Connect() is the actual | |
8217 // result of the SSL handshake. | |
8218 // [ssl_]data1 = Aborted handshake for client auth, TLSv1 | |
Ryan Hamilton
2011/01/05 17:35:02
Would it make sense to elaborate on the comment he
| |
8219 // [ssl_]data2 = Failed handshake due to client auth, TLSv1 | |
8220 // [ssl_]data3 = Failed handshake, SSLv3 fallback (http://crbug.com/66517) | |
Ryan Hamilton
2011/01/05 17:35:02
Is ssl_data3 used? I only see one place where ERR
| |
8221 | |
8222 SSLSocketDataProvider ssl_data1(true /* async */, | |
8223 net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED); | |
8224 SSLSocketDataProvider ssl_data2(true /* async */, | |
8225 net::ERR_SSL_PROTOCOL_ERROR); | |
8226 SSLSocketDataProvider ssl_data3(true /* async */, | |
8227 net::ERR_SSL_PROTOCOL_ERROR); | |
8228 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); | |
8229 cert_request->host_and_port = "www.example.com:443"; | |
8230 ssl_data1.cert_request_info = cert_request.get(); | |
8231 ssl_data2.cert_request_info = cert_request.get(); | |
8232 ssl_data3.cert_request_info = cert_request.get(); | |
8233 | |
8234 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0); | |
8235 net::StaticSocketDataProvider data2(NULL, 0, NULL, 0); | |
8236 net::StaticSocketDataProvider data3(NULL, 0, NULL, 0); | |
8237 | |
8238 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data1); | |
8239 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data2); | |
8240 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data3); | |
8241 session_deps.socket_factory.AddSocketDataProvider(&data1); | |
8242 session_deps.socket_factory.AddSocketDataProvider(&data2); | |
8243 session_deps.socket_factory.AddSocketDataProvider(&data3); | |
8244 | |
8245 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
8246 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); | |
8247 | |
8248 net::HttpRequestInfo request_info; | |
8249 request_info.url = GURL("https://www.example.com/"); | |
8250 request_info.method = "GET"; | |
8251 request_info.load_flags = net::LOAD_NORMAL; | |
8252 | |
8253 TestCompletionCallback callback; | |
8254 int rv = trans->Start(&request_info, &callback, net::BoundNetLog()); | |
8255 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
8256 rv = callback.WaitForResult(); | |
8257 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); | |
8258 | |
8259 // Supply a dummy certificate. The SSLClientAuthCertCache tests ensure | |
8260 // this test should behave the same as if this test used a real cert. | |
8261 rv = trans->RestartWithCertificate(NULL, &callback); | |
8262 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
8263 | |
8264 // Ensure the certificate was added to the client auth cache before | |
8265 // allowing the connection to continue restarting. | |
8266 scoped_refptr<X509Certificate> client_cert; | |
8267 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", | |
8268 &client_cert)); | |
8269 ASSERT_EQ(NULL, client_cert.get()); | |
8270 rv = callback.WaitForResult(); | |
8271 | |
8272 // Now that the new handshake has failed, ensure that the client | |
8273 // certificate was removed from the client auth cache. | |
8274 ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); | |
8275 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", | |
8276 &client_cert)); | |
8277 } | |
8278 | |
8279 // Test that a "bad" client certificate is not cached when TLS False | |
8280 // Start is being used. | |
8281 TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_FalseStart) { | |
8282 SessionDependencies session_deps; | |
8283 | |
8284 // [ssl_]data1 = Aborted handshake (due to client auth), TLSv1 | |
8285 // [ssl_]data2 = Failed handshake, TLSv1 | |
8286 // [ssl_]data3 = Failed handshake, SSLv3 fallback (http://crbug.com/66517) | |
8287 // When False Start is used, the Connect() call is an artificial success. | |
8288 SSLSocketDataProvider ssl_data1(true /* async */, net::OK); | |
8289 SSLSocketDataProvider ssl_data2(true /* async */, net::OK); | |
8290 SSLSocketDataProvider ssl_data3(true /* async */, net::OK); | |
8291 | |
8292 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); | |
8293 cert_request->host_and_port = "www.example.com:443"; | |
8294 ssl_data1.cert_request_info = cert_request.get(); | |
8295 ssl_data2.cert_request_info = cert_request.get(); | |
8296 ssl_data3.cert_request_info = cert_request.get(); | |
8297 | |
8298 // When TLS False Start is used, the SSL handshake is completed by the | |
8299 // first attempt to Read from the socket. Ensure that even if the error is | |
8300 // delayed until Read, the client cert is still evicted from the cache. | |
8301 net::MockRead data1_reads[] = { | |
8302 net::MockRead(true /* async */, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED), | |
8303 }; | |
8304 net::MockRead data2_reads[] = { | |
8305 net::MockRead(true /* async */, net::ERR_SSL_PROTOCOL_ERROR), | |
8306 }; | |
8307 net::StaticSocketDataProvider data1( | |
8308 data1_reads, arraysize(data1_reads), NULL, 0); | |
8309 net::StaticSocketDataProvider data2( | |
8310 data2_reads, arraysize(data2_reads), NULL, 0); | |
8311 net::StaticSocketDataProvider data3( | |
8312 data2_reads, arraysize(data2_reads), NULL, 0); | |
8313 | |
8314 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data1); | |
8315 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data2); | |
8316 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_data3); | |
8317 session_deps.socket_factory.AddSocketDataProvider(&data1); | |
8318 session_deps.socket_factory.AddSocketDataProvider(&data2); | |
8319 session_deps.socket_factory.AddSocketDataProvider(&data3); | |
8320 | |
8321 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
8322 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); | |
8323 | |
8324 net::HttpRequestInfo request_info; | |
8325 request_info.url = GURL("https://www.example.com/"); | |
8326 request_info.method = "GET"; | |
8327 request_info.load_flags = net::LOAD_NORMAL; | |
8328 | |
8329 TestCompletionCallback callback; | |
8330 int rv = trans->Start(&request_info, &callback, net::BoundNetLog()); | |
8331 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
8332 rv = callback.WaitForResult(); | |
8333 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); | |
8334 | |
8335 // Supply a dummy certificate. The SSLClientAuthCertCache tests ensure | |
8336 // this test should behave the same as if this test used a real cert. | |
8337 rv = trans->RestartWithCertificate(NULL, &callback); | |
8338 ASSERT_EQ(net::ERR_IO_PENDING, rv); | |
8339 | |
8340 // Ensure the certificate was added to the client auth cache before | |
8341 // allowing the connection to continue restarting. | |
8342 scoped_refptr<X509Certificate> client_cert; | |
8343 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", | |
8344 &client_cert)); | |
8345 ASSERT_EQ(NULL, client_cert.get()); | |
8346 rv = callback.WaitForResult(); | |
8347 | |
8348 // Now that the new handshake has failed, ensure that the client | |
8349 // certificate was removed from the client auth cache. | |
8350 ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); | |
8351 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", | |
8352 &client_cert)); | |
8353 } | |
8354 | |
8210 } // namespace net | 8355 } // namespace net |
OLD | NEW |