| 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 #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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 net::NetLog::PHASE_NONE); | 66 net::NetLog::PHASE_NONE); |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 TEST_F(SSLClientSocketTest, Connect) { | 69 TEST_F(SSLClientSocketTest, Connect) { |
| 70 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); | 70 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); |
| 71 ASSERT_TRUE(test_server.Start()); | 71 ASSERT_TRUE(test_server.Start()); |
| 72 | 72 |
| 73 net::AddressList addr; | 73 net::AddressList addr; |
| 74 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 74 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 75 | 75 |
| 76 TestOldCompletionCallback callback; | 76 net::TestCompletionCallback callback; |
| 77 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 77 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 78 net::StreamSocket* transport = new net::TCPClientSocket( | 78 net::StreamSocket* transport = new net::TCPClientSocket( |
| 79 addr, &log, net::NetLog::Source()); | 79 addr, &log, net::NetLog::Source()); |
| 80 int rv = transport->Connect(&callback); | 80 int rv = transport->Connect(callback.callback()); |
| 81 if (rv == net::ERR_IO_PENDING) | 81 if (rv == net::ERR_IO_PENDING) |
| 82 rv = callback.WaitForResult(); | 82 rv = callback.WaitForResult(); |
| 83 EXPECT_EQ(net::OK, rv); | 83 EXPECT_EQ(net::OK, rv); |
| 84 | 84 |
| 85 net::SSLClientSocketContext context; | 85 net::SSLClientSocketContext context; |
| 86 context.cert_verifier = cert_verifier_.get(); | 86 context.cert_verifier = cert_verifier_.get(); |
| 87 scoped_ptr<net::SSLClientSocket> sock( | 87 scoped_ptr<net::SSLClientSocket> sock( |
| 88 socket_factory_->CreateSSLClientSocket( | 88 socket_factory_->CreateSSLClientSocket( |
| 89 transport, test_server.host_port_pair(), kDefaultSSLConfig, | 89 transport, test_server.host_port_pair(), kDefaultSSLConfig, |
| 90 NULL, context)); | 90 NULL, context)); |
| 91 | 91 |
| 92 EXPECT_FALSE(sock->IsConnected()); | 92 EXPECT_FALSE(sock->IsConnected()); |
| 93 | 93 |
| 94 rv = sock->Connect(&callback); | 94 rv = sock->Connect(callback.callback()); |
| 95 | 95 |
| 96 net::CapturingNetLog::EntryList entries; | 96 net::CapturingNetLog::EntryList entries; |
| 97 log.GetEntries(&entries); | 97 log.GetEntries(&entries); |
| 98 EXPECT_TRUE(net::LogContainsBeginEvent( | 98 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 99 entries, 5, net::NetLog::TYPE_SSL_CONNECT)); | 99 entries, 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 100 if (rv == net::ERR_IO_PENDING) | 100 if (rv == net::ERR_IO_PENDING) |
| 101 rv = callback.WaitForResult(); | 101 rv = callback.WaitForResult(); |
| 102 EXPECT_EQ(net::OK, rv); | 102 EXPECT_EQ(net::OK, rv); |
| 103 EXPECT_TRUE(sock->IsConnected()); | 103 EXPECT_TRUE(sock->IsConnected()); |
| 104 log.GetEntries(&entries); | 104 log.GetEntries(&entries); |
| 105 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1)); | 105 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1)); |
| 106 | 106 |
| 107 sock->Disconnect(); | 107 sock->Disconnect(); |
| 108 EXPECT_FALSE(sock->IsConnected()); | 108 EXPECT_FALSE(sock->IsConnected()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 TEST_F(SSLClientSocketTest, ConnectExpired) { | 111 TEST_F(SSLClientSocketTest, ConnectExpired) { |
| 112 net::TestServer::HTTPSOptions https_options( | 112 net::TestServer::HTTPSOptions https_options( |
| 113 net::TestServer::HTTPSOptions::CERT_EXPIRED); | 113 net::TestServer::HTTPSOptions::CERT_EXPIRED); |
| 114 net::TestServer test_server(https_options, FilePath()); | 114 net::TestServer test_server(https_options, FilePath()); |
| 115 ASSERT_TRUE(test_server.Start()); | 115 ASSERT_TRUE(test_server.Start()); |
| 116 | 116 |
| 117 net::AddressList addr; | 117 net::AddressList addr; |
| 118 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 118 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 119 | 119 |
| 120 TestOldCompletionCallback callback; | 120 net::TestCompletionCallback callback; |
| 121 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 121 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 122 net::StreamSocket* transport = new net::TCPClientSocket( | 122 net::StreamSocket* transport = new net::TCPClientSocket( |
| 123 addr, &log, net::NetLog::Source()); | 123 addr, &log, net::NetLog::Source()); |
| 124 int rv = transport->Connect(&callback); | 124 int rv = transport->Connect(callback.callback()); |
| 125 if (rv == net::ERR_IO_PENDING) | 125 if (rv == net::ERR_IO_PENDING) |
| 126 rv = callback.WaitForResult(); | 126 rv = callback.WaitForResult(); |
| 127 EXPECT_EQ(net::OK, rv); | 127 EXPECT_EQ(net::OK, rv); |
| 128 | 128 |
| 129 scoped_ptr<net::SSLClientSocket> sock( | 129 scoped_ptr<net::SSLClientSocket> sock( |
| 130 CreateSSLClientSocket(transport, test_server.host_port_pair(), | 130 CreateSSLClientSocket(transport, test_server.host_port_pair(), |
| 131 kDefaultSSLConfig)); | 131 kDefaultSSLConfig)); |
| 132 | 132 |
| 133 EXPECT_FALSE(sock->IsConnected()); | 133 EXPECT_FALSE(sock->IsConnected()); |
| 134 | 134 |
| 135 rv = sock->Connect(&callback); | 135 rv = sock->Connect(callback.callback()); |
| 136 | 136 |
| 137 net::CapturingNetLog::EntryList entries; | 137 net::CapturingNetLog::EntryList entries; |
| 138 log.GetEntries(&entries); | 138 log.GetEntries(&entries); |
| 139 EXPECT_TRUE(net::LogContainsBeginEvent( | 139 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 140 entries, 5, net::NetLog::TYPE_SSL_CONNECT)); | 140 entries, 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 141 if (rv == net::ERR_IO_PENDING) | 141 if (rv == net::ERR_IO_PENDING) |
| 142 rv = callback.WaitForResult(); | 142 rv = callback.WaitForResult(); |
| 143 | 143 |
| 144 EXPECT_EQ(net::ERR_CERT_DATE_INVALID, rv); | 144 EXPECT_EQ(net::ERR_CERT_DATE_INVALID, rv); |
| 145 | 145 |
| 146 // Rather than testing whether or not the underlying socket is connected, | 146 // Rather than testing whether or not the underlying socket is connected, |
| 147 // test that the handshake has finished. This is because it may be | 147 // test that the handshake has finished. This is because it may be |
| 148 // desirable to disconnect the socket before showing a user prompt, since | 148 // desirable to disconnect the socket before showing a user prompt, since |
| 149 // the user may take indefinitely long to respond. | 149 // the user may take indefinitely long to respond. |
| 150 log.GetEntries(&entries); | 150 log.GetEntries(&entries); |
| 151 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1)); | 151 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 TEST_F(SSLClientSocketTest, ConnectMismatched) { | 154 TEST_F(SSLClientSocketTest, ConnectMismatched) { |
| 155 net::TestServer::HTTPSOptions https_options( | 155 net::TestServer::HTTPSOptions https_options( |
| 156 net::TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); | 156 net::TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); |
| 157 net::TestServer test_server(https_options, FilePath()); | 157 net::TestServer test_server(https_options, FilePath()); |
| 158 ASSERT_TRUE(test_server.Start()); | 158 ASSERT_TRUE(test_server.Start()); |
| 159 | 159 |
| 160 net::AddressList addr; | 160 net::AddressList addr; |
| 161 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 161 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 162 | 162 |
| 163 TestOldCompletionCallback callback; | 163 net::TestCompletionCallback callback; |
| 164 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 164 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 165 net::StreamSocket* transport = new net::TCPClientSocket( | 165 net::StreamSocket* transport = new net::TCPClientSocket( |
| 166 addr, &log, net::NetLog::Source()); | 166 addr, &log, net::NetLog::Source()); |
| 167 int rv = transport->Connect(&callback); | 167 int rv = transport->Connect(callback.callback()); |
| 168 if (rv == net::ERR_IO_PENDING) | 168 if (rv == net::ERR_IO_PENDING) |
| 169 rv = callback.WaitForResult(); | 169 rv = callback.WaitForResult(); |
| 170 EXPECT_EQ(net::OK, rv); | 170 EXPECT_EQ(net::OK, rv); |
| 171 | 171 |
| 172 scoped_ptr<net::SSLClientSocket> sock( | 172 scoped_ptr<net::SSLClientSocket> sock( |
| 173 CreateSSLClientSocket(transport, test_server.host_port_pair(), | 173 CreateSSLClientSocket(transport, test_server.host_port_pair(), |
| 174 kDefaultSSLConfig)); | 174 kDefaultSSLConfig)); |
| 175 | 175 |
| 176 EXPECT_FALSE(sock->IsConnected()); | 176 EXPECT_FALSE(sock->IsConnected()); |
| 177 | 177 |
| 178 rv = sock->Connect(&callback); | 178 rv = sock->Connect(callback.callback()); |
| 179 | 179 |
| 180 net::CapturingNetLog::EntryList entries; | 180 net::CapturingNetLog::EntryList entries; |
| 181 log.GetEntries(&entries); | 181 log.GetEntries(&entries); |
| 182 EXPECT_TRUE(net::LogContainsBeginEvent( | 182 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 183 entries, 5, net::NetLog::TYPE_SSL_CONNECT)); | 183 entries, 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 184 if (rv == net::ERR_IO_PENDING) | 184 if (rv == net::ERR_IO_PENDING) |
| 185 rv = callback.WaitForResult(); | 185 rv = callback.WaitForResult(); |
| 186 | 186 |
| 187 EXPECT_EQ(net::ERR_CERT_COMMON_NAME_INVALID, rv); | 187 EXPECT_EQ(net::ERR_CERT_COMMON_NAME_INVALID, rv); |
| 188 | 188 |
| 189 // Rather than testing whether or not the underlying socket is connected, | 189 // Rather than testing whether or not the underlying socket is connected, |
| 190 // test that the handshake has finished. This is because it may be | 190 // test that the handshake has finished. This is because it may be |
| 191 // desirable to disconnect the socket before showing a user prompt, since | 191 // desirable to disconnect the socket before showing a user prompt, since |
| 192 // the user may take indefinitely long to respond. | 192 // the user may take indefinitely long to respond. |
| 193 log.GetEntries(&entries); | 193 log.GetEntries(&entries); |
| 194 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1)); | 194 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1)); |
| 195 } | 195 } |
| 196 | 196 |
| 197 // Attempt to connect to a page which requests a client certificate. It should | 197 // Attempt to connect to a page which requests a client certificate. It should |
| 198 // return an error code on connect. | 198 // return an error code on connect. |
| 199 TEST_F(SSLClientSocketTest, ConnectClientAuthCertRequested) { | 199 TEST_F(SSLClientSocketTest, ConnectClientAuthCertRequested) { |
| 200 net::TestServer::HTTPSOptions https_options; | 200 net::TestServer::HTTPSOptions https_options; |
| 201 https_options.request_client_certificate = true; | 201 https_options.request_client_certificate = true; |
| 202 net::TestServer test_server(https_options, FilePath()); | 202 net::TestServer test_server(https_options, FilePath()); |
| 203 ASSERT_TRUE(test_server.Start()); | 203 ASSERT_TRUE(test_server.Start()); |
| 204 | 204 |
| 205 net::AddressList addr; | 205 net::AddressList addr; |
| 206 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 206 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 207 | 207 |
| 208 TestOldCompletionCallback callback; | 208 net::TestCompletionCallback callback; |
| 209 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 209 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 210 net::StreamSocket* transport = new net::TCPClientSocket( | 210 net::StreamSocket* transport = new net::TCPClientSocket( |
| 211 addr, &log, net::NetLog::Source()); | 211 addr, &log, net::NetLog::Source()); |
| 212 int rv = transport->Connect(&callback); | 212 int rv = transport->Connect(callback.callback()); |
| 213 if (rv == net::ERR_IO_PENDING) | 213 if (rv == net::ERR_IO_PENDING) |
| 214 rv = callback.WaitForResult(); | 214 rv = callback.WaitForResult(); |
| 215 EXPECT_EQ(net::OK, rv); | 215 EXPECT_EQ(net::OK, rv); |
| 216 | 216 |
| 217 scoped_ptr<net::SSLClientSocket> sock( | 217 scoped_ptr<net::SSLClientSocket> sock( |
| 218 CreateSSLClientSocket(transport, test_server.host_port_pair(), | 218 CreateSSLClientSocket(transport, test_server.host_port_pair(), |
| 219 kDefaultSSLConfig)); | 219 kDefaultSSLConfig)); |
| 220 | 220 |
| 221 EXPECT_FALSE(sock->IsConnected()); | 221 EXPECT_FALSE(sock->IsConnected()); |
| 222 | 222 |
| 223 rv = sock->Connect(&callback); | 223 rv = sock->Connect(callback.callback()); |
| 224 | 224 |
| 225 net::CapturingNetLog::EntryList entries; | 225 net::CapturingNetLog::EntryList entries; |
| 226 log.GetEntries(&entries); | 226 log.GetEntries(&entries); |
| 227 EXPECT_TRUE(net::LogContainsBeginEvent( | 227 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 228 entries, 5, net::NetLog::TYPE_SSL_CONNECT)); | 228 entries, 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 229 if (rv == net::ERR_IO_PENDING) | 229 if (rv == net::ERR_IO_PENDING) |
| 230 rv = callback.WaitForResult(); | 230 rv = callback.WaitForResult(); |
| 231 | 231 |
| 232 log.GetEntries(&entries); | 232 log.GetEntries(&entries); |
| 233 // Because we prematurely kill the handshake at CertificateRequest, | 233 // Because we prematurely kill the handshake at CertificateRequest, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 258 // TODO(davidben): Also test providing an actual certificate. | 258 // TODO(davidben): Also test providing an actual certificate. |
| 259 TEST_F(SSLClientSocketTest, ConnectClientAuthSendNullCert) { | 259 TEST_F(SSLClientSocketTest, ConnectClientAuthSendNullCert) { |
| 260 net::TestServer::HTTPSOptions https_options; | 260 net::TestServer::HTTPSOptions https_options; |
| 261 https_options.request_client_certificate = true; | 261 https_options.request_client_certificate = true; |
| 262 net::TestServer test_server(https_options, FilePath()); | 262 net::TestServer test_server(https_options, FilePath()); |
| 263 ASSERT_TRUE(test_server.Start()); | 263 ASSERT_TRUE(test_server.Start()); |
| 264 | 264 |
| 265 net::AddressList addr; | 265 net::AddressList addr; |
| 266 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 266 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 267 | 267 |
| 268 TestOldCompletionCallback callback; | 268 net::TestCompletionCallback callback; |
| 269 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 269 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 270 net::StreamSocket* transport = new net::TCPClientSocket( | 270 net::StreamSocket* transport = new net::TCPClientSocket( |
| 271 addr, &log, net::NetLog::Source()); | 271 addr, &log, net::NetLog::Source()); |
| 272 int rv = transport->Connect(&callback); | 272 int rv = transport->Connect(callback.callback()); |
| 273 if (rv == net::ERR_IO_PENDING) | 273 if (rv == net::ERR_IO_PENDING) |
| 274 rv = callback.WaitForResult(); | 274 rv = callback.WaitForResult(); |
| 275 EXPECT_EQ(net::OK, rv); | 275 EXPECT_EQ(net::OK, rv); |
| 276 | 276 |
| 277 net::SSLConfig ssl_config = kDefaultSSLConfig; | 277 net::SSLConfig ssl_config = kDefaultSSLConfig; |
| 278 ssl_config.send_client_cert = true; | 278 ssl_config.send_client_cert = true; |
| 279 ssl_config.client_cert = NULL; | 279 ssl_config.client_cert = NULL; |
| 280 | 280 |
| 281 scoped_ptr<net::SSLClientSocket> sock( | 281 scoped_ptr<net::SSLClientSocket> sock( |
| 282 CreateSSLClientSocket(transport, test_server.host_port_pair(), | 282 CreateSSLClientSocket(transport, test_server.host_port_pair(), |
| 283 ssl_config)); | 283 ssl_config)); |
| 284 | 284 |
| 285 EXPECT_FALSE(sock->IsConnected()); | 285 EXPECT_FALSE(sock->IsConnected()); |
| 286 | 286 |
| 287 // Our test server accepts certificate-less connections. | 287 // Our test server accepts certificate-less connections. |
| 288 // TODO(davidben): Add a test which requires them and verify the error. | 288 // TODO(davidben): Add a test which requires them and verify the error. |
| 289 rv = sock->Connect(&callback); | 289 rv = sock->Connect(callback.callback()); |
| 290 | 290 |
| 291 net::CapturingNetLog::EntryList entries; | 291 net::CapturingNetLog::EntryList entries; |
| 292 log.GetEntries(&entries); | 292 log.GetEntries(&entries); |
| 293 EXPECT_TRUE(net::LogContainsBeginEvent( | 293 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 294 entries, 5, net::NetLog::TYPE_SSL_CONNECT)); | 294 entries, 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 295 if (rv == net::ERR_IO_PENDING) | 295 if (rv == net::ERR_IO_PENDING) |
| 296 rv = callback.WaitForResult(); | 296 rv = callback.WaitForResult(); |
| 297 | 297 |
| 298 EXPECT_EQ(net::OK, rv); | 298 EXPECT_EQ(net::OK, rv); |
| 299 EXPECT_TRUE(sock->IsConnected()); | 299 EXPECT_TRUE(sock->IsConnected()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 316 // - Server closes the underlying TCP connection directly. | 316 // - Server closes the underlying TCP connection directly. |
| 317 // - Server sends data unexpectedly. | 317 // - Server sends data unexpectedly. |
| 318 | 318 |
| 319 TEST_F(SSLClientSocketTest, Read) { | 319 TEST_F(SSLClientSocketTest, Read) { |
| 320 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); | 320 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); |
| 321 ASSERT_TRUE(test_server.Start()); | 321 ASSERT_TRUE(test_server.Start()); |
| 322 | 322 |
| 323 net::AddressList addr; | 323 net::AddressList addr; |
| 324 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 324 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 325 | 325 |
| 326 TestOldCompletionCallback callback; | 326 net::TestCompletionCallback callback; |
| 327 net::StreamSocket* transport = new net::TCPClientSocket( | 327 net::StreamSocket* transport = new net::TCPClientSocket( |
| 328 addr, NULL, net::NetLog::Source()); | 328 addr, NULL, net::NetLog::Source()); |
| 329 int rv = transport->Connect(&callback); | 329 int rv = transport->Connect(callback.callback()); |
| 330 if (rv == net::ERR_IO_PENDING) | 330 if (rv == net::ERR_IO_PENDING) |
| 331 rv = callback.WaitForResult(); | 331 rv = callback.WaitForResult(); |
| 332 EXPECT_EQ(net::OK, rv); | 332 EXPECT_EQ(net::OK, rv); |
| 333 | 333 |
| 334 scoped_ptr<net::SSLClientSocket> sock( | 334 scoped_ptr<net::SSLClientSocket> sock( |
| 335 CreateSSLClientSocket(transport, test_server.host_port_pair(), | 335 CreateSSLClientSocket(transport, test_server.host_port_pair(), |
| 336 kDefaultSSLConfig)); | 336 kDefaultSSLConfig)); |
| 337 | 337 |
| 338 rv = sock->Connect(&callback); | 338 rv = sock->Connect(callback.callback()); |
| 339 if (rv == net::ERR_IO_PENDING) | 339 if (rv == net::ERR_IO_PENDING) |
| 340 rv = callback.WaitForResult(); | 340 rv = callback.WaitForResult(); |
| 341 EXPECT_EQ(net::OK, rv); | 341 EXPECT_EQ(net::OK, rv); |
| 342 EXPECT_TRUE(sock->IsConnected()); | 342 EXPECT_TRUE(sock->IsConnected()); |
| 343 | 343 |
| 344 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 344 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
| 345 scoped_refptr<net::IOBuffer> request_buffer( | 345 scoped_refptr<net::IOBuffer> request_buffer( |
| 346 new net::IOBuffer(arraysize(request_text) - 1)); | 346 new net::IOBuffer(arraysize(request_text) - 1)); |
| 347 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); | 347 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); |
| 348 | 348 |
| 349 rv = sock->Write(request_buffer, arraysize(request_text) - 1, &callback); | 349 rv = sock->Write(request_buffer, arraysize(request_text) - 1, |
| 350 callback.callback()); |
| 350 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 351 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
| 351 | 352 |
| 352 if (rv == net::ERR_IO_PENDING) | 353 if (rv == net::ERR_IO_PENDING) |
| 353 rv = callback.WaitForResult(); | 354 rv = callback.WaitForResult(); |
| 354 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); | 355 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); |
| 355 | 356 |
| 356 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); | 357 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); |
| 357 for (;;) { | 358 for (;;) { |
| 358 rv = sock->Read(buf, 4096, &callback); | 359 rv = sock->Read(buf, 4096, callback.callback()); |
| 359 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 360 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
| 360 | 361 |
| 361 if (rv == net::ERR_IO_PENDING) | 362 if (rv == net::ERR_IO_PENDING) |
| 362 rv = callback.WaitForResult(); | 363 rv = callback.WaitForResult(); |
| 363 | 364 |
| 364 EXPECT_GE(rv, 0); | 365 EXPECT_GE(rv, 0); |
| 365 if (rv <= 0) | 366 if (rv <= 0) |
| 366 break; | 367 break; |
| 367 } | 368 } |
| 368 } | 369 } |
| 369 | 370 |
| 370 // Test the full duplex mode, with Read and Write pending at the same time. | 371 // Test the full duplex mode, with Read and Write pending at the same time. |
| 371 // This test also serves as a regression test for http://crbug.com/29815. | 372 // This test also serves as a regression test for http://crbug.com/29815. |
| 372 TEST_F(SSLClientSocketTest, Read_FullDuplex) { | 373 TEST_F(SSLClientSocketTest, Read_FullDuplex) { |
| 373 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); | 374 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); |
| 374 ASSERT_TRUE(test_server.Start()); | 375 ASSERT_TRUE(test_server.Start()); |
| 375 | 376 |
| 376 net::AddressList addr; | 377 net::AddressList addr; |
| 377 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 378 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 378 | 379 |
| 379 TestOldCompletionCallback callback; // Used for everything except Write. | 380 net::TestCompletionCallback callback; // Used for everything except Write. |
| 380 TestOldCompletionCallback callback2; // Used for Write only. | |
| 381 | 381 |
| 382 net::StreamSocket* transport = new net::TCPClientSocket( | 382 net::StreamSocket* transport = new net::TCPClientSocket( |
| 383 addr, NULL, net::NetLog::Source()); | 383 addr, NULL, net::NetLog::Source()); |
| 384 int rv = transport->Connect(&callback); | 384 int rv = transport->Connect(callback.callback()); |
| 385 if (rv == net::ERR_IO_PENDING) | 385 if (rv == net::ERR_IO_PENDING) |
| 386 rv = callback.WaitForResult(); | 386 rv = callback.WaitForResult(); |
| 387 EXPECT_EQ(net::OK, rv); | 387 EXPECT_EQ(net::OK, rv); |
| 388 | 388 |
| 389 net::SSLClientSocketContext context; | 389 net::SSLClientSocketContext context; |
| 390 context.cert_verifier = cert_verifier_.get(); | 390 context.cert_verifier = cert_verifier_.get(); |
| 391 scoped_ptr<net::SSLClientSocket> sock( | 391 scoped_ptr<net::SSLClientSocket> sock( |
| 392 socket_factory_->CreateSSLClientSocket( | 392 socket_factory_->CreateSSLClientSocket( |
| 393 transport, test_server.host_port_pair(), kDefaultSSLConfig, | 393 transport, test_server.host_port_pair(), kDefaultSSLConfig, |
| 394 NULL, context)); | 394 NULL, context)); |
| 395 | 395 |
| 396 rv = sock->Connect(&callback); | 396 rv = sock->Connect(callback.callback()); |
| 397 if (rv == net::ERR_IO_PENDING) | 397 if (rv == net::ERR_IO_PENDING) |
| 398 rv = callback.WaitForResult(); | 398 rv = callback.WaitForResult(); |
| 399 EXPECT_EQ(net::OK, rv); | 399 EXPECT_EQ(net::OK, rv); |
| 400 EXPECT_TRUE(sock->IsConnected()); | 400 EXPECT_TRUE(sock->IsConnected()); |
| 401 | 401 |
| 402 // Issue a "hanging" Read first. | 402 // Issue a "hanging" Read first. |
| 403 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); | 403 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); |
| 404 rv = sock->Read(buf, 4096, &callback); | 404 rv = sock->Read(buf, 4096, callback.callback()); |
| 405 // We haven't written the request, so there should be no response yet. | 405 // We haven't written the request, so there should be no response yet. |
| 406 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 406 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 407 | 407 |
| 408 // Write the request. | 408 // Write the request. |
| 409 // The request is padded with a User-Agent header to a size that causes the | 409 // The request is padded with a User-Agent header to a size that causes the |
| 410 // memio circular buffer (4k bytes) in SSLClientSocketNSS to wrap around. | 410 // memio circular buffer (4k bytes) in SSLClientSocketNSS to wrap around. |
| 411 // This tests the fix for http://crbug.com/29815. | 411 // This tests the fix for http://crbug.com/29815. |
| 412 std::string request_text = "GET / HTTP/1.1\r\nUser-Agent: long browser name "; | 412 std::string request_text = "GET / HTTP/1.1\r\nUser-Agent: long browser name "; |
| 413 for (int i = 0; i < 3770; ++i) | 413 for (int i = 0; i < 3770; ++i) |
| 414 request_text.push_back('*'); | 414 request_text.push_back('*'); |
| 415 request_text.append("\r\n\r\n"); | 415 request_text.append("\r\n\r\n"); |
| 416 scoped_refptr<net::IOBuffer> request_buffer( | 416 scoped_refptr<net::IOBuffer> request_buffer( |
| 417 new net::StringIOBuffer(request_text)); | 417 new net::StringIOBuffer(request_text)); |
| 418 | 418 |
| 419 rv = sock->Write(request_buffer, request_text.size(), &callback2); | 419 net::TestCompletionCallback callback2; // Used for Write only. |
| 420 rv = sock->Write(request_buffer, request_text.size(), callback2.callback()); |
| 420 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 421 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
| 421 | 422 |
| 422 if (rv == net::ERR_IO_PENDING) | 423 if (rv == net::ERR_IO_PENDING) |
| 423 rv = callback2.WaitForResult(); | 424 rv = callback2.WaitForResult(); |
| 424 EXPECT_EQ(static_cast<int>(request_text.size()), rv); | 425 EXPECT_EQ(static_cast<int>(request_text.size()), rv); |
| 425 | 426 |
| 426 // Now get the Read result. | 427 // Now get the Read result. |
| 427 rv = callback.WaitForResult(); | 428 rv = callback.WaitForResult(); |
| 428 EXPECT_GT(rv, 0); | 429 EXPECT_GT(rv, 0); |
| 429 } | 430 } |
| 430 | 431 |
| 431 TEST_F(SSLClientSocketTest, Read_SmallChunks) { | 432 TEST_F(SSLClientSocketTest, Read_SmallChunks) { |
| 432 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); | 433 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); |
| 433 ASSERT_TRUE(test_server.Start()); | 434 ASSERT_TRUE(test_server.Start()); |
| 434 | 435 |
| 435 net::AddressList addr; | 436 net::AddressList addr; |
| 436 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 437 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 437 | 438 |
| 438 TestOldCompletionCallback callback; | 439 net::TestCompletionCallback callback; |
| 439 net::StreamSocket* transport = new net::TCPClientSocket( | 440 net::StreamSocket* transport = new net::TCPClientSocket( |
| 440 addr, NULL, net::NetLog::Source()); | 441 addr, NULL, net::NetLog::Source()); |
| 441 int rv = transport->Connect(&callback); | 442 int rv = transport->Connect(callback.callback()); |
| 442 if (rv == net::ERR_IO_PENDING) | 443 if (rv == net::ERR_IO_PENDING) |
| 443 rv = callback.WaitForResult(); | 444 rv = callback.WaitForResult(); |
| 444 EXPECT_EQ(net::OK, rv); | 445 EXPECT_EQ(net::OK, rv); |
| 445 | 446 |
| 446 scoped_ptr<net::SSLClientSocket> sock( | 447 scoped_ptr<net::SSLClientSocket> sock( |
| 447 CreateSSLClientSocket(transport, test_server.host_port_pair(), | 448 CreateSSLClientSocket(transport, test_server.host_port_pair(), |
| 448 kDefaultSSLConfig)); | 449 kDefaultSSLConfig)); |
| 449 | 450 |
| 450 rv = sock->Connect(&callback); | 451 rv = sock->Connect(callback.callback()); |
| 451 if (rv == net::ERR_IO_PENDING) | 452 if (rv == net::ERR_IO_PENDING) |
| 452 rv = callback.WaitForResult(); | 453 rv = callback.WaitForResult(); |
| 453 EXPECT_EQ(net::OK, rv); | 454 EXPECT_EQ(net::OK, rv); |
| 454 | 455 |
| 455 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 456 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
| 456 scoped_refptr<net::IOBuffer> request_buffer( | 457 scoped_refptr<net::IOBuffer> request_buffer( |
| 457 new net::IOBuffer(arraysize(request_text) - 1)); | 458 new net::IOBuffer(arraysize(request_text) - 1)); |
| 458 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); | 459 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); |
| 459 | 460 |
| 460 rv = sock->Write(request_buffer, arraysize(request_text) - 1, &callback); | 461 rv = sock->Write(request_buffer, arraysize(request_text) - 1, |
| 462 callback.callback()); |
| 461 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 463 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
| 462 | 464 |
| 463 if (rv == net::ERR_IO_PENDING) | 465 if (rv == net::ERR_IO_PENDING) |
| 464 rv = callback.WaitForResult(); | 466 rv = callback.WaitForResult(); |
| 465 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); | 467 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); |
| 466 | 468 |
| 467 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(1)); | 469 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(1)); |
| 468 for (;;) { | 470 for (;;) { |
| 469 rv = sock->Read(buf, 1, &callback); | 471 rv = sock->Read(buf, 1, callback.callback()); |
| 470 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 472 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
| 471 | 473 |
| 472 if (rv == net::ERR_IO_PENDING) | 474 if (rv == net::ERR_IO_PENDING) |
| 473 rv = callback.WaitForResult(); | 475 rv = callback.WaitForResult(); |
| 474 | 476 |
| 475 EXPECT_GE(rv, 0); | 477 EXPECT_GE(rv, 0); |
| 476 if (rv <= 0) | 478 if (rv <= 0) |
| 477 break; | 479 break; |
| 478 } | 480 } |
| 479 } | 481 } |
| 480 | 482 |
| 481 TEST_F(SSLClientSocketTest, Read_Interrupted) { | 483 TEST_F(SSLClientSocketTest, Read_Interrupted) { |
| 482 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); | 484 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); |
| 483 ASSERT_TRUE(test_server.Start()); | 485 ASSERT_TRUE(test_server.Start()); |
| 484 | 486 |
| 485 net::AddressList addr; | 487 net::AddressList addr; |
| 486 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 488 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 487 | 489 |
| 488 TestOldCompletionCallback callback; | 490 net::TestCompletionCallback callback; |
| 489 net::StreamSocket* transport = new net::TCPClientSocket( | 491 net::StreamSocket* transport = new net::TCPClientSocket( |
| 490 addr, NULL, net::NetLog::Source()); | 492 addr, NULL, net::NetLog::Source()); |
| 491 int rv = transport->Connect(&callback); | 493 int rv = transport->Connect(callback.callback()); |
| 492 if (rv == net::ERR_IO_PENDING) | 494 if (rv == net::ERR_IO_PENDING) |
| 493 rv = callback.WaitForResult(); | 495 rv = callback.WaitForResult(); |
| 494 EXPECT_EQ(net::OK, rv); | 496 EXPECT_EQ(net::OK, rv); |
| 495 | 497 |
| 496 scoped_ptr<net::SSLClientSocket> sock( | 498 scoped_ptr<net::SSLClientSocket> sock( |
| 497 CreateSSLClientSocket(transport, test_server.host_port_pair(), | 499 CreateSSLClientSocket(transport, test_server.host_port_pair(), |
| 498 kDefaultSSLConfig)); | 500 kDefaultSSLConfig)); |
| 499 | 501 |
| 500 rv = sock->Connect(&callback); | 502 rv = sock->Connect(callback.callback()); |
| 501 if (rv == net::ERR_IO_PENDING) | 503 if (rv == net::ERR_IO_PENDING) |
| 502 rv = callback.WaitForResult(); | 504 rv = callback.WaitForResult(); |
| 503 EXPECT_EQ(net::OK, rv); | 505 EXPECT_EQ(net::OK, rv); |
| 504 | 506 |
| 505 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 507 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
| 506 scoped_refptr<net::IOBuffer> request_buffer( | 508 scoped_refptr<net::IOBuffer> request_buffer( |
| 507 new net::IOBuffer(arraysize(request_text) - 1)); | 509 new net::IOBuffer(arraysize(request_text) - 1)); |
| 508 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); | 510 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); |
| 509 | 511 |
| 510 rv = sock->Write(request_buffer, arraysize(request_text) - 1, &callback); | 512 rv = sock->Write(request_buffer, arraysize(request_text) - 1, |
| 513 callback.callback()); |
| 511 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 514 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
| 512 | 515 |
| 513 if (rv == net::ERR_IO_PENDING) | 516 if (rv == net::ERR_IO_PENDING) |
| 514 rv = callback.WaitForResult(); | 517 rv = callback.WaitForResult(); |
| 515 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); | 518 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); |
| 516 | 519 |
| 517 // Do a partial read and then exit. This test should not crash! | 520 // Do a partial read and then exit. This test should not crash! |
| 518 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(512)); | 521 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(512)); |
| 519 rv = sock->Read(buf, 512, &callback); | 522 rv = sock->Read(buf, 512, callback.callback()); |
| 520 EXPECT_TRUE(rv > 0 || rv == net::ERR_IO_PENDING); | 523 EXPECT_TRUE(rv > 0 || rv == net::ERR_IO_PENDING); |
| 521 | 524 |
| 522 if (rv == net::ERR_IO_PENDING) | 525 if (rv == net::ERR_IO_PENDING) |
| 523 rv = callback.WaitForResult(); | 526 rv = callback.WaitForResult(); |
| 524 | 527 |
| 525 EXPECT_GT(rv, 0); | 528 EXPECT_GT(rv, 0); |
| 526 } | 529 } |
| 527 | 530 |
| 528 TEST_F(SSLClientSocketTest, Read_FullLogging) { | 531 TEST_F(SSLClientSocketTest, Read_FullLogging) { |
| 529 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); | 532 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); |
| 530 ASSERT_TRUE(test_server.Start()); | 533 ASSERT_TRUE(test_server.Start()); |
| 531 | 534 |
| 532 net::AddressList addr; | 535 net::AddressList addr; |
| 533 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 536 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 534 | 537 |
| 535 TestOldCompletionCallback callback; | 538 net::TestCompletionCallback callback; |
| 536 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 539 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 537 log.SetLogLevel(net::NetLog::LOG_ALL); | 540 log.SetLogLevel(net::NetLog::LOG_ALL); |
| 538 net::StreamSocket* transport = new net::TCPClientSocket( | 541 net::StreamSocket* transport = new net::TCPClientSocket( |
| 539 addr, &log, net::NetLog::Source()); | 542 addr, &log, net::NetLog::Source()); |
| 540 int rv = transport->Connect(&callback); | 543 int rv = transport->Connect(callback.callback()); |
| 541 if (rv == net::ERR_IO_PENDING) | 544 if (rv == net::ERR_IO_PENDING) |
| 542 rv = callback.WaitForResult(); | 545 rv = callback.WaitForResult(); |
| 543 EXPECT_EQ(net::OK, rv); | 546 EXPECT_EQ(net::OK, rv); |
| 544 | 547 |
| 545 scoped_ptr<net::SSLClientSocket> sock( | 548 scoped_ptr<net::SSLClientSocket> sock( |
| 546 CreateSSLClientSocket(transport, test_server.host_port_pair(), | 549 CreateSSLClientSocket(transport, test_server.host_port_pair(), |
| 547 kDefaultSSLConfig)); | 550 kDefaultSSLConfig)); |
| 548 | 551 |
| 549 rv = sock->Connect(&callback); | 552 rv = sock->Connect(callback.callback()); |
| 550 if (rv == net::ERR_IO_PENDING) | 553 if (rv == net::ERR_IO_PENDING) |
| 551 rv = callback.WaitForResult(); | 554 rv = callback.WaitForResult(); |
| 552 EXPECT_EQ(net::OK, rv); | 555 EXPECT_EQ(net::OK, rv); |
| 553 EXPECT_TRUE(sock->IsConnected()); | 556 EXPECT_TRUE(sock->IsConnected()); |
| 554 | 557 |
| 555 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 558 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
| 556 scoped_refptr<net::IOBuffer> request_buffer( | 559 scoped_refptr<net::IOBuffer> request_buffer( |
| 557 new net::IOBuffer(arraysize(request_text) - 1)); | 560 new net::IOBuffer(arraysize(request_text) - 1)); |
| 558 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); | 561 memcpy(request_buffer->data(), request_text, arraysize(request_text) - 1); |
| 559 | 562 |
| 560 rv = sock->Write(request_buffer, arraysize(request_text) - 1, &callback); | 563 rv = sock->Write(request_buffer, arraysize(request_text) - 1, |
| 564 callback.callback()); |
| 561 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 565 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
| 562 | 566 |
| 563 if (rv == net::ERR_IO_PENDING) | 567 if (rv == net::ERR_IO_PENDING) |
| 564 rv = callback.WaitForResult(); | 568 rv = callback.WaitForResult(); |
| 565 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); | 569 EXPECT_EQ(static_cast<int>(arraysize(request_text) - 1), rv); |
| 566 | 570 |
| 567 net::CapturingNetLog::EntryList entries; | 571 net::CapturingNetLog::EntryList entries; |
| 568 log.GetEntries(&entries); | 572 log.GetEntries(&entries); |
| 569 size_t last_index = net::ExpectLogContainsSomewhereAfter( | 573 size_t last_index = net::ExpectLogContainsSomewhereAfter( |
| 570 entries, 5, net::NetLog::TYPE_SSL_SOCKET_BYTES_SENT, | 574 entries, 5, net::NetLog::TYPE_SSL_SOCKET_BYTES_SENT, |
| 571 net::NetLog::PHASE_NONE); | 575 net::NetLog::PHASE_NONE); |
| 572 | 576 |
| 573 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); | 577 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(4096)); |
| 574 for (;;) { | 578 for (;;) { |
| 575 rv = sock->Read(buf, 4096, &callback); | 579 rv = sock->Read(buf, 4096, callback.callback()); |
| 576 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 580 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
| 577 | 581 |
| 578 if (rv == net::ERR_IO_PENDING) | 582 if (rv == net::ERR_IO_PENDING) |
| 579 rv = callback.WaitForResult(); | 583 rv = callback.WaitForResult(); |
| 580 | 584 |
| 581 EXPECT_GE(rv, 0); | 585 EXPECT_GE(rv, 0); |
| 582 if (rv <= 0) | 586 if (rv <= 0) |
| 583 break; | 587 break; |
| 584 | 588 |
| 585 log.GetEntries(&entries); | 589 log.GetEntries(&entries); |
| 586 last_index = net::ExpectLogContainsSomewhereAfter( | 590 last_index = net::ExpectLogContainsSomewhereAfter( |
| 587 entries, last_index + 1, net::NetLog::TYPE_SSL_SOCKET_BYTES_RECEIVED, | 591 entries, last_index + 1, net::NetLog::TYPE_SSL_SOCKET_BYTES_RECEIVED, |
| 588 net::NetLog::PHASE_NONE); | 592 net::NetLog::PHASE_NONE); |
| 589 } | 593 } |
| 590 } | 594 } |
| 591 | 595 |
| 592 // Regression test for http://crbug.com/42538 | 596 // Regression test for http://crbug.com/42538 |
| 593 TEST_F(SSLClientSocketTest, PrematureApplicationData) { | 597 TEST_F(SSLClientSocketTest, PrematureApplicationData) { |
| 594 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); | 598 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); |
| 595 ASSERT_TRUE(test_server.Start()); | 599 ASSERT_TRUE(test_server.Start()); |
| 596 | 600 |
| 597 net::AddressList addr; | 601 net::AddressList addr; |
| 598 TestOldCompletionCallback callback; | 602 net::TestCompletionCallback callback; |
| 599 | 603 |
| 600 static const unsigned char application_data[] = { | 604 static const unsigned char application_data[] = { |
| 601 0x17, 0x03, 0x01, 0x00, 0x4a, 0x02, 0x00, 0x00, 0x46, 0x03, 0x01, 0x4b, | 605 0x17, 0x03, 0x01, 0x00, 0x4a, 0x02, 0x00, 0x00, 0x46, 0x03, 0x01, 0x4b, |
| 602 0xc2, 0xf8, 0xb2, 0xc1, 0x56, 0x42, 0xb9, 0x57, 0x7f, 0xde, 0x87, 0x46, | 606 0xc2, 0xf8, 0xb2, 0xc1, 0x56, 0x42, 0xb9, 0x57, 0x7f, 0xde, 0x87, 0x46, |
| 603 0xf7, 0xa3, 0x52, 0x42, 0x21, 0xf0, 0x13, 0x1c, 0x9c, 0x83, 0x88, 0xd6, | 607 0xf7, 0xa3, 0x52, 0x42, 0x21, 0xf0, 0x13, 0x1c, 0x9c, 0x83, 0x88, 0xd6, |
| 604 0x93, 0x0c, 0xf6, 0x36, 0x30, 0x05, 0x7e, 0x20, 0xb5, 0xb5, 0x73, 0x36, | 608 0x93, 0x0c, 0xf6, 0x36, 0x30, 0x05, 0x7e, 0x20, 0xb5, 0xb5, 0x73, 0x36, |
| 605 0x53, 0x83, 0x0a, 0xfc, 0x17, 0x63, 0xbf, 0xa0, 0xe4, 0x42, 0x90, 0x0d, | 609 0x53, 0x83, 0x0a, 0xfc, 0x17, 0x63, 0xbf, 0xa0, 0xe4, 0x42, 0x90, 0x0d, |
| 606 0x2f, 0x18, 0x6d, 0x20, 0xd8, 0x36, 0x3f, 0xfc, 0xe6, 0x01, 0xfa, 0x0f, | 610 0x2f, 0x18, 0x6d, 0x20, 0xd8, 0x36, 0x3f, 0xfc, 0xe6, 0x01, 0xfa, 0x0f, |
| 607 0xa5, 0x75, 0x7f, 0x09, 0x00, 0x04, 0x00, 0x16, 0x03, 0x01, 0x11, 0x57, | 611 0xa5, 0x75, 0x7f, 0x09, 0x00, 0x04, 0x00, 0x16, 0x03, 0x01, 0x11, 0x57, |
| 608 0x0b, 0x00, 0x11, 0x53, 0x00, 0x11, 0x50, 0x00, 0x06, 0x22, 0x30, 0x82, | 612 0x0b, 0x00, 0x11, 0x53, 0x00, 0x11, 0x50, 0x00, 0x06, 0x22, 0x30, 0x82, |
| 609 0x06, 0x1e, 0x30, 0x82, 0x05, 0x06, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, | 613 0x06, 0x1e, 0x30, 0x82, 0x05, 0x06, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, |
| 610 0x0a | 614 0x0a |
| 611 }; | 615 }; |
| 612 | 616 |
| 613 // All reads and writes complete synchronously (async=false). | 617 // All reads and writes complete synchronously (async=false). |
| 614 net::MockRead data_reads[] = { | 618 net::MockRead data_reads[] = { |
| 615 net::MockRead(false, reinterpret_cast<const char*>(application_data), | 619 net::MockRead(false, reinterpret_cast<const char*>(application_data), |
| 616 arraysize(application_data)), | 620 arraysize(application_data)), |
| 617 net::MockRead(false, net::OK), | 621 net::MockRead(false, net::OK), |
| 618 }; | 622 }; |
| 619 | 623 |
| 620 net::StaticSocketDataProvider data(data_reads, arraysize(data_reads), | 624 net::StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 621 NULL, 0); | 625 NULL, 0); |
| 622 | 626 |
| 623 net::StreamSocket* transport = | 627 net::StreamSocket* transport = |
| 624 new net::MockTCPClientSocket(addr, NULL, &data); | 628 new net::MockTCPClientSocket(addr, NULL, &data); |
| 625 int rv = transport->Connect(&callback); | 629 int rv = transport->Connect(callback.callback()); |
| 626 if (rv == net::ERR_IO_PENDING) | 630 if (rv == net::ERR_IO_PENDING) |
| 627 rv = callback.WaitForResult(); | 631 rv = callback.WaitForResult(); |
| 628 EXPECT_EQ(net::OK, rv); | 632 EXPECT_EQ(net::OK, rv); |
| 629 | 633 |
| 630 scoped_ptr<net::SSLClientSocket> sock( | 634 scoped_ptr<net::SSLClientSocket> sock( |
| 631 CreateSSLClientSocket(transport, test_server.host_port_pair(), | 635 CreateSSLClientSocket(transport, test_server.host_port_pair(), |
| 632 kDefaultSSLConfig)); | 636 kDefaultSSLConfig)); |
| 633 | 637 |
| 634 rv = sock->Connect(&callback); | 638 rv = sock->Connect(callback.callback()); |
| 635 EXPECT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); | 639 EXPECT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 636 } | 640 } |
| 637 | 641 |
| 638 // TODO(rsleevi): Not implemented for Schannel. As Schannel is only used when | 642 // TODO(rsleevi): Not implemented for Schannel. As Schannel is only used when |
| 639 // performing client authentication, it will not be tested here. | 643 // performing client authentication, it will not be tested here. |
| 640 TEST_F(SSLClientSocketTest, CipherSuiteDisables) { | 644 TEST_F(SSLClientSocketTest, CipherSuiteDisables) { |
| 641 // Rather than exhaustively disabling every RC4 ciphersuite defined at | 645 // Rather than exhaustively disabling every RC4 ciphersuite defined at |
| 642 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml, | 646 // http://www.iana.org/assignments/tls-parameters/tls-parameters.xml, |
| 643 // only disabling those cipher suites that the test server actually | 647 // only disabling those cipher suites that the test server actually |
| 644 // implements. | 648 // implements. |
| 645 const uint16 kCiphersToDisable[] = { | 649 const uint16 kCiphersToDisable[] = { |
| 646 0x0005, // TLS_RSA_WITH_RC4_128_SHA | 650 0x0005, // TLS_RSA_WITH_RC4_128_SHA |
| 647 }; | 651 }; |
| 648 | 652 |
| 649 net::TestServer::HTTPSOptions https_options; | 653 net::TestServer::HTTPSOptions https_options; |
| 650 // Enable only RC4 on the test server. | 654 // Enable only RC4 on the test server. |
| 651 https_options.bulk_ciphers = | 655 https_options.bulk_ciphers = |
| 652 net::TestServer::HTTPSOptions::BULK_CIPHER_RC4; | 656 net::TestServer::HTTPSOptions::BULK_CIPHER_RC4; |
| 653 net::TestServer test_server(https_options, FilePath()); | 657 net::TestServer test_server(https_options, FilePath()); |
| 654 ASSERT_TRUE(test_server.Start()); | 658 ASSERT_TRUE(test_server.Start()); |
| 655 | 659 |
| 656 net::AddressList addr; | 660 net::AddressList addr; |
| 657 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 661 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 658 | 662 |
| 659 TestOldCompletionCallback callback; | 663 net::TestCompletionCallback callback; |
| 660 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 664 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 661 net::StreamSocket* transport = new net::TCPClientSocket( | 665 net::StreamSocket* transport = new net::TCPClientSocket( |
| 662 addr, &log, net::NetLog::Source()); | 666 addr, &log, net::NetLog::Source()); |
| 663 int rv = transport->Connect(&callback); | 667 int rv = transport->Connect(callback.callback()); |
| 664 if (rv == net::ERR_IO_PENDING) | 668 if (rv == net::ERR_IO_PENDING) |
| 665 rv = callback.WaitForResult(); | 669 rv = callback.WaitForResult(); |
| 666 EXPECT_EQ(net::OK, rv); | 670 EXPECT_EQ(net::OK, rv); |
| 667 | 671 |
| 668 net::SSLConfig ssl_config; | 672 net::SSLConfig ssl_config; |
| 669 for (size_t i = 0; i < arraysize(kCiphersToDisable); ++i) | 673 for (size_t i = 0; i < arraysize(kCiphersToDisable); ++i) |
| 670 ssl_config.disabled_cipher_suites.push_back(kCiphersToDisable[i]); | 674 ssl_config.disabled_cipher_suites.push_back(kCiphersToDisable[i]); |
| 671 | 675 |
| 672 scoped_ptr<net::SSLClientSocket> sock( | 676 scoped_ptr<net::SSLClientSocket> sock( |
| 673 CreateSSLClientSocket(transport, test_server.host_port_pair(), | 677 CreateSSLClientSocket(transport, test_server.host_port_pair(), |
| 674 ssl_config)); | 678 ssl_config)); |
| 675 | 679 |
| 676 EXPECT_FALSE(sock->IsConnected()); | 680 EXPECT_FALSE(sock->IsConnected()); |
| 677 | 681 |
| 678 rv = sock->Connect(&callback); | 682 rv = sock->Connect(callback.callback()); |
| 679 net::CapturingNetLog::EntryList entries; | 683 net::CapturingNetLog::EntryList entries; |
| 680 log.GetEntries(&entries); | 684 log.GetEntries(&entries); |
| 681 EXPECT_TRUE(net::LogContainsBeginEvent( | 685 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 682 entries, 5, net::NetLog::TYPE_SSL_CONNECT)); | 686 entries, 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 683 | 687 |
| 684 // NSS has special handling that maps a handshake_failure alert received | 688 // NSS has special handling that maps a handshake_failure alert received |
| 685 // immediately after a client_hello to be a mismatched cipher suite error, | 689 // immediately after a client_hello to be a mismatched cipher suite error, |
| 686 // leading to ERR_SSL_VERSION_OR_CIPHER_MISMATCH. When using OpenSSL or | 690 // leading to ERR_SSL_VERSION_OR_CIPHER_MISMATCH. When using OpenSSL or |
| 687 // Secure Transport (OS X), the handshake_failure is bubbled up without any | 691 // Secure Transport (OS X), the handshake_failure is bubbled up without any |
| 688 // interpretation, leading to ERR_SSL_PROTOCOL_ERROR. Either way, a failure | 692 // interpretation, leading to ERR_SSL_PROTOCOL_ERROR. Either way, a failure |
| (...skipping 29 matching lines...) Expand all Loading... |
| 718 // ClientSocketHandle that is not obtained from a client socket pool. | 722 // ClientSocketHandle that is not obtained from a client socket pool. |
| 719 // Here we verify that such a simple ClientSocketHandle, not associated with any | 723 // Here we verify that such a simple ClientSocketHandle, not associated with any |
| 720 // client socket pool, can be destroyed safely. | 724 // client socket pool, can be destroyed safely. |
| 721 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) { | 725 TEST_F(SSLClientSocketTest, ClientSocketHandleNotFromPool) { |
| 722 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); | 726 net::TestServer test_server(net::TestServer::TYPE_HTTPS, FilePath()); |
| 723 ASSERT_TRUE(test_server.Start()); | 727 ASSERT_TRUE(test_server.Start()); |
| 724 | 728 |
| 725 net::AddressList addr; | 729 net::AddressList addr; |
| 726 ASSERT_TRUE(test_server.GetAddressList(&addr)); | 730 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 727 | 731 |
| 728 TestOldCompletionCallback callback; | 732 net::TestCompletionCallback callback; |
| 729 net::StreamSocket* transport = new net::TCPClientSocket( | 733 net::StreamSocket* transport = new net::TCPClientSocket( |
| 730 addr, NULL, net::NetLog::Source()); | 734 addr, NULL, net::NetLog::Source()); |
| 731 int rv = transport->Connect(&callback); | 735 int rv = transport->Connect(callback.callback()); |
| 732 if (rv == net::ERR_IO_PENDING) | 736 if (rv == net::ERR_IO_PENDING) |
| 733 rv = callback.WaitForResult(); | 737 rv = callback.WaitForResult(); |
| 734 EXPECT_EQ(net::OK, rv); | 738 EXPECT_EQ(net::OK, rv); |
| 735 | 739 |
| 736 net::ClientSocketHandle* socket_handle = new net::ClientSocketHandle(); | 740 net::ClientSocketHandle* socket_handle = new net::ClientSocketHandle(); |
| 737 socket_handle->set_socket(transport); | 741 socket_handle->set_socket(transport); |
| 738 | 742 |
| 739 net::SSLClientSocketContext context; | 743 net::SSLClientSocketContext context; |
| 740 context.cert_verifier = cert_verifier_.get(); | 744 context.cert_verifier = cert_verifier_.get(); |
| 741 scoped_ptr<net::SSLClientSocket> ssl_socket( | 745 scoped_ptr<net::SSLClientSocket> ssl_socket( |
| 742 socket_factory_->CreateSSLClientSocket( | 746 socket_factory_->CreateSSLClientSocket( |
| 743 socket_handle, test_server.host_port_pair(), kDefaultSSLConfig, | 747 socket_handle, test_server.host_port_pair(), kDefaultSSLConfig, |
| 744 NULL, context)); | 748 NULL, context)); |
| 745 | 749 |
| 746 EXPECT_FALSE(ssl_socket->IsConnected()); | 750 EXPECT_FALSE(ssl_socket->IsConnected()); |
| 747 rv = ssl_socket->Connect(&callback); | 751 rv = ssl_socket->Connect(callback.callback()); |
| 748 if (rv == net::ERR_IO_PENDING) | 752 if (rv == net::ERR_IO_PENDING) |
| 749 rv = callback.WaitForResult(); | 753 rv = callback.WaitForResult(); |
| 750 EXPECT_EQ(net::OK, rv); | 754 EXPECT_EQ(net::OK, rv); |
| 751 } | 755 } |
| OLD | NEW |