| 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 <openssl/bio.h> | 10 #include <openssl/bio.h> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "net/base/address_list.h" | 22 #include "net/base/address_list.h" |
| 23 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
| 24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 25 #include "net/base/net_log.h" | 25 #include "net/base/net_log.h" |
| 26 #include "net/base/net_log_unittest.h" | 26 #include "net/base/net_log_unittest.h" |
| 27 #include "net/base/test_completion_callback.h" | 27 #include "net/base/test_completion_callback.h" |
| 28 #include "net/base/test_data_directory.h" | 28 #include "net/base/test_data_directory.h" |
| 29 #include "net/cert/mock_cert_verifier.h" | 29 #include "net/cert/mock_cert_verifier.h" |
| 30 #include "net/cert/test_root_certs.h" | 30 #include "net/cert/test_root_certs.h" |
| 31 #include "net/dns/host_resolver.h" | 31 #include "net/dns/host_resolver.h" |
| 32 #include "net/http/transport_security_state.h" |
| 32 #include "net/socket/client_socket_factory.h" | 33 #include "net/socket/client_socket_factory.h" |
| 33 #include "net/socket/client_socket_handle.h" | 34 #include "net/socket/client_socket_handle.h" |
| 34 #include "net/socket/socket_test_util.h" | 35 #include "net/socket/socket_test_util.h" |
| 35 #include "net/socket/tcp_client_socket.h" | 36 #include "net/socket/tcp_client_socket.h" |
| 36 #include "net/ssl/openssl_client_key_store.h" | 37 #include "net/ssl/openssl_client_key_store.h" |
| 37 #include "net/ssl/ssl_cert_request_info.h" | 38 #include "net/ssl/ssl_cert_request_info.h" |
| 38 #include "net/ssl/ssl_config_service.h" | 39 #include "net/ssl/ssl_config_service.h" |
| 39 #include "net/test/cert_test_util.h" | 40 #include "net/test/cert_test_util.h" |
| 40 #include "net/test/spawned_test_server/spawned_test_server.h" | 41 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 return false; | 87 return false; |
| 87 } | 88 } |
| 88 pkey->reset(result); | 89 pkey->reset(result); |
| 89 return true; | 90 return true; |
| 90 } | 91 } |
| 91 | 92 |
| 92 class SSLClientSocketOpenSSLClientAuthTest : public PlatformTest { | 93 class SSLClientSocketOpenSSLClientAuthTest : public PlatformTest { |
| 93 public: | 94 public: |
| 94 SSLClientSocketOpenSSLClientAuthTest() | 95 SSLClientSocketOpenSSLClientAuthTest() |
| 95 : socket_factory_(net::ClientSocketFactory::GetDefaultFactory()), | 96 : socket_factory_(net::ClientSocketFactory::GetDefaultFactory()), |
| 96 cert_verifier_(new net::MockCertVerifier) { | 97 cert_verifier_(new net::MockCertVerifier), |
| 98 transport_security_state_(new net::TransportSecurityState) { |
| 97 cert_verifier_->set_default_result(net::OK); | 99 cert_verifier_->set_default_result(net::OK); |
| 98 context_.cert_verifier = cert_verifier_.get(); | 100 context_.cert_verifier = cert_verifier_.get(); |
| 101 context_.transport_security_state = transport_security_state_.get(); |
| 99 key_store_ = net::OpenSSLClientKeyStore::GetInstance(); | 102 key_store_ = net::OpenSSLClientKeyStore::GetInstance(); |
| 100 } | 103 } |
| 101 | 104 |
| 102 virtual ~SSLClientSocketOpenSSLClientAuthTest() { | 105 virtual ~SSLClientSocketOpenSSLClientAuthTest() { |
| 103 key_store_->Flush(); | 106 key_store_->Flush(); |
| 104 } | 107 } |
| 105 | 108 |
| 106 protected: | 109 protected: |
| 107 SSLClientSocket* CreateSSLClientSocket( | 110 SSLClientSocket* CreateSSLClientSocket( |
| 108 StreamSocket* transport_socket, | 111 StreamSocket* transport_socket, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // Check that the client certificate was sent. | 181 // Check that the client certificate was sent. |
| 179 // Returns true on success. | 182 // Returns true on success. |
| 180 bool CheckSSLClientSocketSentCert() { | 183 bool CheckSSLClientSocketSentCert() { |
| 181 SSLInfo ssl_info; | 184 SSLInfo ssl_info; |
| 182 sock_->GetSSLInfo(&ssl_info); | 185 sock_->GetSSLInfo(&ssl_info); |
| 183 return ssl_info.client_cert_sent; | 186 return ssl_info.client_cert_sent; |
| 184 } | 187 } |
| 185 | 188 |
| 186 ClientSocketFactory* socket_factory_; | 189 ClientSocketFactory* socket_factory_; |
| 187 scoped_ptr<MockCertVerifier> cert_verifier_; | 190 scoped_ptr<MockCertVerifier> cert_verifier_; |
| 191 scoped_ptr<TransportSecurityState> transport_security_state_; |
| 188 SSLClientSocketContext context_; | 192 SSLClientSocketContext context_; |
| 189 OpenSSLClientKeyStore* key_store_; | 193 OpenSSLClientKeyStore* key_store_; |
| 190 scoped_ptr<SpawnedTestServer> test_server_; | 194 scoped_ptr<SpawnedTestServer> test_server_; |
| 191 AddressList addr_; | 195 AddressList addr_; |
| 192 TestCompletionCallback callback_; | 196 TestCompletionCallback callback_; |
| 193 CapturingNetLog log_; | 197 CapturingNetLog log_; |
| 194 scoped_ptr<StreamSocket> transport_; | 198 scoped_ptr<StreamSocket> transport_; |
| 195 scoped_ptr<SSLClientSocket> sock_; | 199 scoped_ptr<SSLClientSocket> sock_; |
| 196 }; | 200 }; |
| 197 | 201 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 EXPECT_TRUE(sock_->IsConnected()); | 268 EXPECT_TRUE(sock_->IsConnected()); |
| 265 | 269 |
| 266 EXPECT_TRUE(CheckSSLClientSocketSentCert()); | 270 EXPECT_TRUE(CheckSSLClientSocketSentCert()); |
| 267 | 271 |
| 268 sock_->Disconnect(); | 272 sock_->Disconnect(); |
| 269 EXPECT_FALSE(sock_->IsConnected()); | 273 EXPECT_FALSE(sock_->IsConnected()); |
| 270 } | 274 } |
| 271 | 275 |
| 272 } // namespace | 276 } // namespace |
| 273 } // namespace net | 277 } // namespace net |
| OLD | NEW |