Debian Codegraph @

crt/s2n/tls/s2n_config.h

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #pragma once
17
18 #include "api/s2n.h"
19 #include "api/unstable/async_offload.h"
20 #include "api/unstable/cert_authorities.h"
21 #include "api/unstable/events.h"
22 #include "crypto/s2n_certificate.h"
23 #include "crypto/s2n_dhe.h"
24 #include "tls/s2n_crl.h"
25 #include "tls/s2n_key_update.h"
26 #include "tls/s2n_psk.h"
27 #include "tls/s2n_record.h"
28 #include "tls/s2n_renegotiate.h"
29 #include "tls/s2n_resume.h"
30 #include "tls/s2n_tls_parameters.h"
31 #include "tls/s2n_x509_validator.h"
32 #include "utils/s2n_blob.h"
33 #include "utils/s2n_prelude.h"
34
35 #define S2N_MAX_TICKET_KEYS 48
36
37 /*
38 * TLS1.3 does not allow alert messages to be fragmented, and some TLS
39 * implementations (for example, GnuTLS) reject fragmented TLS1.2 alerts.
40 * The send buffer must be able to hold an unfragmented alert message.
41 *
42 * We choose not to fragment KeyUpdate messages to keep our post-handshake
43 * fragmentation logic simple and consistent across message types.
44 * The send buffer must be able to hold an unfragmented KeyUpdate message.
45 */
46 #define S2N_MIN_SEND_BUFFER_FRAGMENT_SIZE S2N_MAX(S2N_KEY_UPDATE_MESSAGE_SIZE, S2N_ALERT_LENGTH)
47 #define S2N_MIN_SEND_BUFFER_SIZE S2N_TLS_MAX_RECORD_LEN_FOR(S2N_MIN_SEND_BUFFER_FRAGMENT_SIZE)
48
49 struct s2n_cipher_preferences;
50
51 typedef enum {
52 S2N_NOT_OWNED = 0,
53 S2N_APP_OWNED,
54 S2N_LIB_OWNED,
55 } s2n_cert_ownership;
56
57 struct s2n_config {
58 unsigned use_tickets : 1;
59
60 /* Whether a connection can be used by a QUIC implementation.
61 * See s2n_quic_support.h */
62 unsigned quic_enabled : 1;
63
64 unsigned default_certs_are_explicit : 1;
65 unsigned use_session_cache : 1;
66 /* if this is FALSE, server will ignore client's Maximum Fragment Length request */
67 unsigned accept_mfl : 1;
68 unsigned check_ocsp : 1;
69 unsigned disable_x509_time_validation : 1;
70 unsigned disable_x509_intent_verification : 1;
71 unsigned disable_x509_validation : 1;
72 unsigned max_verify_cert_chain_depth_set : 1;
73 /* Whether to add dss cert type during a server certificate request.
74 * See s2n_config_enable_cert_req_dss_legacy_compat. */
75 unsigned cert_req_dss_legacy_compat_enabled : 1;
76 /* Whether any RSA certificates have been configured server-side to send to clients. This is needed so that the
77 * server knows whether or not to self-downgrade to TLS 1.2 if the server is compiled with Openssl 1.0.2 and does
78 * not support RSA PSS signing (which is required for TLS 1.3). */
79 unsigned is_rsa_cert_configured : 1;
80 /* It's possible to use a certificate without loading the private key,
81 * but async signing must be enabled. Use this flag to enforce that restriction.
82 */
83 unsigned no_signing_key : 1;
84 /*
85 * Whether to verify signatures locally before sending them over the wire.
86 * See s2n_config_set_verify_after_sign.
87 */
88 unsigned verify_after_sign : 1;
89
90 /* Indicates support for the npn extension */
91 unsigned npn_supported : 1;
92
93 /* Indicates s2n_recv should read as much as it can into the output buffer
94 *
95 * Note: This defaults to false to ensure backwards compatibility with
96 * applications which relied on s2n_recv returning a single record.
97 */
98 unsigned recv_multi_record : 1;
99
100 /* Indicates whether the user has enabled OCSP status requests */
101 unsigned ocsp_status_requested_by_user : 1;
102
103 /* Indicates whether s2n has enabled OCSP status requests, for backwards compatibility */
104 unsigned ocsp_status_requested_by_s2n : 1;
105
106 /* TLS1.3 can be dangerous with kTLS. Require it to be explicitly enabled. */
107 unsigned ktls_tls13_enabled : 1;
108
109 unsigned custom_blinding_set : 1;
110
111 unsigned ticket_forward_secrecy : 1;
112
113 struct s2n_dh_params *dhparams;
114 /* Needed until we can deprecate s2n_config_add_cert_chain_and_key. This is
115 * used to release memory allocated only in the deprecated API that the application
116 * does not have a reference to. */
117 struct s2n_map *domain_name_to_cert_map;
118 struct certs_by_type default_certs_by_type;
119 struct s2n_blob application_protocols;
120 s2n_clock_time_nanoseconds wall_clock;
121 s2n_clock_time_nanoseconds monotonic_clock;
122
123 const struct s2n_security_policy *security_policy;
124
125 void *sys_clock_ctx;
126 void *monotonic_clock_ctx;
127
128 s2n_client_hello_fn *client_hello_cb;
129 s2n_client_hello_cb_mode client_hello_cb_mode;
130
131 uint32_t max_blinding;
132
133 void *client_hello_cb_ctx;
134
135 uint64_t session_state_lifetime_in_nanos;
136
137 struct s2n_array *ticket_keys;
138 uint64_t encrypt_decrypt_key_lifetime_in_nanos;
139 uint64_t decrypt_key_lifetime_in_nanos;
140
141 /* If session cache is being used, these must all be set */
142 s2n_cache_store_callback cache_store;
143 void *cache_store_data;
144
145 s2n_cache_retrieve_callback cache_retrieve;
146 void *cache_retrieve_data;
147
148 s2n_cache_delete_callback cache_delete;
149 void *cache_delete_data;
150
151 s2n_ct_support_level ct_type;
152
153 /* Track whether the application has overridden the default client auth type.
154 * Clients and servers have different default client auth behavior, and this
155 * config could apply to either.
156 * This should be a bitflag, but that change is blocked on the SAW proofs.
157 */
158 uint8_t client_cert_auth_type_overridden;
159
160 /* Whether or not the client should authenticate itself to the server.
161 * Only used if client_cert_auth_type_overridden is true.
162 */
163 s2n_cert_auth_type client_cert_auth_type;
164
165 s2n_alert_behavior alert_behavior;
166
167 /* Return TRUE if the host should be trusted, If FALSE this will likely be called again for every host/alternative name
168 * in the certificate. If any respond TRUE. If none return TRUE, the cert will be considered untrusted. */
169 s2n_verify_host_fn verify_host_fn;
170 void *data_for_verify_host;
171 unsigned allow_ip_in_cn : 1;
172
173 s2n_crl_lookup_callback crl_lookup_cb;
174 void *crl_lookup_ctx;
175
176 s2n_cert_validation_callback cert_validation_cb;
177 void *cert_validation_ctx;
178
179 STACK_OF(ASN1_OBJECT) *custom_x509_extension_oids;
180
181 /* Application supplied callback to resolve domain name conflicts when loading certs. */
182 s2n_cert_tiebreak_callback cert_tiebreak_cb;
183
184 uint8_t mfl_code;
185
186 uint8_t initial_tickets_to_send;
187
188 struct s2n_x509_trust_store trust_store;
189 uint16_t max_verify_cert_chain_depth;
190
191 s2n_async_offload_cb async_offload_cb;
192 uint32_t async_offload_allow_list;
193 void *async_offload_ctx;
194
195 s2n_async_pkey_fn async_pkey_cb;
196
197 s2n_psk_selection_callback psk_selection_cb;
198 void *psk_selection_ctx;
199
200 s2n_key_log_fn key_log_cb;
201 void *key_log_ctx;
202
203 s2n_session_ticket_fn session_ticket_cb;
204 void *session_ticket_ctx;
205
206 s2n_cert_request_callback cert_request_cb;
207 void *cert_request_cb_ctx;
208
209 s2n_early_data_cb early_data_cb;
210
211 uint32_t server_max_early_data_size;
212
213 s2n_psk_mode psk_mode;
214
215 s2n_async_pkey_validation_mode async_pkey_validation_mode;
216
217 void *subscriber;
218 s2n_event_on_handshake_cb on_handshake_event;
219
220 /* The user defined context associated with config */
221 void *context;
222
223 s2n_cert_ownership cert_ownership;
224
225 /* Used to override the stuffer size for a connection's `out` stuffer. */
226 uint32_t send_buffer_size_override;
227
228 void *renegotiate_request_ctx;
229 s2n_renegotiate_request_cb renegotiate_request_cb;
230
231 /* This version is meant as a safeguard against future TLS features which might affect the connection
232 * serialization feature.
233 *
234 * For example, suppose that a new TLS parameter is released which affects how data is sent
235 * post-handshake. This parameter must be available in both the s2n-tls version that serializes the
236 * connection, as well as the version that deserializes the connection. If not, the serializer
237 * may negotiate this feature with its peer, which would cause an older deserializer to run into errors
238 * sending data to the peer.
239 *
240 * This kind of version-mismatch can happen during deployments and rollbacks, and therefore we require
241 * the user to tell us which serialized version they support pre-handshake.
242 * We will not negotiate a new feature until the user requests the serialized connection
243 * version the feature is tied to (i.e. the request indicates they have finished deploying
244 * the new feature to their entire fleet.)
245 */
246 s2n_serialization_version serialized_connection_version;
247
248 /* List of certificate authorities supported */
249 struct s2n_blob cert_authorities;
250 };
251
252 S2N_CLEANUP_RESULT s2n_config_ptr_free(struct s2n_config **config);
253
254 int s2n_config_defaults_init(void);
255 struct s2n_config *s2n_fetch_default_config(void);
256 int s2n_config_set_unsafe_for_testing(struct s2n_config *config);
257
258 int s2n_config_init_session_ticket_keys(struct s2n_config *config);
259 int s2n_config_free_session_ticket_keys(struct s2n_config *config);
260
261 void s2n_wipe_static_configs(void);
262 struct s2n_cert_chain_and_key *s2n_config_get_single_default_cert(struct s2n_config *config);
263 int s2n_config_get_num_default_certs(const struct s2n_config *config);
264 S2N_RESULT s2n_config_wall_clock(struct s2n_config *config, uint64_t *output);
265 S2N_RESULT s2n_config_monotonic_clock(struct s2n_config *config, uint64_t *output);
266
267 /* Validate that the certificates in `config` respect the certificate preferences
268 * in `security_policy` */
269 S2N_RESULT s2n_config_validate_loaded_certificates(const struct s2n_config *config,
270 const struct s2n_security_policy *security_policy);
271 int s2n_default_monotonic_clock(void *data, uint64_t *nanoseconds);