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 NextProto next_proto : next_protos) { |
243 if (i->size() > 255) { | 243 const std::string proto = NextProtoToString(next_proto); |
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 std::string& proto : next_proto_strings) { |
259 i != next_protos.end(); i++) { | 261 wire_protos.push_back(proto.size()); |
260 if (i->size() == 0 || i->size() > 255) | 262 // TODO(bnc): Rewrite. |
261 continue; | 263 wire_protos.resize(wire_protos.size() + proto.size()); |
262 wire_protos.push_back(i->size()); | 264 memcpy(&wire_protos[wire_protos.size() - proto.size()], proto.data(), |
263 wire_protos.resize(wire_protos.size() + i->size()); | 265 proto.size()); |
264 memcpy(&wire_protos[wire_protos.size() - i->size()], | |
265 i->data(), i->size()); | |
266 } | 266 } |
267 DCHECK_EQ(wire_protos.size(), wire_length); | 267 DCHECK_EQ(wire_protos.size(), wire_length); |
268 | 268 |
269 return wire_protos; | 269 return wire_protos; |
270 } | 270 } |
271 | 271 |
272 void SSLClientSocket::RecordNegotiationExtension() { | 272 void SSLClientSocket::RecordNegotiationExtension() { |
273 if (negotiation_extension_ == kExtensionUnknown) | 273 if (negotiation_extension_ == kExtensionUnknown) |
274 return; | 274 return; |
275 std::string proto; | 275 std::string proto; |
(...skipping 13 matching lines...) Expand all Loading... |
289 } else { | 289 } else { |
290 sample += 500; | 290 sample += 500; |
291 } | 291 } |
292 } else { | 292 } else { |
293 DCHECK_EQ(kExtensionALPN, negotiation_extension_); | 293 DCHECK_EQ(kExtensionALPN, negotiation_extension_); |
294 } | 294 } |
295 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample); | 295 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample); |
296 } | 296 } |
297 | 297 |
298 } // namespace net | 298 } // namespace net |
OLD | NEW |