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::HasCipherAdequateForHTTP2( |
| 239 const std::vector<uint16>& cipher_suites) { |
| 240 for (uint16 cipher : cipher_suites) { |
| 241 if (IsSecureTLSCipherSuite(cipher)) |
| 242 return true; |
| 243 } |
| 244 return false; |
| 245 } |
| 246 |
| 247 // static |
| 248 bool SSLClientSocket::IsTLSVersionAdequateForHTTP2( |
| 249 const SSLConfig& ssl_config) { |
| 250 return ssl_config.version_max >= SSL_PROTOCOL_VERSION_TLS1_2; |
| 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 NextProtoVector& next_protos, |
239 // Do a first pass to determine the total length. | 256 bool can_advertise_http2) { |
240 size_t wire_length = 0; | 257 std::vector<uint8_t> wire_protos; |
241 for (std::vector<std::string>::const_iterator i = next_protos.begin(); | 258 for (const NextProto next_proto : next_protos) { |
242 i != next_protos.end(); ++i) { | 259 if (!can_advertise_http2 && kProtoSPDY4MinimumVersion <= next_proto && |
243 if (i->size() > 255) { | 260 next_proto <= kProtoSPDY4MaximumVersion) { |
244 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << *i; | |
245 continue; | 261 continue; |
246 } | 262 } |
247 if (i->size() == 0) { | 263 const std::string proto = NextProtoToString(next_proto); |
| 264 if (proto.size() > 255) { |
| 265 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << proto; |
| 266 continue; |
| 267 } |
| 268 if (proto.size() == 0) { |
248 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol"; | 269 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol"; |
249 continue; | 270 continue; |
250 } | 271 } |
251 wire_length += i->size(); | 272 wire_protos.push_back(proto.size()); |
252 wire_length++; | 273 for (const char ch : proto) { |
| 274 wire_protos.push_back(static_cast<uint8_t>(ch)); |
| 275 } |
253 } | 276 } |
254 | 277 |
255 // Allocate memory for the result and fill it in. | |
256 std::vector<uint8_t> wire_protos; | |
257 wire_protos.reserve(wire_length); | |
258 for (std::vector<std::string>::const_iterator i = next_protos.begin(); | |
259 i != next_protos.end(); i++) { | |
260 if (i->size() == 0 || i->size() > 255) | |
261 continue; | |
262 wire_protos.push_back(i->size()); | |
263 wire_protos.resize(wire_protos.size() + i->size()); | |
264 memcpy(&wire_protos[wire_protos.size() - i->size()], | |
265 i->data(), i->size()); | |
266 } | |
267 DCHECK_EQ(wire_protos.size(), wire_length); | |
268 | |
269 return wire_protos; | 278 return wire_protos; |
270 } | 279 } |
271 | 280 |
272 void SSLClientSocket::RecordNegotiationExtension() { | 281 void SSLClientSocket::RecordNegotiationExtension() { |
273 if (negotiation_extension_ == kExtensionUnknown) | 282 if (negotiation_extension_ == kExtensionUnknown) |
274 return; | 283 return; |
275 std::string proto; | 284 std::string proto; |
276 SSLClientSocket::NextProtoStatus status = GetNextProto(&proto); | 285 SSLClientSocket::NextProtoStatus status = GetNextProto(&proto); |
277 if (status == kNextProtoUnsupported) | 286 if (status == kNextProtoUnsupported) |
278 return; | 287 return; |
(...skipping 10 matching lines...) Expand all Loading... |
289 } else { | 298 } else { |
290 sample += 500; | 299 sample += 500; |
291 } | 300 } |
292 } else { | 301 } else { |
293 DCHECK_EQ(kExtensionALPN, negotiation_extension_); | 302 DCHECK_EQ(kExtensionALPN, negotiation_extension_); |
294 } | 303 } |
295 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample); | 304 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample); |
296 } | 305 } |
297 | 306 |
298 } // namespace net | 307 } // namespace net |
OLD | NEW |