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 "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 3152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3163 server_options.bulk_ciphers = | 3163 server_options.bulk_ciphers = |
3164 SpawnedTestServer::SSLOptions::BULK_CIPHER_AES128GCM; | 3164 SpawnedTestServer::SSLOptions::BULK_CIPHER_AES128GCM; |
3165 server_options.enable_npn = true; | 3165 server_options.enable_npn = true; |
3166 ASSERT_TRUE(StartTestServer(server_options)); | 3166 ASSERT_TRUE(StartTestServer(server_options)); |
3167 | 3167 |
3168 SSLConfig client_config; | 3168 SSLConfig client_config; |
3169 client_config.next_protos.push_back(kProtoHTTP11); | 3169 client_config.next_protos.push_back(kProtoHTTP11); |
3170 | 3170 |
3171 // Start a handshake up to the server Finished message. | 3171 // Start a handshake up to the server Finished message. |
3172 TestCompletionCallback callback; | 3172 TestCompletionCallback callback; |
3173 FakeBlockingStreamSocket* raw_transport1; | 3173 FakeBlockingStreamSocket* raw_transport1 = NULL; |
3174 scoped_ptr<SSLClientSocket> sock1; | 3174 scoped_ptr<SSLClientSocket> sock1; |
3175 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( | 3175 ASSERT_NO_FATAL_FAILURE(CreateAndConnectUntilServerFinishedReceived( |
3176 client_config, &callback, &raw_transport1, &sock1)); | 3176 client_config, &callback, &raw_transport1, &sock1)); |
3177 // Although raw_transport1 has the server Finished blocked, the handshake | 3177 // Although raw_transport1 has the server Finished blocked, the handshake |
3178 // still completes. | 3178 // still completes. |
3179 EXPECT_EQ(OK, callback.WaitForResult()); | 3179 EXPECT_EQ(OK, callback.WaitForResult()); |
3180 | 3180 |
| 3181 // Continue to block the client (|sock1|) from processing the Finished |
| 3182 // message, but allow it to arrive on the socket. This ensures that, from the |
| 3183 // server's point of view, it has completed the handshake and added the |
| 3184 // session to its session cache. |
| 3185 // |
| 3186 // The actual read on |sock1| will not complete until the Finished message is |
| 3187 // processed; however, pump the underlying transport so that it is read from |
| 3188 // the socket. This still has the potential to race, but is generally unlikely |
| 3189 // due to socket buffer sizes. |
| 3190 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); |
| 3191 int rv = sock1->Read(buf.get(), 4096, callback.callback()); |
| 3192 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3193 raw_transport1->WaitForReadResult(); |
| 3194 |
3181 // Drop the old socket. This is needed because the Python test server can't | 3195 // Drop the old socket. This is needed because the Python test server can't |
3182 // service two sockets in parallel. | 3196 // service two sockets in parallel. |
3183 sock1.reset(); | 3197 sock1.reset(); |
3184 | 3198 |
3185 // Start a second connection. | 3199 // Start a second connection. |
3186 scoped_ptr<StreamSocket> transport2( | 3200 scoped_ptr<StreamSocket> transport2( |
3187 new TCPClientSocket(addr(), &log_, NetLog::Source())); | 3201 new TCPClientSocket(addr(), &log_, NetLog::Source())); |
3188 EXPECT_EQ(OK, callback.GetResult(transport2->Connect(callback.callback()))); | 3202 EXPECT_EQ(OK, callback.GetResult(transport2->Connect(callback.callback()))); |
3189 scoped_ptr<SSLClientSocket> sock2 = CreateSSLClientSocket( | 3203 scoped_ptr<SSLClientSocket> sock2 = CreateSSLClientSocket( |
3190 transport2.Pass(), test_server()->host_port_pair(), client_config); | 3204 transport2.Pass(), test_server()->host_port_pair(), client_config); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3252 ssl_config.channel_id_enabled = true; | 3266 ssl_config.channel_id_enabled = true; |
3253 | 3267 |
3254 int rv; | 3268 int rv; |
3255 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | 3269 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); |
3256 | 3270 |
3257 EXPECT_EQ(ERR_UNEXPECTED, rv); | 3271 EXPECT_EQ(ERR_UNEXPECTED, rv); |
3258 EXPECT_FALSE(sock_->IsConnected()); | 3272 EXPECT_FALSE(sock_->IsConnected()); |
3259 } | 3273 } |
3260 | 3274 |
3261 } // namespace net | 3275 } // namespace net |
OLD | NEW |