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/socket/ssl_client_socket.h" | 5 #include "net/socket/ssl_client_socket.h" |
6 | 6 |
7 #include "net/base/address_list.h" | 7 #include "net/base/address_list.h" |
8 #include "net/base/cert_verifier.h" | 8 #include "net/base/cert_verifier.h" |
9 #include "net/base/host_resolver.h" | 9 #include "net/base/host_resolver.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 276 |
277 EXPECT_EQ(net::OK, rv); | 277 EXPECT_EQ(net::OK, rv); |
278 EXPECT_TRUE(sock->IsConnected()); | 278 EXPECT_TRUE(sock->IsConnected()); |
279 log.GetEntries(&entries); | 279 log.GetEntries(&entries); |
280 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1)); | 280 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1)); |
281 | 281 |
282 sock->Disconnect(); | 282 sock->Disconnect(); |
283 EXPECT_FALSE(sock->IsConnected()); | 283 EXPECT_FALSE(sock->IsConnected()); |
284 } | 284 } |
285 | 285 |
| 286 // Connect using a certificate to a server that has TLS-SRP enabled. Tests that |
| 287 // when we set use_tls_auth=false in SSL config, it doesn't attempt TLS-SRP |
| 288 // auth. |
| 289 TEST_F(SSLClientSocketTest, ConnectUsingCertWithTLSAuthDisabled) { |
| 290 net::TestServer::HTTPSOptions https_options; |
| 291 https_options.use_tls_srp = true; |
| 292 net::TestServer test_server(https_options, FilePath()); |
| 293 ASSERT_TRUE(test_server.Start()); |
| 294 |
| 295 net::AddressList addr; |
| 296 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 297 |
| 298 TestCompletionCallback callback; |
| 299 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 300 net::ClientSocket* transport = new net::TCPClientSocket( |
| 301 addr, &log, net::NetLog::Source()); |
| 302 int rv = transport->Connect(&callback); |
| 303 if (rv == net::ERR_IO_PENDING) |
| 304 rv = callback.WaitForResult(); |
| 305 EXPECT_EQ(net::OK, rv); |
| 306 |
| 307 // Disable TLS-SRP |
| 308 net::SSLConfig ssl_config = kDefaultSSLConfig; |
| 309 ssl_config.use_tls_auth = false; |
| 310 |
| 311 scoped_ptr<net::SSLClientSocket> sock( |
| 312 socket_factory_->CreateSSLClientSocket( |
| 313 transport, test_server.host_port_pair(), ssl_config, |
| 314 NULL, cert_verifier_.get())); |
| 315 |
| 316 EXPECT_FALSE(sock->IsConnected()); |
| 317 |
| 318 rv = sock->Connect(&callback); |
| 319 |
| 320 net::CapturingNetLog::EntryList entries; |
| 321 log.GetEntries(&entries); |
| 322 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 323 entries, 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 324 if (rv == net::ERR_IO_PENDING) |
| 325 rv = callback.WaitForResult(); |
| 326 EXPECT_EQ(net::OK, rv); |
| 327 |
| 328 EXPECT_TRUE(sock->IsConnected()); |
| 329 log.GetEntries(&entries); |
| 330 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1)); |
| 331 |
| 332 sock->Disconnect(); |
| 333 EXPECT_FALSE(sock->IsConnected()); |
| 334 } |
| 335 |
286 // TODO(wtc): Add unit tests for IsConnectedAndIdle: | 336 // TODO(wtc): Add unit tests for IsConnectedAndIdle: |
287 // - Server closes an SSL connection (with a close_notify alert message). | 337 // - Server closes an SSL connection (with a close_notify alert message). |
288 // - Server closes the underlying TCP connection directly. | 338 // - Server closes the underlying TCP connection directly. |
289 // - Server sends data unexpectedly. | 339 // - Server sends data unexpectedly. |
290 | 340 |
291 TEST_F(SSLClientSocketTest, Read) { | 341 TEST_F(SSLClientSocketTest, Read) { |
292 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); | 342 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); |
293 ASSERT_TRUE(test_server.Start()); | 343 ASSERT_TRUE(test_server.Start()); |
294 | 344 |
295 net::AddressList addr; | 345 net::AddressList addr; |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 // to being an error such as a certificate name mismatch, which is | 662 // to being an error such as a certificate name mismatch, which is |
613 // client-only, the exact index of the SSL connect end depends on how | 663 // client-only, the exact index of the SSL connect end depends on how |
614 // quickly the test server closes the underlying socket. If the test server | 664 // quickly the test server closes the underlying socket. If the test server |
615 // closes before the IO message loop pumps messages, there may be a 0-byte | 665 // closes before the IO message loop pumps messages, there may be a 0-byte |
616 // Read event in the NetLog due to TCPClientSocket picking up the EOF. As a | 666 // Read event in the NetLog due to TCPClientSocket picking up the EOF. As a |
617 // result, the SSL connect end event will be the second-to-last entry, | 667 // result, the SSL connect end event will be the second-to-last entry, |
618 // rather than the last entry. | 668 // rather than the last entry. |
619 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1) || | 669 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1) || |
620 LogContainsSSLConnectEndEvent(entries, -2)); | 670 LogContainsSSLConnectEndEvent(entries, -2)); |
621 } | 671 } |
OLD | NEW |