2005-04-07 11:27:13 -04:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2019-02-26 03:21:12 -05:00
|
|
|
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2005-04-07 11:27:13 -04: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.
|
2005-04-07 11:27:13 -04: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.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2009-02-25 07:51:39 -05:00
|
|
|
/* This file is for implementing all "generic" SSL functions that all libcurl
|
|
|
|
internals should use. It is then responsible for calling the proper
|
|
|
|
"backend" function.
|
2005-04-07 11:27:13 -04:00
|
|
|
|
|
|
|
SSL-functions in libcurl should call functions in this source file, and not
|
|
|
|
to any specific SSL-layer.
|
|
|
|
|
|
|
|
Curl_ssl_ - prefix for generic ones
|
|
|
|
|
2017-06-22 18:22:47 -04:00
|
|
|
Note that this source code uses the functions of the configured SSL
|
|
|
|
backend via the global Curl_ssl instance.
|
2008-06-11 13:01:58 -04:00
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
"SSL/TLS Strong Encryption: An Introduction"
|
2016-02-02 23:09:25 -05:00
|
|
|
https://httpd.apache.org/docs/2.0/ssl/ssl_intro.html
|
2005-04-07 11:27:13 -04:00
|
|
|
*/
|
|
|
|
|
2013-01-06 13:06:49 -05:00
|
|
|
#include "curl_setup.h"
|
2007-02-25 23:24:26 -05:00
|
|
|
|
2013-06-24 16:24:35 -04:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "urldata.h"
|
2013-12-17 17:32:47 -05:00
|
|
|
|
|
|
|
#include "vtls.h" /* generic SSL protos etc */
|
2013-07-15 11:26:59 -04:00
|
|
|
#include "slist.h"
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "sendf.h"
|
2016-09-30 12:54:02 -04:00
|
|
|
#include "strcase.h"
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "url.h"
|
|
|
|
#include "progress.h"
|
|
|
|
#include "share.h"
|
2016-11-16 12:49:15 -05:00
|
|
|
#include "multiif.h"
|
2013-06-24 16:24:35 -04:00
|
|
|
#include "timeval.h"
|
2014-10-13 08:39:50 -04:00
|
|
|
#include "curl_md5.h"
|
2014-10-29 15:12:50 -04:00
|
|
|
#include "warnless.h"
|
2014-11-24 13:30:09 -05:00
|
|
|
#include "curl_base64.h"
|
2015-03-03 17:17:43 -05:00
|
|
|
#include "curl_printf.h"
|
2013-07-15 11:26:59 -04:00
|
|
|
|
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"
|
2005-04-07 11:27:13 -04:00
|
|
|
|
2011-11-25 08:58:55 -05:00
|
|
|
/* convenience macro to check if this handle is using a shared SSL session */
|
|
|
|
#define SSLSESSION_SHARED(data) (data->share && \
|
|
|
|
(data->share->specifier & \
|
|
|
|
(1<<CURL_LOCK_DATA_SSL_SESSION)))
|
|
|
|
|
2016-11-23 01:53:24 -05:00
|
|
|
#define CLONE_STRING(var) \
|
|
|
|
if(source->var) { \
|
|
|
|
dest->var = strdup(source->var); \
|
|
|
|
if(!dest->var) \
|
|
|
|
return FALSE; \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
dest->var = NULL;
|
2005-04-07 11:27:13 -04:00
|
|
|
|
|
|
|
bool
|
2016-11-16 12:49:15 -05:00
|
|
|
Curl_ssl_config_matches(struct ssl_primary_config* data,
|
|
|
|
struct ssl_primary_config* needle)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
|
|
|
if((data->version == needle->version) &&
|
2016-12-13 15:10:00 -05:00
|
|
|
(data->version_max == needle->version_max) &&
|
2005-04-07 11:27:13 -04:00
|
|
|
(data->verifypeer == needle->verifypeer) &&
|
|
|
|
(data->verifyhost == needle->verifyhost) &&
|
2017-09-24 08:08:29 -04:00
|
|
|
(data->verifystatus == needle->verifystatus) &&
|
2016-11-16 12:49:15 -05:00
|
|
|
Curl_safe_strcasecompare(data->CApath, needle->CApath) &&
|
|
|
|
Curl_safe_strcasecompare(data->CAfile, needle->CAfile) &&
|
|
|
|
Curl_safe_strcasecompare(data->clientcert, needle->clientcert) &&
|
2017-09-24 08:08:29 -04:00
|
|
|
Curl_safe_strcasecompare(data->random_file, needle->random_file) &&
|
|
|
|
Curl_safe_strcasecompare(data->egdsocket, needle->egdsocket) &&
|
2018-09-03 07:04:00 -04:00
|
|
|
Curl_safe_strcasecompare(data->cipher_list, needle->cipher_list) &&
|
|
|
|
Curl_safe_strcasecompare(data->cipher_list13, needle->cipher_list13))
|
2005-04-07 11:27:13 -04:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-11-16 12:49:15 -05:00
|
|
|
Curl_clone_primary_ssl_config(struct ssl_primary_config *source,
|
|
|
|
struct ssl_primary_config *dest)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
|
|
|
dest->version = source->version;
|
2016-12-13 15:10:00 -05:00
|
|
|
dest->version_max = source->version_max;
|
2017-09-24 08:08:29 -04:00
|
|
|
dest->verifypeer = source->verifypeer;
|
|
|
|
dest->verifyhost = source->verifyhost;
|
|
|
|
dest->verifystatus = source->verifystatus;
|
|
|
|
dest->sessionid = source->sessionid;
|
2005-04-07 11:27:13 -04:00
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
CLONE_STRING(CApath);
|
2017-09-24 08:08:29 -04:00
|
|
|
CLONE_STRING(CAfile);
|
2016-11-16 12:49:15 -05:00
|
|
|
CLONE_STRING(clientcert);
|
2017-09-24 08:08:29 -04:00
|
|
|
CLONE_STRING(random_file);
|
|
|
|
CLONE_STRING(egdsocket);
|
|
|
|
CLONE_STRING(cipher_list);
|
2018-09-03 07:04:00 -04:00
|
|
|
CLONE_STRING(cipher_list13);
|
2017-03-22 01:59:49 -04:00
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
void Curl_free_primary_ssl_config(struct ssl_primary_config* sslc)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
2007-08-01 17:20:01 -04:00
|
|
|
Curl_safefree(sslc->CApath);
|
2017-09-24 08:08:29 -04:00
|
|
|
Curl_safefree(sslc->CAfile);
|
2016-07-01 07:32:31 -04:00
|
|
|
Curl_safefree(sslc->clientcert);
|
2017-09-24 08:08:29 -04:00
|
|
|
Curl_safefree(sslc->random_file);
|
|
|
|
Curl_safefree(sslc->egdsocket);
|
|
|
|
Curl_safefree(sslc->cipher_list);
|
2018-09-03 07:04:00 -04:00
|
|
|
Curl_safefree(sslc->cipher_list13);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
#ifdef USE_SSL
|
2017-07-07 05:49:08 -04:00
|
|
|
static int multissl_init(const struct Curl_ssl *backend);
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
#endif
|
|
|
|
|
2014-08-03 04:40:36 -04:00
|
|
|
int Curl_ssl_backend(void)
|
|
|
|
{
|
2017-06-23 18:25:29 -04:00
|
|
|
#ifdef USE_SSL
|
2017-07-07 05:49:08 -04:00
|
|
|
multissl_init(NULL);
|
2017-07-15 07:49:30 -04:00
|
|
|
return Curl_ssl->info.id;
|
2017-06-23 18:25:29 -04:00
|
|
|
#else
|
|
|
|
return (int)CURLSSLBACKEND_NONE;
|
|
|
|
#endif
|
2014-08-03 04:40:36 -04:00
|
|
|
}
|
|
|
|
|
2008-06-11 13:01:58 -04:00
|
|
|
#ifdef USE_SSL
|
|
|
|
|
|
|
|
/* "global" init done? */
|
2017-09-09 17:09:06 -04:00
|
|
|
static bool init_ssl = FALSE;
|
2008-06-11 13:01:58 -04:00
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
/**
|
|
|
|
* Global SSL init
|
|
|
|
*
|
|
|
|
* @retval 0 error initializing SSL
|
|
|
|
* @retval 1 SSL initialized successfully
|
|
|
|
*/
|
|
|
|
int Curl_ssl_init(void)
|
|
|
|
{
|
|
|
|
/* make sure this is only done once */
|
|
|
|
if(init_ssl)
|
|
|
|
return 1;
|
|
|
|
init_ssl = TRUE; /* never again */
|
|
|
|
|
2017-06-22 18:22:47 -04:00
|
|
|
return Curl_ssl->init();
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Global cleanup */
|
|
|
|
void Curl_ssl_cleanup(void)
|
|
|
|
{
|
|
|
|
if(init_ssl) {
|
|
|
|
/* only cleanup if we did a previous init */
|
2017-06-22 18:22:47 -04:00
|
|
|
Curl_ssl->cleanup();
|
2005-04-07 11:27:13 -04:00
|
|
|
init_ssl = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 09:47:12 -04:00
|
|
|
static bool ssl_prefs_check(struct Curl_easy *data)
|
2015-03-27 02:20:43 -04:00
|
|
|
{
|
|
|
|
/* check for CURLOPT_SSLVERSION invalid parameter value */
|
2016-12-13 15:10:00 -05:00
|
|
|
const long sslver = data->set.ssl.primary.version;
|
|
|
|
if((sslver < 0) || (sslver >= CURL_SSLVERSION_LAST)) {
|
2015-03-27 02:20:43 -04:00
|
|
|
failf(data, "Unrecognized parameter value passed via CURLOPT_SSLVERSION");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-12-13 15:10:00 -05:00
|
|
|
|
|
|
|
switch(data->set.ssl.primary.version_max) {
|
|
|
|
case CURL_SSLVERSION_MAX_NONE:
|
|
|
|
case CURL_SSLVERSION_MAX_DEFAULT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if((data->set.ssl.primary.version_max >> 16) < sslver) {
|
|
|
|
failf(data, "CURL_SSLVERSION_MAX incompatible with CURL_SSLVERSION");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 02:20:43 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
static CURLcode
|
2016-11-23 02:49:04 -05:00
|
|
|
ssl_connect_init_proxy(struct connectdata *conn, int sockindex)
|
|
|
|
{
|
2016-11-16 12:49:15 -05:00
|
|
|
DEBUGASSERT(conn->bits.proxy_ssl_connected[sockindex]);
|
|
|
|
if(ssl_connection_complete == conn->ssl[sockindex].state &&
|
|
|
|
!conn->proxy_ssl[sockindex].use) {
|
2017-09-06 17:39:21 -04:00
|
|
|
struct ssl_backend_data *pbdata;
|
|
|
|
|
2018-05-04 06:10:39 -04:00
|
|
|
if(!(Curl_ssl->supports & SSLSUPP_HTTPS_PROXY))
|
2017-06-26 12:05:38 -04:00
|
|
|
return CURLE_NOT_BUILT_IN;
|
2017-09-06 17:39:21 -04:00
|
|
|
|
|
|
|
/* The pointers to the ssl backend data, which is opaque here, are swapped
|
|
|
|
rather than move the contents. */
|
|
|
|
pbdata = conn->proxy_ssl[sockindex].backend;
|
2016-11-16 12:49:15 -05:00
|
|
|
conn->proxy_ssl[sockindex] = conn->ssl[sockindex];
|
2017-09-06 17:39:21 -04:00
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
memset(&conn->ssl[sockindex], 0, sizeof(conn->ssl[sockindex]));
|
2017-09-06 17:39:21 -04:00
|
|
|
memset(pbdata, 0, Curl_ssl->sizeof_ssl_backend_data);
|
|
|
|
|
|
|
|
conn->ssl[sockindex].backend = pbdata;
|
2016-11-16 12:49:15 -05:00
|
|
|
}
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
CURLcode
|
|
|
|
Curl_ssl_connect(struct connectdata *conn, int sockindex)
|
|
|
|
{
|
2014-10-23 16:56:35 -04:00
|
|
|
CURLcode result;
|
2015-03-27 02:20:43 -04:00
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
if(conn->bits.proxy_ssl_connected[sockindex]) {
|
|
|
|
result = ssl_connect_init_proxy(conn, sockindex);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-03-27 02:20:43 -04:00
|
|
|
if(!ssl_prefs_check(conn->data))
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
|
2008-06-11 13:01:58 -04:00
|
|
|
/* mark this is being ssl-enabled from here on. */
|
2005-04-07 11:27:13 -04:00
|
|
|
conn->ssl[sockindex].use = TRUE;
|
2008-02-20 04:56:26 -05:00
|
|
|
conn->ssl[sockindex].state = ssl_connection_negotiating;
|
2005-04-07 11:27:13 -04:00
|
|
|
|
2019-03-12 18:50:28 -04:00
|
|
|
result = Curl_ssl->connect_blocking(conn, sockindex);
|
2008-07-03 02:56:03 -04:00
|
|
|
|
2014-10-23 16:56:35 -04:00
|
|
|
if(!result)
|
2008-07-03 02:56:03 -04:00
|
|
|
Curl_pgrsTime(conn->data, TIMER_APPCONNECT); /* SSL is connected */
|
|
|
|
|
2014-10-23 16:56:35 -04:00
|
|
|
return result;
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
2006-03-21 16:54:44 -05:00
|
|
|
CURLcode
|
|
|
|
Curl_ssl_connect_nonblocking(struct connectdata *conn, int sockindex,
|
|
|
|
bool *done)
|
|
|
|
{
|
2014-10-23 16:56:35 -04:00
|
|
|
CURLcode result;
|
2016-11-16 12:49:15 -05:00
|
|
|
if(conn->bits.proxy_ssl_connected[sockindex]) {
|
|
|
|
result = ssl_connect_init_proxy(conn, sockindex);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
2015-03-27 02:20:43 -04:00
|
|
|
|
|
|
|
if(!ssl_prefs_check(conn->data))
|
|
|
|
return CURLE_SSL_CONNECT_ERROR;
|
|
|
|
|
2008-06-11 13:01:58 -04:00
|
|
|
/* mark this is being ssl requested from here on. */
|
2006-03-21 16:54:44 -05:00
|
|
|
conn->ssl[sockindex].use = TRUE;
|
2017-06-22 18:22:47 -04:00
|
|
|
result = Curl_ssl->connect_nonblocking(conn, sockindex, done);
|
2014-10-23 16:56:35 -04:00
|
|
|
if(!result && *done)
|
2012-06-08 17:02:57 -04:00
|
|
|
Curl_pgrsTime(conn->data, TIMER_APPCONNECT); /* SSL is connected */
|
2014-10-23 16:56:35 -04:00
|
|
|
return result;
|
2006-03-21 16:54:44 -05:00
|
|
|
}
|
|
|
|
|
2016-06-01 03:30:03 -04:00
|
|
|
/*
|
|
|
|
* Lock shared SSL session data
|
|
|
|
*/
|
|
|
|
void Curl_ssl_sessionid_lock(struct connectdata *conn)
|
|
|
|
{
|
|
|
|
if(SSLSESSION_SHARED(conn->data))
|
|
|
|
Curl_share_lock(conn->data,
|
|
|
|
CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_ACCESS_SINGLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlock shared SSL session data
|
|
|
|
*/
|
|
|
|
void Curl_ssl_sessionid_unlock(struct connectdata *conn)
|
|
|
|
{
|
|
|
|
if(SSLSESSION_SHARED(conn->data))
|
|
|
|
Curl_share_unlock(conn->data, CURL_LOCK_DATA_SSL_SESSION);
|
|
|
|
}
|
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
/*
|
|
|
|
* Check if there's a session ID for the given connection in the cache, and if
|
|
|
|
* there's one suitable, it is provided. Returns TRUE when no entry matched.
|
|
|
|
*/
|
2014-12-25 12:15:15 -05:00
|
|
|
bool Curl_ssl_getsessionid(struct connectdata *conn,
|
|
|
|
void **ssl_sessionid,
|
2016-11-16 12:49:15 -05:00
|
|
|
size_t *idsize, /* set 0 if unknown */
|
|
|
|
int sockindex)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
|
|
|
struct curl_ssl_session *check;
|
2016-06-21 09:47:12 -04:00
|
|
|
struct Curl_easy *data = conn->data;
|
2012-01-18 17:39:30 -05:00
|
|
|
size_t i;
|
2011-11-17 17:34:38 -05:00
|
|
|
long *general_age;
|
2011-11-17 17:55:36 -05:00
|
|
|
bool no_match = TRUE;
|
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
const bool isProxy = CONNECT_PROXY_SSL();
|
|
|
|
struct ssl_primary_config * const ssl_config = isProxy ?
|
2017-01-22 06:00:28 -05:00
|
|
|
&conn->proxy_ssl_config :
|
|
|
|
&conn->ssl_config;
|
2016-11-16 12:49:15 -05:00
|
|
|
const char * const name = isProxy ? conn->http_proxy.host.name :
|
2017-01-22 06:00:28 -05:00
|
|
|
conn->host.name;
|
2016-11-16 12:49:15 -05:00
|
|
|
int port = isProxy ? (int)conn->port : conn->remote_port;
|
2011-11-17 17:55:36 -05:00
|
|
|
*ssl_sessionid = NULL;
|
2005-04-07 11:27:13 -04:00
|
|
|
|
2017-03-22 01:59:49 -04:00
|
|
|
DEBUGASSERT(SSL_SET_OPTION(primary.sessionid));
|
2016-06-12 23:47:12 -04:00
|
|
|
|
2017-03-22 01:59:49 -04:00
|
|
|
if(!SSL_SET_OPTION(primary.sessionid))
|
2006-09-11 13:18:18 -04:00
|
|
|
/* session ID re-use is disabled */
|
|
|
|
return TRUE;
|
|
|
|
|
2011-11-17 17:55:36 -05:00
|
|
|
/* Lock if shared */
|
2016-06-01 03:30:03 -04:00
|
|
|
if(SSLSESSION_SHARED(data))
|
2011-11-17 17:34:38 -05:00
|
|
|
general_age = &data->share->sessionage;
|
|
|
|
else
|
|
|
|
general_age = &data->state.sessionage;
|
2011-09-20 11:43:54 -04:00
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
for(i = 0; i < data->set.general_ssl.max_ssl_sessions; i++) {
|
2005-04-07 11:27:13 -04:00
|
|
|
check = &data->state.session[i];
|
|
|
|
if(!check->sessionid)
|
|
|
|
/* not session ID means blank entry */
|
|
|
|
continue;
|
2016-11-16 12:49:15 -05:00
|
|
|
if(strcasecompare(name, check->name) &&
|
2016-01-25 08:37:24 -05:00
|
|
|
((!conn->bits.conn_to_host && !check->conn_to_host) ||
|
2016-09-30 12:54:02 -04:00
|
|
|
(conn->bits.conn_to_host && check->conn_to_host &&
|
|
|
|
strcasecompare(conn->conn_to_host.name, check->conn_to_host))) &&
|
2016-01-25 08:37:24 -05:00
|
|
|
((!conn->bits.conn_to_port && check->conn_to_port == -1) ||
|
2016-09-30 12:54:02 -04:00
|
|
|
(conn->bits.conn_to_port && check->conn_to_port != -1 &&
|
|
|
|
conn->conn_to_port == check->conn_to_port)) &&
|
2016-11-16 12:49:15 -05:00
|
|
|
(port == check->remote_port) &&
|
2016-09-30 12:54:02 -04:00
|
|
|
strcasecompare(conn->handler->scheme, check->scheme) &&
|
2016-11-16 12:49:15 -05:00
|
|
|
Curl_ssl_config_matches(ssl_config, &check->ssl_config)) {
|
2005-04-07 11:27:13 -04:00
|
|
|
/* yes, we have a session ID! */
|
2011-11-17 17:46:29 -05:00
|
|
|
(*general_age)++; /* increase general age */
|
2011-11-17 17:34:38 -05:00
|
|
|
check->age = *general_age; /* set this as used in this age */
|
2005-04-07 11:27:13 -04:00
|
|
|
*ssl_sessionid = check->sessionid;
|
|
|
|
if(idsize)
|
|
|
|
*idsize = check->idsize;
|
2011-11-17 17:55:36 -05:00
|
|
|
no_match = FALSE;
|
|
|
|
break;
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
}
|
2011-09-20 11:43:54 -04:00
|
|
|
|
2011-11-17 17:55:36 -05:00
|
|
|
return no_match;
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kill a single session ID entry in the cache.
|
|
|
|
*/
|
2012-01-18 17:39:30 -05:00
|
|
|
void Curl_ssl_kill_session(struct curl_ssl_session *session)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
|
|
|
if(session->sessionid) {
|
|
|
|
/* defensive check */
|
|
|
|
|
|
|
|
/* free the ID the SSL-layer specific way */
|
2017-06-22 18:22:47 -04:00
|
|
|
Curl_ssl->session_free(session->sessionid);
|
2008-06-11 13:01:58 -04:00
|
|
|
|
2012-01-18 17:39:30 -05:00
|
|
|
session->sessionid = NULL;
|
2005-04-07 11:27:13 -04:00
|
|
|
session->age = 0; /* fresh */
|
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
Curl_free_primary_ssl_config(&session->ssl_config);
|
2005-04-07 11:27:13 -04:00
|
|
|
|
|
|
|
Curl_safefree(session->name);
|
2016-01-25 08:37:24 -05:00
|
|
|
Curl_safefree(session->conn_to_host);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-04 17:57:14 -04:00
|
|
|
/*
|
|
|
|
* Delete the given session ID from the cache.
|
|
|
|
*/
|
|
|
|
void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid)
|
|
|
|
{
|
2012-01-18 17:39:30 -05:00
|
|
|
size_t i;
|
2017-09-09 17:09:06 -04:00
|
|
|
struct Curl_easy *data = conn->data;
|
2011-09-20 11:43:54 -04:00
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
for(i = 0; i < data->set.general_ssl.max_ssl_sessions; i++) {
|
2011-09-20 11:43:54 -04:00
|
|
|
struct curl_ssl_session *check = &data->state.session[i];
|
2009-05-04 17:57:14 -04:00
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(check->sessionid == ssl_sessionid) {
|
2011-09-20 11:43:54 -04:00
|
|
|
Curl_ssl_kill_session(check);
|
2009-05-04 17:57:14 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
/*
|
|
|
|
* Store session id in the session cache. The ID passed on to this function
|
|
|
|
* must already have been extracted and allocated the proper way for the SSL
|
|
|
|
* layer. Curl_XXXX_session_free() will be called to free/kill the session ID
|
|
|
|
* later on.
|
|
|
|
*/
|
|
|
|
CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
|
|
|
|
void *ssl_sessionid,
|
2016-11-16 12:49:15 -05:00
|
|
|
size_t idsize,
|
|
|
|
int sockindex)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
2012-01-18 17:39:30 -05:00
|
|
|
size_t i;
|
2017-09-09 17:09:06 -04:00
|
|
|
struct Curl_easy *data = conn->data; /* the mother of all structs */
|
2005-04-07 11:27:13 -04:00
|
|
|
struct curl_ssl_session *store = &data->state.session[0];
|
2017-09-09 17:09:06 -04:00
|
|
|
long oldest_age = data->state.session[0].age; /* zero if unused */
|
2005-04-07 11:27:13 -04:00
|
|
|
char *clone_host;
|
2016-01-25 08:37:24 -05:00
|
|
|
char *clone_conn_to_host;
|
|
|
|
int conn_to_port;
|
2011-11-17 17:34:38 -05:00
|
|
|
long *general_age;
|
2016-11-16 12:49:15 -05:00
|
|
|
const bool isProxy = CONNECT_PROXY_SSL();
|
|
|
|
struct ssl_primary_config * const ssl_config = isProxy ?
|
2017-01-22 06:00:28 -05:00
|
|
|
&conn->proxy_ssl_config :
|
|
|
|
&conn->ssl_config;
|
2005-04-07 11:27:13 -04:00
|
|
|
|
2017-03-22 01:59:49 -04:00
|
|
|
DEBUGASSERT(SSL_SET_OPTION(primary.sessionid));
|
2006-09-11 13:18:18 -04:00
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
clone_host = strdup(isProxy ? conn->http_proxy.host.name : conn->host.name);
|
2005-04-07 11:27:13 -04:00
|
|
|
if(!clone_host)
|
|
|
|
return CURLE_OUT_OF_MEMORY; /* bail out */
|
|
|
|
|
2016-01-25 08:37:24 -05:00
|
|
|
if(conn->bits.conn_to_host) {
|
|
|
|
clone_conn_to_host = strdup(conn->conn_to_host.name);
|
|
|
|
if(!clone_conn_to_host) {
|
|
|
|
free(clone_host);
|
|
|
|
return CURLE_OUT_OF_MEMORY; /* bail out */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
clone_conn_to_host = NULL;
|
|
|
|
|
|
|
|
if(conn->bits.conn_to_port)
|
|
|
|
conn_to_port = conn->conn_to_port;
|
|
|
|
else
|
|
|
|
conn_to_port = -1;
|
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
/* Now we should add the session ID and the host name to the cache, (remove
|
|
|
|
the oldest if necessary) */
|
|
|
|
|
2011-09-20 11:43:54 -04:00
|
|
|
/* If using shared SSL session, lock! */
|
2011-11-25 08:58:55 -05:00
|
|
|
if(SSLSESSION_SHARED(data)) {
|
2011-11-17 17:34:38 -05:00
|
|
|
general_age = &data->share->sessionage;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
general_age = &data->state.sessionage;
|
|
|
|
}
|
2011-09-20 11:43:54 -04:00
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
/* find an empty slot for us, or find the oldest */
|
2016-11-16 12:49:15 -05:00
|
|
|
for(i = 1; (i < data->set.general_ssl.max_ssl_sessions) &&
|
2005-04-07 11:27:13 -04:00
|
|
|
data->state.session[i].sessionid; i++) {
|
|
|
|
if(data->state.session[i].age < oldest_age) {
|
|
|
|
oldest_age = data->state.session[i].age;
|
|
|
|
store = &data->state.session[i];
|
|
|
|
}
|
|
|
|
}
|
2016-11-16 12:49:15 -05:00
|
|
|
if(i == data->set.general_ssl.max_ssl_sessions)
|
2005-04-07 11:27:13 -04:00
|
|
|
/* cache is full, we must "kill" the oldest entry! */
|
2011-09-20 11:43:54 -04:00
|
|
|
Curl_ssl_kill_session(store);
|
2005-04-07 11:27:13 -04:00
|
|
|
else
|
|
|
|
store = &data->state.session[i]; /* use this slot */
|
|
|
|
|
|
|
|
/* now init the session struct wisely */
|
|
|
|
store->sessionid = ssl_sessionid;
|
|
|
|
store->idsize = idsize;
|
2011-11-17 17:34:38 -05:00
|
|
|
store->age = *general_age; /* set current age */
|
2017-01-22 06:00:28 -05:00
|
|
|
/* free it if there's one already present */
|
2015-03-11 12:41:01 -04:00
|
|
|
free(store->name);
|
2016-01-25 08:37:24 -05:00
|
|
|
free(store->conn_to_host);
|
2005-04-07 11:27:13 -04:00
|
|
|
store->name = clone_host; /* clone host name */
|
2016-01-25 08:37:24 -05:00
|
|
|
store->conn_to_host = clone_conn_to_host; /* clone connect to host name */
|
|
|
|
store->conn_to_port = conn_to_port; /* connect to port number */
|
2016-11-16 12:49:15 -05:00
|
|
|
/* port number */
|
|
|
|
store->remote_port = isProxy ? (int)conn->port : conn->remote_port;
|
2016-10-10 10:47:54 -04:00
|
|
|
store->scheme = conn->handler->scheme;
|
2005-04-07 11:27:13 -04:00
|
|
|
|
2016-11-16 12:49:15 -05:00
|
|
|
if(!Curl_clone_primary_ssl_config(ssl_config, &store->ssl_config)) {
|
2011-01-10 07:53:01 -05:00
|
|
|
store->sessionid = NULL; /* let caller free sessionid */
|
|
|
|
free(clone_host);
|
2016-01-25 08:37:24 -05:00
|
|
|
free(clone_conn_to_host);
|
2005-04-07 11:27:13 -04:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2011-01-10 07:53:01 -05:00
|
|
|
}
|
2005-04-07 11:27:13 -04:00
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-21 09:47:12 -04:00
|
|
|
void Curl_ssl_close_all(struct Curl_easy *data)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
2012-01-18 17:39:30 -05:00
|
|
|
size_t i;
|
2011-11-25 08:58:55 -05:00
|
|
|
/* kill the session ID cache if not shared */
|
|
|
|
if(data->state.session && !SSLSESSION_SHARED(data)) {
|
2016-11-16 12:49:15 -05:00
|
|
|
for(i = 0; i < data->set.general_ssl.max_ssl_sessions; i++)
|
2005-04-07 11:27:13 -04:00
|
|
|
/* the single-killer function handles empty table slots */
|
2011-09-20 11:43:54 -04:00
|
|
|
Curl_ssl_kill_session(&data->state.session[i]);
|
2005-04-07 11:27:13 -04:00
|
|
|
|
|
|
|
/* free the cache data */
|
2012-01-18 17:39:30 -05:00
|
|
|
Curl_safefree(data->state.session);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
2008-06-11 13:01:58 -04:00
|
|
|
|
2017-06-22 18:22:47 -04:00
|
|
|
Curl_ssl->close_all(data);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
2016-12-25 18:06:33 -05:00
|
|
|
#if defined(USE_OPENSSL) || defined(USE_GNUTLS) || defined(USE_SCHANNEL) || \
|
2019-02-26 03:21:12 -05:00
|
|
|
defined(USE_SECTRANSP) || defined(USE_POLARSSL) || defined(USE_NSS) || \
|
2018-04-11 12:46:08 -04:00
|
|
|
defined(USE_MBEDTLS) || defined(USE_CYASSL)
|
2016-11-16 12:49:15 -05:00
|
|
|
int Curl_ssl_getsock(struct connectdata *conn, curl_socket_t *socks,
|
|
|
|
int numsocks)
|
|
|
|
{
|
|
|
|
struct ssl_connect_data *connssl = &conn->ssl[FIRSTSOCKET];
|
|
|
|
|
|
|
|
if(!numsocks)
|
|
|
|
return GETSOCK_BLANK;
|
|
|
|
|
|
|
|
if(connssl->connecting_state == ssl_connect_2_writing) {
|
|
|
|
/* write mode */
|
|
|
|
socks[0] = conn->sock[FIRSTSOCKET];
|
|
|
|
return GETSOCK_WRITESOCK(0);
|
|
|
|
}
|
2017-03-10 08:28:37 -05:00
|
|
|
if(connssl->connecting_state == ssl_connect_2_reading) {
|
2016-11-16 12:49:15 -05:00
|
|
|
/* read mode */
|
|
|
|
socks[0] = conn->sock[FIRSTSOCKET];
|
|
|
|
return GETSOCK_READSOCK(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GETSOCK_BLANK;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
int Curl_ssl_getsock(struct connectdata *conn,
|
2017-01-22 06:00:28 -05:00
|
|
|
curl_socket_t *socks,
|
|
|
|
int numsocks)
|
2016-11-16 12:49:15 -05:00
|
|
|
{
|
|
|
|
(void)conn;
|
|
|
|
(void)socks;
|
|
|
|
(void)numsocks;
|
|
|
|
return GETSOCK_BLANK;
|
|
|
|
}
|
2019-02-26 03:21:12 -05:00
|
|
|
/* USE_OPENSSL || USE_GNUTLS || USE_SCHANNEL || USE_SECTRANSP || USE_NSS */
|
2016-11-16 12:49:15 -05:00
|
|
|
#endif
|
|
|
|
|
2007-07-29 08:54:05 -04:00
|
|
|
void Curl_ssl_close(struct connectdata *conn, int sockindex)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
2007-07-29 08:54:05 -04:00
|
|
|
DEBUGASSERT((sockindex <= 1) && (sockindex >= -1));
|
2017-10-19 14:55:17 -04:00
|
|
|
Curl_ssl->close_one(conn, sockindex);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
2007-01-05 18:11:14 -05:00
|
|
|
CURLcode Curl_ssl_shutdown(struct connectdata *conn, int sockindex)
|
|
|
|
{
|
2019-03-12 18:50:28 -04:00
|
|
|
if(Curl_ssl->shut_down(conn, sockindex))
|
2007-07-29 08:54:05 -04:00
|
|
|
return CURLE_SSL_SHUTDOWN_FAILED;
|
|
|
|
|
|
|
|
conn->ssl[sockindex].use = FALSE; /* get back to ordinary socket usage */
|
2008-02-20 04:56:26 -05:00
|
|
|
conn->ssl[sockindex].state = ssl_connection_none;
|
2007-07-29 08:54:05 -04:00
|
|
|
|
2011-04-15 10:41:27 -04:00
|
|
|
conn->recv[sockindex] = Curl_recv_plain;
|
|
|
|
conn->send[sockindex] = Curl_send_plain;
|
|
|
|
|
2007-01-05 18:11:14 -05:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2008-06-11 13:01:58 -04:00
|
|
|
/* Selects an SSL crypto engine
|
2005-04-07 11:27:13 -04:00
|
|
|
*/
|
2016-06-21 09:47:12 -04:00
|
|
|
CURLcode Curl_ssl_set_engine(struct Curl_easy *data, const char *engine)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
2017-06-22 18:22:47 -04:00
|
|
|
return Curl_ssl->set_engine(data, engine);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
2008-06-11 13:01:58 -04:00
|
|
|
/* Selects the default SSL crypto engine
|
2005-04-07 11:27:13 -04:00
|
|
|
*/
|
2016-06-21 09:47:12 -04:00
|
|
|
CURLcode Curl_ssl_set_engine_default(struct Curl_easy *data)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
2017-06-22 18:22:47 -04:00
|
|
|
return Curl_ssl->set_engine_default(data);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return list of OpenSSL crypto engine names. */
|
2016-06-21 09:47:12 -04:00
|
|
|
struct curl_slist *Curl_ssl_engines_list(struct Curl_easy *data)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
2017-06-22 18:22:47 -04:00
|
|
|
return Curl_ssl->engines_list(data);
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This sets up a session ID cache to the specified size. Make sure this code
|
|
|
|
* is agnostic to what underlying SSL technology we use.
|
|
|
|
*/
|
2016-06-21 09:47:12 -04:00
|
|
|
CURLcode Curl_ssl_initsessions(struct Curl_easy *data, size_t amount)
|
2005-04-07 11:27:13 -04:00
|
|
|
{
|
|
|
|
struct curl_ssl_session *session;
|
|
|
|
|
|
|
|
if(data->state.session)
|
|
|
|
/* this is just a precaution to prevent multiple inits */
|
|
|
|
return CURLE_OK;
|
|
|
|
|
2009-11-18 05:33:54 -05:00
|
|
|
session = calloc(amount, sizeof(struct curl_ssl_session));
|
2005-04-07 11:27:13 -04:00
|
|
|
if(!session)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
/* store the info in the SSL section */
|
2016-11-16 12:49:15 -05:00
|
|
|
data->set.general_ssl.max_ssl_sessions = amount;
|
2005-04-07 11:27:13 -04:00
|
|
|
data->state.session = session;
|
|
|
|
data->state.sessionage = 1; /* this is brand new */
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2017-08-18 07:01:38 -04:00
|
|
|
static size_t Curl_multissl_version(char *buffer, size_t size);
|
|
|
|
|
2005-04-07 11:27:13 -04:00
|
|
|
size_t Curl_ssl_version(char *buffer, size_t size)
|
|
|
|
{
|
2017-08-18 07:01:38 -04:00
|
|
|
#ifdef CURL_WITH_MULTI_SSL
|
|
|
|
return Curl_multissl_version(buffer, size);
|
|
|
|
#else
|
2017-06-22 18:22:47 -04:00
|
|
|
return Curl_ssl->version(buffer, size);
|
2017-08-18 07:01:38 -04:00
|
|
|
#endif
|
2005-04-07 11:27:13 -04:00
|
|
|
}
|
|
|
|
|
2006-05-10 18:17:42 -04:00
|
|
|
/*
|
|
|
|
* This function tries to determine connection status.
|
|
|
|
*
|
|
|
|
* Return codes:
|
|
|
|
* 1 means the connection is still in place
|
|
|
|
* 0 means the connection has been closed
|
|
|
|
* -1 means the connection status is unknown
|
|
|
|
*/
|
|
|
|
int Curl_ssl_check_cxn(struct connectdata *conn)
|
|
|
|
{
|
2017-06-22 18:22:47 -04:00
|
|
|
return Curl_ssl->check_cxn(conn);
|
2006-05-10 18:17:42 -04:00
|
|
|
}
|
2007-01-24 12:19:08 -05:00
|
|
|
|
2007-08-27 02:31:28 -04:00
|
|
|
bool Curl_ssl_data_pending(const struct connectdata *conn,
|
2007-01-24 12:19:08 -05:00
|
|
|
int connindex)
|
|
|
|
{
|
2017-06-22 18:22:47 -04:00
|
|
|
return Curl_ssl->data_pending(conn, connindex);
|
2007-01-24 12:19:08 -05:00
|
|
|
}
|
2008-06-11 13:01:58 -04:00
|
|
|
|
2016-06-21 09:47:12 -04:00
|
|
|
void Curl_ssl_free_certinfo(struct Curl_easy *data)
|
2008-09-05 10:29:21 -04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct curl_certinfo *ci = &data->info.certs;
|
2014-12-26 06:58:17 -05:00
|
|
|
|
2008-09-05 10:29:21 -04:00
|
|
|
if(ci->num_of_certs) {
|
|
|
|
/* free all individual lists used */
|
2017-09-09 17:09:06 -04:00
|
|
|
for(i = 0; i<ci->num_of_certs; i++) {
|
2008-09-05 10:29:21 -04:00
|
|
|
curl_slist_free_all(ci->certinfo[i]);
|
2011-10-07 14:50:57 -04:00
|
|
|
ci->certinfo[i] = NULL;
|
|
|
|
}
|
2014-12-26 06:58:17 -05:00
|
|
|
|
2008-09-05 10:29:21 -04:00
|
|
|
free(ci->certinfo); /* free the actual array too */
|
2011-10-07 14:50:57 -04:00
|
|
|
ci->certinfo = NULL;
|
2008-09-05 10:29:21 -04:00
|
|
|
ci->num_of_certs = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-06-26 08:52:46 -04:00
|
|
|
|
2016-06-21 09:47:12 -04:00
|
|
|
CURLcode Curl_ssl_init_certinfo(struct Curl_easy *data, int num)
|
2013-07-15 11:26:59 -04:00
|
|
|
{
|
2014-12-26 06:53:34 -05:00
|
|
|
struct curl_certinfo *ci = &data->info.certs;
|
|
|
|
struct curl_slist **table;
|
2013-07-15 11:26:59 -04:00
|
|
|
|
2014-12-26 06:58:17 -05:00
|
|
|
/* Free any previous certificate information structures */
|
2013-07-15 11:26:59 -04:00
|
|
|
Curl_ssl_free_certinfo(data);
|
2014-12-26 06:58:17 -05:00
|
|
|
|
|
|
|
/* Allocate the required certificate information structures */
|
2013-07-15 11:26:59 -04:00
|
|
|
table = calloc((size_t) num, sizeof(struct curl_slist *));
|
|
|
|
if(!table)
|
2014-12-26 06:53:34 -05:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2013-07-15 11:26:59 -04:00
|
|
|
|
2014-12-26 06:58:17 -05:00
|
|
|
ci->num_of_certs = num;
|
2013-07-15 11:26:59 -04:00
|
|
|
ci->certinfo = table;
|
2014-12-26 06:53:34 -05:00
|
|
|
|
|
|
|
return CURLE_OK;
|
2013-07-15 11:26:59 -04:00
|
|
|
}
|
|
|
|
|
2013-11-05 03:56:18 -05:00
|
|
|
/*
|
|
|
|
* 'value' is NOT a zero terminated string
|
|
|
|
*/
|
2016-06-21 09:47:12 -04:00
|
|
|
CURLcode Curl_ssl_push_certinfo_len(struct Curl_easy *data,
|
2013-07-15 11:26:59 -04:00
|
|
|
int certnum,
|
|
|
|
const char *label,
|
|
|
|
const char *value,
|
|
|
|
size_t valuelen)
|
|
|
|
{
|
2016-11-23 01:53:24 -05:00
|
|
|
struct curl_certinfo *ci = &data->info.certs;
|
|
|
|
char *output;
|
|
|
|
struct curl_slist *nl;
|
2014-10-23 16:56:35 -04:00
|
|
|
CURLcode result = CURLE_OK;
|
2013-11-05 03:56:18 -05:00
|
|
|
size_t labellen = strlen(label);
|
|
|
|
size_t outlen = labellen + 1 + valuelen + 1; /* label:value\0 */
|
2013-07-15 11:26:59 -04:00
|
|
|
|
2013-11-05 03:56:18 -05:00
|
|
|
output = malloc(outlen);
|
2013-07-15 11:26:59 -04:00
|
|
|
if(!output)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
2013-11-05 03:56:18 -05:00
|
|
|
/* sprintf the label and colon */
|
2018-11-22 03:01:24 -05:00
|
|
|
msnprintf(output, outlen, "%s:", label);
|
2013-11-05 03:56:18 -05:00
|
|
|
|
|
|
|
/* memcpy the value (it might not be zero terminated) */
|
2017-09-09 17:55:08 -04:00
|
|
|
memcpy(&output[labellen + 1], value, valuelen);
|
2013-11-05 03:56:18 -05:00
|
|
|
|
|
|
|
/* zero terminate the output */
|
|
|
|
output[labellen + 1 + valuelen] = 0;
|
|
|
|
|
2013-07-15 11:26:59 -04:00
|
|
|
nl = Curl_slist_append_nodup(ci->certinfo[certnum], output);
|
|
|
|
if(!nl) {
|
|
|
|
free(output);
|
|
|
|
curl_slist_free_all(ci->certinfo[certnum]);
|
2014-10-23 16:56:35 -04:00
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
2013-07-15 11:26:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ci->certinfo[certnum] = nl;
|
2014-10-23 16:56:35 -04:00
|
|
|
return result;
|
2013-07-15 11:26:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a convenience function for push_certinfo_len that takes a zero
|
|
|
|
* terminated value.
|
|
|
|
*/
|
2016-06-21 09:47:12 -04:00
|
|
|
CURLcode Curl_ssl_push_certinfo(struct Curl_easy *data,
|
2013-07-15 11:26:59 -04:00
|
|
|
int certnum,
|
|
|
|
const char *label,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
size_t valuelen = strlen(value);
|
|
|
|
|
|
|
|
return Curl_ssl_push_certinfo_len(data, certnum, label, value, valuelen);
|
|
|
|
}
|
|
|
|
|
2016-11-11 08:53:36 -05:00
|
|
|
CURLcode Curl_ssl_random(struct Curl_easy *data,
|
|
|
|
unsigned char *entropy,
|
|
|
|
size_t length)
|
2014-06-03 14:04:46 -04:00
|
|
|
{
|
2017-06-22 18:22:47 -04:00
|
|
|
return Curl_ssl->random(data, entropy, length);
|
2014-06-03 14:04:46 -04:00
|
|
|
}
|
|
|
|
|
2014-11-24 13:30:09 -05:00
|
|
|
/*
|
|
|
|
* Public key pem to der conversion
|
|
|
|
*/
|
|
|
|
|
|
|
|
static CURLcode pubkey_pem_to_der(const char *pem,
|
|
|
|
unsigned char **der, size_t *der_len)
|
|
|
|
{
|
|
|
|
char *stripped_pem, *begin_pos, *end_pos;
|
|
|
|
size_t pem_count, stripped_pem_count = 0, pem_len;
|
|
|
|
CURLcode result;
|
|
|
|
|
|
|
|
/* if no pem, exit. */
|
|
|
|
if(!pem)
|
|
|
|
return CURLE_BAD_CONTENT_ENCODING;
|
|
|
|
|
|
|
|
begin_pos = strstr(pem, "-----BEGIN PUBLIC KEY-----");
|
|
|
|
if(!begin_pos)
|
|
|
|
return CURLE_BAD_CONTENT_ENCODING;
|
|
|
|
|
|
|
|
pem_count = begin_pos - pem;
|
|
|
|
/* Invalid if not at beginning AND not directly following \n */
|
|
|
|
if(0 != pem_count && '\n' != pem[pem_count - 1])
|
|
|
|
return CURLE_BAD_CONTENT_ENCODING;
|
|
|
|
|
|
|
|
/* 26 is length of "-----BEGIN PUBLIC KEY-----" */
|
|
|
|
pem_count += 26;
|
|
|
|
|
|
|
|
/* Invalid if not directly following \n */
|
|
|
|
end_pos = strstr(pem + pem_count, "\n-----END PUBLIC KEY-----");
|
|
|
|
if(!end_pos)
|
|
|
|
return CURLE_BAD_CONTENT_ENCODING;
|
|
|
|
|
|
|
|
pem_len = end_pos - pem;
|
|
|
|
|
|
|
|
stripped_pem = malloc(pem_len - pem_count + 1);
|
|
|
|
if(!stripped_pem)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Here we loop through the pem array one character at a time between the
|
|
|
|
* correct indices, and place each character that is not '\n' or '\r'
|
|
|
|
* into the stripped_pem array, which should represent the raw base64 string
|
|
|
|
*/
|
|
|
|
while(pem_count < pem_len) {
|
|
|
|
if('\n' != pem[pem_count] && '\r' != pem[pem_count])
|
|
|
|
stripped_pem[stripped_pem_count++] = pem[pem_count];
|
|
|
|
++pem_count;
|
|
|
|
}
|
|
|
|
/* Place the null terminator in the correct place */
|
|
|
|
stripped_pem[stripped_pem_count] = '\0';
|
|
|
|
|
|
|
|
result = Curl_base64_decode(stripped_pem, der, der_len);
|
|
|
|
|
|
|
|
Curl_safefree(stripped_pem);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-10-13 12:34:51 -04:00
|
|
|
/*
|
|
|
|
* Generic pinned public key check.
|
|
|
|
*/
|
|
|
|
|
2016-06-21 09:47:12 -04:00
|
|
|
CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
|
2015-09-12 17:35:12 -04:00
|
|
|
const char *pinnedpubkey,
|
2014-10-13 12:34:51 -04:00
|
|
|
const unsigned char *pubkey, size_t pubkeylen)
|
|
|
|
{
|
2014-11-24 13:30:09 -05:00
|
|
|
FILE *fp;
|
|
|
|
unsigned char *buf = NULL, *pem_ptr = NULL;
|
|
|
|
long filesize;
|
|
|
|
size_t size, pem_len;
|
|
|
|
CURLcode pem_read;
|
2014-10-13 12:34:51 -04:00
|
|
|
CURLcode result = CURLE_SSL_PINNEDPUBKEYNOTMATCH;
|
2015-09-12 17:35:12 -04:00
|
|
|
CURLcode encode;
|
|
|
|
size_t encodedlen, pinkeylen;
|
|
|
|
char *encoded, *pinkeycopy, *begin_pos, *end_pos;
|
|
|
|
unsigned char *sha256sumdigest = NULL;
|
2014-10-13 12:34:51 -04:00
|
|
|
|
|
|
|
/* if a path wasn't specified, don't pin */
|
|
|
|
if(!pinnedpubkey)
|
|
|
|
return CURLE_OK;
|
|
|
|
if(!pubkey || !pubkeylen)
|
|
|
|
return result;
|
2015-06-30 20:23:54 -04:00
|
|
|
|
|
|
|
/* only do this if pinnedpubkey starts with "sha256//", length 8 */
|
|
|
|
if(strncmp(pinnedpubkey, "sha256//", 8) == 0) {
|
2017-06-22 19:04:56 -04:00
|
|
|
if(!Curl_ssl->sha256sum) {
|
|
|
|
/* without sha256 support, this cannot match */
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-06-30 20:23:54 -04:00
|
|
|
/* compute sha256sum of public key */
|
2017-09-06 03:32:02 -04:00
|
|
|
sha256sumdigest = malloc(CURL_SHA256_DIGEST_LENGTH);
|
2015-06-30 20:23:54 -04:00
|
|
|
if(!sha256sumdigest)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2018-04-02 13:33:00 -04:00
|
|
|
encode = Curl_ssl->sha256sum(pubkey, pubkeylen,
|
2017-09-06 03:32:02 -04:00
|
|
|
sha256sumdigest, CURL_SHA256_DIGEST_LENGTH);
|
2018-04-02 13:33:00 -04:00
|
|
|
|
|
|
|
if(encode != CURLE_OK)
|
|
|
|
return encode;
|
|
|
|
|
2015-09-12 17:35:12 -04:00
|
|
|
encode = Curl_base64_encode(data, (char *)sha256sumdigest,
|
2017-09-06 03:32:02 -04:00
|
|
|
CURL_SHA256_DIGEST_LENGTH, &encoded,
|
|
|
|
&encodedlen);
|
2015-09-12 17:35:12 -04:00
|
|
|
Curl_safefree(sha256sumdigest);
|
|
|
|
|
2015-09-19 22:40:40 -04:00
|
|
|
if(encode)
|
2015-09-12 17:35:12 -04:00
|
|
|
return encode;
|
|
|
|
|
2015-09-19 22:40:40 -04:00
|
|
|
infof(data, "\t public key hash: sha256//%s\n", encoded);
|
|
|
|
|
2015-06-30 20:23:54 -04:00
|
|
|
/* it starts with sha256//, copy so we can modify it */
|
|
|
|
pinkeylen = strlen(pinnedpubkey) + 1;
|
|
|
|
pinkeycopy = malloc(pinkeylen);
|
|
|
|
if(!pinkeycopy) {
|
2015-09-12 17:35:12 -04:00
|
|
|
Curl_safefree(encoded);
|
2015-06-30 20:23:54 -04:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
memcpy(pinkeycopy, pinnedpubkey, pinkeylen);
|
|
|
|
/* point begin_pos to the copy, and start extracting keys */
|
|
|
|
begin_pos = pinkeycopy;
|
|
|
|
do {
|
|
|
|
end_pos = strstr(begin_pos, ";sha256//");
|
|
|
|
/*
|
|
|
|
* if there is an end_pos, null terminate,
|
|
|
|
* otherwise it'll go to the end of the original string
|
|
|
|
*/
|
|
|
|
if(end_pos)
|
|
|
|
end_pos[0] = '\0';
|
|
|
|
|
2015-09-12 17:35:12 -04:00
|
|
|
/* compare base64 sha256 digests, 8 is the length of "sha256//" */
|
|
|
|
if(encodedlen == strlen(begin_pos + 8) &&
|
|
|
|
!memcmp(encoded, begin_pos + 8, encodedlen)) {
|
|
|
|
result = CURLE_OK;
|
|
|
|
break;
|
2015-06-30 20:23:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* change back the null-terminator we changed earlier,
|
|
|
|
* and look for next begin
|
|
|
|
*/
|
|
|
|
if(end_pos) {
|
|
|
|
end_pos[0] = ';';
|
|
|
|
begin_pos = strstr(end_pos, "sha256//");
|
|
|
|
}
|
|
|
|
} while(end_pos && begin_pos);
|
2015-09-12 17:35:12 -04:00
|
|
|
Curl_safefree(encoded);
|
2015-06-30 20:23:54 -04:00
|
|
|
Curl_safefree(pinkeycopy);
|
2016-05-01 11:05:38 -04:00
|
|
|
return result;
|
|
|
|
}
|
2015-06-30 20:23:54 -04:00
|
|
|
|
2014-10-13 12:34:51 -04:00
|
|
|
fp = fopen(pinnedpubkey, "rb");
|
|
|
|
if(!fp)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* Determine the file's size */
|
|
|
|
if(fseek(fp, 0, SEEK_END))
|
|
|
|
break;
|
2014-11-24 13:30:09 -05:00
|
|
|
filesize = ftell(fp);
|
2014-10-13 12:34:51 -04:00
|
|
|
if(fseek(fp, 0, SEEK_SET))
|
|
|
|
break;
|
2014-11-24 13:30:09 -05:00
|
|
|
if(filesize < 0 || filesize > MAX_PINNED_PUBKEY_SIZE)
|
|
|
|
break;
|
2014-10-13 12:34:51 -04:00
|
|
|
|
|
|
|
/*
|
2014-11-24 13:30:09 -05:00
|
|
|
* if the size of our certificate is bigger than the file
|
|
|
|
* size then it can't match
|
2014-10-13 12:34:51 -04:00
|
|
|
*/
|
2014-11-24 13:30:09 -05:00
|
|
|
size = curlx_sotouz((curl_off_t) filesize);
|
|
|
|
if(pubkeylen > size)
|
2014-10-13 12:34:51 -04:00
|
|
|
break;
|
|
|
|
|
2014-11-24 13:30:09 -05:00
|
|
|
/*
|
|
|
|
* Allocate buffer for the pinned key
|
|
|
|
* With 1 additional byte for null terminator in case of PEM key
|
|
|
|
*/
|
|
|
|
buf = malloc(size + 1);
|
2014-10-13 12:34:51 -04:00
|
|
|
if(!buf)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Returns number of elements read, which should be 1 */
|
2014-11-24 13:30:09 -05:00
|
|
|
if((int) fread(buf, size, 1, fp) != 1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* If the sizes are the same, it can't be base64 encoded, must be der */
|
|
|
|
if(pubkeylen == size) {
|
|
|
|
if(!memcmp(pubkey, buf, pubkeylen))
|
|
|
|
result = CURLE_OK;
|
2014-10-13 12:34:51 -04:00
|
|
|
break;
|
2014-11-24 13:30:09 -05:00
|
|
|
}
|
2014-10-13 12:34:51 -04:00
|
|
|
|
2014-11-24 13:30:09 -05:00
|
|
|
/*
|
|
|
|
* Otherwise we will assume it's PEM and try to decode it
|
|
|
|
* after placing null terminator
|
|
|
|
*/
|
|
|
|
buf[size] = '\0';
|
|
|
|
pem_read = pubkey_pem_to_der((const char *)buf, &pem_ptr, &pem_len);
|
|
|
|
/* if it wasn't read successfully, exit */
|
|
|
|
if(pem_read)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if the size of our certificate doesn't match the size of
|
|
|
|
* the decoded file, they can't be the same, otherwise compare
|
|
|
|
*/
|
|
|
|
if(pubkeylen == pem_len && !memcmp(pubkey, pem_ptr, pubkeylen))
|
2014-10-13 12:34:51 -04:00
|
|
|
result = CURLE_OK;
|
|
|
|
} while(0);
|
|
|
|
|
|
|
|
Curl_safefree(buf);
|
2014-11-24 13:30:09 -05:00
|
|
|
Curl_safefree(pem_ptr);
|
2014-10-13 12:34:51 -04:00
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-03-24 16:41:22 -04:00
|
|
|
#ifndef CURL_DISABLE_CRYPTO_AUTH
|
2015-03-25 03:32:12 -04:00
|
|
|
CURLcode Curl_ssl_md5sum(unsigned char *tmp, /* input */
|
|
|
|
size_t tmplen,
|
|
|
|
unsigned char *md5sum, /* output */
|
|
|
|
size_t md5len)
|
2012-06-26 08:52:46 -04:00
|
|
|
{
|
2017-06-22 19:04:56 -04:00
|
|
|
return Curl_ssl->md5sum(tmp, tmplen, md5sum, md5len);
|
2014-10-13 08:39:50 -04:00
|
|
|
}
|
2015-03-24 16:41:22 -04:00
|
|
|
#endif
|
2012-06-27 17:15:56 -04:00
|
|
|
|
2014-06-16 07:20:47 -04:00
|
|
|
/*
|
|
|
|
* Check whether the SSL backend supports the status_request extension.
|
|
|
|
*/
|
|
|
|
bool Curl_ssl_cert_status_request(void)
|
|
|
|
{
|
2017-06-22 18:22:47 -04:00
|
|
|
return Curl_ssl->cert_status_request();
|
2014-06-16 07:20:47 -04:00
|
|
|
}
|
|
|
|
|
2015-02-14 10:57:07 -05:00
|
|
|
/*
|
|
|
|
* Check whether the SSL backend supports false start.
|
|
|
|
*/
|
|
|
|
bool Curl_ssl_false_start(void)
|
|
|
|
{
|
2017-06-22 18:22:47 -04:00
|
|
|
return Curl_ssl->false_start();
|
2015-02-14 10:57:07 -05:00
|
|
|
}
|
|
|
|
|
2018-05-29 10:12:52 -04:00
|
|
|
/*
|
|
|
|
* Check whether the SSL backend supports setting TLS 1.3 cipher suites
|
|
|
|
*/
|
|
|
|
bool Curl_ssl_tls13_ciphersuites(void)
|
|
|
|
{
|
|
|
|
return Curl_ssl->supports & SSLSUPP_TLS13_CIPHERSUITES;
|
|
|
|
}
|
|
|
|
|
2017-06-22 10:45:34 -04:00
|
|
|
/*
|
|
|
|
* Default implementations for unsupported functions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int Curl_none_init(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Curl_none_cleanup(void)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
int Curl_none_shutdown(struct connectdata *conn UNUSED_PARAM,
|
|
|
|
int sockindex UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
(void)conn;
|
|
|
|
(void)sockindex;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Curl_none_check_cxn(struct connectdata *conn UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
(void)conn;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CURLcode Curl_none_random(struct Curl_easy *data UNUSED_PARAM,
|
|
|
|
unsigned char *entropy UNUSED_PARAM,
|
|
|
|
size_t length UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)entropy;
|
|
|
|
(void)length;
|
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Curl_none_close_all(struct Curl_easy *data UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Curl_none_session_free(void *ptr UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
(void)ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Curl_none_data_pending(const struct connectdata *conn UNUSED_PARAM,
|
|
|
|
int connindex UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
(void)conn;
|
|
|
|
(void)connindex;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Curl_none_cert_status_request(void)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CURLcode Curl_none_set_engine(struct Curl_easy *data UNUSED_PARAM,
|
|
|
|
const char *engine UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)engine;
|
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
}
|
|
|
|
|
|
|
|
CURLcode Curl_none_set_engine_default(struct Curl_easy *data UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct curl_slist *Curl_none_engines_list(struct Curl_easy *data UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return (struct curl_slist *)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Curl_none_false_start(void)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-10-04 18:20:34 -04:00
|
|
|
#ifndef CURL_DISABLE_CRYPTO_AUTH
|
2017-06-22 19:04:56 -04:00
|
|
|
CURLcode Curl_none_md5sum(unsigned char *input, size_t inputlen,
|
|
|
|
unsigned char *md5sum, size_t md5len UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
MD5_context *MD5pw;
|
|
|
|
|
|
|
|
(void)md5len;
|
|
|
|
|
|
|
|
MD5pw = Curl_MD5_init(Curl_DIGEST_MD5);
|
|
|
|
if(!MD5pw)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
Curl_MD5_update(MD5pw, input, curlx_uztoui(inputlen));
|
|
|
|
Curl_MD5_final(MD5pw, md5sum);
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2017-10-04 18:20:34 -04:00
|
|
|
#else
|
|
|
|
CURLcode Curl_none_md5sum(unsigned char *input UNUSED_PARAM,
|
|
|
|
size_t inputlen UNUSED_PARAM,
|
|
|
|
unsigned char *md5sum UNUSED_PARAM,
|
|
|
|
size_t md5len UNUSED_PARAM)
|
|
|
|
{
|
2017-10-06 13:01:19 -04:00
|
|
|
(void)input;
|
|
|
|
(void)inputlen;
|
|
|
|
(void)md5sum;
|
|
|
|
(void)md5len;
|
2017-10-04 18:20:34 -04:00
|
|
|
return CURLE_NOT_BUILT_IN;
|
|
|
|
}
|
|
|
|
#endif
|
2017-06-22 19:04:56 -04:00
|
|
|
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
static int Curl_multissl_init(void)
|
|
|
|
{
|
2017-07-07 05:49:08 -04:00
|
|
|
if(multissl_init(NULL))
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
return 1;
|
|
|
|
return Curl_ssl->init();
|
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode Curl_multissl_connect(struct connectdata *conn, int sockindex)
|
|
|
|
{
|
2017-07-07 05:49:08 -04:00
|
|
|
if(multissl_init(NULL))
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
return CURLE_FAILED_INIT;
|
2019-03-12 18:50:28 -04:00
|
|
|
return Curl_ssl->connect_blocking(conn, sockindex);
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode Curl_multissl_connect_nonblocking(struct connectdata *conn,
|
|
|
|
int sockindex, bool *done)
|
|
|
|
{
|
2017-07-07 05:49:08 -04:00
|
|
|
if(multissl_init(NULL))
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
return Curl_ssl->connect_nonblocking(conn, sockindex, done);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *Curl_multissl_get_internals(struct ssl_connect_data *connssl,
|
|
|
|
CURLINFO info)
|
|
|
|
{
|
2017-07-07 05:49:08 -04:00
|
|
|
if(multissl_init(NULL))
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
return NULL;
|
|
|
|
return Curl_ssl->get_internals(connssl, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Curl_multissl_close(struct connectdata *conn, int sockindex)
|
|
|
|
{
|
2017-07-07 05:49:08 -04:00
|
|
|
if(multissl_init(NULL))
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
return;
|
2017-10-19 14:55:17 -04:00
|
|
|
Curl_ssl->close_one(conn, sockindex);
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct Curl_ssl Curl_ssl_multi = {
|
2017-07-15 07:49:30 -04:00
|
|
|
{ CURLSSLBACKEND_NONE, "multi" }, /* info */
|
2018-05-04 06:10:39 -04:00
|
|
|
0, /* supports nothing */
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
(size_t)-1, /* something insanely large to be on the safe side */
|
|
|
|
|
|
|
|
Curl_multissl_init, /* init */
|
|
|
|
Curl_none_cleanup, /* cleanup */
|
|
|
|
Curl_multissl_version, /* version */
|
|
|
|
Curl_none_check_cxn, /* check_cxn */
|
|
|
|
Curl_none_shutdown, /* shutdown */
|
|
|
|
Curl_none_data_pending, /* data_pending */
|
|
|
|
Curl_none_random, /* random */
|
|
|
|
Curl_none_cert_status_request, /* cert_status_request */
|
|
|
|
Curl_multissl_connect, /* connect */
|
|
|
|
Curl_multissl_connect_nonblocking, /* connect_nonblocking */
|
|
|
|
Curl_multissl_get_internals, /* get_internals */
|
2017-10-19 14:55:17 -04:00
|
|
|
Curl_multissl_close, /* close_one */
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
Curl_none_close_all, /* close_all */
|
|
|
|
Curl_none_session_free, /* session_free */
|
|
|
|
Curl_none_set_engine, /* set_engine */
|
|
|
|
Curl_none_set_engine_default, /* set_engine_default */
|
|
|
|
Curl_none_engines_list, /* engines_list */
|
|
|
|
Curl_none_false_start, /* false_start */
|
|
|
|
Curl_none_md5sum, /* md5sum */
|
|
|
|
NULL /* sha256sum */
|
|
|
|
};
|
|
|
|
|
2017-08-18 07:15:12 -04:00
|
|
|
const struct Curl_ssl *Curl_ssl =
|
|
|
|
#if defined(CURL_WITH_MULTI_SSL)
|
|
|
|
&Curl_ssl_multi;
|
|
|
|
#elif defined(USE_CYASSL)
|
|
|
|
&Curl_ssl_cyassl;
|
2019-02-26 03:21:12 -05:00
|
|
|
#elif defined(USE_SECTRANSP)
|
|
|
|
&Curl_ssl_sectransp;
|
2017-08-18 07:15:12 -04:00
|
|
|
#elif defined(USE_GNUTLS)
|
|
|
|
&Curl_ssl_gnutls;
|
|
|
|
#elif defined(USE_GSKIT)
|
|
|
|
&Curl_ssl_gskit;
|
|
|
|
#elif defined(USE_MBEDTLS)
|
|
|
|
&Curl_ssl_mbedtls;
|
|
|
|
#elif defined(USE_NSS)
|
|
|
|
&Curl_ssl_nss;
|
|
|
|
#elif defined(USE_OPENSSL)
|
|
|
|
&Curl_ssl_openssl;
|
|
|
|
#elif defined(USE_POLARSSL)
|
|
|
|
&Curl_ssl_polarssl;
|
|
|
|
#elif defined(USE_SCHANNEL)
|
|
|
|
&Curl_ssl_schannel;
|
2018-09-10 16:08:21 -04:00
|
|
|
#elif defined(USE_MESALINK)
|
|
|
|
&Curl_ssl_mesalink;
|
2017-08-18 07:15:12 -04:00
|
|
|
#else
|
|
|
|
#error "Missing struct Curl_ssl for selected SSL backend"
|
|
|
|
#endif
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
|
|
|
|
static const struct Curl_ssl *available_backends[] = {
|
|
|
|
#if defined(USE_CYASSL)
|
|
|
|
&Curl_ssl_cyassl,
|
|
|
|
#endif
|
2019-02-26 03:21:12 -05:00
|
|
|
#if defined(USE_SECTRANSP)
|
|
|
|
&Curl_ssl_sectransp,
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
#endif
|
|
|
|
#if defined(USE_GNUTLS)
|
|
|
|
&Curl_ssl_gnutls,
|
|
|
|
#endif
|
|
|
|
#if defined(USE_GSKIT)
|
|
|
|
&Curl_ssl_gskit,
|
|
|
|
#endif
|
|
|
|
#if defined(USE_MBEDTLS)
|
|
|
|
&Curl_ssl_mbedtls,
|
|
|
|
#endif
|
|
|
|
#if defined(USE_NSS)
|
|
|
|
&Curl_ssl_nss,
|
|
|
|
#endif
|
|
|
|
#if defined(USE_OPENSSL)
|
|
|
|
&Curl_ssl_openssl,
|
|
|
|
#endif
|
|
|
|
#if defined(USE_POLARSSL)
|
|
|
|
&Curl_ssl_polarssl,
|
|
|
|
#endif
|
|
|
|
#if defined(USE_SCHANNEL)
|
|
|
|
&Curl_ssl_schannel,
|
2018-09-10 16:08:21 -04:00
|
|
|
#endif
|
|
|
|
#if defined(USE_MESALINK)
|
|
|
|
&Curl_ssl_mesalink,
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2017-08-18 07:01:38 -04:00
|
|
|
static size_t Curl_multissl_version(char *buffer, size_t size)
|
|
|
|
{
|
|
|
|
static const struct Curl_ssl *selected;
|
|
|
|
static char backends[200];
|
|
|
|
static size_t total;
|
|
|
|
const struct Curl_ssl *current;
|
|
|
|
|
|
|
|
current = Curl_ssl == &Curl_ssl_multi ? available_backends[0] : Curl_ssl;
|
|
|
|
|
|
|
|
if(current != selected) {
|
|
|
|
char *p = backends;
|
2019-05-13 14:27:50 -04:00
|
|
|
char *end = backends + sizeof(backends);
|
2017-08-18 07:01:38 -04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
selected = current;
|
|
|
|
|
2019-05-13 14:27:50 -04:00
|
|
|
for(i = 0; available_backends[i] && p < (end - 4); i++) {
|
2017-08-18 07:01:38 -04:00
|
|
|
if(i)
|
|
|
|
*(p++) = ' ';
|
|
|
|
if(selected != available_backends[i])
|
|
|
|
*(p++) = '(';
|
2019-05-13 14:27:50 -04:00
|
|
|
p += available_backends[i]->version(p, end - p - 2);
|
2017-08-18 07:01:38 -04:00
|
|
|
if(selected != available_backends[i])
|
|
|
|
*(p++) = ')';
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
total = p - backends;
|
|
|
|
}
|
|
|
|
|
2019-05-13 14:27:50 -04:00
|
|
|
if(size > total)
|
2017-08-18 07:01:38 -04:00
|
|
|
memcpy(buffer, backends, total + 1);
|
|
|
|
else {
|
|
|
|
memcpy(buffer, backends, size - 1);
|
|
|
|
buffer[size - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
2019-05-13 14:27:50 -04:00
|
|
|
return CURLMIN(size - 1, total);
|
2017-08-18 07:01:38 -04:00
|
|
|
}
|
|
|
|
|
2017-07-07 05:49:08 -04:00
|
|
|
static int multissl_init(const struct Curl_ssl *backend)
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
{
|
|
|
|
const char *env;
|
2017-12-10 13:40:44 -05:00
|
|
|
char *env_tmp;
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if(Curl_ssl != &Curl_ssl_multi)
|
|
|
|
return 1;
|
|
|
|
|
2017-07-07 05:49:08 -04:00
|
|
|
if(backend) {
|
|
|
|
Curl_ssl = backend;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
if(!available_backends[0])
|
|
|
|
return 1;
|
|
|
|
|
2017-12-10 13:40:44 -05:00
|
|
|
env = env_tmp = curl_getenv("CURL_SSL_BACKEND");
|
2017-08-24 16:26:48 -04:00
|
|
|
#ifdef CURL_DEFAULT_SSL_BACKEND
|
|
|
|
if(!env)
|
|
|
|
env = CURL_DEFAULT_SSL_BACKEND;
|
|
|
|
#endif
|
2017-09-06 02:22:49 -04:00
|
|
|
if(env) {
|
|
|
|
for(i = 0; available_backends[i]; i++) {
|
|
|
|
if(strcasecompare(env, available_backends[i]->info.name)) {
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
Curl_ssl = available_backends[i];
|
2017-12-10 13:40:44 -05:00
|
|
|
curl_free(env_tmp);
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2017-09-06 02:22:49 -04:00
|
|
|
}
|
|
|
|
}
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
|
|
|
|
/* Fall back to first available backend */
|
|
|
|
Curl_ssl = available_backends[0];
|
2017-12-10 13:40:44 -05:00
|
|
|
curl_free(env_tmp);
|
vtls: allow selecting which SSL backend to use at runtime
When building software for the masses, it is sometimes not possible to
decide for all users which SSL backend is appropriate.
Git for Windows, for example, uses cURL to perform clones, fetches and
pushes via HTTPS, and some users strongly prefer OpenSSL, while other
users really need to use Secure Channel because it offers
enterprise-ready tools to manage credentials via Windows' Credential
Store.
The current Git for Windows versions use the ugly work-around of
building libcurl once with OpenSSL support and once with Secure Channel
support, and switching out the binaries in the installer depending on
the user's choice.
Needless to say, this is a super ugly workaround that actually only
works in some cases: Git for Windows also comes in a portable form, and
in a form intended for third-party applications requiring Git
functionality, in which cases this "swap out libcurl-4.dll" simply is
not an option.
Therefore, the Git for Windows project has a vested interest in teaching
cURL to make the SSL backend a *runtime* option.
This patch makes that possible.
By running ./configure with multiple --with-<backend> options, cURL will
be built with multiple backends.
For the moment, the backend can be configured using the environment
variable CURL_SSL_BACKEND (valid values are e.g. "openssl" and
"schannel").
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2017-06-14 10:56:00 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-07 05:49:08 -04:00
|
|
|
CURLsslset curl_global_sslset(curl_sslbackend id, const char *name,
|
|
|
|
const curl_ssl_backend ***avail)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2018-04-15 04:35:06 -04:00
|
|
|
if(avail)
|
|
|
|
*avail = (const curl_ssl_backend **)&available_backends;
|
|
|
|
|
2017-07-07 05:49:08 -04:00
|
|
|
if(Curl_ssl != &Curl_ssl_multi)
|
2018-12-06 11:18:43 -05:00
|
|
|
return id == Curl_ssl->info.id ||
|
|
|
|
(name && strcasecompare(name, Curl_ssl->info.name)) ?
|
|
|
|
CURLSSLSET_OK :
|
|
|
|
#if defined(CURL_WITH_MULTI_SSL)
|
|
|
|
CURLSSLSET_TOO_LATE;
|
|
|
|
#else
|
|
|
|
CURLSSLSET_UNKNOWN_BACKEND;
|
|
|
|
#endif
|
2017-07-07 05:49:08 -04:00
|
|
|
|
2017-09-06 02:22:49 -04:00
|
|
|
for(i = 0; available_backends[i]; i++) {
|
2017-07-07 05:49:08 -04:00
|
|
|
if(available_backends[i]->info.id == id ||
|
2017-09-06 02:22:49 -04:00
|
|
|
(name && strcasecompare(available_backends[i]->info.name, name))) {
|
2017-07-07 05:49:08 -04:00
|
|
|
multissl_init(available_backends[i]);
|
|
|
|
return CURLSSLSET_OK;
|
|
|
|
}
|
2017-09-06 02:22:49 -04:00
|
|
|
}
|
2017-07-07 05:49:08 -04:00
|
|
|
|
|
|
|
return CURLSSLSET_UNKNOWN_BACKEND;
|
|
|
|
}
|
|
|
|
|
2017-09-21 17:30:48 -04:00
|
|
|
#else /* USE_SSL */
|
|
|
|
CURLsslset curl_global_sslset(curl_sslbackend id, const char *name,
|
|
|
|
const curl_ssl_backend ***avail)
|
|
|
|
{
|
|
|
|
(void)id;
|
|
|
|
(void)name;
|
|
|
|
(void)avail;
|
|
|
|
return CURLSSLSET_NO_BACKENDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !USE_SSL */
|