1*e7be843bSPierre Pronchery /* 2*e7be843bSPierre Pronchery * Copyright 2022-2025 The OpenSSL Project Authors. All Rights Reserved. 3*e7be843bSPierre Pronchery * 4*e7be843bSPierre Pronchery * Licensed under the Apache License 2.0 (the "License"). You may not use 5*e7be843bSPierre Pronchery * this file except in compliance with the License. You can obtain a copy 6*e7be843bSPierre Pronchery * in the file LICENSE in the source distribution or at 7*e7be843bSPierre Pronchery * https://www.openssl.org/source/license.html 8*e7be843bSPierre Pronchery */ 9*e7be843bSPierre Pronchery 10*e7be843bSPierre Pronchery #ifndef OSSL_QUIC_TLS_H 11*e7be843bSPierre Pronchery # define OSSL_QUIC_TLS_H 12*e7be843bSPierre Pronchery 13*e7be843bSPierre Pronchery # include <openssl/ssl.h> 14*e7be843bSPierre Pronchery 15*e7be843bSPierre Pronchery typedef struct quic_tls_st QUIC_TLS; 16*e7be843bSPierre Pronchery 17*e7be843bSPierre Pronchery typedef struct quic_tls_args_st { 18*e7be843bSPierre Pronchery /* 19*e7be843bSPierre Pronchery * The "inner" SSL object for the QUIC Connection. Contains an 20*e7be843bSPierre Pronchery * SSL_CONNECTION 21*e7be843bSPierre Pronchery */ 22*e7be843bSPierre Pronchery SSL *s; 23*e7be843bSPierre Pronchery 24*e7be843bSPierre Pronchery /* 25*e7be843bSPierre Pronchery * Called to send data on the crypto stream. We use a callback rather than 26*e7be843bSPierre Pronchery * passing the crypto stream QUIC_SSTREAM directly because this lets the CSM 27*e7be843bSPierre Pronchery * dynamically select the correct outgoing crypto stream based on the 28*e7be843bSPierre Pronchery * current EL. 29*e7be843bSPierre Pronchery */ 30*e7be843bSPierre Pronchery int (*crypto_send_cb)(const unsigned char *buf, size_t buf_len, 31*e7be843bSPierre Pronchery size_t *consumed, void *arg); 32*e7be843bSPierre Pronchery void *crypto_send_cb_arg; 33*e7be843bSPierre Pronchery 34*e7be843bSPierre Pronchery /* 35*e7be843bSPierre Pronchery * Call to receive crypto stream data. A pointer to the underlying buffer 36*e7be843bSPierre Pronchery * is provided, and subsequently released to avoid unnecessary copying of 37*e7be843bSPierre Pronchery * data. 38*e7be843bSPierre Pronchery */ 39*e7be843bSPierre Pronchery int (*crypto_recv_rcd_cb)(const unsigned char **buf, size_t *bytes_read, 40*e7be843bSPierre Pronchery void *arg); 41*e7be843bSPierre Pronchery void *crypto_recv_rcd_cb_arg; 42*e7be843bSPierre Pronchery int (*crypto_release_rcd_cb)(size_t bytes_read, void *arg); 43*e7be843bSPierre Pronchery void *crypto_release_rcd_cb_arg; 44*e7be843bSPierre Pronchery 45*e7be843bSPierre Pronchery /* 46*e7be843bSPierre Pronchery * Called when a traffic secret is available for a given TLS protection 47*e7be843bSPierre Pronchery * level. 48*e7be843bSPierre Pronchery */ 49*e7be843bSPierre Pronchery int (*yield_secret_cb)(uint32_t prot_level, int direction /* 0=RX, 1=TX */, 50*e7be843bSPierre Pronchery uint32_t suite_id, EVP_MD *md, 51*e7be843bSPierre Pronchery const unsigned char *secret, size_t secret_len, 52*e7be843bSPierre Pronchery void *arg); 53*e7be843bSPierre Pronchery void *yield_secret_cb_arg; 54*e7be843bSPierre Pronchery 55*e7be843bSPierre Pronchery /* 56*e7be843bSPierre Pronchery * Called when we receive transport parameters from the peer. 57*e7be843bSPierre Pronchery * 58*e7be843bSPierre Pronchery * Note: These parameters are not authenticated until the handshake is 59*e7be843bSPierre Pronchery * marked as completed. 60*e7be843bSPierre Pronchery */ 61*e7be843bSPierre Pronchery int (*got_transport_params_cb)(const unsigned char *params, 62*e7be843bSPierre Pronchery size_t params_len, 63*e7be843bSPierre Pronchery void *arg); 64*e7be843bSPierre Pronchery void *got_transport_params_cb_arg; 65*e7be843bSPierre Pronchery 66*e7be843bSPierre Pronchery /* 67*e7be843bSPierre Pronchery * Called when the handshake has been completed as far as the handshake 68*e7be843bSPierre Pronchery * protocol is concerned, meaning that the connection has been 69*e7be843bSPierre Pronchery * authenticated. 70*e7be843bSPierre Pronchery */ 71*e7be843bSPierre Pronchery int (*handshake_complete_cb)(void *arg); 72*e7be843bSPierre Pronchery void *handshake_complete_cb_arg; 73*e7be843bSPierre Pronchery 74*e7be843bSPierre Pronchery /* 75*e7be843bSPierre Pronchery * Called when something has gone wrong with the connection as far as the 76*e7be843bSPierre Pronchery * handshake layer is concerned, meaning that it should be immediately torn 77*e7be843bSPierre Pronchery * down. Note that this may happen at any time, including after a connection 78*e7be843bSPierre Pronchery * has been fully established. 79*e7be843bSPierre Pronchery */ 80*e7be843bSPierre Pronchery int (*alert_cb)(void *arg, unsigned char alert_code); 81*e7be843bSPierre Pronchery void *alert_cb_arg; 82*e7be843bSPierre Pronchery 83*e7be843bSPierre Pronchery /* Set to 1 if we are running in the server role. */ 84*e7be843bSPierre Pronchery int is_server; 85*e7be843bSPierre Pronchery 86*e7be843bSPierre Pronchery /* Set to 1 if this is an internal use of the QUIC TLS */ 87*e7be843bSPierre Pronchery int ossl_quic; 88*e7be843bSPierre Pronchery } QUIC_TLS_ARGS; 89*e7be843bSPierre Pronchery 90*e7be843bSPierre Pronchery QUIC_TLS *ossl_quic_tls_new(const QUIC_TLS_ARGS *args); 91*e7be843bSPierre Pronchery 92*e7be843bSPierre Pronchery void ossl_quic_tls_free(QUIC_TLS *qtls); 93*e7be843bSPierre Pronchery 94*e7be843bSPierre Pronchery int ossl_quic_tls_configure(QUIC_TLS *qtls); 95*e7be843bSPierre Pronchery 96*e7be843bSPierre Pronchery /* Advance the state machine */ 97*e7be843bSPierre Pronchery int ossl_quic_tls_tick(QUIC_TLS *qtls); 98*e7be843bSPierre Pronchery 99*e7be843bSPierre Pronchery void ossl_quic_tls_clear(QUIC_TLS *qtls); 100*e7be843bSPierre Pronchery 101*e7be843bSPierre Pronchery int ossl_quic_tls_set_transport_params(QUIC_TLS *qtls, 102*e7be843bSPierre Pronchery const unsigned char *transport_params, 103*e7be843bSPierre Pronchery size_t transport_params_len); 104*e7be843bSPierre Pronchery 105*e7be843bSPierre Pronchery int ossl_quic_tls_get_error(QUIC_TLS *qtls, 106*e7be843bSPierre Pronchery uint64_t *error_code, 107*e7be843bSPierre Pronchery const char **error_msg, 108*e7be843bSPierre Pronchery ERR_STATE **error_state); 109*e7be843bSPierre Pronchery 110*e7be843bSPierre Pronchery int ossl_quic_tls_is_cert_request(QUIC_TLS *qtls); 111*e7be843bSPierre Pronchery int ossl_quic_tls_has_bad_max_early_data(QUIC_TLS *qtls); 112*e7be843bSPierre Pronchery 113*e7be843bSPierre Pronchery int ossl_quic_tls_set_early_data_enabled(QUIC_TLS *qtls, int enabled); 114*e7be843bSPierre Pronchery #endif 115