[email protected] | c091d360 | 2014-03-24 02:32:48 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/ssl/ssl_config.h" |
| 6 | |
rtenneti | 807f9ea | 2015-06-24 16:26:31 | [diff] [blame] | 7 | #include "net/cert/cert_verifier.h" |
bnc | 984a84a | 2014-12-09 19:47:58 | [diff] [blame] | 8 | |
[email protected] | c091d360 | 2014-03-24 02:32:48 | [diff] [blame] | 9 | namespace net { |
| 10 | |
davidben | 6cacd57 | 2015-09-29 22:24:10 | [diff] [blame] | 11 | const uint16_t kDefaultSSLVersionMin = SSL_PROTOCOL_VERSION_TLS1; |
[email protected] | c091d360 | 2014-03-24 02:32:48 | [diff] [blame] | 12 | |
davidben | 6cacd57 | 2015-09-29 22:24:10 | [diff] [blame] | 13 | const uint16_t kDefaultSSLVersionMax = SSL_PROTOCOL_VERSION_TLS1_2; |
| 14 | |
rsleevi | 74e9974 | 2016-09-13 20:35:25 | [diff] [blame] | 15 | SSLConfig::CertAndStatus::CertAndStatus() = default; |
| 16 | SSLConfig::CertAndStatus::CertAndStatus(scoped_refptr<X509Certificate> cert_arg, |
| 17 | CertStatus status) |
| 18 | : cert(std::move(cert_arg)), cert_status(status) {} |
| 19 | SSLConfig::CertAndStatus::CertAndStatus(const CertAndStatus& other) |
| 20 | : cert(other.cert), cert_status(other.cert_status) {} |
| 21 | SSLConfig::CertAndStatus::~CertAndStatus() = default; |
[email protected] | c091d360 | 2014-03-24 02:32:48 | [diff] [blame] | 22 | |
| 23 | SSLConfig::SSLConfig() |
| 24 | : rev_checking_enabled(false), |
| 25 | rev_checking_required_local_anchors(false), |
rsleevi | f344fae1 | 2017-01-04 22:08:39 | [diff] [blame] | 26 | sha1_local_anchors_enabled(true), |
rsleevi | 0f9bfb0 | 2017-03-04 03:07:20 | [diff] [blame] | 27 | common_name_fallback_local_anchors_enabled(true), |
[email protected] | c091d360 | 2014-03-24 02:32:48 | [diff] [blame] | 28 | version_min(kDefaultSSLVersionMin), |
davidben | 6cacd57 | 2015-09-29 22:24:10 | [diff] [blame] | 29 | version_max(kDefaultSSLVersionMax), |
davidben | 14b1a53 | 2015-10-30 16:01:09 | [diff] [blame] | 30 | deprecated_cipher_suites_enabled(false), |
[email protected] | c091d360 | 2014-03-24 02:32:48 | [diff] [blame] | 31 | channel_id_enabled(true), |
| 32 | false_start_enabled(true), |
| 33 | signed_cert_timestamps_enabled(true), |
sergeyu | ff826d5e | 2015-05-13 20:35:22 | [diff] [blame] | 34 | require_ecdhe(false), |
[email protected] | c091d360 | 2014-03-24 02:32:48 | [diff] [blame] | 35 | send_client_cert(false), |
| 36 | verify_ev_cert(false), |
jeremyim | 8d44fadd | 2015-02-10 19:18:15 | [diff] [blame] | 37 | cert_io_enabled(true), |
davidben | 1de60e7 | 2015-07-21 21:12:27 | [diff] [blame] | 38 | renego_allowed_default(false) {} |
[email protected] | c091d360 | 2014-03-24 02:32:48 | [diff] [blame] | 39 | |
vmpstr | acd23b7 | 2016-02-26 21:08:55 | [diff] [blame] | 40 | SSLConfig::SSLConfig(const SSLConfig& other) = default; |
| 41 | |
[email protected] | c091d360 | 2014-03-24 02:32:48 | [diff] [blame] | 42 | SSLConfig::~SSLConfig() {} |
| 43 | |
| 44 | bool SSLConfig::IsAllowedBadCert(X509Certificate* cert, |
| 45 | CertStatus* cert_status) const { |
rsleevi | 74e9974 | 2016-09-13 20:35:25 | [diff] [blame] | 46 | for (const auto& allowed_bad_cert : allowed_bad_certs) { |
| 47 | if (cert->Equals(allowed_bad_cert.cert.get())) { |
[email protected] | c091d360 | 2014-03-24 02:32:48 | [diff] [blame] | 48 | if (cert_status) |
rsleevi | 74e9974 | 2016-09-13 20:35:25 | [diff] [blame] | 49 | *cert_status = allowed_bad_cert.cert_status; |
[email protected] | c091d360 | 2014-03-24 02:32:48 | [diff] [blame] | 50 | return true; |
| 51 | } |
| 52 | } |
| 53 | return false; |
| 54 | } |
| 55 | |
rtenneti | 807f9ea | 2015-06-24 16:26:31 | [diff] [blame] | 56 | int SSLConfig::GetCertVerifyFlags() const { |
| 57 | int flags = 0; |
| 58 | if (rev_checking_enabled) |
| 59 | flags |= CertVerifier::VERIFY_REV_CHECKING_ENABLED; |
| 60 | if (verify_ev_cert) |
| 61 | flags |= CertVerifier::VERIFY_EV_CERT; |
| 62 | if (cert_io_enabled) |
| 63 | flags |= CertVerifier::VERIFY_CERT_IO_ENABLED; |
| 64 | if (rev_checking_required_local_anchors) |
| 65 | flags |= CertVerifier::VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS; |
mattm | 9b3b296 | 2016-08-15 20:54:23 | [diff] [blame] | 66 | if (sha1_local_anchors_enabled) |
| 67 | flags |= CertVerifier::VERIFY_ENABLE_SHA1_LOCAL_ANCHORS; |
rsleevi | 0f9bfb0 | 2017-03-04 03:07:20 | [diff] [blame] | 68 | if (common_name_fallback_local_anchors_enabled) |
| 69 | flags |= CertVerifier::VERIFY_ENABLE_COMMON_NAME_FALLBACK_LOCAL_ANCHORS; |
rtenneti | 807f9ea | 2015-06-24 16:26:31 | [diff] [blame] | 70 | return flags; |
| 71 | } |
| 72 | |
[email protected] | c091d360 | 2014-03-24 02:32:48 | [diff] [blame] | 73 | } // namespace net |