| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/socket/ssl_client_socket.h" | 5 #include "net/socket/ssl_client_socket.h" |
| 6 | 6 |
| 7 #include "net/base/address_list.h" | 7 #include "net/base/address_list.h" |
| 8 #include "net/base/host_resolver.h" | 8 #include "net/base/host_resolver.h" |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/base/net_log.h" | 10 #include "net/base/net_log.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 TestCompletionCallback callback; | 59 TestCompletionCallback callback; |
| 60 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 60 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 61 net::ClientSocket* transport = new net::TCPClientSocket( | 61 net::ClientSocket* transport = new net::TCPClientSocket( |
| 62 addr, &log, net::NetLog::Source()); | 62 addr, &log, net::NetLog::Source()); |
| 63 int rv = transport->Connect(&callback); | 63 int rv = transport->Connect(&callback); |
| 64 if (rv == net::ERR_IO_PENDING) | 64 if (rv == net::ERR_IO_PENDING) |
| 65 rv = callback.WaitForResult(); | 65 rv = callback.WaitForResult(); |
| 66 EXPECT_EQ(net::OK, rv); | 66 EXPECT_EQ(net::OK, rv); |
| 67 | 67 |
| 68 scoped_ptr<net::SSLClientSocket> sock( | 68 scoped_ptr<net::SSLClientSocket> sock( |
| 69 socket_factory_->CreateSSLClientSocket(transport, | 69 socket_factory_->CreateSSLClientSocket( |
| 70 test_server.host_port_pair().host(), kDefaultSSLConfig, | 70 transport, test_server.host_port_pair().host(), |
| 71 test_server.host_port_pair().port(), kDefaultSSLConfig, |
| 71 NULL /* ssl_host_info */)); | 72 NULL /* ssl_host_info */)); |
| 72 | 73 |
| 73 EXPECT_FALSE(sock->IsConnected()); | 74 EXPECT_FALSE(sock->IsConnected()); |
| 74 | 75 |
| 75 rv = sock->Connect(&callback); | 76 rv = sock->Connect(&callback); |
| 76 EXPECT_TRUE(net::LogContainsBeginEvent( | 77 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 77 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 78 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 78 if (rv != net::OK) { | 79 if (rv != net::OK) { |
| 79 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 80 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 80 EXPECT_FALSE(sock->IsConnected()); | 81 EXPECT_FALSE(sock->IsConnected()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 105 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 106 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 106 net::ClientSocket* transport = new net::TCPClientSocket( | 107 net::ClientSocket* transport = new net::TCPClientSocket( |
| 107 addr, &log, net::NetLog::Source()); | 108 addr, &log, net::NetLog::Source()); |
| 108 int rv = transport->Connect(&callback); | 109 int rv = transport->Connect(&callback); |
| 109 if (rv == net::ERR_IO_PENDING) | 110 if (rv == net::ERR_IO_PENDING) |
| 110 rv = callback.WaitForResult(); | 111 rv = callback.WaitForResult(); |
| 111 EXPECT_EQ(net::OK, rv); | 112 EXPECT_EQ(net::OK, rv); |
| 112 | 113 |
| 113 scoped_ptr<net::SSLClientSocket> sock( | 114 scoped_ptr<net::SSLClientSocket> sock( |
| 114 socket_factory_->CreateSSLClientSocket(transport, | 115 socket_factory_->CreateSSLClientSocket(transport, |
| 115 test_server.host_port_pair().host(), kDefaultSSLConfig, | 116 test_server.host_port_pair().host(), |
| 117 test_server.host_port_pair().port(), |
| 118 kDefaultSSLConfig, |
| 116 NULL /* ssl_host_info */)); | 119 NULL /* ssl_host_info */)); |
| 117 | 120 |
| 118 EXPECT_FALSE(sock->IsConnected()); | 121 EXPECT_FALSE(sock->IsConnected()); |
| 119 | 122 |
| 120 rv = sock->Connect(&callback); | 123 rv = sock->Connect(&callback); |
| 121 EXPECT_TRUE(net::LogContainsBeginEvent( | 124 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 122 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 125 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 123 if (rv != net::OK) { | 126 if (rv != net::OK) { |
| 124 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 127 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 125 EXPECT_FALSE(sock->IsConnected()); | 128 EXPECT_FALSE(sock->IsConnected()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 148 TestCompletionCallback callback; | 151 TestCompletionCallback callback; |
| 149 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 152 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 150 net::ClientSocket* transport = new net::TCPClientSocket( | 153 net::ClientSocket* transport = new net::TCPClientSocket( |
| 151 addr, &log, net::NetLog::Source()); | 154 addr, &log, net::NetLog::Source()); |
| 152 int rv = transport->Connect(&callback); | 155 int rv = transport->Connect(&callback); |
| 153 if (rv == net::ERR_IO_PENDING) | 156 if (rv == net::ERR_IO_PENDING) |
| 154 rv = callback.WaitForResult(); | 157 rv = callback.WaitForResult(); |
| 155 EXPECT_EQ(net::OK, rv); | 158 EXPECT_EQ(net::OK, rv); |
| 156 | 159 |
| 157 scoped_ptr<net::SSLClientSocket> sock( | 160 scoped_ptr<net::SSLClientSocket> sock( |
| 158 socket_factory_->CreateSSLClientSocket(transport, | 161 socket_factory_->CreateSSLClientSocket( |
| 159 test_server.host_port_pair().host(), kDefaultSSLConfig, | 162 transport, test_server.host_port_pair().host(), |
| 163 test_server.host_port_pair().port(), kDefaultSSLConfig, |
| 160 NULL /* ssl_host_info */)); | 164 NULL /* ssl_host_info */)); |
| 161 | 165 |
| 162 EXPECT_FALSE(sock->IsConnected()); | 166 EXPECT_FALSE(sock->IsConnected()); |
| 163 | 167 |
| 164 rv = sock->Connect(&callback); | 168 rv = sock->Connect(&callback); |
| 165 | 169 |
| 166 EXPECT_TRUE(net::LogContainsBeginEvent( | 170 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 167 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 171 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 168 if (rv != net::ERR_CERT_COMMON_NAME_INVALID) { | 172 if (rv != net::ERR_CERT_COMMON_NAME_INVALID) { |
| 169 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 173 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 196 TestCompletionCallback callback; | 200 TestCompletionCallback callback; |
| 197 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 201 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
| 198 net::ClientSocket* transport = new net::TCPClientSocket( | 202 net::ClientSocket* transport = new net::TCPClientSocket( |
| 199 addr, &log, net::NetLog::Source()); | 203 addr, &log, net::NetLog::Source()); |
| 200 int rv = transport->Connect(&callback); | 204 int rv = transport->Connect(&callback); |
| 201 if (rv == net::ERR_IO_PENDING) | 205 if (rv == net::ERR_IO_PENDING) |
| 202 rv = callback.WaitForResult(); | 206 rv = callback.WaitForResult(); |
| 203 EXPECT_EQ(net::OK, rv); | 207 EXPECT_EQ(net::OK, rv); |
| 204 | 208 |
| 205 scoped_ptr<net::SSLClientSocket> sock( | 209 scoped_ptr<net::SSLClientSocket> sock( |
| 206 socket_factory_->CreateSSLClientSocket(transport, | 210 socket_factory_->CreateSSLClientSocket( |
| 207 test_server.host_port_pair().host(), kDefaultSSLConfig, | 211 transport, test_server.host_port_pair().host(), |
| 212 test_server.host_port_pair().port(), kDefaultSSLConfig, |
| 208 NULL /* ssl_host_info */)); | 213 NULL /* ssl_host_info */)); |
| 209 | 214 |
| 210 EXPECT_FALSE(sock->IsConnected()); | 215 EXPECT_FALSE(sock->IsConnected()); |
| 211 | 216 |
| 212 rv = sock->Connect(&callback); | 217 rv = sock->Connect(&callback); |
| 213 EXPECT_TRUE(net::LogContainsBeginEvent( | 218 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 214 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 219 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 215 if (rv != net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 220 if (rv != net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
| 216 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 221 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 217 EXPECT_FALSE(sock->IsConnected()); | 222 EXPECT_FALSE(sock->IsConnected()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 248 int rv = transport->Connect(&callback); | 253 int rv = transport->Connect(&callback); |
| 249 if (rv == net::ERR_IO_PENDING) | 254 if (rv == net::ERR_IO_PENDING) |
| 250 rv = callback.WaitForResult(); | 255 rv = callback.WaitForResult(); |
| 251 EXPECT_EQ(net::OK, rv); | 256 EXPECT_EQ(net::OK, rv); |
| 252 | 257 |
| 253 net::SSLConfig ssl_config = kDefaultSSLConfig; | 258 net::SSLConfig ssl_config = kDefaultSSLConfig; |
| 254 ssl_config.send_client_cert = true; | 259 ssl_config.send_client_cert = true; |
| 255 ssl_config.client_cert = NULL; | 260 ssl_config.client_cert = NULL; |
| 256 | 261 |
| 257 scoped_ptr<net::SSLClientSocket> sock( | 262 scoped_ptr<net::SSLClientSocket> sock( |
| 258 socket_factory_->CreateSSLClientSocket(transport, | 263 socket_factory_->CreateSSLClientSocket( |
| 259 test_server.host_port_pair().host(), ssl_config, | 264 transport, test_server.host_port_pair().host(), |
| 265 test_server.host_port_pair().port(), ssl_config, |
| 260 NULL /* ssl_host_info */)); | 266 NULL /* ssl_host_info */)); |
| 261 | 267 |
| 262 EXPECT_FALSE(sock->IsConnected()); | 268 EXPECT_FALSE(sock->IsConnected()); |
| 263 | 269 |
| 264 // Our test server accepts certificate-less connections. | 270 // Our test server accepts certificate-less connections. |
| 265 // TODO(davidben): Add a test which requires them and verify the error. | 271 // TODO(davidben): Add a test which requires them and verify the error. |
| 266 rv = sock->Connect(&callback); | 272 rv = sock->Connect(&callback); |
| 267 EXPECT_TRUE(net::LogContainsBeginEvent( | 273 EXPECT_TRUE(net::LogContainsBeginEvent( |
| 268 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 274 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
| 269 if (rv != net::OK) { | 275 if (rv != net::OK) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 300 addr, NULL, net::NetLog::Source()); | 306 addr, NULL, net::NetLog::Source()); |
| 301 int rv = transport->Connect(&callback); | 307 int rv = transport->Connect(&callback); |
| 302 if (rv == net::ERR_IO_PENDING) | 308 if (rv == net::ERR_IO_PENDING) |
| 303 rv = callback.WaitForResult(); | 309 rv = callback.WaitForResult(); |
| 304 EXPECT_EQ(net::OK, rv); | 310 EXPECT_EQ(net::OK, rv); |
| 305 | 311 |
| 306 scoped_ptr<net::SSLClientSocket> sock( | 312 scoped_ptr<net::SSLClientSocket> sock( |
| 307 socket_factory_->CreateSSLClientSocket( | 313 socket_factory_->CreateSSLClientSocket( |
| 308 transport, | 314 transport, |
| 309 test_server.host_port_pair().host(), | 315 test_server.host_port_pair().host(), |
| 316 test_server.host_port_pair().port(), |
| 310 kDefaultSSLConfig, | 317 kDefaultSSLConfig, |
| 311 NULL /* ssl_host_info */)); | 318 NULL /* ssl_host_info */)); |
| 312 | 319 |
| 313 rv = sock->Connect(&callback); | 320 rv = sock->Connect(&callback); |
| 314 if (rv != net::OK) { | 321 if (rv != net::OK) { |
| 315 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 322 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 316 | 323 |
| 317 rv = callback.WaitForResult(); | 324 rv = callback.WaitForResult(); |
| 318 EXPECT_EQ(net::OK, rv); | 325 EXPECT_EQ(net::OK, rv); |
| 319 } | 326 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 addr, NULL, net::NetLog::Source()); | 368 addr, NULL, net::NetLog::Source()); |
| 362 int rv = transport->Connect(&callback); | 369 int rv = transport->Connect(&callback); |
| 363 if (rv == net::ERR_IO_PENDING) | 370 if (rv == net::ERR_IO_PENDING) |
| 364 rv = callback.WaitForResult(); | 371 rv = callback.WaitForResult(); |
| 365 EXPECT_EQ(net::OK, rv); | 372 EXPECT_EQ(net::OK, rv); |
| 366 | 373 |
| 367 scoped_ptr<net::SSLClientSocket> sock( | 374 scoped_ptr<net::SSLClientSocket> sock( |
| 368 socket_factory_->CreateSSLClientSocket( | 375 socket_factory_->CreateSSLClientSocket( |
| 369 transport, | 376 transport, |
| 370 test_server.host_port_pair().host(), | 377 test_server.host_port_pair().host(), |
| 378 test_server.host_port_pair().port(), |
| 371 kDefaultSSLConfig, | 379 kDefaultSSLConfig, |
| 372 NULL /* ssl_host_info */)); | 380 NULL /* ssl_host_info */)); |
| 373 | 381 |
| 374 rv = sock->Connect(&callback); | 382 rv = sock->Connect(&callback); |
| 375 if (rv != net::OK) { | 383 if (rv != net::OK) { |
| 376 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 384 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 377 | 385 |
| 378 rv = callback.WaitForResult(); | 386 rv = callback.WaitForResult(); |
| 379 EXPECT_EQ(net::OK, rv); | 387 EXPECT_EQ(net::OK, rv); |
| 380 } | 388 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 TestCompletionCallback callback; | 427 TestCompletionCallback callback; |
| 420 net::ClientSocket* transport = new net::TCPClientSocket( | 428 net::ClientSocket* transport = new net::TCPClientSocket( |
| 421 addr, NULL, net::NetLog::Source()); | 429 addr, NULL, net::NetLog::Source()); |
| 422 int rv = transport->Connect(&callback); | 430 int rv = transport->Connect(&callback); |
| 423 if (rv == net::ERR_IO_PENDING) | 431 if (rv == net::ERR_IO_PENDING) |
| 424 rv = callback.WaitForResult(); | 432 rv = callback.WaitForResult(); |
| 425 EXPECT_EQ(net::OK, rv); | 433 EXPECT_EQ(net::OK, rv); |
| 426 | 434 |
| 427 scoped_ptr<net::SSLClientSocket> sock( | 435 scoped_ptr<net::SSLClientSocket> sock( |
| 428 socket_factory_->CreateSSLClientSocket(transport, | 436 socket_factory_->CreateSSLClientSocket(transport, |
| 429 test_server.host_port_pair().host(), kDefaultSSLConfig, | 437 test_server.host_port_pair().host(), |
| 438 test_server.host_port_pair().port(), |
| 439 kDefaultSSLConfig, |
| 430 NULL /* ssl_host_info */)); | 440 NULL /* ssl_host_info */)); |
| 431 | 441 |
| 432 rv = sock->Connect(&callback); | 442 rv = sock->Connect(&callback); |
| 433 if (rv != net::OK) { | 443 if (rv != net::OK) { |
| 434 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 444 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 435 | 445 |
| 436 rv = callback.WaitForResult(); | 446 rv = callback.WaitForResult(); |
| 437 EXPECT_EQ(net::OK, rv); | 447 EXPECT_EQ(net::OK, rv); |
| 438 } | 448 } |
| 439 | 449 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 TestCompletionCallback callback; | 483 TestCompletionCallback callback; |
| 474 net::ClientSocket* transport = new net::TCPClientSocket( | 484 net::ClientSocket* transport = new net::TCPClientSocket( |
| 475 addr, NULL, net::NetLog::Source()); | 485 addr, NULL, net::NetLog::Source()); |
| 476 int rv = transport->Connect(&callback); | 486 int rv = transport->Connect(&callback); |
| 477 if (rv == net::ERR_IO_PENDING) | 487 if (rv == net::ERR_IO_PENDING) |
| 478 rv = callback.WaitForResult(); | 488 rv = callback.WaitForResult(); |
| 479 EXPECT_EQ(net::OK, rv); | 489 EXPECT_EQ(net::OK, rv); |
| 480 | 490 |
| 481 scoped_ptr<net::SSLClientSocket> sock( | 491 scoped_ptr<net::SSLClientSocket> sock( |
| 482 socket_factory_->CreateSSLClientSocket(transport, | 492 socket_factory_->CreateSSLClientSocket(transport, |
| 483 test_server.host_port_pair().host(), kDefaultSSLConfig, | 493 test_server.host_port_pair().host(), |
| 484 NULL /* ssl_host_info */)); | 494 test_server.host_port_pair().port(), |
| 495 kDefaultSSLConfig, NULL /* ssl_host_info */)); |
| 485 | 496 |
| 486 rv = sock->Connect(&callback); | 497 rv = sock->Connect(&callback); |
| 487 if (rv != net::OK) { | 498 if (rv != net::OK) { |
| 488 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 499 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 489 | 500 |
| 490 rv = callback.WaitForResult(); | 501 rv = callback.WaitForResult(); |
| 491 EXPECT_EQ(net::OK, rv); | 502 EXPECT_EQ(net::OK, rv); |
| 492 } | 503 } |
| 493 | 504 |
| 494 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 505 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 558 |
| 548 net::ClientSocket* transport = | 559 net::ClientSocket* transport = |
| 549 new net::MockTCPClientSocket(addr, NULL, &data); | 560 new net::MockTCPClientSocket(addr, NULL, &data); |
| 550 int rv = transport->Connect(&callback); | 561 int rv = transport->Connect(&callback); |
| 551 if (rv == net::ERR_IO_PENDING) | 562 if (rv == net::ERR_IO_PENDING) |
| 552 rv = callback.WaitForResult(); | 563 rv = callback.WaitForResult(); |
| 553 EXPECT_EQ(net::OK, rv); | 564 EXPECT_EQ(net::OK, rv); |
| 554 | 565 |
| 555 scoped_ptr<net::SSLClientSocket> sock( | 566 scoped_ptr<net::SSLClientSocket> sock( |
| 556 socket_factory_->CreateSSLClientSocket( | 567 socket_factory_->CreateSSLClientSocket( |
| 557 transport, test_server.host_port_pair().host(), kDefaultSSLConfig, | 568 transport, test_server.host_port_pair().host(), |
| 569 test_server.host_port_pair().port(), kDefaultSSLConfig, |
| 558 NULL /* ssl_host_info */)); | 570 NULL /* ssl_host_info */)); |
| 559 | 571 |
| 560 rv = sock->Connect(&callback); | 572 rv = sock->Connect(&callback); |
| 561 EXPECT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); | 573 EXPECT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
| 562 } | 574 } |
| OLD | NEW |