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

Side by Side Diff: net/socket/ssl_client_socket.cc

Issue 757033004: Do not use HTTP/2 without adequate security. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add namespace qualifier to definition. Created 6 years 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 "net/socket/ssl_client_socket.h" 5 #include "net/socket/ssl_client_socket.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/metrics/sparse_histogram.h" 8 #include "base/metrics/sparse_histogram.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "crypto/ec_private_key.h" 10 #include "crypto/ec_private_key.h"
11 #include "net/base/connection_type_histograms.h" 11 #include "net/base/connection_type_histograms.h"
12 #include "net/base/host_port_pair.h" 12 #include "net/base/host_port_pair.h"
13 #include "net/ssl/channel_id_service.h" 13 #include "net/ssl/channel_id_service.h"
14 #include "net/ssl/ssl_cipher_suite_names.h"
14 #include "net/ssl/ssl_config_service.h" 15 #include "net/ssl/ssl_config_service.h"
15 #include "net/ssl/ssl_connection_status_flags.h" 16 #include "net/ssl/ssl_connection_status_flags.h"
16 17
17 namespace net { 18 namespace net {
18 19
19 SSLClientSocket::SSLClientSocket() 20 SSLClientSocket::SSLClientSocket()
20 : was_npn_negotiated_(false), 21 : was_npn_negotiated_(false),
21 was_spdy_negotiated_(false), 22 was_spdy_negotiated_(false),
22 protocol_negotiated_(kProtoUnknown), 23 protocol_negotiated_(kProtoUnknown),
23 channel_id_sent_(false), 24 channel_id_sent_(false),
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 228 }
228 if (!channel_id_service->IsSystemTimeValid()) { 229 if (!channel_id_service->IsSystemTimeValid()) {
229 DVLOG(1) << "System time is not within the supported range for certificate " 230 DVLOG(1) << "System time is not within the supported range for certificate "
230 "generation, not enabling channel ID."; 231 "generation, not enabling channel ID.";
231 return false; 232 return false;
232 } 233 }
233 return true; 234 return true;
234 } 235 }
235 236
236 // static 237 // static
238 bool SSLClientSocket::IsSecurityAdequateForHTTP2(
239 const SSLConfig& ssl_config,
240 const std::vector<uint16>& cipher_suites) {
241 if (ssl_config.version_max < SSL_PROTOCOL_VERSION_TLS1_2) {
242 return false;
243 }
244 for (std::vector<uint16>::const_iterator it = cipher_suites.begin();
Ryan Hamilton 2014/12/10 21:11:41 for (uint16 cipher : cipher_suites) { }
Bence 2014/12/11 16:50:49 Done.
245 it != cipher_suites.end(); ++it) {
246 if (IsSecureTLSCipherSuite(*it)) {
Ryan Hamilton 2014/12/10 21:11:41 Just to confirm, this is the right check, yes?
Ryan Sleevi 2014/12/10 22:53:06 Yes
247 return true;
248 }
249 }
250 return false;
251 }
252
253 // static
237 std::vector<uint8_t> SSLClientSocket::SerializeNextProtos( 254 std::vector<uint8_t> SSLClientSocket::SerializeNextProtos(
238 const std::vector<std::string>& next_protos) { 255 const std::vector<std::string>& next_protos,
256 bool advertise_http2) {
239 // Do a first pass to determine the total length. 257 // Do a first pass to determine the total length.
240 size_t wire_length = 0; 258 size_t wire_length = 0;
241 for (std::vector<std::string>::const_iterator i = next_protos.begin(); 259 for (std::vector<std::string>::const_iterator i = next_protos.begin();
242 i != next_protos.end(); ++i) { 260 i != next_protos.end(); ++i) {
243 if (i->size() > 255) { 261 if (i->size() > 255) {
244 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << *i; 262 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << *i;
245 continue; 263 continue;
246 } 264 }
247 if (i->size() == 0) { 265 if (i->size() == 0) {
248 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol"; 266 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol";
249 continue; 267 continue;
250 } 268 }
269 if (!advertise_http2) {
davidben 2014/12/10 21:29:57 I'm mildly unhappy that the SSL layer needs to kno
Ryan Sleevi 2014/12/10 22:53:06 It's almost like you were at the last IETF meeting
Ryan Hamilton 2014/12/11 19:59:05 We thought about this when bnc and I were brainsto
270 const NextProto proto = NextProtoFromString(*i);
271 if (kProtoSPDY4MinimumVersion <= proto &&
272 proto <= kProtoSPDY4MaximumVersion) {
Ryan Hamilton 2014/12/10 21:11:41 consider adding an IsHttp2NextProto(NextProto next
Bence 2014/12/11 16:50:49 It will not be in two places after rebasing on htt
273 continue;
274 }
275 }
251 wire_length += i->size(); 276 wire_length += i->size();
252 wire_length++; 277 wire_length++;
253 } 278 }
254 279
255 // Allocate memory for the result and fill it in. 280 // Allocate memory for the result and fill it in.
256 std::vector<uint8_t> wire_protos; 281 std::vector<uint8_t> wire_protos;
257 wire_protos.reserve(wire_length); 282 wire_protos.reserve(wire_length);
258 for (std::vector<std::string>::const_iterator i = next_protos.begin(); 283 for (std::vector<std::string>::const_iterator i = next_protos.begin();
259 i != next_protos.end(); i++) { 284 i != next_protos.end(); i++) {
260 if (i->size() == 0 || i->size() > 255) 285 if (i->size() == 0 || i->size() > 255)
261 continue; 286 continue;
287 if (!advertise_http2) {
288 const NextProto proto = NextProtoFromString(*i);
289 if (kProtoSPDY4MinimumVersion <= proto &&
290 proto <= kProtoSPDY4MaximumVersion) {
291 continue;
292 }
293 }
262 wire_protos.push_back(i->size()); 294 wire_protos.push_back(i->size());
263 wire_protos.resize(wire_protos.size() + i->size()); 295 wire_protos.resize(wire_protos.size() + i->size());
264 memcpy(&wire_protos[wire_protos.size() - i->size()], 296 memcpy(&wire_protos[wire_protos.size() - i->size()],
265 i->data(), i->size()); 297 i->data(), i->size());
266 } 298 }
267 DCHECK_EQ(wire_protos.size(), wire_length); 299 DCHECK_EQ(wire_protos.size(), wire_length);
268 300
269 return wire_protos; 301 return wire_protos;
270 } 302 }
271 303
(...skipping 17 matching lines...) Expand all
289 } else { 321 } else {
290 sample += 500; 322 sample += 500;
291 } 323 }
292 } else { 324 } else {
293 DCHECK_EQ(kExtensionALPN, negotiation_extension_); 325 DCHECK_EQ(kExtensionALPN, negotiation_extension_);
294 } 326 }
295 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample); 327 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample);
296 } 328 }
297 329
298 } // namespace net 330 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698