| 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_impl.h" | 5 #include "net/socket/ssl_client_socket_impl.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
| 15 #include "base/feature_list.h" | |
| 16 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 17 #include "base/macros.h" | 16 #include "base/macros.h" |
| 18 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
| 19 #include "base/metrics/field_trial.h" | 18 #include "base/metrics/field_trial.h" |
| 20 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
| 21 #include "base/metrics/sparse_histogram.h" | 20 #include "base/metrics/sparse_histogram.h" |
| 22 #include "base/profiler/scoped_tracker.h" | 21 #include "base/profiler/scoped_tracker.h" |
| 23 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/strings/string_piece.h" | 23 #include "base/strings/string_piece.h" |
| 25 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 if (base::StringToInt(base::FieldTrialList::FindFullName(field_trial), | 211 if (base::StringToInt(base::FieldTrialList::FindFullName(field_trial), |
| 213 &override_buffer_size)) { | 212 &override_buffer_size)) { |
| 214 buffer_size = override_buffer_size; | 213 buffer_size = override_buffer_size; |
| 215 buffer_size = std::max(buffer_size, 1000); | 214 buffer_size = std::max(buffer_size, 1000); |
| 216 buffer_size = std::min(buffer_size, 2 * kDefaultOpenSSLBufferSize); | 215 buffer_size = std::min(buffer_size, 2 * kDefaultOpenSSLBufferSize); |
| 217 } | 216 } |
| 218 #endif // !defined(OS_NACL) | 217 #endif // !defined(OS_NACL) |
| 219 return buffer_size; | 218 return buffer_size; |
| 220 } | 219 } |
| 221 | 220 |
| 222 #if defined(OS_NACL) | |
| 223 bool AreLegacyECDSACiphersEnabled() { | |
| 224 return false; | |
| 225 } | |
| 226 #else | |
| 227 // TODO(davidben): Remove this after the ECDSA CBC removal sticks. | |
| 228 // https:/crbug.com/666191. | |
| 229 const base::Feature kLegacyECDSACiphersFeature{ | |
| 230 "SSLLegacyECDSACiphers", base::FEATURE_DISABLED_BY_DEFAULT}; | |
| 231 | |
| 232 bool AreLegacyECDSACiphersEnabled() { | |
| 233 return base::FeatureList::IsEnabled(kLegacyECDSACiphersFeature); | |
| 234 } | |
| 235 #endif | |
| 236 | |
| 237 scoped_refptr<X509Certificate> OSChainFromBuffers(STACK_OF(CRYPTO_BUFFER) * | 221 scoped_refptr<X509Certificate> OSChainFromBuffers(STACK_OF(CRYPTO_BUFFER) * |
| 238 openssl_chain) { | 222 openssl_chain) { |
| 239 if (sk_CRYPTO_BUFFER_num(openssl_chain) == 0) { | 223 if (sk_CRYPTO_BUFFER_num(openssl_chain) == 0) { |
| 240 NOTREACHED(); | 224 NOTREACHED(); |
| 241 return nullptr; | 225 return nullptr; |
| 242 } | 226 } |
| 243 | 227 |
| 244 // Convert the certificate chains to a platform certificate handle. | 228 // Convert the certificate chains to a platform certificate handle. |
| 245 std::vector<base::StringPiece> der_chain; | 229 std::vector<base::StringPiece> der_chain; |
| 246 der_chain.reserve(sk_CRYPTO_BUFFER_num(openssl_chain)); | 230 der_chain.reserve(sk_CRYPTO_BUFFER_num(openssl_chain)); |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 mode.ConfigureFlag(SSL_MODE_CBC_RECORD_SPLITTING, true); | 906 mode.ConfigureFlag(SSL_MODE_CBC_RECORD_SPLITTING, true); |
| 923 | 907 |
| 924 mode.ConfigureFlag(SSL_MODE_ENABLE_FALSE_START, | 908 mode.ConfigureFlag(SSL_MODE_ENABLE_FALSE_START, |
| 925 ssl_config_.false_start_enabled); | 909 ssl_config_.false_start_enabled); |
| 926 | 910 |
| 927 SSL_set_mode(ssl_.get(), mode.set_mask); | 911 SSL_set_mode(ssl_.get(), mode.set_mask); |
| 928 SSL_clear_mode(ssl_.get(), mode.clear_mask); | 912 SSL_clear_mode(ssl_.get(), mode.clear_mask); |
| 929 | 913 |
| 930 // Use BoringSSL defaults, but disable HMAC-SHA256 and HMAC-SHA384 ciphers | 914 // Use BoringSSL defaults, but disable HMAC-SHA256 and HMAC-SHA384 ciphers |
| 931 // (note that SHA256 and SHA384 only select legacy CBC ciphers). | 915 // (note that SHA256 and SHA384 only select legacy CBC ciphers). |
| 932 std::string command("ALL:!SHA256:!SHA384:!kDHE:!aPSK:!RC4"); | 916 // Additionally disable HMAC-SHA1 ciphers in ECDSA. These are the remaining |
| 917 // CBC-mode ECDSA ciphers. |
| 918 std::string command("ALL:!SHA256:!SHA384:!kDHE:!aPSK:!RC4:!ECDSA+SHA1"); |
| 933 | 919 |
| 934 if (ssl_config_.require_ecdhe) | 920 if (ssl_config_.require_ecdhe) |
| 935 command.append(":!kRSA:!kDHE"); | 921 command.append(":!kRSA:!kDHE"); |
| 936 | 922 |
| 937 // Additionally disable HMAC-SHA1 ciphers in ECDSA. These are the remaining | |
| 938 // CBC-mode ECDSA ciphers. | |
| 939 if (!AreLegacyECDSACiphersEnabled()) | |
| 940 command.append("!ECDSA+SHA1"); | |
| 941 | |
| 942 // Remove any disabled ciphers. | 923 // Remove any disabled ciphers. |
| 943 for (uint16_t id : ssl_config_.disabled_cipher_suites) { | 924 for (uint16_t id : ssl_config_.disabled_cipher_suites) { |
| 944 const SSL_CIPHER* cipher = SSL_get_cipher_by_value(id); | 925 const SSL_CIPHER* cipher = SSL_get_cipher_by_value(id); |
| 945 if (cipher) { | 926 if (cipher) { |
| 946 command.append(":!"); | 927 command.append(":!"); |
| 947 command.append(SSL_CIPHER_get_name(cipher)); | 928 command.append(SSL_CIPHER_get_name(cipher)); |
| 948 } | 929 } |
| 949 } | 930 } |
| 950 | 931 |
| 951 int rv = SSL_set_cipher_list(ssl_.get(), command.c_str()); | 932 int rv = SSL_set_cipher_list(ssl_.get(), command.c_str()); |
| (...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1962 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED && | 1943 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED && |
| 1963 !certificate_requested_) { | 1944 !certificate_requested_) { |
| 1964 net_error = ERR_SSL_PROTOCOL_ERROR; | 1945 net_error = ERR_SSL_PROTOCOL_ERROR; |
| 1965 } | 1946 } |
| 1966 } | 1947 } |
| 1967 | 1948 |
| 1968 return net_error; | 1949 return net_error; |
| 1969 } | 1950 } |
| 1970 | 1951 |
| 1971 } // namespace net | 1952 } // namespace net |
| OLD | NEW |