Chromium Code Reviews| 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" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 if (!channel_id_service->IsSystemTimeValid()) { | 228 if (!channel_id_service->IsSystemTimeValid()) { |
| 229 DVLOG(1) << "System time is not within the supported range for certificate " | 229 DVLOG(1) << "System time is not within the supported range for certificate " |
| 230 "generation, not enabling channel ID."; | 230 "generation, not enabling channel ID."; |
| 231 return false; | 231 return false; |
| 232 } | 232 } |
| 233 return true; | 233 return true; |
| 234 } | 234 } |
| 235 | 235 |
| 236 // static | 236 // static |
| 237 std::vector<uint8_t> SSLClientSocket::SerializeNextProtos( | 237 std::vector<uint8_t> SSLClientSocket::SerializeNextProtos( |
| 238 const std::vector<std::string>& next_protos) { | 238 const NextProtoVector& next_protos) { |
| 239 // Do a first pass to determine the total length. | 239 // Do a first pass to determine the total length. |
| 240 size_t wire_length = 0; | 240 size_t wire_length = 0; |
| 241 for (std::vector<std::string>::const_iterator i = next_protos.begin(); | 241 std::vector<std::string> next_proto_strings; |
| 242 i != next_protos.end(); ++i) { | 242 for (const auto& it : next_protos) { |
|
Ryan Hamilton
2014/12/10 20:09:00
Prefer using the actual type to auto if the type i
Bence
2014/12/10 22:01:23
Done.
| |
| 243 if (i->size() > 255) { | 243 const std::string proto = NextProtoToString(it); |
| 244 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << *i; | 244 if (proto.size() > 255) { |
| 245 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << proto; | |
| 245 continue; | 246 continue; |
| 246 } | 247 } |
| 247 if (i->size() == 0) { | 248 if (proto.size() == 0) { |
| 248 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol"; | 249 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol"; |
| 249 continue; | 250 continue; |
| 250 } | 251 } |
| 251 wire_length += i->size(); | 252 next_proto_strings.push_back(proto); |
| 253 wire_length += proto.size(); | |
| 252 wire_length++; | 254 wire_length++; |
| 253 } | 255 } |
| 254 | 256 |
| 255 // Allocate memory for the result and fill it in. | 257 // Allocate memory for the result and fill it in. |
| 256 std::vector<uint8_t> wire_protos; | 258 std::vector<uint8_t> wire_protos; |
| 257 wire_protos.reserve(wire_length); | 259 wire_protos.reserve(wire_length); |
| 258 for (std::vector<std::string>::const_iterator i = next_protos.begin(); | 260 for (const auto& it : next_proto_strings) { |
|
Ryan Hamilton
2014/12/10 20:09:00
ditto.
Bence
2014/12/10 22:01:23
Done.
| |
| 259 i != next_protos.end(); i++) { | 261 wire_protos.push_back(it.size()); |
| 260 if (i->size() == 0 || i->size() > 255) | 262 wire_protos.resize(wire_protos.size() + it.size()); |
| 261 continue; | 263 memcpy(&wire_protos[wire_protos.size() - it.size()], it.data(), it.size()); |
|
Ryan Hamilton
2014/12/10 20:09:00
This code (which you did not write) looks complete
Bence
2014/12/10 22:01:23
Done.
| |
| 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 } | 264 } |
| 267 DCHECK_EQ(wire_protos.size(), wire_length); | 265 DCHECK_EQ(wire_protos.size(), wire_length); |
| 268 | 266 |
| 269 return wire_protos; | 267 return wire_protos; |
| 270 } | 268 } |
| 271 | 269 |
| 272 void SSLClientSocket::RecordNegotiationExtension() { | 270 void SSLClientSocket::RecordNegotiationExtension() { |
| 273 if (negotiation_extension_ == kExtensionUnknown) | 271 if (negotiation_extension_ == kExtensionUnknown) |
| 274 return; | 272 return; |
| 275 std::string proto; | 273 std::string proto; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 289 } else { | 287 } else { |
| 290 sample += 500; | 288 sample += 500; |
| 291 } | 289 } |
| 292 } else { | 290 } else { |
| 293 DCHECK_EQ(kExtensionALPN, negotiation_extension_); | 291 DCHECK_EQ(kExtensionALPN, negotiation_extension_); |
| 294 } | 292 } |
| 295 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample); | 293 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample); |
| 296 } | 294 } |
| 297 | 295 |
| 298 } // namespace net | 296 } // namespace net |
| OLD | NEW |