mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-12-02 22:17:18 +01:00
Initial preparations for CURL and Discord integration.
This commit is contained in:
883
module/Vendor/CURL/lib/vtls/bearssl.c
vendored
Normal file
883
module/Vendor/CURL/lib/vtls/bearssl.c
vendored
Normal file
@@ -0,0 +1,883 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2019 - 2021, Michael Forney, <mforney@mforney.org>
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_BEARSSL
|
||||
|
||||
#include <bearssl.h>
|
||||
|
||||
#include "bearssl.h"
|
||||
#include "urldata.h"
|
||||
#include "sendf.h"
|
||||
#include "inet_pton.h"
|
||||
#include "vtls.h"
|
||||
#include "connect.h"
|
||||
#include "select.h"
|
||||
#include "multiif.h"
|
||||
#include "curl_printf.h"
|
||||
#include "curl_memory.h"
|
||||
|
||||
struct x509_context {
|
||||
const br_x509_class *vtable;
|
||||
br_x509_minimal_context minimal;
|
||||
bool verifyhost;
|
||||
bool verifypeer;
|
||||
};
|
||||
|
||||
struct ssl_backend_data {
|
||||
br_ssl_client_context ctx;
|
||||
struct x509_context x509;
|
||||
unsigned char buf[BR_SSL_BUFSIZE_BIDI];
|
||||
br_x509_trust_anchor *anchors;
|
||||
size_t anchors_len;
|
||||
const char *protocols[2];
|
||||
/* SSL client context is active */
|
||||
bool active;
|
||||
/* size of pending write, yet to be flushed */
|
||||
size_t pending_write;
|
||||
};
|
||||
|
||||
struct cafile_parser {
|
||||
CURLcode err;
|
||||
bool in_cert;
|
||||
br_x509_decoder_context xc;
|
||||
/* array of trust anchors loaded from CAfile */
|
||||
br_x509_trust_anchor *anchors;
|
||||
size_t anchors_len;
|
||||
/* buffer for DN data */
|
||||
unsigned char dn[1024];
|
||||
size_t dn_len;
|
||||
};
|
||||
|
||||
static void append_dn(void *ctx, const void *buf, size_t len)
|
||||
{
|
||||
struct cafile_parser *ca = ctx;
|
||||
|
||||
if(ca->err != CURLE_OK || !ca->in_cert)
|
||||
return;
|
||||
if(sizeof(ca->dn) - ca->dn_len < len) {
|
||||
ca->err = CURLE_FAILED_INIT;
|
||||
return;
|
||||
}
|
||||
memcpy(ca->dn + ca->dn_len, buf, len);
|
||||
ca->dn_len += len;
|
||||
}
|
||||
|
||||
static void x509_push(void *ctx, const void *buf, size_t len)
|
||||
{
|
||||
struct cafile_parser *ca = ctx;
|
||||
|
||||
if(ca->in_cert)
|
||||
br_x509_decoder_push(&ca->xc, buf, len);
|
||||
}
|
||||
|
||||
static CURLcode load_cafile(const char *path, br_x509_trust_anchor **anchors,
|
||||
size_t *anchors_len)
|
||||
{
|
||||
struct cafile_parser ca;
|
||||
br_pem_decoder_context pc;
|
||||
br_x509_trust_anchor *ta;
|
||||
size_t ta_size;
|
||||
br_x509_trust_anchor *new_anchors;
|
||||
size_t new_anchors_len;
|
||||
br_x509_pkey *pkey;
|
||||
FILE *fp;
|
||||
unsigned char buf[BUFSIZ], *p;
|
||||
const char *name;
|
||||
size_t n, i, pushed;
|
||||
|
||||
fp = fopen(path, "rb");
|
||||
if(!fp)
|
||||
return CURLE_SSL_CACERT_BADFILE;
|
||||
|
||||
ca.err = CURLE_OK;
|
||||
ca.in_cert = FALSE;
|
||||
ca.anchors = NULL;
|
||||
ca.anchors_len = 0;
|
||||
br_pem_decoder_init(&pc);
|
||||
br_pem_decoder_setdest(&pc, x509_push, &ca);
|
||||
for(;;) {
|
||||
n = fread(buf, 1, sizeof(buf), fp);
|
||||
if(n == 0)
|
||||
break;
|
||||
p = buf;
|
||||
while(n) {
|
||||
pushed = br_pem_decoder_push(&pc, p, n);
|
||||
if(ca.err)
|
||||
goto fail;
|
||||
p += pushed;
|
||||
n -= pushed;
|
||||
|
||||
switch(br_pem_decoder_event(&pc)) {
|
||||
case 0:
|
||||
break;
|
||||
case BR_PEM_BEGIN_OBJ:
|
||||
name = br_pem_decoder_name(&pc);
|
||||
if(strcmp(name, "CERTIFICATE") && strcmp(name, "X509 CERTIFICATE"))
|
||||
break;
|
||||
br_x509_decoder_init(&ca.xc, append_dn, &ca);
|
||||
if(ca.anchors_len == SIZE_MAX / sizeof(ca.anchors[0])) {
|
||||
ca.err = CURLE_OUT_OF_MEMORY;
|
||||
goto fail;
|
||||
}
|
||||
new_anchors_len = ca.anchors_len + 1;
|
||||
new_anchors = realloc(ca.anchors,
|
||||
new_anchors_len * sizeof(ca.anchors[0]));
|
||||
if(!new_anchors) {
|
||||
ca.err = CURLE_OUT_OF_MEMORY;
|
||||
goto fail;
|
||||
}
|
||||
ca.anchors = new_anchors;
|
||||
ca.anchors_len = new_anchors_len;
|
||||
ca.in_cert = TRUE;
|
||||
ca.dn_len = 0;
|
||||
ta = &ca.anchors[ca.anchors_len - 1];
|
||||
ta->dn.data = NULL;
|
||||
break;
|
||||
case BR_PEM_END_OBJ:
|
||||
if(!ca.in_cert)
|
||||
break;
|
||||
ca.in_cert = FALSE;
|
||||
if(br_x509_decoder_last_error(&ca.xc)) {
|
||||
ca.err = CURLE_SSL_CACERT_BADFILE;
|
||||
goto fail;
|
||||
}
|
||||
ta->flags = 0;
|
||||
if(br_x509_decoder_isCA(&ca.xc))
|
||||
ta->flags |= BR_X509_TA_CA;
|
||||
pkey = br_x509_decoder_get_pkey(&ca.xc);
|
||||
if(!pkey) {
|
||||
ca.err = CURLE_SSL_CACERT_BADFILE;
|
||||
goto fail;
|
||||
}
|
||||
ta->pkey = *pkey;
|
||||
|
||||
/* calculate space needed for trust anchor data */
|
||||
ta_size = ca.dn_len;
|
||||
switch(pkey->key_type) {
|
||||
case BR_KEYTYPE_RSA:
|
||||
ta_size += pkey->key.rsa.nlen + pkey->key.rsa.elen;
|
||||
break;
|
||||
case BR_KEYTYPE_EC:
|
||||
ta_size += pkey->key.ec.qlen;
|
||||
break;
|
||||
default:
|
||||
ca.err = CURLE_FAILED_INIT;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* fill in trust anchor DN and public key data */
|
||||
ta->dn.data = malloc(ta_size);
|
||||
if(!ta->dn.data) {
|
||||
ca.err = CURLE_OUT_OF_MEMORY;
|
||||
goto fail;
|
||||
}
|
||||
memcpy(ta->dn.data, ca.dn, ca.dn_len);
|
||||
ta->dn.len = ca.dn_len;
|
||||
switch(pkey->key_type) {
|
||||
case BR_KEYTYPE_RSA:
|
||||
ta->pkey.key.rsa.n = ta->dn.data + ta->dn.len;
|
||||
memcpy(ta->pkey.key.rsa.n, pkey->key.rsa.n, pkey->key.rsa.nlen);
|
||||
ta->pkey.key.rsa.e = ta->pkey.key.rsa.n + ta->pkey.key.rsa.nlen;
|
||||
memcpy(ta->pkey.key.rsa.e, pkey->key.rsa.e, pkey->key.rsa.elen);
|
||||
break;
|
||||
case BR_KEYTYPE_EC:
|
||||
ta->pkey.key.ec.q = ta->dn.data + ta->dn.len;
|
||||
memcpy(ta->pkey.key.ec.q, pkey->key.ec.q, pkey->key.ec.qlen);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ca.err = CURLE_SSL_CACERT_BADFILE;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(ferror(fp))
|
||||
ca.err = CURLE_READ_ERROR;
|
||||
|
||||
fail:
|
||||
fclose(fp);
|
||||
if(ca.err == CURLE_OK) {
|
||||
*anchors = ca.anchors;
|
||||
*anchors_len = ca.anchors_len;
|
||||
}
|
||||
else {
|
||||
for(i = 0; i < ca.anchors_len; ++i)
|
||||
free(ca.anchors[i].dn.data);
|
||||
free(ca.anchors);
|
||||
}
|
||||
|
||||
return ca.err;
|
||||
}
|
||||
|
||||
static void x509_start_chain(const br_x509_class **ctx,
|
||||
const char *server_name)
|
||||
{
|
||||
struct x509_context *x509 = (struct x509_context *)ctx;
|
||||
|
||||
if(!x509->verifyhost)
|
||||
server_name = NULL;
|
||||
x509->minimal.vtable->start_chain(&x509->minimal.vtable, server_name);
|
||||
}
|
||||
|
||||
static void x509_start_cert(const br_x509_class **ctx, uint32_t length)
|
||||
{
|
||||
struct x509_context *x509 = (struct x509_context *)ctx;
|
||||
|
||||
x509->minimal.vtable->start_cert(&x509->minimal.vtable, length);
|
||||
}
|
||||
|
||||
static void x509_append(const br_x509_class **ctx, const unsigned char *buf,
|
||||
size_t len)
|
||||
{
|
||||
struct x509_context *x509 = (struct x509_context *)ctx;
|
||||
|
||||
x509->minimal.vtable->append(&x509->minimal.vtable, buf, len);
|
||||
}
|
||||
|
||||
static void x509_end_cert(const br_x509_class **ctx)
|
||||
{
|
||||
struct x509_context *x509 = (struct x509_context *)ctx;
|
||||
|
||||
x509->minimal.vtable->end_cert(&x509->minimal.vtable);
|
||||
}
|
||||
|
||||
static unsigned x509_end_chain(const br_x509_class **ctx)
|
||||
{
|
||||
struct x509_context *x509 = (struct x509_context *)ctx;
|
||||
unsigned err;
|
||||
|
||||
err = x509->minimal.vtable->end_chain(&x509->minimal.vtable);
|
||||
if(err && !x509->verifypeer) {
|
||||
/* ignore any X.509 errors */
|
||||
err = BR_ERR_OK;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static const br_x509_pkey *x509_get_pkey(const br_x509_class *const *ctx,
|
||||
unsigned *usages)
|
||||
{
|
||||
struct x509_context *x509 = (struct x509_context *)ctx;
|
||||
|
||||
return x509->minimal.vtable->get_pkey(&x509->minimal.vtable, usages);
|
||||
}
|
||||
|
||||
static const br_x509_class x509_vtable = {
|
||||
sizeof(struct x509_context),
|
||||
x509_start_chain,
|
||||
x509_start_cert,
|
||||
x509_append,
|
||||
x509_end_cert,
|
||||
x509_end_chain,
|
||||
x509_get_pkey
|
||||
};
|
||||
|
||||
static CURLcode bearssl_connect_step1(struct Curl_easy *data,
|
||||
struct connectdata *conn, int sockindex)
|
||||
{
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
struct ssl_backend_data *backend = connssl->backend;
|
||||
const char * const ssl_cafile = SSL_CONN_CONFIG(CAfile);
|
||||
#ifndef CURL_DISABLE_PROXY
|
||||
const char *hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
|
||||
conn->host.name;
|
||||
#else
|
||||
const char *hostname = conn->host.name;
|
||||
#endif
|
||||
const bool verifypeer = SSL_CONN_CONFIG(verifypeer);
|
||||
const bool verifyhost = SSL_CONN_CONFIG(verifyhost);
|
||||
CURLcode ret;
|
||||
unsigned version_min, version_max;
|
||||
#ifdef ENABLE_IPV6
|
||||
struct in6_addr addr;
|
||||
#else
|
||||
struct in_addr addr;
|
||||
#endif
|
||||
|
||||
switch(SSL_CONN_CONFIG(version)) {
|
||||
case CURL_SSLVERSION_SSLv2:
|
||||
failf(data, "BearSSL does not support SSLv2");
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
case CURL_SSLVERSION_SSLv3:
|
||||
failf(data, "BearSSL does not support SSLv3");
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
case CURL_SSLVERSION_TLSv1_0:
|
||||
version_min = BR_TLS10;
|
||||
version_max = BR_TLS10;
|
||||
break;
|
||||
case CURL_SSLVERSION_TLSv1_1:
|
||||
version_min = BR_TLS11;
|
||||
version_max = BR_TLS11;
|
||||
break;
|
||||
case CURL_SSLVERSION_TLSv1_2:
|
||||
version_min = BR_TLS12;
|
||||
version_max = BR_TLS12;
|
||||
break;
|
||||
case CURL_SSLVERSION_DEFAULT:
|
||||
case CURL_SSLVERSION_TLSv1:
|
||||
version_min = BR_TLS10;
|
||||
version_max = BR_TLS12;
|
||||
break;
|
||||
default:
|
||||
failf(data, "BearSSL: unknown CURLOPT_SSLVERSION");
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
|
||||
if(ssl_cafile) {
|
||||
ret = load_cafile(ssl_cafile, &backend->anchors, &backend->anchors_len);
|
||||
if(ret != CURLE_OK) {
|
||||
if(verifypeer) {
|
||||
failf(data, "error setting certificate verify locations."
|
||||
" CAfile: %s", ssl_cafile);
|
||||
return ret;
|
||||
}
|
||||
infof(data, "error setting certificate verify locations,"
|
||||
" continuing anyway:\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* initialize SSL context */
|
||||
br_ssl_client_init_full(&backend->ctx, &backend->x509.minimal,
|
||||
backend->anchors, backend->anchors_len);
|
||||
br_ssl_engine_set_versions(&backend->ctx.eng, version_min, version_max);
|
||||
br_ssl_engine_set_buffer(&backend->ctx.eng, backend->buf,
|
||||
sizeof(backend->buf), 1);
|
||||
|
||||
/* initialize X.509 context */
|
||||
backend->x509.vtable = &x509_vtable;
|
||||
backend->x509.verifypeer = verifypeer;
|
||||
backend->x509.verifyhost = verifyhost;
|
||||
br_ssl_engine_set_x509(&backend->ctx.eng, &backend->x509.vtable);
|
||||
|
||||
if(SSL_SET_OPTION(primary.sessionid)) {
|
||||
void *session;
|
||||
|
||||
Curl_ssl_sessionid_lock(data);
|
||||
if(!Curl_ssl_getsessionid(data, conn, &session, NULL, sockindex)) {
|
||||
br_ssl_engine_set_session_parameters(&backend->ctx.eng, session);
|
||||
infof(data, "BearSSL: re-using session ID\n");
|
||||
}
|
||||
Curl_ssl_sessionid_unlock(data);
|
||||
}
|
||||
|
||||
if(conn->bits.tls_enable_alpn) {
|
||||
int cur = 0;
|
||||
|
||||
/* NOTE: when adding more protocols here, increase the size of the
|
||||
* protocols array in `struct ssl_backend_data`.
|
||||
*/
|
||||
|
||||
#ifdef USE_NGHTTP2
|
||||
if(data->set.httpversion >= CURL_HTTP_VERSION_2
|
||||
#ifndef CURL_DISABLE_PROXY
|
||||
&& (!SSL_IS_PROXY() || !conn->bits.tunnel_proxy)
|
||||
#endif
|
||||
) {
|
||||
backend->protocols[cur++] = NGHTTP2_PROTO_VERSION_ID;
|
||||
infof(data, "ALPN, offering %s\n", NGHTTP2_PROTO_VERSION_ID);
|
||||
}
|
||||
#endif
|
||||
|
||||
backend->protocols[cur++] = ALPN_HTTP_1_1;
|
||||
infof(data, "ALPN, offering %s\n", ALPN_HTTP_1_1);
|
||||
|
||||
br_ssl_engine_set_protocol_names(&backend->ctx.eng,
|
||||
backend->protocols, cur);
|
||||
}
|
||||
|
||||
if((1 == Curl_inet_pton(AF_INET, hostname, &addr))
|
||||
#ifdef ENABLE_IPV6
|
||||
|| (1 == Curl_inet_pton(AF_INET6, hostname, &addr))
|
||||
#endif
|
||||
) {
|
||||
if(verifyhost) {
|
||||
failf(data, "BearSSL: "
|
||||
"host verification of IP address is not supported");
|
||||
return CURLE_PEER_FAILED_VERIFICATION;
|
||||
}
|
||||
hostname = NULL;
|
||||
}
|
||||
|
||||
if(!br_ssl_client_reset(&backend->ctx, hostname, 0))
|
||||
return CURLE_FAILED_INIT;
|
||||
backend->active = TRUE;
|
||||
|
||||
connssl->connecting_state = ssl_connect_2;
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static CURLcode bearssl_run_until(struct Curl_easy *data,
|
||||
struct connectdata *conn, int sockindex,
|
||||
unsigned target)
|
||||
{
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
struct ssl_backend_data *backend = connssl->backend;
|
||||
curl_socket_t sockfd = conn->sock[sockindex];
|
||||
unsigned state;
|
||||
unsigned char *buf;
|
||||
size_t len;
|
||||
ssize_t ret;
|
||||
int err;
|
||||
|
||||
for(;;) {
|
||||
state = br_ssl_engine_current_state(&backend->ctx.eng);
|
||||
if(state & BR_SSL_CLOSED) {
|
||||
err = br_ssl_engine_last_error(&backend->ctx.eng);
|
||||
switch(err) {
|
||||
case BR_ERR_OK:
|
||||
/* TLS close notify */
|
||||
if(connssl->state != ssl_connection_complete) {
|
||||
failf(data, "SSL: connection closed during handshake");
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
return CURLE_OK;
|
||||
case BR_ERR_X509_EXPIRED:
|
||||
failf(data, "SSL: X.509 verification: "
|
||||
"certificate is expired or not yet valid");
|
||||
return CURLE_PEER_FAILED_VERIFICATION;
|
||||
case BR_ERR_X509_BAD_SERVER_NAME:
|
||||
failf(data, "SSL: X.509 verification: "
|
||||
"expected server name was not found in the chain");
|
||||
return CURLE_PEER_FAILED_VERIFICATION;
|
||||
case BR_ERR_X509_NOT_TRUSTED:
|
||||
failf(data, "SSL: X.509 verification: "
|
||||
"chain could not be linked to a trust anchor");
|
||||
return CURLE_PEER_FAILED_VERIFICATION;
|
||||
}
|
||||
/* X.509 errors are documented to have the range 32..63 */
|
||||
if(err >= 32 && err < 64)
|
||||
return CURLE_PEER_FAILED_VERIFICATION;
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
if(state & target)
|
||||
return CURLE_OK;
|
||||
if(state & BR_SSL_SENDREC) {
|
||||
buf = br_ssl_engine_sendrec_buf(&backend->ctx.eng, &len);
|
||||
ret = swrite(sockfd, buf, len);
|
||||
if(ret == -1) {
|
||||
if(SOCKERRNO == EAGAIN || SOCKERRNO == EWOULDBLOCK) {
|
||||
if(connssl->state != ssl_connection_complete)
|
||||
connssl->connecting_state = ssl_connect_2_writing;
|
||||
return CURLE_AGAIN;
|
||||
}
|
||||
return CURLE_WRITE_ERROR;
|
||||
}
|
||||
br_ssl_engine_sendrec_ack(&backend->ctx.eng, ret);
|
||||
}
|
||||
else if(state & BR_SSL_RECVREC) {
|
||||
buf = br_ssl_engine_recvrec_buf(&backend->ctx.eng, &len);
|
||||
ret = sread(sockfd, buf, len);
|
||||
if(ret == 0) {
|
||||
failf(data, "SSL: EOF without close notify");
|
||||
return CURLE_READ_ERROR;
|
||||
}
|
||||
if(ret == -1) {
|
||||
if(SOCKERRNO == EAGAIN || SOCKERRNO == EWOULDBLOCK) {
|
||||
if(connssl->state != ssl_connection_complete)
|
||||
connssl->connecting_state = ssl_connect_2_reading;
|
||||
return CURLE_AGAIN;
|
||||
}
|
||||
return CURLE_READ_ERROR;
|
||||
}
|
||||
br_ssl_engine_recvrec_ack(&backend->ctx.eng, ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static CURLcode bearssl_connect_step2(struct Curl_easy *data,
|
||||
struct connectdata *conn, int sockindex)
|
||||
{
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
struct ssl_backend_data *backend = connssl->backend;
|
||||
CURLcode ret;
|
||||
|
||||
ret = bearssl_run_until(data, conn, sockindex,
|
||||
BR_SSL_SENDAPP | BR_SSL_RECVAPP);
|
||||
if(ret == CURLE_AGAIN)
|
||||
return CURLE_OK;
|
||||
if(ret == CURLE_OK) {
|
||||
if(br_ssl_engine_current_state(&backend->ctx.eng) == BR_SSL_CLOSED) {
|
||||
failf(data, "SSL: connection closed during handshake");
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
connssl->connecting_state = ssl_connect_3;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static CURLcode bearssl_connect_step3(struct Curl_easy *data,
|
||||
struct connectdata *conn, int sockindex)
|
||||
{
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
struct ssl_backend_data *backend = connssl->backend;
|
||||
CURLcode ret;
|
||||
|
||||
DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
|
||||
|
||||
if(conn->bits.tls_enable_alpn) {
|
||||
const char *protocol;
|
||||
|
||||
protocol = br_ssl_engine_get_selected_protocol(&backend->ctx.eng);
|
||||
if(protocol) {
|
||||
infof(data, "ALPN, server accepted to use %s\n", protocol);
|
||||
|
||||
#ifdef USE_NGHTTP2
|
||||
if(!strcmp(protocol, NGHTTP2_PROTO_VERSION_ID))
|
||||
conn->negnpn = CURL_HTTP_VERSION_2;
|
||||
else
|
||||
#endif
|
||||
if(!strcmp(protocol, ALPN_HTTP_1_1))
|
||||
conn->negnpn = CURL_HTTP_VERSION_1_1;
|
||||
else
|
||||
infof(data, "ALPN, unrecognized protocol %s\n", protocol);
|
||||
Curl_multiuse_state(data, conn->negnpn == CURL_HTTP_VERSION_2 ?
|
||||
BUNDLE_MULTIPLEX : BUNDLE_NO_MULTIUSE);
|
||||
}
|
||||
else
|
||||
infof(data, "ALPN, server did not agree to a protocol\n");
|
||||
}
|
||||
|
||||
if(SSL_SET_OPTION(primary.sessionid)) {
|
||||
bool incache;
|
||||
void *oldsession;
|
||||
br_ssl_session_parameters *session;
|
||||
|
||||
session = malloc(sizeof(*session));
|
||||
if(!session)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
br_ssl_engine_get_session_parameters(&backend->ctx.eng, session);
|
||||
Curl_ssl_sessionid_lock(data);
|
||||
incache = !(Curl_ssl_getsessionid(data, conn,
|
||||
&oldsession, NULL, sockindex));
|
||||
if(incache)
|
||||
Curl_ssl_delsessionid(data, oldsession);
|
||||
ret = Curl_ssl_addsessionid(data, conn, session, 0, sockindex);
|
||||
Curl_ssl_sessionid_unlock(data);
|
||||
if(ret) {
|
||||
free(session);
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
connssl->connecting_state = ssl_connect_done;
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static ssize_t bearssl_send(struct Curl_easy *data, int sockindex,
|
||||
const void *buf, size_t len, CURLcode *err)
|
||||
{
|
||||
struct connectdata *conn = data->conn;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
struct ssl_backend_data *backend = connssl->backend;
|
||||
unsigned char *app;
|
||||
size_t applen;
|
||||
|
||||
for(;;) {
|
||||
*err = bearssl_run_until(data, conn, sockindex, BR_SSL_SENDAPP);
|
||||
if (*err != CURLE_OK)
|
||||
return -1;
|
||||
app = br_ssl_engine_sendapp_buf(&backend->ctx.eng, &applen);
|
||||
if(!app) {
|
||||
failf(data, "SSL: connection closed during write");
|
||||
*err = CURLE_SEND_ERROR;
|
||||
return -1;
|
||||
}
|
||||
if(backend->pending_write) {
|
||||
applen = backend->pending_write;
|
||||
backend->pending_write = 0;
|
||||
return applen;
|
||||
}
|
||||
if(applen > len)
|
||||
applen = len;
|
||||
memcpy(app, buf, applen);
|
||||
br_ssl_engine_sendapp_ack(&backend->ctx.eng, applen);
|
||||
br_ssl_engine_flush(&backend->ctx.eng, 0);
|
||||
backend->pending_write = applen;
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t bearssl_recv(struct Curl_easy *data, int sockindex,
|
||||
char *buf, size_t len, CURLcode *err)
|
||||
{
|
||||
struct connectdata *conn = data->conn;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
struct ssl_backend_data *backend = connssl->backend;
|
||||
unsigned char *app;
|
||||
size_t applen;
|
||||
|
||||
*err = bearssl_run_until(data, conn, sockindex, BR_SSL_RECVAPP);
|
||||
if(*err != CURLE_OK)
|
||||
return -1;
|
||||
app = br_ssl_engine_recvapp_buf(&backend->ctx.eng, &applen);
|
||||
if(!app)
|
||||
return 0;
|
||||
if(applen > len)
|
||||
applen = len;
|
||||
memcpy(buf, app, applen);
|
||||
br_ssl_engine_recvapp_ack(&backend->ctx.eng, applen);
|
||||
|
||||
return applen;
|
||||
}
|
||||
|
||||
static CURLcode bearssl_connect_common(struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
int sockindex,
|
||||
bool nonblocking,
|
||||
bool *done)
|
||||
{
|
||||
CURLcode ret;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
curl_socket_t sockfd = conn->sock[sockindex];
|
||||
timediff_t timeout_ms;
|
||||
int what;
|
||||
|
||||
/* check if the connection has already been established */
|
||||
if(ssl_connection_complete == connssl->state) {
|
||||
*done = TRUE;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
if(ssl_connect_1 == connssl->connecting_state) {
|
||||
ret = bearssl_connect_step1(data, conn, sockindex);
|
||||
if(ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
while(ssl_connect_2 == connssl->connecting_state ||
|
||||
ssl_connect_2_reading == connssl->connecting_state ||
|
||||
ssl_connect_2_writing == connssl->connecting_state) {
|
||||
/* check allowed time left */
|
||||
timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
|
||||
if(timeout_ms < 0) {
|
||||
/* no need to continue if time already is up */
|
||||
failf(data, "SSL connection timeout");
|
||||
return CURLE_OPERATION_TIMEDOUT;
|
||||
}
|
||||
|
||||
/* if ssl is expecting something, check if it's available. */
|
||||
if(ssl_connect_2_reading == connssl->connecting_state ||
|
||||
ssl_connect_2_writing == connssl->connecting_state) {
|
||||
|
||||
curl_socket_t writefd = ssl_connect_2_writing ==
|
||||
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
|
||||
curl_socket_t readfd = ssl_connect_2_reading ==
|
||||
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
|
||||
|
||||
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
|
||||
nonblocking?0:timeout_ms);
|
||||
if(what < 0) {
|
||||
/* fatal error */
|
||||
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
else if(0 == what) {
|
||||
if(nonblocking) {
|
||||
*done = FALSE;
|
||||
return CURLE_OK;
|
||||
}
|
||||
else {
|
||||
/* timeout */
|
||||
failf(data, "SSL connection timeout");
|
||||
return CURLE_OPERATION_TIMEDOUT;
|
||||
}
|
||||
}
|
||||
/* socket is readable or writable */
|
||||
}
|
||||
|
||||
/* Run transaction, and return to the caller if it failed or if this
|
||||
* connection is done nonblocking and this loop would execute again. This
|
||||
* permits the owner of a multi handle to abort a connection attempt
|
||||
* before step2 has completed while ensuring that a client using select()
|
||||
* or epoll() will always have a valid fdset to wait on.
|
||||
*/
|
||||
ret = bearssl_connect_step2(data, conn, sockindex);
|
||||
if(ret || (nonblocking &&
|
||||
(ssl_connect_2 == connssl->connecting_state ||
|
||||
ssl_connect_2_reading == connssl->connecting_state ||
|
||||
ssl_connect_2_writing == connssl->connecting_state)))
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(ssl_connect_3 == connssl->connecting_state) {
|
||||
ret = bearssl_connect_step3(data, conn, sockindex);
|
||||
if(ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(ssl_connect_done == connssl->connecting_state) {
|
||||
connssl->state = ssl_connection_complete;
|
||||
conn->recv[sockindex] = bearssl_recv;
|
||||
conn->send[sockindex] = bearssl_send;
|
||||
*done = TRUE;
|
||||
}
|
||||
else
|
||||
*done = FALSE;
|
||||
|
||||
/* Reset our connect state machine */
|
||||
connssl->connecting_state = ssl_connect_1;
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static size_t bearssl_version(char *buffer, size_t size)
|
||||
{
|
||||
return msnprintf(buffer, size, "BearSSL");
|
||||
}
|
||||
|
||||
static bool bearssl_data_pending(const struct connectdata *conn,
|
||||
int connindex)
|
||||
{
|
||||
const struct ssl_connect_data *connssl = &conn->ssl[connindex];
|
||||
struct ssl_backend_data *backend = connssl->backend;
|
||||
return br_ssl_engine_current_state(&backend->ctx.eng) & BR_SSL_RECVAPP;
|
||||
}
|
||||
|
||||
static CURLcode bearssl_random(struct Curl_easy *data UNUSED_PARAM,
|
||||
unsigned char *entropy, size_t length)
|
||||
{
|
||||
static br_hmac_drbg_context ctx;
|
||||
static bool seeded = FALSE;
|
||||
|
||||
if(!seeded) {
|
||||
br_prng_seeder seeder;
|
||||
|
||||
br_hmac_drbg_init(&ctx, &br_sha256_vtable, NULL, 0);
|
||||
seeder = br_prng_seeder_system(NULL);
|
||||
if(!seeder || !seeder(&ctx.vtable))
|
||||
return CURLE_FAILED_INIT;
|
||||
seeded = TRUE;
|
||||
}
|
||||
br_hmac_drbg_generate(&ctx, entropy, length);
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static CURLcode bearssl_connect(struct Curl_easy *data,
|
||||
struct connectdata *conn, int sockindex)
|
||||
{
|
||||
CURLcode ret;
|
||||
bool done = FALSE;
|
||||
|
||||
ret = bearssl_connect_common(data, conn, sockindex, FALSE, &done);
|
||||
if(ret)
|
||||
return ret;
|
||||
|
||||
DEBUGASSERT(done);
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static CURLcode bearssl_connect_nonblocking(struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
int sockindex, bool *done)
|
||||
{
|
||||
return bearssl_connect_common(data, conn, sockindex, TRUE, done);
|
||||
}
|
||||
|
||||
static void *bearssl_get_internals(struct ssl_connect_data *connssl,
|
||||
CURLINFO info UNUSED_PARAM)
|
||||
{
|
||||
struct ssl_backend_data *backend = connssl->backend;
|
||||
return &backend->ctx;
|
||||
}
|
||||
|
||||
static void bearssl_close(struct Curl_easy *data,
|
||||
struct connectdata *conn, int sockindex)
|
||||
{
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
struct ssl_backend_data *backend = connssl->backend;
|
||||
size_t i;
|
||||
|
||||
if(backend->active) {
|
||||
br_ssl_engine_close(&backend->ctx.eng);
|
||||
(void)bearssl_run_until(data, conn, sockindex, BR_SSL_CLOSED);
|
||||
}
|
||||
for(i = 0; i < backend->anchors_len; ++i)
|
||||
free(backend->anchors[i].dn.data);
|
||||
free(backend->anchors);
|
||||
}
|
||||
|
||||
static void bearssl_session_free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
static CURLcode bearssl_md5sum(unsigned char *input,
|
||||
size_t inputlen,
|
||||
unsigned char *md5sum,
|
||||
size_t md5len UNUSED_PARAM)
|
||||
{
|
||||
br_md5_context ctx;
|
||||
|
||||
br_md5_init(&ctx);
|
||||
br_md5_update(&ctx, input, inputlen);
|
||||
br_md5_out(&ctx, md5sum);
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static CURLcode bearssl_sha256sum(const unsigned char *input,
|
||||
size_t inputlen,
|
||||
unsigned char *sha256sum,
|
||||
size_t sha256len UNUSED_PARAM)
|
||||
{
|
||||
br_sha256_context ctx;
|
||||
|
||||
br_sha256_init(&ctx);
|
||||
br_sha256_update(&ctx, input, inputlen);
|
||||
br_sha256_out(&ctx, sha256sum);
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
const struct Curl_ssl Curl_ssl_bearssl = {
|
||||
{ CURLSSLBACKEND_BEARSSL, "bearssl" },
|
||||
0,
|
||||
sizeof(struct ssl_backend_data),
|
||||
|
||||
Curl_none_init,
|
||||
Curl_none_cleanup,
|
||||
bearssl_version,
|
||||
Curl_none_check_cxn,
|
||||
Curl_none_shutdown,
|
||||
bearssl_data_pending,
|
||||
bearssl_random,
|
||||
Curl_none_cert_status_request,
|
||||
bearssl_connect,
|
||||
bearssl_connect_nonblocking,
|
||||
bearssl_get_internals,
|
||||
bearssl_close,
|
||||
Curl_none_close_all,
|
||||
bearssl_session_free,
|
||||
Curl_none_set_engine,
|
||||
Curl_none_set_engine_default,
|
||||
Curl_none_engines_list,
|
||||
Curl_none_false_start,
|
||||
bearssl_md5sum,
|
||||
bearssl_sha256sum
|
||||
};
|
||||
|
||||
#endif /* USE_BEARSSL */
|
||||
32
module/Vendor/CURL/lib/vtls/bearssl.h
vendored
Normal file
32
module/Vendor/CURL/lib/vtls/bearssl.h
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef HEADER_CURL_BEARSSL_H
|
||||
#define HEADER_CURL_BEARSSL_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2019 - 2020, Michael Forney, <mforney@mforney.org>
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_BEARSSL
|
||||
|
||||
extern const struct Curl_ssl Curl_ssl_bearssl;
|
||||
|
||||
#endif /* USE_BEARSSL */
|
||||
#endif /* HEADER_CURL_BEARSSL_H */
|
||||
1289
module/Vendor/CURL/lib/vtls/gskit.c
vendored
Normal file
1289
module/Vendor/CURL/lib/vtls/gskit.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
38
module/Vendor/CURL/lib/vtls/gskit.h
vendored
Normal file
38
module/Vendor/CURL/lib/vtls/gskit.h
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef HEADER_CURL_GSKIT_H
|
||||
#define HEADER_CURL_GSKIT_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
/*
|
||||
* This header should only be needed to get included by vtls.c and gskit.c
|
||||
*/
|
||||
|
||||
#include "urldata.h"
|
||||
|
||||
#ifdef USE_GSKIT
|
||||
|
||||
extern const struct Curl_ssl Curl_ssl_gskit;
|
||||
|
||||
#endif /* USE_GSKIT */
|
||||
|
||||
#endif /* HEADER_CURL_GSKIT_H */
|
||||
1706
module/Vendor/CURL/lib/vtls/gtls.c
vendored
Normal file
1706
module/Vendor/CURL/lib/vtls/gtls.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
34
module/Vendor/CURL/lib/vtls/gtls.h
vendored
Normal file
34
module/Vendor/CURL/lib/vtls/gtls.h
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef HEADER_CURL_GTLS_H
|
||||
#define HEADER_CURL_GTLS_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_GNUTLS
|
||||
|
||||
#include "urldata.h"
|
||||
|
||||
extern const struct Curl_ssl Curl_ssl_gnutls;
|
||||
|
||||
#endif /* USE_GNUTLS */
|
||||
#endif /* HEADER_CURL_GTLS_H */
|
||||
156
module/Vendor/CURL/lib/vtls/keylog.c
vendored
Normal file
156
module/Vendor/CURL/lib/vtls/keylog.c
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
#include "keylog.h"
|
||||
|
||||
/* The last #include files should be: */
|
||||
#include "curl_memory.h"
|
||||
#include "memdebug.h"
|
||||
|
||||
#define KEYLOG_LABEL_MAXLEN (sizeof("CLIENT_HANDSHAKE_TRAFFIC_SECRET") - 1)
|
||||
|
||||
#define CLIENT_RANDOM_SIZE 32
|
||||
|
||||
/*
|
||||
* The master secret in TLS 1.2 and before is always 48 bytes. In TLS 1.3, the
|
||||
* secret size depends on the cipher suite's hash function which is 32 bytes
|
||||
* for SHA-256 and 48 bytes for SHA-384.
|
||||
*/
|
||||
#define SECRET_MAXLEN 48
|
||||
|
||||
|
||||
/* The fp for the open SSLKEYLOGFILE, or NULL if not open */
|
||||
static FILE *keylog_file_fp;
|
||||
|
||||
void
|
||||
Curl_tls_keylog_open(void)
|
||||
{
|
||||
char *keylog_file_name;
|
||||
|
||||
if(!keylog_file_fp) {
|
||||
keylog_file_name = curl_getenv("SSLKEYLOGFILE");
|
||||
if(keylog_file_name) {
|
||||
keylog_file_fp = fopen(keylog_file_name, FOPEN_APPENDTEXT);
|
||||
if(keylog_file_fp) {
|
||||
#ifdef WIN32
|
||||
if(setvbuf(keylog_file_fp, NULL, _IONBF, 0))
|
||||
#else
|
||||
if(setvbuf(keylog_file_fp, NULL, _IOLBF, 4096))
|
||||
#endif
|
||||
{
|
||||
fclose(keylog_file_fp);
|
||||
keylog_file_fp = NULL;
|
||||
}
|
||||
}
|
||||
Curl_safefree(keylog_file_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Curl_tls_keylog_close(void)
|
||||
{
|
||||
if(keylog_file_fp) {
|
||||
fclose(keylog_file_fp);
|
||||
keylog_file_fp = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Curl_tls_keylog_enabled(void)
|
||||
{
|
||||
return keylog_file_fp != NULL;
|
||||
}
|
||||
|
||||
bool
|
||||
Curl_tls_keylog_write_line(const char *line)
|
||||
{
|
||||
/* The current maximum valid keylog line length LF and NUL is 195. */
|
||||
size_t linelen;
|
||||
char buf[256];
|
||||
|
||||
if(!keylog_file_fp || !line) {
|
||||
return false;
|
||||
}
|
||||
|
||||
linelen = strlen(line);
|
||||
if(linelen == 0 || linelen > sizeof(buf) - 2) {
|
||||
/* Empty line or too big to fit in a LF and NUL. */
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(buf, line, linelen);
|
||||
if(line[linelen - 1] != '\n') {
|
||||
buf[linelen++] = '\n';
|
||||
}
|
||||
buf[linelen] = '\0';
|
||||
|
||||
/* Using fputs here instead of fprintf since libcurl's fprintf replacement
|
||||
may not be thread-safe. */
|
||||
fputs(buf, keylog_file_fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
Curl_tls_keylog_write(const char *label,
|
||||
const unsigned char client_random[CLIENT_RANDOM_SIZE],
|
||||
const unsigned char *secret, size_t secretlen)
|
||||
{
|
||||
const char *hex = "0123456789ABCDEF";
|
||||
size_t pos, i;
|
||||
char line[KEYLOG_LABEL_MAXLEN + 1 + 2 * CLIENT_RANDOM_SIZE + 1 +
|
||||
2 * SECRET_MAXLEN + 1 + 1];
|
||||
|
||||
if(!keylog_file_fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pos = strlen(label);
|
||||
if(pos > KEYLOG_LABEL_MAXLEN || !secretlen || secretlen > SECRET_MAXLEN) {
|
||||
/* Should never happen - sanity check anyway. */
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(line, label, pos);
|
||||
line[pos++] = ' ';
|
||||
|
||||
/* Client Random */
|
||||
for(i = 0; i < CLIENT_RANDOM_SIZE; i++) {
|
||||
line[pos++] = hex[client_random[i] >> 4];
|
||||
line[pos++] = hex[client_random[i] & 0xF];
|
||||
}
|
||||
line[pos++] = ' ';
|
||||
|
||||
/* Secret */
|
||||
for(i = 0; i < secretlen; i++) {
|
||||
line[pos++] = hex[secret[i] >> 4];
|
||||
line[pos++] = hex[secret[i] & 0xF];
|
||||
}
|
||||
line[pos++] = '\n';
|
||||
line[pos] = '\0';
|
||||
|
||||
/* Using fputs here instead of fprintf since libcurl's fprintf replacement
|
||||
may not be thread-safe. */
|
||||
fputs(line, keylog_file_fp);
|
||||
return true;
|
||||
}
|
||||
56
module/Vendor/CURL/lib/vtls/keylog.h
vendored
Normal file
56
module/Vendor/CURL/lib/vtls/keylog.h
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef HEADER_CURL_KEYLOG_H
|
||||
#define HEADER_CURL_KEYLOG_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
/*
|
||||
* Opens the TLS key log file if requested by the user. The SSLKEYLOGFILE
|
||||
* environment variable specifies the output file.
|
||||
*/
|
||||
void Curl_tls_keylog_open(void);
|
||||
|
||||
/*
|
||||
* Closes the TLS key log file if not already.
|
||||
*/
|
||||
void Curl_tls_keylog_close(void);
|
||||
|
||||
/*
|
||||
* Returns true if the user successfully enabled the TLS key log file.
|
||||
*/
|
||||
bool Curl_tls_keylog_enabled(void);
|
||||
|
||||
/*
|
||||
* Appends a key log file entry.
|
||||
* Returns true iff the key log file is open and a valid entry was provided.
|
||||
*/
|
||||
bool Curl_tls_keylog_write(const char *label,
|
||||
const unsigned char client_random[32],
|
||||
const unsigned char *secret, size_t secretlen);
|
||||
|
||||
/*
|
||||
* Appends a line to the key log file, ensure it is terminated by a LF.
|
||||
* Returns true iff the key log file is open and a valid line was provided.
|
||||
*/
|
||||
bool Curl_tls_keylog_write_line(const char *line);
|
||||
|
||||
#endif /* HEADER_CURL_KEYLOG_H */
|
||||
1115
module/Vendor/CURL/lib/vtls/mbedtls.c
vendored
Normal file
1115
module/Vendor/CURL/lib/vtls/mbedtls.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
32
module/Vendor/CURL/lib/vtls/mbedtls.h
vendored
Normal file
32
module/Vendor/CURL/lib/vtls/mbedtls.h
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef HEADER_CURL_MBEDTLS_H
|
||||
#define HEADER_CURL_MBEDTLS_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2012 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 2010, Hoi-Ho Chan, <hoiho.chan@gmail.com>
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_MBEDTLS
|
||||
|
||||
extern const struct Curl_ssl Curl_ssl_mbedtls;
|
||||
|
||||
#endif /* USE_MBEDTLS */
|
||||
#endif /* HEADER_CURL_MBEDTLS_H */
|
||||
144
module/Vendor/CURL/lib/vtls/mbedtls_threadlock.c
vendored
Normal file
144
module/Vendor/CURL/lib/vtls/mbedtls_threadlock.c
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2013 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 2010, 2011, Hoi-Ho Chan, <hoiho.chan@gmail.com>
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
#if defined(USE_MBEDTLS) && \
|
||||
((defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \
|
||||
(defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)))
|
||||
|
||||
#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
|
||||
# include <pthread.h>
|
||||
# define MBEDTLS_MUTEX_T pthread_mutex_t
|
||||
#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
|
||||
# include <process.h>
|
||||
# define MBEDTLS_MUTEX_T HANDLE
|
||||
#endif
|
||||
|
||||
#include "mbedtls_threadlock.h"
|
||||
#include "curl_printf.h"
|
||||
#include "curl_memory.h"
|
||||
/* The last #include file should be: */
|
||||
#include "memdebug.h"
|
||||
|
||||
/* number of thread locks */
|
||||
#define NUMT 2
|
||||
|
||||
/* This array will store all of the mutexes available to Mbedtls. */
|
||||
static MBEDTLS_MUTEX_T *mutex_buf = NULL;
|
||||
|
||||
int Curl_mbedtlsthreadlock_thread_setup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
mutex_buf = calloc(NUMT * sizeof(MBEDTLS_MUTEX_T), 1);
|
||||
if(!mutex_buf)
|
||||
return 0; /* error, no number of threads defined */
|
||||
|
||||
for(i = 0; i < NUMT; i++) {
|
||||
int ret;
|
||||
#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
|
||||
ret = pthread_mutex_init(&mutex_buf[i], NULL);
|
||||
if(ret)
|
||||
return 0; /* pthread_mutex_init failed */
|
||||
#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
|
||||
mutex_buf[i] = CreateMutex(0, FALSE, 0);
|
||||
if(mutex_buf[i] == 0)
|
||||
return 0; /* CreateMutex failed */
|
||||
#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */
|
||||
}
|
||||
|
||||
return 1; /* OK */
|
||||
}
|
||||
|
||||
int Curl_mbedtlsthreadlock_thread_cleanup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(!mutex_buf)
|
||||
return 0; /* error, no threads locks defined */
|
||||
|
||||
for(i = 0; i < NUMT; i++) {
|
||||
int ret;
|
||||
#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
|
||||
ret = pthread_mutex_destroy(&mutex_buf[i]);
|
||||
if(ret)
|
||||
return 0; /* pthread_mutex_destroy failed */
|
||||
#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
|
||||
ret = CloseHandle(mutex_buf[i]);
|
||||
if(!ret)
|
||||
return 0; /* CloseHandle failed */
|
||||
#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */
|
||||
}
|
||||
free(mutex_buf);
|
||||
mutex_buf = NULL;
|
||||
|
||||
return 1; /* OK */
|
||||
}
|
||||
|
||||
int Curl_mbedtlsthreadlock_lock_function(int n)
|
||||
{
|
||||
if(n < NUMT) {
|
||||
int ret;
|
||||
#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
|
||||
ret = pthread_mutex_lock(&mutex_buf[n]);
|
||||
if(ret) {
|
||||
DEBUGF(fprintf(stderr,
|
||||
"Error: mbedtlsthreadlock_lock_function failed\n"));
|
||||
return 0; /* pthread_mutex_lock failed */
|
||||
}
|
||||
#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
|
||||
ret = (WaitForSingleObject(mutex_buf[n], INFINITE) == WAIT_FAILED?1:0);
|
||||
if(ret) {
|
||||
DEBUGF(fprintf(stderr,
|
||||
"Error: mbedtlsthreadlock_lock_function failed\n"));
|
||||
return 0; /* pthread_mutex_lock failed */
|
||||
}
|
||||
#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */
|
||||
}
|
||||
return 1; /* OK */
|
||||
}
|
||||
|
||||
int Curl_mbedtlsthreadlock_unlock_function(int n)
|
||||
{
|
||||
if(n < NUMT) {
|
||||
int ret;
|
||||
#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
|
||||
ret = pthread_mutex_unlock(&mutex_buf[n]);
|
||||
if(ret) {
|
||||
DEBUGF(fprintf(stderr,
|
||||
"Error: mbedtlsthreadlock_unlock_function failed\n"));
|
||||
return 0; /* pthread_mutex_unlock failed */
|
||||
}
|
||||
#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
|
||||
ret = ReleaseMutex(mutex_buf[n]);
|
||||
if(!ret) {
|
||||
DEBUGF(fprintf(stderr,
|
||||
"Error: mbedtlsthreadlock_unlock_function failed\n"));
|
||||
return 0; /* pthread_mutex_lock failed */
|
||||
}
|
||||
#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */
|
||||
}
|
||||
return 1; /* OK */
|
||||
}
|
||||
|
||||
#endif /* USE_MBEDTLS */
|
||||
48
module/Vendor/CURL/lib/vtls/mbedtls_threadlock.h
vendored
Normal file
48
module/Vendor/CURL/lib/vtls/mbedtls_threadlock.h
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef HEADER_CURL_MBEDTLS_THREADLOCK_H
|
||||
#define HEADER_CURL_MBEDTLS_THREADLOCK_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2013 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 2010, Hoi-Ho Chan, <hoiho.chan@gmail.com>
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_MBEDTLS
|
||||
|
||||
#if (defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \
|
||||
(defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H))
|
||||
|
||||
int Curl_mbedtlsthreadlock_thread_setup(void);
|
||||
int Curl_mbedtlsthreadlock_thread_cleanup(void);
|
||||
int Curl_mbedtlsthreadlock_lock_function(int n);
|
||||
int Curl_mbedtlsthreadlock_unlock_function(int n);
|
||||
|
||||
#else
|
||||
|
||||
#define Curl_mbedtlsthreadlock_thread_setup() 1
|
||||
#define Curl_mbedtlsthreadlock_thread_cleanup() 1
|
||||
#define Curl_mbedtlsthreadlock_lock_function(x) 1
|
||||
#define Curl_mbedtlsthreadlock_unlock_function(x) 1
|
||||
|
||||
#endif /* USE_THREADS_POSIX || USE_THREADS_WIN32 */
|
||||
|
||||
#endif /* USE_MBEDTLS */
|
||||
|
||||
#endif /* HEADER_CURL_MBEDTLS_THREADLOCK_H */
|
||||
669
module/Vendor/CURL/lib/vtls/mesalink.c
vendored
Normal file
669
module/Vendor/CURL/lib/vtls/mesalink.c
vendored
Normal file
@@ -0,0 +1,669 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2017 - 2018, Yiming Jing, <jingyiming@baidu.com>
|
||||
* Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
* Source file for all MesaLink-specific code for the TLS/SSL layer. No code
|
||||
* but vtls.c should ever call or use these functions.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Based upon the CyaSSL implementation in cyassl.c and cyassl.h:
|
||||
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* Thanks for code and inspiration!
|
||||
*/
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_MESALINK
|
||||
|
||||
#include <mesalink/options.h>
|
||||
#include <mesalink/version.h>
|
||||
|
||||
#include "urldata.h"
|
||||
#include "sendf.h"
|
||||
#include "inet_pton.h"
|
||||
#include "vtls.h"
|
||||
#include "parsedate.h"
|
||||
#include "connect.h" /* for the connect timeout */
|
||||
#include "select.h"
|
||||
#include "strcase.h"
|
||||
#include "x509asn1.h"
|
||||
#include "curl_printf.h"
|
||||
|
||||
#include "mesalink.h"
|
||||
#include <mesalink/openssl/ssl.h>
|
||||
#include <mesalink/openssl/err.h>
|
||||
|
||||
/* The last #include files should be: */
|
||||
#include "curl_memory.h"
|
||||
#include "memdebug.h"
|
||||
|
||||
#define MESALINK_MAX_ERROR_SZ 80
|
||||
|
||||
struct ssl_backend_data
|
||||
{
|
||||
SSL_CTX *ctx;
|
||||
SSL *handle;
|
||||
};
|
||||
|
||||
#define BACKEND connssl->backend
|
||||
|
||||
static Curl_recv mesalink_recv;
|
||||
static Curl_send mesalink_send;
|
||||
|
||||
static int do_file_type(const char *type)
|
||||
{
|
||||
if(!type || !type[0])
|
||||
return SSL_FILETYPE_PEM;
|
||||
if(strcasecompare(type, "PEM"))
|
||||
return SSL_FILETYPE_PEM;
|
||||
if(strcasecompare(type, "DER"))
|
||||
return SSL_FILETYPE_ASN1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function loads all the client/CA certificates and CRLs. Setup the TLS
|
||||
* layer and do all necessary magic.
|
||||
*/
|
||||
static CURLcode
|
||||
mesalink_connect_step1(struct Curl_easy *data,
|
||||
struct connectdata *conn, int sockindex)
|
||||
{
|
||||
char *ciphers;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
struct in_addr addr4;
|
||||
#ifdef ENABLE_IPV6
|
||||
struct in6_addr addr6;
|
||||
#endif
|
||||
const char *const hostname =
|
||||
SSL_IS_PROXY() ? conn->http_proxy.host.name : conn->host.name;
|
||||
size_t hostname_len = strlen(hostname);
|
||||
|
||||
SSL_METHOD *req_method = NULL;
|
||||
curl_socket_t sockfd = conn->sock[sockindex];
|
||||
|
||||
if(connssl->state == ssl_connection_complete)
|
||||
return CURLE_OK;
|
||||
|
||||
if(SSL_CONN_CONFIG(version_max) != CURL_SSLVERSION_MAX_NONE) {
|
||||
failf(data, "MesaLink does not support to set maximum SSL/TLS version");
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
|
||||
switch(SSL_CONN_CONFIG(version)) {
|
||||
case CURL_SSLVERSION_SSLv3:
|
||||
case CURL_SSLVERSION_TLSv1:
|
||||
case CURL_SSLVERSION_TLSv1_0:
|
||||
case CURL_SSLVERSION_TLSv1_1:
|
||||
failf(data, "MesaLink does not support SSL 3.0, TLS 1.0, or TLS 1.1");
|
||||
return CURLE_NOT_BUILT_IN;
|
||||
case CURL_SSLVERSION_DEFAULT:
|
||||
case CURL_SSLVERSION_TLSv1_2:
|
||||
req_method = TLSv1_2_client_method();
|
||||
break;
|
||||
case CURL_SSLVERSION_TLSv1_3:
|
||||
req_method = TLSv1_3_client_method();
|
||||
break;
|
||||
case CURL_SSLVERSION_SSLv2:
|
||||
failf(data, "MesaLink does not support SSLv2");
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
default:
|
||||
failf(data, "Unrecognized parameter passed via CURLOPT_SSLVERSION");
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
|
||||
if(!req_method) {
|
||||
failf(data, "SSL: couldn't create a method!");
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if(BACKEND->ctx)
|
||||
SSL_CTX_free(BACKEND->ctx);
|
||||
BACKEND->ctx = SSL_CTX_new(req_method);
|
||||
|
||||
if(!BACKEND->ctx) {
|
||||
failf(data, "SSL: couldn't create a context!");
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SSL_CTX_set_verify(
|
||||
BACKEND->ctx, SSL_CONN_CONFIG(verifypeer) ?
|
||||
SSL_VERIFY_PEER : SSL_VERIFY_NONE, NULL);
|
||||
|
||||
if(SSL_CONN_CONFIG(CAfile) || SSL_CONN_CONFIG(CApath)) {
|
||||
if(!SSL_CTX_load_verify_locations(BACKEND->ctx, SSL_CONN_CONFIG(CAfile),
|
||||
SSL_CONN_CONFIG(CApath))) {
|
||||
if(SSL_CONN_CONFIG(verifypeer)) {
|
||||
failf(data,
|
||||
"error setting certificate verify locations: "
|
||||
" CAfile: %s CApath: %s",
|
||||
SSL_CONN_CONFIG(CAfile) ?
|
||||
SSL_CONN_CONFIG(CAfile) : "none",
|
||||
SSL_CONN_CONFIG(CApath) ?
|
||||
SSL_CONN_CONFIG(CApath) : "none");
|
||||
return CURLE_SSL_CACERT_BADFILE;
|
||||
}
|
||||
infof(data,
|
||||
"error setting certificate verify locations,"
|
||||
" continuing anyway:\n");
|
||||
}
|
||||
else {
|
||||
infof(data, "successfully set certificate verify locations:\n");
|
||||
}
|
||||
infof(data, " CAfile: %s\n",
|
||||
SSL_CONN_CONFIG(CAfile) ? SSL_CONN_CONFIG(CAfile): "none");
|
||||
infof(data, " CApath: %s\n",
|
||||
SSL_CONN_CONFIG(CApath) ? SSL_CONN_CONFIG(CApath): "none");
|
||||
}
|
||||
|
||||
if(SSL_SET_OPTION(primary.clientcert) && SSL_SET_OPTION(key)) {
|
||||
int file_type = do_file_type(SSL_SET_OPTION(cert_type));
|
||||
|
||||
if(SSL_CTX_use_certificate_chain_file(BACKEND->ctx,
|
||||
SSL_SET_OPTION(primary.clientcert),
|
||||
file_type) != 1) {
|
||||
failf(data, "unable to use client certificate (no key or wrong pass"
|
||||
" phrase?)");
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
|
||||
file_type = do_file_type(SSL_SET_OPTION(key_type));
|
||||
if(SSL_CTX_use_PrivateKey_file(BACKEND->ctx, SSL_SET_OPTION(key),
|
||||
file_type) != 1) {
|
||||
failf(data, "unable to set private key");
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
infof(data,
|
||||
"client cert: %s\n",
|
||||
SSL_CONN_CONFIG(clientcert)?
|
||||
SSL_CONN_CONFIG(clientcert): "none");
|
||||
}
|
||||
|
||||
ciphers = SSL_CONN_CONFIG(cipher_list);
|
||||
if(ciphers) {
|
||||
#ifdef MESALINK_HAVE_CIPHER
|
||||
if(!SSL_CTX_set_cipher_list(BACKEND->ctx, ciphers)) {
|
||||
failf(data, "failed setting cipher list: %s", ciphers);
|
||||
return CURLE_SSL_CIPHER;
|
||||
}
|
||||
#endif
|
||||
infof(data, "Cipher selection: %s\n", ciphers);
|
||||
}
|
||||
|
||||
if(BACKEND->handle)
|
||||
SSL_free(BACKEND->handle);
|
||||
BACKEND->handle = SSL_new(BACKEND->ctx);
|
||||
if(!BACKEND->handle) {
|
||||
failf(data, "SSL: couldn't create a context (handle)!");
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if((hostname_len < USHRT_MAX) &&
|
||||
(0 == Curl_inet_pton(AF_INET, hostname, &addr4))
|
||||
#ifdef ENABLE_IPV6
|
||||
&& (0 == Curl_inet_pton(AF_INET6, hostname, &addr6))
|
||||
#endif
|
||||
) {
|
||||
/* hostname is not a valid IP address */
|
||||
if(SSL_set_tlsext_host_name(BACKEND->handle, hostname) != SSL_SUCCESS) {
|
||||
failf(data,
|
||||
"WARNING: failed to configure server name indication (SNI) "
|
||||
"TLS extension\n");
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
#ifdef CURLDEBUG
|
||||
/* Check if the hostname is 127.0.0.1 or [::1];
|
||||
* otherwise reject because MesaLink always wants a valid DNS Name
|
||||
* specified in RFC 5280 Section 7.2 */
|
||||
if(strncmp(hostname, "127.0.0.1", 9) == 0
|
||||
#ifdef ENABLE_IPV6
|
||||
|| strncmp(hostname, "[::1]", 5) == 0
|
||||
#endif
|
||||
) {
|
||||
SSL_set_tlsext_host_name(BACKEND->handle, "localhost");
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
failf(data,
|
||||
"ERROR: MesaLink does not accept an IP address as a hostname\n");
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MESALINK_HAVE_SESSION
|
||||
if(SSL_SET_OPTION(primary.sessionid)) {
|
||||
void *ssl_sessionid = NULL;
|
||||
|
||||
Curl_ssl_sessionid_lock(data);
|
||||
if(!Curl_ssl_getsessionid(data, conn, &ssl_sessionid, NULL, sockindex)) {
|
||||
/* we got a session id, use it! */
|
||||
if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) {
|
||||
Curl_ssl_sessionid_unlock(data);
|
||||
failf(
|
||||
data,
|
||||
"SSL: SSL_set_session failed: %s",
|
||||
ERR_error_string(SSL_get_error(BACKEND->handle, 0), error_buffer));
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
/* Informational message */
|
||||
infof(data, "SSL re-using session ID\n");
|
||||
}
|
||||
Curl_ssl_sessionid_unlock(data);
|
||||
}
|
||||
#endif /* MESALINK_HAVE_SESSION */
|
||||
|
||||
if(SSL_set_fd(BACKEND->handle, (int)sockfd) != SSL_SUCCESS) {
|
||||
failf(data, "SSL: SSL_set_fd failed");
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
|
||||
connssl->connecting_state = ssl_connect_2;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static CURLcode
|
||||
mesalink_connect_step2(struct Curl_easy *data,
|
||||
struct connectdata *conn, int sockindex)
|
||||
{
|
||||
int ret = -1;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
|
||||
conn->recv[sockindex] = mesalink_recv;
|
||||
conn->send[sockindex] = mesalink_send;
|
||||
|
||||
ret = SSL_connect(BACKEND->handle);
|
||||
if(ret != SSL_SUCCESS) {
|
||||
int detail = SSL_get_error(BACKEND->handle, ret);
|
||||
|
||||
if(SSL_ERROR_WANT_CONNECT == detail || SSL_ERROR_WANT_READ == detail) {
|
||||
connssl->connecting_state = ssl_connect_2_reading;
|
||||
return CURLE_OK;
|
||||
}
|
||||
else {
|
||||
char error_buffer[MESALINK_MAX_ERROR_SZ];
|
||||
failf(data,
|
||||
"SSL_connect failed with error %d: %s",
|
||||
detail,
|
||||
ERR_error_string_n(detail, error_buffer, sizeof(error_buffer)));
|
||||
ERR_print_errors_fp(stderr);
|
||||
if(detail && SSL_CONN_CONFIG(verifypeer)) {
|
||||
detail &= ~0xFF;
|
||||
if(detail == TLS_ERROR_WEBPKI_ERRORS) {
|
||||
failf(data, "Cert verify failed");
|
||||
return CURLE_PEER_FAILED_VERIFICATION;
|
||||
}
|
||||
}
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
connssl->connecting_state = ssl_connect_3;
|
||||
infof(data,
|
||||
"SSL connection using %s / %s\n",
|
||||
SSL_get_version(BACKEND->handle),
|
||||
SSL_get_cipher_name(BACKEND->handle));
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static CURLcode
|
||||
mesalink_connect_step3(struct connectdata *conn, int sockindex)
|
||||
{
|
||||
CURLcode result = CURLE_OK;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
|
||||
DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
|
||||
|
||||
#ifdef MESALINK_HAVE_SESSION
|
||||
if(SSL_SET_OPTION(primary.sessionid)) {
|
||||
bool incache;
|
||||
SSL_SESSION *our_ssl_sessionid;
|
||||
void *old_ssl_sessionid = NULL;
|
||||
|
||||
our_ssl_sessionid = SSL_get_session(BACKEND->handle);
|
||||
|
||||
Curl_ssl_sessionid_lock(data);
|
||||
incache =
|
||||
!(Curl_ssl_getsessionid(data, conn,
|
||||
&old_ssl_sessionid, NULL, sockindex));
|
||||
if(incache) {
|
||||
if(old_ssl_sessionid != our_ssl_sessionid) {
|
||||
infof(data, "old SSL session ID is stale, removing\n");
|
||||
Curl_ssl_delsessionid(data, old_ssl_sessionid);
|
||||
incache = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if(!incache) {
|
||||
result = Curl_ssl_addsessionid(
|
||||
data, conn, our_ssl_sessionid, 0 /* unknown size */, sockindex);
|
||||
if(result) {
|
||||
Curl_ssl_sessionid_unlock(data);
|
||||
failf(data, "failed to store ssl session");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Curl_ssl_sessionid_unlock(data);
|
||||
}
|
||||
#endif /* MESALINK_HAVE_SESSION */
|
||||
|
||||
connssl->connecting_state = ssl_connect_done;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
mesalink_send(struct Curl_easy *data, int sockindex, const void *mem,
|
||||
size_t len, CURLcode *curlcode)
|
||||
{
|
||||
struct connectdata *conn = data->conn;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
char error_buffer[MESALINK_MAX_ERROR_SZ];
|
||||
int memlen = (len > (size_t)INT_MAX) ? INT_MAX : (int)len;
|
||||
int rc = SSL_write(BACKEND->handle, mem, memlen);
|
||||
|
||||
if(rc < 0) {
|
||||
int err = SSL_get_error(BACKEND->handle, rc);
|
||||
switch(err) {
|
||||
case SSL_ERROR_WANT_READ:
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
/* there's data pending, re-invoke SSL_write() */
|
||||
*curlcode = CURLE_AGAIN;
|
||||
return -1;
|
||||
default:
|
||||
failf(data,
|
||||
"SSL write: %s, errno %d",
|
||||
ERR_error_string_n(err, error_buffer, sizeof(error_buffer)),
|
||||
SOCKERRNO);
|
||||
*curlcode = CURLE_SEND_ERROR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void
|
||||
mesalink_close(struct Curl_easy *data, struct connectdata *conn, int sockindex)
|
||||
{
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
|
||||
(void) data;
|
||||
|
||||
if(BACKEND->handle) {
|
||||
(void)SSL_shutdown(BACKEND->handle);
|
||||
SSL_free(BACKEND->handle);
|
||||
BACKEND->handle = NULL;
|
||||
}
|
||||
if(BACKEND->ctx) {
|
||||
SSL_CTX_free(BACKEND->ctx);
|
||||
BACKEND->ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
mesalink_recv(struct Curl_easy *data, int num, char *buf, size_t buffersize,
|
||||
CURLcode *curlcode)
|
||||
{
|
||||
struct connectdata *conn = data->conn;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[num];
|
||||
char error_buffer[MESALINK_MAX_ERROR_SZ];
|
||||
int buffsize = (buffersize > (size_t)INT_MAX) ? INT_MAX : (int)buffersize;
|
||||
int nread = SSL_read(BACKEND->handle, buf, buffsize);
|
||||
|
||||
if(nread <= 0) {
|
||||
int err = SSL_get_error(BACKEND->handle, nread);
|
||||
|
||||
switch(err) {
|
||||
case SSL_ERROR_ZERO_RETURN: /* no more data */
|
||||
case IO_ERROR_CONNECTION_ABORTED:
|
||||
break;
|
||||
case SSL_ERROR_WANT_READ:
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
/* there's data pending, re-invoke SSL_read() */
|
||||
*curlcode = CURLE_AGAIN;
|
||||
return -1;
|
||||
default:
|
||||
failf(data,
|
||||
"SSL read: %s, errno %d",
|
||||
ERR_error_string_n(err, error_buffer, sizeof(error_buffer)),
|
||||
SOCKERRNO);
|
||||
*curlcode = CURLE_RECV_ERROR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return nread;
|
||||
}
|
||||
|
||||
static size_t
|
||||
mesalink_version(char *buffer, size_t size)
|
||||
{
|
||||
return msnprintf(buffer, size, "MesaLink/%s", MESALINK_VERSION_STRING);
|
||||
}
|
||||
|
||||
static int
|
||||
mesalink_init(void)
|
||||
{
|
||||
return (SSL_library_init() == SSL_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is called to shut down the SSL layer but keep the
|
||||
* socket open (CCC - Clear Command Channel)
|
||||
*/
|
||||
static int
|
||||
mesalink_shutdown(struct Curl_easy *data,
|
||||
struct connectdata *conn, int sockindex)
|
||||
{
|
||||
int retval = 0;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
|
||||
(void) data;
|
||||
|
||||
if(BACKEND->handle) {
|
||||
SSL_free(BACKEND->handle);
|
||||
BACKEND->handle = NULL;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static CURLcode
|
||||
mesalink_connect_common(struct Curl_easy *data, struct connectdata *conn,
|
||||
int sockindex, bool nonblocking, bool *done)
|
||||
{
|
||||
CURLcode result;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
curl_socket_t sockfd = conn->sock[sockindex];
|
||||
timediff_t timeout_ms;
|
||||
int what;
|
||||
|
||||
/* check if the connection has already been established */
|
||||
if(ssl_connection_complete == connssl->state) {
|
||||
*done = TRUE;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
if(ssl_connect_1 == connssl->connecting_state) {
|
||||
/* Find out how much more time we're allowed */
|
||||
timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
|
||||
if(timeout_ms < 0) {
|
||||
/* no need to continue if time already is up */
|
||||
failf(data, "SSL connection timeout");
|
||||
return CURLE_OPERATION_TIMEDOUT;
|
||||
}
|
||||
|
||||
result = mesalink_connect_step1(data, conn, sockindex);
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
|
||||
while(ssl_connect_2 == connssl->connecting_state ||
|
||||
ssl_connect_2_reading == connssl->connecting_state ||
|
||||
ssl_connect_2_writing == connssl->connecting_state) {
|
||||
|
||||
/* check allowed time left */
|
||||
timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
|
||||
if(timeout_ms < 0) {
|
||||
/* no need to continue if time already is up */
|
||||
failf(data, "SSL connection timeout");
|
||||
return CURLE_OPERATION_TIMEDOUT;
|
||||
}
|
||||
|
||||
/* if ssl is expecting something, check if it's available. */
|
||||
if(connssl->connecting_state == ssl_connect_2_reading ||
|
||||
connssl->connecting_state == ssl_connect_2_writing) {
|
||||
|
||||
curl_socket_t writefd =
|
||||
ssl_connect_2_writing == connssl->connecting_state ? sockfd
|
||||
: CURL_SOCKET_BAD;
|
||||
curl_socket_t readfd = ssl_connect_2_reading == connssl->connecting_state
|
||||
? sockfd
|
||||
: CURL_SOCKET_BAD;
|
||||
|
||||
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
|
||||
nonblocking ? 0 : timeout_ms);
|
||||
if(what < 0) {
|
||||
/* fatal error */
|
||||
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
||||
return CURLE_SSL_CONNECT_ERROR;
|
||||
}
|
||||
else if(0 == what) {
|
||||
if(nonblocking) {
|
||||
*done = FALSE;
|
||||
return CURLE_OK;
|
||||
}
|
||||
else {
|
||||
/* timeout */
|
||||
failf(data, "SSL connection timeout");
|
||||
return CURLE_OPERATION_TIMEDOUT;
|
||||
}
|
||||
}
|
||||
/* socket is readable or writable */
|
||||
}
|
||||
|
||||
/* Run transaction, and return to the caller if it failed or if
|
||||
* this connection is part of a multi handle and this loop would
|
||||
* execute again. This permits the owner of a multi handle to
|
||||
* abort a connection attempt before step2 has completed while
|
||||
* ensuring that a client using select() or epoll() will always
|
||||
* have a valid fdset to wait on.
|
||||
*/
|
||||
result = mesalink_connect_step2(data, conn, sockindex);
|
||||
|
||||
if(result ||
|
||||
(nonblocking && (ssl_connect_2 == connssl->connecting_state ||
|
||||
ssl_connect_2_reading == connssl->connecting_state ||
|
||||
ssl_connect_2_writing == connssl->connecting_state))) {
|
||||
return result;
|
||||
}
|
||||
} /* repeat step2 until all transactions are done. */
|
||||
|
||||
if(ssl_connect_3 == connssl->connecting_state) {
|
||||
result = mesalink_connect_step3(conn, sockindex);
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
|
||||
if(ssl_connect_done == connssl->connecting_state) {
|
||||
connssl->state = ssl_connection_complete;
|
||||
conn->recv[sockindex] = mesalink_recv;
|
||||
conn->send[sockindex] = mesalink_send;
|
||||
*done = TRUE;
|
||||
}
|
||||
else
|
||||
*done = FALSE;
|
||||
|
||||
/* Reset our connect state machine */
|
||||
connssl->connecting_state = ssl_connect_1;
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static CURLcode
|
||||
mesalink_connect_nonblocking(struct Curl_easy *data, struct connectdata *conn,
|
||||
int sockindex, bool *done)
|
||||
{
|
||||
return mesalink_connect_common(data, conn, sockindex, TRUE, done);
|
||||
}
|
||||
|
||||
static CURLcode
|
||||
mesalink_connect(struct Curl_easy *data, struct connectdata *conn,
|
||||
int sockindex)
|
||||
{
|
||||
CURLcode result;
|
||||
bool done = FALSE;
|
||||
|
||||
result = mesalink_connect_common(data, conn, sockindex, FALSE, &done);
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
DEBUGASSERT(done);
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static void *
|
||||
mesalink_get_internals(struct ssl_connect_data *connssl,
|
||||
CURLINFO info UNUSED_PARAM)
|
||||
{
|
||||
(void)info;
|
||||
return BACKEND->handle;
|
||||
}
|
||||
|
||||
const struct Curl_ssl Curl_ssl_mesalink = {
|
||||
{ CURLSSLBACKEND_MESALINK, "MesaLink" }, /* info */
|
||||
|
||||
SSLSUPP_SSL_CTX,
|
||||
|
||||
sizeof(struct ssl_backend_data),
|
||||
|
||||
mesalink_init, /* init */
|
||||
Curl_none_cleanup, /* cleanup */
|
||||
mesalink_version, /* version */
|
||||
Curl_none_check_cxn, /* check_cxn */
|
||||
mesalink_shutdown, /* shutdown */
|
||||
Curl_none_data_pending, /* data_pending */
|
||||
Curl_none_random, /* random */
|
||||
Curl_none_cert_status_request, /* cert_status_request */
|
||||
mesalink_connect, /* connect */
|
||||
mesalink_connect_nonblocking, /* connect_nonblocking */
|
||||
mesalink_get_internals, /* get_internals */
|
||||
mesalink_close, /* close_one */
|
||||
Curl_none_close_all, /* close_all */
|
||||
Curl_none_session_free, /* session_free */
|
||||
Curl_none_set_engine, /* set_engine */
|
||||
Curl_none_set_engine_default, /* set_engine_default */
|
||||
Curl_none_engines_list, /* engines_list */
|
||||
Curl_none_false_start, /* false_start */
|
||||
Curl_none_md5sum, /* md5sum */
|
||||
NULL /* sha256sum */
|
||||
};
|
||||
|
||||
#endif
|
||||
32
module/Vendor/CURL/lib/vtls/mesalink.h
vendored
Normal file
32
module/Vendor/CURL/lib/vtls/mesalink.h
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef HEADER_CURL_MESALINK_H
|
||||
#define HEADER_CURL_MESALINK_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2017 - 2018, Yiming Jing, <jingyiming@baidu.com>
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_MESALINK
|
||||
|
||||
extern const struct Curl_ssl Curl_ssl_mesalink;
|
||||
|
||||
#endif /* USE_MESALINK */
|
||||
#endif /* HEADER_CURL_MESALINK_H */
|
||||
2469
module/Vendor/CURL/lib/vtls/nss.c
vendored
Normal file
2469
module/Vendor/CURL/lib/vtls/nss.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
39
module/Vendor/CURL/lib/vtls/nssg.h
vendored
Normal file
39
module/Vendor/CURL/lib/vtls/nssg.h
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef HEADER_CURL_NSSG_H
|
||||
#define HEADER_CURL_NSSG_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_NSS
|
||||
/*
|
||||
* This header should only be needed to get included by vtls.c and nss.c
|
||||
*/
|
||||
|
||||
#include "urldata.h"
|
||||
|
||||
/* initialize NSS library if not already */
|
||||
CURLcode Curl_nss_force_init(struct Curl_easy *data);
|
||||
|
||||
extern const struct Curl_ssl Curl_ssl_nss;
|
||||
|
||||
#endif /* USE_NSS */
|
||||
#endif /* HEADER_CURL_NSSG_H */
|
||||
4504
module/Vendor/CURL/lib/vtls/openssl.c
vendored
Normal file
4504
module/Vendor/CURL/lib/vtls/openssl.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
37
module/Vendor/CURL/lib/vtls/openssl.h
vendored
Normal file
37
module/Vendor/CURL/lib/vtls/openssl.h
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef HEADER_CURL_SSLUSE_H
|
||||
#define HEADER_CURL_SSLUSE_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_OPENSSL
|
||||
/*
|
||||
* This header should only be needed to get included by vtls.c and openssl.c
|
||||
*/
|
||||
|
||||
#include "urldata.h"
|
||||
|
||||
extern const struct Curl_ssl Curl_ssl_openssl;
|
||||
|
||||
#endif /* USE_OPENSSL */
|
||||
#endif /* HEADER_CURL_SSLUSE_H */
|
||||
2442
module/Vendor/CURL/lib/vtls/schannel.c
vendored
Normal file
2442
module/Vendor/CURL/lib/vtls/schannel.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
109
module/Vendor/CURL/lib/vtls/schannel.h
vendored
Normal file
109
module/Vendor/CURL/lib/vtls/schannel.h
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
#ifndef HEADER_CURL_SCHANNEL_H
|
||||
#define HEADER_CURL_SCHANNEL_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2012, Marc Hoersken, <info@marc-hoersken.de>, et al.
|
||||
* Copyright (C) 2012 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_SCHANNEL
|
||||
|
||||
#include <schnlsp.h>
|
||||
#include <schannel.h>
|
||||
#include "curl_sspi.h"
|
||||
|
||||
#include "urldata.h"
|
||||
|
||||
/* <wincrypt.h> has been included via the above <schnlsp.h>.
|
||||
* Or in case of ldap.c, it was included via <winldap.h>.
|
||||
* And since <wincrypt.h> has this:
|
||||
* #define X509_NAME ((LPCSTR) 7)
|
||||
*
|
||||
* And in BoringSSL's <openssl/base.h> there is:
|
||||
* typedef struct X509_name_st X509_NAME;
|
||||
* etc.
|
||||
*
|
||||
* this will cause all kinds of C-preprocessing paste errors in
|
||||
* BoringSSL's <openssl/x509.h>: So just undefine those defines here
|
||||
* (and only here).
|
||||
*/
|
||||
#if defined(HAVE_BORINGSSL) || defined(OPENSSL_IS_BORINGSSL)
|
||||
# undef X509_NAME
|
||||
# undef X509_CERT_PAIR
|
||||
# undef X509_EXTENSIONS
|
||||
#endif
|
||||
|
||||
extern const struct Curl_ssl Curl_ssl_schannel;
|
||||
|
||||
CURLcode Curl_verify_certificate(struct Curl_easy *data,
|
||||
struct connectdata *conn, int sockindex);
|
||||
|
||||
/* structs to expose only in schannel.c and schannel_verify.c */
|
||||
#ifdef EXPOSE_SCHANNEL_INTERNAL_STRUCTS
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#include <_mingw.h>
|
||||
#ifdef __MINGW64_VERSION_MAJOR
|
||||
#define HAS_MANUAL_VERIFY_API
|
||||
#endif
|
||||
#else
|
||||
#include <wincrypt.h>
|
||||
#ifdef CERT_CHAIN_REVOCATION_CHECK_CHAIN
|
||||
#define HAS_MANUAL_VERIFY_API
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct Curl_schannel_cred {
|
||||
CredHandle cred_handle;
|
||||
TimeStamp time_stamp;
|
||||
int refcount;
|
||||
};
|
||||
|
||||
struct Curl_schannel_ctxt {
|
||||
CtxtHandle ctxt_handle;
|
||||
TimeStamp time_stamp;
|
||||
};
|
||||
|
||||
struct ssl_backend_data {
|
||||
struct Curl_schannel_cred *cred;
|
||||
struct Curl_schannel_ctxt *ctxt;
|
||||
SecPkgContext_StreamSizes stream_sizes;
|
||||
size_t encdata_length, decdata_length;
|
||||
size_t encdata_offset, decdata_offset;
|
||||
unsigned char *encdata_buffer, *decdata_buffer;
|
||||
/* encdata_is_incomplete: if encdata contains only a partial record that
|
||||
can't be decrypted without another Curl_read_plain (that is, status is
|
||||
SEC_E_INCOMPLETE_MESSAGE) then set this true. after Curl_read_plain writes
|
||||
more bytes into encdata then set this back to false. */
|
||||
bool encdata_is_incomplete;
|
||||
unsigned long req_flags, ret_flags;
|
||||
CURLcode recv_unrecoverable_err; /* schannel_recv had an unrecoverable err */
|
||||
bool recv_sspi_close_notify; /* true if connection closed by close_notify */
|
||||
bool recv_connection_closed; /* true if connection closed, regardless how */
|
||||
bool use_alpn; /* true if ALPN is used for this connection */
|
||||
#ifdef HAS_MANUAL_VERIFY_API
|
||||
bool use_manual_cred_validation; /* true if manual cred validation is used */
|
||||
#endif
|
||||
};
|
||||
#endif /* EXPOSE_SCHANNEL_INTERNAL_STRUCTS */
|
||||
|
||||
#endif /* USE_SCHANNEL */
|
||||
#endif /* HEADER_CURL_SCHANNEL_H */
|
||||
699
module/Vendor/CURL/lib/vtls/schannel_verify.c
vendored
Normal file
699
module/Vendor/CURL/lib/vtls/schannel_verify.c
vendored
Normal file
@@ -0,0 +1,699 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2012 - 2016, Marc Hoersken, <info@marc-hoersken.de>
|
||||
* Copyright (C) 2012, Mark Salisbury, <mark.salisbury@hp.com>
|
||||
* Copyright (C) 2012 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
* Source file for Schannel-specific certificate verification. This code should
|
||||
* only be invoked by code in schannel.c.
|
||||
*/
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_SCHANNEL
|
||||
#ifndef USE_WINDOWS_SSPI
|
||||
# error "Can't compile SCHANNEL support without SSPI."
|
||||
#endif
|
||||
|
||||
#define EXPOSE_SCHANNEL_INTERNAL_STRUCTS
|
||||
#include "schannel.h"
|
||||
|
||||
#ifdef HAS_MANUAL_VERIFY_API
|
||||
|
||||
#include "vtls.h"
|
||||
#include "sendf.h"
|
||||
#include "strerror.h"
|
||||
#include "curl_multibyte.h"
|
||||
#include "curl_printf.h"
|
||||
#include "hostcheck.h"
|
||||
#include "version_win32.h"
|
||||
|
||||
/* The last #include file should be: */
|
||||
#include "curl_memory.h"
|
||||
#include "memdebug.h"
|
||||
|
||||
#define BACKEND connssl->backend
|
||||
|
||||
#define MAX_CAFILE_SIZE 1048576 /* 1 MiB */
|
||||
#define BEGIN_CERT "-----BEGIN CERTIFICATE-----"
|
||||
#define END_CERT "\n-----END CERTIFICATE-----"
|
||||
|
||||
struct cert_chain_engine_config_win7 {
|
||||
DWORD cbSize;
|
||||
HCERTSTORE hRestrictedRoot;
|
||||
HCERTSTORE hRestrictedTrust;
|
||||
HCERTSTORE hRestrictedOther;
|
||||
DWORD cAdditionalStore;
|
||||
HCERTSTORE *rghAdditionalStore;
|
||||
DWORD dwFlags;
|
||||
DWORD dwUrlRetrievalTimeout;
|
||||
DWORD MaximumCachedCertificates;
|
||||
DWORD CycleDetectionModulus;
|
||||
HCERTSTORE hExclusiveRoot;
|
||||
HCERTSTORE hExclusiveTrustedPeople;
|
||||
};
|
||||
|
||||
static int is_cr_or_lf(char c)
|
||||
{
|
||||
return c == '\r' || c == '\n';
|
||||
}
|
||||
|
||||
static CURLcode add_certs_to_store(HCERTSTORE trust_store,
|
||||
const char *ca_file,
|
||||
struct Curl_easy *data)
|
||||
{
|
||||
CURLcode result;
|
||||
HANDLE ca_file_handle = INVALID_HANDLE_VALUE;
|
||||
LARGE_INTEGER file_size;
|
||||
char *ca_file_buffer = NULL;
|
||||
char *current_ca_file_ptr = NULL;
|
||||
TCHAR *ca_file_tstr = NULL;
|
||||
size_t ca_file_bufsize = 0;
|
||||
DWORD total_bytes_read = 0;
|
||||
bool more_certs = 0;
|
||||
int num_certs = 0;
|
||||
size_t END_CERT_LEN;
|
||||
|
||||
ca_file_tstr = curlx_convert_UTF8_to_tchar((char *)ca_file);
|
||||
if(!ca_file_tstr) {
|
||||
char buffer[STRERROR_LEN];
|
||||
failf(data,
|
||||
"schannel: invalid path name for CA file '%s': %s",
|
||||
ca_file,
|
||||
Curl_winapi_strerror(GetLastError(), buffer, sizeof(buffer)));
|
||||
result = CURLE_SSL_CACERT_BADFILE;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the CA file completely into memory before parsing it. This
|
||||
* optimizes for the common case where the CA file will be relatively
|
||||
* small ( < 1 MiB ).
|
||||
*/
|
||||
ca_file_handle = CreateFile(ca_file_tstr,
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL);
|
||||
if(ca_file_handle == INVALID_HANDLE_VALUE) {
|
||||
char buffer[STRERROR_LEN];
|
||||
failf(data,
|
||||
"schannel: failed to open CA file '%s': %s",
|
||||
ca_file,
|
||||
Curl_winapi_strerror(GetLastError(), buffer, sizeof(buffer)));
|
||||
result = CURLE_SSL_CACERT_BADFILE;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(!GetFileSizeEx(ca_file_handle, &file_size)) {
|
||||
char buffer[STRERROR_LEN];
|
||||
failf(data,
|
||||
"schannel: failed to determine size of CA file '%s': %s",
|
||||
ca_file,
|
||||
Curl_winapi_strerror(GetLastError(), buffer, sizeof(buffer)));
|
||||
result = CURLE_SSL_CACERT_BADFILE;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(file_size.QuadPart > MAX_CAFILE_SIZE) {
|
||||
failf(data,
|
||||
"schannel: CA file exceeds max size of %u bytes",
|
||||
MAX_CAFILE_SIZE);
|
||||
result = CURLE_SSL_CACERT_BADFILE;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ca_file_bufsize = (size_t)file_size.QuadPart;
|
||||
ca_file_buffer = (char *)malloc(ca_file_bufsize + 1);
|
||||
if(!ca_file_buffer) {
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
result = CURLE_OK;
|
||||
while(total_bytes_read < ca_file_bufsize) {
|
||||
DWORD bytes_to_read = (DWORD)(ca_file_bufsize - total_bytes_read);
|
||||
DWORD bytes_read = 0;
|
||||
|
||||
if(!ReadFile(ca_file_handle, ca_file_buffer + total_bytes_read,
|
||||
bytes_to_read, &bytes_read, NULL)) {
|
||||
char buffer[STRERROR_LEN];
|
||||
failf(data,
|
||||
"schannel: failed to read from CA file '%s': %s",
|
||||
ca_file,
|
||||
Curl_winapi_strerror(GetLastError(), buffer, sizeof(buffer)));
|
||||
result = CURLE_SSL_CACERT_BADFILE;
|
||||
goto cleanup;
|
||||
}
|
||||
if(bytes_read == 0) {
|
||||
/* Premature EOF -- adjust the bufsize to the new value */
|
||||
ca_file_bufsize = total_bytes_read;
|
||||
}
|
||||
else {
|
||||
total_bytes_read += bytes_read;
|
||||
}
|
||||
}
|
||||
|
||||
/* Null terminate the buffer */
|
||||
ca_file_buffer[ca_file_bufsize] = '\0';
|
||||
|
||||
if(result != CURLE_OK) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
END_CERT_LEN = strlen(END_CERT);
|
||||
|
||||
more_certs = 1;
|
||||
current_ca_file_ptr = ca_file_buffer;
|
||||
while(more_certs && *current_ca_file_ptr != '\0') {
|
||||
char *begin_cert_ptr = strstr(current_ca_file_ptr, BEGIN_CERT);
|
||||
if(!begin_cert_ptr || !is_cr_or_lf(begin_cert_ptr[strlen(BEGIN_CERT)])) {
|
||||
more_certs = 0;
|
||||
}
|
||||
else {
|
||||
char *end_cert_ptr = strstr(begin_cert_ptr, END_CERT);
|
||||
if(!end_cert_ptr) {
|
||||
failf(data,
|
||||
"schannel: CA file '%s' is not correctly formatted",
|
||||
ca_file);
|
||||
result = CURLE_SSL_CACERT_BADFILE;
|
||||
more_certs = 0;
|
||||
}
|
||||
else {
|
||||
CERT_BLOB cert_blob;
|
||||
CERT_CONTEXT *cert_context = NULL;
|
||||
BOOL add_cert_result = FALSE;
|
||||
DWORD actual_content_type = 0;
|
||||
DWORD cert_size = (DWORD)
|
||||
((end_cert_ptr + END_CERT_LEN) - begin_cert_ptr);
|
||||
|
||||
cert_blob.pbData = (BYTE *)begin_cert_ptr;
|
||||
cert_blob.cbData = cert_size;
|
||||
if(!CryptQueryObject(CERT_QUERY_OBJECT_BLOB,
|
||||
&cert_blob,
|
||||
CERT_QUERY_CONTENT_FLAG_CERT,
|
||||
CERT_QUERY_FORMAT_FLAG_ALL,
|
||||
0,
|
||||
NULL,
|
||||
&actual_content_type,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
(const void **)&cert_context)) {
|
||||
char buffer[STRERROR_LEN];
|
||||
failf(data,
|
||||
"schannel: failed to extract certificate from CA file "
|
||||
"'%s': %s",
|
||||
ca_file,
|
||||
Curl_winapi_strerror(GetLastError(), buffer, sizeof(buffer)));
|
||||
result = CURLE_SSL_CACERT_BADFILE;
|
||||
more_certs = 0;
|
||||
}
|
||||
else {
|
||||
current_ca_file_ptr = begin_cert_ptr + cert_size;
|
||||
|
||||
/* Sanity check that the cert_context object is the right type */
|
||||
if(CERT_QUERY_CONTENT_CERT != actual_content_type) {
|
||||
failf(data,
|
||||
"schannel: unexpected content type '%d' when extracting "
|
||||
"certificate from CA file '%s'",
|
||||
actual_content_type, ca_file);
|
||||
result = CURLE_SSL_CACERT_BADFILE;
|
||||
more_certs = 0;
|
||||
}
|
||||
else {
|
||||
add_cert_result =
|
||||
CertAddCertificateContextToStore(trust_store,
|
||||
cert_context,
|
||||
CERT_STORE_ADD_ALWAYS,
|
||||
NULL);
|
||||
CertFreeCertificateContext(cert_context);
|
||||
if(!add_cert_result) {
|
||||
char buffer[STRERROR_LEN];
|
||||
failf(data,
|
||||
"schannel: failed to add certificate from CA file '%s' "
|
||||
"to certificate store: %s",
|
||||
ca_file,
|
||||
Curl_winapi_strerror(GetLastError(), buffer,
|
||||
sizeof(buffer)));
|
||||
result = CURLE_SSL_CACERT_BADFILE;
|
||||
more_certs = 0;
|
||||
}
|
||||
else {
|
||||
num_certs++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(result == CURLE_OK) {
|
||||
if(!num_certs) {
|
||||
infof(data,
|
||||
"schannel: did not add any certificates from CA file '%s'\n",
|
||||
ca_file);
|
||||
}
|
||||
else {
|
||||
infof(data,
|
||||
"schannel: added %d certificate(s) from CA file '%s'\n",
|
||||
num_certs, ca_file);
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if(ca_file_handle != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(ca_file_handle);
|
||||
}
|
||||
Curl_safefree(ca_file_buffer);
|
||||
curlx_unicodefree(ca_file_tstr);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the number of characters necessary to populate all the host_names.
|
||||
* If host_names is not NULL, populate it with all the host names. Each string
|
||||
* in the host_names is null-terminated and the last string is double
|
||||
* null-terminated. If no DNS names are found, a single null-terminated empty
|
||||
* string is returned.
|
||||
*/
|
||||
static DWORD cert_get_name_string(struct Curl_easy *data,
|
||||
CERT_CONTEXT *cert_context,
|
||||
LPTSTR host_names,
|
||||
DWORD length)
|
||||
{
|
||||
DWORD actual_length = 0;
|
||||
BOOL compute_content = FALSE;
|
||||
CERT_INFO *cert_info = NULL;
|
||||
CERT_EXTENSION *extension = NULL;
|
||||
CRYPT_DECODE_PARA decode_para = {0, 0, 0};
|
||||
CERT_ALT_NAME_INFO *alt_name_info = NULL;
|
||||
DWORD alt_name_info_size = 0;
|
||||
BOOL ret_val = FALSE;
|
||||
LPTSTR current_pos = NULL;
|
||||
DWORD i;
|
||||
|
||||
/* CERT_NAME_SEARCH_ALL_NAMES_FLAG is available from Windows 8 onwards. */
|
||||
if(curlx_verify_windows_version(6, 2, PLATFORM_WINNT,
|
||||
VERSION_GREATER_THAN_EQUAL)) {
|
||||
#ifdef CERT_NAME_SEARCH_ALL_NAMES_FLAG
|
||||
/* CertGetNameString will provide the 8-bit character string without
|
||||
* any decoding */
|
||||
DWORD name_flags =
|
||||
CERT_NAME_DISABLE_IE4_UTF8_FLAG | CERT_NAME_SEARCH_ALL_NAMES_FLAG;
|
||||
actual_length = CertGetNameString(cert_context,
|
||||
CERT_NAME_DNS_TYPE,
|
||||
name_flags,
|
||||
NULL,
|
||||
host_names,
|
||||
length);
|
||||
return actual_length;
|
||||
#endif
|
||||
}
|
||||
|
||||
compute_content = host_names != NULL && length != 0;
|
||||
|
||||
/* Initialize default return values. */
|
||||
actual_length = 1;
|
||||
if(compute_content) {
|
||||
*host_names = '\0';
|
||||
}
|
||||
|
||||
if(!cert_context) {
|
||||
failf(data, "schannel: Null certificate context.");
|
||||
return actual_length;
|
||||
}
|
||||
|
||||
cert_info = cert_context->pCertInfo;
|
||||
if(!cert_info) {
|
||||
failf(data, "schannel: Null certificate info.");
|
||||
return actual_length;
|
||||
}
|
||||
|
||||
extension = CertFindExtension(szOID_SUBJECT_ALT_NAME2,
|
||||
cert_info->cExtension,
|
||||
cert_info->rgExtension);
|
||||
if(!extension) {
|
||||
failf(data, "schannel: CertFindExtension() returned no extension.");
|
||||
return actual_length;
|
||||
}
|
||||
|
||||
decode_para.cbSize = sizeof(CRYPT_DECODE_PARA);
|
||||
|
||||
ret_val =
|
||||
CryptDecodeObjectEx(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
|
||||
szOID_SUBJECT_ALT_NAME2,
|
||||
extension->Value.pbData,
|
||||
extension->Value.cbData,
|
||||
CRYPT_DECODE_ALLOC_FLAG | CRYPT_DECODE_NOCOPY_FLAG,
|
||||
&decode_para,
|
||||
&alt_name_info,
|
||||
&alt_name_info_size);
|
||||
if(!ret_val) {
|
||||
failf(data,
|
||||
"schannel: CryptDecodeObjectEx() returned no alternate name "
|
||||
"information.");
|
||||
return actual_length;
|
||||
}
|
||||
|
||||
current_pos = host_names;
|
||||
|
||||
/* Iterate over the alternate names and populate host_names. */
|
||||
for(i = 0; i < alt_name_info->cAltEntry; i++) {
|
||||
const CERT_ALT_NAME_ENTRY *entry = &alt_name_info->rgAltEntry[i];
|
||||
wchar_t *dns_w = NULL;
|
||||
size_t current_length = 0;
|
||||
|
||||
if(entry->dwAltNameChoice != CERT_ALT_NAME_DNS_NAME) {
|
||||
continue;
|
||||
}
|
||||
if(entry->pwszDNSName == NULL) {
|
||||
infof(data, "schannel: Empty DNS name.");
|
||||
continue;
|
||||
}
|
||||
current_length = wcslen(entry->pwszDNSName) + 1;
|
||||
if(!compute_content) {
|
||||
actual_length += (DWORD)current_length;
|
||||
continue;
|
||||
}
|
||||
/* Sanity check to prevent buffer overrun. */
|
||||
if((actual_length + current_length) > length) {
|
||||
failf(data, "schannel: Not enough memory to list all host names.");
|
||||
break;
|
||||
}
|
||||
dns_w = entry->pwszDNSName;
|
||||
/* pwszDNSName is in ia5 string format and hence doesn't contain any
|
||||
* non-ascii characters. */
|
||||
while(*dns_w != '\0') {
|
||||
*current_pos++ = (char)(*dns_w++);
|
||||
}
|
||||
*current_pos++ = '\0';
|
||||
actual_length += (DWORD)current_length;
|
||||
}
|
||||
if(compute_content) {
|
||||
/* Last string has double null-terminator. */
|
||||
*current_pos = '\0';
|
||||
}
|
||||
return actual_length;
|
||||
}
|
||||
|
||||
static CURLcode verify_host(struct Curl_easy *data,
|
||||
CERT_CONTEXT *pCertContextServer,
|
||||
const char * const conn_hostname)
|
||||
{
|
||||
CURLcode result = CURLE_PEER_FAILED_VERIFICATION;
|
||||
TCHAR *cert_hostname_buff = NULL;
|
||||
size_t cert_hostname_buff_index = 0;
|
||||
DWORD len = 0;
|
||||
DWORD actual_len = 0;
|
||||
|
||||
/* Determine the size of the string needed for the cert hostname */
|
||||
len = cert_get_name_string(data, pCertContextServer, NULL, 0);
|
||||
if(len == 0) {
|
||||
failf(data,
|
||||
"schannel: CertGetNameString() returned no "
|
||||
"certificate name information");
|
||||
result = CURLE_PEER_FAILED_VERIFICATION;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* CertGetNameString guarantees that the returned name will not contain
|
||||
* embedded null bytes. This appears to be undocumented behavior.
|
||||
*/
|
||||
cert_hostname_buff = (LPTSTR)malloc(len * sizeof(TCHAR));
|
||||
if(!cert_hostname_buff) {
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
goto cleanup;
|
||||
}
|
||||
actual_len = cert_get_name_string(
|
||||
data, pCertContextServer, (LPTSTR)cert_hostname_buff, len);
|
||||
|
||||
/* Sanity check */
|
||||
if(actual_len != len) {
|
||||
failf(data,
|
||||
"schannel: CertGetNameString() returned certificate "
|
||||
"name information of unexpected size");
|
||||
result = CURLE_PEER_FAILED_VERIFICATION;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* If HAVE_CERT_NAME_SEARCH_ALL_NAMES is available, the output
|
||||
* will contain all DNS names, where each name is null-terminated
|
||||
* and the last DNS name is double null-terminated. Due to this
|
||||
* encoding, use the length of the buffer to iterate over all names.
|
||||
*/
|
||||
result = CURLE_PEER_FAILED_VERIFICATION;
|
||||
while(cert_hostname_buff_index < len &&
|
||||
cert_hostname_buff[cert_hostname_buff_index] != TEXT('\0') &&
|
||||
result == CURLE_PEER_FAILED_VERIFICATION) {
|
||||
|
||||
char *cert_hostname;
|
||||
|
||||
/* Comparing the cert name and the connection hostname encoded as UTF-8
|
||||
* is acceptable since both values are assumed to use ASCII
|
||||
* (or some equivalent) encoding
|
||||
*/
|
||||
cert_hostname = curlx_convert_tchar_to_UTF8(
|
||||
&cert_hostname_buff[cert_hostname_buff_index]);
|
||||
if(!cert_hostname) {
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
else {
|
||||
int match_result;
|
||||
|
||||
match_result = Curl_cert_hostcheck(cert_hostname, conn_hostname);
|
||||
if(match_result == CURL_HOST_MATCH) {
|
||||
infof(data,
|
||||
"schannel: connection hostname (%s) validated "
|
||||
"against certificate name (%s)\n",
|
||||
conn_hostname, cert_hostname);
|
||||
result = CURLE_OK;
|
||||
}
|
||||
else {
|
||||
size_t cert_hostname_len;
|
||||
|
||||
infof(data,
|
||||
"schannel: connection hostname (%s) did not match "
|
||||
"against certificate name (%s)\n",
|
||||
conn_hostname, cert_hostname);
|
||||
|
||||
cert_hostname_len =
|
||||
_tcslen(&cert_hostname_buff[cert_hostname_buff_index]);
|
||||
|
||||
/* Move on to next cert name */
|
||||
cert_hostname_buff_index += cert_hostname_len + 1;
|
||||
|
||||
result = CURLE_PEER_FAILED_VERIFICATION;
|
||||
}
|
||||
curlx_unicodefree(cert_hostname);
|
||||
}
|
||||
}
|
||||
|
||||
if(result == CURLE_PEER_FAILED_VERIFICATION) {
|
||||
failf(data,
|
||||
"schannel: CertGetNameString() failed to match "
|
||||
"connection hostname (%s) against server certificate names",
|
||||
conn_hostname);
|
||||
}
|
||||
else if(result != CURLE_OK)
|
||||
failf(data, "schannel: server certificate name verification failed");
|
||||
|
||||
cleanup:
|
||||
Curl_safefree(cert_hostname_buff);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CURLcode Curl_verify_certificate(struct Curl_easy *data,
|
||||
struct connectdata *conn, int sockindex)
|
||||
{
|
||||
SECURITY_STATUS sspi_status;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
CURLcode result = CURLE_OK;
|
||||
CERT_CONTEXT *pCertContextServer = NULL;
|
||||
const CERT_CHAIN_CONTEXT *pChainContext = NULL;
|
||||
HCERTCHAINENGINE cert_chain_engine = NULL;
|
||||
HCERTSTORE trust_store = NULL;
|
||||
#ifndef CURL_DISABLE_PROXY
|
||||
const char * const conn_hostname = SSL_IS_PROXY() ?
|
||||
conn->http_proxy.host.name :
|
||||
conn->host.name;
|
||||
#else
|
||||
const char * const conn_hostname = conn->host.name;
|
||||
#endif
|
||||
|
||||
sspi_status =
|
||||
s_pSecFn->QueryContextAttributes(&BACKEND->ctxt->ctxt_handle,
|
||||
SECPKG_ATTR_REMOTE_CERT_CONTEXT,
|
||||
&pCertContextServer);
|
||||
|
||||
if((sspi_status != SEC_E_OK) || (pCertContextServer == NULL)) {
|
||||
char buffer[STRERROR_LEN];
|
||||
failf(data, "schannel: Failed to read remote certificate context: %s",
|
||||
Curl_sspi_strerror(sspi_status, buffer, sizeof(buffer)));
|
||||
result = CURLE_PEER_FAILED_VERIFICATION;
|
||||
}
|
||||
|
||||
if(result == CURLE_OK && SSL_CONN_CONFIG(CAfile) &&
|
||||
BACKEND->use_manual_cred_validation) {
|
||||
/*
|
||||
* Create a chain engine that uses the certificates in the CA file as
|
||||
* trusted certificates. This is only supported on Windows 7+.
|
||||
*/
|
||||
|
||||
if(curlx_verify_windows_version(6, 1, PLATFORM_WINNT, VERSION_LESS_THAN)) {
|
||||
failf(data, "schannel: this version of Windows is too old to support "
|
||||
"certificate verification via CA bundle file.");
|
||||
result = CURLE_SSL_CACERT_BADFILE;
|
||||
}
|
||||
else {
|
||||
/* Open the certificate store */
|
||||
trust_store = CertOpenStore(CERT_STORE_PROV_MEMORY,
|
||||
0,
|
||||
(HCRYPTPROV)NULL,
|
||||
CERT_STORE_CREATE_NEW_FLAG,
|
||||
NULL);
|
||||
if(!trust_store) {
|
||||
char buffer[STRERROR_LEN];
|
||||
failf(data, "schannel: failed to create certificate store: %s",
|
||||
Curl_winapi_strerror(GetLastError(), buffer, sizeof(buffer)));
|
||||
result = CURLE_SSL_CACERT_BADFILE;
|
||||
}
|
||||
else {
|
||||
result = add_certs_to_store(trust_store, SSL_CONN_CONFIG(CAfile),
|
||||
data);
|
||||
}
|
||||
}
|
||||
|
||||
if(result == CURLE_OK) {
|
||||
struct cert_chain_engine_config_win7 engine_config;
|
||||
BOOL create_engine_result;
|
||||
|
||||
memset(&engine_config, 0, sizeof(engine_config));
|
||||
engine_config.cbSize = sizeof(engine_config);
|
||||
engine_config.hExclusiveRoot = trust_store;
|
||||
|
||||
/* CertCreateCertificateChainEngine will check the expected size of the
|
||||
* CERT_CHAIN_ENGINE_CONFIG structure and fail if the specified size
|
||||
* does not match the expected size. When this occurs, it indicates that
|
||||
* CAINFO is not supported on the version of Windows in use.
|
||||
*/
|
||||
create_engine_result =
|
||||
CertCreateCertificateChainEngine(
|
||||
(CERT_CHAIN_ENGINE_CONFIG *)&engine_config, &cert_chain_engine);
|
||||
if(!create_engine_result) {
|
||||
char buffer[STRERROR_LEN];
|
||||
failf(data,
|
||||
"schannel: failed to create certificate chain engine: %s",
|
||||
Curl_winapi_strerror(GetLastError(), buffer, sizeof(buffer)));
|
||||
result = CURLE_SSL_CACERT_BADFILE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(result == CURLE_OK) {
|
||||
CERT_CHAIN_PARA ChainPara;
|
||||
|
||||
memset(&ChainPara, 0, sizeof(ChainPara));
|
||||
ChainPara.cbSize = sizeof(ChainPara);
|
||||
|
||||
if(!CertGetCertificateChain(cert_chain_engine,
|
||||
pCertContextServer,
|
||||
NULL,
|
||||
pCertContextServer->hCertStore,
|
||||
&ChainPara,
|
||||
(data->set.ssl.no_revoke ? 0 :
|
||||
CERT_CHAIN_REVOCATION_CHECK_CHAIN),
|
||||
NULL,
|
||||
&pChainContext)) {
|
||||
char buffer[STRERROR_LEN];
|
||||
failf(data, "schannel: CertGetCertificateChain failed: %s",
|
||||
Curl_winapi_strerror(GetLastError(), buffer, sizeof(buffer)));
|
||||
pChainContext = NULL;
|
||||
result = CURLE_PEER_FAILED_VERIFICATION;
|
||||
}
|
||||
|
||||
if(result == CURLE_OK) {
|
||||
CERT_SIMPLE_CHAIN *pSimpleChain = pChainContext->rgpChain[0];
|
||||
DWORD dwTrustErrorMask = ~(DWORD)(CERT_TRUST_IS_NOT_TIME_NESTED);
|
||||
dwTrustErrorMask &= pSimpleChain->TrustStatus.dwErrorStatus;
|
||||
|
||||
if(data->set.ssl.revoke_best_effort) {
|
||||
/* Ignore errors when root certificates are missing the revocation
|
||||
* list URL, or when the list could not be downloaded because the
|
||||
* server is currently unreachable. */
|
||||
dwTrustErrorMask &= ~(DWORD)(CERT_TRUST_REVOCATION_STATUS_UNKNOWN |
|
||||
CERT_TRUST_IS_OFFLINE_REVOCATION);
|
||||
}
|
||||
|
||||
if(dwTrustErrorMask) {
|
||||
if(dwTrustErrorMask & CERT_TRUST_IS_REVOKED)
|
||||
failf(data, "schannel: CertGetCertificateChain trust error"
|
||||
" CERT_TRUST_IS_REVOKED");
|
||||
else if(dwTrustErrorMask & CERT_TRUST_IS_PARTIAL_CHAIN)
|
||||
failf(data, "schannel: CertGetCertificateChain trust error"
|
||||
" CERT_TRUST_IS_PARTIAL_CHAIN");
|
||||
else if(dwTrustErrorMask & CERT_TRUST_IS_UNTRUSTED_ROOT)
|
||||
failf(data, "schannel: CertGetCertificateChain trust error"
|
||||
" CERT_TRUST_IS_UNTRUSTED_ROOT");
|
||||
else if(dwTrustErrorMask & CERT_TRUST_IS_NOT_TIME_VALID)
|
||||
failf(data, "schannel: CertGetCertificateChain trust error"
|
||||
" CERT_TRUST_IS_NOT_TIME_VALID");
|
||||
else if(dwTrustErrorMask & CERT_TRUST_REVOCATION_STATUS_UNKNOWN)
|
||||
failf(data, "schannel: CertGetCertificateChain trust error"
|
||||
" CERT_TRUST_REVOCATION_STATUS_UNKNOWN");
|
||||
else
|
||||
failf(data, "schannel: CertGetCertificateChain error mask: 0x%08x",
|
||||
dwTrustErrorMask);
|
||||
result = CURLE_PEER_FAILED_VERIFICATION;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(result == CURLE_OK) {
|
||||
if(SSL_CONN_CONFIG(verifyhost)) {
|
||||
result = verify_host(data, pCertContextServer, conn_hostname);
|
||||
}
|
||||
}
|
||||
|
||||
if(cert_chain_engine) {
|
||||
CertFreeCertificateChainEngine(cert_chain_engine);
|
||||
}
|
||||
|
||||
if(trust_store) {
|
||||
CertCloseStore(trust_store, 0);
|
||||
}
|
||||
|
||||
if(pChainContext)
|
||||
CertFreeCertificateChain(pChainContext);
|
||||
|
||||
if(pCertContextServer)
|
||||
CertFreeCertificateContext(pCertContextServer);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif /* HAS_MANUAL_VERIFY_API */
|
||||
#endif /* USE_SCHANNEL */
|
||||
3330
module/Vendor/CURL/lib/vtls/sectransp.c
vendored
Normal file
3330
module/Vendor/CURL/lib/vtls/sectransp.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
32
module/Vendor/CURL/lib/vtls/sectransp.h
vendored
Normal file
32
module/Vendor/CURL/lib/vtls/sectransp.h
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef HEADER_CURL_SECTRANSP_H
|
||||
#define HEADER_CURL_SECTRANSP_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2012 - 2014, Nick Zitzmann, <nickzman@gmail.com>.
|
||||
* Copyright (C) 2012 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_SECTRANSP
|
||||
|
||||
extern const struct Curl_ssl Curl_ssl_sectransp;
|
||||
|
||||
#endif /* USE_SECTRANSP */
|
||||
#endif /* HEADER_CURL_SECTRANSP_H */
|
||||
1437
module/Vendor/CURL/lib/vtls/vtls.c
vendored
Normal file
1437
module/Vendor/CURL/lib/vtls/vtls.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
302
module/Vendor/CURL/lib/vtls/vtls.h
vendored
Normal file
302
module/Vendor/CURL/lib/vtls/vtls.h
vendored
Normal file
@@ -0,0 +1,302 @@
|
||||
#ifndef HEADER_CURL_VTLS_H
|
||||
#define HEADER_CURL_VTLS_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
struct connectdata;
|
||||
struct ssl_connect_data;
|
||||
|
||||
#define SSLSUPP_CA_PATH (1<<0) /* supports CAPATH */
|
||||
#define SSLSUPP_CERTINFO (1<<1) /* supports CURLOPT_CERTINFO */
|
||||
#define SSLSUPP_PINNEDPUBKEY (1<<2) /* supports CURLOPT_PINNEDPUBLICKEY */
|
||||
#define SSLSUPP_SSL_CTX (1<<3) /* supports CURLOPT_SSL_CTX */
|
||||
#define SSLSUPP_HTTPS_PROXY (1<<4) /* supports access via HTTPS proxies */
|
||||
#define SSLSUPP_TLS13_CIPHERSUITES (1<<5) /* supports TLS 1.3 ciphersuites */
|
||||
|
||||
struct Curl_ssl {
|
||||
/*
|
||||
* This *must* be the first entry to allow returning the list of available
|
||||
* backends in curl_global_sslset().
|
||||
*/
|
||||
curl_ssl_backend info;
|
||||
unsigned int supports; /* bitfield, see above */
|
||||
size_t sizeof_ssl_backend_data;
|
||||
|
||||
int (*init)(void);
|
||||
void (*cleanup)(void);
|
||||
|
||||
size_t (*version)(char *buffer, size_t size);
|
||||
int (*check_cxn)(struct connectdata *cxn);
|
||||
int (*shut_down)(struct Curl_easy *data, struct connectdata *conn,
|
||||
int sockindex);
|
||||
bool (*data_pending)(const struct connectdata *conn,
|
||||
int connindex);
|
||||
|
||||
/* return 0 if a find random is filled in */
|
||||
CURLcode (*random)(struct Curl_easy *data, unsigned char *entropy,
|
||||
size_t length);
|
||||
bool (*cert_status_request)(void);
|
||||
|
||||
CURLcode (*connect_blocking)(struct Curl_easy *data,
|
||||
struct connectdata *conn, int sockindex);
|
||||
CURLcode (*connect_nonblocking)(struct Curl_easy *data,
|
||||
struct connectdata *conn, int sockindex,
|
||||
bool *done);
|
||||
void *(*get_internals)(struct ssl_connect_data *connssl, CURLINFO info);
|
||||
void (*close_one)(struct Curl_easy *data, struct connectdata *conn,
|
||||
int sockindex);
|
||||
void (*close_all)(struct Curl_easy *data);
|
||||
void (*session_free)(void *ptr);
|
||||
|
||||
CURLcode (*set_engine)(struct Curl_easy *data, const char *engine);
|
||||
CURLcode (*set_engine_default)(struct Curl_easy *data);
|
||||
struct curl_slist *(*engines_list)(struct Curl_easy *data);
|
||||
|
||||
bool (*false_start)(void);
|
||||
|
||||
CURLcode (*md5sum)(unsigned char *input, size_t inputlen,
|
||||
unsigned char *md5sum, size_t md5sumlen);
|
||||
CURLcode (*sha256sum)(const unsigned char *input, size_t inputlen,
|
||||
unsigned char *sha256sum, size_t sha256sumlen);
|
||||
};
|
||||
|
||||
#ifdef USE_SSL
|
||||
extern const struct Curl_ssl *Curl_ssl;
|
||||
#endif
|
||||
|
||||
int Curl_none_init(void);
|
||||
void Curl_none_cleanup(void);
|
||||
int Curl_none_shutdown(struct Curl_easy *data, struct connectdata *conn,
|
||||
int sockindex);
|
||||
int Curl_none_check_cxn(struct connectdata *conn);
|
||||
CURLcode Curl_none_random(struct Curl_easy *data, unsigned char *entropy,
|
||||
size_t length);
|
||||
void Curl_none_close_all(struct Curl_easy *data);
|
||||
void Curl_none_session_free(void *ptr);
|
||||
bool Curl_none_data_pending(const struct connectdata *conn, int connindex);
|
||||
bool Curl_none_cert_status_request(void);
|
||||
CURLcode Curl_none_set_engine(struct Curl_easy *data, const char *engine);
|
||||
CURLcode Curl_none_set_engine_default(struct Curl_easy *data);
|
||||
struct curl_slist *Curl_none_engines_list(struct Curl_easy *data);
|
||||
bool Curl_none_false_start(void);
|
||||
bool Curl_ssl_tls13_ciphersuites(void);
|
||||
CURLcode Curl_none_md5sum(unsigned char *input, size_t inputlen,
|
||||
unsigned char *md5sum, size_t md5len);
|
||||
|
||||
#include "openssl.h" /* OpenSSL versions */
|
||||
#include "gtls.h" /* GnuTLS versions */
|
||||
#include "nssg.h" /* NSS versions */
|
||||
#include "gskit.h" /* Global Secure ToolKit versions */
|
||||
#include "wolfssl.h" /* wolfSSL versions */
|
||||
#include "schannel.h" /* Schannel SSPI version */
|
||||
#include "sectransp.h" /* SecureTransport (Darwin) version */
|
||||
#include "mbedtls.h" /* mbedTLS versions */
|
||||
#include "mesalink.h" /* MesaLink versions */
|
||||
#include "bearssl.h" /* BearSSL versions */
|
||||
|
||||
#ifndef MAX_PINNED_PUBKEY_SIZE
|
||||
#define MAX_PINNED_PUBKEY_SIZE 1048576 /* 1MB */
|
||||
#endif
|
||||
|
||||
#ifndef CURL_SHA256_DIGEST_LENGTH
|
||||
#define CURL_SHA256_DIGEST_LENGTH 32 /* fixed size */
|
||||
#endif
|
||||
|
||||
/* see https://tools.ietf.org/html/draft-ietf-tls-applayerprotoneg-04 */
|
||||
#define ALPN_HTTP_1_1_LENGTH 8
|
||||
#define ALPN_HTTP_1_1 "http/1.1"
|
||||
|
||||
/* set of helper macros for the backends to access the correct fields. For the
|
||||
proxy or for the remote host - to properly support HTTPS proxy */
|
||||
#ifndef CURL_DISABLE_PROXY
|
||||
#define SSL_IS_PROXY() \
|
||||
(CURLPROXY_HTTPS == conn->http_proxy.proxytype && \
|
||||
ssl_connection_complete != \
|
||||
conn->proxy_ssl[conn->sock[SECONDARYSOCKET] == \
|
||||
CURL_SOCKET_BAD ? FIRSTSOCKET : SECONDARYSOCKET].state)
|
||||
#define SSL_SET_OPTION(var) \
|
||||
(SSL_IS_PROXY() ? data->set.proxy_ssl.var : data->set.ssl.var)
|
||||
#define SSL_SET_OPTION_LVALUE(var) \
|
||||
(*(SSL_IS_PROXY() ? &data->set.proxy_ssl.var : &data->set.ssl.var))
|
||||
#define SSL_CONN_CONFIG(var) \
|
||||
(SSL_IS_PROXY() ? conn->proxy_ssl_config.var : conn->ssl_config.var)
|
||||
#define SSL_HOST_NAME() \
|
||||
(SSL_IS_PROXY() ? conn->http_proxy.host.name : conn->host.name)
|
||||
#define SSL_HOST_DISPNAME() \
|
||||
(SSL_IS_PROXY() ? conn->http_proxy.host.dispname : conn->host.dispname)
|
||||
#define SSL_PINNED_PUB_KEY() (SSL_IS_PROXY() \
|
||||
? data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] \
|
||||
: data->set.str[STRING_SSL_PINNEDPUBLICKEY_ORIG])
|
||||
#else
|
||||
#define SSL_IS_PROXY() FALSE
|
||||
#define SSL_SET_OPTION(var) data->set.ssl.var
|
||||
#define SSL_SET_OPTION_LVALUE(var) data->set.ssl.var
|
||||
#define SSL_CONN_CONFIG(var) conn->ssl_config.var
|
||||
#define SSL_HOST_NAME() conn->host.name
|
||||
#define SSL_HOST_DISPNAME() conn->host.dispname
|
||||
#define SSL_PINNED_PUB_KEY() \
|
||||
data->set.str[STRING_SSL_PINNEDPUBLICKEY_ORIG]
|
||||
#endif
|
||||
|
||||
bool Curl_ssl_config_matches(struct ssl_primary_config *data,
|
||||
struct ssl_primary_config *needle);
|
||||
bool Curl_clone_primary_ssl_config(struct ssl_primary_config *source,
|
||||
struct ssl_primary_config *dest);
|
||||
void Curl_free_primary_ssl_config(struct ssl_primary_config *sslc);
|
||||
int Curl_ssl_getsock(struct connectdata *conn, curl_socket_t *socks);
|
||||
|
||||
int Curl_ssl_backend(void);
|
||||
|
||||
#ifdef USE_SSL
|
||||
int Curl_ssl_init(void);
|
||||
void Curl_ssl_cleanup(void);
|
||||
CURLcode Curl_ssl_connect(struct Curl_easy *data, struct connectdata *conn,
|
||||
int sockindex);
|
||||
CURLcode Curl_ssl_connect_nonblocking(struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
int sockindex,
|
||||
bool *done);
|
||||
/* tell the SSL stuff to close down all open information regarding
|
||||
connections (and thus session ID caching etc) */
|
||||
void Curl_ssl_close_all(struct Curl_easy *data);
|
||||
void Curl_ssl_close(struct Curl_easy *data, struct connectdata *conn,
|
||||
int sockindex);
|
||||
CURLcode Curl_ssl_shutdown(struct Curl_easy *data, struct connectdata *conn,
|
||||
int sockindex);
|
||||
CURLcode Curl_ssl_set_engine(struct Curl_easy *data, const char *engine);
|
||||
/* Sets engine as default for all SSL operations */
|
||||
CURLcode Curl_ssl_set_engine_default(struct Curl_easy *data);
|
||||
struct curl_slist *Curl_ssl_engines_list(struct Curl_easy *data);
|
||||
|
||||
/* init the SSL session ID cache */
|
||||
CURLcode Curl_ssl_initsessions(struct Curl_easy *, size_t);
|
||||
size_t Curl_ssl_version(char *buffer, size_t size);
|
||||
bool Curl_ssl_data_pending(const struct connectdata *conn,
|
||||
int connindex);
|
||||
int Curl_ssl_check_cxn(struct connectdata *conn);
|
||||
|
||||
/* Certificate information list handling. */
|
||||
|
||||
void Curl_ssl_free_certinfo(struct Curl_easy *data);
|
||||
CURLcode Curl_ssl_init_certinfo(struct Curl_easy *data, int num);
|
||||
CURLcode Curl_ssl_push_certinfo_len(struct Curl_easy *data, int certnum,
|
||||
const char *label, const char *value,
|
||||
size_t valuelen);
|
||||
CURLcode Curl_ssl_push_certinfo(struct Curl_easy *data, int certnum,
|
||||
const char *label, const char *value);
|
||||
|
||||
/* Functions to be used by SSL library adaptation functions */
|
||||
|
||||
/* Lock session cache mutex.
|
||||
* Call this before calling other Curl_ssl_*session* functions
|
||||
* Caller should unlock this mutex as soon as possible, as it may block
|
||||
* other SSL connection from making progress.
|
||||
* The purpose of explicitly locking SSL session cache data is to allow
|
||||
* individual SSL engines to manage session lifetime in their specific way.
|
||||
*/
|
||||
void Curl_ssl_sessionid_lock(struct Curl_easy *data);
|
||||
|
||||
/* Unlock session cache mutex */
|
||||
void Curl_ssl_sessionid_unlock(struct Curl_easy *data);
|
||||
|
||||
/* extract a session ID
|
||||
* Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
|
||||
* Caller must make sure that the ownership of returned sessionid object
|
||||
* is properly taken (e.g. its refcount is incremented
|
||||
* under sessionid mutex).
|
||||
*/
|
||||
bool Curl_ssl_getsessionid(struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
void **ssl_sessionid,
|
||||
size_t *idsize, /* set 0 if unknown */
|
||||
int sockindex);
|
||||
/* add a new session ID
|
||||
* Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
|
||||
* Caller must ensure that it has properly shared ownership of this sessionid
|
||||
* object with cache (e.g. incrementing refcount on success)
|
||||
*/
|
||||
CURLcode Curl_ssl_addsessionid(struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
void *ssl_sessionid,
|
||||
size_t idsize,
|
||||
int sockindex);
|
||||
/* Kill a single session ID entry in the cache
|
||||
* Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
|
||||
* This will call engine-specific curlssl_session_free function, which must
|
||||
* take sessionid object ownership from sessionid cache
|
||||
* (e.g. decrement refcount).
|
||||
*/
|
||||
void Curl_ssl_kill_session(struct Curl_ssl_session *session);
|
||||
/* delete a session from the cache
|
||||
* Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
|
||||
* This will call engine-specific curlssl_session_free function, which must
|
||||
* take sessionid object ownership from sessionid cache
|
||||
* (e.g. decrement refcount).
|
||||
*/
|
||||
void Curl_ssl_delsessionid(struct Curl_easy *data, void *ssl_sessionid);
|
||||
|
||||
/* get N random bytes into the buffer */
|
||||
CURLcode Curl_ssl_random(struct Curl_easy *data, unsigned char *buffer,
|
||||
size_t length);
|
||||
CURLcode Curl_ssl_md5sum(unsigned char *tmp, /* input */
|
||||
size_t tmplen,
|
||||
unsigned char *md5sum, /* output */
|
||||
size_t md5len);
|
||||
/* Check pinned public key. */
|
||||
CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
|
||||
const char *pinnedpubkey,
|
||||
const unsigned char *pubkey, size_t pubkeylen);
|
||||
|
||||
bool Curl_ssl_cert_status_request(void);
|
||||
|
||||
bool Curl_ssl_false_start(void);
|
||||
|
||||
#define SSL_SHUTDOWN_TIMEOUT 10000 /* ms */
|
||||
|
||||
#else /* if not USE_SSL */
|
||||
|
||||
/* When SSL support is not present, just define away these function calls */
|
||||
#define Curl_ssl_init() 1
|
||||
#define Curl_ssl_cleanup() Curl_nop_stmt
|
||||
#define Curl_ssl_connect(x,y,z) CURLE_NOT_BUILT_IN
|
||||
#define Curl_ssl_close_all(x) Curl_nop_stmt
|
||||
#define Curl_ssl_close(x,y,z) Curl_nop_stmt
|
||||
#define Curl_ssl_shutdown(x,y,z) CURLE_NOT_BUILT_IN
|
||||
#define Curl_ssl_set_engine(x,y) CURLE_NOT_BUILT_IN
|
||||
#define Curl_ssl_set_engine_default(x) CURLE_NOT_BUILT_IN
|
||||
#define Curl_ssl_engines_list(x) NULL
|
||||
#define Curl_ssl_send(a,b,c,d,e) -1
|
||||
#define Curl_ssl_recv(a,b,c,d,e) -1
|
||||
#define Curl_ssl_initsessions(x,y) CURLE_OK
|
||||
#define Curl_ssl_data_pending(x,y) 0
|
||||
#define Curl_ssl_check_cxn(x) 0
|
||||
#define Curl_ssl_free_certinfo(x) Curl_nop_stmt
|
||||
#define Curl_ssl_connect_nonblocking(x,y,z,w) CURLE_NOT_BUILT_IN
|
||||
#define Curl_ssl_kill_session(x) Curl_nop_stmt
|
||||
#define Curl_ssl_random(x,y,z) ((void)x, CURLE_NOT_BUILT_IN)
|
||||
#define Curl_ssl_cert_status_request() FALSE
|
||||
#define Curl_ssl_false_start() FALSE
|
||||
#define Curl_ssl_tls13_ciphersuites() FALSE
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_CURL_VTLS_H */
|
||||
1167
module/Vendor/CURL/lib/vtls/wolfssl.c
vendored
Normal file
1167
module/Vendor/CURL/lib/vtls/wolfssl.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
31
module/Vendor/CURL/lib/vtls/wolfssl.h
vendored
Normal file
31
module/Vendor/CURL/lib/vtls/wolfssl.h
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef HEADER_CURL_WOLFSSL_H
|
||||
#define HEADER_CURL_WOLFSSL_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_WOLFSSL
|
||||
|
||||
extern const struct Curl_ssl Curl_ssl_wolfssl;
|
||||
|
||||
#endif /* USE_WOLFSSL */
|
||||
#endif /* HEADER_CURL_WOLFSSL_H */
|
||||
Reference in New Issue
Block a user