| 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 #include "net/socket/ssl_client_socket.h" | 5 #include "net/socket/ssl_client_socket.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "net/cert/ct_policy_enforcer.h" | 31 #include "net/cert/ct_policy_enforcer.h" |
| 32 #include "net/cert/ct_policy_status.h" | 32 #include "net/cert/ct_policy_status.h" |
| 33 #include "net/cert/ct_verifier.h" | 33 #include "net/cert/ct_verifier.h" |
| 34 #include "net/cert/mock_cert_verifier.h" | 34 #include "net/cert/mock_cert_verifier.h" |
| 35 #include "net/cert/test_root_certs.h" | 35 #include "net/cert/test_root_certs.h" |
| 36 #include "net/der/input.h" | 36 #include "net/der/input.h" |
| 37 #include "net/der/parser.h" | 37 #include "net/der/parser.h" |
| 38 #include "net/der/tag.h" | 38 #include "net/der/tag.h" |
| 39 #include "net/dns/host_resolver.h" | 39 #include "net/dns/host_resolver.h" |
| 40 #include "net/http/transport_security_state.h" | 40 #include "net/http/transport_security_state.h" |
| 41 #include "net/log/net_log.h" | |
| 42 #include "net/log/net_log_event_type.h" | 41 #include "net/log/net_log_event_type.h" |
| 42 #include "net/log/net_log_source.h" |
| 43 #include "net/log/test_net_log.h" | 43 #include "net/log/test_net_log.h" |
| 44 #include "net/log/test_net_log_entry.h" | 44 #include "net/log/test_net_log_entry.h" |
| 45 #include "net/log/test_net_log_util.h" | 45 #include "net/log/test_net_log_util.h" |
| 46 #include "net/socket/client_socket_factory.h" | 46 #include "net/socket/client_socket_factory.h" |
| 47 #include "net/socket/client_socket_handle.h" | 47 #include "net/socket/client_socket_handle.h" |
| 48 #include "net/socket/socket_test_util.h" | 48 #include "net/socket/socket_test_util.h" |
| 49 #include "net/socket/tcp_client_socket.h" | 49 #include "net/socket/tcp_client_socket.h" |
| 50 #include "net/ssl/channel_id_service.h" | 50 #include "net/ssl/channel_id_service.h" |
| 51 #include "net/ssl/default_channel_id_store.h" | 51 #include "net/ssl/default_channel_id_store.h" |
| 52 #include "net/ssl/ssl_cert_request_info.h" | 52 #include "net/ssl/ssl_cert_request_info.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 64 | 64 |
| 65 using net::test::IsError; | 65 using net::test::IsError; |
| 66 using net::test::IsOk; | 66 using net::test::IsOk; |
| 67 | 67 |
| 68 using testing::_; | 68 using testing::_; |
| 69 using testing::Return; | 69 using testing::Return; |
| 70 using testing::Truly; | 70 using testing::Truly; |
| 71 | 71 |
| 72 namespace net { | 72 namespace net { |
| 73 | 73 |
| 74 class NetLogWithSource; |
| 75 |
| 74 namespace { | 76 namespace { |
| 75 | 77 |
| 76 // WrappedStreamSocket is a base class that wraps an existing StreamSocket, | 78 // WrappedStreamSocket is a base class that wraps an existing StreamSocket, |
| 77 // forwarding the Socket and StreamSocket interfaces to the underlying | 79 // forwarding the Socket and StreamSocket interfaces to the underlying |
| 78 // transport. | 80 // transport. |
| 79 // This is to provide a common base class for subclasses to override specific | 81 // This is to provide a common base class for subclasses to override specific |
| 80 // StreamSocket methods for testing, while still communicating with a 'real' | 82 // StreamSocket methods for testing, while still communicating with a 'real' |
| 81 // StreamSocket. | 83 // StreamSocket. |
| 82 class WrappedStreamSocket : public StreamSocket { | 84 class WrappedStreamSocket : public StreamSocket { |
| 83 public: | 85 public: |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 // server, then wait for connection results. This must be called after | 803 // server, then wait for connection results. This must be called after |
| 802 // a successful StartTestServer() call. | 804 // a successful StartTestServer() call. |
| 803 // |ssl_config| the SSL configuration to use. | 805 // |ssl_config| the SSL configuration to use. |
| 804 // |result| will retrieve the ::Connect() result value. | 806 // |result| will retrieve the ::Connect() result value. |
| 805 // Returns true on success, false otherwise. Success means that the SSL socket | 807 // Returns true on success, false otherwise. Success means that the SSL socket |
| 806 // could be created and its Connect() was called, not that the connection | 808 // could be created and its Connect() was called, not that the connection |
| 807 // itself was a success. | 809 // itself was a success. |
| 808 bool CreateAndConnectSSLClientSocket(const SSLConfig& ssl_config, | 810 bool CreateAndConnectSSLClientSocket(const SSLConfig& ssl_config, |
| 809 int* result) { | 811 int* result) { |
| 810 std::unique_ptr<StreamSocket> transport( | 812 std::unique_ptr<StreamSocket> transport( |
| 811 new TCPClientSocket(addr_, NULL, &log_, NetLog::Source())); | 813 new TCPClientSocket(addr_, NULL, &log_, NetLogSource())); |
| 812 int rv = callback_.GetResult(transport->Connect(callback_.callback())); | 814 int rv = callback_.GetResult(transport->Connect(callback_.callback())); |
| 813 if (rv != OK) { | 815 if (rv != OK) { |
| 814 LOG(ERROR) << "Could not connect to SpawnedTestServer"; | 816 LOG(ERROR) << "Could not connect to SpawnedTestServer"; |
| 815 return false; | 817 return false; |
| 816 } | 818 } |
| 817 | 819 |
| 818 sock_ = CreateSSLClientSocket(std::move(transport), | 820 sock_ = CreateSSLClientSocket(std::move(transport), |
| 819 spawned_test_server_->host_port_pair(), | 821 spawned_test_server_->host_port_pair(), |
| 820 ssl_config); | 822 ssl_config); |
| 821 EXPECT_FALSE(sock_->IsConnected()); | 823 EXPECT_FALSE(sock_->IsConnected()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 if (!spawned_test_server.Start()) | 868 if (!spawned_test_server.Start()) |
| 867 return NULL; | 869 return NULL; |
| 868 | 870 |
| 869 AddressList addr; | 871 AddressList addr; |
| 870 if (!spawned_test_server.GetAddressList(&addr)) | 872 if (!spawned_test_server.GetAddressList(&addr)) |
| 871 return NULL; | 873 return NULL; |
| 872 | 874 |
| 873 TestCompletionCallback callback; | 875 TestCompletionCallback callback; |
| 874 TestNetLog log; | 876 TestNetLog log; |
| 875 std::unique_ptr<StreamSocket> transport( | 877 std::unique_ptr<StreamSocket> transport( |
| 876 new TCPClientSocket(addr, NULL, &log, NetLog::Source())); | 878 new TCPClientSocket(addr, NULL, &log, NetLogSource())); |
| 877 int rv = callback.GetResult(transport->Connect(callback.callback())); | 879 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 878 EXPECT_THAT(rv, IsOk()); | 880 EXPECT_THAT(rv, IsOk()); |
| 879 | 881 |
| 880 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 882 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 881 std::move(transport), spawned_test_server.host_port_pair(), | 883 std::move(transport), spawned_test_server.host_port_pair(), |
| 882 SSLConfig())); | 884 SSLConfig())); |
| 883 EXPECT_FALSE(sock->IsConnected()); | 885 EXPECT_FALSE(sock->IsConnected()); |
| 884 | 886 |
| 885 rv = callback.GetResult(sock->Connect(callback.callback())); | 887 rv = callback.GetResult(sock->Connect(callback.callback())); |
| 886 EXPECT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); | 888 EXPECT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 912 // | 914 // |
| 913 // Must be called after StartTestServer is called. | 915 // Must be called after StartTestServer is called. |
| 914 void CreateAndConnectUntilServerFinishedReceived( | 916 void CreateAndConnectUntilServerFinishedReceived( |
| 915 const SSLConfig& client_config, | 917 const SSLConfig& client_config, |
| 916 TestCompletionCallback* callback, | 918 TestCompletionCallback* callback, |
| 917 FakeBlockingStreamSocket** out_raw_transport, | 919 FakeBlockingStreamSocket** out_raw_transport, |
| 918 std::unique_ptr<SSLClientSocket>* out_sock) { | 920 std::unique_ptr<SSLClientSocket>* out_sock) { |
| 919 CHECK(spawned_test_server()); | 921 CHECK(spawned_test_server()); |
| 920 | 922 |
| 921 std::unique_ptr<StreamSocket> real_transport( | 923 std::unique_ptr<StreamSocket> real_transport( |
| 922 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 924 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 923 std::unique_ptr<FakeBlockingStreamSocket> transport( | 925 std::unique_ptr<FakeBlockingStreamSocket> transport( |
| 924 new FakeBlockingStreamSocket(std::move(real_transport))); | 926 new FakeBlockingStreamSocket(std::move(real_transport))); |
| 925 int rv = callback->GetResult(transport->Connect(callback->callback())); | 927 int rv = callback->GetResult(transport->Connect(callback->callback())); |
| 926 EXPECT_THAT(rv, IsOk()); | 928 EXPECT_THAT(rv, IsOk()); |
| 927 | 929 |
| 928 FakeBlockingStreamSocket* raw_transport = transport.get(); | 930 FakeBlockingStreamSocket* raw_transport = transport.get(); |
| 929 std::unique_ptr<SSLClientSocket> sock = CreateSSLClientSocket( | 931 std::unique_ptr<SSLClientSocket> sock = CreateSSLClientSocket( |
| 930 std::move(transport), spawned_test_server()->host_port_pair(), | 932 std::move(transport), spawned_test_server()->host_port_pair(), |
| 931 client_config); | 933 client_config); |
| 932 | 934 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 } | 1052 } |
| 1051 | 1053 |
| 1052 } // namespace | 1054 } // namespace |
| 1053 | 1055 |
| 1054 TEST_F(SSLClientSocketTest, Connect) { | 1056 TEST_F(SSLClientSocketTest, Connect) { |
| 1055 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1057 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 1056 | 1058 |
| 1057 TestCompletionCallback callback; | 1059 TestCompletionCallback callback; |
| 1058 TestNetLog log; | 1060 TestNetLog log; |
| 1059 std::unique_ptr<StreamSocket> transport( | 1061 std::unique_ptr<StreamSocket> transport( |
| 1060 new TCPClientSocket(addr(), NULL, &log, NetLog::Source())); | 1062 new TCPClientSocket(addr(), NULL, &log, NetLogSource())); |
| 1061 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1063 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 1062 EXPECT_THAT(rv, IsOk()); | 1064 EXPECT_THAT(rv, IsOk()); |
| 1063 | 1065 |
| 1064 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1066 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 1065 std::move(transport), spawned_test_server()->host_port_pair(), | 1067 std::move(transport), spawned_test_server()->host_port_pair(), |
| 1066 SSLConfig())); | 1068 SSLConfig())); |
| 1067 | 1069 |
| 1068 EXPECT_FALSE(sock->IsConnected()); | 1070 EXPECT_FALSE(sock->IsConnected()); |
| 1069 | 1071 |
| 1070 rv = sock->Connect(callback.callback()); | 1072 rv = sock->Connect(callback.callback()); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 // - Server closes the underlying TCP connection directly. | 1198 // - Server closes the underlying TCP connection directly. |
| 1197 // - Server sends data unexpectedly. | 1199 // - Server sends data unexpectedly. |
| 1198 | 1200 |
| 1199 // Tests that the socket can be read from successfully. Also test that a peer's | 1201 // Tests that the socket can be read from successfully. Also test that a peer's |
| 1200 // close_notify alert is successfully processed without error. | 1202 // close_notify alert is successfully processed without error. |
| 1201 TEST_F(SSLClientSocketTest, Read) { | 1203 TEST_F(SSLClientSocketTest, Read) { |
| 1202 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1204 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 1203 | 1205 |
| 1204 TestCompletionCallback callback; | 1206 TestCompletionCallback callback; |
| 1205 std::unique_ptr<StreamSocket> transport( | 1207 std::unique_ptr<StreamSocket> transport( |
| 1206 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1208 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 1207 EXPECT_EQ(0, transport->GetTotalReceivedBytes()); | 1209 EXPECT_EQ(0, transport->GetTotalReceivedBytes()); |
| 1208 | 1210 |
| 1209 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1211 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 1210 EXPECT_THAT(rv, IsOk()); | 1212 EXPECT_THAT(rv, IsOk()); |
| 1211 | 1213 |
| 1212 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1214 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 1213 std::move(transport), spawned_test_server()->host_port_pair(), | 1215 std::move(transport), spawned_test_server()->host_port_pair(), |
| 1214 SSLConfig())); | 1216 SSLConfig())); |
| 1215 EXPECT_EQ(0, sock->GetTotalReceivedBytes()); | 1217 EXPECT_EQ(0, sock->GetTotalReceivedBytes()); |
| 1216 | 1218 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 } | 1255 } |
| 1254 | 1256 |
| 1255 // Tests that SSLClientSocket properly handles when the underlying transport | 1257 // Tests that SSLClientSocket properly handles when the underlying transport |
| 1256 // synchronously fails a transport read in during the handshake. The error code | 1258 // synchronously fails a transport read in during the handshake. The error code |
| 1257 // should be preserved so SSLv3 fallback logic can condition on it. | 1259 // should be preserved so SSLv3 fallback logic can condition on it. |
| 1258 TEST_F(SSLClientSocketTest, Connect_WithSynchronousError) { | 1260 TEST_F(SSLClientSocketTest, Connect_WithSynchronousError) { |
| 1259 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1261 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 1260 | 1262 |
| 1261 TestCompletionCallback callback; | 1263 TestCompletionCallback callback; |
| 1262 std::unique_ptr<StreamSocket> real_transport( | 1264 std::unique_ptr<StreamSocket> real_transport( |
| 1263 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1265 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 1264 std::unique_ptr<SynchronousErrorStreamSocket> transport( | 1266 std::unique_ptr<SynchronousErrorStreamSocket> transport( |
| 1265 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1267 new SynchronousErrorStreamSocket(std::move(real_transport))); |
| 1266 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1268 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 1267 EXPECT_THAT(rv, IsOk()); | 1269 EXPECT_THAT(rv, IsOk()); |
| 1268 | 1270 |
| 1269 // Disable TLS False Start to avoid handshake non-determinism. | 1271 // Disable TLS False Start to avoid handshake non-determinism. |
| 1270 SSLConfig ssl_config; | 1272 SSLConfig ssl_config; |
| 1271 ssl_config.false_start_enabled = false; | 1273 ssl_config.false_start_enabled = false; |
| 1272 | 1274 |
| 1273 SynchronousErrorStreamSocket* raw_transport = transport.get(); | 1275 SynchronousErrorStreamSocket* raw_transport = transport.get(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1284 | 1286 |
| 1285 // Tests that the SSLClientSocket properly handles when the underlying transport | 1287 // Tests that the SSLClientSocket properly handles when the underlying transport |
| 1286 // synchronously returns an error code - such as if an intermediary terminates | 1288 // synchronously returns an error code - such as if an intermediary terminates |
| 1287 // the socket connection uncleanly. | 1289 // the socket connection uncleanly. |
| 1288 // This is a regression test for http://crbug.com/238536 | 1290 // This is a regression test for http://crbug.com/238536 |
| 1289 TEST_F(SSLClientSocketTest, Read_WithSynchronousError) { | 1291 TEST_F(SSLClientSocketTest, Read_WithSynchronousError) { |
| 1290 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1292 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 1291 | 1293 |
| 1292 TestCompletionCallback callback; | 1294 TestCompletionCallback callback; |
| 1293 std::unique_ptr<StreamSocket> real_transport( | 1295 std::unique_ptr<StreamSocket> real_transport( |
| 1294 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1296 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 1295 std::unique_ptr<SynchronousErrorStreamSocket> transport( | 1297 std::unique_ptr<SynchronousErrorStreamSocket> transport( |
| 1296 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1298 new SynchronousErrorStreamSocket(std::move(real_transport))); |
| 1297 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1299 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 1298 EXPECT_THAT(rv, IsOk()); | 1300 EXPECT_THAT(rv, IsOk()); |
| 1299 | 1301 |
| 1300 // Disable TLS False Start to avoid handshake non-determinism. | 1302 // Disable TLS False Start to avoid handshake non-determinism. |
| 1301 SSLConfig ssl_config; | 1303 SSLConfig ssl_config; |
| 1302 ssl_config.false_start_enabled = false; | 1304 ssl_config.false_start_enabled = false; |
| 1303 | 1305 |
| 1304 SynchronousErrorStreamSocket* raw_transport = transport.get(); | 1306 SynchronousErrorStreamSocket* raw_transport = transport.get(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1334 | 1336 |
| 1335 // Tests that the SSLClientSocket properly handles when the underlying transport | 1337 // Tests that the SSLClientSocket properly handles when the underlying transport |
| 1336 // asynchronously returns an error code while writing data - such as if an | 1338 // asynchronously returns an error code while writing data - such as if an |
| 1337 // intermediary terminates the socket connection uncleanly. | 1339 // intermediary terminates the socket connection uncleanly. |
| 1338 // This is a regression test for http://crbug.com/249848 | 1340 // This is a regression test for http://crbug.com/249848 |
| 1339 TEST_F(SSLClientSocketTest, Write_WithSynchronousError) { | 1341 TEST_F(SSLClientSocketTest, Write_WithSynchronousError) { |
| 1340 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1342 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 1341 | 1343 |
| 1342 TestCompletionCallback callback; | 1344 TestCompletionCallback callback; |
| 1343 std::unique_ptr<StreamSocket> real_transport( | 1345 std::unique_ptr<StreamSocket> real_transport( |
| 1344 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1346 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 1345 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer | 1347 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer |
| 1346 // is retained in order to configure additional errors. | 1348 // is retained in order to configure additional errors. |
| 1347 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( | 1349 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( |
| 1348 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1350 new SynchronousErrorStreamSocket(std::move(real_transport))); |
| 1349 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); | 1351 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); |
| 1350 std::unique_ptr<FakeBlockingStreamSocket> transport( | 1352 std::unique_ptr<FakeBlockingStreamSocket> transport( |
| 1351 new FakeBlockingStreamSocket(std::move(error_socket))); | 1353 new FakeBlockingStreamSocket(std::move(error_socket))); |
| 1352 FakeBlockingStreamSocket* raw_transport = transport.get(); | 1354 FakeBlockingStreamSocket* raw_transport = transport.get(); |
| 1353 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1355 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 1354 EXPECT_THAT(rv, IsOk()); | 1356 EXPECT_THAT(rv, IsOk()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 | 1403 |
| 1402 // If there is a Write failure at the transport with no follow-up Read, although | 1404 // If there is a Write failure at the transport with no follow-up Read, although |
| 1403 // the write error will not be returned to the client until a future Read or | 1405 // the write error will not be returned to the client until a future Read or |
| 1404 // Write operation, SSLClientSocket should not spin attempting to re-write on | 1406 // Write operation, SSLClientSocket should not spin attempting to re-write on |
| 1405 // the socket. This is a regression test for part of https://crbug.com/381160. | 1407 // the socket. This is a regression test for part of https://crbug.com/381160. |
| 1406 TEST_F(SSLClientSocketTest, Write_WithSynchronousErrorNoRead) { | 1408 TEST_F(SSLClientSocketTest, Write_WithSynchronousErrorNoRead) { |
| 1407 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1409 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 1408 | 1410 |
| 1409 TestCompletionCallback callback; | 1411 TestCompletionCallback callback; |
| 1410 std::unique_ptr<StreamSocket> real_transport( | 1412 std::unique_ptr<StreamSocket> real_transport( |
| 1411 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1413 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 1412 // Note: intermediate sockets' ownership are handed to |sock|, but a pointer | 1414 // Note: intermediate sockets' ownership are handed to |sock|, but a pointer |
| 1413 // is retained in order to query them. | 1415 // is retained in order to query them. |
| 1414 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( | 1416 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( |
| 1415 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1417 new SynchronousErrorStreamSocket(std::move(real_transport))); |
| 1416 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); | 1418 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); |
| 1417 std::unique_ptr<CountingStreamSocket> counting_socket( | 1419 std::unique_ptr<CountingStreamSocket> counting_socket( |
| 1418 new CountingStreamSocket(std::move(error_socket))); | 1420 new CountingStreamSocket(std::move(error_socket))); |
| 1419 CountingStreamSocket* raw_counting_socket = counting_socket.get(); | 1421 CountingStreamSocket* raw_counting_socket = counting_socket.get(); |
| 1420 int rv = callback.GetResult(counting_socket->Connect(callback.callback())); | 1422 int rv = callback.GetResult(counting_socket->Connect(callback.callback())); |
| 1421 ASSERT_THAT(rv, IsOk()); | 1423 ASSERT_THAT(rv, IsOk()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 // mode when the underlying transport is blocked on sending data. When the | 1503 // mode when the underlying transport is blocked on sending data. When the |
| 1502 // underlying transport completes due to an error, it should invoke both the | 1504 // underlying transport completes due to an error, it should invoke both the |
| 1503 // Read() and Write() callbacks. If the socket is deleted by the Read() | 1505 // Read() and Write() callbacks. If the socket is deleted by the Read() |
| 1504 // callback, the Write() callback should not be invoked. | 1506 // callback, the Write() callback should not be invoked. |
| 1505 // Regression test for http://crbug.com/232633 | 1507 // Regression test for http://crbug.com/232633 |
| 1506 TEST_F(SSLClientSocketTest, Read_DeleteWhilePendingFullDuplex) { | 1508 TEST_F(SSLClientSocketTest, Read_DeleteWhilePendingFullDuplex) { |
| 1507 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1509 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 1508 | 1510 |
| 1509 TestCompletionCallback callback; | 1511 TestCompletionCallback callback; |
| 1510 std::unique_ptr<StreamSocket> real_transport( | 1512 std::unique_ptr<StreamSocket> real_transport( |
| 1511 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1513 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 1512 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer | 1514 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer |
| 1513 // is retained in order to configure additional errors. | 1515 // is retained in order to configure additional errors. |
| 1514 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( | 1516 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( |
| 1515 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1517 new SynchronousErrorStreamSocket(std::move(real_transport))); |
| 1516 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); | 1518 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); |
| 1517 std::unique_ptr<FakeBlockingStreamSocket> transport( | 1519 std::unique_ptr<FakeBlockingStreamSocket> transport( |
| 1518 new FakeBlockingStreamSocket(std::move(error_socket))); | 1520 new FakeBlockingStreamSocket(std::move(error_socket))); |
| 1519 FakeBlockingStreamSocket* raw_transport = transport.get(); | 1521 FakeBlockingStreamSocket* raw_transport = transport.get(); |
| 1520 | 1522 |
| 1521 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1523 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 | 1582 |
| 1581 // Tests that the SSLClientSocket does not crash if data is received on the | 1583 // Tests that the SSLClientSocket does not crash if data is received on the |
| 1582 // transport socket after a failing write. This can occur if we have a Write | 1584 // transport socket after a failing write. This can occur if we have a Write |
| 1583 // error in a SPDY socket. | 1585 // error in a SPDY socket. |
| 1584 // Regression test for http://crbug.com/335557 | 1586 // Regression test for http://crbug.com/335557 |
| 1585 TEST_F(SSLClientSocketTest, Read_WithWriteError) { | 1587 TEST_F(SSLClientSocketTest, Read_WithWriteError) { |
| 1586 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1588 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 1587 | 1589 |
| 1588 TestCompletionCallback callback; | 1590 TestCompletionCallback callback; |
| 1589 std::unique_ptr<StreamSocket> real_transport( | 1591 std::unique_ptr<StreamSocket> real_transport( |
| 1590 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1592 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 1591 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer | 1593 // Note: |error_socket|'s ownership is handed to |transport|, but a pointer |
| 1592 // is retained in order to configure additional errors. | 1594 // is retained in order to configure additional errors. |
| 1593 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( | 1595 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( |
| 1594 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1596 new SynchronousErrorStreamSocket(std::move(real_transport))); |
| 1595 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); | 1597 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); |
| 1596 std::unique_ptr<FakeBlockingStreamSocket> transport( | 1598 std::unique_ptr<FakeBlockingStreamSocket> transport( |
| 1597 new FakeBlockingStreamSocket(std::move(error_socket))); | 1599 new FakeBlockingStreamSocket(std::move(error_socket))); |
| 1598 FakeBlockingStreamSocket* raw_transport = transport.get(); | 1600 FakeBlockingStreamSocket* raw_transport = transport.get(); |
| 1599 | 1601 |
| 1600 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1602 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1670 EXPECT_LT(0, rv); | 1672 EXPECT_LT(0, rv); |
| 1671 } | 1673 } |
| 1672 | 1674 |
| 1673 // Tests that SSLClientSocket fails the handshake if the underlying | 1675 // Tests that SSLClientSocket fails the handshake if the underlying |
| 1674 // transport is cleanly closed. | 1676 // transport is cleanly closed. |
| 1675 TEST_F(SSLClientSocketTest, Connect_WithZeroReturn) { | 1677 TEST_F(SSLClientSocketTest, Connect_WithZeroReturn) { |
| 1676 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1678 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 1677 | 1679 |
| 1678 TestCompletionCallback callback; | 1680 TestCompletionCallback callback; |
| 1679 std::unique_ptr<StreamSocket> real_transport( | 1681 std::unique_ptr<StreamSocket> real_transport( |
| 1680 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1682 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 1681 std::unique_ptr<SynchronousErrorStreamSocket> transport( | 1683 std::unique_ptr<SynchronousErrorStreamSocket> transport( |
| 1682 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1684 new SynchronousErrorStreamSocket(std::move(real_transport))); |
| 1683 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1685 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 1684 EXPECT_THAT(rv, IsOk()); | 1686 EXPECT_THAT(rv, IsOk()); |
| 1685 | 1687 |
| 1686 SynchronousErrorStreamSocket* raw_transport = transport.get(); | 1688 SynchronousErrorStreamSocket* raw_transport = transport.get(); |
| 1687 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1689 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 1688 std::move(transport), spawned_test_server()->host_port_pair(), | 1690 std::move(transport), spawned_test_server()->host_port_pair(), |
| 1689 SSLConfig())); | 1691 SSLConfig())); |
| 1690 | 1692 |
| 1691 raw_transport->SetNextReadError(0); | 1693 raw_transport->SetNextReadError(0); |
| 1692 | 1694 |
| 1693 rv = callback.GetResult(sock->Connect(callback.callback())); | 1695 rv = callback.GetResult(sock->Connect(callback.callback())); |
| 1694 EXPECT_THAT(rv, IsError(ERR_CONNECTION_CLOSED)); | 1696 EXPECT_THAT(rv, IsError(ERR_CONNECTION_CLOSED)); |
| 1695 EXPECT_FALSE(sock->IsConnected()); | 1697 EXPECT_FALSE(sock->IsConnected()); |
| 1696 } | 1698 } |
| 1697 | 1699 |
| 1698 // Tests that SSLClientSocket returns a Read of size 0 if the underlying socket | 1700 // Tests that SSLClientSocket returns a Read of size 0 if the underlying socket |
| 1699 // is cleanly closed, but the peer does not send close_notify. | 1701 // is cleanly closed, but the peer does not send close_notify. |
| 1700 // This is a regression test for https://crbug.com/422246 | 1702 // This is a regression test for https://crbug.com/422246 |
| 1701 TEST_F(SSLClientSocketTest, Read_WithZeroReturn) { | 1703 TEST_F(SSLClientSocketTest, Read_WithZeroReturn) { |
| 1702 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1704 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 1703 | 1705 |
| 1704 TestCompletionCallback callback; | 1706 TestCompletionCallback callback; |
| 1705 std::unique_ptr<StreamSocket> real_transport( | 1707 std::unique_ptr<StreamSocket> real_transport( |
| 1706 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1708 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 1707 std::unique_ptr<SynchronousErrorStreamSocket> transport( | 1709 std::unique_ptr<SynchronousErrorStreamSocket> transport( |
| 1708 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1710 new SynchronousErrorStreamSocket(std::move(real_transport))); |
| 1709 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1711 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 1710 EXPECT_THAT(rv, IsOk()); | 1712 EXPECT_THAT(rv, IsOk()); |
| 1711 | 1713 |
| 1712 // Disable TLS False Start to ensure the handshake has completed. | 1714 // Disable TLS False Start to ensure the handshake has completed. |
| 1713 SSLConfig ssl_config; | 1715 SSLConfig ssl_config; |
| 1714 ssl_config.false_start_enabled = false; | 1716 ssl_config.false_start_enabled = false; |
| 1715 | 1717 |
| 1716 SynchronousErrorStreamSocket* raw_transport = transport.get(); | 1718 SynchronousErrorStreamSocket* raw_transport = transport.get(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1729 } | 1731 } |
| 1730 | 1732 |
| 1731 // Tests that SSLClientSocket cleanly returns a Read of size 0 if the | 1733 // Tests that SSLClientSocket cleanly returns a Read of size 0 if the |
| 1732 // underlying socket is cleanly closed asynchronously. | 1734 // underlying socket is cleanly closed asynchronously. |
| 1733 // This is a regression test for https://crbug.com/422246 | 1735 // This is a regression test for https://crbug.com/422246 |
| 1734 TEST_F(SSLClientSocketTest, Read_WithAsyncZeroReturn) { | 1736 TEST_F(SSLClientSocketTest, Read_WithAsyncZeroReturn) { |
| 1735 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1737 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 1736 | 1738 |
| 1737 TestCompletionCallback callback; | 1739 TestCompletionCallback callback; |
| 1738 std::unique_ptr<StreamSocket> real_transport( | 1740 std::unique_ptr<StreamSocket> real_transport( |
| 1739 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1741 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 1740 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( | 1742 std::unique_ptr<SynchronousErrorStreamSocket> error_socket( |
| 1741 new SynchronousErrorStreamSocket(std::move(real_transport))); | 1743 new SynchronousErrorStreamSocket(std::move(real_transport))); |
| 1742 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); | 1744 SynchronousErrorStreamSocket* raw_error_socket = error_socket.get(); |
| 1743 std::unique_ptr<FakeBlockingStreamSocket> transport( | 1745 std::unique_ptr<FakeBlockingStreamSocket> transport( |
| 1744 new FakeBlockingStreamSocket(std::move(error_socket))); | 1746 new FakeBlockingStreamSocket(std::move(error_socket))); |
| 1745 FakeBlockingStreamSocket* raw_transport = transport.get(); | 1747 FakeBlockingStreamSocket* raw_transport = transport.get(); |
| 1746 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1748 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 1747 EXPECT_THAT(rv, IsOk()); | 1749 EXPECT_THAT(rv, IsOk()); |
| 1748 | 1750 |
| 1749 // Disable TLS False Start to ensure the handshake has completed. | 1751 // Disable TLS False Start to ensure the handshake has completed. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1810 EXPECT_GE(rv, 0); | 1812 EXPECT_GE(rv, 0); |
| 1811 } while (rv > 0); | 1813 } while (rv > 0); |
| 1812 } | 1814 } |
| 1813 | 1815 |
| 1814 TEST_F(SSLClientSocketTest, Read_ManySmallRecords) { | 1816 TEST_F(SSLClientSocketTest, Read_ManySmallRecords) { |
| 1815 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1817 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 1816 | 1818 |
| 1817 TestCompletionCallback callback; | 1819 TestCompletionCallback callback; |
| 1818 | 1820 |
| 1819 std::unique_ptr<StreamSocket> real_transport( | 1821 std::unique_ptr<StreamSocket> real_transport( |
| 1820 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 1822 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 1821 std::unique_ptr<ReadBufferingStreamSocket> transport( | 1823 std::unique_ptr<ReadBufferingStreamSocket> transport( |
| 1822 new ReadBufferingStreamSocket(std::move(real_transport))); | 1824 new ReadBufferingStreamSocket(std::move(real_transport))); |
| 1823 ReadBufferingStreamSocket* raw_transport = transport.get(); | 1825 ReadBufferingStreamSocket* raw_transport = transport.get(); |
| 1824 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1826 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 1825 ASSERT_THAT(rv, IsOk()); | 1827 ASSERT_THAT(rv, IsOk()); |
| 1826 | 1828 |
| 1827 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1829 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 1828 std::move(transport), spawned_test_server()->host_port_pair(), | 1830 std::move(transport), spawned_test_server()->host_port_pair(), |
| 1829 SSLConfig())); | 1831 SSLConfig())); |
| 1830 | 1832 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 EXPECT_GT(rv, 0); | 1883 EXPECT_GT(rv, 0); |
| 1882 } | 1884 } |
| 1883 | 1885 |
| 1884 TEST_F(SSLClientSocketTest, Read_FullLogging) { | 1886 TEST_F(SSLClientSocketTest, Read_FullLogging) { |
| 1885 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 1887 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 1886 | 1888 |
| 1887 TestCompletionCallback callback; | 1889 TestCompletionCallback callback; |
| 1888 TestNetLog log; | 1890 TestNetLog log; |
| 1889 log.SetCaptureMode(NetLogCaptureMode::IncludeSocketBytes()); | 1891 log.SetCaptureMode(NetLogCaptureMode::IncludeSocketBytes()); |
| 1890 std::unique_ptr<StreamSocket> transport( | 1892 std::unique_ptr<StreamSocket> transport( |
| 1891 new TCPClientSocket(addr(), NULL, &log, NetLog::Source())); | 1893 new TCPClientSocket(addr(), NULL, &log, NetLogSource())); |
| 1892 int rv = callback.GetResult(transport->Connect(callback.callback())); | 1894 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 1893 EXPECT_THAT(rv, IsOk()); | 1895 EXPECT_THAT(rv, IsOk()); |
| 1894 | 1896 |
| 1895 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 1897 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 1896 std::move(transport), spawned_test_server()->host_port_pair(), | 1898 std::move(transport), spawned_test_server()->host_port_pair(), |
| 1897 SSLConfig())); | 1899 SSLConfig())); |
| 1898 | 1900 |
| 1899 rv = callback.GetResult(sock->Connect(callback.callback())); | 1901 rv = callback.GetResult(sock->Connect(callback.callback())); |
| 1900 EXPECT_THAT(rv, IsOk()); | 1902 EXPECT_THAT(rv, IsOk()); |
| 1901 EXPECT_TRUE(sock->IsConnected()); | 1903 EXPECT_TRUE(sock->IsConnected()); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1994 | 1996 |
| 1995 // When creating an SSLClientSocket, it is allowed to pass in a | 1997 // When creating an SSLClientSocket, it is allowed to pass in a |
| 1996 // ClientSocketHandle that is not obtained from a client socket pool. | 1998 // ClientSocketHandle that is not obtained from a client socket pool. |
| 1997 // Here we verify that such a simple ClientSocketHandle, not associated with any | 1999 // Here we verify that such a simple ClientSocketHandle, not associated with any |
| 1998 // client socket pool, can be destroyed safely. | 2000 // client socket pool, can be destroyed safely. |
| 1999 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) { | 2001 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) { |
| 2000 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 2002 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 2001 | 2003 |
| 2002 TestCompletionCallback callback; | 2004 TestCompletionCallback callback; |
| 2003 std::unique_ptr<StreamSocket> transport( | 2005 std::unique_ptr<StreamSocket> transport( |
| 2004 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 2006 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 2005 int rv = callback.GetResult(transport->Connect(callback.callback())); | 2007 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 2006 EXPECT_THAT(rv, IsOk()); | 2008 EXPECT_THAT(rv, IsOk()); |
| 2007 | 2009 |
| 2008 std::unique_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle()); | 2010 std::unique_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle()); |
| 2009 socket_handle->SetSocket(std::move(transport)); | 2011 socket_handle->SetSocket(std::move(transport)); |
| 2010 | 2012 |
| 2011 std::unique_ptr<SSLClientSocket> sock(socket_factory_->CreateSSLClientSocket( | 2013 std::unique_ptr<SSLClientSocket> sock(socket_factory_->CreateSSLClientSocket( |
| 2012 std::move(socket_handle), spawned_test_server()->host_port_pair(), | 2014 std::move(socket_handle), spawned_test_server()->host_port_pair(), |
| 2013 SSLConfig(), context_)); | 2015 SSLConfig(), context_)); |
| 2014 | 2016 |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2516 } | 2518 } |
| 2517 | 2519 |
| 2518 // Tests that IsConnectedAndIdle treats a socket as idle even if a Write hasn't | 2520 // Tests that IsConnectedAndIdle treats a socket as idle even if a Write hasn't |
| 2519 // been flushed completely out of SSLClientSocket's internal buffers. This is a | 2521 // been flushed completely out of SSLClientSocket's internal buffers. This is a |
| 2520 // regression test for https://crbug.com/466147. | 2522 // regression test for https://crbug.com/466147. |
| 2521 TEST_F(SSLClientSocketTest, ReusableAfterWrite) { | 2523 TEST_F(SSLClientSocketTest, ReusableAfterWrite) { |
| 2522 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 2524 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 2523 | 2525 |
| 2524 TestCompletionCallback callback; | 2526 TestCompletionCallback callback; |
| 2525 std::unique_ptr<StreamSocket> real_transport( | 2527 std::unique_ptr<StreamSocket> real_transport( |
| 2526 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 2528 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 2527 std::unique_ptr<FakeBlockingStreamSocket> transport( | 2529 std::unique_ptr<FakeBlockingStreamSocket> transport( |
| 2528 new FakeBlockingStreamSocket(std::move(real_transport))); | 2530 new FakeBlockingStreamSocket(std::move(real_transport))); |
| 2529 FakeBlockingStreamSocket* raw_transport = transport.get(); | 2531 FakeBlockingStreamSocket* raw_transport = transport.get(); |
| 2530 ASSERT_THAT(callback.GetResult(transport->Connect(callback.callback())), | 2532 ASSERT_THAT(callback.GetResult(transport->Connect(callback.callback())), |
| 2531 IsOk()); | 2533 IsOk()); |
| 2532 | 2534 |
| 2533 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 2535 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 2534 std::move(transport), spawned_test_server()->host_port_pair(), | 2536 std::move(transport), spawned_test_server()->host_port_pair(), |
| 2535 SSLConfig())); | 2537 SSLConfig())); |
| 2536 ASSERT_THAT(callback.GetResult(sock->Connect(callback.callback())), IsOk()); | 2538 ASSERT_THAT(callback.GetResult(sock->Connect(callback.callback())), IsOk()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2573 | 2575 |
| 2574 // The next connection should resume. | 2576 // The next connection should resume. |
| 2575 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | 2577 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); |
| 2576 ASSERT_THAT(rv, IsOk()); | 2578 ASSERT_THAT(rv, IsOk()); |
| 2577 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); | 2579 ASSERT_TRUE(sock_->GetSSLInfo(&ssl_info)); |
| 2578 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type); | 2580 EXPECT_EQ(SSLInfo::HANDSHAKE_RESUME, ssl_info.handshake_type); |
| 2579 sock_.reset(); | 2581 sock_.reset(); |
| 2580 | 2582 |
| 2581 // Using a different HostPortPair uses a different session cache key. | 2583 // Using a different HostPortPair uses a different session cache key. |
| 2582 std::unique_ptr<StreamSocket> transport( | 2584 std::unique_ptr<StreamSocket> transport( |
| 2583 new TCPClientSocket(addr(), NULL, &log_, NetLog::Source())); | 2585 new TCPClientSocket(addr(), NULL, &log_, NetLogSource())); |
| 2584 TestCompletionCallback callback; | 2586 TestCompletionCallback callback; |
| 2585 ASSERT_THAT(callback.GetResult(transport->Connect(callback.callback())), | 2587 ASSERT_THAT(callback.GetResult(transport->Connect(callback.callback())), |
| 2586 IsOk()); | 2588 IsOk()); |
| 2587 std::unique_ptr<SSLClientSocket> sock = CreateSSLClientSocket( | 2589 std::unique_ptr<SSLClientSocket> sock = CreateSSLClientSocket( |
| 2588 std::move(transport), HostPortPair("example.com", 443), ssl_config); | 2590 std::move(transport), HostPortPair("example.com", 443), ssl_config); |
| 2589 ASSERT_THAT(callback.GetResult(sock->Connect(callback.callback())), IsOk()); | 2591 ASSERT_THAT(callback.GetResult(sock->Connect(callback.callback())), IsOk()); |
| 2590 ASSERT_TRUE(sock->GetSSLInfo(&ssl_info)); | 2592 ASSERT_TRUE(sock->GetSSLInfo(&ssl_info)); |
| 2591 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); | 2593 EXPECT_EQ(SSLInfo::HANDSHAKE_FULL, ssl_info.handshake_type); |
| 2592 sock.reset(); | 2594 sock.reset(); |
| 2593 | 2595 |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3456 EXPECT_TRUE(sock_->IsConnected()); | 3458 EXPECT_TRUE(sock_->IsConnected()); |
| 3457 } | 3459 } |
| 3458 | 3460 |
| 3459 // Test that handshake_failure alerts at the ServerHello are mapped to | 3461 // Test that handshake_failure alerts at the ServerHello are mapped to |
| 3460 // ERR_SSL_VERSION_OR_CIPHER_MISMATCH. | 3462 // ERR_SSL_VERSION_OR_CIPHER_MISMATCH. |
| 3461 TEST_F(SSLClientSocketTest, HandshakeFailureServerHello) { | 3463 TEST_F(SSLClientSocketTest, HandshakeFailureServerHello) { |
| 3462 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 3464 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 3463 | 3465 |
| 3464 TestCompletionCallback callback; | 3466 TestCompletionCallback callback; |
| 3465 std::unique_ptr<StreamSocket> real_transport( | 3467 std::unique_ptr<StreamSocket> real_transport( |
| 3466 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 3468 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 3467 std::unique_ptr<FakeBlockingStreamSocket> transport( | 3469 std::unique_ptr<FakeBlockingStreamSocket> transport( |
| 3468 new FakeBlockingStreamSocket(std::move(real_transport))); | 3470 new FakeBlockingStreamSocket(std::move(real_transport))); |
| 3469 FakeBlockingStreamSocket* raw_transport = transport.get(); | 3471 FakeBlockingStreamSocket* raw_transport = transport.get(); |
| 3470 int rv = callback.GetResult(transport->Connect(callback.callback())); | 3472 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 3471 ASSERT_THAT(rv, IsOk()); | 3473 ASSERT_THAT(rv, IsOk()); |
| 3472 | 3474 |
| 3473 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 3475 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 3474 std::move(transport), spawned_test_server()->host_port_pair(), | 3476 std::move(transport), spawned_test_server()->host_port_pair(), |
| 3475 SSLConfig())); | 3477 SSLConfig())); |
| 3476 | 3478 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3489 EXPECT_THAT(rv, IsError(ERR_SSL_VERSION_OR_CIPHER_MISMATCH)); | 3491 EXPECT_THAT(rv, IsError(ERR_SSL_VERSION_OR_CIPHER_MISMATCH)); |
| 3490 } | 3492 } |
| 3491 | 3493 |
| 3492 // Test that handshake_failure alerts after the ServerHello but without a | 3494 // Test that handshake_failure alerts after the ServerHello but without a |
| 3493 // CertificateRequest are mapped to ERR_SSL_PROTOCOL_ERROR. | 3495 // CertificateRequest are mapped to ERR_SSL_PROTOCOL_ERROR. |
| 3494 TEST_F(SSLClientSocketTest, HandshakeFailureNoClientCerts) { | 3496 TEST_F(SSLClientSocketTest, HandshakeFailureNoClientCerts) { |
| 3495 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 3497 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 3496 | 3498 |
| 3497 TestCompletionCallback callback; | 3499 TestCompletionCallback callback; |
| 3498 std::unique_ptr<StreamSocket> real_transport( | 3500 std::unique_ptr<StreamSocket> real_transport( |
| 3499 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 3501 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 3500 std::unique_ptr<FakeBlockingStreamSocket> transport( | 3502 std::unique_ptr<FakeBlockingStreamSocket> transport( |
| 3501 new FakeBlockingStreamSocket(std::move(real_transport))); | 3503 new FakeBlockingStreamSocket(std::move(real_transport))); |
| 3502 FakeBlockingStreamSocket* raw_transport = transport.get(); | 3504 FakeBlockingStreamSocket* raw_transport = transport.get(); |
| 3503 int rv = callback.GetResult(transport->Connect(callback.callback())); | 3505 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 3504 ASSERT_THAT(rv, IsOk()); | 3506 ASSERT_THAT(rv, IsOk()); |
| 3505 | 3507 |
| 3506 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 3508 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 3507 std::move(transport), spawned_test_server()->host_port_pair(), | 3509 std::move(transport), spawned_test_server()->host_port_pair(), |
| 3508 SSLConfig())); | 3510 SSLConfig())); |
| 3509 | 3511 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3537 // supplied. TLS does not have an alert for this case, so handshake_failure is | 3539 // supplied. TLS does not have an alert for this case, so handshake_failure is |
| 3538 // common. See https://crbug.com/646567. | 3540 // common. See https://crbug.com/646567. |
| 3539 TEST_F(SSLClientSocketTest, LateHandshakeFailureMissingClientCerts) { | 3541 TEST_F(SSLClientSocketTest, LateHandshakeFailureMissingClientCerts) { |
| 3540 // Request a client certificate. | 3542 // Request a client certificate. |
| 3541 SpawnedTestServer::SSLOptions ssl_options; | 3543 SpawnedTestServer::SSLOptions ssl_options; |
| 3542 ssl_options.request_client_certificate = true; | 3544 ssl_options.request_client_certificate = true; |
| 3543 ASSERT_TRUE(StartTestServer(ssl_options)); | 3545 ASSERT_TRUE(StartTestServer(ssl_options)); |
| 3544 | 3546 |
| 3545 TestCompletionCallback callback; | 3547 TestCompletionCallback callback; |
| 3546 std::unique_ptr<StreamSocket> real_transport( | 3548 std::unique_ptr<StreamSocket> real_transport( |
| 3547 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 3549 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 3548 std::unique_ptr<FakeBlockingStreamSocket> transport( | 3550 std::unique_ptr<FakeBlockingStreamSocket> transport( |
| 3549 new FakeBlockingStreamSocket(std::move(real_transport))); | 3551 new FakeBlockingStreamSocket(std::move(real_transport))); |
| 3550 FakeBlockingStreamSocket* raw_transport = transport.get(); | 3552 FakeBlockingStreamSocket* raw_transport = transport.get(); |
| 3551 int rv = callback.GetResult(transport->Connect(callback.callback())); | 3553 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 3552 ASSERT_THAT(rv, IsOk()); | 3554 ASSERT_THAT(rv, IsOk()); |
| 3553 | 3555 |
| 3554 // Send no client certificate. | 3556 // Send no client certificate. |
| 3555 SSLConfig config; | 3557 SSLConfig config; |
| 3556 config.send_client_cert = true; | 3558 config.send_client_cert = true; |
| 3557 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 3559 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3586 // ERR_SSL_PROTOCOL_ERROR if received after sending a client certificate. It is | 3588 // ERR_SSL_PROTOCOL_ERROR if received after sending a client certificate. It is |
| 3587 // assumed servers will send a more appropriate alert in this case. | 3589 // assumed servers will send a more appropriate alert in this case. |
| 3588 TEST_F(SSLClientSocketTest, LateHandshakeFailureSendClientCerts) { | 3590 TEST_F(SSLClientSocketTest, LateHandshakeFailureSendClientCerts) { |
| 3589 // Request a client certificate. | 3591 // Request a client certificate. |
| 3590 SpawnedTestServer::SSLOptions ssl_options; | 3592 SpawnedTestServer::SSLOptions ssl_options; |
| 3591 ssl_options.request_client_certificate = true; | 3593 ssl_options.request_client_certificate = true; |
| 3592 ASSERT_TRUE(StartTestServer(ssl_options)); | 3594 ASSERT_TRUE(StartTestServer(ssl_options)); |
| 3593 | 3595 |
| 3594 TestCompletionCallback callback; | 3596 TestCompletionCallback callback; |
| 3595 std::unique_ptr<StreamSocket> real_transport( | 3597 std::unique_ptr<StreamSocket> real_transport( |
| 3596 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 3598 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 3597 std::unique_ptr<FakeBlockingStreamSocket> transport( | 3599 std::unique_ptr<FakeBlockingStreamSocket> transport( |
| 3598 new FakeBlockingStreamSocket(std::move(real_transport))); | 3600 new FakeBlockingStreamSocket(std::move(real_transport))); |
| 3599 FakeBlockingStreamSocket* raw_transport = transport.get(); | 3601 FakeBlockingStreamSocket* raw_transport = transport.get(); |
| 3600 int rv = callback.GetResult(transport->Connect(callback.callback())); | 3602 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 3601 ASSERT_THAT(rv, IsOk()); | 3603 ASSERT_THAT(rv, IsOk()); |
| 3602 | 3604 |
| 3603 // Send a client certificate. | 3605 // Send a client certificate. |
| 3604 base::FilePath certs_dir = GetTestCertsDirectory(); | 3606 base::FilePath certs_dir = GetTestCertsDirectory(); |
| 3605 SSLConfig config; | 3607 SSLConfig config; |
| 3606 config.send_client_cert = true; | 3608 config.send_client_cert = true; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3636 } | 3638 } |
| 3637 | 3639 |
| 3638 // Test that access_denied alerts are mapped to ERR_SSL_PROTOCOL_ERROR if | 3640 // Test that access_denied alerts are mapped to ERR_SSL_PROTOCOL_ERROR if |
| 3639 // received on a connection not requesting client certificates. This is an | 3641 // received on a connection not requesting client certificates. This is an |
| 3640 // incorrect use of the alert but is common. See https://crbug.com/630883. | 3642 // incorrect use of the alert but is common. See https://crbug.com/630883. |
| 3641 TEST_F(SSLClientSocketTest, AccessDeniedNoClientCerts) { | 3643 TEST_F(SSLClientSocketTest, AccessDeniedNoClientCerts) { |
| 3642 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 3644 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
| 3643 | 3645 |
| 3644 TestCompletionCallback callback; | 3646 TestCompletionCallback callback; |
| 3645 std::unique_ptr<StreamSocket> real_transport( | 3647 std::unique_ptr<StreamSocket> real_transport( |
| 3646 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 3648 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 3647 std::unique_ptr<FakeBlockingStreamSocket> transport( | 3649 std::unique_ptr<FakeBlockingStreamSocket> transport( |
| 3648 new FakeBlockingStreamSocket(std::move(real_transport))); | 3650 new FakeBlockingStreamSocket(std::move(real_transport))); |
| 3649 FakeBlockingStreamSocket* raw_transport = transport.get(); | 3651 FakeBlockingStreamSocket* raw_transport = transport.get(); |
| 3650 int rv = callback.GetResult(transport->Connect(callback.callback())); | 3652 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 3651 ASSERT_THAT(rv, IsOk()); | 3653 ASSERT_THAT(rv, IsOk()); |
| 3652 | 3654 |
| 3653 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( | 3655 std::unique_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 3654 std::move(transport), spawned_test_server()->host_port_pair(), | 3656 std::move(transport), spawned_test_server()->host_port_pair(), |
| 3655 SSLConfig())); | 3657 SSLConfig())); |
| 3656 | 3658 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3682 // Test that access_denied alerts are mapped to ERR_BAD_SSL_CLIENT_AUTH_CERT if | 3684 // Test that access_denied alerts are mapped to ERR_BAD_SSL_CLIENT_AUTH_CERT if |
| 3683 // received on a connection requesting client certificates. | 3685 // received on a connection requesting client certificates. |
| 3684 TEST_F(SSLClientSocketTest, AccessDeniedClientCerts) { | 3686 TEST_F(SSLClientSocketTest, AccessDeniedClientCerts) { |
| 3685 // Request a client certificate. | 3687 // Request a client certificate. |
| 3686 SpawnedTestServer::SSLOptions ssl_options; | 3688 SpawnedTestServer::SSLOptions ssl_options; |
| 3687 ssl_options.request_client_certificate = true; | 3689 ssl_options.request_client_certificate = true; |
| 3688 ASSERT_TRUE(StartTestServer(ssl_options)); | 3690 ASSERT_TRUE(StartTestServer(ssl_options)); |
| 3689 | 3691 |
| 3690 TestCompletionCallback callback; | 3692 TestCompletionCallback callback; |
| 3691 std::unique_ptr<StreamSocket> real_transport( | 3693 std::unique_ptr<StreamSocket> real_transport( |
| 3692 new TCPClientSocket(addr(), NULL, NULL, NetLog::Source())); | 3694 new TCPClientSocket(addr(), NULL, NULL, NetLogSource())); |
| 3693 std::unique_ptr<FakeBlockingStreamSocket> transport( | 3695 std::unique_ptr<FakeBlockingStreamSocket> transport( |
| 3694 new FakeBlockingStreamSocket(std::move(real_transport))); | 3696 new FakeBlockingStreamSocket(std::move(real_transport))); |
| 3695 FakeBlockingStreamSocket* raw_transport = transport.get(); | 3697 FakeBlockingStreamSocket* raw_transport = transport.get(); |
| 3696 int rv = callback.GetResult(transport->Connect(callback.callback())); | 3698 int rv = callback.GetResult(transport->Connect(callback.callback())); |
| 3697 ASSERT_THAT(rv, IsOk()); | 3699 ASSERT_THAT(rv, IsOk()); |
| 3698 | 3700 |
| 3699 // Send a client certificate. | 3701 // Send a client certificate. |
| 3700 base::FilePath certs_dir = GetTestCertsDirectory(); | 3702 base::FilePath certs_dir = GetTestCertsDirectory(); |
| 3701 SSLConfig config; | 3703 SSLConfig config; |
| 3702 config.send_client_cert = true; | 3704 config.send_client_cert = true; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3725 // Replace it with an alert. | 3727 // Replace it with an alert. |
| 3726 raw_transport->ReplaceReadResult( | 3728 raw_transport->ReplaceReadResult( |
| 3727 FormatTLS12Alert(49 /* AlertDescription.access_denied */)); | 3729 FormatTLS12Alert(49 /* AlertDescription.access_denied */)); |
| 3728 raw_transport->UnblockReadResult(); | 3730 raw_transport->UnblockReadResult(); |
| 3729 | 3731 |
| 3730 rv = callback.GetResult(rv); | 3732 rv = callback.GetResult(rv); |
| 3731 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT)); | 3733 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT)); |
| 3732 } | 3734 } |
| 3733 | 3735 |
| 3734 } // namespace net | 3736 } // namespace net |
| OLD | NEW |