2011-03-01 10:02:47 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2011-03-01 10:02:47 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2011-03-01 10:02:47 +08:00
|
|
|
*
|
|
|
|
* 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
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2011-03-01 10:02:47 +08:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/*
|
2019-06-02 22:55:05 +08:00
|
|
|
* Source file for all wolfSSL specific code for the TLS/SSL layer. No code
|
2013-12-25 18:30:51 +08:00
|
|
|
* but vtls.c should ever call or use these functions.
|
2011-03-01 10:02:47 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-01-07 02:06:49 +08:00
|
|
|
#include "curl_setup.h"
|
2011-07-26 23:23:27 +08:00
|
|
|
|
2019-06-02 22:55:05 +08:00
|
|
|
#ifdef USE_WOLFSSL
|
2011-03-01 10:02:47 +08:00
|
|
|
|
2015-04-18 03:22:48 +08:00
|
|
|
#define WOLFSSL_OPTIONS_IGNORE_SYS
|
2019-06-02 22:55:05 +08:00
|
|
|
#include <wolfssl/version.h>
|
|
|
|
#include <wolfssl/options.h>
|
2015-04-18 03:22:48 +08:00
|
|
|
|
2017-06-03 05:02:54 +08:00
|
|
|
/* To determine what functions are available we rely on one or both of:
|
2019-06-02 22:55:05 +08:00
|
|
|
- the user's options.h generated by wolfSSL
|
2017-06-03 05:02:54 +08:00
|
|
|
- the symbols detected by curl's configure
|
|
|
|
Since they are markedly different from one another, and one or the other may
|
|
|
|
not be available, we do some checking below to bring things in sync. */
|
|
|
|
|
|
|
|
/* HAVE_ALPN is wolfSSL's build time symbol for enabling ALPN in options.h. */
|
|
|
|
#ifndef HAVE_ALPN
|
|
|
|
#ifdef HAVE_WOLFSSL_USEALPN
|
|
|
|
#define HAVE_ALPN
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2011-08-24 20:00:42 +08:00
|
|
|
#include <limits.h>
|
|
|
|
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "urldata.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "inet_pton.h"
|
2013-12-25 18:20:39 +08:00
|
|
|
#include "vtls.h"
|
2022-11-11 18:45:34 +08:00
|
|
|
#include "vtls_int.h"
|
2020-05-04 06:16:40 +08:00
|
|
|
#include "keylog.h"
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "parsedate.h"
|
|
|
|
#include "connect.h" /* for the connect timeout */
|
|
|
|
#include "select.h"
|
2016-10-31 19:51:45 +08:00
|
|
|
#include "strcase.h"
|
2015-04-05 13:48:16 +08:00
|
|
|
#include "x509asn1.h"
|
2015-03-04 06:17:43 +08:00
|
|
|
#include "curl_printf.h"
|
2019-04-30 17:14:38 +08:00
|
|
|
#include "multiif.h"
|
2014-04-23 17:01:30 +08:00
|
|
|
|
2019-06-02 22:55:05 +08:00
|
|
|
#include <wolfssl/openssl/ssl.h>
|
|
|
|
#include <wolfssl/ssl.h>
|
|
|
|
#include <wolfssl/error-ssl.h>
|
|
|
|
#include "wolfssl.h"
|
2016-05-01 23:05:38 +08:00
|
|
|
|
2015-03-25 06:12:03 +08:00
|
|
|
/* The last #include files should be: */
|
|
|
|
#include "curl_memory.h"
|
2014-04-23 17:01:30 +08:00
|
|
|
#include "memdebug.h"
|
2011-03-01 10:02:47 +08:00
|
|
|
|
2017-06-20 17:32:53 +08:00
|
|
|
/* KEEP_PEER_CERT is a product of the presence of build time symbol
|
|
|
|
OPENSSL_EXTRA without NO_CERTS, depending on the version. KEEP_PEER_CERT is
|
|
|
|
in wolfSSL's settings.h, and the latter two are build time symbols in
|
|
|
|
options.h. */
|
|
|
|
#ifndef KEEP_PEER_CERT
|
2019-06-02 22:55:05 +08:00
|
|
|
#if defined(HAVE_WOLFSSL_GET_PEER_CERTIFICATE) || \
|
2017-06-20 17:32:53 +08:00
|
|
|
(defined(OPENSSL_EXTRA) && !defined(NO_CERTS))
|
|
|
|
#define KEEP_PEER_CERT
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2022-11-25 21:06:43 +08:00
|
|
|
#if defined(HAVE_WOLFSSL_FULL_BIO) && HAVE_WOLFSSL_FULL_BIO
|
|
|
|
#define USE_BIO_CHAIN
|
|
|
|
#else
|
|
|
|
#undef USE_BIO_CHAIN
|
|
|
|
#endif
|
|
|
|
|
2023-05-09 18:10:40 +08:00
|
|
|
struct wolfssl_ssl_backend_data {
|
2023-08-28 21:47:29 +08:00
|
|
|
WOLFSSL_CTX *ctx;
|
|
|
|
WOLFSSL *handle;
|
|
|
|
CURLcode io_result; /* result of last BIO cfilter operation */
|
vtls: encapsulate SSL backend-specific data
So far, all of the SSL backends' private data has been declared as
part of the ssl_connect_data struct, in one big #if .. #elif .. #endif
block.
This can only work as long as the SSL backend is a compile-time option,
something we want to change in the next commits.
Therefore, let's encapsulate the exact data needed by each SSL backend
into a private struct, and let's avoid bleeding any SSL backend-specific
information into urldata.h. This is also necessary to allow multiple SSL
backends to be compiled in at the same time, as e.g. OpenSSL's and
CyaSSL's headers cannot be included in the same .c file.
To avoid too many malloc() calls, we simply append the private structs
to the connectdata struct in allocate_conn().
This requires us to take extra care of alignment issues: struct fields
often need to be aligned on certain boundaries e.g. 32-bit values need to
be stored at addresses that divide evenly by 4 (= 32 bit / 8
bit-per-byte).
We do that by assuming that no SSL backend's private data contains any
fields that need to be aligned on boundaries larger than `long long`
(typically 64-bit) would need. Under this assumption, we simply add a
dummy field of type `long long` to the `struct connectdata` struct. This
field will never be accessed but acts as a placeholder for the four
instances of ssl_backend_data instead. the size of each ssl_backend_data
struct is stored in the SSL backend-specific metadata, to allow
allocate_conn() to know how much extra space to allocate, and how to
initialize the ssl[sockindex]->backend and proxy_ssl[sockindex]->backend
pointers.
This would appear to be a little complicated at first, but is really
necessary to encapsulate the private data of each SSL backend correctly.
And we need to encapsulate thusly if we ever want to allow selecting
CyaSSL and OpenSSL at runtime, as their headers cannot be included within
the same .c file (there are just too many conflicting definitions and
declarations for that).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-07-29 04:09:35 +08:00
|
|
|
};
|
|
|
|
|
2020-05-04 06:16:40 +08:00
|
|
|
#ifdef OPENSSL_EXTRA
|
|
|
|
/*
|
|
|
|
* Availability note:
|
|
|
|
* The TLS 1.3 secret callback (wolfSSL_set_tls13_secret_cb) was added in
|
|
|
|
* WolfSSL 4.4.0, but requires the -DHAVE_SECRET_CALLBACK build option. If that
|
|
|
|
* option is not set, then TLS 1.3 will not be logged.
|
|
|
|
* For TLS 1.2 and before, we use wolfSSL_get_keys().
|
|
|
|
* SSL_get_client_random and wolfSSL_get_keys require OPENSSL_EXTRA
|
|
|
|
* (--enable-opensslextra or --enable-all).
|
|
|
|
*/
|
|
|
|
#if defined(HAVE_SECRET_CALLBACK) && defined(WOLFSSL_TLS13)
|
|
|
|
static int
|
|
|
|
wolfssl_tls13_secret_callback(SSL *ssl, int id, const unsigned char *secret,
|
|
|
|
int secretSz, void *ctx)
|
|
|
|
{
|
|
|
|
const char *label;
|
|
|
|
unsigned char client_random[SSL3_RANDOM_SIZE];
|
|
|
|
(void)ctx;
|
|
|
|
|
|
|
|
if(!ssl || !Curl_tls_keylog_enabled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(id) {
|
|
|
|
case CLIENT_EARLY_TRAFFIC_SECRET:
|
|
|
|
label = "CLIENT_EARLY_TRAFFIC_SECRET";
|
|
|
|
break;
|
|
|
|
case CLIENT_HANDSHAKE_TRAFFIC_SECRET:
|
|
|
|
label = "CLIENT_HANDSHAKE_TRAFFIC_SECRET";
|
|
|
|
break;
|
|
|
|
case SERVER_HANDSHAKE_TRAFFIC_SECRET:
|
|
|
|
label = "SERVER_HANDSHAKE_TRAFFIC_SECRET";
|
|
|
|
break;
|
|
|
|
case CLIENT_TRAFFIC_SECRET:
|
|
|
|
label = "CLIENT_TRAFFIC_SECRET_0";
|
|
|
|
break;
|
|
|
|
case SERVER_TRAFFIC_SECRET:
|
|
|
|
label = "SERVER_TRAFFIC_SECRET_0";
|
|
|
|
break;
|
|
|
|
case EARLY_EXPORTER_SECRET:
|
|
|
|
label = "EARLY_EXPORTER_SECRET";
|
|
|
|
break;
|
|
|
|
case EXPORTER_SECRET:
|
|
|
|
label = "EXPORTER_SECRET";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SSL_get_client_random(ssl, client_random, SSL3_RANDOM_SIZE) == 0) {
|
|
|
|
/* Should never happen as wolfSSL_KeepArrays() was called before. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Curl_tls_keylog_write(label, client_random, secret, secretSz);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* defined(HAVE_SECRET_CALLBACK) && defined(WOLFSSL_TLS13) */
|
|
|
|
|
|
|
|
static void
|
|
|
|
wolfssl_log_tls12_secret(SSL *ssl)
|
|
|
|
{
|
|
|
|
unsigned char *ms, *sr, *cr;
|
|
|
|
unsigned int msLen, srLen, crLen, i, x = 0;
|
|
|
|
|
|
|
|
#if LIBWOLFSSL_VERSION_HEX >= 0x0300d000 /* >= 3.13.0 */
|
|
|
|
/* wolfSSL_GetVersion is available since 3.13, we use it instead of
|
|
|
|
* SSL_version since the latter relies on OPENSSL_ALL (--enable-opensslall or
|
|
|
|
* --enable-all). Failing to perform this check could result in an unusable
|
|
|
|
* key log line when TLS 1.3 is actually negotiated. */
|
|
|
|
switch(wolfSSL_GetVersion(ssl)) {
|
|
|
|
case WOLFSSL_SSLV3:
|
|
|
|
case WOLFSSL_TLSV1:
|
|
|
|
case WOLFSSL_TLSV1_1:
|
|
|
|
case WOLFSSL_TLSV1_2:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* TLS 1.3 does not use this mechanism, the "master secret" returned below
|
|
|
|
* is not directly usable. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-08-28 21:47:29 +08:00
|
|
|
if(wolfSSL_get_keys(ssl, &ms, &msLen, &sr, &srLen, &cr, &crLen) !=
|
|
|
|
SSL_SUCCESS) {
|
2020-05-04 06:16:40 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for a missing master secret and skip logging. That can happen if
|
|
|
|
* curl rejects the server certificate and aborts the handshake.
|
|
|
|
*/
|
|
|
|
for(i = 0; i < msLen; i++) {
|
|
|
|
x |= ms[i];
|
|
|
|
}
|
|
|
|
if(x == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Curl_tls_keylog_write("CLIENT_RANDOM", cr, ms, msLen);
|
|
|
|
}
|
|
|
|
#endif /* OPENSSL_EXTRA */
|
|
|
|
|
2011-03-01 10:02:47 +08:00
|
|
|
static int do_file_type(const char *type)
|
|
|
|
{
|
|
|
|
if(!type || !type[0])
|
|
|
|
return SSL_FILETYPE_PEM;
|
2016-10-01 00:54:02 +08:00
|
|
|
if(strcasecompare(type, "PEM"))
|
2011-03-01 10:02:47 +08:00
|
|
|
return SSL_FILETYPE_PEM;
|
2016-10-01 00:54:02 +08:00
|
|
|
if(strcasecompare(type, "DER"))
|
2011-03-01 10:02:47 +08:00
|
|
|
return SSL_FILETYPE_ASN1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-09-16 02:47:35 +08:00
|
|
|
#ifdef HAVE_LIBOQS
|
|
|
|
struct group_name_map {
|
|
|
|
const word16 group;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct group_name_map gnm[] = {
|
|
|
|
{ WOLFSSL_KYBER_LEVEL1, "KYBER_LEVEL1" },
|
|
|
|
{ WOLFSSL_KYBER_LEVEL3, "KYBER_LEVEL3" },
|
|
|
|
{ WOLFSSL_KYBER_LEVEL5, "KYBER_LEVEL5" },
|
|
|
|
{ WOLFSSL_P256_KYBER_LEVEL1, "P256_KYBER_LEVEL1" },
|
|
|
|
{ WOLFSSL_P384_KYBER_LEVEL3, "P384_KYBER_LEVEL3" },
|
|
|
|
{ WOLFSSL_P521_KYBER_LEVEL5, "P521_KYBER_LEVEL5" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2022-11-25 21:06:43 +08:00
|
|
|
#ifdef USE_BIO_CHAIN
|
|
|
|
|
2023-10-04 05:18:01 +08:00
|
|
|
static int wolfssl_bio_cf_create(WOLFSSL_BIO *bio)
|
2022-11-25 21:06:43 +08:00
|
|
|
{
|
|
|
|
wolfSSL_BIO_set_shutdown(bio, 1);
|
|
|
|
wolfSSL_BIO_set_data(bio, NULL);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-10-04 05:18:01 +08:00
|
|
|
static int wolfssl_bio_cf_destroy(WOLFSSL_BIO *bio)
|
2022-11-25 21:06:43 +08:00
|
|
|
{
|
|
|
|
if(!bio)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-10-04 05:18:01 +08:00
|
|
|
static long wolfssl_bio_cf_ctrl(WOLFSSL_BIO *bio, int cmd, long num, void *ptr)
|
2022-11-25 21:06:43 +08:00
|
|
|
{
|
|
|
|
struct Curl_cfilter *cf = BIO_get_data(bio);
|
|
|
|
long ret = 1;
|
|
|
|
|
|
|
|
(void)cf;
|
|
|
|
(void)ptr;
|
|
|
|
switch(cmd) {
|
|
|
|
case BIO_CTRL_GET_CLOSE:
|
|
|
|
ret = (long)wolfSSL_BIO_get_shutdown(bio);
|
|
|
|
break;
|
|
|
|
case BIO_CTRL_SET_CLOSE:
|
|
|
|
wolfSSL_BIO_set_shutdown(bio, (int)num);
|
|
|
|
break;
|
|
|
|
case BIO_CTRL_FLUSH:
|
|
|
|
/* we do no delayed writes, but if we ever would, this
|
|
|
|
* needs to trigger it. */
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
case BIO_CTRL_DUP:
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
#ifdef BIO_CTRL_EOF
|
|
|
|
case BIO_CTRL_EOF:
|
|
|
|
/* EOF has been reached on input? */
|
|
|
|
return (!cf->next || !cf->next->connected);
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-10-04 05:18:01 +08:00
|
|
|
static int wolfssl_bio_cf_out_write(WOLFSSL_BIO *bio,
|
|
|
|
const char *buf, int blen)
|
2022-11-25 21:06:43 +08:00
|
|
|
{
|
|
|
|
struct Curl_cfilter *cf = wolfSSL_BIO_get_data(bio);
|
2023-03-09 18:29:59 +08:00
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
2023-05-09 18:10:40 +08:00
|
|
|
struct wolfssl_ssl_backend_data *backend =
|
|
|
|
(struct wolfssl_ssl_backend_data *)connssl->backend;
|
2023-01-23 18:41:23 +08:00
|
|
|
struct Curl_easy *data = CF_DATA_CURRENT(cf);
|
2022-11-25 21:06:43 +08:00
|
|
|
ssize_t nwritten;
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
|
|
|
|
DEBUGASSERT(data);
|
|
|
|
nwritten = Curl_conn_cf_send(cf->next, data, buf, blen, &result);
|
2023-05-09 18:10:40 +08:00
|
|
|
backend->io_result = result;
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "bio_write(len=%d) -> %zd, %d",
|
|
|
|
blen, nwritten, result);
|
2022-11-25 21:06:43 +08:00
|
|
|
wolfSSL_BIO_clear_retry_flags(bio);
|
2022-12-06 15:47:32 +08:00
|
|
|
if(nwritten < 0 && CURLE_AGAIN == result)
|
2023-08-29 19:08:35 +08:00
|
|
|
BIO_set_retry_write(bio);
|
2022-11-25 21:06:43 +08:00
|
|
|
return (int)nwritten;
|
|
|
|
}
|
|
|
|
|
2023-10-04 05:18:01 +08:00
|
|
|
static int wolfssl_bio_cf_in_read(WOLFSSL_BIO *bio, char *buf, int blen)
|
2022-11-25 21:06:43 +08:00
|
|
|
{
|
|
|
|
struct Curl_cfilter *cf = wolfSSL_BIO_get_data(bio);
|
2023-03-09 18:29:59 +08:00
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
2023-05-09 18:10:40 +08:00
|
|
|
struct wolfssl_ssl_backend_data *backend =
|
|
|
|
(struct wolfssl_ssl_backend_data *)connssl->backend;
|
2023-01-23 18:41:23 +08:00
|
|
|
struct Curl_easy *data = CF_DATA_CURRENT(cf);
|
2022-11-25 21:06:43 +08:00
|
|
|
ssize_t nread;
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
|
|
|
|
DEBUGASSERT(data);
|
|
|
|
/* OpenSSL catches this case, so should we. */
|
|
|
|
if(!buf)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nread = Curl_conn_cf_recv(cf->next, data, buf, blen, &result);
|
2023-05-09 18:10:40 +08:00
|
|
|
backend->io_result = result;
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "bio_read(len=%d) -> %zd, %d", blen, nread, result);
|
2022-11-25 21:06:43 +08:00
|
|
|
wolfSSL_BIO_clear_retry_flags(bio);
|
2022-12-06 15:47:32 +08:00
|
|
|
if(nread < 0 && CURLE_AGAIN == result)
|
|
|
|
BIO_set_retry_read(bio);
|
2024-03-08 16:37:27 +08:00
|
|
|
else if(nread == 0)
|
|
|
|
connssl->peer_closed = TRUE;
|
2022-11-25 21:06:43 +08:00
|
|
|
return (int)nread;
|
|
|
|
}
|
|
|
|
|
2023-10-04 05:18:01 +08:00
|
|
|
static WOLFSSL_BIO_METHOD *wolfssl_bio_cf_method = NULL;
|
2022-11-25 21:06:43 +08:00
|
|
|
|
2023-10-04 05:18:01 +08:00
|
|
|
static void wolfssl_bio_cf_init_methods(void)
|
2022-11-25 21:06:43 +08:00
|
|
|
{
|
2023-10-04 05:18:01 +08:00
|
|
|
wolfssl_bio_cf_method = wolfSSL_BIO_meth_new(BIO_TYPE_MEM, "wolfSSL CF BIO");
|
|
|
|
wolfSSL_BIO_meth_set_write(wolfssl_bio_cf_method, &wolfssl_bio_cf_out_write);
|
|
|
|
wolfSSL_BIO_meth_set_read(wolfssl_bio_cf_method, &wolfssl_bio_cf_in_read);
|
|
|
|
wolfSSL_BIO_meth_set_ctrl(wolfssl_bio_cf_method, &wolfssl_bio_cf_ctrl);
|
|
|
|
wolfSSL_BIO_meth_set_create(wolfssl_bio_cf_method, &wolfssl_bio_cf_create);
|
|
|
|
wolfSSL_BIO_meth_set_destroy(wolfssl_bio_cf_method, &wolfssl_bio_cf_destroy);
|
2022-11-25 21:06:43 +08:00
|
|
|
}
|
|
|
|
|
2023-10-04 05:18:01 +08:00
|
|
|
static void wolfssl_bio_cf_free_methods(void)
|
2022-11-25 21:06:43 +08:00
|
|
|
{
|
2023-10-04 05:18:01 +08:00
|
|
|
wolfSSL_BIO_meth_free(wolfssl_bio_cf_method);
|
2022-11-25 21:06:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* USE_BIO_CHAIN */
|
|
|
|
|
2023-10-04 05:18:01 +08:00
|
|
|
#define wolfssl_bio_cf_init_methods() Curl_nop_stmt
|
|
|
|
#define wolfssl_bio_cf_free_methods() Curl_nop_stmt
|
2022-11-25 21:06:43 +08:00
|
|
|
|
|
|
|
#endif /* !USE_BIO_CHAIN */
|
|
|
|
|
2011-03-01 10:02:47 +08:00
|
|
|
/*
|
|
|
|
* This function loads all the client/CA certificates and CRLs. Setup the TLS
|
|
|
|
* layer and do all necessary magic.
|
|
|
|
*/
|
|
|
|
static CURLcode
|
2022-11-22 16:55:41 +08:00
|
|
|
wolfssl_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
2021-09-16 02:47:35 +08:00
|
|
|
char *ciphers, *curves;
|
2022-11-22 16:55:41 +08:00
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
2023-05-09 18:10:40 +08:00
|
|
|
struct wolfssl_ssl_backend_data *backend =
|
|
|
|
(struct wolfssl_ssl_backend_data *)connssl->backend;
|
2022-11-22 16:55:41 +08:00
|
|
|
struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf);
|
2023-07-17 03:09:36 +08:00
|
|
|
const struct curl_blob *ca_info_blob = conn_config->ca_info_blob;
|
2022-11-22 16:55:41 +08:00
|
|
|
const struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data);
|
2023-09-19 20:30:29 +08:00
|
|
|
const char * const ssl_cafile =
|
|
|
|
/* CURLOPT_CAINFO_BLOB overrides CURLOPT_CAINFO */
|
|
|
|
(ca_info_blob ? NULL : conn_config->CAfile);
|
2023-09-19 20:26:20 +08:00
|
|
|
const char * const ssl_capath = conn_config->CApath;
|
2023-08-28 21:47:29 +08:00
|
|
|
WOLFSSL_METHOD* req_method = NULL;
|
2021-09-16 02:47:35 +08:00
|
|
|
#ifdef HAVE_LIBOQS
|
|
|
|
word16 oqsAlg = 0;
|
|
|
|
size_t idx = 0;
|
|
|
|
#endif
|
2015-04-13 13:07:28 +08:00
|
|
|
#ifdef HAVE_SNI
|
|
|
|
bool sni = FALSE;
|
|
|
|
#define use_sni(x) sni = (x)
|
|
|
|
#else
|
|
|
|
#define use_sni(x) Curl_nop_stmt
|
|
|
|
#endif
|
2023-07-17 21:46:34 +08:00
|
|
|
bool imported_native_ca = false;
|
2023-07-17 03:09:36 +08:00
|
|
|
bool imported_ca_info_blob = false;
|
2011-03-01 10:02:47 +08:00
|
|
|
|
2022-02-18 00:48:48 +08:00
|
|
|
DEBUGASSERT(backend);
|
|
|
|
|
2017-06-21 18:41:18 +08:00
|
|
|
if(connssl->state == ssl_connection_complete)
|
2011-03-01 10:02:47 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
if(conn_config->version_max != CURL_SSLVERSION_MAX_NONE) {
|
2019-06-02 22:55:05 +08:00
|
|
|
failf(data, "wolfSSL does not support to set maximum SSL/TLS version");
|
2016-12-14 04:10:00 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-03-01 10:02:47 +08:00
|
|
|
/* check to see if we've been told to use an explicit SSL/TLS version */
|
2022-11-22 16:55:41 +08:00
|
|
|
switch(conn_config->version) {
|
2011-03-01 10:02:47 +08:00
|
|
|
case CURL_SSLVERSION_DEFAULT:
|
|
|
|
case CURL_SSLVERSION_TLSv1:
|
2019-06-02 22:55:05 +08:00
|
|
|
#if LIBWOLFSSL_VERSION_HEX >= 0x03003000 /* >= 3.3.0 */
|
2015-04-03 14:11:35 +08:00
|
|
|
/* minimum protocol version is set later after the CTX object is created */
|
2015-03-25 14:40:00 +08:00
|
|
|
req_method = SSLv23_client_method();
|
|
|
|
#else
|
2019-06-02 22:55:05 +08:00
|
|
|
infof(data, "wolfSSL <3.3.0 cannot be configured to use TLS 1.0-1.2, "
|
2021-07-06 23:05:17 +08:00
|
|
|
"TLS 1.0 is used exclusively");
|
2011-03-01 10:02:47 +08:00
|
|
|
req_method = TLSv1_client_method();
|
2015-03-25 14:40:00 +08:00
|
|
|
#endif
|
2015-04-13 13:07:28 +08:00
|
|
|
use_sni(TRUE);
|
2011-03-01 10:02:47 +08:00
|
|
|
break;
|
2013-09-19 21:17:13 +08:00
|
|
|
case CURL_SSLVERSION_TLSv1_0:
|
2020-12-30 04:46:42 +08:00
|
|
|
#if defined(WOLFSSL_ALLOW_TLSV10) && !defined(NO_OLD_TLS)
|
2013-09-19 21:17:13 +08:00
|
|
|
req_method = TLSv1_client_method();
|
2015-04-13 13:07:28 +08:00
|
|
|
use_sni(TRUE);
|
2024-03-22 20:07:25 +08:00
|
|
|
break;
|
2018-04-25 17:45:35 +08:00
|
|
|
#else
|
2019-06-02 22:55:05 +08:00
|
|
|
failf(data, "wolfSSL does not support TLS 1.0");
|
2018-04-25 17:45:35 +08:00
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
#endif
|
2013-09-19 21:17:13 +08:00
|
|
|
case CURL_SSLVERSION_TLSv1_1:
|
2020-12-30 04:46:42 +08:00
|
|
|
#ifndef NO_OLD_TLS
|
2013-09-19 21:17:13 +08:00
|
|
|
req_method = TLSv1_1_client_method();
|
2015-04-13 13:07:28 +08:00
|
|
|
use_sni(TRUE);
|
2020-12-30 04:46:42 +08:00
|
|
|
#else
|
|
|
|
failf(data, "wolfSSL does not support TLS 1.1");
|
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
#endif
|
2013-09-19 21:17:13 +08:00
|
|
|
break;
|
|
|
|
case CURL_SSLVERSION_TLSv1_2:
|
2023-07-16 18:20:23 +08:00
|
|
|
#ifndef WOLFSSL_NO_TLS12
|
2013-09-19 21:17:13 +08:00
|
|
|
req_method = TLSv1_2_client_method();
|
2015-04-13 13:07:28 +08:00
|
|
|
use_sni(TRUE);
|
2023-07-16 18:20:23 +08:00
|
|
|
#else
|
|
|
|
failf(data, "wolfSSL does not support TLS 1.2");
|
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
#endif
|
2013-09-19 21:17:13 +08:00
|
|
|
break;
|
2016-11-08 10:51:27 +08:00
|
|
|
case CURL_SSLVERSION_TLSv1_3:
|
2018-03-02 02:10:36 +08:00
|
|
|
#ifdef WOLFSSL_TLS13
|
|
|
|
req_method = wolfTLSv1_3_client_method();
|
|
|
|
use_sni(TRUE);
|
|
|
|
break;
|
|
|
|
#else
|
2019-06-02 22:55:05 +08:00
|
|
|
failf(data, "wolfSSL: TLS 1.3 is not yet supported");
|
2016-11-08 10:51:27 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
2018-03-02 02:10:36 +08:00
|
|
|
#endif
|
2015-03-25 14:40:00 +08:00
|
|
|
default:
|
|
|
|
failf(data, "Unrecognized parameter passed via CURLOPT_SSLVERSION");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!req_method) {
|
2022-04-16 17:55:05 +08:00
|
|
|
failf(data, "SSL: couldn't create a method");
|
2011-03-01 10:02:47 +08:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2020-03-19 06:16:02 +08:00
|
|
|
if(backend->ctx)
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_CTX_free(backend->ctx);
|
|
|
|
backend->ctx = wolfSSL_CTX_new(req_method);
|
2011-03-01 10:02:47 +08:00
|
|
|
|
2020-03-19 06:16:02 +08:00
|
|
|
if(!backend->ctx) {
|
2022-04-16 17:55:05 +08:00
|
|
|
failf(data, "SSL: couldn't create a context");
|
2011-03-01 10:02:47 +08:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
switch(conn_config->version) {
|
2015-04-03 14:11:35 +08:00
|
|
|
case CURL_SSLVERSION_DEFAULT:
|
|
|
|
case CURL_SSLVERSION_TLSv1:
|
2019-06-02 22:55:05 +08:00
|
|
|
#if LIBWOLFSSL_VERSION_HEX > 0x03004006 /* > 3.4.6 */
|
|
|
|
/* Versions 3.3.0 to 3.4.6 we know the minimum protocol version is
|
|
|
|
* whatever minimum version of TLS was built in and at least TLS 1.0. For
|
|
|
|
* later library versions that could change (eg TLS 1.0 built in but
|
|
|
|
* defaults to TLS 1.1) so we have this short circuit evaluation to find
|
|
|
|
* the minimum supported TLS version.
|
2015-04-03 14:11:35 +08:00
|
|
|
*/
|
2020-03-19 06:16:02 +08:00
|
|
|
if((wolfSSL_CTX_SetMinVersion(backend->ctx, WOLFSSL_TLSV1) != 1) &&
|
|
|
|
(wolfSSL_CTX_SetMinVersion(backend->ctx, WOLFSSL_TLSV1_1) != 1) &&
|
|
|
|
(wolfSSL_CTX_SetMinVersion(backend->ctx, WOLFSSL_TLSV1_2) != 1)
|
2018-03-02 02:10:36 +08:00
|
|
|
#ifdef WOLFSSL_TLS13
|
2020-03-19 06:16:02 +08:00
|
|
|
&& (wolfSSL_CTX_SetMinVersion(backend->ctx, WOLFSSL_TLSV1_3) != 1)
|
2018-03-02 02:10:36 +08:00
|
|
|
#endif
|
|
|
|
) {
|
2015-04-03 14:11:35 +08:00
|
|
|
failf(data, "SSL: couldn't set the minimum protocol version");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
#endif
|
2024-03-22 20:07:25 +08:00
|
|
|
FALLTHROUGH();
|
2023-10-28 05:23:33 +08:00
|
|
|
default:
|
2015-04-03 14:11:35 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
ciphers = conn_config->cipher_list;
|
2017-01-07 06:00:45 +08:00
|
|
|
if(ciphers) {
|
2020-03-19 06:16:02 +08:00
|
|
|
if(!SSL_CTX_set_cipher_list(backend->ctx, ciphers)) {
|
2017-01-07 06:00:45 +08:00
|
|
|
failf(data, "failed setting cipher list: %s", ciphers);
|
|
|
|
return CURLE_SSL_CIPHER;
|
|
|
|
}
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "Cipher selection: %s", ciphers);
|
2017-01-07 06:00:45 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
curves = conn_config->curves;
|
2021-09-16 02:47:35 +08:00
|
|
|
if(curves) {
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBOQS
|
|
|
|
for(idx = 0; gnm[idx].name != NULL; idx++) {
|
|
|
|
if(strncmp(curves, gnm[idx].name, strlen(gnm[idx].name)) == 0) {
|
|
|
|
oqsAlg = gnm[idx].group;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(oqsAlg == 0)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if(!SSL_CTX_set1_curves_list(backend->ctx, curves)) {
|
|
|
|
failf(data, "failed setting curves list: '%s'", curves);
|
|
|
|
return CURLE_SSL_CIPHER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-17 03:09:36 +08:00
|
|
|
|
2023-10-13 15:00:50 +08:00
|
|
|
#if !defined(NO_FILESYSTEM) && defined(WOLFSSL_SYS_CA_CERTS)
|
2023-07-17 21:46:34 +08:00
|
|
|
/* load native CA certificates */
|
|
|
|
if(ssl_config->native_ca_store) {
|
|
|
|
if(wolfSSL_CTX_load_system_CA_certs(backend->ctx) != WOLFSSL_SUCCESS) {
|
|
|
|
infof(data, "error importing native CA store, continuing anyway");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
imported_native_ca = true;
|
|
|
|
infof(data, "successfully imported native CA store");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* !NO_FILESYSTEM */
|
|
|
|
|
|
|
|
/* load certificate blob */
|
2023-07-17 03:09:36 +08:00
|
|
|
if(ca_info_blob) {
|
2023-08-28 21:47:29 +08:00
|
|
|
if(wolfSSL_CTX_load_verify_buffer(backend->ctx, ca_info_blob->data,
|
|
|
|
ca_info_blob->len,
|
|
|
|
SSL_FILETYPE_PEM) != SSL_SUCCESS) {
|
2023-07-17 21:46:34 +08:00
|
|
|
if(imported_native_ca) {
|
|
|
|
infof(data, "error importing CA certificate blob, continuing anyway");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
failf(data, "error importing CA certificate blob");
|
|
|
|
return CURLE_SSL_CACERT_BADFILE;
|
|
|
|
}
|
2023-07-17 03:09:36 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
imported_ca_info_blob = true;
|
|
|
|
infof(data, "successfully imported CA certificate blob");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-21 05:40:59 +08:00
|
|
|
#ifndef NO_FILESYSTEM
|
2023-09-19 16:53:44 +08:00
|
|
|
/* load trusted cacert from file if not blob */
|
2023-09-19 20:30:29 +08:00
|
|
|
if(ssl_cafile || ssl_capath) {
|
2023-09-29 18:58:43 +08:00
|
|
|
int rc =
|
|
|
|
wolfSSL_CTX_load_verify_locations_ex(backend->ctx,
|
|
|
|
ssl_cafile,
|
|
|
|
ssl_capath,
|
|
|
|
WOLFSSL_LOAD_FLAG_IGNORE_ERR);
|
|
|
|
if(SSL_SUCCESS != rc) {
|
2023-09-19 20:30:29 +08:00
|
|
|
if(conn_config->verifypeer && !imported_ca_info_blob &&
|
|
|
|
!imported_native_ca) {
|
|
|
|
/* 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");
|
|
|
|
return CURLE_SSL_CACERT_BADFILE;
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
else {
|
2023-09-19 20:30:29 +08:00
|
|
|
/* Just continue with a warning if no strict certificate
|
|
|
|
verification is required. */
|
|
|
|
infof(data, "error setting certificate verify locations,"
|
|
|
|
" continuing anyway:");
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
}
|
2023-09-19 20:30:29 +08:00
|
|
|
else {
|
|
|
|
/* Everything is fine. */
|
|
|
|
infof(data, "successfully set certificate verify locations:");
|
|
|
|
}
|
|
|
|
infof(data, " CAfile: %s", ssl_cafile ? ssl_cafile : "none");
|
|
|
|
infof(data, " CApath: %s", ssl_capath ? ssl_capath : "none");
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the client certificate, and private key */
|
2022-11-22 16:55:41 +08:00
|
|
|
if(ssl_config->primary.clientcert && ssl_config->key) {
|
|
|
|
int file_type = do_file_type(ssl_config->cert_type);
|
2011-03-01 10:02:47 +08:00
|
|
|
|
2024-01-06 04:12:53 +08:00
|
|
|
if(file_type == WOLFSSL_FILETYPE_PEM) {
|
|
|
|
if(wolfSSL_CTX_use_certificate_chain_file(backend->ctx,
|
|
|
|
ssl_config->primary.clientcert)
|
|
|
|
!= 1) {
|
|
|
|
failf(data, "unable to use client certificate");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(file_type == WOLFSSL_FILETYPE_ASN1) {
|
|
|
|
if(wolfSSL_CTX_use_certificate_file(backend->ctx,
|
|
|
|
ssl_config->primary.clientcert,
|
|
|
|
file_type) != 1) {
|
|
|
|
failf(data, "unable to use client certificate");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
failf(data, "unknown cert type");
|
|
|
|
return CURLE_BAD_FUNCTION_ARGUMENT;
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
file_type = do_file_type(ssl_config->key_type);
|
2023-08-28 21:47:29 +08:00
|
|
|
if(wolfSSL_CTX_use_PrivateKey_file(backend->ctx, ssl_config->key,
|
|
|
|
file_type) != 1) {
|
2011-03-01 10:02:47 +08:00
|
|
|
failf(data, "unable to set private key");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2015-03-28 12:16:08 +08:00
|
|
|
#endif /* !NO_FILESYSTEM */
|
2011-03-01 10:02:47 +08:00
|
|
|
|
|
|
|
/* SSL always tries to verify the peer, this only says whether it should
|
|
|
|
* fail to connect if the verification fails, or if it should continue
|
|
|
|
* anyway. In the latter case the result of the verification is checked with
|
|
|
|
* SSL_get_verify_result() below. */
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_CTX_set_verify(backend->ctx,
|
|
|
|
conn_config->verifypeer?SSL_VERIFY_PEER:
|
|
|
|
SSL_VERIFY_NONE, NULL);
|
2011-03-01 10:02:47 +08:00
|
|
|
|
2015-04-13 13:07:28 +08:00
|
|
|
#ifdef HAVE_SNI
|
2023-11-17 22:26:08 +08:00
|
|
|
if(sni && connssl->peer.sni) {
|
|
|
|
size_t sni_len = strlen(connssl->peer.sni);
|
|
|
|
if((sni_len < USHRT_MAX)) {
|
|
|
|
if(wolfSSL_CTX_UseSNI(backend->ctx, WOLFSSL_SNI_HOST_NAME,
|
|
|
|
connssl->peer.sni,
|
|
|
|
(unsigned short)sni_len) != 1) {
|
2022-01-23 06:44:00 +08:00
|
|
|
failf(data, "Failed to set SNI");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
2015-04-13 13:07:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-27 19:22:32 +08:00
|
|
|
/* give application a chance to interfere with SSL set up. */
|
|
|
|
if(data->set.ssl.fsslctx) {
|
2020-03-19 06:16:02 +08:00
|
|
|
CURLcode result = (*data->set.ssl.fsslctx)(data, backend->ctx,
|
2019-05-25 16:06:08 +08:00
|
|
|
data->set.ssl.fsslctxp);
|
2015-03-27 19:22:32 +08:00
|
|
|
if(result) {
|
|
|
|
failf(data, "error signaled by ssl ctx callback");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef NO_FILESYSTEM
|
2022-11-22 16:55:41 +08:00
|
|
|
else if(conn_config->verifypeer) {
|
2019-06-02 22:55:05 +08:00
|
|
|
failf(data, "SSL: Certificates can't be loaded because wolfSSL was built"
|
2015-03-28 12:16:08 +08:00
|
|
|
" with \"no filesystem\". Either disable peer verification"
|
|
|
|
" (insecure) or if you are building an application with libcurl you"
|
|
|
|
" can load certificates via CURLOPT_SSL_CTX_FUNCTION.");
|
2015-03-27 19:22:32 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-03-01 10:02:47 +08:00
|
|
|
/* Let's make an SSL structure */
|
2020-03-19 06:16:02 +08:00
|
|
|
if(backend->handle)
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_free(backend->handle);
|
|
|
|
backend->handle = wolfSSL_new(backend->ctx);
|
2020-03-19 06:16:02 +08:00
|
|
|
if(!backend->handle) {
|
2022-05-19 23:54:30 +08:00
|
|
|
failf(data, "SSL: couldn't create a handle");
|
2011-03-01 10:02:47 +08:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2021-09-16 02:47:35 +08:00
|
|
|
#ifdef HAVE_LIBOQS
|
|
|
|
if(oqsAlg) {
|
|
|
|
if(wolfSSL_UseKeyShare(backend->handle, oqsAlg) != WOLFSSL_SUCCESS) {
|
|
|
|
failf(data, "unable to use oqs KEM");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-03-29 06:18:09 +08:00
|
|
|
#ifdef HAVE_ALPN
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
if(connssl->alpn) {
|
|
|
|
struct alpn_proto_buf proto;
|
|
|
|
CURLcode result;
|
2016-03-29 06:18:09 +08:00
|
|
|
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
result = Curl_alpn_to_proto_str(&proto, connssl->alpn);
|
|
|
|
if(result ||
|
|
|
|
wolfSSL_UseALPN(backend->handle, (char *)proto.data, proto.len,
|
2016-03-29 06:18:09 +08:00
|
|
|
WOLFSSL_ALPN_CONTINUE_ON_MISMATCH) != SSL_SUCCESS) {
|
|
|
|
failf(data, "SSL: failed setting ALPN protocols");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
infof(data, VTLS_INFOF_ALPN_OFFER_1STR, proto.data);
|
2016-03-29 06:18:09 +08:00
|
|
|
}
|
|
|
|
#endif /* HAVE_ALPN */
|
|
|
|
|
2020-05-04 06:16:40 +08:00
|
|
|
#ifdef OPENSSL_EXTRA
|
|
|
|
if(Curl_tls_keylog_enabled()) {
|
|
|
|
/* Ensure the Client Random is preserved. */
|
|
|
|
wolfSSL_KeepArrays(backend->handle);
|
|
|
|
#if defined(HAVE_SECRET_CALLBACK) && defined(WOLFSSL_TLS13)
|
|
|
|
wolfSSL_set_tls13_secret_cb(backend->handle,
|
|
|
|
wolfssl_tls13_secret_callback, NULL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* OPENSSL_EXTRA */
|
|
|
|
|
2020-09-01 03:35:35 +08:00
|
|
|
#ifdef HAVE_SECURE_RENEGOTIATION
|
|
|
|
if(wolfSSL_UseSecureRenegotiation(backend->handle) != SSL_SUCCESS) {
|
|
|
|
failf(data, "SSL: failed setting secure renegotiation");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_SECURE_RENEGOTIATION */
|
|
|
|
|
2011-03-01 10:02:47 +08:00
|
|
|
/* Check if there's a cached ID we can/should use here! */
|
2022-11-22 16:55:41 +08:00
|
|
|
if(ssl_config->primary.sessionid) {
|
2016-06-13 11:47:12 +08:00
|
|
|
void *ssl_sessionid = NULL;
|
|
|
|
|
2021-01-14 00:01:31 +08:00
|
|
|
Curl_ssl_sessionid_lock(data);
|
2024-03-22 20:07:25 +08:00
|
|
|
if(!Curl_ssl_getsessionid(cf, data, &connssl->peer,
|
|
|
|
&ssl_sessionid, NULL)) {
|
2016-06-13 11:47:12 +08:00
|
|
|
/* we got a session id, use it! */
|
2020-03-19 06:16:02 +08:00
|
|
|
if(!SSL_set_session(backend->handle, ssl_sessionid)) {
|
2021-07-05 23:55:24 +08:00
|
|
|
Curl_ssl_delsessionid(data, ssl_sessionid);
|
2021-10-19 23:38:18 +08:00
|
|
|
infof(data, "Can't use session ID, going on without");
|
2016-06-13 11:47:12 +08:00
|
|
|
}
|
2021-07-05 23:55:24 +08:00
|
|
|
else
|
2023-08-23 20:47:45 +08:00
|
|
|
infof(data, "SSL reusing session ID");
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
2021-01-14 00:01:31 +08:00
|
|
|
Curl_ssl_sessionid_unlock(data);
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
|
2022-11-25 21:06:43 +08:00
|
|
|
#ifdef USE_BIO_CHAIN
|
|
|
|
{
|
|
|
|
WOLFSSL_BIO *bio;
|
|
|
|
|
2023-10-04 05:18:01 +08:00
|
|
|
bio = BIO_new(wolfssl_bio_cf_method);
|
2022-11-25 21:06:43 +08:00
|
|
|
if(!bio)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
wolfSSL_BIO_set_data(bio, cf);
|
|
|
|
wolfSSL_set_bio(backend->handle, bio, bio);
|
|
|
|
}
|
|
|
|
#else /* USE_BIO_CHAIN */
|
2011-03-01 10:02:47 +08:00
|
|
|
/* pass the raw socket into the SSL layer */
|
2023-08-28 21:47:29 +08:00
|
|
|
if(!wolfSSL_set_fd(backend->handle,
|
|
|
|
(int)Curl_conn_cf_get_socket(cf, data))) {
|
2011-03-01 10:02:47 +08:00
|
|
|
failf(data, "SSL: SSL_set_fd failed");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
2022-11-25 21:06:43 +08:00
|
|
|
#endif /* !USE_BIO_CHAIN */
|
2011-03-01 10:02:47 +08:00
|
|
|
|
2017-06-21 18:41:18 +08:00
|
|
|
connssl->connecting_state = ssl_connect_2;
|
2011-03-01 10:02:47 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static CURLcode
|
2022-11-22 16:55:41 +08:00
|
|
|
wolfssl_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
|
|
|
int ret = -1;
|
2022-11-22 16:55:41 +08:00
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
2023-05-09 18:10:40 +08:00
|
|
|
struct wolfssl_ssl_backend_data *backend =
|
|
|
|
(struct wolfssl_ssl_backend_data *)connssl->backend;
|
2022-11-22 16:55:41 +08:00
|
|
|
struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf);
|
2024-03-26 07:19:23 +08:00
|
|
|
#ifndef CURL_DISABLE_PROXY
|
2022-11-22 16:55:41 +08:00
|
|
|
const char * const pinnedpubkey = Curl_ssl_cf_is_proxy(cf)?
|
|
|
|
data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY]:
|
|
|
|
data->set.str[STRING_SSL_PINNEDPUBLICKEY];
|
2024-03-26 07:19:23 +08:00
|
|
|
#else
|
|
|
|
const char * const pinnedpubkey = data->set.str[STRING_SSL_PINNEDPUBLICKEY];
|
|
|
|
#endif
|
2011-03-01 10:02:47 +08:00
|
|
|
|
2022-02-18 00:48:48 +08:00
|
|
|
DEBUGASSERT(backend);
|
|
|
|
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_ERR_clear_error();
|
2021-08-20 01:45:55 +08:00
|
|
|
|
2012-11-03 09:06:51 +08:00
|
|
|
/* Enable RFC2818 checks */
|
2022-11-22 16:55:41 +08:00
|
|
|
if(conn_config->verifyhost) {
|
2023-11-17 22:26:08 +08:00
|
|
|
char *snihost = connssl->peer.sni?
|
|
|
|
connssl->peer.sni : connssl->peer.hostname;
|
|
|
|
if(wolfSSL_check_domain_name(backend->handle, snihost) == SSL_FAILURE)
|
2022-01-23 06:44:00 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
2012-11-03 09:06:51 +08:00
|
|
|
}
|
|
|
|
|
2023-08-28 21:47:29 +08:00
|
|
|
ret = wolfSSL_connect(backend->handle);
|
2020-05-04 06:16:40 +08:00
|
|
|
|
|
|
|
#ifdef OPENSSL_EXTRA
|
|
|
|
if(Curl_tls_keylog_enabled()) {
|
|
|
|
/* If key logging is enabled, wait for the handshake to complete and then
|
|
|
|
* proceed with logging secrets (for TLS 1.2 or older).
|
|
|
|
*
|
|
|
|
* During the handshake (ret==-1), wolfSSL_want_read() is true as it waits
|
|
|
|
* for the server response. At that point the master secret is not yet
|
|
|
|
* available, so we must not try to read it.
|
|
|
|
* To log the secret on completion with a handshake failure, detect
|
|
|
|
* completion via the observation that there is nothing to read or write.
|
|
|
|
* Note that OpenSSL SSL_want_read() is always true here. If wolfSSL ever
|
|
|
|
* changes, the worst case is that no key is logged on error.
|
|
|
|
*/
|
|
|
|
if(ret == SSL_SUCCESS ||
|
|
|
|
(!wolfSSL_want_read(backend->handle) &&
|
|
|
|
!wolfSSL_want_write(backend->handle))) {
|
|
|
|
wolfssl_log_tls12_secret(backend->handle);
|
|
|
|
/* Client Random and master secrets are no longer needed, erase these.
|
|
|
|
* Ignored while the handshake is still in progress. */
|
|
|
|
wolfSSL_FreeArrays(backend->handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* OPENSSL_EXTRA */
|
|
|
|
|
2011-04-20 21:17:42 +08:00
|
|
|
if(ret != 1) {
|
2019-06-02 22:55:05 +08:00
|
|
|
char error_buffer[WOLFSSL_MAX_ERROR_SZ];
|
2023-08-28 21:47:29 +08:00
|
|
|
int detail = wolfSSL_get_error(backend->handle, ret);
|
2011-03-01 10:02:47 +08:00
|
|
|
|
2022-12-06 15:47:32 +08:00
|
|
|
if(SSL_ERROR_WANT_READ == detail) {
|
2017-06-21 18:41:18 +08:00
|
|
|
connssl->connecting_state = ssl_connect_2_reading;
|
2011-03-01 10:02:47 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2012-11-03 09:06:51 +08:00
|
|
|
else if(SSL_ERROR_WANT_WRITE == detail) {
|
2017-06-21 18:41:18 +08:00
|
|
|
connssl->connecting_state = ssl_connect_2_writing;
|
2011-03-01 10:02:47 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2012-11-03 09:06:51 +08:00
|
|
|
/* There is no easy way to override only the CN matching.
|
|
|
|
* This will enable the override of both mismatching SubjectAltNames
|
|
|
|
* as also mismatching CN fields */
|
|
|
|
else if(DOMAIN_NAME_MISMATCH == detail) {
|
|
|
|
#if 1
|
2021-07-06 23:05:17 +08:00
|
|
|
failf(data, " subject alt name(s) or common name do not match \"%s\"",
|
2023-11-17 22:26:08 +08:00
|
|
|
connssl->peer.dispname);
|
2012-11-03 09:06:51 +08:00
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
|
|
|
#else
|
2019-06-02 22:55:05 +08:00
|
|
|
/* When the wolfssl_check_domain_name() is used and you desire to
|
2022-11-22 16:55:41 +08:00
|
|
|
* continue on a DOMAIN_NAME_MISMATCH, i.e. 'ssl_config.verifyhost
|
2019-06-02 22:55:05 +08:00
|
|
|
* == 0', CyaSSL version 2.4.0 will fail with an INCOMPLETE_DATA
|
|
|
|
* error. The only way to do this is currently to switch the
|
|
|
|
* Wolfssl_check_domain_name() in and out based on the
|
2022-11-22 16:55:41 +08:00
|
|
|
* 'ssl_config.verifyhost' value. */
|
|
|
|
if(conn_config->verifyhost) {
|
2012-11-03 09:06:51 +08:00
|
|
|
failf(data,
|
2021-07-06 23:05:17 +08:00
|
|
|
" subject alt name(s) or common name do not match \"%s\"\n",
|
2022-11-22 16:55:41 +08:00
|
|
|
connssl->dispname);
|
2012-11-03 09:06:51 +08:00
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
infof(data,
|
2021-07-06 23:05:17 +08:00
|
|
|
" subject alt name(s) and/or common name do not match \"%s\"",
|
2022-11-22 16:55:41 +08:00
|
|
|
connssl->dispname);
|
2012-11-03 09:06:51 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2019-06-02 22:55:05 +08:00
|
|
|
#if LIBWOLFSSL_VERSION_HEX >= 0x02007000 /* 2.7.0 */
|
2014-07-23 06:43:47 +08:00
|
|
|
else if(ASN_NO_SIGNER_E == detail) {
|
2022-11-22 16:55:41 +08:00
|
|
|
if(conn_config->verifypeer) {
|
2021-07-06 23:05:17 +08:00
|
|
|
failf(data, " CA signer not available for verification");
|
2014-07-23 06:43:47 +08:00
|
|
|
return CURLE_SSL_CACERT_BADFILE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Just continue with a warning if no strict certificate
|
|
|
|
verification is required. */
|
|
|
|
infof(data, "CA signer not available for verification, "
|
2021-07-06 23:05:17 +08:00
|
|
|
"continuing anyway");
|
2014-07-23 06:43:47 +08:00
|
|
|
}
|
|
|
|
}
|
2014-07-30 16:07:42 +08:00
|
|
|
#endif
|
2023-03-09 18:29:59 +08:00
|
|
|
else if(backend->io_result == CURLE_AGAIN) {
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2012-11-03 09:06:51 +08:00
|
|
|
else {
|
|
|
|
failf(data, "SSL_connect failed with error %d: %s", detail,
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_ERR_error_string(detail, error_buffer));
|
2012-11-03 09:06:51 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
|
2016-11-25 17:47:25 +08:00
|
|
|
if(pinnedpubkey) {
|
2016-03-29 06:18:09 +08:00
|
|
|
#ifdef KEEP_PEER_CERT
|
2015-04-05 13:48:16 +08:00
|
|
|
X509 *x509;
|
|
|
|
const char *x509_der;
|
|
|
|
int x509_der_len;
|
2020-05-14 06:05:04 +08:00
|
|
|
struct Curl_X509certificate x509_parsed;
|
|
|
|
struct Curl_asn1Element *pubkey;
|
2015-04-05 13:48:16 +08:00
|
|
|
CURLcode result;
|
|
|
|
|
2023-08-28 21:47:29 +08:00
|
|
|
x509 = wolfSSL_get_peer_certificate(backend->handle);
|
2015-04-05 13:48:16 +08:00
|
|
|
if(!x509) {
|
|
|
|
failf(data, "SSL: failed retrieving server certificate");
|
|
|
|
return CURLE_SSL_PINNEDPUBKEYNOTMATCH;
|
|
|
|
}
|
|
|
|
|
2019-06-11 13:45:12 +08:00
|
|
|
x509_der = (const char *)wolfSSL_X509_get_der(x509, &x509_der_len);
|
2015-04-05 13:48:16 +08:00
|
|
|
if(!x509_der) {
|
|
|
|
failf(data, "SSL: failed retrieving ASN.1 server certificate");
|
|
|
|
return CURLE_SSL_PINNEDPUBKEYNOTMATCH;
|
|
|
|
}
|
|
|
|
|
2018-05-12 05:40:58 +08:00
|
|
|
memset(&x509_parsed, 0, sizeof(x509_parsed));
|
2016-11-24 21:28:39 +08:00
|
|
|
if(Curl_parseX509(&x509_parsed, x509_der, x509_der + x509_der_len))
|
|
|
|
return CURLE_SSL_PINNEDPUBKEYNOTMATCH;
|
2015-04-05 13:48:16 +08:00
|
|
|
|
|
|
|
pubkey = &x509_parsed.subjectPublicKeyInfo;
|
|
|
|
if(!pubkey->header || pubkey->end <= pubkey->header) {
|
|
|
|
failf(data, "SSL: failed retrieving public key from server certificate");
|
|
|
|
return CURLE_SSL_PINNEDPUBKEYNOTMATCH;
|
|
|
|
}
|
|
|
|
|
2015-09-13 05:35:12 +08:00
|
|
|
result = Curl_pin_peer_pubkey(data,
|
2016-11-25 17:47:25 +08:00
|
|
|
pinnedpubkey,
|
2015-04-05 13:48:16 +08:00
|
|
|
(const unsigned char *)pubkey->header,
|
|
|
|
(size_t)(pubkey->end - pubkey->header));
|
2024-03-17 22:49:58 +08:00
|
|
|
wolfSSL_FreeX509(x509);
|
2015-04-05 13:48:16 +08:00
|
|
|
if(result) {
|
2022-04-16 17:55:05 +08:00
|
|
|
failf(data, "SSL: public key does not match pinned public key");
|
2015-04-05 13:48:16 +08:00
|
|
|
return result;
|
|
|
|
}
|
2015-12-16 17:25:31 +08:00
|
|
|
#else
|
|
|
|
failf(data, "Library lacks pinning support built-in");
|
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
#endif
|
2015-04-05 13:48:16 +08:00
|
|
|
}
|
|
|
|
|
2016-03-29 06:18:09 +08:00
|
|
|
#ifdef HAVE_ALPN
|
2023-04-06 15:54:57 +08:00
|
|
|
if(connssl->alpn) {
|
2016-03-29 06:18:09 +08:00
|
|
|
int rc;
|
|
|
|
char *protocol = NULL;
|
|
|
|
unsigned short protocol_len = 0;
|
|
|
|
|
2020-03-19 06:16:02 +08:00
|
|
|
rc = wolfSSL_ALPN_GetProtocol(backend->handle, &protocol, &protocol_len);
|
2016-03-29 06:18:09 +08:00
|
|
|
|
|
|
|
if(rc == SSL_SUCCESS) {
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
Curl_alpn_set_negotiated(cf, data, (const unsigned char *)protocol,
|
|
|
|
protocol_len);
|
2016-03-29 06:18:09 +08:00
|
|
|
}
|
|
|
|
else if(rc == SSL_ALPN_NOT_FOUND)
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
Curl_alpn_set_negotiated(cf, data, NULL, 0);
|
2016-03-29 06:18:09 +08:00
|
|
|
else {
|
|
|
|
failf(data, "ALPN, failure getting protocol, error %d", rc);
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_ALPN */
|
|
|
|
|
2017-06-21 18:41:18 +08:00
|
|
|
connssl->connecting_state = ssl_connect_3;
|
2019-06-02 22:55:05 +08:00
|
|
|
#if (LIBWOLFSSL_VERSION_HEX >= 0x03009010)
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "SSL connection using %s / %s",
|
2020-03-19 06:16:02 +08:00
|
|
|
wolfSSL_get_version(backend->handle),
|
|
|
|
wolfSSL_get_cipher_name(backend->handle));
|
2017-01-07 07:09:10 +08:00
|
|
|
#else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "SSL connected");
|
2017-01-07 07:09:10 +08:00
|
|
|
#endif
|
2011-03-01 10:02:47 +08:00
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static CURLcode
|
2022-11-22 16:55:41 +08:00
|
|
|
wolfssl_connect_step3(struct Curl_cfilter *cf, struct Curl_easy *data)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
2014-12-25 19:39:47 +08:00
|
|
|
CURLcode result = CURLE_OK;
|
2022-11-22 16:55:41 +08:00
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
2023-05-09 18:10:40 +08:00
|
|
|
struct wolfssl_ssl_backend_data *backend =
|
|
|
|
(struct wolfssl_ssl_backend_data *)connssl->backend;
|
2022-11-22 16:55:41 +08:00
|
|
|
const struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data);
|
2011-03-01 10:02:47 +08:00
|
|
|
|
|
|
|
DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
|
2022-02-18 00:48:48 +08:00
|
|
|
DEBUGASSERT(backend);
|
2011-03-01 10:02:47 +08:00
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
if(ssl_config->primary.sessionid) {
|
2016-06-13 11:47:12 +08:00
|
|
|
bool incache;
|
2022-09-13 09:14:14 +08:00
|
|
|
bool added = FALSE;
|
2016-06-13 11:47:12 +08:00
|
|
|
void *old_ssl_sessionid = NULL;
|
2023-08-28 21:47:29 +08:00
|
|
|
/* wolfSSL_get1_session allocates memory that has to be freed. */
|
|
|
|
WOLFSSL_SESSION *our_ssl_sessionid = wolfSSL_get1_session(backend->handle);
|
2021-02-17 21:19:57 +08:00
|
|
|
|
|
|
|
if(our_ssl_sessionid) {
|
|
|
|
Curl_ssl_sessionid_lock(data);
|
2024-03-22 20:07:25 +08:00
|
|
|
incache = !(Curl_ssl_getsessionid(cf, data, &connssl->peer,
|
|
|
|
&old_ssl_sessionid, NULL));
|
2021-02-17 21:19:57 +08:00
|
|
|
if(incache) {
|
|
|
|
if(old_ssl_sessionid != our_ssl_sessionid) {
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "old SSL session ID is stale, removing");
|
2021-02-17 21:19:57 +08:00
|
|
|
Curl_ssl_delsessionid(data, old_ssl_sessionid);
|
|
|
|
incache = FALSE;
|
|
|
|
}
|
2016-06-13 11:47:12 +08:00
|
|
|
}
|
2014-12-26 01:15:15 +08:00
|
|
|
|
2021-02-17 21:19:57 +08:00
|
|
|
if(!incache) {
|
2024-03-22 20:07:25 +08:00
|
|
|
result = Curl_ssl_addsessionid(cf, data, &connssl->peer,
|
|
|
|
our_ssl_sessionid, 0, NULL);
|
2021-02-17 21:19:57 +08:00
|
|
|
if(result) {
|
|
|
|
Curl_ssl_sessionid_unlock(data);
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_SESSION_free(our_ssl_sessionid);
|
2021-02-17 21:19:57 +08:00
|
|
|
failf(data, "failed to store ssl session");
|
|
|
|
return result;
|
|
|
|
}
|
2022-09-13 09:14:14 +08:00
|
|
|
else {
|
|
|
|
added = TRUE;
|
|
|
|
}
|
2016-06-13 11:47:12 +08:00
|
|
|
}
|
2021-02-17 21:19:57 +08:00
|
|
|
Curl_ssl_sessionid_unlock(data);
|
2022-09-13 09:14:14 +08:00
|
|
|
|
|
|
|
if(!added) {
|
|
|
|
/* If the session info wasn't added to the cache, free our copy. */
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_SESSION_free(our_ssl_sessionid);
|
2022-09-13 09:14:14 +08:00
|
|
|
}
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
connssl->connecting_state = ssl_connect_done;
|
|
|
|
|
2014-12-25 19:39:47 +08:00
|
|
|
return result;
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
static ssize_t wolfssl_send(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
2021-01-09 00:58:15 +08:00
|
|
|
const void *mem,
|
|
|
|
size_t len,
|
|
|
|
CURLcode *curlcode)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
2022-11-22 16:55:41 +08:00
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
2023-05-09 18:10:40 +08:00
|
|
|
struct wolfssl_ssl_backend_data *backend =
|
|
|
|
(struct wolfssl_ssl_backend_data *)connssl->backend;
|
2019-06-02 22:55:05 +08:00
|
|
|
char error_buffer[WOLFSSL_MAX_ERROR_SZ];
|
2020-03-19 06:16:02 +08:00
|
|
|
int memlen = (len > (size_t)INT_MAX) ? INT_MAX : (int)len;
|
2021-08-20 01:45:55 +08:00
|
|
|
int rc;
|
|
|
|
|
2022-02-18 00:48:48 +08:00
|
|
|
DEBUGASSERT(backend);
|
|
|
|
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_ERR_clear_error();
|
2021-08-20 01:45:55 +08:00
|
|
|
|
2023-08-28 21:47:29 +08:00
|
|
|
rc = wolfSSL_write(backend->handle, mem, memlen);
|
2021-04-26 17:11:59 +08:00
|
|
|
if(rc <= 0) {
|
2023-08-28 21:47:29 +08:00
|
|
|
int err = wolfSSL_get_error(backend->handle, rc);
|
2011-03-01 10:02:47 +08:00
|
|
|
|
|
|
|
switch(err) {
|
|
|
|
case SSL_ERROR_WANT_READ:
|
|
|
|
case SSL_ERROR_WANT_WRITE:
|
|
|
|
/* there's data pending, re-invoke SSL_write() */
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "wolfssl_send(len=%zu) -> AGAIN", len);
|
2011-03-01 10:02:47 +08:00
|
|
|
*curlcode = CURLE_AGAIN;
|
|
|
|
return -1;
|
|
|
|
default:
|
2023-03-09 18:29:59 +08:00
|
|
|
if(backend->io_result == CURLE_AGAIN) {
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "wolfssl_send(len=%zu) -> AGAIN", len);
|
2023-03-09 18:29:59 +08:00
|
|
|
*curlcode = CURLE_AGAIN;
|
|
|
|
return -1;
|
|
|
|
}
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "wolfssl_send(len=%zu) -> %d, %d", len, rc, err);
|
2021-01-09 00:58:15 +08:00
|
|
|
failf(data, "SSL write: %s, errno %d",
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_ERR_error_string(err, error_buffer),
|
2011-03-01 10:02:47 +08:00
|
|
|
SOCKERRNO);
|
|
|
|
*curlcode = CURLE_SEND_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "wolfssl_send(len=%zu) -> %d", len, rc);
|
2011-03-01 10:02:47 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
static void wolfssl_close(struct Curl_cfilter *cf, struct Curl_easy *data)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
2022-11-22 16:55:41 +08:00
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
2023-05-09 18:10:40 +08:00
|
|
|
struct wolfssl_ssl_backend_data *backend =
|
|
|
|
(struct wolfssl_ssl_backend_data *)connssl->backend;
|
2011-03-01 10:02:47 +08:00
|
|
|
|
2021-01-14 00:01:31 +08:00
|
|
|
(void) data;
|
|
|
|
|
2022-02-18 00:48:48 +08:00
|
|
|
DEBUGASSERT(backend);
|
|
|
|
|
2020-03-19 06:16:02 +08:00
|
|
|
if(backend->handle) {
|
2021-05-18 17:34:02 +08:00
|
|
|
char buf[32];
|
|
|
|
/* Maybe the server has already sent a close notify alert.
|
|
|
|
Read it to avoid an RST on the TCP connection. */
|
2023-08-28 21:47:29 +08:00
|
|
|
(void)wolfSSL_read(backend->handle, buf, (int)sizeof(buf));
|
2024-03-08 16:37:27 +08:00
|
|
|
if(!connssl->peer_closed)
|
|
|
|
(void)wolfSSL_shutdown(backend->handle);
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_free(backend->handle);
|
2020-03-19 06:16:02 +08:00
|
|
|
backend->handle = NULL;
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
2020-03-19 06:16:02 +08:00
|
|
|
if(backend->ctx) {
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_CTX_free(backend->ctx);
|
2020-03-19 06:16:02 +08:00
|
|
|
backend->ctx = NULL;
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
static ssize_t wolfssl_recv(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
2023-03-09 18:29:59 +08:00
|
|
|
char *buf, size_t blen,
|
2020-03-19 06:16:02 +08:00
|
|
|
CURLcode *curlcode)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
2022-11-22 16:55:41 +08:00
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
2023-05-09 18:10:40 +08:00
|
|
|
struct wolfssl_ssl_backend_data *backend =
|
|
|
|
(struct wolfssl_ssl_backend_data *)connssl->backend;
|
2019-06-02 22:55:05 +08:00
|
|
|
char error_buffer[WOLFSSL_MAX_ERROR_SZ];
|
2023-03-09 18:29:59 +08:00
|
|
|
int buffsize = (blen > (size_t)INT_MAX) ? INT_MAX : (int)blen;
|
2021-08-20 01:45:55 +08:00
|
|
|
int nread;
|
|
|
|
|
2022-02-18 00:48:48 +08:00
|
|
|
DEBUGASSERT(backend);
|
|
|
|
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_ERR_clear_error();
|
2023-03-09 18:29:59 +08:00
|
|
|
*curlcode = CURLE_OK;
|
2021-08-20 01:45:55 +08:00
|
|
|
|
2023-08-28 21:47:29 +08:00
|
|
|
nread = wolfSSL_read(backend->handle, buf, buffsize);
|
2011-03-01 10:02:47 +08:00
|
|
|
|
2022-02-11 06:50:35 +08:00
|
|
|
if(nread <= 0) {
|
2023-08-28 21:47:29 +08:00
|
|
|
int err = wolfSSL_get_error(backend->handle, nread);
|
2011-03-01 10:02:47 +08:00
|
|
|
|
|
|
|
switch(err) {
|
|
|
|
case SSL_ERROR_ZERO_RETURN: /* no more data */
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "wolfssl_recv(len=%zu) -> CLOSED", blen);
|
2023-03-09 18:29:59 +08:00
|
|
|
*curlcode = CURLE_OK;
|
|
|
|
return 0;
|
2022-02-11 17:41:28 +08:00
|
|
|
case SSL_ERROR_NONE:
|
2011-03-01 10:02:47 +08:00
|
|
|
case SSL_ERROR_WANT_READ:
|
|
|
|
case SSL_ERROR_WANT_WRITE:
|
2023-08-28 21:47:29 +08:00
|
|
|
/* there's data pending, re-invoke wolfSSL_read() */
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "wolfssl_recv(len=%zu) -> AGAIN", blen);
|
2011-03-01 10:02:47 +08:00
|
|
|
*curlcode = CURLE_AGAIN;
|
|
|
|
return -1;
|
|
|
|
default:
|
2023-03-09 18:29:59 +08:00
|
|
|
if(backend->io_result == CURLE_AGAIN) {
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "wolfssl_recv(len=%zu) -> AGAIN", blen);
|
2023-03-09 18:29:59 +08:00
|
|
|
*curlcode = CURLE_AGAIN;
|
|
|
|
return -1;
|
|
|
|
}
|
2021-01-09 00:58:15 +08:00
|
|
|
failf(data, "SSL read: %s, errno %d",
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_ERR_error_string(err, error_buffer), SOCKERRNO);
|
2011-03-01 10:02:47 +08:00
|
|
|
*curlcode = CURLE_RECV_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2023-08-03 23:32:25 +08:00
|
|
|
CURL_TRC_CF(data, cf, "wolfssl_recv(len=%zu) -> %d", blen, nread);
|
2011-03-01 10:02:47 +08:00
|
|
|
return nread;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-13 15:42:36 +08:00
|
|
|
static void wolfssl_session_free(void *ptr)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_SESSION_free(ptr);
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-13 15:42:36 +08:00
|
|
|
static size_t wolfssl_version(char *buffer, size_t size)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
2019-06-02 22:55:05 +08:00
|
|
|
#if LIBWOLFSSL_VERSION_HEX >= 0x03006000
|
2018-11-22 16:01:24 +08:00
|
|
|
return msnprintf(buffer, size, "wolfSSL/%s", wolfSSL_lib_version());
|
2017-02-27 07:49:39 +08:00
|
|
|
#elif defined(WOLFSSL_VERSION)
|
2018-11-22 16:01:24 +08:00
|
|
|
return msnprintf(buffer, size, "wolfSSL/%s", WOLFSSL_VERSION);
|
2011-03-01 10:02:47 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-13 15:42:36 +08:00
|
|
|
static int wolfssl_init(void)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
2022-11-25 21:06:43 +08:00
|
|
|
int ret;
|
|
|
|
|
2020-05-04 06:16:40 +08:00
|
|
|
#ifdef OPENSSL_EXTRA
|
|
|
|
Curl_tls_keylog_open();
|
|
|
|
#endif
|
2022-11-25 21:06:43 +08:00
|
|
|
ret = (wolfSSL_Init() == SSL_SUCCESS);
|
2023-10-04 05:18:01 +08:00
|
|
|
wolfssl_bio_cf_init_methods();
|
2022-11-25 21:06:43 +08:00
|
|
|
return ret;
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-13 15:42:36 +08:00
|
|
|
static void wolfssl_cleanup(void)
|
2018-12-20 00:30:44 +08:00
|
|
|
{
|
2023-10-04 05:18:01 +08:00
|
|
|
wolfssl_bio_cf_free_methods();
|
2019-06-02 22:55:05 +08:00
|
|
|
wolfSSL_Cleanup();
|
2020-05-04 06:16:40 +08:00
|
|
|
#ifdef OPENSSL_EXTRA
|
|
|
|
Curl_tls_keylog_close();
|
|
|
|
#endif
|
2018-12-20 00:30:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
static bool wolfssl_data_pending(struct Curl_cfilter *cf,
|
|
|
|
const struct Curl_easy *data)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
2022-11-22 16:55:41 +08:00
|
|
|
struct ssl_connect_data *ctx = cf->ctx;
|
2023-05-09 18:10:40 +08:00
|
|
|
struct wolfssl_ssl_backend_data *backend;
|
2022-11-22 16:55:41 +08:00
|
|
|
|
|
|
|
(void)data;
|
|
|
|
DEBUGASSERT(ctx && ctx->backend);
|
2023-05-09 18:10:40 +08:00
|
|
|
|
|
|
|
backend = (struct wolfssl_ssl_backend_data *)ctx->backend;
|
|
|
|
if(backend->handle) /* SSL is in use */
|
2023-08-28 21:47:29 +08:00
|
|
|
return (0 != wolfSSL_pending(backend->handle)) ? TRUE : FALSE;
|
2011-03-01 10:02:47 +08:00
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is called to shut down the SSL layer but keep the
|
|
|
|
* socket open (CCC - Clear Command Channel)
|
|
|
|
*/
|
2022-11-22 16:55:41 +08:00
|
|
|
static int wolfssl_shutdown(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
2022-11-22 16:55:41 +08:00
|
|
|
struct ssl_connect_data *ctx = cf->ctx;
|
2023-05-09 18:10:40 +08:00
|
|
|
struct wolfssl_ssl_backend_data *backend;
|
2011-03-01 10:02:47 +08:00
|
|
|
int retval = 0;
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
(void)data;
|
|
|
|
DEBUGASSERT(ctx && ctx->backend);
|
2022-02-18 00:48:48 +08:00
|
|
|
|
2023-05-09 18:10:40 +08:00
|
|
|
backend = (struct wolfssl_ssl_backend_data *)ctx->backend;
|
|
|
|
if(backend->handle) {
|
2023-08-28 21:47:29 +08:00
|
|
|
wolfSSL_ERR_clear_error();
|
|
|
|
wolfSSL_free(backend->handle);
|
2023-05-09 18:10:40 +08:00
|
|
|
backend->handle = NULL;
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static CURLcode
|
2022-11-22 16:55:41 +08:00
|
|
|
wolfssl_connect_common(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
|
|
|
bool nonblocking,
|
|
|
|
bool *done)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
2014-12-25 19:39:47 +08:00
|
|
|
CURLcode result;
|
2022-11-22 16:55:41 +08:00
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
connections: introduce http/3 happy eyeballs
New cfilter HTTP-CONNECT for h3/h2/http1.1 eyeballing.
- filter is installed when `--http3` in the tool is used (or
the equivalent CURLOPT_ done in the library)
- starts a QUIC/HTTP/3 connect right away. Should that not
succeed after 100ms (subject to change), a parallel attempt
is started for HTTP/2 and HTTP/1.1 via TCP
- both attempts are subject to IPv6/IPv4 eyeballing, same
as happens for other connections
- tie timeout to the ip-version HAPPY_EYEBALLS_TIMEOUT
- use a `soft` timeout at half the value. When the soft timeout
expires, the HTTPS-CONNECT filter checks if the QUIC filter
has received any data from the server. If not, it will start
the HTTP/2 attempt.
HTTP/3(ngtcp2) improvements.
- setting call_data in all cfilter calls similar to http/2 and vtls filters
for use in callback where no stream data is available.
- returning CURLE_PARTIAL_FILE for prematurely terminated transfers
- enabling pytest test_05 for h3
- shifting functionality to "connect" UDP sockets from ngtcp2
implementation into the udp socket cfilter. Because unconnected
UDP sockets are weird. For example they error when adding to a
pollset.
HTTP/3(quiche) improvements.
- fixed upload bug in quiche implementation, now passes 251 and pytest
- error codes on stream RESET
- improved debug logs
- handling of DRAIN during connect
- limiting pending event queue
HTTP/2 cfilter improvements.
- use LOG_CF macros for dynamic logging in debug build
- fix CURLcode on RST streams to be CURLE_PARTIAL_FILE
- enable pytest test_05 for h2
- fix upload pytests and improve parallel transfer performance.
GOAWAY handling for ngtcp2/quiche
- during connect, when the remote server refuses to accept new connections
and closes immediately (so the local conn goes into DRAIN phase), the
connection is torn down and a another attempt is made after a short grace
period.
This is the behaviour observed with nghttpx when we tell it to shut
down gracefully. Tested in pytest test_03_02.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
- new tests/tests-httpd/scorecard.py for testing h3/h2 protocol implementation.
Invoke:
python3 tests/tests-httpd/scorecard.py --help
for usage.
Improvements on gathering connect statistics and socket access.
- new CF_CTRL_CONN_REPORT_STATS cfilter control for having cfilters
report connection statistics. This is triggered when the connection
has completely connected.
- new void Curl_pgrsTimeWas(..) method to report a timer update with
a timestamp of when it happend. This allows for updating timers
"later", e.g. a connect statistic after full connectivity has been
reached.
- in case of HTTP eyeballing, the previous changes will update
statistics only from the filter chain that "won" the eyeballing.
- new cfilter query CF_QUERY_SOCKET for retrieving the socket used
by a filter chain.
Added methods Curl_conn_cf_get_socket() and Curl_conn_get_socket()
for convenient use of this query.
- Change VTLS backend to query their sub-filters for the socket when
checks during the handshake are made.
HTTP/3 documentation on how https eyeballing works.
TLS improvements
- ALPN selection for SSL/SSL-PROXY filters in one vtls set of functions, replaces
copy of logic in all tls backends.
- standardized the infof logging of offered ALPNs
- ALPN negotiated: have common function for all backends that sets alpn proprty
and connection related things based on the negotiated protocol (or lack thereof).
Scorecard with Caddy.
- configure can be run with `--with-test-caddy=path` to specify which caddy to use for testing
- tests/tests-httpd/scorecard.py now measures download speeds with caddy
pytest improvements
- adding Makfile to clean gen dir
- adding nghttpx rundir creation on start
- checking httpd version 2.4.55 for test_05 cases where it is needed. Skipping with message if too old.
- catch exception when checking for caddy existance on system.
Closes #10349
2023-02-02 00:13:12 +08:00
|
|
|
curl_socket_t sockfd = Curl_conn_cf_get_socket(cf, data);
|
2011-03-01 10:02:47 +08:00
|
|
|
int what;
|
|
|
|
|
|
|
|
/* check if the connection has already been established */
|
|
|
|
if(ssl_connection_complete == connssl->state) {
|
|
|
|
*done = TRUE;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2017-09-10 05:09:06 +08:00
|
|
|
if(ssl_connect_1 == connssl->connecting_state) {
|
2011-03-01 10:02:47 +08:00
|
|
|
/* Find out how much more time we're allowed */
|
2020-05-29 06:08:03 +08:00
|
|
|
const timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
2011-03-01 10:02:47 +08:00
|
|
|
|
|
|
|
if(timeout_ms < 0) {
|
|
|
|
/* no need to continue if time already is up */
|
|
|
|
failf(data, "SSL connection timeout");
|
|
|
|
return CURLE_OPERATION_TIMEDOUT;
|
|
|
|
}
|
2014-12-25 19:39:47 +08:00
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
result = wolfssl_connect_step1(cf, data);
|
2014-12-25 19:39:47 +08:00
|
|
|
if(result)
|
|
|
|
return result;
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while(ssl_connect_2 == connssl->connecting_state ||
|
|
|
|
ssl_connect_2_reading == connssl->connecting_state ||
|
|
|
|
ssl_connect_2_writing == connssl->connecting_state) {
|
|
|
|
|
|
|
|
/* check allowed time left */
|
2020-05-29 06:08:03 +08:00
|
|
|
const timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
2011-03-01 10:02:47 +08:00
|
|
|
|
|
|
|
if(timeout_ms < 0) {
|
|
|
|
/* no need to continue if time already is up */
|
|
|
|
failf(data, "SSL connection timeout");
|
|
|
|
return CURLE_OPERATION_TIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if ssl is expecting something, check if it's available. */
|
|
|
|
if(connssl->connecting_state == ssl_connect_2_reading
|
|
|
|
|| connssl->connecting_state == ssl_connect_2_writing) {
|
|
|
|
|
2017-09-10 05:09:06 +08:00
|
|
|
curl_socket_t writefd = ssl_connect_2_writing ==
|
2011-03-01 10:02:47 +08:00
|
|
|
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
|
2017-09-10 05:09:06 +08:00
|
|
|
curl_socket_t readfd = ssl_connect_2_reading ==
|
2011-03-01 10:02:47 +08:00
|
|
|
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
|
|
|
|
|
2016-10-18 16:58:58 +08:00
|
|
|
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
|
|
|
|
nonblocking?0:timeout_ms);
|
2011-03-01 10:02:47 +08:00
|
|
|
if(what < 0) {
|
|
|
|
/* fatal error */
|
|
|
|
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
else if(0 == what) {
|
|
|
|
if(nonblocking) {
|
|
|
|
*done = FALSE;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* timeout */
|
|
|
|
failf(data, "SSL connection timeout");
|
|
|
|
return CURLE_OPERATION_TIMEDOUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* socket is readable or writable */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Run transaction, and return to the caller if it failed or if
|
|
|
|
* this connection is part of a multi handle and this loop would
|
|
|
|
* execute again. This permits the owner of a multi handle to
|
|
|
|
* abort a connection attempt before step2 has completed while
|
|
|
|
* ensuring that a client using select() or epoll() will always
|
|
|
|
* have a valid fdset to wait on.
|
|
|
|
*/
|
2022-11-22 16:55:41 +08:00
|
|
|
result = wolfssl_connect_step2(cf, data);
|
2014-12-25 19:39:47 +08:00
|
|
|
if(result || (nonblocking &&
|
|
|
|
(ssl_connect_2 == connssl->connecting_state ||
|
|
|
|
ssl_connect_2_reading == connssl->connecting_state ||
|
|
|
|
ssl_connect_2_writing == connssl->connecting_state)))
|
|
|
|
return result;
|
2011-03-01 10:02:47 +08:00
|
|
|
} /* repeat step2 until all transactions are done. */
|
|
|
|
|
2014-12-25 19:39:47 +08:00
|
|
|
if(ssl_connect_3 == connssl->connecting_state) {
|
2022-11-22 16:55:41 +08:00
|
|
|
result = wolfssl_connect_step3(cf, data);
|
2014-12-25 19:39:47 +08:00
|
|
|
if(result)
|
|
|
|
return result;
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
|
2014-12-25 19:39:47 +08:00
|
|
|
if(ssl_connect_done == connssl->connecting_state) {
|
2011-03-01 10:02:47 +08:00
|
|
|
connssl->state = ssl_connection_complete;
|
|
|
|
*done = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*done = FALSE;
|
|
|
|
|
|
|
|
/* Reset our connect state machine */
|
|
|
|
connssl->connecting_state = ssl_connect_1;
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
static CURLcode wolfssl_connect_nonblocking(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
|
|
|
bool *done)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
2022-11-22 16:55:41 +08:00
|
|
|
return wolfssl_connect_common(cf, data, TRUE, done);
|
2011-03-01 10:02:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
static CURLcode wolfssl_connect(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data)
|
2011-03-01 10:02:47 +08:00
|
|
|
{
|
2014-12-25 19:39:47 +08:00
|
|
|
CURLcode result;
|
2011-03-01 10:02:47 +08:00
|
|
|
bool done = FALSE;
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
result = wolfssl_connect_common(cf, data, FALSE, &done);
|
2014-12-25 19:39:47 +08:00
|
|
|
if(result)
|
|
|
|
return result;
|
2011-03-01 10:02:47 +08:00
|
|
|
|
|
|
|
DEBUGASSERT(done);
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2021-01-13 15:42:36 +08:00
|
|
|
static CURLcode wolfssl_random(struct Curl_easy *data,
|
|
|
|
unsigned char *entropy, size_t length)
|
2014-07-31 06:09:13 +08:00
|
|
|
{
|
2020-01-16 22:59:56 +08:00
|
|
|
WC_RNG rng;
|
2014-07-31 06:09:13 +08:00
|
|
|
(void)data;
|
2019-06-02 22:55:05 +08:00
|
|
|
if(wc_InitRng(&rng))
|
2017-01-13 00:41:26 +08:00
|
|
|
return CURLE_FAILED_INIT;
|
2015-03-25 14:37:20 +08:00
|
|
|
if(length > UINT_MAX)
|
2017-01-13 00:41:26 +08:00
|
|
|
return CURLE_FAILED_INIT;
|
2019-06-02 22:55:05 +08:00
|
|
|
if(wc_RNG_GenerateBlock(&rng, entropy, (unsigned)length))
|
2017-01-13 00:41:26 +08:00
|
|
|
return CURLE_FAILED_INIT;
|
2019-06-02 22:55:05 +08:00
|
|
|
if(wc_FreeRng(&rng))
|
2018-07-21 04:00:09 +08:00
|
|
|
return CURLE_FAILED_INIT;
|
2017-01-13 00:41:26 +08:00
|
|
|
return CURLE_OK;
|
2014-07-31 06:09:13 +08:00
|
|
|
}
|
|
|
|
|
2021-01-13 15:42:36 +08:00
|
|
|
static CURLcode wolfssl_sha256sum(const unsigned char *tmp, /* input */
|
|
|
|
size_t tmplen,
|
|
|
|
unsigned char *sha256sum /* output */,
|
|
|
|
size_t unused)
|
2015-07-01 08:23:54 +08:00
|
|
|
{
|
2020-01-16 22:59:56 +08:00
|
|
|
wc_Sha256 SHA256pw;
|
2015-07-01 08:23:54 +08:00
|
|
|
(void)unused;
|
2023-03-10 17:01:44 +08:00
|
|
|
if(wc_InitSha256(&SHA256pw))
|
|
|
|
return CURLE_FAILED_INIT;
|
2019-06-02 22:55:05 +08:00
|
|
|
wc_Sha256Update(&SHA256pw, tmp, (word32)tmplen);
|
|
|
|
wc_Sha256Final(&SHA256pw, sha256sum);
|
2018-04-03 01:33:00 +08:00
|
|
|
return CURLE_OK;
|
2015-07-01 08:23:54 +08:00
|
|
|
}
|
|
|
|
|
2021-01-13 15:42:36 +08:00
|
|
|
static void *wolfssl_get_internals(struct ssl_connect_data *connssl,
|
2021-07-06 23:05:17 +08:00
|
|
|
CURLINFO info UNUSED_PARAM)
|
2017-06-23 22:05:26 +08:00
|
|
|
{
|
2023-05-09 18:10:40 +08:00
|
|
|
struct wolfssl_ssl_backend_data *backend =
|
|
|
|
(struct wolfssl_ssl_backend_data *)connssl->backend;
|
2017-06-23 22:05:26 +08:00
|
|
|
(void)info;
|
2022-02-18 00:48:48 +08:00
|
|
|
DEBUGASSERT(backend);
|
2020-03-19 06:16:02 +08:00
|
|
|
return backend->handle;
|
2017-06-23 22:05:26 +08:00
|
|
|
}
|
|
|
|
|
2019-06-02 22:55:05 +08:00
|
|
|
const struct Curl_ssl Curl_ssl_wolfssl = {
|
2017-08-30 18:48:53 +08:00
|
|
|
{ CURLSSLBACKEND_WOLFSSL, "WolfSSL" }, /* info */
|
2017-06-22 22:45:34 +08:00
|
|
|
|
2017-06-20 17:32:53 +08:00
|
|
|
#ifdef KEEP_PEER_CERT
|
2018-05-04 18:10:39 +08:00
|
|
|
SSLSUPP_PINNEDPUBKEY |
|
2022-11-25 21:06:43 +08:00
|
|
|
#endif
|
|
|
|
#ifdef USE_BIO_CHAIN
|
|
|
|
SSLSUPP_HTTPS_PROXY |
|
2017-06-20 17:32:53 +08:00
|
|
|
#endif
|
2023-09-29 18:58:43 +08:00
|
|
|
SSLSUPP_CA_PATH |
|
2023-07-17 03:09:36 +08:00
|
|
|
SSLSUPP_CAINFO_BLOB |
|
2018-05-05 05:02:36 +08:00
|
|
|
SSLSUPP_SSL_CTX,
|
2017-06-20 17:32:53 +08:00
|
|
|
|
2023-05-09 18:10:40 +08:00
|
|
|
sizeof(struct wolfssl_ssl_backend_data),
|
vtls: encapsulate SSL backend-specific data
So far, all of the SSL backends' private data has been declared as
part of the ssl_connect_data struct, in one big #if .. #elif .. #endif
block.
This can only work as long as the SSL backend is a compile-time option,
something we want to change in the next commits.
Therefore, let's encapsulate the exact data needed by each SSL backend
into a private struct, and let's avoid bleeding any SSL backend-specific
information into urldata.h. This is also necessary to allow multiple SSL
backends to be compiled in at the same time, as e.g. OpenSSL's and
CyaSSL's headers cannot be included in the same .c file.
To avoid too many malloc() calls, we simply append the private structs
to the connectdata struct in allocate_conn().
This requires us to take extra care of alignment issues: struct fields
often need to be aligned on certain boundaries e.g. 32-bit values need to
be stored at addresses that divide evenly by 4 (= 32 bit / 8
bit-per-byte).
We do that by assuming that no SSL backend's private data contains any
fields that need to be aligned on boundaries larger than `long long`
(typically 64-bit) would need. Under this assumption, we simply add a
dummy field of type `long long` to the `struct connectdata` struct. This
field will never be accessed but acts as a placeholder for the four
instances of ssl_backend_data instead. the size of each ssl_backend_data
struct is stored in the SSL backend-specific metadata, to allow
allocate_conn() to know how much extra space to allocate, and how to
initialize the ssl[sockindex]->backend and proxy_ssl[sockindex]->backend
pointers.
This would appear to be a little complicated at first, but is really
necessary to encapsulate the private data of each SSL backend correctly.
And we need to encapsulate thusly if we ever want to allow selecting
CyaSSL and OpenSSL at runtime, as their headers cannot be included within
the same .c file (there are just too many conflicting definitions and
declarations for that).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-07-29 04:09:35 +08:00
|
|
|
|
2021-01-13 15:42:36 +08:00
|
|
|
wolfssl_init, /* init */
|
|
|
|
wolfssl_cleanup, /* cleanup */
|
|
|
|
wolfssl_version, /* version */
|
2017-06-22 22:45:34 +08:00
|
|
|
Curl_none_check_cxn, /* check_cxn */
|
2021-01-13 15:42:36 +08:00
|
|
|
wolfssl_shutdown, /* shutdown */
|
|
|
|
wolfssl_data_pending, /* data_pending */
|
|
|
|
wolfssl_random, /* random */
|
2017-06-22 22:45:34 +08:00
|
|
|
Curl_none_cert_status_request, /* cert_status_request */
|
2021-01-13 15:42:36 +08:00
|
|
|
wolfssl_connect, /* connect */
|
|
|
|
wolfssl_connect_nonblocking, /* connect_nonblocking */
|
lib: introduce struct easy_poll_set for poll information
Connection filter had a `get_select_socks()` method, inspired by the
various `getsocks` functions involved during the lifetime of a
transfer. These, depending on transfer state (CONNECT/DO/DONE/ etc.),
return sockets to monitor and flag if this shall be done for POLLIN
and/or POLLOUT.
Due to this design, sockets and flags could only be added, not
removed. This led to problems in filters like HTTP/2 where flow control
prohibits the sending of data until the peer increases the flow
window. The general transfer loop wants to write, adds POLLOUT, the
socket is writeable but no data can be written.
This leads to cpu busy loops. To prevent that, HTTP/2 did set the
`SEND_HOLD` flag of such a blocked transfer, so the transfer loop cedes
further attempts. This works if only one such filter is involved. If a
HTTP/2 transfer goes through a HTTP/2 proxy, two filters are
setting/clearing this flag and may step on each other's toes.
Connection filters `get_select_socks()` is replaced by
`adjust_pollset()`. They get passed a `struct easy_pollset` that keeps
up to `MAX_SOCKSPEREASYHANDLE` sockets and their `POLLIN|POLLOUT`
flags. This struct is initialized in `multi_getsock()` by calling the
various `getsocks()` implementations based on transfer state, as before.
After protocol handlers/transfer loop have set the sockets and flags
they want, the `easy_pollset` is *always* passed to the filters. Filters
"higher" in the chain are called first, starting at the first
not-yet-connection one. Each filter may add sockets and/or change
flags. When all flags are removed, the socket itself is removed from the
pollset.
Example:
* transfer wants to send, adds POLLOUT
* http/2 filter has a flow control block, removes POLLOUT and adds
POLLIN (it is waiting on a WINDOW_UPDATE from the server)
* TLS filter is connected and changes nothing
* h2-proxy filter also has a flow control block on its tunnel stream,
removes POLLOUT and adds POLLIN also.
* socket filter is connected and changes nothing
* The resulting pollset is then mixed together with all other transfers
and their pollsets, just as before.
Use of `SEND_HOLD` is no longer necessary in the filters.
All filters are adapted for the changed method. The handling in
`multi.c` has been adjusted, but its state handling the the protocol
handlers' `getsocks` method are untouched.
The most affected filters are http/2, ngtcp2, quiche and h2-proxy. TLS
filters needed to be adjusted for the connecting handshake read/write
handling.
No noticeable difference in performance was detected in local scorecard
runs.
Closes #11833
2023-09-04 18:06:07 +08:00
|
|
|
Curl_ssl_adjust_pollset, /* adjust_pollset */
|
2021-01-13 15:42:36 +08:00
|
|
|
wolfssl_get_internals, /* get_internals */
|
|
|
|
wolfssl_close, /* close_one */
|
2017-06-22 22:45:34 +08:00
|
|
|
Curl_none_close_all, /* close_all */
|
2021-01-13 15:42:36 +08:00
|
|
|
wolfssl_session_free, /* session_free */
|
2017-06-22 22:45:34 +08:00
|
|
|
Curl_none_set_engine, /* set_engine */
|
|
|
|
Curl_none_set_engine_default, /* set_engine_default */
|
|
|
|
Curl_none_engines_list, /* engines_list */
|
2017-06-23 07:04:56 +08:00
|
|
|
Curl_none_false_start, /* false_start */
|
2021-05-05 19:42:26 +08:00
|
|
|
wolfssl_sha256sum, /* sha256sum */
|
|
|
|
NULL, /* associate_connection */
|
2022-09-28 22:51:44 +08:00
|
|
|
NULL, /* disassociate_connection */
|
2022-11-11 18:45:34 +08:00
|
|
|
NULL, /* free_multi_ssl_backend_data */
|
|
|
|
wolfssl_recv, /* recv decrypted data */
|
|
|
|
wolfssl_send, /* send data to encrypt */
|
2017-06-22 22:45:34 +08:00
|
|
|
};
|
|
|
|
|
2011-03-01 10:02:47 +08:00
|
|
|
#endif
|