| 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/feature_list.h" |
| 7 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/metrics/sparse_histogram.h" | 9 #include "base/metrics/sparse_histogram.h" |
| 9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "build/build_config.h" |
| 10 #include "crypto/ec_private_key.h" | 12 #include "crypto/ec_private_key.h" |
| 11 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 12 #include "net/socket/ssl_client_socket_impl.h" | 14 #include "net/socket/ssl_client_socket_impl.h" |
| 13 #include "net/ssl/channel_id_service.h" | 15 #include "net/ssl/channel_id_service.h" |
| 14 #include "net/ssl/ssl_config_service.h" | 16 #include "net/ssl/ssl_config_service.h" |
| 15 | 17 |
| 16 namespace net { | 18 namespace net { |
| 17 | 19 |
| 20 namespace { |
| 21 #if !defined(OS_NACL) |
| 22 const base::Feature kPostQuantumExperiment{"SSLPostQuantumExperiment", |
| 23 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 24 #endif |
| 25 } // namespace |
| 26 |
| 18 SSLClientSocket::SSLClientSocket() | 27 SSLClientSocket::SSLClientSocket() |
| 19 : signed_cert_timestamps_received_(false), | 28 : signed_cert_timestamps_received_(false), |
| 20 stapled_ocsp_response_received_(false) {} | 29 stapled_ocsp_response_received_(false) {} |
| 21 | 30 |
| 22 // static | 31 // static |
| 23 NextProto SSLClientSocket::NextProtoFromString(base::StringPiece proto_string) { | 32 NextProto SSLClientSocket::NextProtoFromString(base::StringPiece proto_string) { |
| 24 if (proto_string == "http1.1" || proto_string == "http/1.1") { | 33 if (proto_string == "http1.1" || proto_string == "http/1.1") { |
| 25 return kProtoHTTP11; | 34 return kProtoHTTP11; |
| 26 } else if (proto_string == "h2") { | 35 } else if (proto_string == "h2") { |
| 27 return kProtoHTTP2; | 36 return kProtoHTTP2; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 82 } |
| 74 | 83 |
| 75 bool SSLClientSocket::IgnoreCertError(int error, int load_flags) { | 84 bool SSLClientSocket::IgnoreCertError(int error, int load_flags) { |
| 76 if (error == OK) | 85 if (error == OK) |
| 77 return true; | 86 return true; |
| 78 return (load_flags & LOAD_IGNORE_ALL_CERT_ERRORS) && | 87 return (load_flags & LOAD_IGNORE_ALL_CERT_ERRORS) && |
| 79 IsCertificateError(error); | 88 IsCertificateError(error); |
| 80 } | 89 } |
| 81 | 90 |
| 82 // static | 91 // static |
| 92 bool SSLClientSocket::IsPostQuantumExperimentEnabled() { |
| 93 #if !defined(OS_NACL) |
| 94 return base::FeatureList::IsEnabled(kPostQuantumExperiment); |
| 95 #else |
| 96 return false; |
| 97 #endif |
| 98 } |
| 99 |
| 100 // static |
| 83 std::vector<uint8_t> SSLClientSocket::SerializeNextProtos( | 101 std::vector<uint8_t> SSLClientSocket::SerializeNextProtos( |
| 84 const NextProtoVector& next_protos) { | 102 const NextProtoVector& next_protos) { |
| 85 std::vector<uint8_t> wire_protos; | 103 std::vector<uint8_t> wire_protos; |
| 86 for (const NextProto next_proto : next_protos) { | 104 for (const NextProto next_proto : next_protos) { |
| 87 const std::string proto = NextProtoToString(next_proto); | 105 const std::string proto = NextProtoToString(next_proto); |
| 88 if (proto.size() > 255) { | 106 if (proto.size() > 255) { |
| 89 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << proto; | 107 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << proto; |
| 90 continue; | 108 continue; |
| 91 } | 109 } |
| 92 if (proto.size() == 0) { | 110 if (proto.size() == 0) { |
| 93 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol"; | 111 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol"; |
| 94 continue; | 112 continue; |
| 95 } | 113 } |
| 96 wire_protos.push_back(proto.size()); | 114 wire_protos.push_back(proto.size()); |
| 97 for (const char ch : proto) { | 115 for (const char ch : proto) { |
| 98 wire_protos.push_back(static_cast<uint8_t>(ch)); | 116 wire_protos.push_back(static_cast<uint8_t>(ch)); |
| 99 } | 117 } |
| 100 } | 118 } |
| 101 | 119 |
| 102 return wire_protos; | 120 return wire_protos; |
| 103 } | 121 } |
| 104 | 122 |
| 105 } // namespace net | 123 } // namespace net |
| OLD | NEW |