2010-12-03 13:23:45 -05:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2013-12-25 05:30:51 -05:00
|
|
|
* Copyright (C) 2010, DirecTV, Contact: Eric Hu, <ehu@directv.com>.
|
2018-05-04 06:10:39 -04:00
|
|
|
* Copyright (C) 2010 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2010-12-03 13:23:45 -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.
|
2010-12-03 13:23:45 -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 axTLS-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.
|
2010-12-03 13:23:45 -05:00
|
|
|
*/
|
|
|
|
|
2013-01-06 13:06:49 -05:00
|
|
|
#include "curl_setup.h"
|
2011-07-26 11:23:27 -04:00
|
|
|
|
2010-12-03 13:23:45 -05:00
|
|
|
#ifdef USE_AXTLS
|
2018-06-01 08:41:41 -04:00
|
|
|
|
2018-06-02 07:40:32 -04:00
|
|
|
#error axTLS support has been disabled in curl due to doubts about quality,
|
2018-06-01 08:41:41 -04:00
|
|
|
#error user dedication and a lack of use/testing. We urge users to consider
|
|
|
|
#error using a more established TLS backend instead.
|
|
|
|
|
2015-03-19 05:11:17 -04:00
|
|
|
#include <axTLS/config.h>
|
2010-12-03 13:23:45 -05:00
|
|
|
#include <axTLS/ssl.h>
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "axtls.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"
|
2015-03-03 17:17:43 -05:00
|
|
|
#include "curl_printf.h"
|
2015-03-24 18:12:03 -04:00
|
|
|
#include "hostcheck.h"
|
2013-06-12 04:36:31 -04:00
|
|
|
#include <unistd.h>
|
2015-03-24 18:12:03 -04:00
|
|
|
|
|
|
|
/* The last #include files should be: */
|
|
|
|
#include "curl_memory.h"
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "memdebug.h"
|
2012-11-02 21:06:51 -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
|
|
|
struct ssl_backend_data {
|
|
|
|
SSL_CTX* ssl_ctx;
|
|
|
|
SSL* ssl;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BACKEND connssl->backend
|
2017-06-21 06:41:18 -04:00
|
|
|
|
2010-12-06 19:18:35 -05:00
|
|
|
static CURLcode map_error_to_curl(int axtls_err)
|
|
|
|
{
|
2016-12-13 17:34:59 -05:00
|
|
|
switch(axtls_err) {
|
2010-12-06 19:18:35 -05:00
|
|
|
case SSL_ERROR_NOT_SUPPORTED:
|
|
|
|
case SSL_ERROR_INVALID_VERSION:
|
|
|
|
case -70: /* protocol version alert from server */
|
|
|
|
return CURLE_UNSUPPORTED_PROTOCOL;
|
|
|
|
break;
|
|
|
|
case SSL_ERROR_NO_CIPHER:
|
|
|
|
return CURLE_SSL_CIPHER;
|
|
|
|
break;
|
|
|
|
case SSL_ERROR_BAD_CERTIFICATE: /* this may be bad server cert too */
|
|
|
|
case SSL_ERROR_NO_CERT_DEFINED:
|
|
|
|
case -42: /* bad certificate alert from server */
|
|
|
|
case -43: /* unsupported cert alert from server */
|
|
|
|
case -44: /* cert revoked alert from server */
|
|
|
|
case -45: /* cert expired alert from server */
|
|
|
|
case -46: /* cert unknown alert from server */
|
|
|
|
return CURLE_SSL_CERTPROBLEM;
|
|
|
|
break;
|
|
|
|
case SSL_X509_ERROR(X509_NOT_OK):
|
|
|
|
case SSL_X509_ERROR(X509_VFY_ERROR_NO_TRUSTED_CERT):
|
|
|
|
case SSL_X509_ERROR(X509_VFY_ERROR_BAD_SIGNATURE):
|
|
|
|
case SSL_X509_ERROR(X509_VFY_ERROR_NOT_YET_VALID):
|
|
|
|
case SSL_X509_ERROR(X509_VFY_ERROR_EXPIRED):
|
|
|
|
case SSL_X509_ERROR(X509_VFY_ERROR_SELF_SIGNED):
|
|
|
|
case SSL_X509_ERROR(X509_VFY_ERROR_INVALID_CHAIN):
|
|
|
|
case SSL_X509_ERROR(X509_VFY_ERROR_UNSUPPORTED_DIGEST):
|
|
|
|
case SSL_X509_ERROR(X509_INVALID_PRIV_KEY):
|
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
|
|
|
break;
|
|
|
|
case -48: /* unknown ca alert from server */
|
|
|
|
return CURLE_SSL_CACERT;
|
|
|
|
break;
|
|
|
|
case -49: /* access denied alert from server */
|
|
|
|
return CURLE_REMOTE_ACCESS_DENIED;
|
|
|
|
break;
|
|
|
|
case SSL_ERROR_CONN_LOST:
|
|
|
|
case SSL_ERROR_SOCK_SETUP_FAILURE:
|
|
|
|
case SSL_ERROR_INVALID_HANDSHAKE:
|
|
|
|
case SSL_ERROR_INVALID_PROT_MSG:
|
|
|
|
case SSL_ERROR_INVALID_HMAC:
|
|
|
|
case SSL_ERROR_INVALID_SESSION:
|
|
|
|
case SSL_ERROR_INVALID_KEY: /* it's too bad this doesn't map better */
|
|
|
|
case SSL_ERROR_FINISHED_INVALID:
|
|
|
|
case SSL_ERROR_NO_CLIENT_RENOG:
|
|
|
|
default:
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Curl_recv axtls_recv;
|
|
|
|
static Curl_send axtls_send;
|
|
|
|
|
2013-06-12 04:36:31 -04:00
|
|
|
static void free_ssl_structs(struct ssl_connect_data *connssl)
|
2013-05-16 14:26:42 -04:00
|
|
|
{
|
2017-06-21 06:41:18 -04:00
|
|
|
if(BACKEND->ssl) {
|
|
|
|
ssl_free(BACKEND->ssl);
|
|
|
|
BACKEND->ssl = NULL;
|
2013-05-16 14:26:42 -04:00
|
|
|
}
|
2017-06-21 06:41:18 -04:00
|
|
|
if(BACKEND->ssl_ctx) {
|
|
|
|
ssl_ctx_free(BACKEND->ssl_ctx);
|
|
|
|
BACKEND->ssl_ctx = NULL;
|
2013-05-16 14:26:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-03 13:23:45 -05:00
|
|
|
/*
|
2013-06-12 04:36:31 -04:00
|
|
|
* For both blocking and non-blocking connects, this function sets up the
|
|
|
|
* ssl context and state. This function is called after the TCP connect
|
|
|
|
* has completed.
|
2010-12-03 13:23:45 -05:00
|
|
|
*/
|
2013-06-12 04:36:31 -04:00
|
|
|
static CURLcode connect_prep(struct connectdata *conn, int sockindex)
|
2010-12-03 13:23:45 -05:00
|
|
|
{
|
2017-06-21 06:41:18 -04:00
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
2016-06-21 09:47:12 -04:00
|
|
|
struct Curl_easy *data = conn->data;
|
2010-12-06 19:18:35 -05:00
|
|
|
SSL_CTX *ssl_ctx;
|
2013-05-16 14:26:42 -04:00
|
|
|
SSL *ssl = NULL;
|
2010-12-06 19:18:35 -05:00
|
|
|
int cert_types[] = {SSL_OBJ_X509_CERT, SSL_OBJ_PKCS12, 0};
|
|
|
|
int key_types[] = {SSL_OBJ_RSA_KEY, SSL_OBJ_PKCS8, SSL_OBJ_PKCS12, 0};
|
|
|
|
int i, ssl_fcn_return;
|
|
|
|
|
2013-06-12 04:36:31 -04:00
|
|
|
/* Assuming users will not compile in custom key/cert to axTLS.
|
|
|
|
* Also, even for blocking connects, use axTLS non-blocking feature.
|
|
|
|
*/
|
|
|
|
uint32_t client_option = SSL_NO_DEFAULT_KEY |
|
|
|
|
SSL_SERVER_VERIFY_LATER |
|
|
|
|
SSL_CONNECT_IN_PARTS;
|
2010-12-06 19:18:35 -05:00
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
if(connssl->state == ssl_connection_complete)
|
2010-12-06 19:18:35 -05:00
|
|
|
/* to make us tolerant against being called more than once for the
|
|
|
|
same connection */
|
|
|
|
return CURLE_OK;
|
|
|
|
|
2016-12-13 15:10:00 -05:00
|
|
|
if(SSL_CONN_CONFIG(version_max) != CURL_SSLVERSION_MAX_NONE) {
|
|
|
|
failf(data, "axtls does not support CURL_SSLVERSION_MAX");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-06 19:18:35 -05:00
|
|
|
/* axTLS only supports TLSv1 */
|
2010-12-15 04:23:19 -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)) {
|
2010-12-15 04:23:19 -05:00
|
|
|
case CURL_SSLVERSION_DEFAULT:
|
|
|
|
case CURL_SSLVERSION_TLSv1:
|
|
|
|
break;
|
|
|
|
default:
|
2013-09-19 09:17:13 -04:00
|
|
|
failf(data, "axTLS only supports TLS 1.0 and 1.1, "
|
|
|
|
"and it cannot be specified which one to use");
|
2010-12-06 19:18:35 -05:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef AXTLSDEBUG
|
|
|
|
client_option |= SSL_DISPLAY_STATES | SSL_DISPLAY_RSA | SSL_DISPLAY_CERTS;
|
|
|
|
#endif /* AXTLSDEBUG */
|
|
|
|
|
|
|
|
/* Allocate an SSL_CTX struct */
|
|
|
|
ssl_ctx = ssl_ctx_new(client_option, SSL_DEFAULT_CLNT_SESS);
|
|
|
|
if(ssl_ctx == NULL) {
|
|
|
|
failf(data, "unable to create client SSL context");
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
BACKEND->ssl_ctx = ssl_ctx;
|
|
|
|
BACKEND->ssl = NULL;
|
2013-06-12 04:36:31 -04:00
|
|
|
|
2010-12-06 19:18:35 -05:00
|
|
|
/* Load the trusted CA cert bundle file */
|
2016-11-16 12:49:15 -05:00
|
|
|
if(SSL_CONN_CONFIG(CAfile)) {
|
|
|
|
if(ssl_obj_load(ssl_ctx, SSL_OBJ_X509_CACERT,
|
|
|
|
SSL_CONN_CONFIG(CAfile), NULL) != SSL_OK) {
|
2010-12-06 19:18:35 -05:00
|
|
|
infof(data, "error reading ca cert file %s \n",
|
2016-11-16 12:49:15 -05:00
|
|
|
SSL_CONN_CONFIG(CAfile));
|
|
|
|
if(SSL_CONN_CONFIG(verifypeer)) {
|
2010-12-10 18:55:06 -05:00
|
|
|
return CURLE_SSL_CACERT_BADFILE;
|
2010-12-06 19:18:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-11-16 12:49:15 -05:00
|
|
|
infof(data, "found certificates in %s\n", SSL_CONN_CONFIG(CAfile));
|
2010-12-06 19:18:35 -05:00
|
|
|
}
|
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
/* gtls.c tasks we're skipping for now:
|
2010-12-06 19:18:35 -05:00
|
|
|
* 1) certificate revocation list checking
|
|
|
|
* 2) dns name assignment to host
|
|
|
|
* 3) set protocol priority. axTLS is TLSv1 only, so can probably ignore
|
2010-12-10 18:55:06 -05:00
|
|
|
* 4) set certificate priority. axTLS ignores type and sends certs in
|
2010-12-06 19:18:35 -05:00
|
|
|
* order added. can probably ignore this.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Load client certificate */
|
2016-11-16 12:49:15 -05:00
|
|
|
if(SSL_SET_OPTION(cert)) {
|
2017-09-09 17:09:06 -04:00
|
|
|
i = 0;
|
2010-12-06 19:18:35 -05:00
|
|
|
/* Instead of trying to analyze cert type here, let axTLS try them all. */
|
2011-07-04 16:10:32 -04:00
|
|
|
while(cert_types[i] != 0) {
|
2010-12-10 18:55:06 -05:00
|
|
|
ssl_fcn_return = ssl_obj_load(ssl_ctx, cert_types[i],
|
2016-11-16 12:49:15 -05:00
|
|
|
SSL_SET_OPTION(cert), NULL);
|
2011-07-04 16:10:32 -04:00
|
|
|
if(ssl_fcn_return == SSL_OK) {
|
2010-12-10 18:55:06 -05:00
|
|
|
infof(data, "successfully read cert file %s \n",
|
2016-11-16 12:49:15 -05:00
|
|
|
SSL_SET_OPTION(cert));
|
2010-12-10 18:55:06 -05:00
|
|
|
break;
|
2010-12-06 19:18:35 -05:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
/* Tried all cert types, none worked. */
|
2011-07-04 16:10:32 -04:00
|
|
|
if(cert_types[i] == 0) {
|
2010-12-10 18:55:06 -05:00
|
|
|
failf(data, "%s is not x509 or pkcs12 format",
|
2016-11-16 12:49:15 -05:00
|
|
|
SSL_SET_OPTION(cert));
|
2010-12-06 19:18:35 -05:00
|
|
|
return CURLE_SSL_CERTPROBLEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load client key.
|
|
|
|
If a pkcs12 file successfully loaded a cert, then there's nothing to do
|
|
|
|
because the key has already been loaded. */
|
2016-11-16 12:49:15 -05:00
|
|
|
if(SSL_SET_OPTION(key) && cert_types[i] != SSL_OBJ_PKCS12) {
|
2017-09-09 17:09:06 -04:00
|
|
|
i = 0;
|
2010-12-06 19:18:35 -05:00
|
|
|
/* Instead of trying to analyze key type here, let axTLS try them all. */
|
2011-07-04 16:10:32 -04:00
|
|
|
while(key_types[i] != 0) {
|
2010-12-10 18:55:06 -05:00
|
|
|
ssl_fcn_return = ssl_obj_load(ssl_ctx, key_types[i],
|
2016-11-16 12:49:15 -05:00
|
|
|
SSL_SET_OPTION(key), NULL);
|
2011-07-04 16:10:32 -04:00
|
|
|
if(ssl_fcn_return == SSL_OK) {
|
2010-12-10 18:55:06 -05:00
|
|
|
infof(data, "successfully read key file %s \n",
|
2016-11-16 12:49:15 -05:00
|
|
|
SSL_SET_OPTION(key));
|
2010-12-10 18:55:06 -05:00
|
|
|
break;
|
2010-12-06 19:18:35 -05:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
/* Tried all key types, none worked. */
|
2011-07-04 16:10:32 -04:00
|
|
|
if(key_types[i] == 0) {
|
2010-12-10 18:55:06 -05:00
|
|
|
failf(data, "Failure: %s is not a supported key file",
|
2016-11-16 12:49:15 -05:00
|
|
|
SSL_SET_OPTION(key));
|
2010-12-06 19:18:35 -05:00
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
/* gtls.c does more here that is being left out for now
|
2010-12-06 19:18:35 -05:00
|
|
|
* 1) set session credentials. can probably ignore since axtls puts this
|
|
|
|
* info in the ssl_ctx struct
|
|
|
|
* 2) setting up callbacks. these seem gnutls specific
|
|
|
|
*/
|
|
|
|
|
2017-03-22 01:59:49 -04:00
|
|
|
if(SSL_SET_OPTION(primary.sessionid)) {
|
2016-06-12 23:47:12 -04:00
|
|
|
const uint8_t *ssl_sessionid;
|
|
|
|
size_t ssl_idsize;
|
|
|
|
|
|
|
|
/* In axTLS, handshaking happens inside ssl_client_new. */
|
|
|
|
Curl_ssl_sessionid_lock(conn);
|
2016-11-16 12:49:15 -05:00
|
|
|
if(!Curl_ssl_getsessionid(conn, (void **) &ssl_sessionid, &ssl_idsize,
|
|
|
|
sockindex)) {
|
2016-06-12 23:47:12 -04:00
|
|
|
/* we got a session id, use it! */
|
2016-12-13 17:34:59 -05:00
|
|
|
infof(data, "SSL re-using session ID\n");
|
2016-06-12 23:47:12 -04:00
|
|
|
ssl = ssl_client_new(ssl_ctx, conn->sock[sockindex],
|
2017-01-19 19:00:51 -05:00
|
|
|
ssl_sessionid, (uint8_t)ssl_idsize, NULL);
|
2016-06-12 23:47:12 -04:00
|
|
|
}
|
2016-06-16 02:29:10 -04:00
|
|
|
Curl_ssl_sessionid_unlock(conn);
|
2010-12-06 19:18:35 -05:00
|
|
|
}
|
2016-06-12 23:47:12 -04:00
|
|
|
|
|
|
|
if(!ssl)
|
2017-01-19 19:00:51 -05:00
|
|
|
ssl = ssl_client_new(ssl_ctx, conn->sock[sockindex], NULL, 0, NULL);
|
2010-12-06 19:18:35 -05:00
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
BACKEND->ssl = ssl;
|
2013-06-12 04:36:31 -04:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-23 07:19:00 -04:00
|
|
|
static void Curl_axtls_close(struct connectdata *conn, int sockindex)
|
2017-06-25 06:44:26 -04:00
|
|
|
{
|
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
|
|
|
|
|
|
|
infof(conn->data, " Curl_axtls_close\n");
|
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
/* line from openssl.c: (void)SSL_shutdown(BACKEND->ssl);
|
2017-06-25 06:44:26 -04:00
|
|
|
axTLS compat layer does nothing for SSL_shutdown */
|
|
|
|
|
|
|
|
/* The following line is from openssl.c. There seems to be no axTLS
|
|
|
|
equivalent. ssl_free and ssl_ctx_free close things.
|
|
|
|
SSL_set_connect_state(connssl->handle); */
|
|
|
|
|
|
|
|
free_ssl_structs(connssl);
|
|
|
|
}
|
|
|
|
|
2013-06-12 04:36:31 -04:00
|
|
|
/*
|
|
|
|
* For both blocking and non-blocking connects, this function finalizes the
|
|
|
|
* SSL connection.
|
|
|
|
*/
|
|
|
|
static CURLcode connect_finish(struct connectdata *conn, int sockindex)
|
|
|
|
{
|
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];
|
|
|
|
SSL *ssl = BACKEND->ssl;
|
2013-06-12 04:36:31 -04:00
|
|
|
const char *peer_CN;
|
|
|
|
uint32_t dns_altname_index;
|
|
|
|
const char *dns_altname;
|
|
|
|
int8_t found_subject_alt_names = 0;
|
|
|
|
int8_t found_subject_alt_name_matching_conn = 0;
|
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;
|
2010-12-06 19:18:35 -05:00
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
/* Here, gtls.c gets the peer certificates and fails out depending on
|
2010-12-06 19:18:35 -05:00
|
|
|
* settings in "data." axTLS api doesn't have get cert chain fcn, so omit?
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Verify server's certificate */
|
2016-11-16 12:49:15 -05:00
|
|
|
if(SSL_CONN_CONFIG(verifypeer)) {
|
2011-07-04 16:10:32 -04:00
|
|
|
if(ssl_verify_cert(ssl) != SSL_OK) {
|
2010-12-10 18:55:06 -05:00
|
|
|
Curl_axtls_close(conn, sockindex);
|
2010-12-06 19:18:35 -05:00
|
|
|
failf(data, "server cert verify failed");
|
2013-06-12 04:36:31 -04:00
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
2010-12-06 19:18:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
infof(data, "\t server certificate verification SKIPPED\n");
|
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
/* Here, gtls.c does issuer verification. axTLS has no straightforward
|
2010-12-06 19:18:35 -05:00
|
|
|
* equivalent, so omitting for now.*/
|
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
/* Here, gtls.c does the following
|
2010-12-10 18:55:06 -05:00
|
|
|
* 1) x509 hostname checking per RFC2818. axTLS doesn't support this, but
|
2012-11-02 21:06:51 -04:00
|
|
|
* it seems useful. This is now implemented, by Oscar Koeroo
|
2010-12-06 19:18:35 -05:00
|
|
|
* 2) checks cert validity based on time. axTLS does this in ssl_verify_cert
|
|
|
|
* 3) displays a bunch of cert information. axTLS doesn't support most of
|
|
|
|
* this, but a couple fields are available.
|
|
|
|
*/
|
|
|
|
|
2012-11-02 21:06:51 -04:00
|
|
|
/* There is no (DNS) Altnames count in the version 1.4.8 API. There is a
|
|
|
|
risk of an inifite loop */
|
|
|
|
for(dns_altname_index = 0; ; dns_altname_index++) {
|
|
|
|
dns_altname = ssl_get_cert_subject_alt_dnsname(ssl, dns_altname_index);
|
|
|
|
if(dns_altname == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
found_subject_alt_names = 1;
|
|
|
|
|
|
|
|
infof(data, "\tComparing subject alt name DNS with hostname: %s <-> %s\n",
|
2016-11-16 12:49:15 -05:00
|
|
|
dns_altname, hostname);
|
|
|
|
if(Curl_cert_hostcheck(dns_altname, hostname)) {
|
2012-11-02 21:06:51 -04:00
|
|
|
found_subject_alt_name_matching_conn = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RFC2818 checks */
|
|
|
|
if(found_subject_alt_names && !found_subject_alt_name_matching_conn) {
|
2016-11-16 12:49:15 -05:00
|
|
|
if(SSL_CONN_CONFIG(verifyhost)) {
|
2013-06-07 18:20:38 -04:00
|
|
|
/* Break connection ! */
|
|
|
|
Curl_axtls_close(conn, sockindex);
|
2016-11-16 12:49:15 -05:00
|
|
|
failf(data, "\tsubjectAltName(s) do not match %s\n", dispname);
|
2013-06-07 18:20:38 -04:00
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
|
|
|
}
|
|
|
|
else
|
2016-11-16 12:49:15 -05:00
|
|
|
infof(data, "\tsubjectAltName(s) do not match %s\n", dispname);
|
2012-11-02 21:06:51 -04:00
|
|
|
}
|
|
|
|
else if(found_subject_alt_names == 0) {
|
|
|
|
/* Per RFC2818, when no Subject Alt Names were available, examine the peer
|
|
|
|
CN as a legacy fallback */
|
|
|
|
peer_CN = ssl_get_cert_dn(ssl, SSL_X509_CERT_COMMON_NAME);
|
|
|
|
if(peer_CN == NULL) {
|
2016-11-16 12:49:15 -05:00
|
|
|
if(SSL_CONN_CONFIG(verifyhost)) {
|
2013-06-07 18:20:38 -04:00
|
|
|
Curl_axtls_close(conn, sockindex);
|
|
|
|
failf(data, "unable to obtain common name from peer certificate");
|
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
infof(data, "unable to obtain common name from peer certificate");
|
2012-11-02 21:06:51 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-11-16 12:49:15 -05:00
|
|
|
if(!Curl_cert_hostcheck((const char *)peer_CN, hostname)) {
|
|
|
|
if(SSL_CONN_CONFIG(verifyhost)) {
|
2012-11-02 21:06:51 -04:00
|
|
|
/* Break connection ! */
|
|
|
|
Curl_axtls_close(conn, sockindex);
|
|
|
|
failf(data, "\tcommon name \"%s\" does not match \"%s\"\n",
|
2016-11-16 12:49:15 -05:00
|
|
|
peer_CN, dispname);
|
2012-11-02 21:06:51 -04:00
|
|
|
return CURLE_PEER_FAILED_VERIFICATION;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
infof(data, "\tcommon name \"%s\" does not match \"%s\"\n",
|
2016-11-16 12:49:15 -05:00
|
|
|
peer_CN, dispname);
|
2012-11-02 21:06:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-06 19:18:35 -05:00
|
|
|
/* General housekeeping */
|
2017-06-21 06:41:18 -04:00
|
|
|
connssl->state = ssl_connection_complete;
|
2010-12-06 19:18:35 -05:00
|
|
|
conn->recv[sockindex] = axtls_recv;
|
|
|
|
conn->send[sockindex] = axtls_send;
|
|
|
|
|
|
|
|
/* Put our freshly minted SSL session in cache */
|
2017-03-22 01:59:49 -04:00
|
|
|
if(SSL_SET_OPTION(primary.sessionid)) {
|
2017-01-19 19:00:51 -05:00
|
|
|
const uint8_t *ssl_sessionid = ssl_get_session_id(ssl);
|
|
|
|
size_t ssl_idsize = ssl_get_session_id_size(ssl);
|
2016-06-12 23:47:12 -04:00
|
|
|
Curl_ssl_sessionid_lock(conn);
|
2016-11-16 12:49:15 -05:00
|
|
|
if(Curl_ssl_addsessionid(conn, (void *) ssl_sessionid, ssl_idsize,
|
|
|
|
sockindex) != CURLE_OK)
|
2016-12-13 17:34:59 -05:00
|
|
|
infof(data, "failed to add session to cache\n");
|
2016-06-12 23:47:12 -04:00
|
|
|
Curl_ssl_sessionid_unlock(conn);
|
|
|
|
}
|
2010-12-06 19:18:35 -05:00
|
|
|
|
2010-12-03 13:23:45 -05:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-12 04:36:31 -04:00
|
|
|
/*
|
|
|
|
* Use axTLS's non-blocking connection feature to open an SSL connection.
|
|
|
|
* This is called after a TCP connection is already established.
|
2014-02-18 15:14:09 -05:00
|
|
|
*/
|
2017-06-23 07:19:00 -04:00
|
|
|
static CURLcode Curl_axtls_connect_nonblocking(struct connectdata *conn,
|
|
|
|
int sockindex, bool *done)
|
2013-06-12 04:36:31 -04:00
|
|
|
{
|
2017-06-21 06:41:18 -04:00
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
2013-06-12 04:36:31 -04:00
|
|
|
CURLcode conn_step;
|
|
|
|
int ssl_fcn_return;
|
2014-02-14 04:20:20 -05:00
|
|
|
int i;
|
2013-06-12 04:36:31 -04:00
|
|
|
|
|
|
|
*done = FALSE;
|
|
|
|
/* connectdata is calloc'd and connecting_state is only changed in this
|
|
|
|
function, so this is safe, as the state is effectively initialized. */
|
2017-06-21 06:41:18 -04:00
|
|
|
if(connssl->connecting_state == ssl_connect_1) {
|
2013-06-12 04:36:31 -04:00
|
|
|
conn_step = connect_prep(conn, sockindex);
|
|
|
|
if(conn_step != CURLE_OK) {
|
|
|
|
Curl_axtls_close(conn, sockindex);
|
|
|
|
return conn_step;
|
|
|
|
}
|
2017-06-21 06:41:18 -04:00
|
|
|
connssl->connecting_state = ssl_connect_2;
|
2013-06-12 04:36:31 -04:00
|
|
|
}
|
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
if(connssl->connecting_state == ssl_connect_2) {
|
2013-06-12 04:36:31 -04:00
|
|
|
/* Check to make sure handshake was ok. */
|
2017-06-21 06:41:18 -04:00
|
|
|
if(ssl_handshake_status(BACKEND->ssl) != SSL_OK) {
|
2014-02-18 15:14:09 -05:00
|
|
|
/* Loop to perform more work in between sleeps. This is work around the
|
|
|
|
fact that axtls does not expose any knowledge about when work needs
|
|
|
|
to be performed. This can save ~25% of time on SSL handshakes. */
|
2017-09-09 17:09:06 -04:00
|
|
|
for(i = 0; i<5; i++) {
|
2017-06-21 06:41:18 -04:00
|
|
|
ssl_fcn_return = ssl_read(BACKEND->ssl, NULL);
|
2014-02-14 04:20:20 -05:00
|
|
|
if(ssl_fcn_return < 0) {
|
|
|
|
Curl_axtls_close(conn, sockindex);
|
|
|
|
ssl_display_error(ssl_fcn_return); /* goes to stdout. */
|
|
|
|
return map_error_to_curl(ssl_fcn_return);
|
|
|
|
}
|
|
|
|
return CURLE_OK;
|
2013-06-12 04:36:31 -04:00
|
|
|
}
|
|
|
|
}
|
2016-12-13 17:34:59 -05:00
|
|
|
infof(conn->data, "handshake completed successfully\n");
|
2017-06-21 06:41:18 -04:00
|
|
|
connssl->connecting_state = ssl_connect_3;
|
2013-06-12 04:36:31 -04:00
|
|
|
}
|
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
if(connssl->connecting_state == ssl_connect_3) {
|
2013-06-12 04:36:31 -04:00
|
|
|
conn_step = connect_finish(conn, sockindex);
|
|
|
|
if(conn_step != CURLE_OK) {
|
|
|
|
Curl_axtls_close(conn, sockindex);
|
|
|
|
return conn_step;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset connect state */
|
2017-06-21 06:41:18 -04:00
|
|
|
connssl->connecting_state = ssl_connect_1;
|
2013-06-12 04:36:31 -04:00
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unrecognized state. Things are very bad. */
|
2017-06-21 06:41:18 -04:00
|
|
|
connssl->state = ssl_connection_none;
|
|
|
|
connssl->connecting_state = ssl_connect_1;
|
2013-06-12 04:36:31 -04:00
|
|
|
/* Return value perhaps not strictly correct, but distinguishes the issue.*/
|
|
|
|
return CURLE_BAD_FUNCTION_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is called after the TCP connect has completed. Setup the TLS
|
|
|
|
* layer and do all necessary magic for a blocking connect.
|
|
|
|
*/
|
2017-06-23 07:19:00 -04:00
|
|
|
static CURLcode Curl_axtls_connect(struct connectdata *conn, int sockindex)
|
2013-06-12 04:36:31 -04:00
|
|
|
{
|
2016-06-21 09:47:12 -04:00
|
|
|
struct Curl_easy *data = conn->data;
|
2013-06-12 04:36:31 -04:00
|
|
|
CURLcode conn_step = connect_prep(conn, sockindex);
|
|
|
|
int ssl_fcn_return;
|
2017-06-21 06:41:18 -04:00
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
|
|
|
SSL *ssl = BACKEND->ssl;
|
2015-03-30 20:04:22 -04:00
|
|
|
long timeout_ms;
|
2013-06-12 04:36:31 -04:00
|
|
|
|
|
|
|
if(conn_step != CURLE_OK) {
|
|
|
|
Curl_axtls_close(conn, sockindex);
|
|
|
|
return conn_step;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check to make sure handshake was ok. */
|
|
|
|
while(ssl_handshake_status(ssl) != SSL_OK) {
|
2015-03-30 20:04:22 -04:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2013-06-12 04:36:31 -04:00
|
|
|
ssl_fcn_return = ssl_read(ssl, NULL);
|
|
|
|
if(ssl_fcn_return < 0) {
|
|
|
|
Curl_axtls_close(conn, sockindex);
|
|
|
|
ssl_display_error(ssl_fcn_return); /* goes to stdout. */
|
|
|
|
return map_error_to_curl(ssl_fcn_return);
|
|
|
|
}
|
2015-03-30 20:04:22 -04:00
|
|
|
/* TODO: avoid polling */
|
2016-06-16 02:44:08 -04:00
|
|
|
Curl_wait_ms(10);
|
2013-06-12 04:36:31 -04:00
|
|
|
}
|
2016-12-13 17:34:59 -05:00
|
|
|
infof(conn->data, "handshake completed successfully\n");
|
2013-06-12 04:36:31 -04:00
|
|
|
|
|
|
|
conn_step = connect_finish(conn, sockindex);
|
|
|
|
if(conn_step != CURLE_OK) {
|
|
|
|
Curl_axtls_close(conn, sockindex);
|
|
|
|
return conn_step;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2010-12-03 13:23:45 -05:00
|
|
|
|
|
|
|
/* return number of sent (non-SSL) bytes */
|
2010-12-06 19:18:35 -05:00
|
|
|
static ssize_t axtls_send(struct connectdata *conn,
|
2010-12-10 18:55:06 -05:00
|
|
|
int sockindex,
|
|
|
|
const void *mem,
|
|
|
|
size_t len,
|
|
|
|
CURLcode *err)
|
2010-12-03 13:23:45 -05:00
|
|
|
{
|
2017-06-21 06:41:18 -04:00
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
2010-12-10 18:55:06 -05:00
|
|
|
/* ssl_write() returns 'int' while write() and send() returns 'size_t' */
|
2017-06-21 06:41:18 -04:00
|
|
|
int rc = ssl_write(BACKEND->ssl, mem, (int)len);
|
2010-12-06 19:18:35 -05:00
|
|
|
|
2010-12-09 19:29:39 -05:00
|
|
|
infof(conn->data, " axtls_send\n");
|
|
|
|
|
2016-04-03 14:28:34 -04:00
|
|
|
if(rc < 0) {
|
2010-12-06 19:18:35 -05:00
|
|
|
*err = map_error_to_curl(rc);
|
|
|
|
rc = -1; /* generic error code for send failure */
|
|
|
|
}
|
|
|
|
|
|
|
|
*err = CURLE_OK;
|
|
|
|
return rc;
|
2010-12-03 13:23:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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_axtls_shutdown(struct connectdata *conn, int sockindex)
|
2010-12-03 13:23:45 -05:00
|
|
|
{
|
2013-12-25 05:30:51 -05:00
|
|
|
/* Outline taken from openssl.c since functions are in axTLS compat layer.
|
2013-01-03 20:50:28 -05:00
|
|
|
axTLS's error set is much smaller, so a lot of error-handling was removed.
|
2010-12-06 19:18:35 -05:00
|
|
|
*/
|
|
|
|
int retval = 0;
|
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
2016-06-21 09:47:12 -04:00
|
|
|
struct Curl_easy *data = conn->data;
|
2013-06-12 04:36:31 -04:00
|
|
|
uint8_t *buf;
|
2010-12-06 19:18:35 -05:00
|
|
|
ssize_t nread;
|
|
|
|
|
2010-12-09 19:29:39 -05:00
|
|
|
infof(conn->data, " Curl_axtls_shutdown\n");
|
|
|
|
|
2010-12-06 19:18:35 -05:00
|
|
|
/* This has only been tested on the proftpd server, and the mod_tls code
|
|
|
|
sends a close notify alert without waiting for a close notify alert in
|
|
|
|
response. Thus we wait for a close notify alert from the server, but
|
|
|
|
we do not send one. Let's hope other servers do the same... */
|
|
|
|
|
|
|
|
/* axTLS compat layer does nothing for SSL_shutdown, so we do nothing too
|
|
|
|
if(data->set.ftp_ccc == CURLFTPSSL_CCC_ACTIVE)
|
2017-06-21 06:41:18 -04:00
|
|
|
(void)SSL_shutdown(BACKEND->ssl);
|
2010-12-06 19:18:35 -05:00
|
|
|
*/
|
|
|
|
|
2017-06-21 06:41:18 -04:00
|
|
|
if(BACKEND->ssl) {
|
2016-10-18 04:58:58 -04:00
|
|
|
int what = SOCKET_READABLE(conn->sock[sockindex], SSL_SHUTDOWN_TIMEOUT);
|
2010-12-06 19:18:35 -05:00
|
|
|
if(what > 0) {
|
|
|
|
/* Something to read, let's do it and hope that it is the close
|
2013-06-12 04:36:31 -04:00
|
|
|
notify alert from the server. buf is managed internally by
|
|
|
|
axTLS and will be released upon calling ssl_free via
|
|
|
|
free_ssl_structs. */
|
2017-06-21 06:41:18 -04:00
|
|
|
nread = (ssize_t)ssl_read(BACKEND->ssl, &buf);
|
2010-12-06 19:18:35 -05:00
|
|
|
|
2011-07-04 16:10:32 -04:00
|
|
|
if(nread < SSL_OK) {
|
2010-12-10 18:55:06 -05:00
|
|
|
failf(data, "close notify alert not received during shutdown");
|
|
|
|
retval = -1;
|
2010-12-06 19:18:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(0 == what) {
|
|
|
|
/* timeout */
|
|
|
|
failf(data, "SSL shutdown timeout");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* anything that gets here is fatally bad */
|
|
|
|
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
|
|
|
retval = -1;
|
|
|
|
}
|
|
|
|
|
2013-06-12 04:36:31 -04:00
|
|
|
free_ssl_structs(connssl);
|
2010-12-06 19:18:35 -05:00
|
|
|
}
|
|
|
|
return retval;
|
2010-12-03 13:23:45 -05:00
|
|
|
}
|
|
|
|
|
2010-12-06 19:18:35 -05:00
|
|
|
static ssize_t axtls_recv(struct connectdata *conn, /* connection data */
|
2010-12-10 18:55:06 -05:00
|
|
|
int num, /* socketindex */
|
|
|
|
char *buf, /* store read data here */
|
|
|
|
size_t buffersize, /* max amount to read */
|
|
|
|
CURLcode *err)
|
2010-12-03 13:23:45 -05:00
|
|
|
{
|
2010-12-09 19:29:39 -05:00
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[num];
|
|
|
|
ssize_t ret = 0;
|
2013-06-12 04:36:31 -04:00
|
|
|
uint8_t *read_buf;
|
2010-12-09 19:29:39 -05:00
|
|
|
|
|
|
|
infof(conn->data, " axtls_recv\n");
|
|
|
|
|
2013-06-12 04:36:31 -04:00
|
|
|
*err = CURLE_OK;
|
2011-07-04 16:10:32 -04:00
|
|
|
if(connssl) {
|
2017-06-21 06:41:18 -04:00
|
|
|
ret = ssl_read(BACKEND->ssl, &read_buf);
|
2013-06-12 04:36:31 -04:00
|
|
|
if(ret > SSL_OK) {
|
|
|
|
/* ssl_read returns SSL_OK if there is more data to read, so if it is
|
|
|
|
larger, then all data has been read already. */
|
|
|
|
memcpy(buf, read_buf,
|
|
|
|
(size_t)ret > buffersize ? buffersize : (size_t)ret);
|
|
|
|
}
|
|
|
|
else if(ret == SSL_OK) {
|
|
|
|
/* more data to be read, signal caller to call again */
|
|
|
|
*err = CURLE_AGAIN;
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
else if(ret == -3) {
|
|
|
|
/* With patched axTLS, SSL_CLOSE_NOTIFY=-3. Hard-coding until axTLS
|
|
|
|
team approves proposed fix. */
|
2010-12-09 19:29:39 -05:00
|
|
|
Curl_axtls_close(conn, num);
|
|
|
|
}
|
2013-06-12 04:36:31 -04:00
|
|
|
else {
|
|
|
|
failf(conn->data, "axTLS recv error (%d)", ret);
|
2014-01-20 18:53:44 -05:00
|
|
|
*err = map_error_to_curl((int) ret);
|
2013-06-12 04:36:31 -04:00
|
|
|
ret = -1;
|
2010-12-09 19:29:39 -05:00
|
|
|
}
|
2010-12-06 19:18:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2010-12-03 13:23:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return codes:
|
|
|
|
* 1 means the connection is still in place
|
|
|
|
* 0 means the connection has been closed
|
|
|
|
* -1 means the connection status is unknown
|
|
|
|
*/
|
2017-06-23 07:19:00 -04:00
|
|
|
static int Curl_axtls_check_cxn(struct connectdata *conn)
|
2010-12-03 13:23:45 -05:00
|
|
|
{
|
2017-06-21 06:41:18 -04:00
|
|
|
/* openssl.c line:
|
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
|
|
|
rc = SSL_peek(conn->ssl[FIRSTSOCKET].backend->ssl, (void*)&buf, 1);
|
2010-12-10 18:55:06 -05:00
|
|
|
axTLS compat layer always returns the last argument, so connection is
|
2010-12-06 19:18:35 -05:00
|
|
|
always alive? */
|
|
|
|
|
2010-12-09 19:29:39 -05:00
|
|
|
infof(conn->data, " Curl_axtls_check_cxn\n");
|
2010-12-06 19:18:35 -05:00
|
|
|
return 1; /* connection still in place */
|
2010-12-03 13:23:45 -05:00
|
|
|
}
|
|
|
|
|
2017-06-23 07:19:00 -04:00
|
|
|
static void Curl_axtls_session_free(void *ptr)
|
2010-12-03 13:23:45 -05:00
|
|
|
{
|
2010-12-10 18:55:06 -05:00
|
|
|
(void)ptr;
|
2010-12-06 19:18:35 -05:00
|
|
|
/* free the ID */
|
2013-12-25 05:30:51 -05:00
|
|
|
/* both openssl.c and gtls.c do something here, but axTLS's OpenSSL
|
2013-01-03 20:50:28 -05:00
|
|
|
compatibility layer does nothing, so we do nothing too. */
|
2010-12-03 13:23:45 -05:00
|
|
|
}
|
|
|
|
|
2017-06-23 07:19:00 -04:00
|
|
|
static size_t Curl_axtls_version(char *buffer, size_t size)
|
2010-12-03 13:23:45 -05:00
|
|
|
{
|
2010-12-06 19:18:35 -05:00
|
|
|
return snprintf(buffer, size, "axTLS/%s", ssl_version());
|
2010-12-03 13:23:45 -05:00
|
|
|
}
|
|
|
|
|
2017-06-23 07:19:00 -04:00
|
|
|
static CURLcode Curl_axtls_random(struct Curl_easy *data,
|
|
|
|
unsigned char *entropy, size_t length)
|
2014-07-30 19:03:30 -04:00
|
|
|
{
|
|
|
|
static bool ssl_seeded = FALSE;
|
|
|
|
(void)data;
|
|
|
|
if(!ssl_seeded) {
|
|
|
|
ssl_seeded = TRUE;
|
|
|
|
/* Initialize the seed if not already done. This call is not exactly thread
|
|
|
|
* safe (and neither is the ssl_seeded check), but the worst effect of a
|
|
|
|
* race condition is that some global resources will leak. */
|
|
|
|
RNG_initialize();
|
|
|
|
}
|
2015-02-06 08:04:16 -05:00
|
|
|
get_random((int)length, entropy);
|
2017-01-12 11:41:26 -05:00
|
|
|
return CURLE_OK;
|
2014-07-30 19:03:30 -04:00
|
|
|
}
|
|
|
|
|
2017-06-23 10:05:26 -04:00
|
|
|
static void *Curl_axtls_get_internals(struct ssl_connect_data *connssl,
|
|
|
|
CURLINFO info UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
(void)info;
|
2017-06-21 06:41:18 -04:00
|
|
|
return BACKEND->ssl;
|
2017-06-23 10:05:26 -04:00
|
|
|
}
|
|
|
|
|
2017-06-22 10:45:34 -04:00
|
|
|
const struct Curl_ssl Curl_ssl_axtls = {
|
2017-07-15 07:49:30 -04:00
|
|
|
{ CURLSSLBACKEND_AXTLS, "axtls" }, /* info */
|
2018-05-04 06:10:39 -04:00
|
|
|
0, /* no fancy stuff */
|
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-20 05:32:53 -04:00
|
|
|
/*
|
|
|
|
* axTLS has no global init. Everything is done through SSL and SSL_CTX
|
|
|
|
* structs stored in connectdata structure.
|
|
|
|
*/
|
|
|
|
Curl_none_init, /* init */
|
|
|
|
/* axTLS has no global cleanup. */
|
|
|
|
Curl_none_cleanup, /* cleanup */
|
2017-06-22 10:45:34 -04:00
|
|
|
Curl_axtls_version, /* version */
|
|
|
|
Curl_axtls_check_cxn, /* check_cxn */
|
|
|
|
Curl_axtls_shutdown, /* shutdown */
|
|
|
|
Curl_none_data_pending, /* data_pending */
|
|
|
|
Curl_axtls_random, /* random */
|
|
|
|
Curl_none_cert_status_request, /* cert_status_request */
|
|
|
|
Curl_axtls_connect, /* connect */
|
|
|
|
Curl_axtls_connect_nonblocking, /* connect_nonblocking */
|
2017-06-23 10:05:26 -04:00
|
|
|
Curl_axtls_get_internals, /* get_internals */
|
2017-10-19 14:55:17 -04:00
|
|
|
Curl_axtls_close, /* close_one */
|
2017-06-22 10:45:34 -04:00
|
|
|
Curl_none_close_all, /* close_all */
|
|
|
|
Curl_axtls_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 */
|
|
|
|
NULL /* sha256sum */
|
2017-06-22 10:45:34 -04:00
|
|
|
};
|
|
|
|
|
2010-12-03 13:23:45 -05:00
|
|
|
#endif /* USE_AXTLS */
|