xref: /aosp_15_r20/external/cronet/net/ssl/ssl_config.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2014 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker #ifndef NET_SSL_SSL_CONFIG_H_
6*6777b538SAndroid Build Coastguard Worker #define NET_SSL_SSL_CONFIG_H_
7*6777b538SAndroid Build Coastguard Worker 
8*6777b538SAndroid Build Coastguard Worker #include <stdint.h>
9*6777b538SAndroid Build Coastguard Worker 
10*6777b538SAndroid Build Coastguard Worker #include <optional>
11*6777b538SAndroid Build Coastguard Worker 
12*6777b538SAndroid Build Coastguard Worker #include "base/containers/flat_map.h"
13*6777b538SAndroid Build Coastguard Worker #include "base/memory/scoped_refptr.h"
14*6777b538SAndroid Build Coastguard Worker #include "net/base/net_export.h"
15*6777b538SAndroid Build Coastguard Worker #include "net/base/network_anonymization_key.h"
16*6777b538SAndroid Build Coastguard Worker #include "net/base/privacy_mode.h"
17*6777b538SAndroid Build Coastguard Worker #include "net/cert/cert_status_flags.h"
18*6777b538SAndroid Build Coastguard Worker #include "net/cert/x509_certificate.h"
19*6777b538SAndroid Build Coastguard Worker #include "net/socket/next_proto.h"
20*6777b538SAndroid Build Coastguard Worker 
21*6777b538SAndroid Build Coastguard Worker namespace net {
22*6777b538SAndroid Build Coastguard Worker 
23*6777b538SAndroid Build Coastguard Worker // Supported TLS ProtocolVersion values encoded as uint16_t.
24*6777b538SAndroid Build Coastguard Worker enum {
25*6777b538SAndroid Build Coastguard Worker   SSL_PROTOCOL_VERSION_TLS1_2 = 0x0303,
26*6777b538SAndroid Build Coastguard Worker   SSL_PROTOCOL_VERSION_TLS1_3 = 0x0304,
27*6777b538SAndroid Build Coastguard Worker };
28*6777b538SAndroid Build Coastguard Worker 
29*6777b538SAndroid Build Coastguard Worker // Default minimum protocol version.
30*6777b538SAndroid Build Coastguard Worker NET_EXPORT extern const uint16_t kDefaultSSLVersionMin;
31*6777b538SAndroid Build Coastguard Worker 
32*6777b538SAndroid Build Coastguard Worker // Default maximum protocol version.
33*6777b538SAndroid Build Coastguard Worker NET_EXPORT extern const uint16_t kDefaultSSLVersionMax;
34*6777b538SAndroid Build Coastguard Worker 
35*6777b538SAndroid Build Coastguard Worker // A collection of SSL-related configuration settings.
36*6777b538SAndroid Build Coastguard Worker struct NET_EXPORT SSLConfig {
37*6777b538SAndroid Build Coastguard Worker   using ApplicationSettings = base::flat_map<NextProto, std::vector<uint8_t>>;
38*6777b538SAndroid Build Coastguard Worker 
39*6777b538SAndroid Build Coastguard Worker   // Default to revocation checking.
40*6777b538SAndroid Build Coastguard Worker   SSLConfig();
41*6777b538SAndroid Build Coastguard Worker   SSLConfig(const SSLConfig& other);
42*6777b538SAndroid Build Coastguard Worker   ~SSLConfig();
43*6777b538SAndroid Build Coastguard Worker 
44*6777b538SAndroid Build Coastguard Worker   // Returns true if |cert| is one of the certs in |allowed_bad_certs|.
45*6777b538SAndroid Build Coastguard Worker   // The expected cert status is written to |cert_status|. |*cert_status| can
46*6777b538SAndroid Build Coastguard Worker   // be NULL if user doesn't care about the cert status.
47*6777b538SAndroid Build Coastguard Worker   bool IsAllowedBadCert(X509Certificate* cert, CertStatus* cert_status) const;
48*6777b538SAndroid Build Coastguard Worker 
49*6777b538SAndroid Build Coastguard Worker   // Returns the set of flags to use for certificate verification, which is a
50*6777b538SAndroid Build Coastguard Worker   // bitwise OR of CertVerifier::VerifyFlags that represent this SSLConfig's
51*6777b538SAndroid Build Coastguard Worker   // configuration.
52*6777b538SAndroid Build Coastguard Worker   int GetCertVerifyFlags() const;
53*6777b538SAndroid Build Coastguard Worker 
54*6777b538SAndroid Build Coastguard Worker   // If specified, the minimum and maximum protocol versions that are enabled.
55*6777b538SAndroid Build Coastguard Worker   // (Use the SSL_PROTOCOL_VERSION_xxx enumerators defined above.) If
56*6777b538SAndroid Build Coastguard Worker   // unspecified, values from the SSLConfigService are used.
57*6777b538SAndroid Build Coastguard Worker   std::optional<uint16_t> version_min_override;
58*6777b538SAndroid Build Coastguard Worker   std::optional<uint16_t> version_max_override;
59*6777b538SAndroid Build Coastguard Worker 
60*6777b538SAndroid Build Coastguard Worker   // Whether early data is enabled on this connection. Note that early data has
61*6777b538SAndroid Build Coastguard Worker   // weaker security properties than normal data and changes the
62*6777b538SAndroid Build Coastguard Worker   // SSLClientSocket's behavior. The caller must only send replayable data prior
63*6777b538SAndroid Build Coastguard Worker   // to handshake confirmation. See StreamSocket::ConfirmHandshake for details.
64*6777b538SAndroid Build Coastguard Worker   //
65*6777b538SAndroid Build Coastguard Worker   // Additionally, early data may be rejected by the server, resulting in some
66*6777b538SAndroid Build Coastguard Worker   // socket operation failing with ERR_EARLY_DATA_REJECTED or
67*6777b538SAndroid Build Coastguard Worker   // ERR_WRONG_VERSION_ON_EARLY_DATA before any data is returned from the
68*6777b538SAndroid Build Coastguard Worker   // server. The caller must handle these cases, typically by retrying the
69*6777b538SAndroid Build Coastguard Worker   // high-level operation.
70*6777b538SAndroid Build Coastguard Worker   //
71*6777b538SAndroid Build Coastguard Worker   // If unsure, do not enable this option.
72*6777b538SAndroid Build Coastguard Worker   bool early_data_enabled = false;
73*6777b538SAndroid Build Coastguard Worker 
74*6777b538SAndroid Build Coastguard Worker   // If true, causes only ECDHE cipher suites to be enabled.
75*6777b538SAndroid Build Coastguard Worker   bool require_ecdhe = false;
76*6777b538SAndroid Build Coastguard Worker 
77*6777b538SAndroid Build Coastguard Worker   // TODO(wtc): move the following members to a new SSLParams structure.  They
78*6777b538SAndroid Build Coastguard Worker   // are not SSL configuration settings.
79*6777b538SAndroid Build Coastguard Worker 
80*6777b538SAndroid Build Coastguard Worker   struct NET_EXPORT CertAndStatus {
81*6777b538SAndroid Build Coastguard Worker     CertAndStatus();
82*6777b538SAndroid Build Coastguard Worker     CertAndStatus(scoped_refptr<X509Certificate> cert, CertStatus status);
83*6777b538SAndroid Build Coastguard Worker     CertAndStatus(const CertAndStatus&);
84*6777b538SAndroid Build Coastguard Worker     ~CertAndStatus();
85*6777b538SAndroid Build Coastguard Worker 
86*6777b538SAndroid Build Coastguard Worker     scoped_refptr<X509Certificate> cert;
87*6777b538SAndroid Build Coastguard Worker     CertStatus cert_status = 0;
88*6777b538SAndroid Build Coastguard Worker   };
89*6777b538SAndroid Build Coastguard Worker 
90*6777b538SAndroid Build Coastguard Worker   // Add any known-bad SSL certificate (with its cert status) to
91*6777b538SAndroid Build Coastguard Worker   // |allowed_bad_certs| that should not trigger an ERR_CERT_* error when
92*6777b538SAndroid Build Coastguard Worker   // calling SSLClientSocket::Connect.  This would normally be done in
93*6777b538SAndroid Build Coastguard Worker   // response to the user explicitly accepting the bad certificate.
94*6777b538SAndroid Build Coastguard Worker   std::vector<CertAndStatus> allowed_bad_certs;
95*6777b538SAndroid Build Coastguard Worker 
96*6777b538SAndroid Build Coastguard Worker   // True if all certificate errors should be ignored.
97*6777b538SAndroid Build Coastguard Worker   bool ignore_certificate_errors = false;
98*6777b538SAndroid Build Coastguard Worker 
99*6777b538SAndroid Build Coastguard Worker   // True if, for a single connection, any dependent network fetches should
100*6777b538SAndroid Build Coastguard Worker   // be disabled. This can be used to avoid triggering re-entrancy in the
101*6777b538SAndroid Build Coastguard Worker   // network layer. For example, fetching a PAC script over HTTPS may cause
102*6777b538SAndroid Build Coastguard Worker   // AIA, OCSP, or CRL fetches to block on retrieving the PAC script, while
103*6777b538SAndroid Build Coastguard Worker   // the PAC script fetch is waiting for those dependent fetches, creating a
104*6777b538SAndroid Build Coastguard Worker   // deadlock.
105*6777b538SAndroid Build Coastguard Worker   bool disable_cert_verification_network_fetches = false;
106*6777b538SAndroid Build Coastguard Worker 
107*6777b538SAndroid Build Coastguard Worker   // The list of application level protocols supported with ALPN (Application
108*6777b538SAndroid Build Coastguard Worker   // Layer Protocol Negotiation), in decreasing order of preference.  Protocols
109*6777b538SAndroid Build Coastguard Worker   // will be advertised in this order during TLS handshake.
110*6777b538SAndroid Build Coastguard Worker   NextProtoVector alpn_protos;
111*6777b538SAndroid Build Coastguard Worker 
112*6777b538SAndroid Build Coastguard Worker   // True if renegotiation should be allowed for the default application-level
113*6777b538SAndroid Build Coastguard Worker   // protocol when the peer does not negotiate ALPN.
114*6777b538SAndroid Build Coastguard Worker   bool renego_allowed_default = false;
115*6777b538SAndroid Build Coastguard Worker 
116*6777b538SAndroid Build Coastguard Worker   // The list of application-level protocols to enable renegotiation for.
117*6777b538SAndroid Build Coastguard Worker   NextProtoVector renego_allowed_for_protos;
118*6777b538SAndroid Build Coastguard Worker 
119*6777b538SAndroid Build Coastguard Worker   // ALPS data for each supported protocol in |alpn_protos|. Specifying a
120*6777b538SAndroid Build Coastguard Worker   // protocol in this map offers ALPS for that protocol and uses the
121*6777b538SAndroid Build Coastguard Worker   // corresponding value as the client settings string. The value may be empty.
122*6777b538SAndroid Build Coastguard Worker   // Keys which do not appear in |alpn_protos| are ignored.
123*6777b538SAndroid Build Coastguard Worker   ApplicationSettings application_settings;
124*6777b538SAndroid Build Coastguard Worker 
125*6777b538SAndroid Build Coastguard Worker   // If the PartitionSSLSessionsByNetworkIsolationKey feature is enabled, the
126*6777b538SAndroid Build Coastguard Worker   // session cache is partitioned by this value.
127*6777b538SAndroid Build Coastguard Worker   NetworkAnonymizationKey network_anonymization_key;
128*6777b538SAndroid Build Coastguard Worker 
129*6777b538SAndroid Build Coastguard Worker   // If non-empty, a serialized ECHConfigList to use to encrypt the ClientHello.
130*6777b538SAndroid Build Coastguard Worker   // If this field is non-empty, callers should handle |ERR_ECH_NOT_NEGOTIATED|
131*6777b538SAndroid Build Coastguard Worker   // errors from Connect() by calling GetECHRetryConfigs() to determine how to
132*6777b538SAndroid Build Coastguard Worker   // retry the connection.
133*6777b538SAndroid Build Coastguard Worker   std::vector<uint8_t> ech_config_list;
134*6777b538SAndroid Build Coastguard Worker 
135*6777b538SAndroid Build Coastguard Worker   // An additional boolean to partition the session cache by.
136*6777b538SAndroid Build Coastguard Worker   //
137*6777b538SAndroid Build Coastguard Worker   // TODO(https://crbug.com/775438, https://crbug.com/951205): This should
138*6777b538SAndroid Build Coastguard Worker   // additionally disable client certificates, once client certificate handling
139*6777b538SAndroid Build Coastguard Worker   // is moved into SSLClientContext. With client certificates are disabled, the
140*6777b538SAndroid Build Coastguard Worker   // current session cache partitioning behavior will be needed to correctly
141*6777b538SAndroid Build Coastguard Worker   // implement it. For now, it acts as an incomplete version of
142*6777b538SAndroid Build Coastguard Worker   // PartitionSSLSessionsByNetworkIsolationKey.
143*6777b538SAndroid Build Coastguard Worker   PrivacyMode privacy_mode = PRIVACY_MODE_DISABLED;
144*6777b538SAndroid Build Coastguard Worker 
145*6777b538SAndroid Build Coastguard Worker   // True if the post-handshake peeking of the transport should be skipped. This
146*6777b538SAndroid Build Coastguard Worker   // logic ensures tickets are resolved early, but can interfere with some unit
147*6777b538SAndroid Build Coastguard Worker   // tests.
148*6777b538SAndroid Build Coastguard Worker   bool disable_post_handshake_peek_for_testing = false;
149*6777b538SAndroid Build Coastguard Worker };
150*6777b538SAndroid Build Coastguard Worker 
151*6777b538SAndroid Build Coastguard Worker }  // namespace net
152*6777b538SAndroid Build Coastguard Worker 
153*6777b538SAndroid Build Coastguard Worker #endif  // NET_SSL_SSL_CONFIG_H_
154