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