2005-04-07 23:27:13 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2005-04-07 23:27:13 +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.
|
2005-04-07 23:27:13 +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
|
|
|
*
|
2005-04-07 23:27:13 +08:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Source file for all GnuTLS-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.
|
2005-04-07 23:27:13 +08:00
|
|
|
*
|
|
|
|
* Note: don't use the GnuTLS' *_t variable type names in this source code,
|
|
|
|
* since they were not present in 1.0.X.
|
|
|
|
*/
|
|
|
|
|
2013-01-07 02:06:49 +08:00
|
|
|
#include "curl_setup.h"
|
2011-07-26 23:23:27 +08:00
|
|
|
|
2005-04-07 23:27:13 +08:00
|
|
|
#ifdef USE_GNUTLS
|
2011-07-26 23:23:27 +08:00
|
|
|
|
2014-10-01 14:14:49 +08:00
|
|
|
#include <gnutls/abstract.h>
|
2005-04-07 23:27:13 +08:00
|
|
|
#include <gnutls/gnutls.h>
|
|
|
|
#include <gnutls/x509.h>
|
2012-08-06 21:04:25 +08:00
|
|
|
#include <gnutls/crypto.h>
|
2015-07-01 08:23:54 +08:00
|
|
|
#include <nettle/sha2.h>
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "urldata.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "inet_pton.h"
|
2024-03-22 20:07:25 +08:00
|
|
|
#include "keylog.h"
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "gtls.h"
|
2013-12-25 18:20:39 +08:00
|
|
|
#include "vtls.h"
|
2022-11-11 18:45:34 +08:00
|
|
|
#include "vtls_int.h"
|
2022-09-27 07:01:16 +08:00
|
|
|
#include "vauth/vauth.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"
|
2014-07-16 03:28:10 +08:00
|
|
|
#include "warnless.h"
|
2015-03-21 02:03:53 +08:00
|
|
|
#include "x509asn1.h"
|
2019-04-30 17:14:38 +08:00
|
|
|
#include "multiif.h"
|
2015-03-04 06:17:43 +08:00
|
|
|
#include "curl_printf.h"
|
2009-04-21 19:46:16 +08:00
|
|
|
#include "curl_memory.h"
|
2005-04-07 23:27:13 +08:00
|
|
|
/* The last #include file should be: */
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "memdebug.h"
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2024-03-22 20:07:25 +08:00
|
|
|
#ifndef ARRAYSIZE
|
|
|
|
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define QUIC_PRIORITY \
|
|
|
|
"NORMAL:-VERS-ALL:+VERS-TLS1.3:-CIPHER-ALL:+AES-128-GCM:+AES-256-GCM:" \
|
|
|
|
"+CHACHA20-POLY1305:+AES-128-CCM:-GROUP-ALL:+GROUP-SECP256R1:" \
|
|
|
|
"+GROUP-X25519:+GROUP-SECP384R1:+GROUP-SECP521R1:" \
|
|
|
|
"%DISABLE_TLS13_COMPAT_MODE"
|
|
|
|
|
2005-04-10 05:38:14 +08:00
|
|
|
/* Enable GnuTLS debugging by defining GTLSDEBUG */
|
|
|
|
/*#define GTLSDEBUG */
|
|
|
|
|
|
|
|
#ifdef GTLSDEBUG
|
|
|
|
static void tls_log_func(int level, const char *str)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "|<%d>| %s", level, str);
|
|
|
|
}
|
|
|
|
#endif
|
2007-04-29 05:01:30 +08:00
|
|
|
static bool gtls_inited = FALSE;
|
2010-11-20 12:00:12 +08:00
|
|
|
|
2020-04-21 04:23:48 +08:00
|
|
|
#if !defined(GNUTLS_VERSION_NUMBER) || (GNUTLS_VERSION_NUMBER < 0x03010a)
|
|
|
|
#error "too old GnuTLS version"
|
2014-06-16 19:21:02 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
# include <gnutls/ocsp.h>
|
2011-10-29 20:58:50 +08:00
|
|
|
|
2023-05-09 18:10:40 +08:00
|
|
|
struct gtls_ssl_backend_data {
|
2024-03-22 20:07:25 +08:00
|
|
|
struct gtls_ctx gtls;
|
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
|
|
|
};
|
|
|
|
|
2022-11-25 21:06:43 +08:00
|
|
|
static ssize_t gtls_push(void *s, const void *buf, size_t blen)
|
2006-12-17 05:33:51 +08:00
|
|
|
{
|
2022-11-25 21:06:43 +08:00
|
|
|
struct Curl_cfilter *cf = s;
|
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
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;
|
2006-12-17 05:33:51 +08:00
|
|
|
|
2022-11-25 21:06:43 +08:00
|
|
|
DEBUGASSERT(data);
|
|
|
|
nwritten = Curl_conn_cf_send(cf->next, data, buf, blen, &result);
|
|
|
|
if(nwritten < 0) {
|
2023-05-09 18:10:40 +08:00
|
|
|
struct gtls_ssl_backend_data *backend =
|
|
|
|
(struct gtls_ssl_backend_data *)connssl->backend;
|
|
|
|
gnutls_transport_set_errno(backend->gtls.session,
|
2022-11-25 21:06:43 +08:00
|
|
|
(CURLE_AGAIN == result)? EAGAIN : EINVAL);
|
|
|
|
nwritten = -1;
|
|
|
|
}
|
|
|
|
return nwritten;
|
2006-12-17 05:33:51 +08:00
|
|
|
}
|
2005-04-10 05:38:14 +08:00
|
|
|
|
2022-11-25 21:06:43 +08:00
|
|
|
static ssize_t gtls_pull(void *s, void *buf, size_t blen)
|
2016-11-17 01:49:15 +08:00
|
|
|
{
|
2022-11-25 21:06:43 +08:00
|
|
|
struct Curl_cfilter *cf = s;
|
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
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;
|
2016-11-17 01:49:15 +08:00
|
|
|
|
2022-11-25 21:06:43 +08:00
|
|
|
DEBUGASSERT(data);
|
|
|
|
nread = Curl_conn_cf_recv(cf->next, data, buf, blen, &result);
|
|
|
|
if(nread < 0) {
|
2023-05-09 18:10:40 +08:00
|
|
|
struct gtls_ssl_backend_data *backend =
|
|
|
|
(struct gtls_ssl_backend_data *)connssl->backend;
|
|
|
|
gnutls_transport_set_errno(backend->gtls.session,
|
2022-11-25 21:06:43 +08:00
|
|
|
(CURLE_AGAIN == result)? EAGAIN : EINVAL);
|
|
|
|
nread = -1;
|
|
|
|
}
|
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 nread;
|
2016-11-17 01:49:15 +08:00
|
|
|
}
|
|
|
|
|
2021-01-13 15:28:10 +08:00
|
|
|
/* gtls_init()
|
2009-02-25 20:51:17 +08:00
|
|
|
*
|
|
|
|
* Global GnuTLS init, called from Curl_ssl_init(). This calls functions that
|
|
|
|
* are not thread-safe and thus this function itself is not thread-safe and
|
|
|
|
* must only be called from within curl_global_init() to keep the thread
|
|
|
|
* situation under control!
|
2007-04-29 05:01:30 +08:00
|
|
|
*/
|
2021-01-13 15:28:10 +08:00
|
|
|
static int gtls_init(void)
|
2007-04-29 05:01:30 +08:00
|
|
|
{
|
|
|
|
int ret = 1;
|
2007-11-07 17:21:35 +08:00
|
|
|
if(!gtls_inited) {
|
2007-04-29 05:01:30 +08:00
|
|
|
ret = gnutls_global_init()?0:1;
|
2005-04-10 05:38:14 +08:00
|
|
|
#ifdef GTLSDEBUG
|
2007-04-29 05:01:30 +08:00
|
|
|
gnutls_global_set_log_function(tls_log_func);
|
|
|
|
gnutls_global_set_log_level(2);
|
2005-04-10 05:38:14 +08:00
|
|
|
#endif
|
2007-04-29 05:01:30 +08:00
|
|
|
gtls_inited = TRUE;
|
|
|
|
}
|
|
|
|
return ret;
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
|
|
|
|
2021-01-13 15:28:10 +08:00
|
|
|
static void gtls_cleanup(void)
|
2005-04-07 23:27:13 +08:00
|
|
|
{
|
2008-02-09 06:02:00 +08:00
|
|
|
if(gtls_inited) {
|
2007-04-29 05:01:30 +08:00
|
|
|
gnutls_global_deinit();
|
2008-02-09 06:02:00 +08:00
|
|
|
gtls_inited = FALSE;
|
|
|
|
}
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
|
|
|
|
2017-04-22 18:07:13 +08:00
|
|
|
#ifndef CURL_DISABLE_VERBOSE_STRINGS
|
2016-06-21 21:47:12 +08:00
|
|
|
static void showtime(struct Curl_easy *data,
|
2005-04-07 23:27:13 +08:00
|
|
|
const char *text,
|
|
|
|
time_t stamp)
|
|
|
|
{
|
|
|
|
struct tm buffer;
|
2011-02-07 22:00:48 +08:00
|
|
|
const struct tm *tm = &buffer;
|
2017-05-02 15:08:56 +08:00
|
|
|
char str[96];
|
2011-02-07 22:00:48 +08:00
|
|
|
CURLcode result = Curl_gmtime(stamp, &buffer);
|
|
|
|
if(result)
|
|
|
|
return;
|
|
|
|
|
2018-11-22 16:01:24 +08:00
|
|
|
msnprintf(str,
|
|
|
|
sizeof(str),
|
2021-07-06 23:05:17 +08:00
|
|
|
" %s: %s, %02d %s %4d %02d:%02d:%02d GMT",
|
2018-11-22 16:01:24 +08:00
|
|
|
text,
|
|
|
|
Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
|
|
|
|
tm->tm_mday,
|
|
|
|
Curl_month[tm->tm_mon],
|
|
|
|
tm->tm_year + 1900,
|
|
|
|
tm->tm_hour,
|
|
|
|
tm->tm_min,
|
|
|
|
tm->tm_sec);
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "%s", str);
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
2017-04-22 18:07:13 +08:00
|
|
|
#endif
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2016-12-14 06:34:59 +08:00
|
|
|
static gnutls_datum_t load_file(const char *file)
|
2008-06-07 04:52:32 +08:00
|
|
|
{
|
|
|
|
FILE *f;
|
2014-04-29 20:13:52 +08:00
|
|
|
gnutls_datum_t loaded_file = { NULL, 0 };
|
2008-06-07 04:52:32 +08:00
|
|
|
long filelen;
|
|
|
|
void *ptr;
|
|
|
|
|
2016-12-14 08:29:44 +08:00
|
|
|
f = fopen(file, "rb");
|
|
|
|
if(!f)
|
2009-07-22 17:48:32 +08:00
|
|
|
return loaded_file;
|
2011-04-20 21:17:42 +08:00
|
|
|
if(fseek(f, 0, SEEK_END) != 0
|
|
|
|
|| (filelen = ftell(f)) < 0
|
|
|
|
|| fseek(f, 0, SEEK_SET) != 0
|
|
|
|
|| !(ptr = malloc((size_t)filelen)))
|
2009-07-22 17:48:32 +08:00
|
|
|
goto out;
|
2011-04-20 21:17:42 +08:00
|
|
|
if(fread(ptr, 1, (size_t)filelen, f) < (size_t)filelen) {
|
2009-07-22 17:48:32 +08:00
|
|
|
free(ptr);
|
|
|
|
goto out;
|
2008-06-07 04:52:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
loaded_file.data = ptr;
|
|
|
|
loaded_file.size = (unsigned int)filelen;
|
2009-07-22 17:48:32 +08:00
|
|
|
out:
|
|
|
|
fclose(f);
|
2008-06-07 04:52:32 +08:00
|
|
|
return loaded_file;
|
|
|
|
}
|
|
|
|
|
2016-11-23 15:49:04 +08:00
|
|
|
static void unload_file(gnutls_datum_t data)
|
|
|
|
{
|
2008-06-07 04:52:32 +08:00
|
|
|
free(data.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-17 04:43:01 +08:00
|
|
|
/* this function does a SSL/TLS (re-)handshake */
|
2022-11-22 16:55:41 +08:00
|
|
|
static CURLcode handshake(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
2010-04-17 04:43:01 +08:00
|
|
|
bool duringconnect,
|
|
|
|
bool nonblocking)
|
2005-10-23 05:05:07 +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 gtls_ssl_backend_data *backend =
|
|
|
|
(struct gtls_ssl_backend_data *)connssl->backend;
|
2022-02-18 00:48:48 +08:00
|
|
|
gnutls_session_t session;
|
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);
|
2005-10-23 05:05:07 +08:00
|
|
|
|
2022-02-18 00:48:48 +08:00
|
|
|
DEBUGASSERT(backend);
|
2022-11-30 21:42:37 +08:00
|
|
|
session = backend->gtls.session;
|
2022-02-18 00:48:48 +08:00
|
|
|
|
2010-11-08 11:03:11 +08:00
|
|
|
for(;;) {
|
2019-09-23 01:04:18 +08:00
|
|
|
timediff_t timeout_ms;
|
2019-05-12 03:42:48 +08:00
|
|
|
int rc;
|
|
|
|
|
2010-04-17 04:43:01 +08:00
|
|
|
/* check allowed time left */
|
2011-01-05 06:07:58 +08:00
|
|
|
timeout_ms = Curl_timeleft(data, NULL, duringconnect);
|
2005-10-23 05:05:07 +08:00
|
|
|
|
2010-04-17 04:43:01 +08:00
|
|
|
if(timeout_ms < 0) {
|
|
|
|
/* no need to continue if time already is up */
|
|
|
|
failf(data, "SSL connection timeout");
|
|
|
|
return CURLE_OPERATION_TIMEDOUT;
|
|
|
|
}
|
2005-10-23 05:05:07 +08:00
|
|
|
|
2010-04-17 04:43:01 +08:00
|
|
|
/* 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) {
|
2019-05-12 03:42:48 +08:00
|
|
|
int what;
|
2017-09-10 05:09:06 +08:00
|
|
|
curl_socket_t writefd = ssl_connect_2_writing ==
|
2010-04-17 04:43:01 +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 ==
|
2010-04-17 04:43:01 +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,
|
2011-05-19 02:48:42 +08:00
|
|
|
nonblocking?0:
|
2020-05-29 06:08:03 +08:00
|
|
|
timeout_ms?timeout_ms:1000);
|
2010-04-17 04:43:01 +08:00
|
|
|
if(what < 0) {
|
|
|
|
/* fatal error */
|
2007-03-28 02:16:35 +08:00
|
|
|
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
2005-10-23 05:05:07 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
2010-04-17 04:43:01 +08:00
|
|
|
else if(0 == what) {
|
2010-11-14 19:42:29 +08:00
|
|
|
if(nonblocking)
|
2010-04-17 04:43:01 +08:00
|
|
|
return CURLE_OK;
|
2010-11-14 19:42:29 +08:00
|
|
|
else if(timeout_ms) {
|
2010-04-17 04:43:01 +08:00
|
|
|
/* timeout */
|
2017-04-07 01:34:44 +08:00
|
|
|
failf(data, "SSL connection timeout at %ld", (long)timeout_ms);
|
2010-04-17 04:43:01 +08:00
|
|
|
return CURLE_OPERATION_TIMEDOUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* socket is readable or writable */
|
2005-10-23 05:05:07 +08:00
|
|
|
}
|
|
|
|
|
2010-04-17 04:43:01 +08:00
|
|
|
rc = gnutls_handshake(session);
|
2005-10-23 05:05:07 +08:00
|
|
|
|
2010-04-17 04:43:01 +08:00
|
|
|
if((rc == GNUTLS_E_AGAIN) || (rc == GNUTLS_E_INTERRUPTED)) {
|
|
|
|
connssl->connecting_state =
|
|
|
|
gnutls_record_get_direction(session)?
|
|
|
|
ssl_connect_2_writing:ssl_connect_2_reading;
|
2012-10-24 17:47:32 +08:00
|
|
|
continue;
|
2010-11-14 19:42:29 +08:00
|
|
|
}
|
2012-10-24 17:47:32 +08:00
|
|
|
else if((rc < 0) && !gnutls_error_is_fatal(rc)) {
|
2012-11-07 02:45:51 +08:00
|
|
|
const char *strerr = NULL;
|
2012-10-24 20:34:00 +08:00
|
|
|
|
|
|
|
if(rc == GNUTLS_E_WARNING_ALERT_RECEIVED) {
|
|
|
|
int alert = gnutls_alert_get(session);
|
|
|
|
strerr = gnutls_alert_get_name(alert);
|
|
|
|
}
|
|
|
|
|
2021-04-19 16:46:11 +08:00
|
|
|
if(!strerr)
|
2012-10-24 20:34:00 +08:00
|
|
|
strerr = gnutls_strerror(rc);
|
|
|
|
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "gnutls_handshake() warning: %s", strerr);
|
2015-05-21 03:50:55 +08:00
|
|
|
continue;
|
2012-08-20 22:47:48 +08:00
|
|
|
}
|
2011-04-20 21:17:42 +08:00
|
|
|
else if(rc < 0) {
|
2012-11-07 02:45:51 +08:00
|
|
|
const char *strerr = NULL;
|
2012-10-24 20:34:00 +08:00
|
|
|
|
|
|
|
if(rc == GNUTLS_E_FATAL_ALERT_RECEIVED) {
|
|
|
|
int alert = gnutls_alert_get(session);
|
|
|
|
strerr = gnutls_alert_get_name(alert);
|
|
|
|
}
|
|
|
|
|
2021-04-19 16:46:11 +08:00
|
|
|
if(!strerr)
|
2012-10-24 20:34:00 +08:00
|
|
|
strerr = gnutls_strerror(rc);
|
|
|
|
|
|
|
|
failf(data, "gnutls_handshake() failed: %s", strerr);
|
2010-11-14 19:42:29 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
2012-10-24 17:47:32 +08:00
|
|
|
|
|
|
|
/* Reset our connect state machine */
|
|
|
|
connssl->connecting_state = ssl_connect_1;
|
|
|
|
return CURLE_OK;
|
2010-04-17 04:43:01 +08:00
|
|
|
}
|
2005-10-23 05:05:07 +08:00
|
|
|
}
|
|
|
|
|
2014-04-29 20:13:52 +08:00
|
|
|
static gnutls_x509_crt_fmt_t do_file_type(const char *type)
|
2005-11-12 07:20:07 +08:00
|
|
|
{
|
|
|
|
if(!type || !type[0])
|
|
|
|
return GNUTLS_X509_FMT_PEM;
|
2016-10-01 00:54:02 +08:00
|
|
|
if(strcasecompare(type, "PEM"))
|
2005-11-12 07:20:07 +08:00
|
|
|
return GNUTLS_X509_FMT_PEM;
|
2016-10-01 00:54:02 +08:00
|
|
|
if(strcasecompare(type, "DER"))
|
2005-11-12 07:20:07 +08:00
|
|
|
return GNUTLS_X509_FMT_DER;
|
2020-09-07 16:52:48 +08:00
|
|
|
return GNUTLS_X509_FMT_PEM; /* default to PEM */
|
2005-11-12 07:20:07 +08:00
|
|
|
}
|
|
|
|
|
2016-12-14 04:10:00 +08:00
|
|
|
#define GNUTLS_CIPHERS "NORMAL:-ARCFOUR-128:-CTYPE-ALL:+CTYPE-X509"
|
|
|
|
/* If GnuTLS was compiled without support for SRP it will error out if SRP is
|
|
|
|
requested in the priority string, so treat it specially
|
|
|
|
*/
|
|
|
|
#define GNUTLS_SRP "+SRP"
|
|
|
|
|
|
|
|
static CURLcode
|
2022-11-30 21:42:37 +08:00
|
|
|
set_ssl_version_min_max(struct Curl_easy *data,
|
2024-03-22 20:07:25 +08:00
|
|
|
struct ssl_peer *peer,
|
2022-11-30 21:42:37 +08:00
|
|
|
struct ssl_primary_config *conn_config,
|
2021-05-06 05:26:01 +08:00
|
|
|
const char **prioritylist,
|
|
|
|
const char *tls13support)
|
2016-12-14 04:10:00 +08:00
|
|
|
{
|
2022-11-22 16:55:41 +08:00
|
|
|
long ssl_version = conn_config->version;
|
|
|
|
long ssl_version_max = conn_config->version_max;
|
2018-09-11 02:35:38 +08:00
|
|
|
|
2024-03-22 20:07:25 +08:00
|
|
|
if(peer->transport == TRNSPRT_QUIC) {
|
|
|
|
if((ssl_version != CURL_SSLVERSION_DEFAULT) &&
|
|
|
|
(ssl_version < CURL_SSLVERSION_TLSv1_3)) {
|
|
|
|
failf(data, "QUIC needs at least TLS version 1.3");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
*prioritylist = QUIC_PRIORITY;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:34:14 +08:00
|
|
|
if((ssl_version == CURL_SSLVERSION_DEFAULT) ||
|
|
|
|
(ssl_version == CURL_SSLVERSION_TLSv1))
|
|
|
|
ssl_version = CURL_SSLVERSION_TLSv1_0;
|
|
|
|
if(ssl_version_max == CURL_SSLVERSION_MAX_NONE)
|
2018-09-19 04:35:36 +08:00
|
|
|
ssl_version_max = CURL_SSLVERSION_MAX_DEFAULT;
|
2021-05-06 05:26:01 +08:00
|
|
|
if(!tls13support) {
|
|
|
|
/* If the running GnuTLS doesn't support TLS 1.3, we must not specify a
|
|
|
|
prioritylist involving that since it will make GnuTLS return an en
|
|
|
|
error back at us */
|
|
|
|
if((ssl_version_max == CURL_SSLVERSION_MAX_TLSv1_3) ||
|
|
|
|
(ssl_version_max == CURL_SSLVERSION_MAX_DEFAULT)) {
|
|
|
|
ssl_version_max = CURL_SSLVERSION_MAX_TLSv1_2;
|
|
|
|
}
|
|
|
|
}
|
2021-06-18 20:54:07 +08:00
|
|
|
else if(ssl_version_max == CURL_SSLVERSION_MAX_DEFAULT) {
|
|
|
|
ssl_version_max = CURL_SSLVERSION_MAX_TLSv1_3;
|
|
|
|
}
|
2021-05-04 19:34:14 +08:00
|
|
|
|
2016-12-14 04:10:00 +08:00
|
|
|
switch(ssl_version | ssl_version_max) {
|
2020-04-21 04:23:48 +08:00
|
|
|
case CURL_SSLVERSION_TLSv1_0 | CURL_SSLVERSION_MAX_TLSv1_0:
|
|
|
|
*prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
|
|
|
|
"+VERS-TLS1.0";
|
|
|
|
return CURLE_OK;
|
|
|
|
case CURL_SSLVERSION_TLSv1_0 | CURL_SSLVERSION_MAX_TLSv1_1:
|
|
|
|
*prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
|
2021-06-18 20:54:07 +08:00
|
|
|
"+VERS-TLS1.1:+VERS-TLS1.0";
|
2020-04-21 04:23:48 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
case CURL_SSLVERSION_TLSv1_0 | CURL_SSLVERSION_MAX_TLSv1_2:
|
|
|
|
*prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
|
2021-06-18 20:54:07 +08:00
|
|
|
"+VERS-TLS1.2:+VERS-TLS1.1:+VERS-TLS1.0";
|
2020-04-21 04:23:48 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
case CURL_SSLVERSION_TLSv1_1 | CURL_SSLVERSION_MAX_TLSv1_1:
|
|
|
|
*prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
|
|
|
|
"+VERS-TLS1.1";
|
|
|
|
return CURLE_OK;
|
|
|
|
case CURL_SSLVERSION_TLSv1_1 | CURL_SSLVERSION_MAX_TLSv1_2:
|
|
|
|
*prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
|
2021-06-18 20:54:07 +08:00
|
|
|
"+VERS-TLS1.2:+VERS-TLS1.1";
|
2020-04-21 04:23:48 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
case CURL_SSLVERSION_TLSv1_2 | CURL_SSLVERSION_MAX_TLSv1_2:
|
|
|
|
*prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
|
|
|
|
"+VERS-TLS1.2";
|
|
|
|
return CURLE_OK;
|
|
|
|
case CURL_SSLVERSION_TLSv1_3 | CURL_SSLVERSION_MAX_TLSv1_3:
|
|
|
|
*prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
|
|
|
|
"+VERS-TLS1.3";
|
|
|
|
return CURLE_OK;
|
2021-06-18 20:54:07 +08:00
|
|
|
case CURL_SSLVERSION_TLSv1_0 | CURL_SSLVERSION_MAX_TLSv1_3:
|
|
|
|
*prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0";
|
2020-04-21 04:23:48 +08:00
|
|
|
return CURLE_OK;
|
2021-06-18 20:54:07 +08:00
|
|
|
case CURL_SSLVERSION_TLSv1_1 | CURL_SSLVERSION_MAX_TLSv1_3:
|
2020-04-21 04:23:48 +08:00
|
|
|
*prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
|
2021-06-18 20:54:07 +08:00
|
|
|
"+VERS-TLS1.3:+VERS-TLS1.2:+VERS-TLS1.1";
|
2020-04-21 04:23:48 +08:00
|
|
|
return CURLE_OK;
|
2021-06-18 20:54:07 +08:00
|
|
|
case CURL_SSLVERSION_TLSv1_2 | CURL_SSLVERSION_MAX_TLSv1_3:
|
2020-04-21 04:23:48 +08:00
|
|
|
*prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
|
2021-06-18 20:54:07 +08:00
|
|
|
"+VERS-TLS1.3:+VERS-TLS1.2";
|
2020-04-21 04:23:48 +08:00
|
|
|
return CURLE_OK;
|
2016-12-14 04:10:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
failf(data, "GnuTLS: cannot set ssl protocol");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
|
2024-03-22 20:07:25 +08:00
|
|
|
static CURLcode gtls_client_init(struct Curl_easy *data,
|
|
|
|
struct ssl_primary_config *config,
|
|
|
|
struct ssl_config_data *ssl_config,
|
|
|
|
struct ssl_peer *peer,
|
|
|
|
struct gtls_ctx *gtls,
|
|
|
|
long *pverifyresult)
|
2005-04-07 23:27:13 +08:00
|
|
|
{
|
2017-01-29 03:06:31 +08:00
|
|
|
unsigned int init_flags;
|
2005-04-07 23:27:13 +08:00
|
|
|
int rc;
|
2009-08-02 06:11:58 +08:00
|
|
|
bool sni = TRUE; /* default is SNI enabled */
|
2016-11-23 14:53:24 +08:00
|
|
|
const char *prioritylist;
|
2014-07-13 07:30:52 +08:00
|
|
|
const char *err = NULL;
|
2021-05-06 05:26:01 +08:00
|
|
|
const char *tls13support;
|
2021-09-29 16:00:52 +08:00
|
|
|
CURLcode result;
|
2016-11-17 01:49:15 +08:00
|
|
|
|
2008-02-20 16:28:02 +08:00
|
|
|
if(!gtls_inited)
|
2021-01-13 15:28:10 +08:00
|
|
|
gtls_init();
|
2008-02-20 16:28:02 +08:00
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
*pverifyresult = 0;
|
2020-04-24 03:36:35 +08:00
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->version == CURL_SSLVERSION_SSLv2) {
|
2005-04-07 23:27:13 +08:00
|
|
|
failf(data, "GnuTLS does not support SSLv2");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
2022-11-30 21:42:37 +08:00
|
|
|
else if(config->version == CURL_SSLVERSION_SSLv3)
|
2009-08-02 06:11:58 +08:00
|
|
|
sni = FALSE; /* SSLv3 has no SNI */
|
2005-04-07 23:27:13 +08:00
|
|
|
|
|
|
|
/* allocate a cred struct */
|
2022-11-30 21:42:37 +08:00
|
|
|
rc = gnutls_certificate_allocate_credentials(>ls->cred);
|
2009-03-09 06:52:05 +08:00
|
|
|
if(rc != GNUTLS_E_SUCCESS) {
|
2005-04-13 20:38:01 +08:00
|
|
|
failf(data, "gnutls_cert_all_cred() failed: %s", gnutls_strerror(rc));
|
2005-04-07 23:27:13 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
|
2022-03-18 03:31:10 +08:00
|
|
|
#ifdef USE_GNUTLS_SRP
|
2022-12-30 22:04:57 +08:00
|
|
|
if(config->username && Curl_auth_allowed_to_host(data)) {
|
2022-11-30 21:42:37 +08:00
|
|
|
infof(data, "Using TLS-SRP username: %s", config->username);
|
2011-01-20 03:35:02 +08:00
|
|
|
|
2022-12-30 22:04:57 +08:00
|
|
|
rc = gnutls_srp_allocate_client_credentials(>ls->srp_client_cred);
|
2011-01-20 03:35:02 +08:00
|
|
|
if(rc != GNUTLS_E_SUCCESS) {
|
|
|
|
failf(data, "gnutls_srp_allocate_client_cred() failed: %s",
|
|
|
|
gnutls_strerror(rc));
|
2011-02-10 06:34:30 +08:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2011-01-20 03:35:02 +08:00
|
|
|
}
|
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
rc = gnutls_srp_set_client_credentials(gtls->srp_client_cred,
|
|
|
|
config->username,
|
|
|
|
config->password);
|
2011-01-20 03:35:02 +08:00
|
|
|
if(rc != GNUTLS_E_SUCCESS) {
|
|
|
|
failf(data, "gnutls_srp_set_client_cred() failed: %s",
|
|
|
|
gnutls_strerror(rc));
|
2011-02-10 06:34:30 +08:00
|
|
|
return CURLE_BAD_FUNCTION_ARGUMENT;
|
2011-01-20 03:35:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-10-16 20:46:36 +08:00
|
|
|
if(config->verifypeer) {
|
|
|
|
bool imported_native_ca = false;
|
|
|
|
|
|
|
|
if(ssl_config->native_ca_store) {
|
|
|
|
rc = gnutls_certificate_set_x509_system_trust(gtls->cred);
|
|
|
|
if(rc < 0)
|
|
|
|
infof(data, "error reading native ca store (%s), continuing anyway",
|
|
|
|
gnutls_strerror(rc));
|
|
|
|
else {
|
|
|
|
infof(data, "found %d certificates in native ca store", rc);
|
|
|
|
if(rc > 0)
|
|
|
|
imported_native_ca = true;
|
2020-04-24 03:36:35 +08:00
|
|
|
}
|
2006-10-21 19:32:05 +08:00
|
|
|
}
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2023-10-16 20:46:36 +08:00
|
|
|
if(config->CAfile) {
|
|
|
|
/* set the trusted CA cert bundle file */
|
|
|
|
gnutls_certificate_set_verify_flags(gtls->cred,
|
|
|
|
GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT);
|
|
|
|
|
|
|
|
rc = gnutls_certificate_set_x509_trust_file(gtls->cred,
|
|
|
|
config->CAfile,
|
|
|
|
GNUTLS_X509_FMT_PEM);
|
|
|
|
if(rc < 0) {
|
|
|
|
infof(data, "error reading ca cert file %s (%s)%s",
|
|
|
|
config->CAfile, gnutls_strerror(rc),
|
|
|
|
(imported_native_ca ? ", continuing anyway" : ""));
|
|
|
|
if(!imported_native_ca) {
|
|
|
|
*pverifyresult = rc;
|
|
|
|
return CURLE_SSL_CACERT_BADFILE;
|
|
|
|
}
|
2020-04-24 03:36:35 +08:00
|
|
|
}
|
2023-10-16 20:46:36 +08:00
|
|
|
else
|
|
|
|
infof(data, "found %d certificates in %s", rc, config->CAfile);
|
2015-03-09 03:11:06 +08:00
|
|
|
}
|
|
|
|
|
2023-10-16 20:46:36 +08:00
|
|
|
if(config->CApath) {
|
|
|
|
/* set the trusted CA cert directory */
|
|
|
|
rc = gnutls_certificate_set_x509_trust_dir(gtls->cred,
|
|
|
|
config->CApath,
|
|
|
|
GNUTLS_X509_FMT_PEM);
|
|
|
|
if(rc < 0) {
|
|
|
|
infof(data, "error reading ca cert file %s (%s)%s",
|
|
|
|
config->CApath, gnutls_strerror(rc),
|
|
|
|
(imported_native_ca ? ", continuing anyway" : ""));
|
|
|
|
if(!imported_native_ca) {
|
|
|
|
*pverifyresult = rc;
|
|
|
|
return CURLE_SSL_CACERT_BADFILE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
infof(data, "found %d certificates in %s", rc, config->CApath);
|
|
|
|
}
|
2015-03-24 20:25:17 +08:00
|
|
|
}
|
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->CRLfile) {
|
2008-06-07 02:40:21 +08:00
|
|
|
/* set the CRL list file */
|
2022-11-30 21:42:37 +08:00
|
|
|
rc = gnutls_certificate_set_x509_crl_file(gtls->cred,
|
|
|
|
config->CRLfile,
|
2009-02-25 20:51:17 +08:00
|
|
|
GNUTLS_X509_FMT_PEM);
|
2008-06-07 02:40:21 +08:00
|
|
|
if(rc < 0) {
|
2012-06-14 19:32:05 +08:00
|
|
|
failf(data, "error reading crl file %s (%s)",
|
2022-11-30 21:42:37 +08:00
|
|
|
config->CRLfile, gnutls_strerror(rc));
|
2008-06-07 02:40:21 +08:00
|
|
|
return CURLE_SSL_CRL_BADFILE;
|
|
|
|
}
|
|
|
|
else
|
2022-11-30 21:42:37 +08:00
|
|
|
infof(data, "found %d CRL in %s", rc, config->CRLfile);
|
2008-06-07 02:40:21 +08:00
|
|
|
}
|
|
|
|
|
2005-04-07 23:27:13 +08:00
|
|
|
/* Initialize TLS session as a client */
|
2020-02-27 10:01:16 +08:00
|
|
|
init_flags = GNUTLS_CLIENT;
|
|
|
|
|
|
|
|
#if defined(GNUTLS_FORCE_CLIENT_CERT)
|
|
|
|
init_flags |= GNUTLS_FORCE_CLIENT_CERT;
|
|
|
|
#endif
|
2017-01-29 03:06:31 +08:00
|
|
|
|
|
|
|
#if defined(GNUTLS_NO_TICKETS)
|
|
|
|
/* Disable TLS session tickets */
|
|
|
|
init_flags |= GNUTLS_NO_TICKETS;
|
|
|
|
#endif
|
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
rc = gnutls_init(>ls->session, init_flags);
|
2009-03-09 06:52:05 +08:00
|
|
|
if(rc != GNUTLS_E_SUCCESS) {
|
2005-04-07 23:27:13 +08:00
|
|
|
failf(data, "gnutls_init() failed: %d", rc);
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
|
2023-11-17 22:26:08 +08:00
|
|
|
if(sni && peer->sni) {
|
|
|
|
if(gnutls_server_name_set(gtls->session, GNUTLS_NAME_DNS,
|
|
|
|
peer->sni, strlen(peer->sni)) < 0) {
|
2022-01-23 06:44:00 +08:00
|
|
|
failf(data, "Failed to set SNI");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2008-02-26 18:30:13 +08:00
|
|
|
|
2005-04-07 23:27:13 +08:00
|
|
|
/* Use default priorities */
|
2022-11-30 21:42:37 +08:00
|
|
|
rc = gnutls_set_default_priority(gtls->session);
|
2009-03-09 06:52:05 +08:00
|
|
|
if(rc != GNUTLS_E_SUCCESS)
|
2005-04-07 23:27:13 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
|
2021-05-06 05:26:01 +08:00
|
|
|
/* "In GnuTLS 3.6.5, TLS 1.3 is enabled by default" */
|
|
|
|
tls13support = gnutls_check_version("3.6.5");
|
|
|
|
|
2014-07-15 04:27:03 +08:00
|
|
|
/* Ensure +SRP comes at the *end* of all relevant strings so that it can be
|
|
|
|
* removed if a run-time error indicates that SRP is not supported by this
|
|
|
|
* GnuTLS version */
|
2021-09-29 16:00:52 +08:00
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->version == CURL_SSLVERSION_SSLv2 ||
|
|
|
|
config->version == CURL_SSLVERSION_SSLv3) {
|
2021-09-29 16:00:52 +08:00
|
|
|
failf(data, "GnuTLS does not support SSLv2 or SSLv3");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->version == CURL_SSLVERSION_TLSv1_3) {
|
2021-09-29 16:00:52 +08:00
|
|
|
if(!tls13support) {
|
|
|
|
failf(data, "This GnuTLS installation does not support TLS 1.3");
|
2016-11-08 10:51:27 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
2021-09-29 16:00:52 +08:00
|
|
|
}
|
2014-01-19 16:47:31 +08:00
|
|
|
}
|
2014-07-15 04:27:03 +08:00
|
|
|
|
2021-09-29 16:00:52 +08:00
|
|
|
/* At this point we know we have a supported TLS version, so set it */
|
2024-03-22 20:07:25 +08:00
|
|
|
result = set_ssl_version_min_max(data, peer,
|
|
|
|
config, &prioritylist, tls13support);
|
2021-09-29 16:00:52 +08:00
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
2022-03-18 03:31:10 +08:00
|
|
|
#ifdef USE_GNUTLS_SRP
|
2020-04-12 19:29:09 +08:00
|
|
|
/* Only add SRP to the cipher list if SRP is requested. Otherwise
|
|
|
|
* GnuTLS will disable TLS 1.3 support. */
|
2022-12-30 22:04:57 +08:00
|
|
|
if(config->username) {
|
2023-12-05 22:55:35 +08:00
|
|
|
char *prioritysrp = aprintf("%s:" GNUTLS_SRP, prioritylist);
|
2020-04-12 19:29:09 +08:00
|
|
|
if(!prioritysrp)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2022-11-30 21:42:37 +08:00
|
|
|
rc = gnutls_priority_set_direct(gtls->session, prioritysrp, &err);
|
2020-04-12 19:29:09 +08:00
|
|
|
free(prioritysrp);
|
|
|
|
|
|
|
|
if((rc == GNUTLS_E_INVALID_REQUEST) && err) {
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "This GnuTLS does not support SRP");
|
2014-07-15 04:27:03 +08:00
|
|
|
}
|
|
|
|
}
|
2020-04-12 19:29:09 +08:00
|
|
|
else {
|
|
|
|
#endif
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "GnuTLS ciphers: %s", prioritylist);
|
2022-11-30 21:42:37 +08:00
|
|
|
rc = gnutls_priority_set_direct(gtls->session, prioritylist, &err);
|
2022-03-18 03:31:10 +08:00
|
|
|
#ifdef USE_GNUTLS_SRP
|
2020-04-12 19:29:09 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-07-13 07:30:52 +08:00
|
|
|
if(rc != GNUTLS_E_SUCCESS) {
|
|
|
|
failf(data, "Error %d setting GnuTLS cipher list starting with %s",
|
|
|
|
rc, err);
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->clientcert) {
|
2022-11-22 16:55:41 +08:00
|
|
|
if(ssl_config->key_passwd) {
|
2015-09-21 17:34:55 +08:00
|
|
|
const unsigned int supported_key_encryption_algorithms =
|
|
|
|
GNUTLS_PKCS_USE_PKCS12_3DES | GNUTLS_PKCS_USE_PKCS12_ARCFOUR |
|
|
|
|
GNUTLS_PKCS_USE_PKCS12_RC2_40 | GNUTLS_PKCS_USE_PBES2_3DES |
|
|
|
|
GNUTLS_PKCS_USE_PBES2_AES_128 | GNUTLS_PKCS_USE_PBES2_AES_192 |
|
|
|
|
GNUTLS_PKCS_USE_PBES2_AES_256;
|
2015-09-23 19:31:29 +08:00
|
|
|
rc = gnutls_certificate_set_x509_key_file2(
|
2022-11-30 21:42:37 +08:00
|
|
|
gtls->cred,
|
|
|
|
config->clientcert,
|
|
|
|
ssl_config->key ? ssl_config->key : config->clientcert,
|
2022-11-22 16:55:41 +08:00
|
|
|
do_file_type(ssl_config->cert_type),
|
|
|
|
ssl_config->key_passwd,
|
2015-09-23 19:31:29 +08:00
|
|
|
supported_key_encryption_algorithms);
|
|
|
|
if(rc != GNUTLS_E_SUCCESS) {
|
2015-09-21 17:34:55 +08:00
|
|
|
failf(data,
|
2015-09-23 19:31:29 +08:00
|
|
|
"error reading X.509 potentially-encrypted key file: %s",
|
|
|
|
gnutls_strerror(rc));
|
2015-09-21 17:34:55 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
2016-02-14 10:54:45 +08:00
|
|
|
}
|
2015-09-21 17:34:55 +08:00
|
|
|
}
|
|
|
|
else {
|
2016-11-17 01:49:15 +08:00
|
|
|
if(gnutls_certificate_set_x509_key_file(
|
2022-11-30 21:42:37 +08:00
|
|
|
gtls->cred,
|
|
|
|
config->clientcert,
|
|
|
|
ssl_config->key ? ssl_config->key : config->clientcert,
|
2022-11-22 16:55:41 +08:00
|
|
|
do_file_type(ssl_config->cert_type) ) !=
|
2016-11-17 01:49:15 +08:00
|
|
|
GNUTLS_E_SUCCESS) {
|
|
|
|
failf(data, "error reading X.509 key or certificate file");
|
2015-09-21 17:34:55 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
2005-11-12 07:20:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-18 03:31:10 +08:00
|
|
|
#ifdef USE_GNUTLS_SRP
|
2005-11-12 07:20:07 +08:00
|
|
|
/* put the credentials to the current session */
|
2022-12-30 22:04:57 +08:00
|
|
|
if(config->username) {
|
2022-11-30 21:42:37 +08:00
|
|
|
rc = gnutls_credentials_set(gtls->session, GNUTLS_CRD_SRP,
|
|
|
|
gtls->srp_client_cred);
|
2015-03-21 23:50:51 +08:00
|
|
|
if(rc != GNUTLS_E_SUCCESS) {
|
2011-01-20 03:35:02 +08:00
|
|
|
failf(data, "gnutls_credentials_set() failed: %s", gnutls_strerror(rc));
|
2015-03-21 23:50:51 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
2011-04-20 21:17:42 +08:00
|
|
|
}
|
|
|
|
else
|
2011-01-20 03:35:02 +08:00
|
|
|
#endif
|
2015-03-21 23:50:51 +08:00
|
|
|
{
|
2022-11-30 21:42:37 +08:00
|
|
|
rc = gnutls_credentials_set(gtls->session, GNUTLS_CRD_CERTIFICATE,
|
|
|
|
gtls->cred);
|
2015-03-21 23:50:51 +08:00
|
|
|
if(rc != GNUTLS_E_SUCCESS) {
|
|
|
|
failf(data, "gnutls_credentials_set() failed: %s", gnutls_strerror(rc));
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->verifystatus) {
|
|
|
|
rc = gnutls_ocsp_status_request_enable_client(gtls->session,
|
|
|
|
NULL, 0, NULL);
|
|
|
|
if(rc != GNUTLS_E_SUCCESS) {
|
|
|
|
failf(data, "gnutls_ocsp_status_request_enable_client() failed: %d", rc);
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2024-03-22 20:07:25 +08:00
|
|
|
static int keylog_callback(gnutls_session_t session, const char *label,
|
|
|
|
const gnutls_datum_t *secret)
|
|
|
|
{
|
|
|
|
gnutls_datum_t crandom;
|
|
|
|
gnutls_datum_t srandom;
|
|
|
|
|
|
|
|
gnutls_session_get_random(session, &crandom, &srandom);
|
|
|
|
if(crandom.size != 32) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Curl_tls_keylog_write(label, crandom.data, secret->data, secret->size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CURLcode Curl_gtls_ctx_init(struct gtls_ctx *gctx,
|
|
|
|
struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
|
|
|
struct ssl_peer *peer,
|
|
|
|
const unsigned char *alpn, size_t alpn_len,
|
|
|
|
Curl_gtls_ctx_setup_cb *cb_setup,
|
|
|
|
void *cb_user_data,
|
|
|
|
void *ssl_user_data)
|
2022-11-30 21:42:37 +08:00
|
|
|
{
|
|
|
|
struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf);
|
|
|
|
struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data);
|
|
|
|
long * const pverifyresult = &ssl_config->certverifyresult;
|
|
|
|
CURLcode result;
|
|
|
|
|
2024-03-22 20:07:25 +08:00
|
|
|
DEBUGASSERT(gctx);
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2024-03-22 20:07:25 +08:00
|
|
|
result = gtls_client_init(data, conn_config, ssl_config, peer,
|
|
|
|
gctx, pverifyresult);
|
2022-11-30 21:42:37 +08:00
|
|
|
if(result)
|
|
|
|
return result;
|
2006-12-17 05:33:51 +08:00
|
|
|
|
2024-03-22 20:07:25 +08:00
|
|
|
gnutls_session_set_ptr(gctx->session, ssl_user_data);
|
|
|
|
|
|
|
|
if(cb_setup) {
|
|
|
|
result = cb_setup(cf, data, cb_user_data);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
2022-11-30 21:42:37 +08:00
|
|
|
|
2024-03-22 20:07:25 +08:00
|
|
|
/* Open the file if a TLS or QUIC backend has not done this before. */
|
|
|
|
Curl_tls_keylog_open();
|
|
|
|
if(Curl_tls_keylog_enabled()) {
|
|
|
|
gnutls_session_set_keylog_function(gctx->session, keylog_callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert the ALPN string from our arguments to a list of strings
|
|
|
|
* that gnutls wants and will convert internally back to this very
|
|
|
|
* string for sending to the server. nice. */
|
2024-04-09 15:53:26 +08:00
|
|
|
if(alpn && alpn_len) {
|
2024-03-22 20:07:25 +08:00
|
|
|
gnutls_datum_t alpns[5];
|
|
|
|
size_t i, alen = alpn_len;
|
|
|
|
unsigned char *s = (unsigned char *)alpn;
|
|
|
|
unsigned char slen;
|
|
|
|
for(i = 0; (i < ARRAYSIZE(alpns)) && alen; ++i) {
|
|
|
|
slen = s[0];
|
|
|
|
if(slen >= alen)
|
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
alpns[i].data = s + 1;
|
|
|
|
alpns[i].size = slen;
|
|
|
|
s += slen + 1;
|
|
|
|
alen -= (size_t)slen + 1;
|
2022-12-31 00:37:11 +08:00
|
|
|
}
|
2024-03-22 20:07:25 +08:00
|
|
|
if(alen) /* not all alpn chars used, wrong format or too many */
|
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
if(i && gnutls_alpn_set_protocols(gctx->session,
|
|
|
|
alpns, (unsigned int)i,
|
|
|
|
GNUTLS_ALPN_MANDATORY)) {
|
2022-11-30 21:42:37 +08:00
|
|
|
failf(data, "failed setting ALPN");
|
2014-06-16 19:21:02 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-07 23:27:13 +08:00
|
|
|
/* This might be a reconnect, so we check for a session ID in the cache
|
|
|
|
to speed up things */
|
2022-11-30 21:42:37 +08:00
|
|
|
if(conn_config->sessionid) {
|
2016-06-13 11:47:12 +08:00
|
|
|
void *ssl_sessionid;
|
|
|
|
size_t ssl_idsize;
|
2005-04-07 23:27:13 +08:00
|
|
|
|
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, peer, &ssl_sessionid, &ssl_idsize)) {
|
2016-06-13 11:47:12 +08:00
|
|
|
/* we got a session id, use it! */
|
2024-03-22 20:07:25 +08:00
|
|
|
gnutls_session_set_data(gctx->session, ssl_sessionid, ssl_idsize);
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2016-06-13 11:47:12 +08:00
|
|
|
/* Informational message */
|
2023-08-23 20:47:45 +08:00
|
|
|
infof(data, "SSL reusing session ID");
|
2016-06-13 11:47:12 +08:00
|
|
|
}
|
2021-01-14 00:01:31 +08:00
|
|
|
Curl_ssl_sessionid_unlock(data);
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
2024-03-22 20:07:25 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode
|
|
|
|
gtls_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data)
|
|
|
|
{
|
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
|
|
|
struct gtls_ssl_backend_data *backend =
|
|
|
|
(struct gtls_ssl_backend_data *)connssl->backend;
|
|
|
|
struct alpn_proto_buf proto;
|
|
|
|
CURLcode result;
|
|
|
|
|
|
|
|
DEBUGASSERT(backend);
|
|
|
|
DEBUGASSERT(ssl_connect_1 == connssl->connecting_state);
|
|
|
|
|
|
|
|
if(connssl->state == ssl_connection_complete)
|
|
|
|
/* to make us tolerant against being called more than once for the
|
|
|
|
same connection */
|
|
|
|
return CURLE_OK;
|
|
|
|
|
|
|
|
memset(&proto, 0, sizeof(proto));
|
|
|
|
if(connssl->alpn) {
|
|
|
|
result = Curl_alpn_to_proto_buf(&proto, connssl->alpn);
|
|
|
|
if(result) {
|
|
|
|
failf(data, "Error determining ALPN");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = Curl_gtls_ctx_init(&backend->gtls, cf, data, &connssl->peer,
|
|
|
|
proto.data, proto.len, NULL, NULL, cf);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
/* register callback functions and handle to send and receive data. */
|
|
|
|
gnutls_transport_set_ptr(backend->gtls.session, cf);
|
|
|
|
gnutls_transport_set_push_function(backend->gtls.session, gtls_push);
|
|
|
|
gnutls_transport_set_pull_function(backend->gtls.session, gtls_pull);
|
|
|
|
|
2010-04-17 04:43:01 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2016-06-21 21:47:12 +08:00
|
|
|
static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data,
|
2015-09-13 05:35:12 +08:00
|
|
|
gnutls_x509_crt_t cert,
|
2014-10-14 00:34:51 +08:00
|
|
|
const char *pinnedpubkey)
|
2014-10-01 14:14:49 +08:00
|
|
|
{
|
|
|
|
/* Scratch */
|
|
|
|
size_t len1 = 0, len2 = 0;
|
2014-10-14 00:34:51 +08:00
|
|
|
unsigned char *buff1 = NULL;
|
2014-10-01 14:14:49 +08:00
|
|
|
|
|
|
|
gnutls_pubkey_t key = NULL;
|
|
|
|
|
|
|
|
/* Result is returned to caller */
|
2014-10-14 00:34:51 +08:00
|
|
|
CURLcode result = CURLE_SSL_PINNEDPUBKEYNOTMATCH;
|
2014-10-01 14:14:49 +08:00
|
|
|
|
|
|
|
/* if a path wasn't specified, don't pin */
|
2021-12-26 04:41:14 +08:00
|
|
|
if(!pinnedpubkey)
|
2014-10-14 04:22:49 +08:00
|
|
|
return CURLE_OK;
|
|
|
|
|
2021-12-26 04:41:14 +08:00
|
|
|
if(!cert)
|
2014-10-14 04:22:49 +08:00
|
|
|
return result;
|
2014-10-01 14:14:49 +08:00
|
|
|
|
|
|
|
do {
|
2019-05-12 03:42:48 +08:00
|
|
|
int ret;
|
|
|
|
|
2014-10-01 14:14:49 +08:00
|
|
|
/* Begin Gyrations to get the public key */
|
|
|
|
gnutls_pubkey_init(&key);
|
|
|
|
|
|
|
|
ret = gnutls_pubkey_import_x509(key, cert, 0);
|
|
|
|
if(ret < 0)
|
|
|
|
break; /* failed */
|
|
|
|
|
|
|
|
ret = gnutls_pubkey_export(key, GNUTLS_X509_FMT_DER, NULL, &len1);
|
|
|
|
if(ret != GNUTLS_E_SHORT_MEMORY_BUFFER || len1 == 0)
|
2014-10-14 04:22:49 +08:00
|
|
|
break; /* failed */
|
2014-10-01 14:14:49 +08:00
|
|
|
|
|
|
|
buff1 = malloc(len1);
|
2021-12-26 04:41:14 +08:00
|
|
|
if(!buff1)
|
2014-10-01 14:14:49 +08:00
|
|
|
break; /* failed */
|
|
|
|
|
|
|
|
len2 = len1;
|
|
|
|
|
|
|
|
ret = gnutls_pubkey_export(key, GNUTLS_X509_FMT_DER, buff1, &len2);
|
|
|
|
if(ret < 0 || len1 != len2)
|
|
|
|
break; /* failed */
|
|
|
|
|
|
|
|
/* End Gyrations */
|
|
|
|
|
|
|
|
/* The one good exit point */
|
2015-09-13 05:35:12 +08:00
|
|
|
result = Curl_pin_peer_pubkey(data, pinnedpubkey, buff1, len1);
|
2014-10-01 14:14:49 +08:00
|
|
|
} while(0);
|
|
|
|
|
2021-12-26 04:41:14 +08:00
|
|
|
if(key)
|
2014-10-01 14:14:49 +08:00
|
|
|
gnutls_pubkey_deinit(key);
|
|
|
|
|
2014-10-14 00:34:51 +08:00
|
|
|
Curl_safefree(buff1);
|
2014-10-01 14:14:49 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-12-25 23:14:53 +08:00
|
|
|
CURLcode
|
2022-11-30 21:42:37 +08:00
|
|
|
Curl_gtls_verifyserver(struct Curl_easy *data,
|
|
|
|
gnutls_session_t session,
|
|
|
|
struct ssl_primary_config *config,
|
|
|
|
struct ssl_config_data *ssl_config,
|
2023-11-17 22:26:08 +08:00
|
|
|
struct ssl_peer *peer,
|
2022-11-30 21:42:37 +08:00
|
|
|
const char *pinned_key)
|
2010-04-17 04:43:01 +08:00
|
|
|
{
|
|
|
|
unsigned int cert_list_size;
|
2014-04-29 20:13:52 +08:00
|
|
|
const gnutls_datum_t *chainp;
|
2015-03-21 23:44:17 +08:00
|
|
|
unsigned int verify_status = 0;
|
2015-03-17 20:41:49 +08:00
|
|
|
gnutls_x509_crt_t x509_cert, x509_issuer;
|
2014-04-29 20:13:52 +08:00
|
|
|
gnutls_datum_t issuerp;
|
2020-04-20 18:11:54 +08:00
|
|
|
gnutls_datum_t certfields;
|
|
|
|
char certname[65] = ""; /* limited to 64 chars by ASN.1 */
|
2010-04-17 04:43:01 +08:00
|
|
|
size_t size;
|
|
|
|
time_t certclock;
|
|
|
|
int rc;
|
2011-01-06 07:47:37 +08:00
|
|
|
CURLcode result = CURLE_OK;
|
2017-04-08 19:40:41 +08:00
|
|
|
#ifndef CURL_DISABLE_VERBOSE_STRINGS
|
2023-12-12 02:45:01 +08:00
|
|
|
const char *ptr;
|
2017-04-22 18:07:13 +08:00
|
|
|
unsigned int algo;
|
|
|
|
unsigned int bits;
|
2015-03-10 06:52:16 +08:00
|
|
|
gnutls_protocol_t version = gnutls_protocol_get_version(session);
|
2017-04-08 19:40:41 +08:00
|
|
|
#endif
|
2022-11-22 16:55:41 +08:00
|
|
|
long * const certverifyresult = &ssl_config->certverifyresult;
|
2015-03-10 06:52:16 +08:00
|
|
|
|
2023-12-12 02:45:01 +08:00
|
|
|
#ifndef CURL_DISABLE_VERBOSE_STRINGS
|
2015-03-10 06:52:16 +08:00
|
|
|
/* the name of the cipher suite used, e.g. ECDHE_RSA_AES_256_GCM_SHA384. */
|
|
|
|
ptr = gnutls_cipher_suite_get_name(gnutls_kx_get(session),
|
|
|
|
gnutls_cipher_get(session),
|
|
|
|
gnutls_mac_get(session));
|
|
|
|
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "SSL connection using %s / %s",
|
2015-03-10 06:52:16 +08:00
|
|
|
gnutls_protocol_get_name(version), ptr);
|
2023-12-12 02:45:01 +08:00
|
|
|
#endif
|
2015-03-10 06:52:16 +08:00
|
|
|
|
2005-04-07 23:27:13 +08:00
|
|
|
/* This function will return the peer's raw certificate (chain) as sent by
|
|
|
|
the peer. These certificates are in raw format (DER encoded for
|
|
|
|
X.509). In case of a X.509 then a certificate list may be present. The
|
|
|
|
first certificate in the list is the peer's certificate, following the
|
|
|
|
issuer's certificate, then the issuer's issuer etc. */
|
|
|
|
|
|
|
|
chainp = gnutls_certificate_get_peers(session, &cert_list_size);
|
|
|
|
if(!chainp) {
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->verifypeer ||
|
|
|
|
config->verifyhost ||
|
|
|
|
config->issuercert) {
|
2022-03-18 03:31:10 +08:00
|
|
|
#ifdef USE_GNUTLS_SRP
|
2022-12-30 22:04:57 +08:00
|
|
|
if(ssl_config->primary.username && !config->verifypeer &&
|
|
|
|
gnutls_cipher_get(session)) {
|
2011-01-20 03:35:02 +08:00
|
|
|
/* no peer cert, but auth is ok if we have SRP user and cipher and no
|
|
|
|
peer verify */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#endif
|
|
|
|
failf(data, "failed to get server cert");
|
2020-04-24 03:36:35 +08:00
|
|
|
*certverifyresult = GNUTLS_E_NO_CERTIFICATE_FOUND;
|
2011-01-20 03:35:02 +08:00
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
2022-03-18 03:31:10 +08:00
|
|
|
#ifdef USE_GNUTLS_SRP
|
2011-01-20 03:35:02 +08:00
|
|
|
}
|
|
|
|
#endif
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " common name: WARNING couldn't obtain");
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
|
|
|
|
2015-03-21 23:47:22 +08:00
|
|
|
if(data->set.ssl.certinfo && chainp) {
|
2015-03-21 02:03:53 +08:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
result = Curl_ssl_init_certinfo(data, cert_list_size);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
for(i = 0; i < cert_list_size; i++) {
|
|
|
|
const char *beg = (const char *) chainp[i].data;
|
|
|
|
const char *end = beg + chainp[i].size;
|
|
|
|
|
2021-01-09 00:58:15 +08:00
|
|
|
result = Curl_extract_certinfo(data, i, beg, end);
|
2015-03-21 02:03:53 +08:00
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->verifypeer) {
|
2008-02-16 06:37:00 +08:00
|
|
|
/* This function will try to verify the peer's certificate and return its
|
|
|
|
status (trusted, invalid etc.). The value of status should be one or
|
|
|
|
more of the gnutls_certificate_status_t enumerated elements bitwise
|
|
|
|
or'd. To avoid denial of service attacks some default upper limits
|
|
|
|
regarding the certificate key size and chain size are set. To override
|
|
|
|
them use gnutls_certificate_set_verify_limits(). */
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2008-02-16 06:37:00 +08:00
|
|
|
rc = gnutls_certificate_verify_peers2(session, &verify_status);
|
|
|
|
if(rc < 0) {
|
|
|
|
failf(data, "server cert verify failed: %d", rc);
|
2020-04-24 03:36:35 +08:00
|
|
|
*certverifyresult = rc;
|
2008-02-16 06:37:00 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2020-04-24 03:36:35 +08:00
|
|
|
*certverifyresult = verify_status;
|
|
|
|
|
2008-02-16 06:37:00 +08:00
|
|
|
/* verify_status is a bitmask of gnutls_certificate_status bits */
|
|
|
|
if(verify_status & GNUTLS_CERT_INVALID) {
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->verifypeer) {
|
2008-06-07 04:52:32 +08:00
|
|
|
failf(data, "server certificate verification failed. CAfile: %s "
|
2022-11-30 21:42:37 +08:00
|
|
|
"CRLfile: %s", config->CAfile ? config->CAfile:
|
2016-11-17 01:49:15 +08:00
|
|
|
"none",
|
2022-11-22 16:55:41 +08:00
|
|
|
ssl_config->primary.CRLfile ?
|
|
|
|
ssl_config->primary.CRLfile : "none");
|
2018-11-20 09:48:59 +08:00
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
2008-02-16 06:37:00 +08:00
|
|
|
}
|
|
|
|
else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " server certificate verification FAILED");
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
|
|
|
else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " server certificate verification OK");
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
2013-11-30 05:46:05 +08:00
|
|
|
else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " server certificate verification SKIPPED");
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->verifystatus) {
|
2014-06-16 19:21:02 +08:00
|
|
|
if(gnutls_ocsp_status_request_is_checked(session, 0) == 0) {
|
2015-05-04 16:41:25 +08:00
|
|
|
gnutls_datum_t status_request;
|
|
|
|
gnutls_ocsp_resp_t ocsp_resp;
|
|
|
|
|
|
|
|
gnutls_ocsp_cert_status_t status;
|
|
|
|
gnutls_x509_crl_reason_t reason;
|
|
|
|
|
|
|
|
rc = gnutls_ocsp_status_request_get(session, &status_request);
|
|
|
|
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " server certificate status verification FAILED");
|
2015-05-04 16:41:25 +08:00
|
|
|
|
|
|
|
if(rc == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) {
|
|
|
|
failf(data, "No OCSP response received");
|
|
|
|
return CURLE_SSL_INVALIDCERTSTATUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rc < 0) {
|
|
|
|
failf(data, "Invalid OCSP response received");
|
|
|
|
return CURLE_SSL_INVALIDCERTSTATUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
gnutls_ocsp_resp_init(&ocsp_resp);
|
|
|
|
|
|
|
|
rc = gnutls_ocsp_resp_import(ocsp_resp, &status_request);
|
|
|
|
if(rc < 0) {
|
|
|
|
failf(data, "Invalid OCSP response received");
|
|
|
|
return CURLE_SSL_INVALIDCERTSTATUS;
|
|
|
|
}
|
|
|
|
|
2018-10-23 06:31:16 +08:00
|
|
|
(void)gnutls_ocsp_resp_get_single(ocsp_resp, 0, NULL, NULL, NULL, NULL,
|
|
|
|
&status, NULL, NULL, NULL, &reason);
|
2015-05-04 16:41:25 +08:00
|
|
|
|
|
|
|
switch(status) {
|
|
|
|
case GNUTLS_OCSP_CERT_GOOD:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GNUTLS_OCSP_CERT_REVOKED: {
|
|
|
|
const char *crl_reason;
|
|
|
|
|
|
|
|
switch(reason) {
|
|
|
|
default:
|
|
|
|
case GNUTLS_X509_CRLREASON_UNSPECIFIED:
|
|
|
|
crl_reason = "unspecified reason";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GNUTLS_X509_CRLREASON_KEYCOMPROMISE:
|
|
|
|
crl_reason = "private key compromised";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GNUTLS_X509_CRLREASON_CACOMPROMISE:
|
|
|
|
crl_reason = "CA compromised";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GNUTLS_X509_CRLREASON_AFFILIATIONCHANGED:
|
|
|
|
crl_reason = "affiliation has changed";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GNUTLS_X509_CRLREASON_SUPERSEDED:
|
|
|
|
crl_reason = "certificate superseded";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GNUTLS_X509_CRLREASON_CESSATIONOFOPERATION:
|
|
|
|
crl_reason = "operation has ceased";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GNUTLS_X509_CRLREASON_CERTIFICATEHOLD:
|
|
|
|
crl_reason = "certificate is on hold";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GNUTLS_X509_CRLREASON_REMOVEFROMCRL:
|
|
|
|
crl_reason = "will be removed from delta CRL";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GNUTLS_X509_CRLREASON_PRIVILEGEWITHDRAWN:
|
|
|
|
crl_reason = "privilege withdrawn";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GNUTLS_X509_CRLREASON_AACOMPROMISE:
|
|
|
|
crl_reason = "AA compromised";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
failf(data, "Server certificate was revoked: %s", crl_reason);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
case GNUTLS_OCSP_CERT_UNKNOWN:
|
|
|
|
failf(data, "Server certificate status is unknown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gnutls_ocsp_resp_deinit(ocsp_resp);
|
2014-06-16 19:21:02 +08:00
|
|
|
|
|
|
|
return CURLE_SSL_INVALIDCERTSTATUS;
|
|
|
|
}
|
|
|
|
else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " server certificate status verification OK");
|
2014-06-16 19:21:02 +08:00
|
|
|
}
|
|
|
|
else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " server certificate status verification SKIPPED");
|
2014-06-16 19:21:02 +08:00
|
|
|
|
2005-04-07 23:27:13 +08:00
|
|
|
/* initialize an X.509 certificate structure. */
|
|
|
|
gnutls_x509_crt_init(&x509_cert);
|
|
|
|
|
2014-04-23 05:24:31 +08:00
|
|
|
if(chainp)
|
|
|
|
/* convert the given DER or PEM encoded Certificate to the native
|
|
|
|
gnutls_x509_crt_t format */
|
|
|
|
gnutls_x509_crt_import(x509_cert, chainp, GNUTLS_X509_FMT_DER);
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->issuercert) {
|
2008-06-07 04:52:32 +08:00
|
|
|
gnutls_x509_crt_init(&x509_issuer);
|
2022-11-30 21:42:37 +08:00
|
|
|
issuerp = load_file(config->issuercert);
|
2008-06-07 04:52:32 +08:00
|
|
|
gnutls_x509_crt_import(x509_issuer, &issuerp, GNUTLS_X509_FMT_PEM);
|
2015-03-17 20:41:49 +08:00
|
|
|
rc = gnutls_x509_crt_check_issuer(x509_cert, x509_issuer);
|
2014-10-14 00:34:51 +08:00
|
|
|
gnutls_x509_crt_deinit(x509_issuer);
|
2008-06-07 04:52:32 +08:00
|
|
|
unload_file(issuerp);
|
2011-04-20 21:17:42 +08:00
|
|
|
if(rc <= 0) {
|
2008-06-07 04:52:32 +08:00
|
|
|
failf(data, "server certificate issuer check failed (IssuerCert: %s)",
|
2022-11-30 21:42:37 +08:00
|
|
|
config->issuercert?config->issuercert:"none");
|
2014-10-14 00:34:51 +08:00
|
|
|
gnutls_x509_crt_deinit(x509_cert);
|
2008-06-07 04:52:32 +08:00
|
|
|
return CURLE_SSL_ISSUER_ERROR;
|
|
|
|
}
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " server certificate issuer check OK (Issuer Cert: %s)",
|
2022-11-30 21:42:37 +08:00
|
|
|
config->issuercert?config->issuercert:"none");
|
2008-06-07 04:52:32 +08:00
|
|
|
}
|
|
|
|
|
2020-04-20 18:11:54 +08:00
|
|
|
size = sizeof(certname);
|
2005-04-07 23:27:13 +08:00
|
|
|
rc = gnutls_x509_crt_get_dn_by_oid(x509_cert, GNUTLS_OID_X520_COMMON_NAME,
|
|
|
|
0, /* the first and only one */
|
2005-04-23 04:56:26 +08:00
|
|
|
FALSE,
|
2020-04-20 18:11:54 +08:00
|
|
|
certname,
|
2005-04-07 23:27:13 +08:00
|
|
|
&size);
|
2005-04-23 04:56:26 +08:00
|
|
|
if(rc) {
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "error fetching CN from cert:%s",
|
2005-04-23 04:56:26 +08:00
|
|
|
gnutls_strerror(rc));
|
|
|
|
}
|
2005-04-07 23:27:13 +08:00
|
|
|
|
|
|
|
/* This function will check if the given certificate's subject matches the
|
|
|
|
given hostname. This is a basic implementation of the matching described
|
|
|
|
in RFC2818 (HTTPS), which takes into account wildcards, and the subject
|
|
|
|
alternative name PKIX extension. Returns non zero on success, and zero on
|
|
|
|
failure. */
|
2023-11-17 22:26:08 +08:00
|
|
|
rc = gnutls_x509_crt_check_hostname(x509_cert, peer->hostname);
|
2014-07-15 02:04:55 +08:00
|
|
|
#if GNUTLS_VERSION_NUMBER < 0x030306
|
|
|
|
/* Before 3.3.6, gnutls_x509_crt_check_hostname() didn't check IP
|
|
|
|
addresses. */
|
|
|
|
if(!rc) {
|
|
|
|
#ifdef ENABLE_IPV6
|
|
|
|
#define use_addr in6_addr
|
|
|
|
#else
|
|
|
|
#define use_addr in_addr
|
|
|
|
#endif
|
|
|
|
unsigned char addrbuf[sizeof(struct use_addr)];
|
2019-05-12 03:42:48 +08:00
|
|
|
size_t addrlen = 0;
|
2014-07-15 02:04:55 +08:00
|
|
|
|
2023-11-17 22:26:08 +08:00
|
|
|
if(Curl_inet_pton(AF_INET, peer->hostname, addrbuf) > 0)
|
2014-07-15 02:04:55 +08:00
|
|
|
addrlen = 4;
|
|
|
|
#ifdef ENABLE_IPV6
|
2023-11-17 22:26:08 +08:00
|
|
|
else if(Curl_inet_pton(AF_INET6, peer->hostname, addrbuf) > 0)
|
2014-07-15 02:04:55 +08:00
|
|
|
addrlen = 16;
|
|
|
|
#endif
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2014-07-15 02:04:55 +08:00
|
|
|
if(addrlen) {
|
2019-05-12 03:42:48 +08:00
|
|
|
unsigned char certaddr[sizeof(struct use_addr)];
|
|
|
|
int i;
|
|
|
|
|
2017-09-10 05:09:06 +08:00
|
|
|
for(i = 0; ; i++) {
|
2019-05-12 03:42:48 +08:00
|
|
|
size_t certaddrlen = sizeof(certaddr);
|
|
|
|
int ret = gnutls_x509_crt_get_subject_alt_name(x509_cert, i, certaddr,
|
|
|
|
&certaddrlen, NULL);
|
2014-07-15 02:04:55 +08:00
|
|
|
/* If this happens, it wasn't an IP address. */
|
|
|
|
if(ret == GNUTLS_E_SHORT_MEMORY_BUFFER)
|
|
|
|
continue;
|
|
|
|
if(ret < 0)
|
|
|
|
break;
|
|
|
|
if(ret != GNUTLS_SAN_IPADDRESS)
|
|
|
|
continue;
|
|
|
|
if(certaddrlen == addrlen && !memcmp(addrbuf, certaddr, addrlen)) {
|
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2005-04-07 23:27:13 +08:00
|
|
|
if(!rc) {
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->verifyhost) {
|
2005-04-07 23:27:13 +08:00
|
|
|
failf(data, "SSL: certificate subject name (%s) does not match "
|
2023-11-17 22:26:08 +08:00
|
|
|
"target host name '%s'", certname, peer->dispname);
|
2005-04-07 23:27:13 +08:00
|
|
|
gnutls_x509_crt_deinit(x509_cert);
|
2007-10-03 16:07:50 +08:00
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
|
|
|
else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " common name: %s (does not match '%s')",
|
2023-11-17 22:26:08 +08:00
|
|
|
certname, peer->dispname);
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
|
|
|
else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " common name: %s (matched)", certname);
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2007-07-11 05:36:30 +08:00
|
|
|
/* Check for time-based validity */
|
2008-02-16 21:41:55 +08:00
|
|
|
certclock = gnutls_x509_crt_get_expiration_time(x509_cert);
|
2007-07-11 05:36:30 +08:00
|
|
|
|
2008-02-16 21:41:55 +08:00
|
|
|
if(certclock == (time_t)-1) {
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->verifypeer) {
|
2014-07-12 05:21:31 +08:00
|
|
|
failf(data, "server cert expiration date verify failed");
|
2020-04-24 03:36:35 +08:00
|
|
|
*certverifyresult = GNUTLS_CERT_EXPIRED;
|
2014-10-14 00:34:51 +08:00
|
|
|
gnutls_x509_crt_deinit(x509_cert);
|
2014-07-12 05:21:31 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
2007-07-11 05:36:30 +08:00
|
|
|
}
|
|
|
|
else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " server certificate expiration date verify FAILED");
|
2014-07-12 05:21:31 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(certclock < time(NULL)) {
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->verifypeer) {
|
2014-07-12 05:21:31 +08:00
|
|
|
failf(data, "server certificate expiration date has passed.");
|
2020-04-24 03:36:35 +08:00
|
|
|
*certverifyresult = GNUTLS_CERT_EXPIRED;
|
2014-10-14 00:34:51 +08:00
|
|
|
gnutls_x509_crt_deinit(x509_cert);
|
2014-07-12 05:21:31 +08:00
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
|
|
|
}
|
|
|
|
else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " server certificate expiration date FAILED");
|
2014-07-12 05:21:31 +08:00
|
|
|
}
|
|
|
|
else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " server certificate expiration date OK");
|
2007-07-11 05:36:30 +08:00
|
|
|
}
|
|
|
|
|
2008-02-16 21:41:55 +08:00
|
|
|
certclock = gnutls_x509_crt_get_activation_time(x509_cert);
|
2007-07-11 05:36:30 +08:00
|
|
|
|
2008-02-16 21:41:55 +08:00
|
|
|
if(certclock == (time_t)-1) {
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->verifypeer) {
|
2014-07-12 05:21:31 +08:00
|
|
|
failf(data, "server cert activation date verify failed");
|
2020-04-24 03:36:35 +08:00
|
|
|
*certverifyresult = GNUTLS_CERT_NOT_ACTIVATED;
|
2014-10-14 00:34:51 +08:00
|
|
|
gnutls_x509_crt_deinit(x509_cert);
|
2014-07-12 05:21:31 +08:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
2007-07-11 05:36:30 +08:00
|
|
|
}
|
|
|
|
else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " server certificate activation date verify FAILED");
|
2014-07-12 05:21:31 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(certclock > time(NULL)) {
|
2022-11-30 21:42:37 +08:00
|
|
|
if(config->verifypeer) {
|
2014-07-12 05:21:31 +08:00
|
|
|
failf(data, "server certificate not activated yet.");
|
2020-04-24 03:36:35 +08:00
|
|
|
*certverifyresult = GNUTLS_CERT_NOT_ACTIVATED;
|
2014-10-14 00:34:51 +08:00
|
|
|
gnutls_x509_crt_deinit(x509_cert);
|
2014-07-12 05:21:31 +08:00
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
|
|
|
}
|
|
|
|
else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " server certificate activation date FAILED");
|
2014-07-12 05:21:31 +08:00
|
|
|
}
|
|
|
|
else
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " server certificate activation date OK");
|
2007-07-11 05:36:30 +08:00
|
|
|
}
|
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
if(pinned_key) {
|
|
|
|
result = pkp_pin_peer_pubkey(data, x509_cert, pinned_key);
|
2014-10-14 00:34:51 +08:00
|
|
|
if(result != CURLE_OK) {
|
2022-04-16 17:55:05 +08:00
|
|
|
failf(data, "SSL: public key does not match pinned public key");
|
2014-10-14 00:34:51 +08:00
|
|
|
gnutls_x509_crt_deinit(x509_cert);
|
|
|
|
return result;
|
|
|
|
}
|
2014-10-01 14:14:49 +08:00
|
|
|
}
|
|
|
|
|
2005-04-07 23:27:13 +08:00
|
|
|
/* Show:
|
|
|
|
|
|
|
|
- subject
|
|
|
|
- start date
|
|
|
|
- expire date
|
|
|
|
- common name
|
|
|
|
- issuer
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-04-22 18:07:13 +08:00
|
|
|
#ifndef CURL_DISABLE_VERBOSE_STRINGS
|
2005-04-07 23:27:13 +08:00
|
|
|
/* public key algorithm's parameters */
|
|
|
|
algo = gnutls_x509_crt_get_pk_algorithm(x509_cert, &bits);
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " certificate public key: %s",
|
2005-04-07 23:27:13 +08:00
|
|
|
gnutls_pk_algorithm_get_name(algo));
|
|
|
|
|
|
|
|
/* version of the X.509 certificate. */
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " certificate version: #%d",
|
2005-04-07 23:27:13 +08:00
|
|
|
gnutls_x509_crt_get_version(x509_cert));
|
|
|
|
|
|
|
|
|
2020-04-20 18:11:54 +08:00
|
|
|
rc = gnutls_x509_crt_get_dn2(x509_cert, &certfields);
|
2020-08-05 16:54:39 +08:00
|
|
|
if(rc)
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "Failed to get certificate name");
|
2020-08-05 16:54:39 +08:00
|
|
|
else {
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " subject: %s", certfields.data);
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2020-08-05 16:54:39 +08:00
|
|
|
certclock = gnutls_x509_crt_get_activation_time(x509_cert);
|
|
|
|
showtime(data, "start date", certclock);
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2020-08-05 16:54:39 +08:00
|
|
|
certclock = gnutls_x509_crt_get_expiration_time(x509_cert);
|
|
|
|
showtime(data, "expire date", certclock);
|
2020-11-02 05:32:15 +08:00
|
|
|
|
|
|
|
gnutls_free(certfields.data);
|
2020-08-05 16:54:39 +08:00
|
|
|
}
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2020-04-20 18:11:54 +08:00
|
|
|
rc = gnutls_x509_crt_get_issuer_dn2(x509_cert, &certfields);
|
2020-08-05 16:54:39 +08:00
|
|
|
if(rc)
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "Failed to get certificate issuer");
|
2020-11-02 05:32:15 +08:00
|
|
|
else {
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, " issuer: %s", certfields.data);
|
2020-11-02 05:32:15 +08:00
|
|
|
|
|
|
|
gnutls_free(certfields.data);
|
|
|
|
}
|
2017-04-22 18:07:13 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
gnutls_x509_crt_deinit(x509_cert);
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode gtls_verifyserver(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
|
|
|
gnutls_session_t session)
|
|
|
|
{
|
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
|
|
|
struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf);
|
|
|
|
struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data);
|
2024-03-26 07:19:23 +08:00
|
|
|
#ifndef CURL_DISABLE_PROXY
|
2022-11-30 21:42:37 +08:00
|
|
|
const char *pinned_key = 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 *pinned_key = data->set.str[STRING_SSL_PINNEDPUBLICKEY];
|
|
|
|
#endif
|
2022-11-30 21:42:37 +08:00
|
|
|
CURLcode result;
|
|
|
|
|
|
|
|
result = Curl_gtls_verifyserver(data, session, conn_config, ssl_config,
|
2023-11-17 22:26:08 +08:00
|
|
|
&connssl->peer, pinned_key);
|
2022-11-30 21:42:37 +08:00
|
|
|
if(result)
|
|
|
|
goto out;
|
|
|
|
|
2023-04-06 15:54:57 +08:00
|
|
|
if(connssl->alpn) {
|
2022-11-30 21:42:37 +08:00
|
|
|
gnutls_datum_t proto;
|
|
|
|
int rc;
|
|
|
|
|
2014-02-11 14:18:11 +08:00
|
|
|
rc = gnutls_alpn_get_selected_protocol(session, &proto);
|
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(rc == 0)
|
|
|
|
Curl_alpn_set_negotiated(cf, data, proto.data, proto.size);
|
2015-02-19 23:22:07 +08:00
|
|
|
else
|
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);
|
2014-02-04 16:10:37 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
if(ssl_config->primary.sessionid) {
|
2009-05-05 06:20:09 +08:00
|
|
|
/* we always unconditionally get the session id here, as even if we
|
|
|
|
already got it from the cache and asked to use it in the connection, it
|
|
|
|
might've been rejected and then a new one is in use now and we need to
|
|
|
|
detect that. */
|
|
|
|
void *connect_sessionid;
|
2014-07-12 07:31:12 +08:00
|
|
|
size_t connect_idsize = 0;
|
2005-04-07 23:27:13 +08:00
|
|
|
|
|
|
|
/* get the session ID data size */
|
2009-05-05 06:20:09 +08:00
|
|
|
gnutls_session_get_data(session, NULL, &connect_idsize);
|
|
|
|
connect_sessionid = malloc(connect_idsize); /* get a buffer for it */
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2009-05-05 06:20:09 +08:00
|
|
|
if(connect_sessionid) {
|
2019-05-12 03:42:48 +08:00
|
|
|
bool incache;
|
2021-09-22 18:04:25 +08:00
|
|
|
bool added = FALSE;
|
2019-05-12 03:42:48 +08:00
|
|
|
void *ssl_sessionid;
|
|
|
|
|
2005-04-07 23:27:13 +08:00
|
|
|
/* extract session ID to the allocated buffer */
|
2009-05-05 06:20:09 +08:00
|
|
|
gnutls_session_get_data(session, connect_sessionid, &connect_idsize);
|
|
|
|
|
2021-01-14 00:01:31 +08:00
|
|
|
Curl_ssl_sessionid_lock(data);
|
2024-03-22 20:07:25 +08:00
|
|
|
incache = !(Curl_ssl_getsessionid(cf, data, &connssl->peer,
|
|
|
|
&ssl_sessionid, NULL));
|
2011-04-20 21:17:42 +08:00
|
|
|
if(incache) {
|
2009-05-05 16:33:29 +08:00
|
|
|
/* there was one before in the cache, so instead of risking that the
|
|
|
|
previous one was rejected, we just kill that and store the new */
|
2021-01-14 00:01:31 +08:00
|
|
|
Curl_ssl_delsessionid(data, ssl_sessionid);
|
2010-04-17 04:43:01 +08:00
|
|
|
}
|
2005-04-07 23:27:13 +08:00
|
|
|
|
|
|
|
/* store this session id */
|
2024-03-22 20:07:25 +08:00
|
|
|
result = Curl_ssl_addsessionid(cf, data, &connssl->peer,
|
|
|
|
connect_sessionid, connect_idsize,
|
|
|
|
&added);
|
2021-01-14 00:01:31 +08:00
|
|
|
Curl_ssl_sessionid_unlock(data);
|
2021-09-22 18:04:25 +08:00
|
|
|
if(!added)
|
2011-01-06 07:47:37 +08:00
|
|
|
free(connect_sessionid);
|
2021-09-22 18:04:25 +08:00
|
|
|
if(result) {
|
2011-01-06 07:47:37 +08:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
2011-01-06 07:47:37 +08:00
|
|
|
else
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2010-04-17 04:43:01 +08:00
|
|
|
}
|
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
out:
|
2011-01-06 07:47:37 +08:00
|
|
|
return result;
|
2010-04-17 04:43:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is called after the TCP connect has completed. Setup the TLS
|
|
|
|
* layer and do all necessary magic.
|
|
|
|
*/
|
|
|
|
/* We use connssl->connecting_state to keep track of the connection status;
|
|
|
|
there are three states: 'ssl_connect_1' (not started yet or complete),
|
|
|
|
'ssl_connect_2_reading' (waiting for data from server), and
|
|
|
|
'ssl_connect_2_writing' (waiting to be able to write).
|
|
|
|
*/
|
|
|
|
static CURLcode
|
2022-11-22 16:55:41 +08:00
|
|
|
gtls_connect_common(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
2010-04-17 04:43:01 +08:00
|
|
|
bool nonblocking,
|
|
|
|
bool *done)
|
|
|
|
{
|
2022-11-22 16:55:41 +08:00
|
|
|
struct ssl_connect_data *connssl = cf->ctx;
|
2022-11-25 21:06:43 +08:00
|
|
|
int rc;
|
|
|
|
CURLcode result = CURLE_OK;
|
2010-04-17 04:43:01 +08:00
|
|
|
|
|
|
|
/* Initiate the connection, if not already done */
|
2017-09-10 05:09:06 +08:00
|
|
|
if(ssl_connect_1 == connssl->connecting_state) {
|
2022-11-22 16:55:41 +08:00
|
|
|
rc = gtls_connect_step1(cf, data);
|
2022-11-25 21:06:43 +08:00
|
|
|
if(rc) {
|
|
|
|
result = rc;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
rc = handshake(cf, data, TRUE, nonblocking);
|
2022-11-25 21:06:43 +08:00
|
|
|
if(rc) {
|
2010-04-17 04:43:01 +08:00
|
|
|
/* handshake() sets its own error message with failf() */
|
2022-11-25 21:06:43 +08:00
|
|
|
result = rc;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-04-17 04:43:01 +08:00
|
|
|
|
|
|
|
/* Finish connecting once the handshake is done */
|
2017-09-10 05:09:06 +08:00
|
|
|
if(ssl_connect_1 == connssl->connecting_state) {
|
2023-05-09 18:10:40 +08:00
|
|
|
struct gtls_ssl_backend_data *backend =
|
|
|
|
(struct gtls_ssl_backend_data *)connssl->backend;
|
2022-02-18 00:48:48 +08:00
|
|
|
gnutls_session_t session;
|
|
|
|
DEBUGASSERT(backend);
|
2022-11-30 21:42:37 +08:00
|
|
|
session = backend->gtls.session;
|
|
|
|
rc = gtls_verifyserver(cf, data, session);
|
2022-11-25 21:06:43 +08:00
|
|
|
if(rc) {
|
|
|
|
result = rc;
|
|
|
|
goto out;
|
|
|
|
}
|
2022-11-30 21:42:37 +08:00
|
|
|
connssl->state = ssl_connection_complete;
|
2010-04-17 04:43:01 +08:00
|
|
|
}
|
|
|
|
|
2022-11-25 21:06:43 +08:00
|
|
|
out:
|
2017-09-10 05:09:06 +08:00
|
|
|
*done = ssl_connect_1 == connssl->connecting_state;
|
2010-04-17 04:43:01 +08:00
|
|
|
|
2022-11-25 21:06:43 +08:00
|
|
|
return result;
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
static CURLcode gtls_connect_nonblocking(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
|
|
|
bool *done)
|
2010-04-17 04:43:01 +08:00
|
|
|
{
|
2022-11-22 16:55:41 +08:00
|
|
|
return gtls_connect_common(cf, data, TRUE, done);
|
2010-04-17 04:43:01 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
static CURLcode gtls_connect(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data)
|
2010-04-17 04:43:01 +08:00
|
|
|
{
|
2014-12-25 01:26:21 +08:00
|
|
|
CURLcode result;
|
2010-04-17 04:43:01 +08:00
|
|
|
bool done = FALSE;
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
result = gtls_connect_common(cf, data, FALSE, &done);
|
2014-12-25 01:26:21 +08:00
|
|
|
if(result)
|
|
|
|
return result;
|
2010-04-17 04:43:01 +08:00
|
|
|
|
|
|
|
DEBUGASSERT(done);
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
static bool gtls_data_pending(struct Curl_cfilter *cf,
|
|
|
|
const struct Curl_easy *data)
|
2016-11-17 01:49:15 +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 gtls_ssl_backend_data *backend;
|
2022-02-18 00:48:48 +08:00
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
(void)data;
|
|
|
|
DEBUGASSERT(ctx && ctx->backend);
|
2023-05-09 18:10:40 +08:00
|
|
|
backend = (struct gtls_ssl_backend_data *)ctx->backend;
|
|
|
|
if(backend->gtls.session &&
|
|
|
|
0 != gnutls_record_check_pending(backend->gtls.session))
|
2022-11-22 16:55:41 +08:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
2016-11-17 01:49:15 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
static ssize_t gtls_send(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
2010-05-07 21:05:34 +08:00
|
|
|
const void *mem,
|
|
|
|
size_t len,
|
|
|
|
CURLcode *curlcode)
|
2005-04-07 23:27:13 +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 gtls_ssl_backend_data *backend =
|
|
|
|
(struct gtls_ssl_backend_data *)connssl->backend;
|
2022-02-18 00:48:48 +08:00
|
|
|
ssize_t rc;
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
(void)data;
|
2022-02-18 00:48:48 +08:00
|
|
|
DEBUGASSERT(backend);
|
2022-11-30 21:42:37 +08:00
|
|
|
rc = gnutls_record_send(backend->gtls.session, mem, len);
|
2005-04-07 23:27:13 +08:00
|
|
|
|
2016-04-04 02:28:34 +08:00
|
|
|
if(rc < 0) {
|
2010-04-05 05:37:18 +08:00
|
|
|
*curlcode = (rc == GNUTLS_E_AGAIN)
|
2010-05-07 21:05:34 +08:00
|
|
|
? CURLE_AGAIN
|
2010-04-05 05:37:18 +08:00
|
|
|
: CURLE_SEND_ERROR;
|
|
|
|
|
|
|
|
rc = -1;
|
2006-05-04 14:00:40 +08:00
|
|
|
}
|
|
|
|
|
2005-04-07 23:27:13 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
static void gtls_close(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data)
|
2005-04-07 23:27:13 +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 gtls_ssl_backend_data *backend =
|
|
|
|
(struct gtls_ssl_backend_data *)connssl->backend;
|
2022-11-22 16:55:41 +08:00
|
|
|
|
|
|
|
(void) data;
|
2022-02-18 00:48:48 +08:00
|
|
|
DEBUGASSERT(backend);
|
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
if(backend->gtls.session) {
|
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. */
|
2022-11-30 21:42:37 +08:00
|
|
|
(void)gnutls_record_recv(backend->gtls.session, buf, sizeof(buf));
|
|
|
|
gnutls_bye(backend->gtls.session, GNUTLS_SHUT_WR);
|
|
|
|
gnutls_deinit(backend->gtls.session);
|
|
|
|
backend->gtls.session = NULL;
|
2005-04-08 06:47:43 +08:00
|
|
|
}
|
2022-11-30 21:42:37 +08:00
|
|
|
if(backend->gtls.cred) {
|
|
|
|
gnutls_certificate_free_credentials(backend->gtls.cred);
|
|
|
|
backend->gtls.cred = NULL;
|
2007-07-29 20:54:05 +08:00
|
|
|
}
|
2022-03-18 03:31:10 +08:00
|
|
|
#ifdef USE_GNUTLS_SRP
|
2022-11-30 21:42:37 +08:00
|
|
|
if(backend->gtls.srp_client_cred) {
|
|
|
|
gnutls_srp_free_client_credentials(backend->gtls.srp_client_cred);
|
|
|
|
backend->gtls.srp_client_cred = NULL;
|
2011-01-20 03:35:02 +08:00
|
|
|
}
|
|
|
|
#endif
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
|
|
|
|
2007-01-06 07:11:14 +08:00
|
|
|
/*
|
|
|
|
* 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 gtls_shutdown(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data)
|
2007-01-06 07:11:14 +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 gtls_ssl_backend_data *backend =
|
|
|
|
(struct gtls_ssl_backend_data *)connssl->backend;
|
2007-01-06 07:11:14 +08:00
|
|
|
int retval = 0;
|
|
|
|
|
2022-02-18 00:48:48 +08:00
|
|
|
DEBUGASSERT(backend);
|
|
|
|
|
2019-05-21 15:38:11 +08:00
|
|
|
#ifndef CURL_DISABLE_FTP
|
2007-01-06 07:11:14 +08:00
|
|
|
/* This has only been tested on the proftpd server, and the mod_tls code
|
|
|
|
sends a close notify alert without waiting for a close notify alert in
|
|
|
|
response. Thus we wait for a close notify alert from the server, but
|
|
|
|
we do not send one. Let's hope other servers do the same... */
|
|
|
|
|
2007-02-21 06:02:11 +08:00
|
|
|
if(data->set.ftp_ccc == CURLFTPSSL_CCC_ACTIVE)
|
2022-11-30 21:42:37 +08:00
|
|
|
gnutls_bye(backend->gtls.session, GNUTLS_SHUT_WR);
|
2019-05-21 15:38:11 +08:00
|
|
|
#endif
|
2007-02-21 06:02:11 +08:00
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
if(backend->gtls.session) {
|
2019-05-12 03:42:48 +08:00
|
|
|
ssize_t result;
|
|
|
|
bool done = FALSE;
|
|
|
|
char buf[120];
|
|
|
|
|
2024-03-08 16:37:27 +08:00
|
|
|
while(!done && !connssl->peer_closed) {
|
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
|
|
|
int what = SOCKET_READABLE(Curl_conn_cf_get_socket(cf, data),
|
2016-10-18 16:58:58 +08:00
|
|
|
SSL_SHUTDOWN_TIMEOUT);
|
2007-01-06 07:11:14 +08:00
|
|
|
if(what > 0) {
|
|
|
|
/* Something to read, let's do it and hope that it is the close
|
|
|
|
notify alert from the server */
|
2022-11-30 21:42:37 +08:00
|
|
|
result = gnutls_record_recv(backend->gtls.session,
|
2007-01-06 07:11:14 +08:00
|
|
|
buf, sizeof(buf));
|
|
|
|
switch(result) {
|
|
|
|
case 0:
|
|
|
|
/* This is the expected response. There was no data but only
|
|
|
|
the close notify alert */
|
2018-10-23 06:31:16 +08:00
|
|
|
done = TRUE;
|
2007-01-06 07:11:14 +08:00
|
|
|
break;
|
|
|
|
case GNUTLS_E_AGAIN:
|
|
|
|
case GNUTLS_E_INTERRUPTED:
|
2021-07-06 23:05:17 +08:00
|
|
|
infof(data, "GNUTLS_E_AGAIN || GNUTLS_E_INTERRUPTED");
|
2007-01-06 07:11:14 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
retval = -1;
|
2018-10-23 06:31:16 +08:00
|
|
|
done = TRUE;
|
2007-01-06 07:11:14 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(0 == what) {
|
|
|
|
/* timeout */
|
|
|
|
failf(data, "SSL shutdown timeout");
|
2018-10-23 06:31:16 +08:00
|
|
|
done = TRUE;
|
2007-01-06 07:11:14 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* anything that gets here is fatally bad */
|
2007-03-28 02:16:35 +08:00
|
|
|
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
2007-01-06 07:11:14 +08:00
|
|
|
retval = -1;
|
2018-10-23 06:31:16 +08:00
|
|
|
done = TRUE;
|
2007-01-06 07:11:14 +08:00
|
|
|
}
|
|
|
|
}
|
2022-11-30 21:42:37 +08:00
|
|
|
gnutls_deinit(backend->gtls.session);
|
2007-01-06 07:11:14 +08:00
|
|
|
}
|
2022-11-30 21:42:37 +08:00
|
|
|
gnutls_certificate_free_credentials(backend->gtls.cred);
|
2007-01-06 07:11:14 +08:00
|
|
|
|
2022-03-18 03:31:10 +08:00
|
|
|
#ifdef USE_GNUTLS_SRP
|
2023-09-27 21:40:54 +08:00
|
|
|
{
|
|
|
|
struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data);
|
|
|
|
if(ssl_config->primary.username)
|
|
|
|
gnutls_srp_free_client_credentials(backend->gtls.srp_client_cred);
|
|
|
|
}
|
2011-01-20 03:35:02 +08:00
|
|
|
#endif
|
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
backend->gtls.cred = NULL;
|
|
|
|
backend->gtls.session = NULL;
|
2007-01-06 07:11:14 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
static ssize_t gtls_recv(struct Curl_cfilter *cf,
|
|
|
|
struct Curl_easy *data,
|
|
|
|
char *buf,
|
|
|
|
size_t buffersize,
|
2010-05-07 21:05:34 +08:00
|
|
|
CURLcode *curlcode)
|
2005-04-07 23:27:13 +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 gtls_ssl_backend_data *backend =
|
|
|
|
(struct gtls_ssl_backend_data *)connssl->backend;
|
2005-04-07 23:27:13 +08:00
|
|
|
ssize_t ret;
|
|
|
|
|
2022-11-22 16:55:41 +08:00
|
|
|
(void)data;
|
2022-02-18 00:48:48 +08:00
|
|
|
DEBUGASSERT(backend);
|
|
|
|
|
2022-11-30 21:42:37 +08:00
|
|
|
ret = gnutls_record_recv(backend->gtls.session, buf, buffersize);
|
2005-04-07 23:27:13 +08:00
|
|
|
if((ret == GNUTLS_E_AGAIN) || (ret == GNUTLS_E_INTERRUPTED)) {
|
2010-05-07 21:05:34 +08:00
|
|
|
*curlcode = CURLE_AGAIN;
|
2022-11-25 21:06:43 +08:00
|
|
|
ret = -1;
|
|
|
|
goto out;
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
|
|
|
|
2005-10-23 05:05:07 +08:00
|
|
|
if(ret == GNUTLS_E_REHANDSHAKE) {
|
|
|
|
/* BLOCKING call, this is bad but a work-around for now. Fixing this "the
|
|
|
|
proper way" takes a whole lot of work. */
|
2022-11-22 16:55:41 +08:00
|
|
|
CURLcode result = handshake(cf, data, FALSE, FALSE);
|
2014-12-25 01:26:21 +08:00
|
|
|
if(result)
|
2005-10-23 05:05:07 +08:00
|
|
|
/* handshake() writes error message on its own */
|
2014-12-25 01:26:21 +08:00
|
|
|
*curlcode = result;
|
2010-04-05 05:37:18 +08:00
|
|
|
else
|
2010-05-07 21:05:34 +08:00
|
|
|
*curlcode = CURLE_AGAIN; /* then return as if this was a wouldblock */
|
2022-11-25 21:06:43 +08:00
|
|
|
ret = -1;
|
|
|
|
goto out;
|
2005-10-23 05:05:07 +08:00
|
|
|
}
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
if(ret < 0) {
|
2021-01-14 00:01:31 +08:00
|
|
|
failf(data, "GnuTLS recv error (%d): %s",
|
2017-06-23 19:19:00 +08:00
|
|
|
|
2009-08-30 09:36:01 +08:00
|
|
|
(int)ret, gnutls_strerror((int)ret));
|
2010-04-05 05:37:18 +08:00
|
|
|
*curlcode = CURLE_RECV_ERROR;
|
2022-11-25 21:06:43 +08:00
|
|
|
ret = -1;
|
|
|
|
goto out;
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
|
|
|
|
2022-11-25 21:06:43 +08:00
|
|
|
out:
|
2005-04-07 23:27:13 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-01-13 15:28:10 +08:00
|
|
|
static void gtls_session_free(void *ptr)
|
2005-04-07 23:27:13 +08:00
|
|
|
{
|
|
|
|
free(ptr);
|
|
|
|
}
|
|
|
|
|
2021-01-13 15:28:10 +08:00
|
|
|
static size_t gtls_version(char *buffer, size_t size)
|
2005-04-07 23:27:13 +08:00
|
|
|
{
|
2018-11-22 16:01:24 +08:00
|
|
|
return msnprintf(buffer, size, "GnuTLS/%s", gnutls_check_version(NULL));
|
2005-04-07 23:27:13 +08:00
|
|
|
}
|
|
|
|
|
2014-06-04 02:04:46 +08:00
|
|
|
/* data might be NULL! */
|
2021-01-13 15:28:10 +08:00
|
|
|
static CURLcode gtls_random(struct Curl_easy *data,
|
|
|
|
unsigned char *entropy, size_t length)
|
2012-06-26 20:52:46 +08:00
|
|
|
{
|
2016-12-23 22:01:53 +08:00
|
|
|
int rc;
|
2012-06-26 20:52:46 +08:00
|
|
|
(void)data;
|
2016-12-23 22:01:53 +08:00
|
|
|
rc = gnutls_rnd(GNUTLS_RND_RANDOM, entropy, length);
|
2017-01-13 00:41:26 +08:00
|
|
|
return rc?CURLE_FAILED_INIT:CURLE_OK;
|
2012-06-26 20:52:46 +08:00
|
|
|
}
|
|
|
|
|
2021-01-13 15:28:10 +08:00
|
|
|
static CURLcode gtls_sha256sum(const unsigned char *tmp, /* input */
|
|
|
|
size_t tmplen,
|
|
|
|
unsigned char *sha256sum, /* output */
|
|
|
|
size_t sha256len)
|
2015-07-01 08:23:54 +08:00
|
|
|
{
|
|
|
|
struct sha256_ctx SHA256pw;
|
|
|
|
sha256_init(&SHA256pw);
|
|
|
|
sha256_update(&SHA256pw, (unsigned int)tmplen, tmp);
|
|
|
|
sha256_digest(&SHA256pw, (unsigned int)sha256len, sha256sum);
|
2018-04-03 01:33:00 +08:00
|
|
|
return CURLE_OK;
|
2015-07-01 08:23:54 +08:00
|
|
|
}
|
|
|
|
|
2021-01-13 15:28:10 +08:00
|
|
|
static bool gtls_cert_status_request(void)
|
2014-06-16 19:21:02 +08:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-01-13 15:28:10 +08:00
|
|
|
static void *gtls_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 gtls_ssl_backend_data *backend =
|
|
|
|
(struct gtls_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);
|
2022-11-30 21:42:37 +08:00
|
|
|
return backend->gtls.session;
|
2017-06-23 22:05:26 +08:00
|
|
|
}
|
|
|
|
|
2017-06-22 22:45:34 +08:00
|
|
|
const struct Curl_ssl Curl_ssl_gnutls = {
|
2017-07-15 19:49:30 +08:00
|
|
|
{ CURLSSLBACKEND_GNUTLS, "gnutls" }, /* info */
|
2017-06-22 22:45:34 +08:00
|
|
|
|
2018-05-04 18:10:39 +08:00
|
|
|
SSLSUPP_CA_PATH |
|
|
|
|
SSLSUPP_CERTINFO |
|
|
|
|
SSLSUPP_PINNEDPUBKEY |
|
|
|
|
SSLSUPP_HTTPS_PROXY,
|
2017-06-20 17:32:53 +08:00
|
|
|
|
2023-05-09 18:10:40 +08:00
|
|
|
sizeof(struct gtls_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:28:10 +08:00
|
|
|
gtls_init, /* init */
|
|
|
|
gtls_cleanup, /* cleanup */
|
|
|
|
gtls_version, /* version */
|
2017-06-22 22:45:34 +08:00
|
|
|
Curl_none_check_cxn, /* check_cxn */
|
2021-01-13 15:28:10 +08:00
|
|
|
gtls_shutdown, /* shutdown */
|
|
|
|
gtls_data_pending, /* data_pending */
|
|
|
|
gtls_random, /* random */
|
|
|
|
gtls_cert_status_request, /* cert_status_request */
|
|
|
|
gtls_connect, /* connect */
|
|
|
|
gtls_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:28:10 +08:00
|
|
|
gtls_get_internals, /* get_internals */
|
|
|
|
gtls_close, /* close_one */
|
2017-06-22 22:45:34 +08:00
|
|
|
Curl_none_close_all, /* close_all */
|
2021-01-13 15:28:10 +08:00
|
|
|
gtls_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
|
|
|
gtls_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 */
|
|
|
|
gtls_recv, /* recv decrypted data */
|
|
|
|
gtls_send, /* send data to encrypt */
|
2017-06-22 22:45:34 +08:00
|
|
|
};
|
|
|
|
|
2005-04-07 23:27:13 +08:00
|
|
|
#endif /* USE_GNUTLS */
|