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

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 ssl_cipher_suite_names to NaCl build. 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 for (std::vector<uint16>::const_iterator it = cipher_suites.begin();
244 it != cipher_suites.end(); ++it) {
245 if (IsSecureTLSCipherSuite(*it))
246 return true;
247 }
248 return false;
249 }
250
251 // static
237 std::vector<uint8_t> SSLClientSocket::SerializeNextProtos( 252 std::vector<uint8_t> SSLClientSocket::SerializeNextProtos(
238 const std::vector<std::string>& next_protos) { 253 const std::vector<std::string>& next_protos,
254 bool advertise_http2) {
239 // Do a first pass to determine the total length. 255 // Do a first pass to determine the total length.
240 size_t wire_length = 0; 256 size_t wire_length = 0;
241 for (std::vector<std::string>::const_iterator i = next_protos.begin(); 257 for (std::vector<std::string>::const_iterator i = next_protos.begin();
242 i != next_protos.end(); ++i) { 258 i != next_protos.end(); ++i) {
243 if (i->size() > 255) { 259 if (i->size() > 255) {
244 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << *i; 260 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << *i;
245 continue; 261 continue;
246 } 262 }
247 if (i->size() == 0) { 263 if (i->size() == 0) {
248 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol"; 264 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol";
249 continue; 265 continue;
250 } 266 }
267 if (!advertise_http2) {
268 const NextProto proto = NextProtoFromString(*i);
269 if (kProtoSPDY4MinimumVersion <= proto &&
270 proto <= kProtoSPDY4MaximumVersion) {
271 continue;
272 }
273 }
251 wire_length += i->size(); 274 wire_length += i->size();
252 wire_length++; 275 wire_length++;
253 } 276 }
254 277
255 // Allocate memory for the result and fill it in. 278 // Allocate memory for the result and fill it in.
256 std::vector<uint8_t> wire_protos; 279 std::vector<uint8_t> wire_protos;
257 wire_protos.reserve(wire_length); 280 wire_protos.reserve(wire_length);
258 for (std::vector<std::string>::const_iterator i = next_protos.begin(); 281 for (std::vector<std::string>::const_iterator i = next_protos.begin();
259 i != next_protos.end(); i++) { 282 i != next_protos.end(); i++) {
260 if (i->size() == 0 || i->size() > 255) 283 if (i->size() == 0 || i->size() > 255)
261 continue; 284 continue;
285 if (!advertise_http2) {
286 const NextProto proto = NextProtoFromString(*i);
287 if (kProtoSPDY4MinimumVersion <= proto &&
288 proto <= kProtoSPDY4MaximumVersion) {
289 continue;
290 }
291 }
262 wire_protos.push_back(i->size()); 292 wire_protos.push_back(i->size());
263 wire_protos.resize(wire_protos.size() + i->size()); 293 wire_protos.resize(wire_protos.size() + i->size());
264 memcpy(&wire_protos[wire_protos.size() - i->size()], 294 memcpy(&wire_protos[wire_protos.size() - i->size()],
265 i->data(), i->size()); 295 i->data(), i->size());
266 } 296 }
267 DCHECK_EQ(wire_protos.size(), wire_length); 297 DCHECK_EQ(wire_protos.size(), wire_length);
268 298
269 return wire_protos; 299 return wire_protos;
270 } 300 }
271 301
(...skipping 17 matching lines...) Expand all
289 } else { 319 } else {
290 sample += 500; 320 sample += 500;
291 } 321 }
292 } else { 322 } else {
293 DCHECK_EQ(kExtensionALPN, negotiation_extension_); 323 DCHECK_EQ(kExtensionALPN, negotiation_extension_);
294 } 324 }
295 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample); 325 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample);
296 } 326 }
297 327
298 } // namespace net 328 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698