Home | History | Annotate | Line # | Download | only in internal
      1 /*
      2  * Copyright 2022-2025 The OpenSSL Project Authors. All Rights Reserved.
      3  *
      4  * Licensed under the Apache License 2.0 (the "License").  You may not use
      5  * this file except in compliance with the License.  You can obtain a copy
      6  * in the file LICENSE in the source distribution or at
      7  * https://www.openssl.org/source/license.html
      8  */
      9 
     10 #ifndef OSSL_QUIC_SSL_H
     11 #define OSSL_QUIC_SSL_H
     12 
     13 #include <openssl/ssl.h>
     14 #include <openssl/bio.h>
     15 #include "internal/refcount.h"
     16 #include "internal/quic_record_rx.h" /* OSSL_QRX */
     17 #include "internal/quic_ackm.h" /* OSSL_ACKM */
     18 #include "internal/quic_channel.h" /* QUIC_CHANNEL */
     19 #include "internal/quic_predef.h"
     20 
     21 #ifndef OPENSSL_NO_QUIC
     22 
     23 __owur SSL *ossl_quic_new(SSL_CTX *ctx);
     24 __owur SSL *ossl_quic_new_listener(SSL_CTX *ctx, uint64_t flags);
     25 __owur SSL *ossl_quic_new_listener_from(SSL *ssl, uint64_t flags);
     26 __owur SSL *ossl_quic_new_from_listener(SSL *ssl, uint64_t flags);
     27 __owur SSL *ossl_quic_new_domain(SSL_CTX *ctx, uint64_t flags);
     28 
     29 /*
     30  * Datatype returned from ossl_quic_get_peer_token
     31  */
     32 typedef struct quic_token_st {
     33     CRYPTO_REF_COUNT references;
     34     uint8_t *hashkey;
     35     size_t hashkey_len;
     36     uint8_t *token;
     37     size_t token_len;
     38 } QUIC_TOKEN;
     39 
     40 SSL_TOKEN_STORE *ossl_quic_new_token_store(void);
     41 void ossl_quic_free_token_store(SSL_TOKEN_STORE *hdl);
     42 SSL_TOKEN_STORE *ossl_quic_get0_token_store(SSL_CTX *ctx);
     43 int ossl_quic_set1_token_store(SSL_CTX *ctx, SSL_TOKEN_STORE *hdl);
     44 int ossl_quic_set_peer_token(SSL_CTX *ctx, BIO_ADDR *peer,
     45     const uint8_t *token, size_t token_len);
     46 int ossl_quic_get_peer_token(SSL_CTX *ctx, BIO_ADDR *peer,
     47     QUIC_TOKEN **token);
     48 void ossl_quic_free_peer_token(QUIC_TOKEN *token);
     49 
     50 __owur int ossl_quic_init(SSL *s);
     51 void ossl_quic_deinit(SSL *s);
     52 void ossl_quic_free(SSL *s);
     53 int ossl_quic_reset(SSL *s);
     54 int ossl_quic_clear(SSL *s);
     55 __owur int ossl_quic_accept(SSL *s);
     56 __owur int ossl_quic_connect(SSL *s);
     57 __owur int ossl_quic_read(SSL *s, void *buf, size_t len, size_t *readbytes);
     58 __owur int ossl_quic_peek(SSL *s, void *buf, size_t len, size_t *readbytes);
     59 __owur int ossl_quic_write_flags(SSL *s, const void *buf, size_t len,
     60     uint64_t flags, size_t *written);
     61 __owur int ossl_quic_write(SSL *s, const void *buf, size_t len, size_t *written);
     62 __owur long ossl_quic_ctrl(SSL *s, int cmd, long larg, void *parg);
     63 __owur long ossl_quic_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg);
     64 __owur long ossl_quic_callback_ctrl(SSL *s, int cmd, void (*fp)(void));
     65 __owur long ossl_quic_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void));
     66 __owur size_t ossl_quic_pending(const SSL *s);
     67 __owur int ossl_quic_key_update(SSL *s, int update_type);
     68 __owur int ossl_quic_get_key_update_type(const SSL *s);
     69 __owur const SSL_CIPHER *ossl_quic_get_cipher_by_char(const unsigned char *p);
     70 __owur int ossl_quic_num_ciphers(void);
     71 __owur const SSL_CIPHER *ossl_quic_get_cipher(unsigned int u);
     72 int ossl_quic_renegotiate_check(SSL *ssl, int initok);
     73 
     74 int ossl_quic_do_handshake(SSL *s);
     75 int ossl_quic_set_connect_state(SSL *s, int raiseerrs);
     76 int ossl_quic_set_accept_state(SSL *s, int raiseerrs);
     77 
     78 __owur int ossl_quic_has_pending(const SSL *s);
     79 __owur int ossl_quic_handle_events(SSL *s);
     80 __owur int ossl_quic_get_event_timeout(SSL *s, struct timeval *tv,
     81     int *is_infinite);
     82 OSSL_TIME ossl_quic_get_event_deadline(SSL *s);
     83 __owur int ossl_quic_get_rpoll_descriptor(SSL *s, BIO_POLL_DESCRIPTOR *d);
     84 __owur int ossl_quic_get_wpoll_descriptor(SSL *s, BIO_POLL_DESCRIPTOR *d);
     85 __owur int ossl_quic_get_net_read_desired(SSL *s);
     86 __owur int ossl_quic_get_net_write_desired(SSL *s);
     87 __owur int ossl_quic_get_error(const SSL *s, int i);
     88 __owur int ossl_quic_want(const SSL *s);
     89 __owur int ossl_quic_conn_get_blocking_mode(const SSL *s);
     90 __owur int ossl_quic_conn_set_blocking_mode(SSL *s, int blocking);
     91 __owur int ossl_quic_conn_shutdown(SSL *s, uint64_t flags,
     92     const SSL_SHUTDOWN_EX_ARGS *args,
     93     size_t args_len);
     94 __owur int ossl_quic_conn_stream_conclude(SSL *s);
     95 void ossl_quic_conn_set0_net_rbio(SSL *s, BIO *net_wbio);
     96 void ossl_quic_conn_set0_net_wbio(SSL *s, BIO *net_wbio);
     97 BIO *ossl_quic_conn_get_net_rbio(const SSL *s);
     98 BIO *ossl_quic_conn_get_net_wbio(const SSL *s);
     99 __owur int ossl_quic_conn_set_initial_peer_addr(SSL *s,
    100     const BIO_ADDR *peer_addr);
    101 __owur SSL *ossl_quic_conn_stream_new(SSL *s, uint64_t flags);
    102 __owur SSL *ossl_quic_get0_connection(SSL *s);
    103 __owur SSL *ossl_quic_get0_listener(SSL *s);
    104 __owur SSL *ossl_quic_get0_domain(SSL *s);
    105 __owur int ossl_quic_get_domain_flags(const SSL *s, uint64_t *domain_flags);
    106 __owur int ossl_quic_get_stream_type(SSL *s);
    107 __owur uint64_t ossl_quic_get_stream_id(SSL *s);
    108 __owur int ossl_quic_is_stream_local(SSL *s);
    109 __owur int ossl_quic_set_default_stream_mode(SSL *s, uint32_t mode);
    110 __owur SSL *ossl_quic_detach_stream(SSL *s);
    111 __owur int ossl_quic_attach_stream(SSL *conn, SSL *stream);
    112 __owur int ossl_quic_set_incoming_stream_policy(SSL *s, int policy,
    113     uint64_t aec);
    114 __owur SSL *ossl_quic_accept_stream(SSL *s, uint64_t flags);
    115 __owur size_t ossl_quic_get_accept_stream_queue_len(SSL *s);
    116 __owur int ossl_quic_get_value_uint(SSL *s, uint32_t class_, uint32_t id,
    117     uint64_t *value);
    118 __owur int ossl_quic_set_value_uint(SSL *s, uint32_t class_, uint32_t id,
    119     uint64_t value);
    120 __owur SSL *ossl_quic_accept_connection(SSL *ssl, uint64_t flags);
    121 __owur size_t ossl_quic_get_accept_connection_queue_len(SSL *ssl);
    122 __owur int ossl_quic_listen(SSL *ssl);
    123 
    124 __owur int ossl_quic_stream_reset(SSL *ssl,
    125     const SSL_STREAM_RESET_ARGS *args,
    126     size_t args_len);
    127 
    128 __owur int ossl_quic_get_stream_read_state(SSL *ssl);
    129 __owur int ossl_quic_get_stream_write_state(SSL *ssl);
    130 __owur int ossl_quic_get_stream_read_error_code(SSL *ssl,
    131     uint64_t *app_error_code);
    132 __owur int ossl_quic_get_stream_write_error_code(SSL *ssl,
    133     uint64_t *app_error_code);
    134 __owur int ossl_quic_get_conn_close_info(SSL *ssl,
    135     SSL_CONN_CLOSE_INFO *info,
    136     size_t info_len);
    137 
    138 uint64_t ossl_quic_set_options(SSL *s, uint64_t opts);
    139 uint64_t ossl_quic_clear_options(SSL *s, uint64_t opts);
    140 uint64_t ossl_quic_get_options(const SSL *s);
    141 
    142 /* Modifies write buffer size for a stream. */
    143 __owur int ossl_quic_set_write_buffer_size(SSL *s, size_t size);
    144 
    145 /*
    146  * Used to override ossl_time_now() for debug purposes. While this may be
    147  * overridden at any time, expect strange results if you change it after
    148  * connecting.
    149  */
    150 int ossl_quic_set_override_now_cb(SSL *s,
    151     OSSL_TIME (*now_cb)(void *arg),
    152     void *now_cb_arg);
    153 
    154 /*
    155  * Condvar waiting in the assist thread doesn't support time faking as it relies
    156  * on the OS's notion of time, thus this is used in test code to force a
    157  * spurious wakeup instead.
    158  */
    159 void ossl_quic_conn_force_assist_thread_wake(SSL *s);
    160 
    161 /* For use by tests only. */
    162 QUIC_CHANNEL *ossl_quic_conn_get_channel(SSL *s);
    163 
    164 int ossl_quic_has_pending(const SSL *s);
    165 int ossl_quic_get_shutdown(const SSL *s);
    166 
    167 /*
    168  * Set qlog diagnostic title. String is copied internally on success and need
    169  * not remain allocated. Only has any effect if logging has not already begun.
    170  * For use by tests only. Setting this on a context affects any QCSO created
    171  * after this is called but does not affect QCSOs already created from a
    172  * context.
    173  */
    174 int ossl_quic_set_diag_title(SSL_CTX *ctx, const char *title);
    175 
    176 /* APIs used by the polling infrastructure */
    177 int ossl_quic_conn_poll_events(SSL *ssl, uint64_t events, int do_tick,
    178     uint64_t *revents);
    179 int ossl_quic_get_notifier_fd(SSL *ssl);
    180 void ossl_quic_enter_blocking_section(SSL *ssl, QUIC_REACTOR_WAIT_CTX *wctx);
    181 void ossl_quic_leave_blocking_section(SSL *ssl, QUIC_REACTOR_WAIT_CTX *wctx);
    182 
    183 #endif
    184 
    185 #endif
    186