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 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 (uint16 cipher : cipher_suites) { | |
244 if (IsSecureTLSCipherSuite(cipher)) | |
245 return true; | |
246 } | |
247 return false; | |
248 } | |
249 | |
250 // static | |
237 std::vector<uint8_t> SSLClientSocket::SerializeNextProtos( | 251 std::vector<uint8_t> SSLClientSocket::SerializeNextProtos( |
238 const NextProtoVector& next_protos) { | 252 const NextProtoVector& next_protos, |
239 // Do a first pass to determine the total length. | 253 bool can_advertise_http2) { |
240 size_t wire_length = 0; | 254 size_t wire_length = 0; |
241 std::vector<std::string> next_proto_strings; | 255 std::vector<std::string> next_proto_strings; |
242 for (const NextProto next_proto : next_protos) { | 256 for (const NextProto next_proto : next_protos) { |
257 if (!can_advertise_http2) { | |
258 if (kProtoSPDY4MinimumVersion <= next_proto && | |
259 next_proto <= kProtoSPDY4MaximumVersion) { | |
Bence
2014/12/11 16:50:49
Ryan: do I need to use curly braces if the stateme
Ryan Hamilton
2014/12/11 20:06:09
Yes, that's the convention. I'm not sure this is o
Bence
2014/12/12 15:49:24
Acknowledged.
| |
260 continue; | |
261 } | |
262 } | |
243 const std::string proto = NextProtoToString(next_proto); | 263 const std::string proto = NextProtoToString(next_proto); |
244 if (proto.size() > 255) { | 264 if (proto.size() > 255) { |
245 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << proto; | 265 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << proto; |
246 continue; | 266 continue; |
247 } | 267 } |
248 if (proto.size() == 0) { | 268 if (proto.size() == 0) { |
249 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol"; | 269 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol"; |
250 continue; | 270 continue; |
251 } | 271 } |
252 next_proto_strings.push_back(proto); | 272 next_proto_strings.push_back(proto); |
253 wire_length += proto.size(); | 273 wire_length += proto.size(); |
254 wire_length++; | 274 wire_length++; |
255 } | 275 } |
256 | 276 |
257 // Allocate memory for the result and fill it in. | |
258 std::vector<uint8_t> wire_protos; | 277 std::vector<uint8_t> wire_protos; |
259 wire_protos.reserve(wire_length); | 278 wire_protos.reserve(wire_length); |
260 for (const std::string& proto : next_proto_strings) { | 279 for (const std::string& proto : next_proto_strings) { |
261 wire_protos.push_back(proto.size()); | 280 wire_protos.push_back(proto.size()); |
262 // TODO(bnc): Rewrite. | 281 // TODO(bnc): Rewrite. |
263 wire_protos.resize(wire_protos.size() + proto.size()); | 282 wire_protos.resize(wire_protos.size() + proto.size()); |
264 memcpy(&wire_protos[wire_protos.size() - proto.size()], proto.data(), | 283 memcpy(&wire_protos[wire_protos.size() - proto.size()], proto.data(), |
265 proto.size()); | 284 proto.size()); |
266 } | 285 } |
267 DCHECK_EQ(wire_protos.size(), wire_length); | 286 DCHECK_EQ(wire_protos.size(), wire_length); |
(...skipping 21 matching lines...) Expand all Loading... | |
289 } else { | 308 } else { |
290 sample += 500; | 309 sample += 500; |
291 } | 310 } |
292 } else { | 311 } else { |
293 DCHECK_EQ(kExtensionALPN, negotiation_extension_); | 312 DCHECK_EQ(kExtensionALPN, negotiation_extension_); |
294 } | 313 } |
295 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample); | 314 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample); |
296 } | 315 } |
297 | 316 |
298 } // namespace net | 317 } // namespace net |
OLD | NEW |