| 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 // This test suite uses SSLClientSocket to test the implementation of | 5 // This test suite uses SSLClientSocket to test the implementation of |
| 6 // SSLServerSocket. In order to establish connections between the sockets | 6 // SSLServerSocket. In order to establish connections between the sockets |
| 7 // we need two additional classes: | 7 // we need two additional classes: |
| 8 // 1. FakeSocket | 8 // 1. FakeSocket |
| 9 // Connects SSL socket to FakeDataChannel. This class is just a stub. | 9 // Connects SSL socket to FakeDataChannel. This class is just a stub. |
| 10 // | 10 // |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "net/base/completion_callback.h" | 30 #include "net/base/completion_callback.h" |
| 31 #include "net/base/host_port_pair.h" | 31 #include "net/base/host_port_pair.h" |
| 32 #include "net/base/io_buffer.h" | 32 #include "net/base/io_buffer.h" |
| 33 #include "net/base/ip_endpoint.h" | 33 #include "net/base/ip_endpoint.h" |
| 34 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
| 35 #include "net/base/net_log.h" | 35 #include "net/base/net_log.h" |
| 36 #include "net/base/test_data_directory.h" | 36 #include "net/base/test_data_directory.h" |
| 37 #include "net/cert/cert_status_flags.h" | 37 #include "net/cert/cert_status_flags.h" |
| 38 #include "net/cert/mock_cert_verifier.h" | 38 #include "net/cert/mock_cert_verifier.h" |
| 39 #include "net/cert/x509_certificate.h" | 39 #include "net/cert/x509_certificate.h" |
| 40 #include "net/http/transport_security_state.h" |
| 40 #include "net/socket/client_socket_factory.h" | 41 #include "net/socket/client_socket_factory.h" |
| 41 #include "net/socket/socket_test_util.h" | 42 #include "net/socket/socket_test_util.h" |
| 42 #include "net/socket/ssl_client_socket.h" | 43 #include "net/socket/ssl_client_socket.h" |
| 43 #include "net/socket/stream_socket.h" | 44 #include "net/socket/stream_socket.h" |
| 44 #include "net/ssl/ssl_config_service.h" | 45 #include "net/ssl/ssl_config_service.h" |
| 45 #include "net/ssl/ssl_info.h" | 46 #include "net/ssl/ssl_info.h" |
| 46 #include "net/test/cert_test_util.h" | 47 #include "net/test/cert_test_util.h" |
| 47 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
| 48 #include "testing/platform_test.h" | 49 #include "testing/platform_test.h" |
| 49 | 50 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 read = callback.WaitForResult(); | 290 read = callback.WaitForResult(); |
| 290 EXPECT_GT(read, 0); | 291 EXPECT_GT(read, 0); |
| 291 EXPECT_LE(read, written); | 292 EXPECT_LE(read, written); |
| 292 EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), read)); | 293 EXPECT_EQ(0, memcmp(kTestData, read_buf->data(), read)); |
| 293 } | 294 } |
| 294 | 295 |
| 295 class SSLServerSocketTest : public PlatformTest { | 296 class SSLServerSocketTest : public PlatformTest { |
| 296 public: | 297 public: |
| 297 SSLServerSocketTest() | 298 SSLServerSocketTest() |
| 298 : socket_factory_(net::ClientSocketFactory::GetDefaultFactory()), | 299 : socket_factory_(net::ClientSocketFactory::GetDefaultFactory()), |
| 299 cert_verifier_(new MockCertVerifier()) { | 300 cert_verifier_(new MockCertVerifier()), |
| 301 transport_security_state_(new TransportSecurityState) { |
| 300 cert_verifier_->set_default_result(net::CERT_STATUS_AUTHORITY_INVALID); | 302 cert_verifier_->set_default_result(net::CERT_STATUS_AUTHORITY_INVALID); |
| 301 } | 303 } |
| 302 | 304 |
| 303 protected: | 305 protected: |
| 304 void Initialize() { | 306 void Initialize() { |
| 305 FakeSocket* fake_client_socket = new FakeSocket(&channel_1_, &channel_2_); | 307 FakeSocket* fake_client_socket = new FakeSocket(&channel_1_, &channel_2_); |
| 306 FakeSocket* fake_server_socket = new FakeSocket(&channel_2_, &channel_1_); | 308 FakeSocket* fake_server_socket = new FakeSocket(&channel_2_, &channel_1_); |
| 307 | 309 |
| 308 base::FilePath certs_dir(GetTestCertsDirectory()); | 310 base::FilePath certs_dir(GetTestCertsDirectory()); |
| 309 | 311 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 334 | 336 |
| 335 // Certificate provided by the host doesn't need authority. | 337 // Certificate provided by the host doesn't need authority. |
| 336 net::SSLConfig::CertAndStatus cert_and_status; | 338 net::SSLConfig::CertAndStatus cert_and_status; |
| 337 cert_and_status.cert_status = CERT_STATUS_AUTHORITY_INVALID; | 339 cert_and_status.cert_status = CERT_STATUS_AUTHORITY_INVALID; |
| 338 cert_and_status.der_cert = cert_der; | 340 cert_and_status.der_cert = cert_der; |
| 339 ssl_config.allowed_bad_certs.push_back(cert_and_status); | 341 ssl_config.allowed_bad_certs.push_back(cert_and_status); |
| 340 | 342 |
| 341 net::HostPortPair host_and_pair("unittest", 0); | 343 net::HostPortPair host_and_pair("unittest", 0); |
| 342 net::SSLClientSocketContext context; | 344 net::SSLClientSocketContext context; |
| 343 context.cert_verifier = cert_verifier_.get(); | 345 context.cert_verifier = cert_verifier_.get(); |
| 346 context.transport_security_state = transport_security_state_.get(); |
| 344 client_socket_.reset( | 347 client_socket_.reset( |
| 345 socket_factory_->CreateSSLClientSocket( | 348 socket_factory_->CreateSSLClientSocket( |
| 346 fake_client_socket, host_and_pair, ssl_config, context)); | 349 fake_client_socket, host_and_pair, ssl_config, context)); |
| 347 server_socket_.reset(net::CreateSSLServerSocket( | 350 server_socket_.reset(net::CreateSSLServerSocket( |
| 348 fake_server_socket, cert.get(), private_key.get(), net::SSLConfig())); | 351 fake_server_socket, cert.get(), private_key.get(), net::SSLConfig())); |
| 349 } | 352 } |
| 350 | 353 |
| 351 FakeDataChannel channel_1_; | 354 FakeDataChannel channel_1_; |
| 352 FakeDataChannel channel_2_; | 355 FakeDataChannel channel_2_; |
| 353 scoped_ptr<net::SSLClientSocket> client_socket_; | 356 scoped_ptr<net::SSLClientSocket> client_socket_; |
| 354 scoped_ptr<net::SSLServerSocket> server_socket_; | 357 scoped_ptr<net::SSLServerSocket> server_socket_; |
| 355 net::ClientSocketFactory* socket_factory_; | 358 net::ClientSocketFactory* socket_factory_; |
| 356 scoped_ptr<net::MockCertVerifier> cert_verifier_; | 359 scoped_ptr<net::MockCertVerifier> cert_verifier_; |
| 360 scoped_ptr<net::TransportSecurityState> transport_security_state_; |
| 357 }; | 361 }; |
| 358 | 362 |
| 359 // SSLServerSocket is only implemented using NSS. | 363 // SSLServerSocket is only implemented using NSS. |
| 360 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) | 364 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) |
| 361 | 365 |
| 362 // This test only executes creation of client and server sockets. This is to | 366 // This test only executes creation of client and server sockets. This is to |
| 363 // test that creation of sockets doesn't crash and have minimal code to run | 367 // test that creation of sockets doesn't crash and have minimal code to run |
| 364 // under valgrind in order to help debugging memory problems. | 368 // under valgrind in order to help debugging memory problems. |
| 365 TEST_F(SSLServerSocketTest, Initialize) { | 369 TEST_F(SSLServerSocketTest, Initialize) { |
| 366 Initialize(); | 370 Initialize(); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 unsigned char client_bad[kKeyingMaterialSize]; | 575 unsigned char client_bad[kKeyingMaterialSize]; |
| 572 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad, | 576 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad, |
| 573 false, kKeyingContext, | 577 false, kKeyingContext, |
| 574 client_bad, sizeof(client_bad)); | 578 client_bad, sizeof(client_bad)); |
| 575 ASSERT_EQ(rv, net::OK); | 579 ASSERT_EQ(rv, net::OK); |
| 576 EXPECT_NE(0, memcmp(server_out, client_bad, sizeof(server_out))); | 580 EXPECT_NE(0, memcmp(server_out, client_bad, sizeof(server_out))); |
| 577 } | 581 } |
| 578 #endif | 582 #endif |
| 579 | 583 |
| 580 } // namespace net | 584 } // namespace net |
| OLD | NEW |