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

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

Issue 14125003: Do not roll back to SSL 3.0 for Google properties. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 7 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "net/base/net_util.h"
10 #include "net/base/request_priority.h"
11 #include "net/dns/mock_host_resolver.h"
12 #include "net/http/http_auth_handler_mock.h"
13 #include "net/http/http_network_session.h"
14 #include "net/http/http_network_transaction.h"
15 #include "net/http/http_request_info.h"
16 #include "net/http/http_server_properties_impl.h"
17 #include "net/http/transport_security_state.h"
18 #include "net/proxy/proxy_service.h"
19 #include "net/socket/socket_test_util.h"
20 #include "net/ssl/ssl_config_service_defaults.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22
23 namespace net {
24
25 class HttpNetworkTransactionSSLTest : public testing::Test {
26 protected:
27 virtual void SetUp() {
28 ssl_config_ = new SSLConfigServiceDefaults;
29 session_params_.ssl_config_service = ssl_config_.get();
30
31 auth_handler_factory_.reset(new HttpAuthHandlerMock::Factory());
32 session_params_.http_auth_handler_factory = auth_handler_factory_.get();
33
34 proxy_service_.reset(ProxyService::CreateDirect());
35 session_params_.proxy_service = proxy_service_.get();
36
37 session_params_.host_resolver = &mock_resolver_;
38 session_params_.http_server_properties = &http_server_properties_;
39 session_params_.transport_security_state = &transport_security_state_;
40 }
41
42 HttpRequestInfo* GetRequestInfo(std::string url) {
43 HttpRequestInfo* request_info = new HttpRequestInfo;
44 request_info->url = GURL(url);
45 request_info->method = "GET";
46 return request_info;
47 }
48
49 SSLConfig& GetServerSSLConfig(HttpNetworkTransaction* trans) {
50 return trans->server_ssl_config_;
51 }
52
53 scoped_refptr<SSLConfigService> ssl_config_;
54 scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory_;
55 scoped_ptr<ProxyService> proxy_service_;
56
57 MockHostResolver mock_resolver_;
58 HttpServerPropertiesImpl http_server_properties_;
59 TransportSecurityState transport_security_state_;
60 HttpNetworkSession::Params session_params_;
61 };
62
63 TEST_F(HttpNetworkTransactionSSLTest, Google_SSLVersionMinPreloadedEnabled) {
64 MockClientSocketFactory mock_socket_factory;
Ryan Sleevi 2013/04/17 01:16:36 Seems like all your tests just end up creating a m
thaidn_google 2013/04/17 04:34:47 Nice tip. Thanks! On 2013/04/17 01:16:36, Ryan Sl
65
66 // |ssl_data| contains the data for the first TLS 1.0 handshake that will
67 // return |ERR_SSL_PROTOCOL_ERROR| to trigger the SSL 3.0 fallback logic in
68 // |HttpNetworkTransaction|.
Ryan Sleevi 2013/04/17 01:16:36 comment style nit: While the || notation isn't for
thaidn_google 2013/04/17 04:34:47 Good to know. Thanks! On 2013/04/17 01:16:36, Rya
69
70 // Note: When a connection to a server fails during a handshake,
71 // |HttpNetworkTransaction| will attempt to fallback to SSL 3.0 if the
72 // previous connection was attempted with TLS 1.0. Since that behavior is
Ryan Sleevi 2013/04/17 01:16:36 comment nit: Two bits: 1) This is explaining a con
thaidn_google 2013/04/17 04:34:47 I hope the modified comments LGTY :-). On 2013/04
73 // disabled for Google properties, there is only one handshake data here.
74 SSLSocketDataProvider ssl_data(ASYNC, ERR_SSL_PROTOCOL_ERROR);
75 mock_socket_factory.AddSSLSocketDataProvider(&ssl_data);
76 net::StaticSocketDataProvider data(NULL, 0, NULL, 0);
Ryan Sleevi 2013/04/17 01:16:36 style: net:: namespace issues still
thaidn_google 2013/04/17 04:34:47 Done.
77 mock_socket_factory.AddSocketDataProvider(&data);
78
79 session_params_.client_socket_factory = &mock_socket_factory;
80
81 scoped_refptr<HttpNetworkSession> session(
82 new HttpNetworkSession(session_params_));
83 scoped_ptr<HttpNetworkTransaction> trans(
84 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
85 TestCompletionCallback callback;
Ryan Sleevi 2013/04/17 01:16:36 style nit: Move the TestCompletionCallback declara
thaidn_google 2013/04/17 04:34:47 Done.
86
87 SSLConfig& ssl_config = GetServerSSLConfig(trans.get());
88 // Explicitly configures the maximum supported SSL version to TLS 1.0.
89 ssl_config.version_max = SSL_PROTOCOL_VERSION_TLS1;
Ryan Sleevi 2013/04/17 01:16:36 Seems like this could be done in the test harness
thaidn_google 2013/04/17 04:34:47 Done.
90
91 // This will consume |ssl_data|.
92 int rv = callback.GetResult(
93 trans->Start(GetRequestInfo("https://www.google.com/"),
94 callback.callback(), BoundNetLog()));
95 EXPECT_EQ(ERR_SSL_PROTOCOL_ERROR, rv);
96
97 // |version_max| never fallbacks to SSLv3 for Google properties.
98 EXPECT_EQ(SSL_PROTOCOL_VERSION_TLS1,
99 ssl_config.version_max);
100 EXPECT_FALSE(ssl_config.version_fallback);
101 }
102
103 TEST_F(HttpNetworkTransactionSSLTest, Google_SSLVersionMinPreloadedDisabled) {
104 MockClientSocketFactory mock_socket_factory;
105
106 // |ssl_data1| contains the data for the first TLS 1.0 handshake that will
107 // return |ERR_SSL_PROTOCOL_ERROR| to trigger the SSL 3.0 fallback logic in
108 // |HttpNetworkTransaction|.
109 SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_PROTOCOL_ERROR);
110 mock_socket_factory.AddSSLSocketDataProvider(&ssl_data1);
111 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0);
112 mock_socket_factory.AddSocketDataProvider(&data1);
113
114 // |ssl_data2| contains the data for the second SSL 3.0 handshake. When a
115 // connection to a server fails during a handshake,
116 // |HttpNetworkTransaction| will attempt to fallback to SSL 3.0 if the
117 // previous connection was attempted with TLS 1.0. This is transparent to the
118 // caller of the |HttpNetworkTransaction|.
Ryan Sleevi 2013/04/17 01:16:36 With the comments from line 72 incorporated (eg: i
thaidn_google 2013/04/17 04:34:47 Done.
119
120 // Note: if |ssl_data2| is omitted (like in
121 // |Google_SSLVersionMinPreloadedEnabled|) then this test will crash, because
122 // |HttpNetworkTransaction| will attempt to handshake two times, but there is
123 // only one handshake data.
Ryan Sleevi 2013/04/17 01:16:36 comment nit: I'm generally not fond of inter-test
thaidn_google 2013/04/17 04:34:47 I agree. On 2013/04/17 01:16:36, Ryan Sleevi wrot
124 SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR);
125 mock_socket_factory.AddSSLSocketDataProvider(&ssl_data2);
126 net::StaticSocketDataProvider data2(NULL, 0, NULL, 0);
127 mock_socket_factory.AddSocketDataProvider(&data2);
128
129 session_params_.client_socket_factory = &mock_socket_factory;
130
131 scoped_refptr<HttpNetworkSession> session(
132 new HttpNetworkSession(session_params_));
133 scoped_ptr<HttpNetworkTransaction> trans(
134 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
135 TestCompletionCallback callback;
136
137 SSLConfig& ssl_config = GetServerSSLConfig(trans.get());
138 // Explicitly configures the maximum supported SSL version to TLS 1.0.
139 ssl_config.version_max = SSL_PROTOCOL_VERSION_TLS1;
140
141 ssl_config.ssl_version_min_preloaded_disabled = true;
142
143 // This will consume |ssl_data1| and |ssl_data2|.
144 int rv = callback.GetResult(
145 trans->Start(GetRequestInfo("https://www.google.com/"),
146 callback.callback(), BoundNetLog()));
147 EXPECT_EQ(ERR_SSL_PROTOCOL_ERROR, rv);
148
149 // |version_max| fallbacks to SSL 3.0 for Google properties when
150 // |ssl_version_min_preloaded_disabled| is true.
151 EXPECT_EQ(SSL_PROTOCOL_VERSION_SSL3,
152 ssl_config.version_max);
153 EXPECT_TRUE(ssl_config.version_fallback);
154 }
155
156 TEST_F(HttpNetworkTransactionSSLTest, PayPal_SSLVersionMinPreloadedDisabled) {
157 MockClientSocketFactory mock_socket_factory;
158 // |ssl_data1| contains the data for the first TLS 1.0 handshake that will
159 // return |ERR_SSL_PROTOCOL_ERROR| to trigger the SSL 3.0 fallback logic in
160 // |HttpNetworkTransaction|.
161 SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_PROTOCOL_ERROR);
162 mock_socket_factory.AddSSLSocketDataProvider(&ssl_data1);
163 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0);
164 mock_socket_factory.AddSocketDataProvider(&data1);
165
166 // |ssl_data2| contains the data for the second SSL 3.0 handshake. When a
167 // connection to a server fails during a handshake,
168 // |HttpNetworkTransaction| will attempt to fallback to SSL 3.0 if the
169 // previous connection was attempted with TLS 1.0. This is transparent to the
170 // caller of the |HttpNetworkTransaction|.
171
172 // Note: if |ssl_data2| is omitted (like in
173 // |Google_SSLVersionMinPreloadedEnabled|) then this test will crash, because
174 // |HttpNetworkTransaction| will attempt to handshake two times, but there is
175 // only one handshake data.
176 SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR);
177 mock_socket_factory.AddSSLSocketDataProvider(&ssl_data2);
178 net::StaticSocketDataProvider data2(NULL, 0, NULL, 0);
179 mock_socket_factory.AddSocketDataProvider(&data2);
180
181 session_params_.client_socket_factory = &mock_socket_factory;
182
183 scoped_refptr<HttpNetworkSession> session(
184 new HttpNetworkSession(session_params_));
185 scoped_ptr<HttpNetworkTransaction> trans(
186 new HttpNetworkTransaction(DEFAULT_PRIORITY, session));
187 TestCompletionCallback callback;
188
189 SSLConfig& ssl_config = GetServerSSLConfig(trans.get());
190 // Explicitly configures the maximum supported SSL version to TLS 1.0.
191 ssl_config.version_max = SSL_PROTOCOL_VERSION_TLS1;
192
193 // This will consume |ssl_data1| and |ssl_data2|.
194 int rv = callback.GetResult(
195 trans->Start(GetRequestInfo("https://www.paypal.com/"),
196 callback.callback(), BoundNetLog()));
197 EXPECT_EQ(ERR_SSL_PROTOCOL_ERROR, rv);
198
199 // |version_max| fallbacks to SSL 3.0.
200 EXPECT_EQ(SSL_PROTOCOL_VERSION_SSL3,
201 ssl_config.version_max);
Ryan Sleevi 2013/04/17 01:16:36 Is wrapping really necessary here?
thaidn_google 2013/04/17 04:34:47 Done.
202 EXPECT_TRUE(ssl_config.version_fallback);
203 }
204
205 } // namespace net
206
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698