Debian Codegraph @

crt/s2n/tls/s2n_quic_support.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
20 /*
21 * APIs intended to support an external implementation of the QUIC protocol:
22 * https://datatracker.ietf.org/wg/quic/about/
23 *
24 * QUIC requires access to parts of S2N not usually surfaced to customers. These APIs change
25 * the behavior of S2N in potentially dangerous ways and should only be used by implementations
26 * of the QUIC protocol.
27 *
28 * Additionally, all QUIC APIs are considered experimental and are subject to change without
29 * notice. They should only be used for testing purposes.
30 */
31
32 S2N_API int s2n_config_enable_quic(struct s2n_config *config);
33 S2N_API int s2n_connection_enable_quic(struct s2n_connection *conn);
34 S2N_API bool s2n_connection_is_quic_enabled(struct s2n_connection *conn);
35 S2N_API bool s2n_connection_are_session_tickets_enabled(struct s2n_connection *conn);
36
37 /*
38 * Set the data to be sent in the quic_transport_parameters extension.
39 * The data provided will be copied into a buffer owned by S2N.
40 */
41 S2N_API int s2n_connection_set_quic_transport_parameters(struct s2n_connection *conn,
42 const uint8_t *data_buffer, uint16_t data_len);
43
44 /*
45 * Retrieve the data from the peer's quic_transport_parameters extension.
46 * data_buffer will be set to a buffer owned by S2N which will be freed when the connection is freed.
47 * data_len will be set to the length of the data returned.
48 *
49 * S2N treats the extension data as opaque bytes and performs no validation.
50 */
51 S2N_API int s2n_connection_get_quic_transport_parameters(struct s2n_connection *conn,
52 const uint8_t **data_buffer, uint16_t *data_len);
53
54 typedef enum {
55 S2N_CLIENT_EARLY_TRAFFIC_SECRET = 0,
56 S2N_CLIENT_HANDSHAKE_TRAFFIC_SECRET,
57 S2N_SERVER_HANDSHAKE_TRAFFIC_SECRET,
58 S2N_CLIENT_APPLICATION_TRAFFIC_SECRET,
59 S2N_SERVER_APPLICATION_TRAFFIC_SECRET,
60 S2N_EXPORTER_SECRET,
61 } s2n_secret_type_t;
62
63 /*
64 * Called when S2N begins using a new key.
65 *
66 * The memory pointed to by "secret" will be wiped after this method returns and should be copied by
67 * the application if necessary. The application should also be very careful managing the memory and
68 * lifespan of the secret: if the secret is compromised, TLS is compromised.
69 */
70 typedef int (*s2n_secret_cb)(void *context, struct s2n_connection *conn,
71 s2n_secret_type_t secret_type, uint8_t *secret, uint8_t secret_size);
72
73 /*
74 * Set the function to be called when S2N begins using a new key.
75 *
76 * The callback function will ONLY be triggered if QUIC is enabled. This API is not intended to be
77 * used outside of a QUIC implementation.
78 */
79 S2N_API int s2n_connection_set_secret_callback(struct s2n_connection *conn, s2n_secret_cb cb_func, void *ctx);
80
81 /*
82 * Return the TLS alert that S2N-TLS would send, if S2N-TLS sent specific alerts.
83 *
84 * S2N-TLS only sends generic close_notify alerts for security reasons, and TLS never
85 * sends alerts when used by QUIC. This method returns the alert that would have been
86 * sent if S2N-TLS sent specific alerts as defined in the protocol specifications.
87 *
88 * WARNING: this method is still considered experimental and will not always report
89 * the correct alert description. It may be used for testing and logging, but
90 * not relied on for production logic.
91 */
92 S2N_API int s2n_error_get_alert(int error, uint8_t *alert);
93
94 /* Attempts to read and process a post-handshake message from QUIC. This function
95 * should be called when post-handshake messages in QUIC have been received.
96 */
97 S2N_API int s2n_recv_quic_post_handshake_message(struct s2n_connection *conn, s2n_blocked_status *blocked);