2011-02-28 21:02:47 -05:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2018-04-25 05:45:35 -04:00
|
|
|
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2011-02-28 21:02:47 -05:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-02 18:19:02 -05:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2011-02-28 21:02:47 -05:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Source file for all CyaSSL-specific code for the TLS/SSL layer. No code
|
2013-12-25 05:30:51 -05:00
|
|
|
* but vtls.c should ever call or use these functions.
|
2011-02-28 21:02:47 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-01-06 13:06:49 -05:00
|
|
|
#include "curl_setup.h"
|
2011-07-26 11:23:27 -04:00
|
|
|
|
2011-02-28 21:02:47 -05:00
|
|
|
#ifdef USE_CYASSL
|
|
|
|
|
2015-04-17 15:22:48 -04:00
|
|
|
#define WOLFSSL_OPTIONS_IGNORE_SYS
|
|
|
|
/* CyaSSL's version.h, which should contain only the version, should come
|
|
|
|
before all other CyaSSL includes and be immediately followed by build config
|
2016-02-02 18:19:02 -05:00
|
|
|
aka options.h. https://curl.haxx.se/mail/lib-2015-04/0069.html */
|
2015-04-17 15:22:48 -04:00
|
|
|
#include <cyassl/version.h>
|
|
|
|
#if defined(HAVE_CYASSL_OPTIONS_H) && (LIBCYASSL_VERSION_HEX > 0x03004008)
|
|
|
|
#if defined(CYASSL_API) || defined(WOLFSSL_API)
|
|
|
|
/* Safety measure. If either is defined some API include was already included
|
|
|
|
and that's a problem since options.h hasn't been included yet. */
|
|
|
|
#error "CyaSSL API was included before the CyaSSL build options."
|
|
|
|
#endif
|
|
|
|
#include <cyassl/options.h>
|
|
|
|
#endif
|
|
|
|
|
2017-06-02 17:02:54 -04:00
|
|
|
/* To determine what functions are available we rely on one or both of:
|
|
|
|
- the user's options.h generated by CyaSSL/wolfSSL
|
|
|
|
- the symbols detected by curl's configure
|
|
|
|
Since they are markedly different from one another, and one or the other may
|
|
|
|
not be available, we do some checking below to bring things in sync. */
|
|
|
|
|
|
|
|
/* HAVE_ALPN is wolfSSL's build time symbol for enabling ALPN in options.h. */
|
|
|
|
#ifndef HAVE_ALPN
|
|
|
|
#ifdef HAVE_WOLFSSL_USEALPN
|
|
|
|
#define HAVE_ALPN
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* WOLFSSL_ALLOW_SSLV3 is wolfSSL's build time symbol for enabling SSLv3 in
|
|
|
|
options.h, but is only seen in >= 3.6.6 since that's when they started
|
|
|
|
disabling SSLv3 by default. */
|
|
|
|
#ifndef WOLFSSL_ALLOW_SSLV3
|
|
|
|
#if (LIBCYASSL_VERSION_HEX < 0x03006006) || \
|
|
|
|
defined(HAVE_WOLFSSLV3_CLIENT_METHOD)
|
|
|
|
#define WOLFSSL_ALLOW_SSLV3
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* HAVE_SUPPORTED_CURVES is wolfSSL's build time symbol for enabling the ECC
|
|
|
|
supported curve extension in options.h. Note ECC is enabled separately. */
|
|
|
|
#ifndef HAVE_SUPPORTED_CURVES
|
|
|
|
#if defined(HAVE_CYASSL_CTX_USESUPPORTEDCURVE) || \
|
|
|
|
defined(HAVE_WOLFSSL_CTX_USESUPPORTEDCURVE)
|
|
|
|
#define HAVE_SUPPORTED_CURVES
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2011-08-24 08:00:42 -04:00
|
|
|
#include <limits.h>
|
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "urldata.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "inet_pton.h"
|
2013-12-25 05:20:39 -05:00
|
|
|
#include "vtls.h"
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "parsedate.h"
|
|
|
|
#include "connect.h" /* for the connect timeout */
|
|
|
|
#include "select.h"
|
2016-10-31 07:51:45 -04:00
|
|
|
#include "strcase.h"
|
2015-04-05 01:48:16 -04:00
|
|
|
#include "x509asn1.h"
|
2015-03-03 17:17:43 -05:00
|
|
|
#include "curl_printf.h"
|
2014-04-23 05:01:30 -04:00
|
|
|
|
vtls: encapsulate SSL backend-specific data
So far, all of the SSL backends' private data has been declared as
part of the ssl_connect_data struct, in one big #if .. #elif .. #endif
block.
This can only work as long as the SSL backend is a compile-time option,
something we want to change in the next commits.
Therefore, let's encapsulate the exact data needed by each SSL backend
into a private struct, and let's avoid bleeding any SSL backend-specific
information into urldata.h. This is also necessary to allow multiple SSL
backends to be compiled in at the same time, as e.g. OpenSSL's and
CyaSSL's headers cannot be included in the same .c file.
To avoid too many malloc() calls, we simply append the private structs
to the connectdata struct in allocate_conn().
This requires us to take extra care of alignment issues: struct fields
often need to be aligned on certain boundaries e.g. 32-bit values need to
be stored at addresses that divide evenly by 4 (= 32 bit / 8
bit-per-byte).
We do that by assuming that no SSL backend's private data contains any
fields that need to be aligned on boundaries larger than `long long`
(typically 64-bit) would need. Under this assumption, we simply add a
dummy field of type `long long` to the `struct connectdata` struct. This
field will never be accessed but acts as a placeholder for the four
instances of ssl_backend_data instead. the size of each ssl_backend_data
struct is stored in the SSL backend-specific metadata, to allow
allocate_conn() to know how much extra space to allocate, and how to
initialize the ssl[sockindex]->backend and proxy_ssl[sockindex]->backend
pointers.
This would appear to be a little complicated at first, but is really
necessary to encapsulate the private data of each SSL backend correctly.
And we need to encapsulate thusly if we ever want to allow selecting
CyaSSL and OpenSSL at runtime, as their headers cannot be included within
the same .c file (there are just too many conflicting definitions and
declarations for that).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-07-28 16:09:35 -04:00
|
|
|
#include <cyassl/openssl/ssl.h>
|
2012-11-02 21:06:51 -04:00
|
|
|
#include <cyassl/ssl.h>
|
2014-04-23 05:01:30 -04:00
|
|
|
#ifdef HAVE_CYASSL_ERROR_SSL_H
|
|
|
|
#include <cyassl/error-ssl.h>
|
|
|
|
#else
|
2012-11-02 21:06:51 -04:00
|
|
|
#include <cyassl/error.h>
|
2014-04-23 05:01:30 -04:00
|
|
|
#endif
|
2014-07-30 18:09:13 -04:00
|
|
|
#include <cyassl/ctaocrypt/random.h>
|
2015-06-30 20:23:54 -04:00
|
|
|
#include <cyassl/ctaocrypt/sha256.h>
|
2011-02-28 21:02:47 -05:00
|
|
|
|
2016-05-01 11:05:38 -04:00
|
|
|
#include "cyassl.h"
|
|
|
|
|
2015-03-24 18:12:03 -04:00
|
|
|
/* The last #include files should be: */
|
|
|
|
#include "curl_memory.h"
|
2014-04-23 05:01:30 -04:00
|
|
|
#include "memdebug.h"
|
2011-02-28 21:02:47 -05:00
|
|
|
|
2015-04-04 02:12:03 -04:00
|
|
|
#if LIBCYASSL_VERSION_HEX < 0x02007002 /* < 2.7.2 */
|
|
|
|
#define CYASSL_MAX_ERROR_SZ 80
|
|
|
|
#endif
|
|
|
|
|
2017-06-20 05:32:53 -04:00
|
|
|
/* KEEP_PEER_CERT is a product of the presence of build time symbol
|
|
|
|
OPENSSL_EXTRA without NO_CERTS, depending on the version. KEEP_PEER_CERT is
|
|
|
|
in wolfSSL's settings.h, and the latter two are build time symbols in
|
|
|
|
options.h. */
|
|
|
|
#ifndef KEEP_PEER_CERT
|
|
|
|
#if defined(HAVE_CYASSL_GET_PEER_CERTIFICATE) || \
|
|
|
|
defined(HAVE_WOLFSSL_GET_PEER_CERTIFICATE) || \
|
|
|
|
(defined(OPENSSL_EXTRA) && !defined(NO_CERTS))
|
|
|
|
#define KEEP_PEER_CERT
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
vtls: encapsulate SSL backend-specific data
So far, all of the SSL backends' private data has been declared as
part of the ssl_connect_data struct, in one big #if .. #elif .. #endif
block.
This can only work as long as the SSL backend is a compile-time option,
something we want to change in the next commits.
Therefore, let's encapsulate the exact data needed by each SSL backend
into a private struct, and let's avoid bleeding any SSL backend-specific
information into urldata.h. This is also necessary to allow multiple SSL
backends to be compiled in at the same time, as e.g. OpenSSL's and
CyaSSL's headers cannot be included in the same .c file.
To avoid too many malloc() calls, we simply append the private structs
to the connectdata struct in allocate_conn().
This requires us to take extra care of alignment issues: struct fields
often need to be aligned on certain boundaries e.g. 32-bit values need to
be stored at addresses that divide evenly by 4 (= 32 bit / 8
bit-per-byte).
We do that by assuming that no SSL backend's private data contains any
fields that need to be aligned on boundaries larger than `long long`
(typically 64-bit) would need. Under this assumption, we simply add a
dummy field of type `long long` to the `struct connectdata` struct. This
field will never be accessed but acts as a placeholder for the four
instances of ssl_backend_data instead. the size of each ssl_backend_data
struct is stored in the SSL backend-specific metadata, to allow
allocate_conn() to know how much extra space to allocate, and how to
initialize the ssl[sockindex]->backend and proxy_ssl[sockindex]->backend
pointers.
This would appear to be a little complicated at first, but is really
necessary to encapsulate the private data of each SSL backend correctly.
And we need to encapsulate thusly if we ever want to allow selecting
CyaSSL and OpenSSL at runtime, as their headers cannot be included within
the same .c file (there are just too many conflicting definitions and
declarations for that).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-07-28 16:09:35 -04:00
|
|
|
struct ssl_backend_data {
|
|
|
|
SSL_CTX* ctx;
|
|
|
|
SSL* handle;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BACKEND connssl->backend
|
2017-06-21 06:41:18 -04:00
|
|
|
|
2011-02-28 21:02:47 -05:00
|
|
|
static Curl_recv cyassl_recv;
|
|
|
|
static Curl_send cyassl_send;
|
|
|
|
|
|
|
|
|
|
|
|
static int do_file_type(const char *type)
|
|
|
|
{
|
|
|
|
if(!type || !type[0])
|
|
|
|
return SSL_FILETYPE_PEM;
|
2016-09-30 12:54:02 -04:00
|
|
|
if(strcasecompare(type, "PEM"))
|
2011-02-28 21:02:47 -05:00
|
|
|
return SSL_FILETYPE_PEM;
|
2016-09-30 12:54:02 -04:00
|
|
|
if(strcasecompare(type, "DER"))
|
2011-02-28 21:02:47 -05:00
|
|
|
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
|
|
|
|
cyassl_connect_step1(struct connectdata *conn,
|
|
|
|
int sockindex)
|
|
|
|
{
|
2015-04-04 02:12:03 -04:00
|
|
|
char error_buffer[CYASSL_MAX_ERROR_SZ];
|
2017-01-06 17:00:45 -05:00
|
|
|
char *ciphers;
|
2016-06-21 09:47:12 -04:00
|
|
|
struct Curl_easy *data = conn->data;
|
2017-06-21 06:41:18 -04:00
|
|
|
struct ssl_connect_data* connssl = &conn->ssl[sockindex];
|
2011-02-28 21:02:47 -05:00
|
|
|
SSL_METHOD* req_method = NULL;
|
|
|
|
curl_socket_t sockfd = conn->sock[sockindex];
|
2015-04-13 01:07:28 -04:00
|
|
|
#ifdef HAVE_SNI
|
|
|
|
bool sni = FALSE;
|
|
|
|
#define use_sni(x) sni = (x)
|
|
|
|
#else
|
|
|
|
#define use_sni(x) Curl_nop_stmt
|
|
|
|
#endif
|
2011-02-28 21:02:47 -05:00
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
if(connssl->state == ssl_connection_complete)
|
2011-02-28 21:02:47 -05:00
|
|
|
return CURLE_OK;
|
|
|
|
|
2016-12-13 15:10:00 -05:00
|
|
|
if(SSL_CONN_CONFIG(version_max) != CURL_SSLVERSION_MAX_NONE) {
|
|
|
|
failf(data, "CyaSSL does not support to set maximum SSL/TLS version");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-02-28 21:02:47 -05:00
|
|
|
/* check to see if we've been told to use an explicit SSL/TLS version */
|
2016-11-16 12:49:15 -05:00
|
|
|
switch(SSL_CONN_CONFIG(version)) {
|
2011-02-28 21:02:47 -05:00
|
|
|
case CURL_SSLVERSION_DEFAULT:
|
|
|
|
case CURL_SSLVERSION_TLSv1:
|
2015-04-03 02:11:35 -04:00
|
|
|
#if LIBCYASSL_VERSION_HEX >= 0x03003000 /* >= 3.3.0 */
|
|
|
|
/* minimum protocol version is set later after the CTX object is created */
|
2015-03-25 02:40:00 -04:00
|
|
|
req_method = SSLv23_client_method();
|
|
|
|
#else
|
|
|
|
infof(data, "CyaSSL <3.3.0 cannot be configured to use TLS 1.0-1.2, "
|
2013-09-19 09:17:13 -04:00
|
|
|
"TLS 1.0 is used exclusively\n");
|
2011-02-28 21:02:47 -05:00
|
|
|
req_method = TLSv1_client_method();
|
2015-03-25 02:40:00 -04:00
|
|
|
#endif
|
2015-04-13 01:07:28 -04:00
|
|
|
use_sni(TRUE);
|
2011-02-28 21:02:47 -05:00
|
|
|
break;
|
2013-09-19 09:17:13 -04:00
|
|
|
case CURL_SSLVERSION_TLSv1_0:
|
2018-04-25 05:45:35 -04:00
|
|
|
#ifdef WOLFSSL_ALLOW_TLSV10
|
2013-09-19 09:17:13 -04:00
|
|
|
req_method = TLSv1_client_method();
|
2015-04-13 01:07:28 -04:00
|
|
|
use_sni(TRUE);
|
2018-04-25 05:45:35 -04:00
|
|
|
#else
|
|
|
|
failf(data, "CyaSSL does not support TLS 1.0");
|
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
#endif
|
2013-09-19 09:17:13 -04:00
|
|
|
break;
|
|
|
|
case CURL_SSLVERSION_TLSv1_1:
|
|
|
|
req_method = TLSv1_1_client_method();
|
2015-04-13 01:07:28 -04:00
|
|
|
use_sni(TRUE);
|
2013-09-19 09:17:13 -04:00
|
|
|
break;
|
|
|
|
case CURL_SSLVERSION_TLSv1_2:
|
|
|
|
req_method = TLSv1_2_client_method();
|
2015-04-13 01:07:28 -04:00
|
|
|
use_sni(TRUE);
|
2013-09-19 09:17:13 -04:00
|
|
|
break;
|
2016-11-07 21:51:27 -05:00
|
|
|
case CURL_SSLVERSION_TLSv1_3:
|
2018-03-01 13:10:36 -05:00
|
|
|
#ifdef WOLFSSL_TLS13
|
|
|
|
req_method = wolfTLSv1_3_client_method();
|
|
|
|
use_sni(TRUE);
|
|
|
|
break;
|
|
|
|
#else
|
2016-11-07 21:51:27 -05:00
|
|
|
failf(data, "CyaSSL: TLS 1.3 is not yet supported");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
2018-03-01 13:10:36 -05:00
|
|
|
#endif
|
2011-02-28 21:02:47 -05:00
|
|
|
case CURL_SSLVERSION_SSLv3:
|
2016-03-28 18:18:09 -04:00
|
|
|
#ifdef WOLFSSL_ALLOW_SSLV3
|
2011-02-28 21:02:47 -05:00
|
|
|
req_method = SSLv3_client_method();
|
2015-04-13 01:07:28 -04:00
|
|
|
use_sni(FALSE);
|
2015-12-16 04:06:09 -05:00
|
|
|
#else
|
2016-11-07 21:51:27 -05:00
|
|
|
failf(data, "CyaSSL does not support SSLv3");
|
2015-12-16 04:06:09 -05:00
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
#endif
|
2011-02-28 21:02:47 -05:00
|
|
|
break;
|
2015-03-25 02:40:00 -04:00
|
|
|
case CURL_SSLVERSION_SSLv2:
|
|
|
|
failf(data, "CyaSSL does not support SSLv2");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
default:
|
|
|
|
failf(data, "Unrecognized parameter passed via CURLOPT_SSLVERSION");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!req_method) {
|
|
|
|
failf(data, "SSL: couldn't create a method!");
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
if(BACKEND->ctx)
|
|
|
|
SSL_CTX_free(BACKEND->ctx);
|
|
|
|
BACKEND->ctx = SSL_CTX_new(req_method);
|
2011-02-28 21:02:47 -05:00
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
if(!BACKEND->ctx) {
|
2011-02-28 21:02:47 -05:00
|
|
|
failf(data, "SSL: couldn't create a context!");
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
switch(SSL_CONN_CONFIG(version)) {
|
2015-04-03 02:11:35 -04:00
|
|
|
case CURL_SSLVERSION_DEFAULT:
|
|
|
|
case CURL_SSLVERSION_TLSv1:
|
|
|
|
#if LIBCYASSL_VERSION_HEX > 0x03004006 /* > 3.4.6 */
|
|
|
|
/* Versions 3.3.0 to 3.4.6 we know the minimum protocol version is whatever
|
|
|
|
minimum version of TLS was built in and at least TLS 1.0. For later library
|
|
|
|
versions that could change (eg TLS 1.0 built in but defaults to TLS 1.1) so
|
|
|
|
we have this short circuit evaluation to find the minimum supported TLS
|
|
|
|
version. We use wolfSSL_CTX_SetMinVersion and not CyaSSL_SetMinVersion
|
|
|
|
because only the former will work before the user's CTX callback is called.
|
|
|
|
*/
|
2017-06-21 06:41:18 -04:00
|
|
|
if((wolfSSL_CTX_SetMinVersion(BACKEND->ctx, WOLFSSL_TLSV1) != 1) &&
|
|
|
|
(wolfSSL_CTX_SetMinVersion(BACKEND->ctx, WOLFSSL_TLSV1_1) != 1) &&
|
2018-03-01 13:10:36 -05:00
|
|
|
(wolfSSL_CTX_SetMinVersion(BACKEND->ctx, WOLFSSL_TLSV1_2) != 1)
|
|
|
|
#ifdef WOLFSSL_TLS13
|
|
|
|
&& (wolfSSL_CTX_SetMinVersion(BACKEND->ctx, WOLFSSL_TLSV1_3) != 1)
|
|
|
|
#endif
|
|
|
|
) {
|
2015-04-03 02:11:35 -04:00
|
|
|
failf(data, "SSL: couldn't set the minimum protocol version");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:00:45 -05:00
|
|
|
ciphers = SSL_CONN_CONFIG(cipher_list);
|
|
|
|
if(ciphers) {
|
2017-06-21 06:41:18 -04:00
|
|
|
if(!SSL_CTX_set_cipher_list(BACKEND->ctx, ciphers)) {
|
2017-01-06 17:00:45 -05:00
|
|
|
failf(data, "failed setting cipher list: %s", ciphers);
|
|
|
|
return CURLE_SSL_CIPHER;
|
|
|
|
}
|
|
|
|
infof(data, "Cipher selection: %s\n", ciphers);
|
|
|
|
}
|
|
|
|
|
2011-05-20 17:40:59 -04:00
|
|
|
#ifndef NO_FILESYSTEM
|
2011-02-28 21:02:47 -05:00
|
|
|
/* load trusted cacert */
|
2016-11-16 12:49:15 -05:00
|
|
|
if(SSL_CONN_CONFIG(CAfile)) {
|
2017-06-21 06:41:18 -04:00
|
|
|
if(1 != SSL_CTX_load_verify_locations(BACKEND->ctx,
|
2016-11-16 12:49:15 -05:00
|
|
|
SSL_CONN_CONFIG(CAfile),
|
|
|
|
SSL_CONN_CONFIG(CApath))) {
|
|
|
|
if(SSL_CONN_CONFIG(verifypeer)) {
|
2014-07-22 18:43:47 -04:00
|
|
|
/* Fail if we insist on successfully verifying the server. */
|
2015-03-17 08:41:49 -04:00
|
|
|
failf(data, "error setting certificate verify locations:\n"
|
2012-06-14 07:32:05 -04:00
|
|
|
" CAfile: %s\n CApath: %s",
|
2016-11-16 12:49:15 -05:00
|
|
|
SSL_CONN_CONFIG(CAfile)?
|
|
|
|
SSL_CONN_CONFIG(CAfile): "none",
|
|
|
|
SSL_CONN_CONFIG(CApath)?
|
|
|
|
SSL_CONN_CONFIG(CApath) : "none");
|
2011-02-28 21:02:47 -05:00
|
|
|
return CURLE_SSL_CACERT_BADFILE;
|
|
|
|
}
|
|
|
|
else {
|
2014-07-22 18:43:47 -04:00
|
|
|
/* Just continue with a warning if no strict certificate
|
2011-02-28 21:02:47 -05:00
|
|
|
verification is required. */
|
|
|
|
infof(data, "error setting certificate verify locations,"
|
|
|
|
" continuing anyway:\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Everything is fine. */
|
|
|
|
infof(data, "successfully set certificate verify locations:\n");
|
|
|
|
}
|
|
|
|
infof(data,
|
|
|
|
" CAfile: %s\n"
|
|
|
|
" CApath: %s\n",
|
2016-11-16 12:49:15 -05:00
|
|
|
SSL_CONN_CONFIG(CAfile) ? SSL_CONN_CONFIG(CAfile):
|
2011-02-28 21:02:47 -05:00
|
|
|
"none",
|
2016-11-16 12:49:15 -05:00
|
|
|
SSL_CONN_CONFIG(CApath) ? SSL_CONN_CONFIG(CApath):
|
2011-02-28 21:02:47 -05:00
|
|
|
"none");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the client certificate, and private key */
|
2016-11-16 12:49:15 -05:00
|
|
|
if(SSL_SET_OPTION(cert) && SSL_SET_OPTION(key)) {
|
|
|
|
int file_type = do_file_type(SSL_SET_OPTION(cert_type));
|
2011-02-28 21:02:47 -05:00
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
if(SSL_CTX_use_certificate_file(BACKEND->ctx, SSL_SET_OPTION(cert),
|
2011-02-28 21:02:47 -05:00
|
|
|
file_type) != 1) {
|
|
|
|
failf(data, "unable to use client certificate (no key or wrong pass"
|
|
|
|
" phrase?)");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
file_type = do_file_type(SSL_SET_OPTION(key_type));
|
2017-06-21 06:41:18 -04:00
|
|
|
if(SSL_CTX_use_PrivateKey_file(BACKEND->ctx, SSL_SET_OPTION(key),
|
2011-02-28 21:02:47 -05:00
|
|
|
file_type) != 1) {
|
|
|
|
failf(data, "unable to set private key");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2015-03-28 00:16:08 -04:00
|
|
|
#endif /* !NO_FILESYSTEM */
|
2011-02-28 21:02:47 -05:00
|
|
|
|
|
|
|
/* SSL always tries to verify the peer, this only says whether it should
|
|
|
|
* fail to connect if the verification fails, or if it should continue
|
|
|
|
* anyway. In the latter case the result of the verification is checked with
|
|
|
|
* SSL_get_verify_result() below. */
|
2017-06-21 06:41:18 -04:00
|
|
|
SSL_CTX_set_verify(BACKEND->ctx,
|
2016-11-16 12:49:15 -05:00
|
|
|
SSL_CONN_CONFIG(verifypeer)?SSL_VERIFY_PEER:
|
|
|
|
SSL_VERIFY_NONE,
|
2011-02-28 21:02:47 -05:00
|
|
|
NULL);
|
|
|
|
|
2015-04-13 01:07:28 -04:00
|
|
|
#ifdef HAVE_SNI
|
|
|
|
if(sni) {
|
|
|
|
struct in_addr addr4;
|
|
|
|
#ifdef ENABLE_IPV6
|
|
|
|
struct in6_addr addr6;
|
|
|
|
#endif
|
2016-11-16 12:49:15 -05:00
|
|
|
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
|
|
|
|
conn->host.name;
|
|
|
|
size_t hostname_len = strlen(hostname);
|
2015-04-13 01:07:28 -04:00
|
|
|
if((hostname_len < USHRT_MAX) &&
|
2016-11-16 12:49:15 -05:00
|
|
|
(0 == Curl_inet_pton(AF_INET, hostname, &addr4)) &&
|
2015-04-13 01:07:28 -04:00
|
|
|
#ifdef ENABLE_IPV6
|
2016-11-16 12:49:15 -05:00
|
|
|
(0 == Curl_inet_pton(AF_INET6, hostname, &addr6)) &&
|
2015-04-13 01:07:28 -04:00
|
|
|
#endif
|
2017-06-21 06:41:18 -04:00
|
|
|
(CyaSSL_CTX_UseSNI(BACKEND->ctx, CYASSL_SNI_HOST_NAME, hostname,
|
2015-04-13 01:07:28 -04:00
|
|
|
(unsigned short)hostname_len) != 1)) {
|
|
|
|
infof(data, "WARNING: failed to configure server name indication (SNI) "
|
|
|
|
"TLS extension\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-03-29 19:06:55 -04:00
|
|
|
#ifdef HAVE_SUPPORTED_CURVES
|
|
|
|
/* CyaSSL/wolfSSL does not send the supported ECC curves ext automatically:
|
|
|
|
https://github.com/wolfSSL/wolfssl/issues/366
|
|
|
|
The supported curves below are those also supported by OpenSSL 1.0.2 and
|
|
|
|
in the same order. */
|
2017-06-21 06:41:18 -04:00
|
|
|
CyaSSL_CTX_UseSupportedCurve(BACKEND->ctx, 0x17); /* secp256r1 */
|
|
|
|
CyaSSL_CTX_UseSupportedCurve(BACKEND->ctx, 0x19); /* secp521r1 */
|
|
|
|
CyaSSL_CTX_UseSupportedCurve(BACKEND->ctx, 0x18); /* secp384r1 */
|
2016-03-29 19:06:55 -04:00
|
|
|
#endif
|
|
|
|
|
2015-03-27 07:22:32 -04:00
|
|
|
/* give application a chance to interfere with SSL set up. */
|
|
|
|
if(data->set.ssl.fsslctx) {
|
|
|
|
CURLcode result = CURLE_OK;
|
2017-06-21 06:41:18 -04:00
|
|
|
result = (*data->set.ssl.fsslctx)(data, BACKEND->ctx,
|
2015-03-28 00:16:08 -04:00
|
|
|
data->set.ssl.fsslctxp);
|
2015-03-27 07:22:32 -04:00
|
|
|
if(result) {
|
|
|
|
failf(data, "error signaled by ssl ctx callback");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef NO_FILESYSTEM
|
2016-11-16 12:49:15 -05:00
|
|
|
else if(SSL_CONN_CONFIG(verifypeer)) {
|
2015-03-28 00:16:08 -04:00
|
|
|
failf(data, "SSL: Certificates couldn't be loaded because CyaSSL was built"
|
|
|
|
" with \"no filesystem\". Either disable peer verification"
|
|
|
|
" (insecure) or if you are building an application with libcurl you"
|
|
|
|
" can load certificates via CURLOPT_SSL_CTX_FUNCTION.");
|
2015-03-27 07:22:32 -04:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-02-28 21:02:47 -05:00
|
|
|
/* Let's make an SSL structure */
|
2017-06-21 06:41:18 -04:00
|
|
|
if(BACKEND->handle)
|
|
|
|
SSL_free(BACKEND->handle);
|
|
|
|
BACKEND->handle = SSL_new(BACKEND->ctx);
|
|
|
|
if(!BACKEND->handle) {
|
2011-02-28 21:02:47 -05:00
|
|
|
failf(data, "SSL: couldn't create a context (handle)!");
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2016-03-28 18:18:09 -04:00
|
|
|
#ifdef HAVE_ALPN
|
2016-05-09 10:50:11 -04:00
|
|
|
if(conn->bits.tls_enable_alpn) {
|
2016-03-28 18:18:09 -04:00
|
|
|
char protocols[128];
|
|
|
|
*protocols = '\0';
|
|
|
|
|
|
|
|
/* wolfSSL's ALPN protocol name list format is a comma separated string of
|
|
|
|
protocols in descending order of preference, eg: "h2,http/1.1" */
|
|
|
|
|
|
|
|
#ifdef USE_NGHTTP2
|
|
|
|
if(data->set.httpversion >= CURL_HTTP_VERSION_2) {
|
|
|
|
strcpy(protocols + strlen(protocols), NGHTTP2_PROTO_VERSION_ID ",");
|
|
|
|
infof(data, "ALPN, offering %s\n", NGHTTP2_PROTO_VERSION_ID);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
strcpy(protocols + strlen(protocols), ALPN_HTTP_1_1);
|
|
|
|
infof(data, "ALPN, offering %s\n", ALPN_HTTP_1_1);
|
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
if(wolfSSL_UseALPN(BACKEND->handle, protocols,
|
2016-03-28 18:18:09 -04:00
|
|
|
(unsigned)strlen(protocols),
|
|
|
|
WOLFSSL_ALPN_CONTINUE_ON_MISMATCH) != SSL_SUCCESS) {
|
|
|
|
failf(data, "SSL: failed setting ALPN protocols");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_ALPN */
|
|
|
|
|
2011-02-28 21:02:47 -05:00
|
|
|
/* Check if there's a cached ID we can/should use here! */
|
2017-03-22 01:59:49 -04:00
|
|
|
if(SSL_SET_OPTION(primary.sessionid)) {
|
2016-06-12 23:47:12 -04:00
|
|
|
void *ssl_sessionid = NULL;
|
|
|
|
|
|
|
|
Curl_ssl_sessionid_lock(conn);
|
2016-11-16 12:49:15 -05:00
|
|
|
if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, sockindex)) {
|
2016-06-12 23:47:12 -04:00
|
|
|
/* we got a session id, use it! */
|
2017-06-21 06:41:18 -04:00
|
|
|
if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) {
|
2016-06-12 23:47:12 -04:00
|
|
|
Curl_ssl_sessionid_unlock(conn);
|
|
|
|
failf(data, "SSL: SSL_set_session failed: %s",
|
2017-06-21 06:41:18 -04:00
|
|
|
ERR_error_string(SSL_get_error(BACKEND->handle, 0),
|
2016-06-12 23:47:12 -04:00
|
|
|
error_buffer));
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
/* Informational message */
|
2016-12-13 17:34:59 -05:00
|
|
|
infof(data, "SSL re-using session ID\n");
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
2016-06-12 23:47:12 -04:00
|
|
|
Curl_ssl_sessionid_unlock(conn);
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pass the raw socket into the SSL layer */
|
2017-06-21 06:41:18 -04:00
|
|
|
if(!SSL_set_fd(BACKEND->handle, (int)sockfd)) {
|
2011-02-28 21:02:47 -05:00
|
|
|
failf(data, "SSL: SSL_set_fd failed");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
connssl->connecting_state = ssl_connect_2;
|
2011-02-28 21:02:47 -05:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static CURLcode
|
|
|
|
cyassl_connect_step2(struct connectdata *conn,
|
|
|
|
int sockindex)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
2016-06-21 09:47:12 -04:00
|
|
|
struct Curl_easy *data = conn->data;
|
2017-06-21 06:41:18 -04:00
|
|
|
struct ssl_connect_data* connssl = &conn->ssl[sockindex];
|
2016-11-16 12:49:15 -05:00
|
|
|
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
|
|
|
|
conn->host.name;
|
|
|
|
const char * const dispname = SSL_IS_PROXY() ?
|
|
|
|
conn->http_proxy.host.dispname : conn->host.dispname;
|
2016-11-25 04:47:25 -05:00
|
|
|
const char * const pinnedpubkey = SSL_IS_PROXY() ?
|
|
|
|
data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] :
|
|
|
|
data->set.str[STRING_SSL_PINNEDPUBLICKEY_ORIG];
|
2011-02-28 21:02:47 -05:00
|
|
|
|
|
|
|
conn->recv[sockindex] = cyassl_recv;
|
|
|
|
conn->send[sockindex] = cyassl_send;
|
|
|
|
|
2012-11-02 21:06:51 -04:00
|
|
|
/* Enable RFC2818 checks */
|
2016-11-16 12:49:15 -05:00
|
|
|
if(SSL_CONN_CONFIG(verifyhost)) {
|
2017-06-21 06:41:18 -04:00
|
|
|
ret = CyaSSL_check_domain_name(BACKEND->handle, hostname);
|
2012-11-02 21:06:51 -04:00
|
|
|
if(ret == SSL_FAILURE)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
ret = SSL_connect(BACKEND->handle);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(ret != 1) {
|
2015-04-04 02:12:03 -04:00
|
|
|
char error_buffer[CYASSL_MAX_ERROR_SZ];
|
2017-06-21 06:41:18 -04:00
|
|
|
int detail = SSL_get_error(BACKEND->handle, ret);
|
2011-02-28 21:02:47 -05:00
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(SSL_ERROR_WANT_READ == detail) {
|
2017-06-21 06:41:18 -04:00
|
|
|
connssl->connecting_state = ssl_connect_2_reading;
|
2011-02-28 21:02:47 -05:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2012-11-02 21:06:51 -04:00
|
|
|
else if(SSL_ERROR_WANT_WRITE == detail) {
|
2017-06-21 06:41:18 -04:00
|
|
|
connssl->connecting_state = ssl_connect_2_writing;
|
2011-02-28 21:02:47 -05:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2012-11-02 21:06:51 -04:00
|
|
|
/* There is no easy way to override only the CN matching.
|
|
|
|
* This will enable the override of both mismatching SubjectAltNames
|
|
|
|
* as also mismatching CN fields */
|
|
|
|
else if(DOMAIN_NAME_MISMATCH == detail) {
|
|
|
|
#if 1
|
|
|
|
failf(data, "\tsubject alt name(s) or common name do not match \"%s\"\n",
|
2016-11-16 12:49:15 -05:00
|
|
|
dispname);
|
2012-11-02 21:06:51 -04:00
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
|
|
|
#else
|
|
|
|
/* When the CyaSSL_check_domain_name() is used and you desire to continue
|
2016-11-16 12:49:15 -05:00
|
|
|
* on a DOMAIN_NAME_MISMATCH, i.e. 'conn->ssl_config.verifyhost == 0',
|
2012-11-02 21:06:51 -04:00
|
|
|
* CyaSSL version 2.4.0 will fail with an INCOMPLETE_DATA error. The only
|
|
|
|
* way to do this is currently to switch the CyaSSL_check_domain_name()
|
2016-11-16 12:49:15 -05:00
|
|
|
* in and out based on the 'conn->ssl_config.verifyhost' value. */
|
|
|
|
if(SSL_CONN_CONFIG(verifyhost)) {
|
2012-11-02 21:06:51 -04:00
|
|
|
failf(data,
|
|
|
|
"\tsubject alt name(s) or common name do not match \"%s\"\n",
|
2016-11-16 12:49:15 -05:00
|
|
|
dispname);
|
2012-11-02 21:06:51 -04:00
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
infof(data,
|
|
|
|
"\tsubject alt name(s) and/or common name do not match \"%s\"\n",
|
2016-11-16 12:49:15 -05:00
|
|
|
dispname);
|
2012-11-02 21:06:51 -04:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2014-07-30 18:31:36 -04:00
|
|
|
#if LIBCYASSL_VERSION_HEX >= 0x02007000 /* 2.7.0 */
|
2014-07-22 18:43:47 -04:00
|
|
|
else if(ASN_NO_SIGNER_E == detail) {
|
2016-11-16 12:49:15 -05:00
|
|
|
if(SSL_CONN_CONFIG(verifypeer)) {
|
2014-07-22 18:43:47 -04:00
|
|
|
failf(data, "\tCA signer not available for verification\n");
|
|
|
|
return CURLE_SSL_CACERT_BADFILE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Just continue with a warning if no strict certificate
|
|
|
|
verification is required. */
|
|
|
|
infof(data, "CA signer not available for verification, "
|
|
|
|
"continuing anyway\n");
|
|
|
|
}
|
|
|
|
}
|
2014-07-30 04:07:42 -04:00
|
|
|
#endif
|
2012-11-02 21:06:51 -04:00
|
|
|
else {
|
|
|
|
failf(data, "SSL_connect failed with error %d: %s", detail,
|
2011-02-28 21:02:47 -05:00
|
|
|
ERR_error_string(detail, error_buffer));
|
2012-11-02 21:06:51 -04:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
|
|
|
|
2016-11-25 04:47:25 -05:00
|
|
|
if(pinnedpubkey) {
|
2016-03-28 18:18:09 -04:00
|
|
|
#ifdef KEEP_PEER_CERT
|
2015-04-05 01:48:16 -04:00
|
|
|
X509 *x509;
|
|
|
|
const char *x509_der;
|
|
|
|
int x509_der_len;
|
|
|
|
curl_X509certificate x509_parsed;
|
|
|
|
curl_asn1Element *pubkey;
|
|
|
|
CURLcode result;
|
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
x509 = SSL_get_peer_certificate(BACKEND->handle);
|
2015-04-05 01:48:16 -04:00
|
|
|
if(!x509) {
|
|
|
|
failf(data, "SSL: failed retrieving server certificate");
|
|
|
|
return CURLE_SSL_PINNEDPUBKEYNOTMATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
x509_der = (const char *)CyaSSL_X509_get_der(x509, &x509_der_len);
|
|
|
|
if(!x509_der) {
|
|
|
|
failf(data, "SSL: failed retrieving ASN.1 server certificate");
|
|
|
|
return CURLE_SSL_PINNEDPUBKEYNOTMATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&x509_parsed, 0, sizeof x509_parsed);
|
2016-11-24 08:28:39 -05:00
|
|
|
if(Curl_parseX509(&x509_parsed, x509_der, x509_der + x509_der_len))
|
|
|
|
return CURLE_SSL_PINNEDPUBKEYNOTMATCH;
|
2015-04-05 01:48:16 -04:00
|
|
|
|
|
|
|
pubkey = &x509_parsed.subjectPublicKeyInfo;
|
|
|
|
if(!pubkey->header || pubkey->end <= pubkey->header) {
|
|
|
|
failf(data, "SSL: failed retrieving public key from server certificate");
|
|
|
|
return CURLE_SSL_PINNEDPUBKEYNOTMATCH;
|
|
|
|
}
|
|
|
|
|
2015-09-12 17:35:12 -04:00
|
|
|
result = Curl_pin_peer_pubkey(data,
|
2016-11-25 04:47:25 -05:00
|
|
|
pinnedpubkey,
|
2015-04-05 01:48:16 -04:00
|
|
|
(const unsigned char *)pubkey->header,
|
|
|
|
(size_t)(pubkey->end - pubkey->header));
|
|
|
|
if(result) {
|
|
|
|
failf(data, "SSL: public key does not match pinned public key!");
|
|
|
|
return result;
|
|
|
|
}
|
2015-12-16 04:25:31 -05:00
|
|
|
#else
|
|
|
|
failf(data, "Library lacks pinning support built-in");
|
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
#endif
|
2015-04-05 01:48:16 -04:00
|
|
|
}
|
|
|
|
|
2016-03-28 18:18:09 -04:00
|
|
|
#ifdef HAVE_ALPN
|
2016-05-09 10:50:11 -04:00
|
|
|
if(conn->bits.tls_enable_alpn) {
|
2016-03-28 18:18:09 -04:00
|
|
|
int rc;
|
|
|
|
char *protocol = NULL;
|
|
|
|
unsigned short protocol_len = 0;
|
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
rc = wolfSSL_ALPN_GetProtocol(BACKEND->handle, &protocol, &protocol_len);
|
2016-03-28 18:18:09 -04:00
|
|
|
|
|
|
|
if(rc == SSL_SUCCESS) {
|
|
|
|
infof(data, "ALPN, server accepted to use %.*s\n", protocol_len,
|
|
|
|
protocol);
|
|
|
|
|
|
|
|
if(protocol_len == ALPN_HTTP_1_1_LENGTH &&
|
|
|
|
!memcmp(protocol, ALPN_HTTP_1_1, ALPN_HTTP_1_1_LENGTH))
|
|
|
|
conn->negnpn = CURL_HTTP_VERSION_1_1;
|
|
|
|
#ifdef USE_NGHTTP2
|
|
|
|
else if(data->set.httpversion >= CURL_HTTP_VERSION_2 &&
|
|
|
|
protocol_len == NGHTTP2_PROTO_VERSION_ID_LEN &&
|
|
|
|
!memcmp(protocol, NGHTTP2_PROTO_VERSION_ID,
|
|
|
|
NGHTTP2_PROTO_VERSION_ID_LEN))
|
|
|
|
conn->negnpn = CURL_HTTP_VERSION_2;
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
infof(data, "ALPN, unrecognized protocol %.*s\n", protocol_len,
|
|
|
|
protocol);
|
|
|
|
}
|
|
|
|
else if(rc == SSL_ALPN_NOT_FOUND)
|
|
|
|
infof(data, "ALPN, server did not agree to a protocol\n");
|
|
|
|
else {
|
|
|
|
failf(data, "ALPN, failure getting protocol, error %d", rc);
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_ALPN */
|
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
connssl->connecting_state = ssl_connect_3;
|
2017-01-06 18:09:10 -05:00
|
|
|
#if (LIBCYASSL_VERSION_HEX >= 0x03009010)
|
|
|
|
infof(data, "SSL connection using %s / %s\n",
|
2017-06-21 06:41:18 -04:00
|
|
|
wolfSSL_get_version(BACKEND->handle),
|
|
|
|
wolfSSL_get_cipher_name(BACKEND->handle));
|
2017-01-06 18:09:10 -05:00
|
|
|
#else
|
2012-01-16 15:14:05 -05:00
|
|
|
infof(data, "SSL connected\n");
|
2017-01-06 18:09:10 -05:00
|
|
|
#endif
|
2011-02-28 21:02:47 -05:00
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static CURLcode
|
|
|
|
cyassl_connect_step3(struct connectdata *conn,
|
|
|
|
int sockindex)
|
|
|
|
{
|
2014-12-25 06:39:47 -05:00
|
|
|
CURLcode result = CURLE_OK;
|
2016-06-21 09:47:12 -04:00
|
|
|
struct Curl_easy *data = conn->data;
|
2011-02-28 21:02:47 -05:00
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
|
|
|
|
|
|
|
DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
|
|
|
|
|
2017-03-22 01:59:49 -04:00
|
|
|
if(SSL_SET_OPTION(primary.sessionid)) {
|
2016-06-12 23:47:12 -04:00
|
|
|
bool incache;
|
|
|
|
SSL_SESSION *our_ssl_sessionid;
|
|
|
|
void *old_ssl_sessionid = NULL;
|
2011-02-28 21:02:47 -05:00
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
our_ssl_sessionid = SSL_get_session(BACKEND->handle);
|
2016-06-12 23:47:12 -04:00
|
|
|
|
|
|
|
Curl_ssl_sessionid_lock(conn);
|
2016-11-16 12:49:15 -05:00
|
|
|
incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL,
|
|
|
|
sockindex));
|
2016-06-12 23:47:12 -04:00
|
|
|
if(incache) {
|
|
|
|
if(old_ssl_sessionid != our_ssl_sessionid) {
|
|
|
|
infof(data, "old SSL session ID is stale, removing\n");
|
|
|
|
Curl_ssl_delsessionid(conn, old_ssl_sessionid);
|
|
|
|
incache = FALSE;
|
|
|
|
}
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
2014-12-25 12:15:15 -05:00
|
|
|
|
2016-06-12 23:47:12 -04:00
|
|
|
if(!incache) {
|
|
|
|
result = Curl_ssl_addsessionid(conn, our_ssl_sessionid,
|
2016-11-16 12:49:15 -05:00
|
|
|
0 /* unknown size */, sockindex);
|
2016-06-12 23:47:12 -04:00
|
|
|
if(result) {
|
|
|
|
Curl_ssl_sessionid_unlock(conn);
|
|
|
|
failf(data, "failed to store ssl session");
|
|
|
|
return result;
|
|
|
|
}
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
2016-06-12 23:47:12 -04:00
|
|
|
Curl_ssl_sessionid_unlock(conn);
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
connssl->connecting_state = ssl_connect_done;
|
|
|
|
|
2014-12-25 06:39:47 -05:00
|
|
|
return result;
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ssize_t cyassl_send(struct connectdata *conn,
|
|
|
|
int sockindex,
|
|
|
|
const void *mem,
|
|
|
|
size_t len,
|
|
|
|
CURLcode *curlcode)
|
|
|
|
{
|
2017-06-21 06:41:18 -04:00
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
2015-04-04 02:12:03 -04:00
|
|
|
char error_buffer[CYASSL_MAX_ERROR_SZ];
|
2011-02-28 21:02:47 -05:00
|
|
|
int memlen = (len > (size_t)INT_MAX) ? INT_MAX : (int)len;
|
2017-06-21 06:41:18 -04:00
|
|
|
int rc = SSL_write(BACKEND->handle, mem, memlen);
|
2011-02-28 21:02:47 -05:00
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc < 0) {
|
2017-06-21 06:41:18 -04:00
|
|
|
int err = SSL_get_error(BACKEND->handle, rc);
|
2011-02-28 21:02:47 -05:00
|
|
|
|
|
|
|
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(conn->data, "SSL write: %s, errno %d",
|
|
|
|
ERR_error_string(err, error_buffer),
|
|
|
|
SOCKERRNO);
|
|
|
|
*curlcode = CURLE_SEND_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-06-23 07:19:00 -04:00
|
|
|
static void Curl_cyassl_close(struct connectdata *conn, int sockindex)
|
2011-02-28 21:02:47 -05:00
|
|
|
{
|
2017-06-21 06:41:18 -04:00
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
2011-02-28 21:02:47 -05:00
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
if(BACKEND->handle) {
|
|
|
|
(void)SSL_shutdown(BACKEND->handle);
|
|
|
|
SSL_free(BACKEND->handle);
|
|
|
|
BACKEND->handle = NULL;
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
2017-06-21 06:41:18 -04:00
|
|
|
if(BACKEND->ctx) {
|
|
|
|
SSL_CTX_free(BACKEND->ctx);
|
|
|
|
BACKEND->ctx = NULL;
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t cyassl_recv(struct connectdata *conn,
|
|
|
|
int num,
|
|
|
|
char *buf,
|
|
|
|
size_t buffersize,
|
|
|
|
CURLcode *curlcode)
|
|
|
|
{
|
2017-06-21 06:41:18 -04:00
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[num];
|
2015-04-04 02:12:03 -04:00
|
|
|
char error_buffer[CYASSL_MAX_ERROR_SZ];
|
2011-02-28 21:02:47 -05:00
|
|
|
int buffsize = (buffersize > (size_t)INT_MAX) ? INT_MAX : (int)buffersize;
|
2017-06-21 06:41:18 -04:00
|
|
|
int nread = SSL_read(BACKEND->handle, buf, buffsize);
|
2011-02-28 21:02:47 -05:00
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(nread < 0) {
|
2017-06-21 06:41:18 -04:00
|
|
|
int err = SSL_get_error(BACKEND->handle, nread);
|
2011-02-28 21:02:47 -05:00
|
|
|
|
|
|
|
switch(err) {
|
|
|
|
case SSL_ERROR_ZERO_RETURN: /* no more data */
|
|
|
|
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(conn->data, "SSL read: %s, errno %d",
|
|
|
|
ERR_error_string(err, error_buffer),
|
|
|
|
SOCKERRNO);
|
|
|
|
*curlcode = CURLE_RECV_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nread;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-23 07:19:00 -04:00
|
|
|
static void Curl_cyassl_session_free(void *ptr)
|
2011-02-28 21:02:47 -05:00
|
|
|
{
|
2011-03-08 08:09:20 -05:00
|
|
|
(void)ptr;
|
2011-02-28 21:02:47 -05:00
|
|
|
/* CyaSSL reuses sessions on own, no free */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-23 07:19:00 -04:00
|
|
|
static size_t Curl_cyassl_version(char *buffer, size_t size)
|
2011-02-28 21:02:47 -05:00
|
|
|
{
|
2017-02-26 18:49:39 -05:00
|
|
|
#if LIBCYASSL_VERSION_HEX >= 0x03006000
|
|
|
|
return snprintf(buffer, size, "wolfSSL/%s", wolfSSL_lib_version());
|
|
|
|
#elif defined(WOLFSSL_VERSION)
|
2015-03-25 02:33:44 -04:00
|
|
|
return snprintf(buffer, size, "wolfSSL/%s", WOLFSSL_VERSION);
|
2015-03-20 18:49:53 -04:00
|
|
|
#elif defined(CYASSL_VERSION)
|
2011-02-28 21:02:47 -05:00
|
|
|
return snprintf(buffer, size, "CyaSSL/%s", CYASSL_VERSION);
|
|
|
|
#else
|
|
|
|
return snprintf(buffer, size, "CyaSSL/%s", "<1.8.8");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-23 07:19:00 -04:00
|
|
|
static int Curl_cyassl_init(void)
|
2011-02-28 21:02:47 -05:00
|
|
|
{
|
2015-03-30 19:09:26 -04:00
|
|
|
return (CyaSSL_Init() == SSL_SUCCESS);
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-23 07:19:00 -04:00
|
|
|
static bool Curl_cyassl_data_pending(const struct connectdata* conn,
|
|
|
|
int connindex)
|
2011-02-28 21:02:47 -05:00
|
|
|
{
|
2017-06-21 06:41:18 -04:00
|
|
|
const struct ssl_connect_data *connssl = &conn->ssl[connindex];
|
|
|
|
if(BACKEND->handle) /* SSL is in use */
|
|
|
|
return (0 != SSL_pending(BACKEND->handle)) ? TRUE : FALSE;
|
2011-02-28 21:02:47 -05:00
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is called to shut down the SSL layer but keep the
|
|
|
|
* socket open (CCC - Clear Command Channel)
|
|
|
|
*/
|
2017-06-23 07:19:00 -04:00
|
|
|
static int Curl_cyassl_shutdown(struct connectdata *conn, int sockindex)
|
2011-02-28 21:02:47 -05:00
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
if(BACKEND->handle) {
|
|
|
|
SSL_free(BACKEND->handle);
|
|
|
|
BACKEND->handle = NULL;
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static CURLcode
|
|
|
|
cyassl_connect_common(struct connectdata *conn,
|
|
|
|
int sockindex,
|
|
|
|
bool nonblocking,
|
|
|
|
bool *done)
|
|
|
|
{
|
2014-12-25 06:39:47 -05:00
|
|
|
CURLcode result;
|
2016-06-21 09:47:12 -04:00
|
|
|
struct Curl_easy *data = conn->data;
|
2011-02-28 21:02:47 -05:00
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
|
|
|
curl_socket_t sockfd = conn->sock[sockindex];
|
2016-12-24 13:25:03 -05:00
|
|
|
time_t timeout_ms;
|
2011-02-28 21:02:47 -05:00
|
|
|
int what;
|
|
|
|
|
|
|
|
/* check if the connection has already been established */
|
|
|
|
if(ssl_connection_complete == connssl->state) {
|
|
|
|
*done = TRUE;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2017-09-09 17:09:06 -04:00
|
|
|
if(ssl_connect_1 == connssl->connecting_state) {
|
2011-02-28 21:02:47 -05:00
|
|
|
/* 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;
|
|
|
|
}
|
2014-12-25 06:39:47 -05:00
|
|
|
|
|
|
|
result = cyassl_connect_step1(conn, sockindex);
|
|
|
|
if(result)
|
|
|
|
return result;
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
while(ssl_connect_2 == connssl->connecting_state ||
|
|
|
|
ssl_connect_2_reading == connssl->connecting_state ||
|
|
|
|
ssl_connect_2_writing == connssl->connecting_state) {
|
|
|
|
|
|
|
|
/* check allowed time left */
|
|
|
|
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) {
|
|
|
|
|
2017-09-09 17:09:06 -04:00
|
|
|
curl_socket_t writefd = ssl_connect_2_writing ==
|
2011-02-28 21:02:47 -05:00
|
|
|
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
|
2017-09-09 17:09:06 -04:00
|
|
|
curl_socket_t readfd = ssl_connect_2_reading ==
|
2011-02-28 21:02:47 -05:00
|
|
|
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
|
|
|
|
|
2016-10-18 04:58:58 -04:00
|
|
|
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
|
|
|
|
nonblocking?0:timeout_ms);
|
2011-02-28 21:02:47 -05:00
|
|
|
if(what < 0) {
|
|
|
|
/* fatal error */
|
|
|
|
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
else if(0 == what) {
|
|
|
|
if(nonblocking) {
|
|
|
|
*done = FALSE;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* timeout */
|
|
|
|
failf(data, "SSL connection timeout");
|
|
|
|
return CURLE_OPERATION_TIMEDOUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* socket is readable or writable */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Run transaction, and return to the caller if it failed or if
|
|
|
|
* this connection is part of a multi handle and this loop would
|
|
|
|
* execute again. This permits the owner of a multi handle to
|
|
|
|
* abort a connection attempt before step2 has completed while
|
|
|
|
* ensuring that a client using select() or epoll() will always
|
|
|
|
* have a valid fdset to wait on.
|
|
|
|
*/
|
2014-12-25 06:39:47 -05:00
|
|
|
result = cyassl_connect_step2(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;
|
2011-02-28 21:02:47 -05:00
|
|
|
} /* repeat step2 until all transactions are done. */
|
|
|
|
|
2014-12-25 06:39:47 -05:00
|
|
|
if(ssl_connect_3 == connssl->connecting_state) {
|
|
|
|
result = cyassl_connect_step3(conn, sockindex);
|
|
|
|
if(result)
|
|
|
|
return result;
|
2011-02-28 21:02:47 -05:00
|
|
|
}
|
|
|
|
|
2014-12-25 06:39:47 -05:00
|
|
|
if(ssl_connect_done == connssl->connecting_state) {
|
2011-02-28 21:02:47 -05:00
|
|
|
connssl->state = ssl_connection_complete;
|
|
|
|
conn->recv[sockindex] = cyassl_recv;
|
|
|
|
conn->send[sockindex] = cyassl_send;
|
|
|
|
*done = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*done = FALSE;
|
|
|
|
|
|
|
|
/* Reset our connect state machine */
|
|
|
|
connssl->connecting_state = ssl_connect_1;
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-23 07:19:00 -04:00
|
|
|
static CURLcode Curl_cyassl_connect_nonblocking(struct connectdata *conn,
|
|
|
|
int sockindex, bool *done)
|
2011-02-28 21:02:47 -05:00
|
|
|
{
|
|
|
|
return cyassl_connect_common(conn, sockindex, TRUE, done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-23 07:19:00 -04:00
|
|
|
static CURLcode Curl_cyassl_connect(struct connectdata *conn, int sockindex)
|
2011-02-28 21:02:47 -05:00
|
|
|
{
|
2014-12-25 06:39:47 -05:00
|
|
|
CURLcode result;
|
2011-02-28 21:02:47 -05:00
|
|
|
bool done = FALSE;
|
|
|
|
|
2014-12-25 06:39:47 -05:00
|
|
|
result = cyassl_connect_common(conn, sockindex, FALSE, &done);
|
|
|
|
if(result)
|
|
|
|
return result;
|
2011-02-28 21:02:47 -05:00
|
|
|
|
|
|
|
DEBUGASSERT(done);
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-23 07:19:00 -04:00
|
|
|
static CURLcode Curl_cyassl_random(struct Curl_easy *data,
|
|
|
|
unsigned char *entropy, size_t length)
|
2014-07-30 18:09:13 -04:00
|
|
|
{
|
|
|
|
RNG rng;
|
|
|
|
(void)data;
|
|
|
|
if(InitRng(&rng))
|
2017-01-12 11:41:26 -05:00
|
|
|
return CURLE_FAILED_INIT;
|
2015-03-25 02:37:20 -04:00
|
|
|
if(length > UINT_MAX)
|
2017-01-12 11:41:26 -05:00
|
|
|
return CURLE_FAILED_INIT;
|
2015-03-25 02:37:20 -04:00
|
|
|
if(RNG_GenerateBlock(&rng, entropy, (unsigned)length))
|
2017-01-12 11:41:26 -05:00
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
return CURLE_OK;
|
2014-07-30 18:09:13 -04:00
|
|
|
}
|
|
|
|
|
2018-04-02 13:33:00 -04:00
|
|
|
static CURLcode Curl_cyassl_sha256sum(const unsigned char *tmp, /* input */
|
2017-06-22 19:04:56 -04:00
|
|
|
size_t tmplen,
|
|
|
|
unsigned char *sha256sum /* output */,
|
|
|
|
size_t unused)
|
2015-06-30 20:23:54 -04:00
|
|
|
{
|
|
|
|
Sha256 SHA256pw;
|
|
|
|
(void)unused;
|
|
|
|
InitSha256(&SHA256pw);
|
2015-12-14 18:36:08 -05:00
|
|
|
Sha256Update(&SHA256pw, tmp, (word32)tmplen);
|
2015-06-30 20:23:54 -04:00
|
|
|
Sha256Final(&SHA256pw, sha256sum);
|
2018-04-02 13:33:00 -04:00
|
|
|
return CURLE_OK;
|
2015-06-30 20:23:54 -04:00
|
|
|
}
|
|
|
|
|
2017-06-23 10:05:26 -04:00
|
|
|
static void *Curl_cyassl_get_internals(struct ssl_connect_data *connssl,
|
|
|
|
CURLINFO info UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
(void)info;
|
2017-06-21 06:41:18 -04:00
|
|
|
return BACKEND->handle;
|
2017-06-23 10:05:26 -04:00
|
|
|
}
|
|
|
|
|
2017-06-22 10:45:34 -04:00
|
|
|
const struct Curl_ssl Curl_ssl_cyassl = {
|
2017-08-30 06:48:53 -04:00
|
|
|
{ CURLSSLBACKEND_WOLFSSL, "WolfSSL" }, /* info */
|
2017-06-22 10:45:34 -04:00
|
|
|
|
2017-06-20 05:32:53 -04:00
|
|
|
0, /* have_ca_path */
|
|
|
|
0, /* have_certinfo */
|
|
|
|
#ifdef KEEP_PEER_CERT
|
|
|
|
1, /* have_pinnedpubkey */
|
|
|
|
#else
|
|
|
|
0, /* have_pinnedpubkey */
|
|
|
|
#endif
|
|
|
|
1, /* have_ssl_ctx */
|
2017-06-26 12:05:38 -04:00
|
|
|
0, /* support_https_proxy */
|
2017-06-20 05:32:53 -04:00
|
|
|
|
vtls: encapsulate SSL backend-specific data
So far, all of the SSL backends' private data has been declared as
part of the ssl_connect_data struct, in one big #if .. #elif .. #endif
block.
This can only work as long as the SSL backend is a compile-time option,
something we want to change in the next commits.
Therefore, let's encapsulate the exact data needed by each SSL backend
into a private struct, and let's avoid bleeding any SSL backend-specific
information into urldata.h. This is also necessary to allow multiple SSL
backends to be compiled in at the same time, as e.g. OpenSSL's and
CyaSSL's headers cannot be included in the same .c file.
To avoid too many malloc() calls, we simply append the private structs
to the connectdata struct in allocate_conn().
This requires us to take extra care of alignment issues: struct fields
often need to be aligned on certain boundaries e.g. 32-bit values need to
be stored at addresses that divide evenly by 4 (= 32 bit / 8
bit-per-byte).
We do that by assuming that no SSL backend's private data contains any
fields that need to be aligned on boundaries larger than `long long`
(typically 64-bit) would need. Under this assumption, we simply add a
dummy field of type `long long` to the `struct connectdata` struct. This
field will never be accessed but acts as a placeholder for the four
instances of ssl_backend_data instead. the size of each ssl_backend_data
struct is stored in the SSL backend-specific metadata, to allow
allocate_conn() to know how much extra space to allocate, and how to
initialize the ssl[sockindex]->backend and proxy_ssl[sockindex]->backend
pointers.
This would appear to be a little complicated at first, but is really
necessary to encapsulate the private data of each SSL backend correctly.
And we need to encapsulate thusly if we ever want to allow selecting
CyaSSL and OpenSSL at runtime, as their headers cannot be included within
the same .c file (there are just too many conflicting definitions and
declarations for that).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-07-28 16:09:35 -04:00
|
|
|
sizeof(struct ssl_backend_data),
|
|
|
|
|
2017-06-22 10:45:34 -04:00
|
|
|
Curl_cyassl_init, /* init */
|
|
|
|
Curl_none_cleanup, /* cleanup */
|
|
|
|
Curl_cyassl_version, /* version */
|
|
|
|
Curl_none_check_cxn, /* check_cxn */
|
|
|
|
Curl_cyassl_shutdown, /* shutdown */
|
|
|
|
Curl_cyassl_data_pending, /* data_pending */
|
|
|
|
Curl_cyassl_random, /* random */
|
|
|
|
Curl_none_cert_status_request, /* cert_status_request */
|
|
|
|
Curl_cyassl_connect, /* connect */
|
|
|
|
Curl_cyassl_connect_nonblocking, /* connect_nonblocking */
|
2017-06-23 10:05:26 -04:00
|
|
|
Curl_cyassl_get_internals, /* get_internals */
|
2017-10-19 14:55:17 -04:00
|
|
|
Curl_cyassl_close, /* close_one */
|
2017-06-22 10:45:34 -04:00
|
|
|
Curl_none_close_all, /* close_all */
|
|
|
|
Curl_cyassl_session_free, /* session_free */
|
|
|
|
Curl_none_set_engine, /* set_engine */
|
|
|
|
Curl_none_set_engine_default, /* set_engine_default */
|
|
|
|
Curl_none_engines_list, /* engines_list */
|
2017-06-22 19:04:56 -04:00
|
|
|
Curl_none_false_start, /* false_start */
|
2017-06-22 19:04:56 -04:00
|
|
|
Curl_none_md5sum, /* md5sum */
|
|
|
|
Curl_cyassl_sha256sum /* sha256sum */
|
2017-06-22 10:45:34 -04:00
|
|
|
};
|
|
|
|
|
2011-02-28 21:02:47 -05:00
|
|
|
#endif
|