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