Avi Drissman | 6459548 | 2022-09-14 20:52:29 | [diff] [blame^] | 1 | // Copyright 2015 The Chromium Authors |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_SSL_SSL_SERVER_CONFIG_H_ |
| 6 | #define NET_SSL_SSL_SERVER_CONFIG_H_ |
| 7 | |
| 8 | #include <stdint.h> |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 9 | |
David Benjamin | f3b8b51 | 2021-09-01 21:14:01 | [diff] [blame] | 10 | #include <utility> |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
David Benjamin | 4c81d93e | 2021-10-12 17:32:36 | [diff] [blame] | 13 | #include "base/callback.h" |
Bence Béky | cc85986 | 2021-02-08 17:26:40 | [diff] [blame] | 14 | #include "base/containers/flat_map.h" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 15 | #include "base/memory/raw_ptr.h" |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 16 | #include "net/base/net_export.h" |
David Benjamin | 0627236e | 2019-06-27 02:01:18 | [diff] [blame] | 17 | #include "net/socket/next_proto.h" |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 18 | #include "net/ssl/ssl_config.h" |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 19 | #include "third_party/abseil-cpp/absl/types/optional.h" |
David Benjamin | f3b8b51 | 2021-09-01 21:14:01 | [diff] [blame] | 20 | #include "third_party/boringssl/src/include/openssl/base.h" |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 21 | |
| 22 | namespace net { |
| 23 | |
ryanchung | 987b2ff | 2016-02-19 00:17:12 | [diff] [blame] | 24 | class ClientCertVerifier; |
| 25 | |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 26 | // A collection of server-side SSL-related configuration settings. |
| 27 | struct NET_EXPORT SSLServerConfig { |
ryanchung | 987b2ff | 2016-02-19 00:17:12 | [diff] [blame] | 28 | enum ClientCertType { |
| 29 | NO_CLIENT_CERT, |
| 30 | OPTIONAL_CLIENT_CERT, |
| 31 | REQUIRE_CLIENT_CERT, |
| 32 | }; |
| 33 | |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 34 | // Defaults |
| 35 | SSLServerConfig(); |
vmpstr | acd23b7 | 2016-02-26 21:08:55 | [diff] [blame] | 36 | SSLServerConfig(const SSLServerConfig& other); |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 37 | ~SSLServerConfig(); |
| 38 | |
| 39 | // The minimum and maximum protocol versions that are enabled. |
| 40 | // (Use the SSL_PROTOCOL_VERSION_xxx enumerators defined in ssl_config.h) |
| 41 | // SSL 2.0 and SSL 3.0 are not supported. If version_max < version_min, it |
| 42 | // means no protocol versions are enabled. |
Tsuyoshi Horo | 432981d5 | 2022-06-09 09:50:13 | [diff] [blame] | 43 | uint16_t version_min = kDefaultSSLVersionMin; |
| 44 | uint16_t version_max = kDefaultSSLVersionMax; |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 45 | |
Steven Valdez | 6af02df | 2018-07-15 21:52:33 | [diff] [blame] | 46 | // Whether early data is enabled on this connection. The caller is obligated |
| 47 | // to reject early data that is non-safe to be replayed. |
Tsuyoshi Horo | b2022b5 | 2022-06-09 01:44:07 | [diff] [blame] | 48 | bool early_data_enabled = false; |
Steven Valdez | 6af02df | 2018-07-15 21:52:33 | [diff] [blame] | 49 | |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 50 | // Presorted list of cipher suites which should be explicitly prevented from |
| 51 | // being used in addition to those disabled by the net built-in policy. |
| 52 | // |
| 53 | // By default, all cipher suites supported by the underlying SSL |
| 54 | // implementation will be enabled except for: |
| 55 | // - Null encryption cipher suites. |
| 56 | // - Weak cipher suites: < 80 bits of security strength. |
| 57 | // - FORTEZZA cipher suites (obsolete). |
| 58 | // - IDEA cipher suites (RFC 5469 explains why). |
| 59 | // - Anonymous cipher suites. |
| 60 | // - ECDSA cipher suites on platforms that do not support ECDSA signed |
| 61 | // certificates, as servers may use the presence of such ciphersuites as a |
| 62 | // hint to send an ECDSA certificate. |
| 63 | // The ciphers listed in |disabled_cipher_suites| will be removed in addition |
| 64 | // to the above list. |
| 65 | // |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 66 | // Though cipher suites are sent in TLS as "uint8_t CipherSuite[2]", in |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 67 | // big-endian form, they should be declared in host byte order, with the |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 68 | // first uint8_t occupying the most significant byte. |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 69 | // Ex: To disable TLS_RSA_WITH_RC4_128_MD5, specify 0x0004, while to |
| 70 | // disable TLS_ECDH_ECDSA_WITH_RC4_128_SHA, specify 0xC002. |
| 71 | std::vector<uint16_t> disabled_cipher_suites; |
| 72 | |
| 73 | // If true, causes only ECDHE cipher suites to be enabled. |
Tsuyoshi Horo | b2022b5 | 2022-06-09 01:44:07 | [diff] [blame] | 74 | bool require_ecdhe = false; |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 75 | |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 76 | // cipher_suite_for_testing, if set, causes the server to only support the |
| 77 | // specified cipher suite in TLS 1.2 and below. This should only be used in |
| 78 | // unit tests. |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 79 | absl::optional<uint16_t> cipher_suite_for_testing; |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 80 | |
| 81 | // signature_algorithm_for_testing, if set, causes the server to only support |
| 82 | // the specified signature algorithm in TLS 1.2 and below. This should only be |
| 83 | // used in unit tests. |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 84 | absl::optional<uint16_t> signature_algorithm_for_testing; |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 85 | |
Adam Langley | 7d873ea | 2021-03-26 20:24:20 | [diff] [blame] | 86 | // curves_for_testing, if not empty, specifies the list of NID values (e.g. |
| 87 | // NID_X25519) to configure as supported curves for the TLS connection. |
| 88 | std::vector<int> curves_for_testing; |
| 89 | |
ryanchung | 987b2ff | 2016-02-19 00:17:12 | [diff] [blame] | 90 | // Sets the requirement for client certificates during handshake. |
Tsuyoshi Horo | b2022b5 | 2022-06-09 01:44:07 | [diff] [blame] | 91 | ClientCertType client_cert_type = NO_CLIENT_CERT; |
ryanchung | 987b2ff | 2016-02-19 00:17:12 | [diff] [blame] | 92 | |
| 93 | // List of DER-encoded X.509 DistinguishedName of certificate authorities |
| 94 | // to be included in the CertificateRequest handshake message, |
| 95 | // if client certificates are required. |
David Benjamin | bba56ef | 2019-10-29 18:51:55 | [diff] [blame] | 96 | std::vector<std::string> cert_authorities; |
ryanchung | 987b2ff | 2016-02-19 00:17:12 | [diff] [blame] | 97 | |
| 98 | // Provides the ClientCertVerifier that is to be used to verify |
| 99 | // client certificates during the handshake. |
| 100 | // The |client_cert_verifier| continues to be owned by the caller, |
ryanchung | eb9e3bc | 2016-03-08 05:08:10 | [diff] [blame] | 101 | // and must outlive any sockets spawned from this SSLServerContext. |
ryanchung | 987b2ff | 2016-02-19 00:17:12 | [diff] [blame] | 102 | // This field is meaningful only if client certificates are requested. |
| 103 | // If a verifier is not provided then all certificates are accepted. |
Tsuyoshi Horo | 432981d5 | 2022-06-09 09:50:13 | [diff] [blame] | 104 | raw_ptr<ClientCertVerifier> client_cert_verifier = nullptr; |
David Benjamin | 0627236e | 2019-06-27 02:01:18 | [diff] [blame] | 105 | |
| 106 | // The list of application level protocols supported with ALPN (Application |
| 107 | // Layer Protocol Negotiation), in decreasing order of preference. Protocols |
| 108 | // will be advertised in this order during TLS handshake. |
| 109 | NextProtoVector alpn_protos; |
Matt Mueller | f566f0e5 | 2020-05-06 00:52:25 | [diff] [blame] | 110 | |
Bence Béky | cc85986 | 2021-02-08 17:26:40 | [diff] [blame] | 111 | // ALPS TLS extension is enabled and corresponding data is sent to client if |
| 112 | // client also enabled ALPS, for each NextProto in |application_settings|. |
| 113 | // Data might be empty. |
| 114 | base::flat_map<NextProto, std::vector<uint8_t>> application_settings; |
| 115 | |
Matt Mueller | f566f0e5 | 2020-05-06 00:52:25 | [diff] [blame] | 116 | // If non-empty, the DER-encoded OCSP response to staple. |
| 117 | std::vector<uint8_t> ocsp_response; |
David Benjamin | f3b8b51 | 2021-09-01 21:14:01 | [diff] [blame] | 118 | |
David Benjamin | 8e657bc | 2021-09-20 19:07:44 | [diff] [blame] | 119 | // If non-empty, the serialized SignedCertificateTimestampList to send in the |
| 120 | // handshake. |
| 121 | std::vector<uint8_t> signed_cert_timestamp_list; |
| 122 | |
David Benjamin | 4c81d93e | 2021-10-12 17:32:36 | [diff] [blame] | 123 | // If specified, called at the start of each connection with the ClientHello. |
David Benjamin | d8d00b6 | 2021-11-16 18:27:01 | [diff] [blame] | 124 | // Returns true to continue the handshake and false to fail it. |
| 125 | base::RepeatingCallback<bool(const SSL_CLIENT_HELLO*)> |
David Benjamin | 4c81d93e | 2021-10-12 17:32:36 | [diff] [blame] | 126 | client_hello_callback_for_testing; |
| 127 | |
David Benjamin | 50c88f9 | 2021-11-16 23:26:09 | [diff] [blame] | 128 | // If specified, causes the specified alert to be sent immediately after the |
| 129 | // handshake. |
| 130 | absl::optional<uint8_t> alert_after_handshake_for_testing; |
| 131 | |
David Benjamin | f3b8b51 | 2021-09-01 21:14:01 | [diff] [blame] | 132 | // This is a workaround for BoringSSL's scopers not being copyable. See |
| 133 | // https://crbug.com/boringssl/431. |
| 134 | class NET_EXPORT ECHKeysContainer { |
| 135 | public: |
| 136 | ECHKeysContainer(); |
| 137 | // Intentionally allow implicit conversion from bssl::UniquePtr. |
Tsuyoshi Horo | ab268d6 | 2022-06-21 04:41:23 | [diff] [blame] | 138 | ECHKeysContainer( // NOLINT(google-explicit-constructor) |
| 139 | bssl::UniquePtr<SSL_ECH_KEYS> keys); |
David Benjamin | f3b8b51 | 2021-09-01 21:14:01 | [diff] [blame] | 140 | ~ECHKeysContainer(); |
| 141 | |
| 142 | ECHKeysContainer(const ECHKeysContainer& other); |
| 143 | ECHKeysContainer& operator=(const ECHKeysContainer& other); |
| 144 | |
| 145 | // Forward APIs from bssl::UniquePtr. |
| 146 | SSL_ECH_KEYS* get() const { return keys_.get(); } |
| 147 | explicit operator bool() const { return static_cast<bool>(keys_); } |
| 148 | // This is defined out-of-line to avoid an ssl.h include. |
| 149 | void reset(SSL_ECH_KEYS* keys = nullptr); |
| 150 | |
| 151 | private: |
| 152 | bssl::UniquePtr<SSL_ECH_KEYS> keys_; |
| 153 | }; |
| 154 | |
| 155 | // If not nullptr, an ECH configuration to use on the server. |
| 156 | ECHKeysContainer ech_keys; |
svaldez | 6e7e82a2 | 2015-10-28 19:39:53 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | } // namespace net |
| 160 | |
| 161 | #endif // NET_SSL_SSL_SERVER_CONFIG_H_ |