113498266Sopenharmony_ci#ifndef HEADER_CURL_VQUIC_TLS_H
213498266Sopenharmony_ci#define HEADER_CURL_VQUIC_TLS_H
313498266Sopenharmony_ci/***************************************************************************
413498266Sopenharmony_ci *                                  _   _ ____  _
513498266Sopenharmony_ci *  Project                     ___| | | |  _ \| |
613498266Sopenharmony_ci *                             / __| | | | |_) | |
713498266Sopenharmony_ci *                            | (__| |_| |  _ <| |___
813498266Sopenharmony_ci *                             \___|\___/|_| \_\_____|
913498266Sopenharmony_ci *
1013498266Sopenharmony_ci * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
1113498266Sopenharmony_ci *
1213498266Sopenharmony_ci * This software is licensed as described in the file COPYING, which
1313498266Sopenharmony_ci * you should have received as part of this distribution. The terms
1413498266Sopenharmony_ci * are also available at https://curl.se/docs/copyright.html.
1513498266Sopenharmony_ci *
1613498266Sopenharmony_ci * You may opt to use, copy, modify, merge, publish, distribute and/or sell
1713498266Sopenharmony_ci * copies of the Software, and permit persons to whom the Software is
1813498266Sopenharmony_ci * furnished to do so, under the terms of the COPYING file.
1913498266Sopenharmony_ci *
2013498266Sopenharmony_ci * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
2113498266Sopenharmony_ci * KIND, either express or implied.
2213498266Sopenharmony_ci *
2313498266Sopenharmony_ci * SPDX-License-Identifier: curl
2413498266Sopenharmony_ci *
2513498266Sopenharmony_ci ***************************************************************************/
2613498266Sopenharmony_ci
2713498266Sopenharmony_ci#include "curl_setup.h"
2813498266Sopenharmony_ci#include "bufq.h"
2913498266Sopenharmony_ci
3013498266Sopenharmony_ci#if defined(ENABLE_QUIC) && \
3113498266Sopenharmony_ci  (defined(USE_OPENSSL) || defined(USE_GNUTLS) || defined(USE_WOLFSSL))
3213498266Sopenharmony_ci
3313498266Sopenharmony_cistruct quic_tls_ctx {
3413498266Sopenharmony_ci#ifdef USE_OPENSSL
3513498266Sopenharmony_ci  SSL_CTX *ssl_ctx;
3613498266Sopenharmony_ci  SSL *ssl;
3713498266Sopenharmony_ci#elif defined(USE_GNUTLS)
3813498266Sopenharmony_ci  struct gtls_instance *gtls;
3913498266Sopenharmony_ci#elif defined(USE_WOLFSSL)
4013498266Sopenharmony_ci  WOLFSSL_CTX *ssl_ctx;
4113498266Sopenharmony_ci  WOLFSSL *ssl;
4213498266Sopenharmony_ci#endif
4313498266Sopenharmony_ci  BIT(x509_store_setup);             /* if x509 store has been set up */
4413498266Sopenharmony_ci};
4513498266Sopenharmony_ci
4613498266Sopenharmony_ci/**
4713498266Sopenharmony_ci * Callback passed to `Curl_vquic_tls_init()` that can
4813498266Sopenharmony_ci * do early initializations on the not otherwise configured TLS
4913498266Sopenharmony_ci * instances created. This varies by TLS backend:
5013498266Sopenharmony_ci * - openssl/wolfssl: SSL_CTX* has just been created
5113498266Sopenharmony_ci * - gnutls: gtls_client_init() has run
5213498266Sopenharmony_ci */
5313498266Sopenharmony_citypedef CURLcode Curl_vquic_tls_ctx_setup(struct quic_tls_ctx *ctx,
5413498266Sopenharmony_ci                                          struct Curl_cfilter *cf,
5513498266Sopenharmony_ci                                          struct Curl_easy *data);
5613498266Sopenharmony_ci
5713498266Sopenharmony_ci/**
5813498266Sopenharmony_ci * Initialize the QUIC TLS instances based of the SSL configurations
5913498266Sopenharmony_ci * for the connection filter, transfer and peer.
6013498266Sopenharmony_ci * @param ctx         the TLS context to initialize
6113498266Sopenharmony_ci * @param cf          the connection filter involved
6213498266Sopenharmony_ci * @param data        the transfer involved
6313498266Sopenharmony_ci * @param peer        the peer that will be connected to
6413498266Sopenharmony_ci * @param alpn        the ALPN string in protocol format ((len+bytes+)+),
6513498266Sopenharmony_ci *                    may be NULL
6613498266Sopenharmony_ci * @param alpn_len    the overall number of bytes in `alpn`
6713498266Sopenharmony_ci * @param ctx_setup   optional callback for very early TLS config
6813498266Sopenharmony_ci * @param user_data   optional pointer to set in TLS application context
6913498266Sopenharmony_ci */
7013498266Sopenharmony_ciCURLcode Curl_vquic_tls_init(struct quic_tls_ctx *ctx,
7113498266Sopenharmony_ci                             struct Curl_cfilter *cf,
7213498266Sopenharmony_ci                             struct Curl_easy *data,
7313498266Sopenharmony_ci                             struct ssl_peer *peer,
7413498266Sopenharmony_ci                             const char *alpn, size_t alpn_len,
7513498266Sopenharmony_ci                             Curl_vquic_tls_ctx_setup *ctx_setup,
7613498266Sopenharmony_ci                             void *user_data);
7713498266Sopenharmony_ci
7813498266Sopenharmony_ci/**
7913498266Sopenharmony_ci * Cleanup all data that has been initialized.
8013498266Sopenharmony_ci */
8113498266Sopenharmony_civoid Curl_vquic_tls_cleanup(struct quic_tls_ctx *ctx);
8213498266Sopenharmony_ci
8313498266Sopenharmony_ciCURLcode Curl_vquic_tls_before_recv(struct quic_tls_ctx *ctx,
8413498266Sopenharmony_ci                                    struct Curl_cfilter *cf,
8513498266Sopenharmony_ci                                    struct Curl_easy *data);
8613498266Sopenharmony_ci
8713498266Sopenharmony_ci/**
8813498266Sopenharmony_ci * After the QUIC basic handshake has been, verify that the peer
8913498266Sopenharmony_ci * (and its certificate) fulfill our requirements.
9013498266Sopenharmony_ci */
9113498266Sopenharmony_ciCURLcode Curl_vquic_tls_verify_peer(struct quic_tls_ctx *ctx,
9213498266Sopenharmony_ci                                    struct Curl_cfilter *cf,
9313498266Sopenharmony_ci                                    struct Curl_easy *data,
9413498266Sopenharmony_ci                                    struct ssl_peer *peer);
9513498266Sopenharmony_ci
9613498266Sopenharmony_ci#endif /* !ENABLE_QUIC && (USE_OPENSSL || USE_GNUTLS || USE_WOLFSSL) */
9713498266Sopenharmony_ci
9813498266Sopenharmony_ci#endif /* HEADER_CURL_VQUIC_TLS_H */
99