2016-06-14 13:55:28 +02:00
|
|
|
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates.
|
|
|
|
Copyright (c) 2011, 2016, MariaDB
|
2001-12-06 13:10:51 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
2001-07-24 08:07:46 +02:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2001-12-06 13:10:51 +01:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2001-12-06 13:10:51 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2019-05-11 20:29:06 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2003-08-27 01:51:39 +02:00
|
|
|
#include "vio_priv.h"
|
2017-05-03 21:22:59 +02:00
|
|
|
#include <ssl_compat.h>
|
2001-07-24 08:07:46 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_OPENSSL
|
2016-02-05 14:04:24 +01:00
|
|
|
#include <openssl/dh.h>
|
|
|
|
#include <openssl/bn.h>
|
2024-03-05 04:46:28 +01:00
|
|
|
#include <openssl/x509.h>
|
2001-07-24 08:07:46 +02:00
|
|
|
|
2008-02-18 23:29:39 +01:00
|
|
|
static my_bool ssl_algorithms_added = FALSE;
|
|
|
|
static my_bool ssl_error_strings_loaded= FALSE;
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2024-03-05 04:46:28 +01:00
|
|
|
#ifndef X509_VERSION_3
|
|
|
|
#define X509_VERSION_3 2
|
|
|
|
#endif
|
|
|
|
|
2015-07-28 19:11:53 +02:00
|
|
|
/* the function below was generated with "openssl dhparam -2 -C 2048" */
|
2022-01-24 20:00:35 +01:00
|
|
|
#ifndef HAVE_WOLFSSL
|
2017-05-03 21:22:59 +02:00
|
|
|
static
|
|
|
|
DH *get_dh2048()
|
2001-08-31 23:51:52 +02:00
|
|
|
{
|
2017-05-03 21:22:59 +02:00
|
|
|
static unsigned char dhp_2048[] = {
|
|
|
|
0xA1,0xBB,0x7C,0x20,0xC5,0x5B,0xC0,0x7B,0x21,0x8B,0xD6,0xA8,
|
|
|
|
0x15,0xFC,0x3B,0xBA,0xAB,0x9F,0xDF,0x68,0xC4,0x79,0x78,0x0D,
|
|
|
|
0xC1,0x12,0x64,0xE4,0x15,0xC9,0x66,0xDB,0xF6,0xCB,0xB3,0x39,
|
|
|
|
0x02,0x5B,0x78,0x62,0xFB,0x09,0xAE,0x09,0x6B,0xDD,0xD4,0x5D,
|
|
|
|
0x97,0xBC,0xDC,0x7F,0xE6,0xD6,0xF1,0xCB,0xF5,0xEB,0xDA,0xA7,
|
|
|
|
0x2E,0x5A,0x43,0x2B,0xE9,0x40,0xE2,0x85,0x00,0x1C,0xC0,0x0A,
|
|
|
|
0x98,0x77,0xA9,0x31,0xDE,0x0B,0x75,0x4D,0x1E,0x1F,0x16,0x83,
|
|
|
|
0xCA,0xDE,0xBD,0x21,0xFC,0xC1,0x82,0x37,0x36,0x33,0x0B,0x66,
|
|
|
|
0x06,0x3C,0xF3,0xAF,0x21,0x57,0x57,0x80,0xF6,0x94,0x1B,0xA9,
|
|
|
|
0xD4,0xF6,0x8F,0x18,0x62,0x0E,0xC4,0x22,0xF9,0x5B,0x62,0xCC,
|
|
|
|
0x3F,0x19,0x95,0xCF,0x4B,0x00,0xA6,0x6C,0x0B,0xAF,0x9F,0xD5,
|
|
|
|
0xFA,0x3D,0x6D,0xDA,0x30,0x83,0x07,0x91,0xAC,0x15,0xFF,0x8F,
|
|
|
|
0x59,0x54,0xEA,0x25,0xBC,0x4E,0xEB,0x6A,0x54,0xDF,0x75,0x09,
|
|
|
|
0x72,0x0F,0xEF,0x23,0x70,0xE0,0xA8,0x04,0xEA,0xFF,0x90,0x54,
|
|
|
|
0xCD,0x84,0x18,0xC0,0x75,0x91,0x99,0x0F,0xA1,0x78,0x0C,0x07,
|
|
|
|
0xB7,0xC5,0xDE,0x55,0x06,0x7B,0x95,0x68,0x2C,0x33,0x39,0xBC,
|
|
|
|
0x2C,0xD0,0x6D,0xDD,0xFA,0xDC,0xB5,0x8F,0x82,0x39,0xF8,0x67,
|
|
|
|
0x44,0xF1,0xD8,0xF7,0x78,0x11,0x9A,0x77,0x9B,0x53,0x47,0xD6,
|
|
|
|
0x2B,0x5D,0x67,0xB8,0xB7,0xBC,0xC1,0xD7,0x79,0x62,0x15,0xC2,
|
|
|
|
0xC5,0x83,0x97,0xA7,0xF8,0xB4,0x9C,0xF6,0x8F,0x9A,0xC7,0xDA,
|
|
|
|
0x1B,0xBB,0x87,0x07,0xA7,0x71,0xAD,0xB2,0x8A,0x50,0xF8,0x26,
|
|
|
|
0x12,0xB7,0x3E,0x0B,
|
|
|
|
};
|
|
|
|
static unsigned char dhg_2048[] = {
|
|
|
|
0x02
|
|
|
|
};
|
|
|
|
DH *dh = DH_new();
|
|
|
|
BIGNUM *dhp_bn, *dhg_bn;
|
|
|
|
|
|
|
|
if (dh == NULL)
|
|
|
|
return NULL;
|
|
|
|
dhp_bn = BN_bin2bn(dhp_2048, sizeof (dhp_2048), NULL);
|
|
|
|
dhg_bn = BN_bin2bn(dhg_2048, sizeof (dhg_2048), NULL);
|
|
|
|
if (dhp_bn == NULL || dhg_bn == NULL
|
|
|
|
|| !DH_set0_pqg(dh, dhp_bn, NULL, dhg_bn)) {
|
|
|
|
DH_free(dh);
|
|
|
|
BN_free(dhp_bn);
|
|
|
|
BN_free(dhg_bn);
|
|
|
|
return NULL;
|
2017-03-08 17:39:47 +01:00
|
|
|
}
|
2017-05-03 21:22:59 +02:00
|
|
|
return dh;
|
2001-08-31 23:51:52 +02:00
|
|
|
}
|
2022-01-24 20:00:35 +01:00
|
|
|
#endif
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2009-07-23 13:38:11 +02:00
|
|
|
static const char*
|
2017-03-08 17:39:47 +01:00
|
|
|
ssl_error_string[] =
|
2009-07-23 13:38:11 +02:00
|
|
|
{
|
|
|
|
"No error",
|
|
|
|
"Unable to get certificate",
|
|
|
|
"Unable to get private key",
|
2012-12-01 16:33:22 +01:00
|
|
|
"Private key does not match the certificate public key",
|
2009-07-23 13:38:11 +02:00
|
|
|
"SSL_CTX_set_default_verify_paths failed",
|
|
|
|
"Failed to set ciphers to use",
|
2015-05-02 12:32:10 +02:00
|
|
|
"SSL_CTX_new failed",
|
MDEV-14101 Provide an option to select TLS protocol version
Server and command line tools now support option --tls_version to specify the
TLS version between client and server. Valid values are TLSv1.0, TLSv1.1, TLSv1.2, TLSv1.3
or a combination of them. E.g.
--tls_version=TLSv1.3
--tls_version=TLSv1.2,TLSv1.3
In case there is a gap between versions, the lowest version will be used:
--tls_version=TLSv1.1,TLSv1.3 -> Only TLSv1.1 will be available.
If the used TLS library doesn't support the specified TLS version, it will use
the default configuration.
Limitations:
SSLv3 is not supported. The default configuration doesn't support TLSv1.0 anymore.
TLSv1.3 protocol currently is only supported by OpenSSL 1.1.0 (client and server) and
GnuTLS 3.6.5 (client only).
Overview of TLS implementations and protocols
Server:
+-----------+-----------------------------------------+
| Library | Supported TLS versions |
+-----------+-----------------------------------------+
| WolfSSL | TLSv1.1, TLSv1,2 |
+-----------+-----------------------------------------+
| OpenSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
| LibreSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
Client (MariaDB Connector/C)
+-----------+-----------------------------------------+
| Library | Supported TLS versions |
+-----------+-----------------------------------------+
| GnuTLS | (TLSv1.0), TLSv1.1, TLSv1.2, TLSv1.3 |
+-----------+-----------------------------------------+
| Schannel | (TLSv1.0), TLSv1.1, TLSv1.2 |
+-----------+-----------------------------------------+
| OpenSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
| LibreSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
2019-06-11 12:44:16 +02:00
|
|
|
"SSL_CTX_set_tmp_dh failed",
|
|
|
|
"Unknown TLS version"
|
2009-07-23 13:38:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const char*
|
|
|
|
sslGetErrString(enum enum_ssl_init_error e)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(SSL_INITERR_NOERROR < e && e < SSL_INITERR_LASTERR);
|
|
|
|
return ssl_error_string[e];
|
|
|
|
}
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2023-08-23 17:45:57 +02:00
|
|
|
static EVP_PKEY *vio_keygen()
|
|
|
|
{
|
|
|
|
EVP_PKEY_CTX *ctx;
|
|
|
|
EVP_PKEY *pkey = NULL;
|
|
|
|
|
|
|
|
if (!(ctx= EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (EVP_PKEY_keygen_init(ctx) <= 0)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, 4096) <= 0)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (EVP_PKEY_keygen(ctx, &pkey) <= 0)
|
|
|
|
pkey= NULL; /* just in case */
|
|
|
|
|
|
|
|
end:
|
|
|
|
EVP_PKEY_CTX_free(ctx);
|
|
|
|
return pkey;
|
|
|
|
}
|
|
|
|
|
|
|
|
static X509 *vio_gencert(EVP_PKEY *pkey)
|
|
|
|
{
|
|
|
|
X509 *x;
|
|
|
|
X509_NAME *name;
|
|
|
|
|
|
|
|
if (!(x= X509_new()))
|
|
|
|
goto err;
|
|
|
|
|
2024-03-05 04:46:28 +01:00
|
|
|
if (!X509_set_version(x, X509_VERSION_3))
|
|
|
|
goto err;
|
2023-08-23 17:45:57 +02:00
|
|
|
if (!(name= X509_get_subject_name(x)))
|
|
|
|
goto err;
|
|
|
|
if (!X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC,
|
|
|
|
(uchar*)STRING_WITH_LEN("MariaDB Server"), -1, 0))
|
|
|
|
goto err;
|
|
|
|
if (!X509_set_issuer_name(x, name))
|
|
|
|
goto err;
|
|
|
|
if (!X509_gmtime_adj(X509_get_notBefore(x), 0))
|
|
|
|
goto err;
|
|
|
|
if (!X509_gmtime_adj(X509_get_notAfter(x), 60*60*24*365*10))
|
|
|
|
goto err;
|
|
|
|
if (!X509_set_pubkey(x, pkey))
|
|
|
|
goto err;
|
|
|
|
if (!X509_sign(x, pkey, EVP_sha256()))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return x;
|
|
|
|
|
|
|
|
err:
|
|
|
|
X509_free(x);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-05-20 14:04:46 +02:00
|
|
|
static int
|
2009-07-23 13:38:11 +02:00
|
|
|
vio_set_cert_stuff(SSL_CTX *ctx, const char *cert_file, const char *key_file,
|
2022-10-21 19:50:07 +02:00
|
|
|
my_bool is_client, enum enum_ssl_init_error* error)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("vio_set_cert_stuff");
|
2017-09-19 19:45:17 +02:00
|
|
|
DBUG_PRINT("enter", ("ctx: %p cert_file: %s key_file: %s",
|
|
|
|
ctx, cert_file, key_file));
|
2006-03-10 16:41:14 +01:00
|
|
|
|
2023-08-23 17:45:21 +02:00
|
|
|
if (!cert_file && !key_file)
|
|
|
|
{
|
|
|
|
if (!is_client)
|
|
|
|
{
|
2023-08-23 17:45:57 +02:00
|
|
|
EVP_PKEY *pkey;
|
|
|
|
X509 *x509;
|
|
|
|
if (!(pkey= vio_keygen()) || SSL_CTX_use_PrivateKey(ctx, pkey) < 1)
|
|
|
|
{
|
|
|
|
*error= SSL_INITERR_KEY;
|
|
|
|
fprintf(stderr, "SSL error: %s\n", sslGetErrString(*error));
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(x509= vio_gencert(pkey)) || SSL_CTX_use_certificate(ctx, x509) < 1)
|
|
|
|
{
|
|
|
|
*error= SSL_INITERR_CERT;
|
|
|
|
fprintf(stderr, "SSL error: %s\n", sslGetErrString(*error));
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
EVP_PKEY_free(pkey); /* decrement refcnt */
|
|
|
|
X509_free(x509); /* ditto */
|
2023-08-23 17:45:21 +02:00
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cert and key can be combined in one file */
|
|
|
|
if (!cert_file)
|
2012-08-11 12:13:04 +02:00
|
|
|
cert_file= key_file;
|
2023-08-23 17:45:21 +02:00
|
|
|
else if (!key_file)
|
2012-08-11 12:13:04 +02:00
|
|
|
key_file= cert_file;
|
2006-03-10 16:41:14 +01:00
|
|
|
|
2023-08-23 17:45:21 +02:00
|
|
|
if (SSL_CTX_use_certificate_chain_file(ctx, cert_file) <= 0)
|
2012-08-11 12:13:04 +02:00
|
|
|
{
|
|
|
|
*error= SSL_INITERR_CERT;
|
|
|
|
DBUG_PRINT("error",("%s from file '%s'", sslGetErrString(*error), cert_file));
|
|
|
|
DBUG_EXECUTE("error", ERR_print_errors_fp(DBUG_FILE););
|
|
|
|
fprintf(stderr, "SSL error: %s from '%s'\n", sslGetErrString(*error),
|
|
|
|
cert_file);
|
|
|
|
fflush(stderr);
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2023-08-23 17:45:21 +02:00
|
|
|
if (SSL_CTX_use_PrivateKey_file(ctx, key_file, SSL_FILETYPE_PEM) <= 0)
|
2012-08-11 12:13:04 +02:00
|
|
|
{
|
|
|
|
*error= SSL_INITERR_KEY;
|
|
|
|
DBUG_PRINT("error", ("%s from file '%s'", sslGetErrString(*error), key_file));
|
|
|
|
DBUG_EXECUTE("error", ERR_print_errors_fp(DBUG_FILE););
|
|
|
|
fprintf(stderr, "SSL error: %s from '%s'\n", sslGetErrString(*error),
|
|
|
|
key_file);
|
|
|
|
fflush(stderr);
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-10-21 19:50:07 +02:00
|
|
|
If certificate is used check if private key matches.
|
|
|
|
Note, that server side has to use certificate.
|
2012-08-11 12:13:04 +02:00
|
|
|
*/
|
2023-08-23 17:45:21 +02:00
|
|
|
if (!SSL_CTX_check_private_key(ctx))
|
2012-08-11 12:13:04 +02:00
|
|
|
{
|
|
|
|
*error= SSL_INITERR_NOMATCH;
|
|
|
|
DBUG_PRINT("error", ("%s",sslGetErrString(*error)));
|
|
|
|
DBUG_EXECUTE("error", ERR_print_errors_fp(DBUG_FILE););
|
|
|
|
fprintf(stderr, "SSL error: %s\n", sslGetErrString(*error));
|
|
|
|
fflush(stderr);
|
|
|
|
DBUG_RETURN(1);
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
2012-08-11 12:13:04 +02:00
|
|
|
|
2006-03-10 16:41:14 +01:00
|
|
|
DBUG_RETURN(0);
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-16 21:01:16 +02:00
|
|
|
void vio_check_ssl_init()
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
|
|
|
if (!ssl_algorithms_added)
|
|
|
|
{
|
2006-03-10 16:41:14 +01:00
|
|
|
ssl_algorithms_added= TRUE;
|
2017-03-08 17:39:47 +01:00
|
|
|
OPENSSL_init_ssl(0, NULL);
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
2006-03-10 16:41:14 +01:00
|
|
|
|
2001-05-20 14:04:46 +02:00
|
|
|
if (!ssl_error_strings_loaded)
|
|
|
|
{
|
2006-03-10 16:41:14 +01:00
|
|
|
ssl_error_strings_loaded= TRUE;
|
2001-05-20 14:04:46 +02:00
|
|
|
SSL_load_error_strings();
|
|
|
|
}
|
2006-03-10 16:41:14 +01:00
|
|
|
}
|
|
|
|
|
2019-02-13 09:08:06 +01:00
|
|
|
#ifdef HAVE_WOLFSSL
|
|
|
|
static int wolfssl_recv(WOLFSSL* ssl, char* buf, int sz, void* vio)
|
|
|
|
{
|
|
|
|
size_t ret;
|
|
|
|
(void)ssl;
|
|
|
|
ret = vio_read((Vio *)vio, (uchar *)buf, sz);
|
|
|
|
/* check if connection was closed */
|
|
|
|
if (ret == 0)
|
|
|
|
return WOLFSSL_CBIO_ERR_CONN_CLOSE;
|
|
|
|
|
|
|
|
return (int)ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wolfssl_send(WOLFSSL* ssl, char* buf, int sz, void* vio)
|
|
|
|
{
|
|
|
|
return (int)vio_write((Vio *)vio, (unsigned char*)buf, sz);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_WOLFSSL */
|
|
|
|
|
MDEV-14101 Provide an option to select TLS protocol version
Server and command line tools now support option --tls_version to specify the
TLS version between client and server. Valid values are TLSv1.0, TLSv1.1, TLSv1.2, TLSv1.3
or a combination of them. E.g.
--tls_version=TLSv1.3
--tls_version=TLSv1.2,TLSv1.3
In case there is a gap between versions, the lowest version will be used:
--tls_version=TLSv1.1,TLSv1.3 -> Only TLSv1.1 will be available.
If the used TLS library doesn't support the specified TLS version, it will use
the default configuration.
Limitations:
SSLv3 is not supported. The default configuration doesn't support TLSv1.0 anymore.
TLSv1.3 protocol currently is only supported by OpenSSL 1.1.0 (client and server) and
GnuTLS 3.6.5 (client only).
Overview of TLS implementations and protocols
Server:
+-----------+-----------------------------------------+
| Library | Supported TLS versions |
+-----------+-----------------------------------------+
| WolfSSL | TLSv1.1, TLSv1,2 |
+-----------+-----------------------------------------+
| OpenSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
| LibreSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
Client (MariaDB Connector/C)
+-----------+-----------------------------------------+
| Library | Supported TLS versions |
+-----------+-----------------------------------------+
| GnuTLS | (TLSv1.0), TLSv1.1, TLSv1.2, TLSv1.3 |
+-----------+-----------------------------------------+
| Schannel | (TLSv1.0), TLSv1.1, TLSv1.2 |
+-----------+-----------------------------------------+
| OpenSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
| LibreSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
2019-06-11 12:44:16 +02:00
|
|
|
static long vio_tls_protocol_options(ulonglong tls_version)
|
|
|
|
{
|
|
|
|
long tls_protocol_flags=
|
|
|
|
#ifdef TLS1_3_VERSION
|
|
|
|
SSL_OP_NO_TLSv1_3 |
|
|
|
|
#endif
|
|
|
|
#if defined(TLS1_2_VERSION) || defined(HAVE_WOLFSSL)
|
|
|
|
SSL_OP_NO_TLSv1_2 |
|
|
|
|
#endif
|
|
|
|
SSL_OP_NO_TLSv1_1 |
|
|
|
|
SSL_OP_NO_TLSv1;
|
|
|
|
long disabled_tls_protocols= tls_protocol_flags,
|
|
|
|
disabled_ssl_protocols= SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3;
|
|
|
|
|
|
|
|
if (!tls_version)
|
|
|
|
return disabled_ssl_protocols;
|
|
|
|
|
|
|
|
if (tls_version & VIO_TLSv1_0)
|
|
|
|
disabled_tls_protocols&= ~SSL_OP_NO_TLSv1;
|
|
|
|
if (tls_version & VIO_TLSv1_1)
|
|
|
|
disabled_tls_protocols&= ~SSL_OP_NO_TLSv1_1;
|
|
|
|
#if defined(TLS1_2_VERSION) || defined(HAVE_WOLFSSL)
|
|
|
|
if (tls_version & VIO_TLSv1_2)
|
|
|
|
disabled_tls_protocols&= ~SSL_OP_NO_TLSv1_2;
|
|
|
|
#endif
|
|
|
|
#ifdef TLS1_3_VERSION
|
|
|
|
if (tls_version & VIO_TLSv1_3)
|
|
|
|
disabled_tls_protocols&= ~SSL_OP_NO_TLSv1_3;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* some garbage was specified in tls_version option */
|
|
|
|
if (tls_protocol_flags == disabled_tls_protocols)
|
|
|
|
return -1;
|
|
|
|
return (disabled_tls_protocols | disabled_ssl_protocols);
|
|
|
|
}
|
|
|
|
|
2023-08-23 15:23:22 +02:00
|
|
|
/*
|
|
|
|
If some optional parameters indicate empty strings, then
|
|
|
|
for compatibility with SSL libraries, replace them with NULL,
|
|
|
|
otherwise these libraries will try to open files with an empty
|
|
|
|
name, etc., and they will return an error code instead of performing
|
|
|
|
the necessary operations:
|
|
|
|
*/
|
|
|
|
#define fix_value(X) if (X && !X[0]) X= NULL
|
|
|
|
|
2006-03-10 16:41:14 +01:00
|
|
|
/************************ VioSSLFd **********************************/
|
2006-05-08 17:14:06 +02:00
|
|
|
static struct st_VioSSLFd *
|
2023-08-23 15:23:22 +02:00
|
|
|
new_VioSSLFd(const char *key_file, const char *cert_file, const char *ca_file,
|
|
|
|
const char *ca_path, const char *cipher, my_bool is_client_method,
|
|
|
|
enum enum_ssl_init_error *error, const char *crl_file,
|
|
|
|
const char *crl_path, ulonglong tls_version)
|
2006-03-10 16:41:14 +01:00
|
|
|
{
|
|
|
|
struct st_VioSSLFd *ssl_fd;
|
MDEV-14101 Provide an option to select TLS protocol version
Server and command line tools now support option --tls_version to specify the
TLS version between client and server. Valid values are TLSv1.0, TLSv1.1, TLSv1.2, TLSv1.3
or a combination of them. E.g.
--tls_version=TLSv1.3
--tls_version=TLSv1.2,TLSv1.3
In case there is a gap between versions, the lowest version will be used:
--tls_version=TLSv1.1,TLSv1.3 -> Only TLSv1.1 will be available.
If the used TLS library doesn't support the specified TLS version, it will use
the default configuration.
Limitations:
SSLv3 is not supported. The default configuration doesn't support TLSv1.0 anymore.
TLSv1.3 protocol currently is only supported by OpenSSL 1.1.0 (client and server) and
GnuTLS 3.6.5 (client only).
Overview of TLS implementations and protocols
Server:
+-----------+-----------------------------------------+
| Library | Supported TLS versions |
+-----------+-----------------------------------------+
| WolfSSL | TLSv1.1, TLSv1,2 |
+-----------+-----------------------------------------+
| OpenSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
| LibreSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
Client (MariaDB Connector/C)
+-----------+-----------------------------------------+
| Library | Supported TLS versions |
+-----------+-----------------------------------------+
| GnuTLS | (TLSv1.0), TLSv1.1, TLSv1.2, TLSv1.3 |
+-----------+-----------------------------------------+
| Schannel | (TLSv1.0), TLSv1.1, TLSv1.2 |
+-----------+-----------------------------------------+
| OpenSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
| LibreSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
2019-06-11 12:44:16 +02:00
|
|
|
long ssl_ctx_options;
|
2006-03-10 16:41:14 +01:00
|
|
|
DBUG_ENTER("new_VioSSLFd");
|
2021-12-14 03:47:59 +01:00
|
|
|
|
2023-08-23 17:45:57 +02:00
|
|
|
fix_value(key_file);
|
|
|
|
fix_value(cert_file);
|
2023-08-23 15:23:22 +02:00
|
|
|
fix_value(ca_file);
|
|
|
|
fix_value(ca_path);
|
|
|
|
fix_value(crl_file);
|
|
|
|
fix_value(crl_path);
|
2023-09-02 15:09:48 +02:00
|
|
|
fix_value(cipher);
|
2021-12-14 03:47:59 +01:00
|
|
|
|
2007-02-23 12:13:55 +01:00
|
|
|
DBUG_PRINT("enter",
|
|
|
|
("key_file: '%s' cert_file: '%s' ca_file: '%s' ca_path: '%s' "
|
2023-08-23 15:23:22 +02:00
|
|
|
"cipher: '%s' crl_file: '%s' crl_path: '%s'", key_file,
|
|
|
|
cert_file, ca_file, ca_path, cipher, crl_file, crl_path));
|
2006-03-10 16:41:14 +01:00
|
|
|
|
2020-06-16 21:01:16 +02:00
|
|
|
vio_check_ssl_init();
|
2006-03-10 16:41:14 +01:00
|
|
|
|
|
|
|
if (!(ssl_fd= ((struct st_VioSSLFd*)
|
2020-01-29 13:50:26 +01:00
|
|
|
my_malloc(key_memory_vio_ssl_fd,
|
|
|
|
sizeof(struct st_VioSSLFd), MYF(0)))))
|
2015-05-02 12:32:10 +02:00
|
|
|
goto err0;
|
2012-05-15 12:12:22 +02:00
|
|
|
if (!(ssl_fd->ssl_context= SSL_CTX_new(is_client_method ?
|
2014-11-18 17:57:06 +01:00
|
|
|
SSLv23_client_method() :
|
|
|
|
SSLv23_server_method())))
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
2009-07-23 13:38:11 +02:00
|
|
|
*error= SSL_INITERR_MEMFAIL;
|
|
|
|
DBUG_PRINT("error", ("%s", sslGetErrString(*error)));
|
2015-05-02 12:32:10 +02:00
|
|
|
goto err1;
|
2001-09-30 04:46:20 +02:00
|
|
|
}
|
2006-03-10 16:41:14 +01:00
|
|
|
|
MDEV-14101 Provide an option to select TLS protocol version
Server and command line tools now support option --tls_version to specify the
TLS version between client and server. Valid values are TLSv1.0, TLSv1.1, TLSv1.2, TLSv1.3
or a combination of them. E.g.
--tls_version=TLSv1.3
--tls_version=TLSv1.2,TLSv1.3
In case there is a gap between versions, the lowest version will be used:
--tls_version=TLSv1.1,TLSv1.3 -> Only TLSv1.1 will be available.
If the used TLS library doesn't support the specified TLS version, it will use
the default configuration.
Limitations:
SSLv3 is not supported. The default configuration doesn't support TLSv1.0 anymore.
TLSv1.3 protocol currently is only supported by OpenSSL 1.1.0 (client and server) and
GnuTLS 3.6.5 (client only).
Overview of TLS implementations and protocols
Server:
+-----------+-----------------------------------------+
| Library | Supported TLS versions |
+-----------+-----------------------------------------+
| WolfSSL | TLSv1.1, TLSv1,2 |
+-----------+-----------------------------------------+
| OpenSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
| LibreSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
Client (MariaDB Connector/C)
+-----------+-----------------------------------------+
| Library | Supported TLS versions |
+-----------+-----------------------------------------+
| GnuTLS | (TLSv1.0), TLSv1.1, TLSv1.2, TLSv1.3 |
+-----------+-----------------------------------------+
| Schannel | (TLSv1.0), TLSv1.1, TLSv1.2 |
+-----------+-----------------------------------------+
| OpenSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
| LibreSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
2019-06-11 12:44:16 +02:00
|
|
|
ssl_ctx_options= vio_tls_protocol_options(tls_version);
|
|
|
|
if (ssl_ctx_options == -1)
|
|
|
|
{
|
|
|
|
*error= SSL_INITERR_PROTOCOL;
|
|
|
|
DBUG_PRINT("error", ("%s", sslGetErrString(*error)));
|
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
2015-01-02 05:48:04 +01:00
|
|
|
SSL_CTX_set_options(ssl_fd->ssl_context, ssl_ctx_options);
|
2014-11-19 18:54:02 +01:00
|
|
|
|
2007-04-02 13:12:59 +02:00
|
|
|
/*
|
|
|
|
Set the ciphers that can be used
|
2024-09-04 02:58:59 +02:00
|
|
|
NOTE: SSL_CTX_set_ciphersuites/SSL_CTX_set_cipher_list will return 0 if
|
2007-04-02 13:12:59 +02:00
|
|
|
none of the provided ciphers could be selected
|
|
|
|
*/
|
2024-09-04 02:58:59 +02:00
|
|
|
if (cipher)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
2024-09-04 02:58:59 +02:00
|
|
|
int cipher_result= 0;
|
|
|
|
|
|
|
|
cipher_result|= SSL_CTX_set_ciphersuites(ssl_fd->ssl_context, cipher);
|
|
|
|
cipher_result|= SSL_CTX_set_cipher_list(ssl_fd->ssl_context, cipher);
|
|
|
|
|
|
|
|
if (cipher_result == 0)
|
|
|
|
{
|
|
|
|
*error= SSL_INITERR_CIPHERS;
|
|
|
|
DBUG_PRINT("error", ("%s", sslGetErrString(*error)));
|
|
|
|
goto err2;
|
|
|
|
}
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
2006-03-10 16:41:14 +01:00
|
|
|
|
2006-05-03 14:09:08 +02:00
|
|
|
/* Load certs from the trusted ca */
|
2016-03-01 05:47:25 +01:00
|
|
|
if (SSL_CTX_load_verify_locations(ssl_fd->ssl_context, ca_file, ca_path) <= 0)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("warning", ("SSL_CTX_load_verify_locations failed"));
|
2012-08-11 12:13:04 +02:00
|
|
|
if (ca_file || ca_path)
|
|
|
|
{
|
|
|
|
/* fail only if ca file or ca path were supplied and looking into
|
|
|
|
them fails. */
|
|
|
|
*error= SSL_INITERR_BAD_PATHS;
|
|
|
|
DBUG_PRINT("error", ("SSL_CTX_load_verify_locations failed : %s",
|
|
|
|
sslGetErrString(*error)));
|
2015-05-02 12:32:10 +02:00
|
|
|
goto err2;
|
2012-08-11 12:13:04 +02:00
|
|
|
}
|
2019-02-13 09:08:06 +01:00
|
|
|
#ifndef HAVE_WOLFSSL
|
2012-08-11 12:13:04 +02:00
|
|
|
/* otherwise go use the defaults */
|
2006-03-10 16:41:14 +01:00
|
|
|
if (SSL_CTX_set_default_verify_paths(ssl_fd->ssl_context) == 0)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
2009-07-23 13:38:11 +02:00
|
|
|
*error= SSL_INITERR_BAD_PATHS;
|
|
|
|
DBUG_PRINT("error", ("%s", sslGetErrString(*error)));
|
2015-05-02 12:32:10 +02:00
|
|
|
goto err2;
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
2019-02-13 09:08:06 +01:00
|
|
|
#endif
|
2006-03-10 16:41:14 +01:00
|
|
|
}
|
2001-08-31 23:51:52 +02:00
|
|
|
|
2012-08-14 16:23:34 +02:00
|
|
|
if (crl_file || crl_path)
|
|
|
|
{
|
2019-02-13 09:08:06 +01:00
|
|
|
#ifdef HAVE_WOLFSSL
|
|
|
|
/* CRL does not work with WolfSSL. */
|
2012-08-14 16:23:34 +02:00
|
|
|
DBUG_ASSERT(0);
|
2019-02-13 09:08:06 +01:00
|
|
|
goto err2;
|
2012-08-14 16:23:34 +02:00
|
|
|
#else
|
|
|
|
X509_STORE *store= SSL_CTX_get_cert_store(ssl_fd->ssl_context);
|
|
|
|
/* Load crls from the trusted ca */
|
|
|
|
if (X509_STORE_load_locations(store, crl_file, crl_path) == 0 ||
|
|
|
|
X509_STORE_set_flags(store,
|
|
|
|
X509_V_FLAG_CRL_CHECK |
|
|
|
|
X509_V_FLAG_CRL_CHECK_ALL) == 0)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("warning", ("X509_STORE_load_locations for CRL failed"));
|
|
|
|
*error= SSL_INITERR_BAD_PATHS;
|
|
|
|
DBUG_PRINT("error", ("%s", sslGetErrString(*error)));
|
2015-05-02 12:32:10 +02:00
|
|
|
goto err2;
|
2012-08-14 16:23:34 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-10-21 19:50:07 +02:00
|
|
|
if (vio_set_cert_stuff(ssl_fd->ssl_context, cert_file, key_file,
|
|
|
|
is_client_method, error))
|
2006-05-03 14:09:08 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("vio_set_cert_stuff failed"));
|
2015-05-02 12:32:10 +02:00
|
|
|
goto err2;
|
2006-05-03 14:09:08 +02:00
|
|
|
}
|
2001-08-31 23:51:52 +02:00
|
|
|
|
2022-01-24 20:00:35 +01:00
|
|
|
#ifndef HAVE_WOLFSSL
|
2001-08-31 23:51:52 +02:00
|
|
|
/* DH stuff */
|
2015-11-15 10:44:20 +01:00
|
|
|
if (!is_client_method)
|
2015-05-02 12:32:10 +02:00
|
|
|
{
|
2022-01-24 20:00:35 +01:00
|
|
|
DH *dh= get_dh2048();
|
2015-11-15 10:44:20 +01:00
|
|
|
if (!SSL_CTX_set_tmp_dh(ssl_fd->ssl_context, dh))
|
|
|
|
{
|
|
|
|
*error= SSL_INITERR_DH;
|
2022-01-24 20:00:35 +01:00
|
|
|
DH_free(dh);
|
|
|
|
goto err2;
|
2015-11-15 10:44:20 +01:00
|
|
|
}
|
2015-05-02 12:32:10 +02:00
|
|
|
|
2015-11-15 10:44:20 +01:00
|
|
|
DH_free(dh);
|
|
|
|
}
|
2022-01-24 20:00:35 +01:00
|
|
|
#endif
|
2001-08-31 23:51:52 +02:00
|
|
|
|
2019-02-13 09:08:06 +01:00
|
|
|
#ifdef HAVE_WOLFSSL
|
|
|
|
/* set IO functions used by wolfSSL */
|
|
|
|
wolfSSL_SetIORecv(ssl_fd->ssl_context, wolfssl_recv);
|
|
|
|
wolfSSL_SetIOSend(ssl_fd->ssl_context, wolfssl_send);
|
|
|
|
#endif
|
|
|
|
|
2006-03-10 16:41:14 +01:00
|
|
|
DBUG_PRINT("exit", ("OK 1"));
|
|
|
|
|
|
|
|
DBUG_RETURN(ssl_fd);
|
2015-05-02 12:32:10 +02:00
|
|
|
|
|
|
|
err2:
|
|
|
|
SSL_CTX_free(ssl_fd->ssl_context);
|
|
|
|
err1:
|
|
|
|
my_free(ssl_fd);
|
|
|
|
err0:
|
|
|
|
DBUG_EXECUTE("error", ERR_print_errors_fp(DBUG_FILE););
|
|
|
|
DBUG_RETURN(0);
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
|
|
|
|
2023-09-03 22:34:03 +02:00
|
|
|
int always_ok(int preverify, X509_STORE_CTX* store)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2006-03-10 16:41:14 +01:00
|
|
|
/************************ VioSSLConnectorFd **********************************/
|
|
|
|
struct st_VioSSLFd *
|
|
|
|
new_VioSSLConnectorFd(const char *key_file, const char *cert_file,
|
|
|
|
const char *ca_file, const char *ca_path,
|
2012-08-14 16:23:34 +02:00
|
|
|
const char *cipher, enum enum_ssl_init_error* error,
|
|
|
|
const char *crl_file, const char *crl_path)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
2006-03-10 16:41:14 +01:00
|
|
|
struct st_VioSSLFd *ssl_fd;
|
2023-09-03 22:34:03 +02:00
|
|
|
int (*cb)(int, X509_STORE_CTX *) = NULL;
|
2007-03-28 12:23:55 +02:00
|
|
|
|
|
|
|
/*
|
2023-09-03 22:34:03 +02:00
|
|
|
Don't abort when the certificate cannot be verified if neither
|
|
|
|
ca_file nor ca_path were set.
|
2007-03-28 12:23:55 +02:00
|
|
|
*/
|
2023-08-23 15:23:22 +02:00
|
|
|
if ((ca_file == 0 || ca_file[0] == 0) && (ca_path == 0 || ca_path[0] == 0))
|
2023-09-03 22:34:03 +02:00
|
|
|
cb= always_ok;
|
2007-03-28 12:23:55 +02:00
|
|
|
|
2023-08-23 15:23:22 +02:00
|
|
|
/* Init the VioSSLFd as a "connector" ie. the client side */
|
|
|
|
if (!(ssl_fd= new_VioSSLFd(key_file, cert_file, ca_file, ca_path, cipher,
|
|
|
|
TRUE, error, crl_file, crl_path, 0)))
|
2006-03-10 16:41:14 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2023-09-03 22:34:03 +02:00
|
|
|
SSL_CTX_set_verify(ssl_fd->ssl_context, SSL_VERIFY_PEER, cb);
|
2006-03-10 16:41:14 +01:00
|
|
|
return ssl_fd;
|
|
|
|
}
|
2005-11-29 09:15:48 +01:00
|
|
|
|
|
|
|
|
2006-03-10 16:41:14 +01:00
|
|
|
/************************ VioSSLAcceptorFd **********************************/
|
2006-05-09 19:50:29 +02:00
|
|
|
struct st_VioSSLFd *
|
2006-03-10 16:41:14 +01:00
|
|
|
new_VioSSLAcceptorFd(const char *key_file, const char *cert_file,
|
|
|
|
const char *ca_file, const char *ca_path,
|
2012-08-14 16:23:34 +02:00
|
|
|
const char *cipher, enum enum_ssl_init_error* error,
|
MDEV-14101 Provide an option to select TLS protocol version
Server and command line tools now support option --tls_version to specify the
TLS version between client and server. Valid values are TLSv1.0, TLSv1.1, TLSv1.2, TLSv1.3
or a combination of them. E.g.
--tls_version=TLSv1.3
--tls_version=TLSv1.2,TLSv1.3
In case there is a gap between versions, the lowest version will be used:
--tls_version=TLSv1.1,TLSv1.3 -> Only TLSv1.1 will be available.
If the used TLS library doesn't support the specified TLS version, it will use
the default configuration.
Limitations:
SSLv3 is not supported. The default configuration doesn't support TLSv1.0 anymore.
TLSv1.3 protocol currently is only supported by OpenSSL 1.1.0 (client and server) and
GnuTLS 3.6.5 (client only).
Overview of TLS implementations and protocols
Server:
+-----------+-----------------------------------------+
| Library | Supported TLS versions |
+-----------+-----------------------------------------+
| WolfSSL | TLSv1.1, TLSv1,2 |
+-----------+-----------------------------------------+
| OpenSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
| LibreSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
Client (MariaDB Connector/C)
+-----------+-----------------------------------------+
| Library | Supported TLS versions |
+-----------+-----------------------------------------+
| GnuTLS | (TLSv1.0), TLSv1.1, TLSv1.2, TLSv1.3 |
+-----------+-----------------------------------------+
| Schannel | (TLSv1.0), TLSv1.1, TLSv1.2 |
+-----------+-----------------------------------------+
| OpenSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
| LibreSSL | (TLSv1.0), TLSv1.1, TLSv1,2, TLSv1.3 |
+-----------+-----------------------------------------+
2019-06-11 12:44:16 +02:00
|
|
|
const char *crl_file, const char *crl_path,
|
|
|
|
ulonglong tls_version)
|
2006-03-10 16:41:14 +01:00
|
|
|
{
|
|
|
|
struct st_VioSSLFd *ssl_fd;
|
|
|
|
int verify= SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE;
|
2021-12-14 03:47:59 +01:00
|
|
|
|
2023-08-23 15:23:22 +02:00
|
|
|
/* Init the the VioSSLFd as a "acceptor" ie. the server side */
|
|
|
|
if (!(ssl_fd= new_VioSSLFd(key_file, cert_file, ca_file, ca_path, cipher,
|
|
|
|
FALSE, error, crl_file, crl_path, tls_version)))
|
2001-09-30 04:46:20 +02:00
|
|
|
{
|
2006-03-10 16:41:14 +01:00
|
|
|
return 0;
|
2001-09-30 04:46:20 +02:00
|
|
|
}
|
2006-03-10 16:41:14 +01:00
|
|
|
/* Set max number of cached sessions, returns the previous size */
|
|
|
|
SSL_CTX_sess_set_cache_size(ssl_fd->ssl_context, 128);
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2009-10-27 14:11:06 +01:00
|
|
|
SSL_CTX_set_verify(ssl_fd->ssl_context, verify, NULL);
|
2002-06-11 10:20:31 +02:00
|
|
|
|
2006-03-10 16:41:14 +01:00
|
|
|
/*
|
|
|
|
Set session_id - an identifier for this server session
|
|
|
|
Use the ssl_fd pointer
|
|
|
|
*/
|
|
|
|
SSL_CTX_set_session_id_context(ssl_fd->ssl_context,
|
2006-05-04 10:30:08 +02:00
|
|
|
(const unsigned char *)ssl_fd,
|
2006-03-10 16:41:14 +01:00
|
|
|
sizeof(ssl_fd));
|
2006-05-03 14:59:17 +02:00
|
|
|
|
2006-03-10 16:41:14 +01:00
|
|
|
return ssl_fd;
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
2006-05-03 14:59:17 +02:00
|
|
|
|
2006-05-09 19:50:29 +02:00
|
|
|
void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd)
|
2006-05-03 14:59:17 +02:00
|
|
|
{
|
2019-08-12 14:47:24 +02:00
|
|
|
DBUG_ENTER("free_vio_ssl_acceptor_fd");
|
2006-05-03 14:59:17 +02:00
|
|
|
SSL_CTX_free(fd->ssl_context);
|
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly
slow as it checks all allocated blocks for overrun at each
memory management primitive, yielding a almost exponential
slowdown for the memory management functions (malloc, realloc,
free). The overrun check basically consists of verifying some
bytes of a block for certain magic keys, which catches some
simple forms of overrun. Another minor problem is violation
of aliasing rules and that its own internal list of blocks
is prone to corruption.
Another issue with safemalloc is rather the maintenance cost
as the tool has a significant impact on the server code.
Given the magnitude of memory debuggers available nowadays,
especially those that are provided with the platform malloc
implementation, maintenance of a in-house and largely obsolete
memory debugger becomes a burden that is not worth the effort
due to its slowness and lack of support for detecting more
common forms of heap corruption.
Since there are third-party tools that can provide the same
functionality at a lower or comparable performance cost, the
solution is to simply remove safemalloc. Third-party tools
can provide the same functionality at a lower or comparable
performance cost.
The removal of safemalloc also allows a simplification of the
malloc wrappers, removing quite a bit of kludge: redefinition
of my_malloc, my_free and the removal of the unused second
argument of my_free. Since free() always check whether the
supplied pointer is null, redudant checks are also removed.
Also, this patch adds unit testing for my_malloc and moves
my_realloc implementation into the same file as the other
memory allocation primitives.
client/mysqldump.c:
Pass my_free directly as its signature is compatible with the
callback type -- which wasn't the case for free_table_ent.
2010-07-08 23:20:08 +02:00
|
|
|
my_free(fd);
|
2019-08-12 14:47:24 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2006-05-03 14:59:17 +02:00
|
|
|
}
|
2001-05-20 14:04:46 +02:00
|
|
|
#endif /* HAVE_OPENSSL */
|