init repo.
This commit is contained in:
1115
third_party/curl/lib/vquic/curl_msh3.c
vendored
Normal file
1115
third_party/curl/lib/vquic/curl_msh3.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
46
third_party/curl/lib/vquic/curl_msh3.h
vendored
Normal file
46
third_party/curl/lib/vquic/curl_msh3.h
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef HEADER_CURL_VQUIC_CURL_MSH3_H
|
||||
#define HEADER_CURL_VQUIC_CURL_MSH3_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_MSH3
|
||||
|
||||
#include <msh3.h>
|
||||
|
||||
void Curl_msh3_ver(char *p, size_t len);
|
||||
|
||||
CURLcode Curl_cf_msh3_create(struct Curl_cfilter **pcf,
|
||||
struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
const struct Curl_addrinfo *ai);
|
||||
|
||||
bool Curl_conn_is_msh3(const struct Curl_easy *data,
|
||||
const struct connectdata *conn,
|
||||
int sockindex);
|
||||
|
||||
#endif /* USE_MSQUIC */
|
||||
|
||||
#endif /* HEADER_CURL_VQUIC_CURL_MSH3_H */
|
2509
third_party/curl/lib/vquic/curl_ngtcp2.c
vendored
Normal file
2509
third_party/curl/lib/vquic/curl_ngtcp2.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
61
third_party/curl/lib/vquic/curl_ngtcp2.h
vendored
Normal file
61
third_party/curl/lib/vquic/curl_ngtcp2.h
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
#ifndef HEADER_CURL_VQUIC_CURL_NGTCP2_H
|
||||
#define HEADER_CURL_VQUIC_CURL_NGTCP2_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#if defined(USE_NGTCP2) && defined(USE_NGHTTP3)
|
||||
|
||||
#ifdef HAVE_NETINET_UDP_H
|
||||
#include <netinet/udp.h>
|
||||
#endif
|
||||
|
||||
#include <ngtcp2/ngtcp2_crypto.h>
|
||||
#include <nghttp3/nghttp3.h>
|
||||
#ifdef USE_OPENSSL
|
||||
#include <openssl/ssl.h>
|
||||
#elif defined(USE_WOLFSSL)
|
||||
#include <wolfssl/options.h>
|
||||
#include <wolfssl/ssl.h>
|
||||
#include <wolfssl/quic.h>
|
||||
#endif
|
||||
|
||||
struct Curl_cfilter;
|
||||
|
||||
#include "urldata.h"
|
||||
|
||||
void Curl_ngtcp2_ver(char *p, size_t len);
|
||||
|
||||
CURLcode Curl_cf_ngtcp2_create(struct Curl_cfilter **pcf,
|
||||
struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
const struct Curl_addrinfo *ai);
|
||||
|
||||
bool Curl_conn_is_ngtcp2(const struct Curl_easy *data,
|
||||
const struct connectdata *conn,
|
||||
int sockindex);
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_CURL_VQUIC_CURL_NGTCP2_H */
|
2332
third_party/curl/lib/vquic/curl_osslq.c
vendored
Normal file
2332
third_party/curl/lib/vquic/curl_osslq.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
51
third_party/curl/lib/vquic/curl_osslq.h
vendored
Normal file
51
third_party/curl/lib/vquic/curl_osslq.h
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
#ifndef HEADER_CURL_VQUIC_CURL_OSSLQ_H
|
||||
#define HEADER_CURL_VQUIC_CURL_OSSLQ_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#if defined(USE_OPENSSL_QUIC) && defined(USE_NGHTTP3)
|
||||
|
||||
#ifdef HAVE_NETINET_UDP_H
|
||||
#include <netinet/udp.h>
|
||||
#endif
|
||||
|
||||
struct Curl_cfilter;
|
||||
|
||||
#include "urldata.h"
|
||||
|
||||
void Curl_osslq_ver(char *p, size_t len);
|
||||
|
||||
CURLcode Curl_cf_osslq_create(struct Curl_cfilter **pcf,
|
||||
struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
const struct Curl_addrinfo *ai);
|
||||
|
||||
bool Curl_conn_is_osslq(const struct Curl_easy *data,
|
||||
const struct connectdata *conn,
|
||||
int sockindex);
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_CURL_VQUIC_CURL_OSSLQ_H */
|
1651
third_party/curl/lib/vquic/curl_quiche.c
vendored
Normal file
1651
third_party/curl/lib/vquic/curl_quiche.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
50
third_party/curl/lib/vquic/curl_quiche.h
vendored
Normal file
50
third_party/curl/lib/vquic/curl_quiche.h
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
#ifndef HEADER_CURL_VQUIC_CURL_QUICHE_H
|
||||
#define HEADER_CURL_VQUIC_CURL_QUICHE_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_QUICHE
|
||||
|
||||
#include <quiche.h>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
struct Curl_cfilter;
|
||||
struct Curl_easy;
|
||||
|
||||
void Curl_quiche_ver(char *p, size_t len);
|
||||
|
||||
CURLcode Curl_cf_quiche_create(struct Curl_cfilter **pcf,
|
||||
struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
const struct Curl_addrinfo *ai);
|
||||
|
||||
bool Curl_conn_is_quiche(const struct Curl_easy *data,
|
||||
const struct connectdata *conn,
|
||||
int sockindex);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_CURL_VQUIC_CURL_QUICHE_H */
|
342
third_party/curl/lib/vquic/vquic-tls.c
vendored
Normal file
342
third_party/curl/lib/vquic/vquic-tls.c
vendored
Normal file
@ -0,0 +1,342 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#if defined(USE_HTTP3) && \
|
||||
(defined(USE_OPENSSL) || defined(USE_GNUTLS) || defined(USE_WOLFSSL))
|
||||
|
||||
#ifdef USE_OPENSSL
|
||||
#include <openssl/err.h>
|
||||
#include "vtls/openssl.h"
|
||||
#elif defined(USE_GNUTLS)
|
||||
#include <gnutls/abstract.h>
|
||||
#include <gnutls/gnutls.h>
|
||||
#include <gnutls/x509.h>
|
||||
#include <gnutls/crypto.h>
|
||||
#include <nettle/sha2.h>
|
||||
#include "vtls/gtls.h"
|
||||
#elif defined(USE_WOLFSSL)
|
||||
#include <wolfssl/options.h>
|
||||
#include <wolfssl/ssl.h>
|
||||
#include <wolfssl/quic.h>
|
||||
#include "vtls/wolfssl.h"
|
||||
#endif
|
||||
|
||||
#include "urldata.h"
|
||||
#include "curl_trc.h"
|
||||
#include "cfilters.h"
|
||||
#include "multiif.h"
|
||||
#include "vtls/keylog.h"
|
||||
#include "vtls/vtls.h"
|
||||
#include "vquic-tls.h"
|
||||
|
||||
/* The last 3 #include files should be in this order */
|
||||
#include "curl_printf.h"
|
||||
#include "curl_memory.h"
|
||||
#include "memdebug.h"
|
||||
|
||||
#ifndef ARRAYSIZE
|
||||
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
|
||||
#endif
|
||||
|
||||
#if defined(USE_WOLFSSL)
|
||||
|
||||
#define QUIC_CIPHERS \
|
||||
"TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_" \
|
||||
"POLY1305_SHA256:TLS_AES_128_CCM_SHA256"
|
||||
#define QUIC_GROUPS "P-256:P-384:P-521"
|
||||
|
||||
#if defined(HAVE_SECRET_CALLBACK)
|
||||
static void keylog_callback(const WOLFSSL *ssl, const char *line)
|
||||
{
|
||||
(void)ssl;
|
||||
Curl_tls_keylog_write_line(line);
|
||||
}
|
||||
#endif
|
||||
|
||||
static CURLcode curl_wssl_init_ctx(struct curl_tls_ctx *ctx,
|
||||
struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
Curl_vquic_tls_ctx_setup *cb_setup,
|
||||
void *cb_user_data)
|
||||
{
|
||||
struct ssl_primary_config *conn_config;
|
||||
CURLcode result = CURLE_FAILED_INIT;
|
||||
|
||||
conn_config = Curl_ssl_cf_get_primary_config(cf);
|
||||
if(!conn_config) {
|
||||
result = CURLE_FAILED_INIT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ctx->ssl_ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
|
||||
if(!ctx->ssl_ctx) {
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(cb_setup) {
|
||||
result = cb_setup(cf, data, cb_user_data);
|
||||
if(result)
|
||||
goto out;
|
||||
}
|
||||
|
||||
wolfSSL_CTX_set_default_verify_paths(ctx->ssl_ctx);
|
||||
|
||||
if(wolfSSL_CTX_set_cipher_list(ctx->ssl_ctx, conn_config->cipher_list13 ?
|
||||
conn_config->cipher_list13 :
|
||||
QUIC_CIPHERS) != 1) {
|
||||
char error_buffer[256];
|
||||
ERR_error_string_n(ERR_get_error(), error_buffer, sizeof(error_buffer));
|
||||
failf(data, "wolfSSL failed to set ciphers: %s", error_buffer);
|
||||
result = CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(wolfSSL_CTX_set1_groups_list(ctx->ssl_ctx, conn_config->curves ?
|
||||
conn_config->curves :
|
||||
(char *)QUIC_GROUPS) != 1) {
|
||||
failf(data, "wolfSSL failed to set curves");
|
||||
result = CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Open the file if a TLS or QUIC backend has not done this before. */
|
||||
Curl_tls_keylog_open();
|
||||
if(Curl_tls_keylog_enabled()) {
|
||||
#if defined(HAVE_SECRET_CALLBACK)
|
||||
wolfSSL_CTX_set_keylog_callback(ctx->ssl_ctx, keylog_callback);
|
||||
#else
|
||||
failf(data, "wolfSSL was built without keylog callback");
|
||||
result = CURLE_NOT_BUILT_IN;
|
||||
goto out;
|
||||
#endif
|
||||
}
|
||||
|
||||
if(conn_config->verifypeer) {
|
||||
const char * const ssl_cafile = conn_config->CAfile;
|
||||
const char * const ssl_capath = conn_config->CApath;
|
||||
|
||||
wolfSSL_CTX_set_verify(ctx->ssl_ctx, SSL_VERIFY_PEER, NULL);
|
||||
if(ssl_cafile || ssl_capath) {
|
||||
/* tell wolfSSL where to find CA certificates that are used to verify
|
||||
the server's certificate. */
|
||||
int rc =
|
||||
wolfSSL_CTX_load_verify_locations_ex(ctx->ssl_ctx, ssl_cafile,
|
||||
ssl_capath,
|
||||
WOLFSSL_LOAD_FLAG_IGNORE_ERR);
|
||||
if(SSL_SUCCESS != rc) {
|
||||
/* Fail if we insist on successfully verifying the server. */
|
||||
failf(data, "error setting certificate verify locations:"
|
||||
" CAfile: %s CApath: %s",
|
||||
ssl_cafile ? ssl_cafile : "none",
|
||||
ssl_capath ? ssl_capath : "none");
|
||||
result = CURLE_SSL_CACERT_BADFILE;
|
||||
goto out;
|
||||
}
|
||||
infof(data, " CAfile: %s", ssl_cafile ? ssl_cafile : "none");
|
||||
infof(data, " CApath: %s", ssl_capath ? ssl_capath : "none");
|
||||
}
|
||||
#ifdef CURL_CA_FALLBACK
|
||||
else {
|
||||
/* verifying the peer without any CA certificates won't work so
|
||||
use wolfssl's built-in default as fallback */
|
||||
wolfSSL_CTX_set_default_verify_paths(ctx->ssl_ctx);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
wolfSSL_CTX_set_verify(ctx->ssl_ctx, SSL_VERIFY_NONE, NULL);
|
||||
}
|
||||
|
||||
/* give application a chance to interfere with SSL set up. */
|
||||
if(data->set.ssl.fsslctx) {
|
||||
Curl_set_in_callback(data, true);
|
||||
result = (*data->set.ssl.fsslctx)(data, ctx->ssl_ctx,
|
||||
data->set.ssl.fsslctxp);
|
||||
Curl_set_in_callback(data, false);
|
||||
if(result) {
|
||||
failf(data, "error signaled by ssl ctx callback");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
result = CURLE_OK;
|
||||
|
||||
out:
|
||||
if(result && ctx->ssl_ctx) {
|
||||
SSL_CTX_free(ctx->ssl_ctx);
|
||||
ctx->ssl_ctx = NULL;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** SSL callbacks ***/
|
||||
|
||||
static CURLcode curl_wssl_init_ssl(struct curl_tls_ctx *ctx,
|
||||
struct Curl_easy *data,
|
||||
struct ssl_peer *peer,
|
||||
const char *alpn, size_t alpn_len,
|
||||
void *user_data)
|
||||
{
|
||||
(void)data;
|
||||
DEBUGASSERT(!ctx->ssl);
|
||||
DEBUGASSERT(ctx->ssl_ctx);
|
||||
ctx->ssl = wolfSSL_new(ctx->ssl_ctx);
|
||||
|
||||
wolfSSL_set_app_data(ctx->ssl, user_data);
|
||||
wolfSSL_set_connect_state(ctx->ssl);
|
||||
wolfSSL_set_quic_use_legacy_codepoint(ctx->ssl, 0);
|
||||
|
||||
if(alpn)
|
||||
wolfSSL_set_alpn_protos(ctx->ssl, (const unsigned char *)alpn,
|
||||
(int)alpn_len);
|
||||
|
||||
if(peer->sni) {
|
||||
wolfSSL_UseSNI(ctx->ssl, WOLFSSL_SNI_HOST_NAME,
|
||||
peer->sni, (unsigned short)strlen(peer->sni));
|
||||
}
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
#endif /* defined(USE_WOLFSSL) */
|
||||
|
||||
CURLcode Curl_vquic_tls_init(struct curl_tls_ctx *ctx,
|
||||
struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct ssl_peer *peer,
|
||||
const char *alpn, size_t alpn_len,
|
||||
Curl_vquic_tls_ctx_setup *cb_setup,
|
||||
void *cb_user_data, void *ssl_user_data)
|
||||
{
|
||||
CURLcode result;
|
||||
|
||||
#ifdef USE_OPENSSL
|
||||
(void)result;
|
||||
return Curl_ossl_ctx_init(&ctx->ossl, cf, data, peer, TRNSPRT_QUIC,
|
||||
(const unsigned char *)alpn, alpn_len,
|
||||
cb_setup, cb_user_data, NULL, ssl_user_data);
|
||||
#elif defined(USE_GNUTLS)
|
||||
(void)result;
|
||||
return Curl_gtls_ctx_init(&ctx->gtls, cf, data, peer,
|
||||
(const unsigned char *)alpn, alpn_len,
|
||||
cb_setup, cb_user_data, ssl_user_data);
|
||||
#elif defined(USE_WOLFSSL)
|
||||
result = curl_wssl_init_ctx(ctx, cf, data, cb_setup, cb_user_data);
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
return curl_wssl_init_ssl(ctx, data, peer, alpn, alpn_len, ssl_user_data);
|
||||
#else
|
||||
#error "no TLS lib in used, should not happen"
|
||||
return CURLE_FAILED_INIT;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Curl_vquic_tls_cleanup(struct curl_tls_ctx *ctx)
|
||||
{
|
||||
#ifdef USE_OPENSSL
|
||||
if(ctx->ossl.ssl)
|
||||
SSL_free(ctx->ossl.ssl);
|
||||
if(ctx->ossl.ssl_ctx)
|
||||
SSL_CTX_free(ctx->ossl.ssl_ctx);
|
||||
#elif defined(USE_GNUTLS)
|
||||
if(ctx->gtls.cred)
|
||||
gnutls_certificate_free_credentials(ctx->gtls.cred);
|
||||
if(ctx->gtls.session)
|
||||
gnutls_deinit(ctx->gtls.session);
|
||||
#elif defined(USE_WOLFSSL)
|
||||
if(ctx->ssl)
|
||||
wolfSSL_free(ctx->ssl);
|
||||
if(ctx->ssl_ctx)
|
||||
wolfSSL_CTX_free(ctx->ssl_ctx);
|
||||
#endif
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
}
|
||||
|
||||
CURLcode Curl_vquic_tls_before_recv(struct curl_tls_ctx *ctx,
|
||||
struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data)
|
||||
{
|
||||
#ifdef USE_OPENSSL
|
||||
if(!ctx->ossl.x509_store_setup) {
|
||||
CURLcode result = Curl_ssl_setup_x509_store(cf, data, ctx->ossl.ssl_ctx);
|
||||
if(result)
|
||||
return result;
|
||||
ctx->ossl.x509_store_setup = TRUE;
|
||||
}
|
||||
#elif defined(USE_GNUTLS)
|
||||
if(!ctx->gtls.trust_setup) {
|
||||
CURLcode result = Curl_gtls_client_trust_setup(cf, data, &ctx->gtls);
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
(void)ctx; (void)cf; (void)data;
|
||||
#endif
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
CURLcode Curl_vquic_tls_verify_peer(struct curl_tls_ctx *ctx,
|
||||
struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct ssl_peer *peer)
|
||||
{
|
||||
struct ssl_primary_config *conn_config;
|
||||
CURLcode result = CURLE_OK;
|
||||
|
||||
conn_config = Curl_ssl_cf_get_primary_config(cf);
|
||||
if(!conn_config)
|
||||
return CURLE_FAILED_INIT;
|
||||
|
||||
#ifdef USE_OPENSSL
|
||||
(void)conn_config;
|
||||
result = Curl_oss_check_peer_cert(cf, data, &ctx->ossl, peer);
|
||||
#elif defined(USE_GNUTLS)
|
||||
if(conn_config->verifyhost) {
|
||||
result = Curl_gtls_verifyserver(data, ctx->gtls.session,
|
||||
conn_config, &data->set.ssl, peer,
|
||||
data->set.str[STRING_SSL_PINNEDPUBLICKEY]);
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
#elif defined(USE_WOLFSSL)
|
||||
(void)data;
|
||||
if(conn_config->verifyhost) {
|
||||
if(peer->sni) {
|
||||
WOLFSSL_X509* cert = wolfSSL_get_peer_certificate(ctx->ssl);
|
||||
if(wolfSSL_X509_check_host(cert, peer->sni, strlen(peer->sni), 0, NULL)
|
||||
== WOLFSSL_FAILURE) {
|
||||
result = CURLE_PEER_FAILED_VERIFICATION;
|
||||
}
|
||||
wolfSSL_X509_free(cert);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#endif /* !USE_HTTP3 && (USE_OPENSSL || USE_GNUTLS || USE_WOLFSSL) */
|
99
third_party/curl/lib/vquic/vquic-tls.h
vendored
Normal file
99
third_party/curl/lib/vquic/vquic-tls.h
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
#ifndef HEADER_CURL_VQUIC_TLS_H
|
||||
#define HEADER_CURL_VQUIC_TLS_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "curl_setup.h"
|
||||
#include "bufq.h"
|
||||
#include "vtls/openssl.h"
|
||||
|
||||
#if defined(USE_HTTP3) && \
|
||||
(defined(USE_OPENSSL) || defined(USE_GNUTLS) || defined(USE_WOLFSSL))
|
||||
|
||||
struct curl_tls_ctx {
|
||||
#ifdef USE_OPENSSL
|
||||
struct ossl_ctx ossl;
|
||||
#elif defined(USE_GNUTLS)
|
||||
struct gtls_ctx gtls;
|
||||
#elif defined(USE_WOLFSSL)
|
||||
WOLFSSL_CTX *ssl_ctx;
|
||||
WOLFSSL *ssl;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback passed to `Curl_vquic_tls_init()` that can
|
||||
* do early initializations on the not otherwise configured TLS
|
||||
* instances created. This varies by TLS backend:
|
||||
* - openssl/wolfssl: SSL_CTX* has just been created
|
||||
* - gnutls: gtls_client_init() has run
|
||||
*/
|
||||
typedef CURLcode Curl_vquic_tls_ctx_setup(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
void *cb_user_data);
|
||||
|
||||
/**
|
||||
* Initialize the QUIC TLS instances based of the SSL configurations
|
||||
* for the connection filter, transfer and peer.
|
||||
* @param ctx the TLS context to initialize
|
||||
* @param cf the connection filter involved
|
||||
* @param data the transfer involved
|
||||
* @param peer the peer that will be connected to
|
||||
* @param alpn the ALPN string in protocol format ((len+bytes+)+),
|
||||
* may be NULL
|
||||
* @param alpn_len the overall number of bytes in `alpn`
|
||||
* @param cb_setup optional callback for very early TLS config
|
||||
± @param cb_user_data user_data param for callback
|
||||
* @param ssl_user_data optional pointer to set in TLS application context
|
||||
*/
|
||||
CURLcode Curl_vquic_tls_init(struct curl_tls_ctx *ctx,
|
||||
struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct ssl_peer *peer,
|
||||
const char *alpn, size_t alpn_len,
|
||||
Curl_vquic_tls_ctx_setup *cb_setup,
|
||||
void *cb_user_data,
|
||||
void *ssl_user_data);
|
||||
|
||||
/**
|
||||
* Cleanup all data that has been initialized.
|
||||
*/
|
||||
void Curl_vquic_tls_cleanup(struct curl_tls_ctx *ctx);
|
||||
|
||||
CURLcode Curl_vquic_tls_before_recv(struct curl_tls_ctx *ctx,
|
||||
struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data);
|
||||
|
||||
/**
|
||||
* After the QUIC basic handshake has been, verify that the peer
|
||||
* (and its certificate) fulfill our requirements.
|
||||
*/
|
||||
CURLcode Curl_vquic_tls_verify_peer(struct curl_tls_ctx *ctx,
|
||||
struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct ssl_peer *peer);
|
||||
|
||||
#endif /* !USE_HTTP3 && (USE_OPENSSL || USE_GNUTLS || USE_WOLFSSL) */
|
||||
|
||||
#endif /* HEADER_CURL_VQUIC_TLS_H */
|
677
third_party/curl/lib/vquic/vquic.c
vendored
Normal file
677
third_party/curl/lib/vquic/vquic.c
vendored
Normal file
@ -0,0 +1,677 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/* WIP, experimental: use recvmmsg() on linux
|
||||
* we have no configure check, yet
|
||||
* and also it is only available for _GNU_SOURCE, which
|
||||
* we do not use otherwise.
|
||||
#define HAVE_SENDMMSG
|
||||
*/
|
||||
#if defined(HAVE_SENDMMSG)
|
||||
#define _GNU_SOURCE
|
||||
#include <sys/socket.h>
|
||||
#undef _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#include "urldata.h"
|
||||
#include "bufq.h"
|
||||
#include "dynbuf.h"
|
||||
#include "cfilters.h"
|
||||
#include "curl_trc.h"
|
||||
#include "curl_msh3.h"
|
||||
#include "curl_ngtcp2.h"
|
||||
#include "curl_osslq.h"
|
||||
#include "curl_quiche.h"
|
||||
#include "rand.h"
|
||||
#include "vquic.h"
|
||||
#include "vquic_int.h"
|
||||
#include "strerror.h"
|
||||
|
||||
/* The last 3 #include files should be in this order */
|
||||
#include "curl_printf.h"
|
||||
#include "curl_memory.h"
|
||||
#include "memdebug.h"
|
||||
|
||||
|
||||
#ifdef USE_HTTP3
|
||||
|
||||
#ifdef O_BINARY
|
||||
#define QLOGMODE O_WRONLY|O_CREAT|O_BINARY
|
||||
#else
|
||||
#define QLOGMODE O_WRONLY|O_CREAT
|
||||
#endif
|
||||
|
||||
#define NW_CHUNK_SIZE (64 * 1024)
|
||||
#define NW_SEND_CHUNKS 2
|
||||
|
||||
|
||||
void Curl_quic_ver(char *p, size_t len)
|
||||
{
|
||||
#if defined(USE_NGTCP2) && defined(USE_NGHTTP3)
|
||||
Curl_ngtcp2_ver(p, len);
|
||||
#elif defined(USE_OPENSSL_QUIC) && defined(USE_NGHTTP3)
|
||||
Curl_osslq_ver(p, len);
|
||||
#elif defined(USE_QUICHE)
|
||||
Curl_quiche_ver(p, len);
|
||||
#elif defined(USE_MSH3)
|
||||
Curl_msh3_ver(p, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
CURLcode vquic_ctx_init(struct cf_quic_ctx *qctx)
|
||||
{
|
||||
Curl_bufq_init2(&qctx->sendbuf, NW_CHUNK_SIZE, NW_SEND_CHUNKS,
|
||||
BUFQ_OPT_SOFT_LIMIT);
|
||||
#if defined(__linux__) && defined(UDP_SEGMENT) && defined(HAVE_SENDMSG)
|
||||
qctx->no_gso = FALSE;
|
||||
#else
|
||||
qctx->no_gso = TRUE;
|
||||
#endif
|
||||
#ifdef DEBUGBUILD
|
||||
{
|
||||
char *p = getenv("CURL_DBG_QUIC_WBLOCK");
|
||||
if(p) {
|
||||
long l = strtol(p, NULL, 10);
|
||||
if(l >= 0 && l <= 100)
|
||||
qctx->wblock_percent = (int)l;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
vquic_ctx_update_time(qctx);
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void vquic_ctx_free(struct cf_quic_ctx *qctx)
|
||||
{
|
||||
Curl_bufq_free(&qctx->sendbuf);
|
||||
}
|
||||
|
||||
void vquic_ctx_update_time(struct cf_quic_ctx *qctx)
|
||||
{
|
||||
qctx->last_op = Curl_now();
|
||||
}
|
||||
|
||||
static CURLcode send_packet_no_gso(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx,
|
||||
const uint8_t *pkt, size_t pktlen,
|
||||
size_t gsolen, size_t *psent);
|
||||
|
||||
static CURLcode do_sendmsg(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx,
|
||||
const uint8_t *pkt, size_t pktlen, size_t gsolen,
|
||||
size_t *psent)
|
||||
{
|
||||
#ifdef HAVE_SENDMSG
|
||||
struct iovec msg_iov;
|
||||
struct msghdr msg = {0};
|
||||
ssize_t sent;
|
||||
#if defined(__linux__) && defined(UDP_SEGMENT)
|
||||
uint8_t msg_ctrl[32];
|
||||
struct cmsghdr *cm;
|
||||
#endif
|
||||
|
||||
*psent = 0;
|
||||
msg_iov.iov_base = (uint8_t *)pkt;
|
||||
msg_iov.iov_len = pktlen;
|
||||
msg.msg_iov = &msg_iov;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
#if defined(__linux__) && defined(UDP_SEGMENT)
|
||||
if(pktlen > gsolen) {
|
||||
/* Only set this, when we need it. macOS, for example,
|
||||
* does not seem to like a msg_control of length 0. */
|
||||
msg.msg_control = msg_ctrl;
|
||||
assert(sizeof(msg_ctrl) >= CMSG_SPACE(sizeof(uint16_t)));
|
||||
msg.msg_controllen = CMSG_SPACE(sizeof(uint16_t));
|
||||
cm = CMSG_FIRSTHDR(&msg);
|
||||
cm->cmsg_level = SOL_UDP;
|
||||
cm->cmsg_type = UDP_SEGMENT;
|
||||
cm->cmsg_len = CMSG_LEN(sizeof(uint16_t));
|
||||
*(uint16_t *)(void *)CMSG_DATA(cm) = gsolen & 0xffff;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
while((sent = sendmsg(qctx->sockfd, &msg, 0)) == -1 && SOCKERRNO == EINTR)
|
||||
;
|
||||
|
||||
if(sent == -1) {
|
||||
switch(SOCKERRNO) {
|
||||
case EAGAIN:
|
||||
#if EAGAIN != EWOULDBLOCK
|
||||
case EWOULDBLOCK:
|
||||
#endif
|
||||
return CURLE_AGAIN;
|
||||
case EMSGSIZE:
|
||||
/* UDP datagram is too large; caused by PMTUD. Just let it be lost. */
|
||||
break;
|
||||
case EIO:
|
||||
if(pktlen > gsolen) {
|
||||
/* GSO failure */
|
||||
failf(data, "sendmsg() returned %zd (errno %d); disable GSO", sent,
|
||||
SOCKERRNO);
|
||||
qctx->no_gso = TRUE;
|
||||
return send_packet_no_gso(cf, data, qctx, pkt, pktlen, gsolen, psent);
|
||||
}
|
||||
FALLTHROUGH();
|
||||
default:
|
||||
failf(data, "sendmsg() returned %zd (errno %d)", sent, SOCKERRNO);
|
||||
return CURLE_SEND_ERROR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
assert(pktlen == (size_t)sent);
|
||||
}
|
||||
#else
|
||||
ssize_t sent;
|
||||
(void)gsolen;
|
||||
|
||||
*psent = 0;
|
||||
|
||||
while((sent = send(qctx->sockfd,
|
||||
(const char *)pkt, (SEND_TYPE_ARG3)pktlen, 0)) == -1 &&
|
||||
SOCKERRNO == EINTR)
|
||||
;
|
||||
|
||||
if(sent == -1) {
|
||||
if(SOCKERRNO == EAGAIN || SOCKERRNO == EWOULDBLOCK) {
|
||||
return CURLE_AGAIN;
|
||||
}
|
||||
else {
|
||||
failf(data, "send() returned %zd (errno %d)", sent, SOCKERRNO);
|
||||
if(SOCKERRNO != EMSGSIZE) {
|
||||
return CURLE_SEND_ERROR;
|
||||
}
|
||||
/* UDP datagram is too large; caused by PMTUD. Just let it be
|
||||
lost. */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
(void)cf;
|
||||
*psent = pktlen;
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static CURLcode send_packet_no_gso(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx,
|
||||
const uint8_t *pkt, size_t pktlen,
|
||||
size_t gsolen, size_t *psent)
|
||||
{
|
||||
const uint8_t *p, *end = pkt + pktlen;
|
||||
size_t sent;
|
||||
|
||||
*psent = 0;
|
||||
|
||||
for(p = pkt; p < end; p += gsolen) {
|
||||
size_t len = CURLMIN(gsolen, (size_t)(end - p));
|
||||
CURLcode curlcode = do_sendmsg(cf, data, qctx, p, len, len, &sent);
|
||||
if(curlcode != CURLE_OK) {
|
||||
return curlcode;
|
||||
}
|
||||
*psent += sent;
|
||||
}
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static CURLcode vquic_send_packets(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx,
|
||||
const uint8_t *pkt, size_t pktlen,
|
||||
size_t gsolen, size_t *psent)
|
||||
{
|
||||
CURLcode result;
|
||||
#ifdef DEBUGBUILD
|
||||
/* simulate network blocking/partial writes */
|
||||
if(qctx->wblock_percent > 0) {
|
||||
unsigned char c;
|
||||
Curl_rand(data, &c, 1);
|
||||
if(c >= ((100-qctx->wblock_percent)*256/100)) {
|
||||
CURL_TRC_CF(data, cf, "vquic_flush() simulate EWOULDBLOCK");
|
||||
return CURLE_AGAIN;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if(qctx->no_gso && pktlen > gsolen) {
|
||||
result = send_packet_no_gso(cf, data, qctx, pkt, pktlen, gsolen, psent);
|
||||
}
|
||||
else {
|
||||
result = do_sendmsg(cf, data, qctx, pkt, pktlen, gsolen, psent);
|
||||
}
|
||||
if(!result)
|
||||
qctx->last_io = qctx->last_op;
|
||||
return result;
|
||||
}
|
||||
|
||||
CURLcode vquic_flush(struct Curl_cfilter *cf, struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx)
|
||||
{
|
||||
const unsigned char *buf;
|
||||
size_t blen, sent;
|
||||
CURLcode result;
|
||||
size_t gsolen;
|
||||
|
||||
while(Curl_bufq_peek(&qctx->sendbuf, &buf, &blen)) {
|
||||
gsolen = qctx->gsolen;
|
||||
if(qctx->split_len) {
|
||||
gsolen = qctx->split_gsolen;
|
||||
if(blen > qctx->split_len)
|
||||
blen = qctx->split_len;
|
||||
}
|
||||
|
||||
result = vquic_send_packets(cf, data, qctx, buf, blen, gsolen, &sent);
|
||||
CURL_TRC_CF(data, cf, "vquic_send(len=%zu, gso=%zu) -> %d, sent=%zu",
|
||||
blen, gsolen, result, sent);
|
||||
if(result) {
|
||||
if(result == CURLE_AGAIN) {
|
||||
Curl_bufq_skip(&qctx->sendbuf, sent);
|
||||
if(qctx->split_len)
|
||||
qctx->split_len -= sent;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Curl_bufq_skip(&qctx->sendbuf, sent);
|
||||
if(qctx->split_len)
|
||||
qctx->split_len -= sent;
|
||||
}
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
CURLcode vquic_send(struct Curl_cfilter *cf, struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx, size_t gsolen)
|
||||
{
|
||||
qctx->gsolen = gsolen;
|
||||
return vquic_flush(cf, data, qctx);
|
||||
}
|
||||
|
||||
CURLcode vquic_send_tail_split(struct Curl_cfilter *cf, struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx, size_t gsolen,
|
||||
size_t tail_len, size_t tail_gsolen)
|
||||
{
|
||||
DEBUGASSERT(Curl_bufq_len(&qctx->sendbuf) > tail_len);
|
||||
qctx->split_len = Curl_bufq_len(&qctx->sendbuf) - tail_len;
|
||||
qctx->split_gsolen = gsolen;
|
||||
qctx->gsolen = tail_gsolen;
|
||||
CURL_TRC_CF(data, cf, "vquic_send_tail_split: [%zu gso=%zu][%zu gso=%zu]",
|
||||
qctx->split_len, qctx->split_gsolen,
|
||||
tail_len, qctx->gsolen);
|
||||
return vquic_flush(cf, data, qctx);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SENDMMSG
|
||||
static CURLcode recvmmsg_packets(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx,
|
||||
size_t max_pkts,
|
||||
vquic_recv_pkt_cb *recv_cb, void *userp)
|
||||
{
|
||||
#define MMSG_NUM 64
|
||||
struct iovec msg_iov[MMSG_NUM];
|
||||
struct mmsghdr mmsg[MMSG_NUM];
|
||||
uint8_t bufs[MMSG_NUM][2*1024];
|
||||
struct sockaddr_storage remote_addr[MMSG_NUM];
|
||||
size_t total_nread, pkts;
|
||||
int mcount, i, n;
|
||||
char errstr[STRERROR_LEN];
|
||||
CURLcode result = CURLE_OK;
|
||||
|
||||
DEBUGASSERT(max_pkts > 0);
|
||||
pkts = 0;
|
||||
total_nread = 0;
|
||||
while(pkts < max_pkts) {
|
||||
n = (int)CURLMIN(MMSG_NUM, max_pkts);
|
||||
memset(&mmsg, 0, sizeof(mmsg));
|
||||
for(i = 0; i < n; ++i) {
|
||||
msg_iov[i].iov_base = bufs[i];
|
||||
msg_iov[i].iov_len = (int)sizeof(bufs[i]);
|
||||
mmsg[i].msg_hdr.msg_iov = &msg_iov[i];
|
||||
mmsg[i].msg_hdr.msg_iovlen = 1;
|
||||
mmsg[i].msg_hdr.msg_name = &remote_addr[i];
|
||||
mmsg[i].msg_hdr.msg_namelen = sizeof(remote_addr[i]);
|
||||
}
|
||||
|
||||
while((mcount = recvmmsg(qctx->sockfd, mmsg, n, 0, NULL)) == -1 &&
|
||||
SOCKERRNO == EINTR)
|
||||
;
|
||||
if(mcount == -1) {
|
||||
if(SOCKERRNO == EAGAIN || SOCKERRNO == EWOULDBLOCK) {
|
||||
CURL_TRC_CF(data, cf, "ingress, recvmmsg -> EAGAIN");
|
||||
goto out;
|
||||
}
|
||||
if(!cf->connected && SOCKERRNO == ECONNREFUSED) {
|
||||
struct ip_quadruple ip;
|
||||
Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip);
|
||||
failf(data, "QUIC: connection to %s port %u refused",
|
||||
ip.remote_ip, ip.remote_port);
|
||||
result = CURLE_COULDNT_CONNECT;
|
||||
goto out;
|
||||
}
|
||||
Curl_strerror(SOCKERRNO, errstr, sizeof(errstr));
|
||||
failf(data, "QUIC: recvmsg() unexpectedly returned %d (errno=%d; %s)",
|
||||
mcount, SOCKERRNO, errstr);
|
||||
result = CURLE_RECV_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
CURL_TRC_CF(data, cf, "recvmmsg() -> %d packets", mcount);
|
||||
pkts += mcount;
|
||||
for(i = 0; i < mcount; ++i) {
|
||||
total_nread += mmsg[i].msg_len;
|
||||
result = recv_cb(bufs[i], mmsg[i].msg_len,
|
||||
mmsg[i].msg_hdr.msg_name, mmsg[i].msg_hdr.msg_namelen,
|
||||
0, userp);
|
||||
if(result)
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if(total_nread || result)
|
||||
CURL_TRC_CF(data, cf, "recvd %zu packets with %zu bytes -> %d",
|
||||
pkts, total_nread, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#elif defined(HAVE_SENDMSG)
|
||||
static CURLcode recvmsg_packets(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx,
|
||||
size_t max_pkts,
|
||||
vquic_recv_pkt_cb *recv_cb, void *userp)
|
||||
{
|
||||
struct iovec msg_iov;
|
||||
struct msghdr msg;
|
||||
uint8_t buf[64*1024];
|
||||
struct sockaddr_storage remote_addr;
|
||||
size_t total_nread, pkts;
|
||||
ssize_t nread;
|
||||
char errstr[STRERROR_LEN];
|
||||
CURLcode result = CURLE_OK;
|
||||
|
||||
msg_iov.iov_base = buf;
|
||||
msg_iov.iov_len = (int)sizeof(buf);
|
||||
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
msg.msg_iov = &msg_iov;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
DEBUGASSERT(max_pkts > 0);
|
||||
for(pkts = 0, total_nread = 0; pkts < max_pkts;) {
|
||||
msg.msg_name = &remote_addr;
|
||||
msg.msg_namelen = sizeof(remote_addr);
|
||||
while((nread = recvmsg(qctx->sockfd, &msg, 0)) == -1 &&
|
||||
SOCKERRNO == EINTR)
|
||||
;
|
||||
if(nread == -1) {
|
||||
if(SOCKERRNO == EAGAIN || SOCKERRNO == EWOULDBLOCK) {
|
||||
goto out;
|
||||
}
|
||||
if(!cf->connected && SOCKERRNO == ECONNREFUSED) {
|
||||
struct ip_quadruple ip;
|
||||
Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip);
|
||||
failf(data, "QUIC: connection to %s port %u refused",
|
||||
ip.remote_ip, ip.remote_port);
|
||||
result = CURLE_COULDNT_CONNECT;
|
||||
goto out;
|
||||
}
|
||||
Curl_strerror(SOCKERRNO, errstr, sizeof(errstr));
|
||||
failf(data, "QUIC: recvmsg() unexpectedly returned %zd (errno=%d; %s)",
|
||||
nread, SOCKERRNO, errstr);
|
||||
result = CURLE_RECV_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
++pkts;
|
||||
total_nread += (size_t)nread;
|
||||
result = recv_cb(buf, (size_t)nread, msg.msg_name, msg.msg_namelen,
|
||||
0, userp);
|
||||
if(result)
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
if(total_nread || result)
|
||||
CURL_TRC_CF(data, cf, "recvd %zu packets with %zu bytes -> %d",
|
||||
pkts, total_nread, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#else /* HAVE_SENDMMSG || HAVE_SENDMSG */
|
||||
static CURLcode recvfrom_packets(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx,
|
||||
size_t max_pkts,
|
||||
vquic_recv_pkt_cb *recv_cb, void *userp)
|
||||
{
|
||||
uint8_t buf[64*1024];
|
||||
int bufsize = (int)sizeof(buf);
|
||||
struct sockaddr_storage remote_addr;
|
||||
socklen_t remote_addrlen = sizeof(remote_addr);
|
||||
size_t total_nread, pkts;
|
||||
ssize_t nread;
|
||||
char errstr[STRERROR_LEN];
|
||||
CURLcode result = CURLE_OK;
|
||||
|
||||
DEBUGASSERT(max_pkts > 0);
|
||||
for(pkts = 0, total_nread = 0; pkts < max_pkts;) {
|
||||
while((nread = recvfrom(qctx->sockfd, (char *)buf, bufsize, 0,
|
||||
(struct sockaddr *)&remote_addr,
|
||||
&remote_addrlen)) == -1 &&
|
||||
SOCKERRNO == EINTR)
|
||||
;
|
||||
if(nread == -1) {
|
||||
if(SOCKERRNO == EAGAIN || SOCKERRNO == EWOULDBLOCK) {
|
||||
CURL_TRC_CF(data, cf, "ingress, recvfrom -> EAGAIN");
|
||||
goto out;
|
||||
}
|
||||
if(!cf->connected && SOCKERRNO == ECONNREFUSED) {
|
||||
struct ip_quadruple ip;
|
||||
Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip);
|
||||
failf(data, "QUIC: connection to %s port %u refused",
|
||||
ip.remote_ip, ip.remote_port);
|
||||
result = CURLE_COULDNT_CONNECT;
|
||||
goto out;
|
||||
}
|
||||
Curl_strerror(SOCKERRNO, errstr, sizeof(errstr));
|
||||
failf(data, "QUIC: recvfrom() unexpectedly returned %zd (errno=%d; %s)",
|
||||
nread, SOCKERRNO, errstr);
|
||||
result = CURLE_RECV_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
++pkts;
|
||||
total_nread += (size_t)nread;
|
||||
result = recv_cb(buf, (size_t)nread, &remote_addr, remote_addrlen,
|
||||
0, userp);
|
||||
if(result)
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
if(total_nread || result)
|
||||
CURL_TRC_CF(data, cf, "recvd %zu packets with %zu bytes -> %d",
|
||||
pkts, total_nread, result);
|
||||
return result;
|
||||
}
|
||||
#endif /* !HAVE_SENDMMSG && !HAVE_SENDMSG */
|
||||
|
||||
CURLcode vquic_recv_packets(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx,
|
||||
size_t max_pkts,
|
||||
vquic_recv_pkt_cb *recv_cb, void *userp)
|
||||
{
|
||||
CURLcode result;
|
||||
#if defined(HAVE_SENDMMSG)
|
||||
result = recvmmsg_packets(cf, data, qctx, max_pkts, recv_cb, userp);
|
||||
#elif defined(HAVE_SENDMSG)
|
||||
result = recvmsg_packets(cf, data, qctx, max_pkts, recv_cb, userp);
|
||||
#else
|
||||
result = recvfrom_packets(cf, data, qctx, max_pkts, recv_cb, userp);
|
||||
#endif
|
||||
if(!result) {
|
||||
if(!qctx->got_first_byte) {
|
||||
qctx->got_first_byte = TRUE;
|
||||
qctx->first_byte_at = qctx->last_op;
|
||||
}
|
||||
qctx->last_io = qctx->last_op;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the QLOGDIR environment variable is set, open and return a file
|
||||
* descriptor to write the log to.
|
||||
*
|
||||
* This function returns error if something failed outside of failing to
|
||||
* create the file. Open file success is deemed by seeing if the returned fd
|
||||
* is != -1.
|
||||
*/
|
||||
CURLcode Curl_qlogdir(struct Curl_easy *data,
|
||||
unsigned char *scid,
|
||||
size_t scidlen,
|
||||
int *qlogfdp)
|
||||
{
|
||||
const char *qlog_dir = getenv("QLOGDIR");
|
||||
*qlogfdp = -1;
|
||||
if(qlog_dir) {
|
||||
struct dynbuf fname;
|
||||
CURLcode result;
|
||||
unsigned int i;
|
||||
Curl_dyn_init(&fname, DYN_QLOG_NAME);
|
||||
result = Curl_dyn_add(&fname, qlog_dir);
|
||||
if(!result)
|
||||
result = Curl_dyn_add(&fname, "/");
|
||||
for(i = 0; (i < scidlen) && !result; i++) {
|
||||
char hex[3];
|
||||
msnprintf(hex, 3, "%02x", scid[i]);
|
||||
result = Curl_dyn_add(&fname, hex);
|
||||
}
|
||||
if(!result)
|
||||
result = Curl_dyn_add(&fname, ".sqlog");
|
||||
|
||||
if(!result) {
|
||||
int qlogfd = open(Curl_dyn_ptr(&fname), QLOGMODE,
|
||||
data->set.new_file_perms);
|
||||
if(qlogfd != -1)
|
||||
*qlogfdp = qlogfd;
|
||||
}
|
||||
Curl_dyn_free(&fname);
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
CURLcode Curl_cf_quic_create(struct Curl_cfilter **pcf,
|
||||
struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
const struct Curl_addrinfo *ai,
|
||||
int transport)
|
||||
{
|
||||
(void)transport;
|
||||
DEBUGASSERT(transport == TRNSPRT_QUIC);
|
||||
#if defined(USE_NGTCP2) && defined(USE_NGHTTP3)
|
||||
return Curl_cf_ngtcp2_create(pcf, data, conn, ai);
|
||||
#elif defined(USE_OPENSSL_QUIC) && defined(USE_NGHTTP3)
|
||||
return Curl_cf_osslq_create(pcf, data, conn, ai);
|
||||
#elif defined(USE_QUICHE)
|
||||
return Curl_cf_quiche_create(pcf, data, conn, ai);
|
||||
#elif defined(USE_MSH3)
|
||||
return Curl_cf_msh3_create(pcf, data, conn, ai);
|
||||
#else
|
||||
*pcf = NULL;
|
||||
(void)data;
|
||||
(void)conn;
|
||||
(void)ai;
|
||||
return CURLE_NOT_BUILT_IN;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Curl_conn_is_http3(const struct Curl_easy *data,
|
||||
const struct connectdata *conn,
|
||||
int sockindex)
|
||||
{
|
||||
#if defined(USE_NGTCP2) && defined(USE_NGHTTP3)
|
||||
return Curl_conn_is_ngtcp2(data, conn, sockindex);
|
||||
#elif defined(USE_OPENSSL_QUIC) && defined(USE_NGHTTP3)
|
||||
return Curl_conn_is_osslq(data, conn, sockindex);
|
||||
#elif defined(USE_QUICHE)
|
||||
return Curl_conn_is_quiche(data, conn, sockindex);
|
||||
#elif defined(USE_MSH3)
|
||||
return Curl_conn_is_msh3(data, conn, sockindex);
|
||||
#else
|
||||
return ((conn->handler->protocol & PROTO_FAMILY_HTTP) &&
|
||||
(conn->httpversion == 30));
|
||||
#endif
|
||||
}
|
||||
|
||||
CURLcode Curl_conn_may_http3(struct Curl_easy *data,
|
||||
const struct connectdata *conn)
|
||||
{
|
||||
if(conn->transport == TRNSPRT_UNIX) {
|
||||
/* cannot do QUIC over a unix domain socket */
|
||||
return CURLE_QUIC_CONNECT_ERROR;
|
||||
}
|
||||
if(!(conn->handler->flags & PROTOPT_SSL)) {
|
||||
failf(data, "HTTP/3 requested for non-HTTPS URL");
|
||||
return CURLE_URL_MALFORMAT;
|
||||
}
|
||||
#ifndef CURL_DISABLE_PROXY
|
||||
if(conn->bits.socksproxy) {
|
||||
failf(data, "HTTP/3 is not supported over a SOCKS proxy");
|
||||
return CURLE_URL_MALFORMAT;
|
||||
}
|
||||
if(conn->bits.httpproxy && conn->bits.tunnel_proxy) {
|
||||
failf(data, "HTTP/3 is not supported over a HTTP proxy");
|
||||
return CURLE_URL_MALFORMAT;
|
||||
}
|
||||
#endif
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
#else /* USE_HTTP3 */
|
||||
|
||||
CURLcode Curl_conn_may_http3(struct Curl_easy *data,
|
||||
const struct connectdata *conn)
|
||||
{
|
||||
(void)conn;
|
||||
(void)data;
|
||||
DEBUGF(infof(data, "QUIC is not supported in this build"));
|
||||
return CURLE_NOT_BUILT_IN;
|
||||
}
|
||||
|
||||
#endif /* !USE_HTTP3 */
|
64
third_party/curl/lib/vquic/vquic.h
vendored
Normal file
64
third_party/curl/lib/vquic/vquic.h
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
#ifndef HEADER_CURL_VQUIC_QUIC_H
|
||||
#define HEADER_CURL_VQUIC_QUIC_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_HTTP3
|
||||
struct Curl_cfilter;
|
||||
struct Curl_easy;
|
||||
struct connectdata;
|
||||
struct Curl_addrinfo;
|
||||
|
||||
void Curl_quic_ver(char *p, size_t len);
|
||||
|
||||
CURLcode Curl_qlogdir(struct Curl_easy *data,
|
||||
unsigned char *scid,
|
||||
size_t scidlen,
|
||||
int *qlogfdp);
|
||||
|
||||
|
||||
CURLcode Curl_cf_quic_create(struct Curl_cfilter **pcf,
|
||||
struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
const struct Curl_addrinfo *ai,
|
||||
int transport);
|
||||
|
||||
bool Curl_conn_is_http3(const struct Curl_easy *data,
|
||||
const struct connectdata *conn,
|
||||
int sockindex);
|
||||
|
||||
extern struct Curl_cftype Curl_cft_http3;
|
||||
|
||||
#else /* USE_HTTP3 */
|
||||
|
||||
#define Curl_conn_is_http3(a,b,c) FALSE
|
||||
|
||||
#endif /* !USE_HTTP3 */
|
||||
|
||||
CURLcode Curl_conn_may_http3(struct Curl_easy *data,
|
||||
const struct connectdata *conn);
|
||||
|
||||
#endif /* HEADER_CURL_VQUIC_QUIC_H */
|
93
third_party/curl/lib/vquic/vquic_int.h
vendored
Normal file
93
third_party/curl/lib/vquic/vquic_int.h
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
#ifndef HEADER_CURL_VQUIC_QUIC_INT_H
|
||||
#define HEADER_CURL_VQUIC_QUIC_INT_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "curl_setup.h"
|
||||
#include "bufq.h"
|
||||
|
||||
#ifdef USE_HTTP3
|
||||
|
||||
#define MAX_PKT_BURST 10
|
||||
#define MAX_UDP_PAYLOAD_SIZE 1452
|
||||
/* Default QUIC connection timeout we announce from our side */
|
||||
#define CURL_QUIC_MAX_IDLE_MS (120 * 1000)
|
||||
|
||||
struct cf_quic_ctx {
|
||||
curl_socket_t sockfd; /* connected UDP socket */
|
||||
struct sockaddr_storage local_addr; /* address socket is bound to */
|
||||
socklen_t local_addrlen; /* length of local address */
|
||||
|
||||
struct bufq sendbuf; /* buffer for sending one or more packets */
|
||||
struct curltime first_byte_at; /* when first byte was recvd */
|
||||
struct curltime last_op; /* last (attempted) send/recv operation */
|
||||
struct curltime last_io; /* last successful socket IO */
|
||||
size_t gsolen; /* length of individual packets in send buf */
|
||||
size_t split_len; /* if != 0, buffer length after which GSO differs */
|
||||
size_t split_gsolen; /* length of individual packets after split_len */
|
||||
#ifdef DEBUGBUILD
|
||||
int wblock_percent; /* percent of writes doing EAGAIN */
|
||||
#endif
|
||||
BIT(got_first_byte); /* if first byte was received */
|
||||
BIT(no_gso); /* do not use gso on sending */
|
||||
};
|
||||
|
||||
CURLcode vquic_ctx_init(struct cf_quic_ctx *qctx);
|
||||
void vquic_ctx_free(struct cf_quic_ctx *qctx);
|
||||
|
||||
void vquic_ctx_update_time(struct cf_quic_ctx *qctx);
|
||||
|
||||
void vquic_push_blocked_pkt(struct Curl_cfilter *cf,
|
||||
struct cf_quic_ctx *qctx,
|
||||
const uint8_t *pkt, size_t pktlen, size_t gsolen);
|
||||
|
||||
CURLcode vquic_send_blocked_pkts(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx);
|
||||
|
||||
CURLcode vquic_send(struct Curl_cfilter *cf, struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx, size_t gsolen);
|
||||
|
||||
CURLcode vquic_send_tail_split(struct Curl_cfilter *cf, struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx, size_t gsolen,
|
||||
size_t tail_len, size_t tail_gsolen);
|
||||
|
||||
CURLcode vquic_flush(struct Curl_cfilter *cf, struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx);
|
||||
|
||||
|
||||
typedef CURLcode vquic_recv_pkt_cb(const unsigned char *pkt, size_t pktlen,
|
||||
struct sockaddr_storage *remote_addr,
|
||||
socklen_t remote_addrlen, int ecn,
|
||||
void *userp);
|
||||
|
||||
CURLcode vquic_recv_packets(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data,
|
||||
struct cf_quic_ctx *qctx,
|
||||
size_t max_pkts,
|
||||
vquic_recv_pkt_cb *recv_cb, void *userp);
|
||||
|
||||
#endif /* !USE_HTTP3 */
|
||||
|
||||
#endif /* HEADER_CURL_VQUIC_QUIC_INT_H */
|
Reference in New Issue
Block a user