Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(744)

Side by Side Diff: net/http/http_network_transaction_ssl_unittest.cc

Issue 1139013002: Completely remove SSLv3 support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "net/base/net_util.h" 10 #include "net/base/net_util.h"
11 #include "net/base/request_priority.h" 11 #include "net/base/request_priority.h"
12 #include "net/dns/mock_host_resolver.h" 12 #include "net/dns/mock_host_resolver.h"
13 #include "net/http/http_auth_handler_mock.h" 13 #include "net/http/http_auth_handler_mock.h"
14 #include "net/http/http_network_session.h" 14 #include "net/http/http_network_session.h"
15 #include "net/http/http_network_transaction.h" 15 #include "net/http/http_network_transaction.h"
16 #include "net/http/http_request_info.h" 16 #include "net/http/http_request_info.h"
17 #include "net/http/http_server_properties_impl.h" 17 #include "net/http/http_server_properties_impl.h"
18 #include "net/http/transport_security_state.h" 18 #include "net/http/transport_security_state.h"
19 #include "net/proxy/proxy_service.h" 19 #include "net/proxy/proxy_service.h"
20 #include "net/socket/socket_test_util.h" 20 #include "net/socket/socket_test_util.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 namespace net { 23 namespace net {
24 24
25 namespace { 25 namespace {
26 26
27 class TLS10SSLConfigService : public SSLConfigService { 27 class TLS10SSLConfigService : public SSLConfigService {
28 public: 28 public:
29 TLS10SSLConfigService() { 29 TLS10SSLConfigService() {
30 ssl_config_.version_min = SSL_PROTOCOL_VERSION_SSL3; 30 ssl_config_.version_min = SSL_PROTOCOL_VERSION_TLS1;
31 ssl_config_.version_max = SSL_PROTOCOL_VERSION_TLS1; 31 ssl_config_.version_max = SSL_PROTOCOL_VERSION_TLS1;
32 } 32 }
33 33
34 void GetSSLConfig(SSLConfig* config) override { *config = ssl_config_; } 34 void GetSSLConfig(SSLConfig* config) override { *config = ssl_config_; }
35 35
36 private: 36 private:
37 ~TLS10SSLConfigService() override {} 37 ~TLS10SSLConfigService() override {}
38 38
39 SSLConfig ssl_config_; 39 SSLConfig ssl_config_;
40 }; 40 };
41 41
42 class TLS11SSLConfigService : public SSLConfigService { 42 class TLS12SSLConfigService : public SSLConfigService {
43 public: 43 public:
44 TLS11SSLConfigService() { 44 TLS12SSLConfigService() {
45 ssl_config_.version_min = SSL_PROTOCOL_VERSION_SSL3; 45 ssl_config_.version_min = SSL_PROTOCOL_VERSION_TLS1;
46 ssl_config_.version_max = SSL_PROTOCOL_VERSION_TLS1_1; 46 ssl_config_.version_max = SSL_PROTOCOL_VERSION_TLS1_2;
47 } 47 }
48 48
49 void GetSSLConfig(SSLConfig* config) override { *config = ssl_config_; } 49 void GetSSLConfig(SSLConfig* config) override { *config = ssl_config_; }
50 50
51 private: 51 private:
52 ~TLS11SSLConfigService() override {} 52 ~TLS12SSLConfigService() override {}
53 53
54 SSLConfig ssl_config_; 54 SSLConfig ssl_config_;
55 }; 55 };
56 56
57 } // namespace 57 } // namespace
58 58
59 class HttpNetworkTransactionSSLTest : public testing::Test { 59 class HttpNetworkTransactionSSLTest : public testing::Test {
60 protected: 60 protected:
61 void SetUp() override { 61 void SetUp() override {
62 ssl_config_service_ = new TLS10SSLConfigService; 62 ssl_config_service_ = new TLS10SSLConfigService;
(...skipping 30 matching lines...) Expand all
93 93
94 MockClientSocketFactory mock_socket_factory_; 94 MockClientSocketFactory mock_socket_factory_;
95 MockHostResolver mock_resolver_; 95 MockHostResolver mock_resolver_;
96 HttpServerPropertiesImpl http_server_properties_; 96 HttpServerPropertiesImpl http_server_properties_;
97 TransportSecurityState transport_security_state_; 97 TransportSecurityState transport_security_state_;
98 HttpNetworkSession::Params session_params_; 98 HttpNetworkSession::Params session_params_;
99 ScopedVector<HttpRequestInfo> request_info_vector_; 99 ScopedVector<HttpRequestInfo> request_info_vector_;
100 }; 100 };
101 101
102 // Tests that HttpNetworkTransaction attempts to fallback from 102 // Tests that HttpNetworkTransaction attempts to fallback from
103 // TLS 1.1 to TLS 1.0, then from TLS 1.0 to SSL 3.0. 103 // TLS 1.2 to TLS 1.1, then from TLS 1.1 to TLS 1.0.
104 TEST_F(HttpNetworkTransactionSSLTest, SSLFallback) { 104 TEST_F(HttpNetworkTransactionSSLTest, SSLFallback) {
105 ssl_config_service_ = new TLS11SSLConfigService; 105 ssl_config_service_ = new TLS12SSLConfigService;
106 session_params_.ssl_config_service = ssl_config_service_.get(); 106 session_params_.ssl_config_service = ssl_config_service_.get();
107 // |ssl_data1| is for the first handshake (TLS 1.1), which will fail 107 // |ssl_data1| is for the first handshake (TLS 1.2), which will fail
108 // for protocol reasons (e.g., simulating a version rollback attack). 108 // for protocol reasons (e.g., simulating a version rollback attack).
109 SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_PROTOCOL_ERROR); 109 SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_PROTOCOL_ERROR);
110 mock_socket_factory_.AddSSLSocketDataProvider(&ssl_data1); 110 mock_socket_factory_.AddSSLSocketDataProvider(&ssl_data1);
111 StaticSocketDataProvider data1(NULL, 0, NULL, 0); 111 StaticSocketDataProvider data1(NULL, 0, NULL, 0);
112 mock_socket_factory_.AddSocketDataProvider(&data1); 112 mock_socket_factory_.AddSocketDataProvider(&data1);
113 113
114 // |ssl_data2| contains the handshake result for a TLS 1.0 114 // |ssl_data2| contains the handshake result for a TLS 1.1
115 // handshake which will be attempted after the TLS 1.1 115 // handshake which will be attempted after the TLS 1.2
116 // handshake fails. 116 // handshake fails.
117 SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); 117 SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR);
118 mock_socket_factory_.AddSSLSocketDataProvider(&ssl_data2); 118 mock_socket_factory_.AddSSLSocketDataProvider(&ssl_data2);
119 StaticSocketDataProvider data2(NULL, 0, NULL, 0); 119 StaticSocketDataProvider data2(NULL, 0, NULL, 0);
120 mock_socket_factory_.AddSocketDataProvider(&data2); 120 mock_socket_factory_.AddSocketDataProvider(&data2);
121 121
122 // |ssl_data3| contains the handshake result for a SSL 3.0 122 // |ssl_data3| contains the handshake result for a TLS 1.0
123 // handshake which will be attempted after the TLS 1.0 123 // handshake which will be attempted after the TLS 1.1
124 // handshake fails. 124 // handshake fails.
125 SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); 125 SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR);
126 mock_socket_factory_.AddSSLSocketDataProvider(&ssl_data3); 126 mock_socket_factory_.AddSSLSocketDataProvider(&ssl_data3);
127 StaticSocketDataProvider data3(NULL, 0, NULL, 0); 127 StaticSocketDataProvider data3(NULL, 0, NULL, 0);
128 mock_socket_factory_.AddSocketDataProvider(&data3); 128 mock_socket_factory_.AddSocketDataProvider(&data3);
129 129
130 scoped_refptr<HttpNetworkSession> session( 130 scoped_refptr<HttpNetworkSession> session(
131 new HttpNetworkSession(session_params_)); 131 new HttpNetworkSession(session_params_));
132 scoped_ptr<HttpNetworkTransaction> trans( 132 scoped_ptr<HttpNetworkTransaction> trans(
133 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 133 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
134 134
135 TestCompletionCallback callback; 135 TestCompletionCallback callback;
136 // This will consume |ssl_data1|, |ssl_data2| and |ssl_data3|. 136 // This will consume |ssl_data1|, |ssl_data2| and |ssl_data3|.
137 int rv = callback.GetResult( 137 int rv = callback.GetResult(
138 trans->Start(GetRequestInfo("https://www.paypal.com/"), 138 trans->Start(GetRequestInfo("https://www.paypal.com/"),
139 callback.callback(), BoundNetLog())); 139 callback.callback(), BoundNetLog()));
140 EXPECT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); 140 EXPECT_EQ(ERR_SSL_PROTOCOL_ERROR, rv);
141 141
142 SocketDataProviderArray<SocketDataProvider>& mock_data = 142 SocketDataProviderArray<SocketDataProvider>& mock_data =
143 mock_socket_factory_.mock_data(); 143 mock_socket_factory_.mock_data();
144 // Confirms that |ssl_data1|, |ssl_data2| and |ssl_data3| are consumed. 144 // Confirms that |ssl_data1|, |ssl_data2| and |ssl_data3| are consumed.
145 EXPECT_EQ(3u, mock_data.next_index()); 145 EXPECT_EQ(3u, mock_data.next_index());
146 146
147 SSLConfig& ssl_config = GetServerSSLConfig(trans.get()); 147 SSLConfig& ssl_config = GetServerSSLConfig(trans.get());
148 // |version_max| fallbacks to SSL 3.0. 148 // |version_max| fallbacks to TLS 1.0.
149 EXPECT_EQ(SSL_PROTOCOL_VERSION_SSL3, ssl_config.version_max); 149 EXPECT_EQ(SSL_PROTOCOL_VERSION_TLS1, ssl_config.version_max);
150 EXPECT_TRUE(ssl_config.version_fallback); 150 EXPECT_TRUE(ssl_config.version_fallback);
151 } 151 }
152 152
153 } // namespace net 153 } // namespace net
154 154
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698