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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(transport, |
70 test_server.host_port_pair().host(), kDefaultSSLConfig)); | 70 test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 71 NULL /* ssl_host_info */)); |
71 | 72 |
72 EXPECT_FALSE(sock->IsConnected()); | 73 EXPECT_FALSE(sock->IsConnected()); |
73 | 74 |
74 rv = sock->Connect(&callback); | 75 rv = sock->Connect(&callback); |
75 EXPECT_TRUE(net::LogContainsBeginEvent( | 76 EXPECT_TRUE(net::LogContainsBeginEvent( |
76 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 77 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
77 if (rv != net::OK) { | 78 if (rv != net::OK) { |
78 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 79 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
79 EXPECT_FALSE(sock->IsConnected()); | 80 EXPECT_FALSE(sock->IsConnected()); |
80 EXPECT_FALSE(net::LogContainsEndEvent( | 81 EXPECT_FALSE(net::LogContainsEndEvent( |
(...skipping 22 matching lines...) Expand all Loading... |
103 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 104 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
104 net::ClientSocket* transport = new net::TCPClientSocket( | 105 net::ClientSocket* transport = new net::TCPClientSocket( |
105 addr, &log, net::NetLog::Source()); | 106 addr, &log, net::NetLog::Source()); |
106 int rv = transport->Connect(&callback); | 107 int rv = transport->Connect(&callback); |
107 if (rv == net::ERR_IO_PENDING) | 108 if (rv == net::ERR_IO_PENDING) |
108 rv = callback.WaitForResult(); | 109 rv = callback.WaitForResult(); |
109 EXPECT_EQ(net::OK, rv); | 110 EXPECT_EQ(net::OK, rv); |
110 | 111 |
111 scoped_ptr<net::SSLClientSocket> sock( | 112 scoped_ptr<net::SSLClientSocket> sock( |
112 socket_factory_->CreateSSLClientSocket(transport, | 113 socket_factory_->CreateSSLClientSocket(transport, |
113 test_server.host_port_pair().host(), kDefaultSSLConfig)); | 114 test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 115 NULL /* ssl_host_info */)); |
114 | 116 |
115 EXPECT_FALSE(sock->IsConnected()); | 117 EXPECT_FALSE(sock->IsConnected()); |
116 | 118 |
117 rv = sock->Connect(&callback); | 119 rv = sock->Connect(&callback); |
118 EXPECT_TRUE(net::LogContainsBeginEvent( | 120 EXPECT_TRUE(net::LogContainsBeginEvent( |
119 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 121 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
120 if (rv != net::OK) { | 122 if (rv != net::OK) { |
121 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 123 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
122 EXPECT_FALSE(sock->IsConnected()); | 124 EXPECT_FALSE(sock->IsConnected()); |
123 EXPECT_FALSE(net::LogContainsEndEvent( | 125 EXPECT_FALSE(net::LogContainsEndEvent( |
(...skipping 21 matching lines...) Expand all Loading... |
145 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 147 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
146 net::ClientSocket* transport = new net::TCPClientSocket( | 148 net::ClientSocket* transport = new net::TCPClientSocket( |
147 addr, &log, net::NetLog::Source()); | 149 addr, &log, net::NetLog::Source()); |
148 int rv = transport->Connect(&callback); | 150 int rv = transport->Connect(&callback); |
149 if (rv == net::ERR_IO_PENDING) | 151 if (rv == net::ERR_IO_PENDING) |
150 rv = callback.WaitForResult(); | 152 rv = callback.WaitForResult(); |
151 EXPECT_EQ(net::OK, rv); | 153 EXPECT_EQ(net::OK, rv); |
152 | 154 |
153 scoped_ptr<net::SSLClientSocket> sock( | 155 scoped_ptr<net::SSLClientSocket> sock( |
154 socket_factory_->CreateSSLClientSocket(transport, | 156 socket_factory_->CreateSSLClientSocket(transport, |
155 test_server.host_port_pair().host(), kDefaultSSLConfig)); | 157 test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 158 NULL /* ssl_host_info */)); |
156 | 159 |
157 EXPECT_FALSE(sock->IsConnected()); | 160 EXPECT_FALSE(sock->IsConnected()); |
158 | 161 |
159 rv = sock->Connect(&callback); | 162 rv = sock->Connect(&callback); |
160 | 163 |
161 EXPECT_TRUE(net::LogContainsBeginEvent( | 164 EXPECT_TRUE(net::LogContainsBeginEvent( |
162 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 165 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
163 if (rv != net::ERR_CERT_COMMON_NAME_INVALID) { | 166 if (rv != net::ERR_CERT_COMMON_NAME_INVALID) { |
164 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 167 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
165 EXPECT_FALSE(sock->IsConnected()); | 168 EXPECT_FALSE(sock->IsConnected()); |
(...skipping 24 matching lines...) Expand all Loading... |
190 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); | 193 net::CapturingNetLog log(net::CapturingNetLog::kUnbounded); |
191 net::ClientSocket* transport = new net::TCPClientSocket( | 194 net::ClientSocket* transport = new net::TCPClientSocket( |
192 addr, &log, net::NetLog::Source()); | 195 addr, &log, net::NetLog::Source()); |
193 int rv = transport->Connect(&callback); | 196 int rv = transport->Connect(&callback); |
194 if (rv == net::ERR_IO_PENDING) | 197 if (rv == net::ERR_IO_PENDING) |
195 rv = callback.WaitForResult(); | 198 rv = callback.WaitForResult(); |
196 EXPECT_EQ(net::OK, rv); | 199 EXPECT_EQ(net::OK, rv); |
197 | 200 |
198 scoped_ptr<net::SSLClientSocket> sock( | 201 scoped_ptr<net::SSLClientSocket> sock( |
199 socket_factory_->CreateSSLClientSocket(transport, | 202 socket_factory_->CreateSSLClientSocket(transport, |
200 test_server.host_port_pair().host(), kDefaultSSLConfig)); | 203 test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 204 NULL /* ssl_host_info */)); |
201 | 205 |
202 EXPECT_FALSE(sock->IsConnected()); | 206 EXPECT_FALSE(sock->IsConnected()); |
203 | 207 |
204 rv = sock->Connect(&callback); | 208 rv = sock->Connect(&callback); |
205 EXPECT_TRUE(net::LogContainsBeginEvent( | 209 EXPECT_TRUE(net::LogContainsBeginEvent( |
206 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 210 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
207 if (rv != net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 211 if (rv != net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
208 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 212 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
209 EXPECT_FALSE(sock->IsConnected()); | 213 EXPECT_FALSE(sock->IsConnected()); |
210 EXPECT_FALSE(net::LogContainsEndEvent( | 214 EXPECT_FALSE(net::LogContainsEndEvent( |
(...skipping 29 matching lines...) Expand all Loading... |
240 if (rv == net::ERR_IO_PENDING) | 244 if (rv == net::ERR_IO_PENDING) |
241 rv = callback.WaitForResult(); | 245 rv = callback.WaitForResult(); |
242 EXPECT_EQ(net::OK, rv); | 246 EXPECT_EQ(net::OK, rv); |
243 | 247 |
244 net::SSLConfig ssl_config = kDefaultSSLConfig; | 248 net::SSLConfig ssl_config = kDefaultSSLConfig; |
245 ssl_config.send_client_cert = true; | 249 ssl_config.send_client_cert = true; |
246 ssl_config.client_cert = NULL; | 250 ssl_config.client_cert = NULL; |
247 | 251 |
248 scoped_ptr<net::SSLClientSocket> sock( | 252 scoped_ptr<net::SSLClientSocket> sock( |
249 socket_factory_->CreateSSLClientSocket(transport, | 253 socket_factory_->CreateSSLClientSocket(transport, |
250 test_server.host_port_pair().host(), ssl_config)); | 254 test_server.host_port_pair().host(), ssl_config, |
| 255 NULL /* ssl_host_info */)); |
251 | 256 |
252 EXPECT_FALSE(sock->IsConnected()); | 257 EXPECT_FALSE(sock->IsConnected()); |
253 | 258 |
254 // Our test server accepts certificate-less connections. | 259 // Our test server accepts certificate-less connections. |
255 // TODO(davidben): Add a test which requires them and verify the error. | 260 // TODO(davidben): Add a test which requires them and verify the error. |
256 rv = sock->Connect(&callback); | 261 rv = sock->Connect(&callback); |
257 EXPECT_TRUE(net::LogContainsBeginEvent( | 262 EXPECT_TRUE(net::LogContainsBeginEvent( |
258 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); | 263 log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); |
259 if (rv != net::OK) { | 264 if (rv != net::OK) { |
260 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 265 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
(...skipping 29 matching lines...) Expand all Loading... |
290 addr, NULL, net::NetLog::Source()); | 295 addr, NULL, net::NetLog::Source()); |
291 int rv = transport->Connect(&callback); | 296 int rv = transport->Connect(&callback); |
292 if (rv == net::ERR_IO_PENDING) | 297 if (rv == net::ERR_IO_PENDING) |
293 rv = callback.WaitForResult(); | 298 rv = callback.WaitForResult(); |
294 EXPECT_EQ(net::OK, rv); | 299 EXPECT_EQ(net::OK, rv); |
295 | 300 |
296 scoped_ptr<net::SSLClientSocket> sock( | 301 scoped_ptr<net::SSLClientSocket> sock( |
297 socket_factory_->CreateSSLClientSocket( | 302 socket_factory_->CreateSSLClientSocket( |
298 transport, | 303 transport, |
299 test_server.host_port_pair().host(), | 304 test_server.host_port_pair().host(), |
300 kDefaultSSLConfig)); | 305 kDefaultSSLConfig, |
| 306 NULL /* ssl_host_info */)); |
301 | 307 |
302 rv = sock->Connect(&callback); | 308 rv = sock->Connect(&callback); |
303 if (rv != net::OK) { | 309 if (rv != net::OK) { |
304 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 310 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
305 | 311 |
306 rv = callback.WaitForResult(); | 312 rv = callback.WaitForResult(); |
307 EXPECT_EQ(net::OK, rv); | 313 EXPECT_EQ(net::OK, rv); |
308 } | 314 } |
309 EXPECT_TRUE(sock->IsConnected()); | 315 EXPECT_TRUE(sock->IsConnected()); |
310 | 316 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 addr, NULL, net::NetLog::Source()); | 356 addr, NULL, net::NetLog::Source()); |
351 int rv = transport->Connect(&callback); | 357 int rv = transport->Connect(&callback); |
352 if (rv == net::ERR_IO_PENDING) | 358 if (rv == net::ERR_IO_PENDING) |
353 rv = callback.WaitForResult(); | 359 rv = callback.WaitForResult(); |
354 EXPECT_EQ(net::OK, rv); | 360 EXPECT_EQ(net::OK, rv); |
355 | 361 |
356 scoped_ptr<net::SSLClientSocket> sock( | 362 scoped_ptr<net::SSLClientSocket> sock( |
357 socket_factory_->CreateSSLClientSocket( | 363 socket_factory_->CreateSSLClientSocket( |
358 transport, | 364 transport, |
359 test_server.host_port_pair().host(), | 365 test_server.host_port_pair().host(), |
360 kDefaultSSLConfig)); | 366 kDefaultSSLConfig, |
| 367 NULL /* ssl_host_info */)); |
361 | 368 |
362 rv = sock->Connect(&callback); | 369 rv = sock->Connect(&callback); |
363 if (rv != net::OK) { | 370 if (rv != net::OK) { |
364 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 371 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
365 | 372 |
366 rv = callback.WaitForResult(); | 373 rv = callback.WaitForResult(); |
367 EXPECT_EQ(net::OK, rv); | 374 EXPECT_EQ(net::OK, rv); |
368 } | 375 } |
369 EXPECT_TRUE(sock->IsConnected()); | 376 EXPECT_TRUE(sock->IsConnected()); |
370 | 377 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 TestCompletionCallback callback; | 414 TestCompletionCallback callback; |
408 net::ClientSocket* transport = new net::TCPClientSocket( | 415 net::ClientSocket* transport = new net::TCPClientSocket( |
409 addr, NULL, net::NetLog::Source()); | 416 addr, NULL, net::NetLog::Source()); |
410 int rv = transport->Connect(&callback); | 417 int rv = transport->Connect(&callback); |
411 if (rv == net::ERR_IO_PENDING) | 418 if (rv == net::ERR_IO_PENDING) |
412 rv = callback.WaitForResult(); | 419 rv = callback.WaitForResult(); |
413 EXPECT_EQ(net::OK, rv); | 420 EXPECT_EQ(net::OK, rv); |
414 | 421 |
415 scoped_ptr<net::SSLClientSocket> sock( | 422 scoped_ptr<net::SSLClientSocket> sock( |
416 socket_factory_->CreateSSLClientSocket(transport, | 423 socket_factory_->CreateSSLClientSocket(transport, |
417 test_server.host_port_pair().host(), kDefaultSSLConfig)); | 424 test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 425 NULL /* ssl_host_info */)); |
418 | 426 |
419 rv = sock->Connect(&callback); | 427 rv = sock->Connect(&callback); |
420 if (rv != net::OK) { | 428 if (rv != net::OK) { |
421 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 429 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
422 | 430 |
423 rv = callback.WaitForResult(); | 431 rv = callback.WaitForResult(); |
424 EXPECT_EQ(net::OK, rv); | 432 EXPECT_EQ(net::OK, rv); |
425 } | 433 } |
426 | 434 |
427 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 435 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 TestCompletionCallback callback; | 468 TestCompletionCallback callback; |
461 net::ClientSocket* transport = new net::TCPClientSocket( | 469 net::ClientSocket* transport = new net::TCPClientSocket( |
462 addr, NULL, net::NetLog::Source()); | 470 addr, NULL, net::NetLog::Source()); |
463 int rv = transport->Connect(&callback); | 471 int rv = transport->Connect(&callback); |
464 if (rv == net::ERR_IO_PENDING) | 472 if (rv == net::ERR_IO_PENDING) |
465 rv = callback.WaitForResult(); | 473 rv = callback.WaitForResult(); |
466 EXPECT_EQ(net::OK, rv); | 474 EXPECT_EQ(net::OK, rv); |
467 | 475 |
468 scoped_ptr<net::SSLClientSocket> sock( | 476 scoped_ptr<net::SSLClientSocket> sock( |
469 socket_factory_->CreateSSLClientSocket(transport, | 477 socket_factory_->CreateSSLClientSocket(transport, |
470 test_server.host_port_pair().host(), kDefaultSSLConfig)); | 478 test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 479 NULL /* ssl_host_info */)); |
471 | 480 |
472 rv = sock->Connect(&callback); | 481 rv = sock->Connect(&callback); |
473 if (rv != net::OK) { | 482 if (rv != net::OK) { |
474 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 483 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
475 | 484 |
476 rv = callback.WaitForResult(); | 485 rv = callback.WaitForResult(); |
477 EXPECT_EQ(net::OK, rv); | 486 EXPECT_EQ(net::OK, rv); |
478 } | 487 } |
479 | 488 |
480 const char request_text[] = "GET / HTTP/1.0\r\n\r\n"; | 489 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... |
533 | 542 |
534 net::ClientSocket* transport = | 543 net::ClientSocket* transport = |
535 new net::MockTCPClientSocket(addr, NULL, &data); | 544 new net::MockTCPClientSocket(addr, NULL, &data); |
536 int rv = transport->Connect(&callback); | 545 int rv = transport->Connect(&callback); |
537 if (rv == net::ERR_IO_PENDING) | 546 if (rv == net::ERR_IO_PENDING) |
538 rv = callback.WaitForResult(); | 547 rv = callback.WaitForResult(); |
539 EXPECT_EQ(net::OK, rv); | 548 EXPECT_EQ(net::OK, rv); |
540 | 549 |
541 scoped_ptr<net::SSLClientSocket> sock( | 550 scoped_ptr<net::SSLClientSocket> sock( |
542 socket_factory_->CreateSSLClientSocket( | 551 socket_factory_->CreateSSLClientSocket( |
543 transport, test_server.host_port_pair().host(), kDefaultSSLConfig)); | 552 transport, test_server.host_port_pair().host(), kDefaultSSLConfig, |
| 553 NULL /* ssl_host_info */)); |
544 | 554 |
545 rv = sock->Connect(&callback); | 555 rv = sock->Connect(&callback); |
546 EXPECT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); | 556 EXPECT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv); |
547 } | 557 } |
OLD | NEW |