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 "net/base/address_list.h" | 9 #include "net/base/address_list.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 1775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1786 scoped_refptr<SSLCertRequestInfo> request_info = GetCertRequest(ssl_options); | 1786 scoped_refptr<SSLCertRequestInfo> request_info = GetCertRequest(ssl_options); |
1787 ASSERT_TRUE(request_info.get()); | 1787 ASSERT_TRUE(request_info.get()); |
1788 ASSERT_EQ(2u, request_info->cert_authorities.size()); | 1788 ASSERT_EQ(2u, request_info->cert_authorities.size()); |
1789 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kThawteDN), kThawteLen), | 1789 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kThawteDN), kThawteLen), |
1790 request_info->cert_authorities[0]); | 1790 request_info->cert_authorities[0]); |
1791 EXPECT_EQ( | 1791 EXPECT_EQ( |
1792 std::string(reinterpret_cast<const char*>(kDiginotarDN), kDiginotarLen), | 1792 std::string(reinterpret_cast<const char*>(kDiginotarDN), kDiginotarLen), |
1793 request_info->cert_authorities[1]); | 1793 request_info->cert_authorities[1]); |
1794 } | 1794 } |
1795 | 1795 |
| 1796 TEST_F(SSLClientSocketTest, ConnectSignedCertTimestampsEnabled) { |
| 1797 SpawnedTestServer::SSLOptions ssl_options; |
| 1798 // base64 of "test". |
| 1799 ssl_options.signed_cert_timestamps = "dGVzdA=="; |
| 1800 |
| 1801 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, |
| 1802 ssl_options, |
| 1803 base::FilePath()); |
| 1804 ASSERT_TRUE(test_server.Start()); |
| 1805 |
| 1806 AddressList addr; |
| 1807 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 1808 |
| 1809 TestCompletionCallback callback; |
| 1810 CapturingNetLog log; |
| 1811 scoped_ptr<StreamSocket> transport( |
| 1812 new TCPClientSocket(addr, &log, NetLog::Source())); |
| 1813 int rv = transport->Connect(callback.callback()); |
| 1814 if (rv == ERR_IO_PENDING) |
| 1815 rv = callback.WaitForResult(); |
| 1816 EXPECT_EQ(OK, rv); |
| 1817 |
| 1818 SSLConfig ssl_config; |
| 1819 ssl_config.signed_cert_timestamps_enabled = true; |
| 1820 |
| 1821 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 1822 transport.Pass(), test_server.host_port_pair(), ssl_config)); |
| 1823 |
| 1824 EXPECT_FALSE(sock->IsConnected()); |
| 1825 |
| 1826 rv = sock->Connect(callback.callback()); |
| 1827 |
| 1828 CapturingNetLog::CapturedEntryList entries; |
| 1829 log.GetEntries(&entries); |
| 1830 EXPECT_TRUE(LogContainsBeginEvent(entries, 5, NetLog::TYPE_SSL_CONNECT)); |
| 1831 if (rv == ERR_IO_PENDING) |
| 1832 rv = callback.WaitForResult(); |
| 1833 EXPECT_EQ(OK, rv); |
| 1834 EXPECT_TRUE(sock->IsConnected()); |
| 1835 log.GetEntries(&entries); |
| 1836 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1)); |
| 1837 |
| 1838 #if !defined(USE_OPENSSL) |
| 1839 EXPECT_TRUE(sock->WereSignedCertTimestampsReceived()); |
| 1840 #else |
| 1841 // Enabling CT for OpenSSL is currently a noop. |
| 1842 EXPECT_FALSE(sock->WereSignedCertTimestampsReceived()); |
| 1843 #endif |
| 1844 |
| 1845 sock->Disconnect(); |
| 1846 EXPECT_FALSE(sock->IsConnected()); |
| 1847 } |
| 1848 |
| 1849 TEST_F(SSLClientSocketTest, ConnectSignedCertTimestampsDisabled) { |
| 1850 SpawnedTestServer::SSLOptions ssl_options; |
| 1851 // base64 of "test". |
| 1852 ssl_options.signed_cert_timestamps = "dGVzdA=="; |
| 1853 |
| 1854 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, |
| 1855 ssl_options, |
| 1856 base::FilePath()); |
| 1857 ASSERT_TRUE(test_server.Start()); |
| 1858 |
| 1859 AddressList addr; |
| 1860 ASSERT_TRUE(test_server.GetAddressList(&addr)); |
| 1861 |
| 1862 TestCompletionCallback callback; |
| 1863 CapturingNetLog log; |
| 1864 scoped_ptr<StreamSocket> transport( |
| 1865 new TCPClientSocket(addr, &log, NetLog::Source())); |
| 1866 int rv = transport->Connect(callback.callback()); |
| 1867 if (rv == ERR_IO_PENDING) |
| 1868 rv = callback.WaitForResult(); |
| 1869 EXPECT_EQ(OK, rv); |
| 1870 |
| 1871 SSLConfig ssl_config; |
| 1872 ssl_config.signed_cert_timestamps_enabled = false; |
| 1873 |
| 1874 scoped_ptr<SSLClientSocket> sock(CreateSSLClientSocket( |
| 1875 transport.Pass(), test_server.host_port_pair(), ssl_config)); |
| 1876 |
| 1877 EXPECT_FALSE(sock->IsConnected()); |
| 1878 |
| 1879 rv = sock->Connect(callback.callback()); |
| 1880 |
| 1881 CapturingNetLog::CapturedEntryList entries; |
| 1882 log.GetEntries(&entries); |
| 1883 EXPECT_TRUE(LogContainsBeginEvent(entries, 5, NetLog::TYPE_SSL_CONNECT)); |
| 1884 if (rv == ERR_IO_PENDING) |
| 1885 rv = callback.WaitForResult(); |
| 1886 EXPECT_EQ(OK, rv); |
| 1887 EXPECT_TRUE(sock->IsConnected()); |
| 1888 log.GetEntries(&entries); |
| 1889 EXPECT_TRUE(LogContainsSSLConnectEndEvent(entries, -1)); |
| 1890 |
| 1891 EXPECT_FALSE(sock->WereSignedCertTimestampsReceived()); |
| 1892 |
| 1893 sock->Disconnect(); |
| 1894 EXPECT_FALSE(sock->IsConnected()); |
| 1895 } |
| 1896 |
1796 } // namespace | 1897 } // namespace |
1797 | 1898 |
1798 } // namespace net | 1899 } // namespace net |
OLD | NEW |