blob: 8dcabab2ac1fdb94d36e4dcf9b6925937125c9cb [file] [log] [blame]
Avi Drissman64595482022-09-14 20:52:291// Copyright 2015 The Chromium Authors
svaldez6e7e82a22015-10-28 19:39:532// 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 Drissman13fc8932015-12-20 04:40:469
David Benjaminf3b8b512021-09-01 21:14:0110#include <utility>
svaldez6e7e82a22015-10-28 19:39:5311#include <vector>
12
David Benjamin4c81d93e2021-10-12 17:32:3613#include "base/callback.h"
Bence Békycc859862021-02-08 17:26:4014#include "base/containers/flat_map.h"
Keishi Hattori0e45c022021-11-27 09:25:5215#include "base/memory/raw_ptr.h"
svaldez6e7e82a22015-10-28 19:39:5316#include "net/base/net_export.h"
David Benjamin0627236e2019-06-27 02:01:1817#include "net/socket/next_proto.h"
svaldez6e7e82a22015-10-28 19:39:5318#include "net/ssl/ssl_config.h"
Anton Bikineev068d2912021-05-15 20:43:5219#include "third_party/abseil-cpp/absl/types/optional.h"
David Benjaminf3b8b512021-09-01 21:14:0120#include "third_party/boringssl/src/include/openssl/base.h"
svaldez6e7e82a22015-10-28 19:39:5321
22namespace net {
23
ryanchung987b2ff2016-02-19 00:17:1224class ClientCertVerifier;
25
svaldez6e7e82a22015-10-28 19:39:5326// A collection of server-side SSL-related configuration settings.
27struct NET_EXPORT SSLServerConfig {
ryanchung987b2ff2016-02-19 00:17:1228 enum ClientCertType {
29 NO_CLIENT_CERT,
30 OPTIONAL_CLIENT_CERT,
31 REQUIRE_CLIENT_CERT,
32 };
33
svaldez6e7e82a22015-10-28 19:39:5334 // Defaults
35 SSLServerConfig();
vmpstracd23b72016-02-26 21:08:5536 SSLServerConfig(const SSLServerConfig& other);
svaldez6e7e82a22015-10-28 19:39:5337 ~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 Horo432981d52022-06-09 09:50:1343 uint16_t version_min = kDefaultSSLVersionMin;
44 uint16_t version_max = kDefaultSSLVersionMax;
svaldez6e7e82a22015-10-28 19:39:5345
Steven Valdez6af02df2018-07-15 21:52:3346 // 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 Horob2022b52022-06-09 01:44:0748 bool early_data_enabled = false;
Steven Valdez6af02df2018-07-15 21:52:3349
svaldez6e7e82a22015-10-28 19:39:5350 // 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 Drissman13fc8932015-12-20 04:40:4666 // Though cipher suites are sent in TLS as "uint8_t CipherSuite[2]", in
svaldez6e7e82a22015-10-28 19:39:5367 // big-endian form, they should be declared in host byte order, with the
Avi Drissman13fc8932015-12-20 04:40:4668 // first uint8_t occupying the most significant byte.
svaldez6e7e82a22015-10-28 19:39:5369 // 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 Horob2022b52022-06-09 01:44:0774 bool require_ecdhe = false;
svaldez6e7e82a22015-10-28 19:39:5375
David Benjamin07a07d652020-02-26 22:26:5976 // 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 Bikineev068d2912021-05-15 20:43:5279 absl::optional<uint16_t> cipher_suite_for_testing;
David Benjamin07a07d652020-02-26 22:26:5980
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 Bikineev068d2912021-05-15 20:43:5284 absl::optional<uint16_t> signature_algorithm_for_testing;
David Benjamin07a07d652020-02-26 22:26:5985
Adam Langley7d873ea2021-03-26 20:24:2086 // 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
ryanchung987b2ff2016-02-19 00:17:1290 // Sets the requirement for client certificates during handshake.
Tsuyoshi Horob2022b52022-06-09 01:44:0791 ClientCertType client_cert_type = NO_CLIENT_CERT;
ryanchung987b2ff2016-02-19 00:17:1292
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 Benjaminbba56ef2019-10-29 18:51:5596 std::vector<std::string> cert_authorities;
ryanchung987b2ff2016-02-19 00:17:1297
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,
ryanchungeb9e3bc2016-03-08 05:08:10101 // and must outlive any sockets spawned from this SSLServerContext.
ryanchung987b2ff2016-02-19 00:17:12102 // This field is meaningful only if client certificates are requested.
103 // If a verifier is not provided then all certificates are accepted.
Tsuyoshi Horo432981d52022-06-09 09:50:13104 raw_ptr<ClientCertVerifier> client_cert_verifier = nullptr;
David Benjamin0627236e2019-06-27 02:01:18105
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 Muellerf566f0e52020-05-06 00:52:25110
Bence Békycc859862021-02-08 17:26:40111 // 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 Muellerf566f0e52020-05-06 00:52:25116 // If non-empty, the DER-encoded OCSP response to staple.
117 std::vector<uint8_t> ocsp_response;
David Benjaminf3b8b512021-09-01 21:14:01118
David Benjamin8e657bc2021-09-20 19:07:44119 // If non-empty, the serialized SignedCertificateTimestampList to send in the
120 // handshake.
121 std::vector<uint8_t> signed_cert_timestamp_list;
122
David Benjamin4c81d93e2021-10-12 17:32:36123 // If specified, called at the start of each connection with the ClientHello.
David Benjamind8d00b62021-11-16 18:27:01124 // Returns true to continue the handshake and false to fail it.
125 base::RepeatingCallback<bool(const SSL_CLIENT_HELLO*)>
David Benjamin4c81d93e2021-10-12 17:32:36126 client_hello_callback_for_testing;
127
David Benjamin50c88f92021-11-16 23:26:09128 // 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 Benjaminf3b8b512021-09-01 21:14:01132 // 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 Horoab268d62022-06-21 04:41:23138 ECHKeysContainer( // NOLINT(google-explicit-constructor)
139 bssl::UniquePtr<SSL_ECH_KEYS> keys);
David Benjaminf3b8b512021-09-01 21:14:01140 ~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;
svaldez6e7e82a22015-10-28 19:39:53157};
158
159} // namespace net
160
161#endif // NET_SSL_SSL_SERVER_CONFIG_H_