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