You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-07 02:42:49 +03:00
TLS/SSL changes (major rework)
Peer certificate validation: Since version 3.4 peer certificate verification is enabled by default. It can be disabled via `mysql_optionsv`, using option MYSQL_OPT_SSL_VERIFY_SERVER_CERT: my_bool verify= 0; mysql_options(mariadb, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &verify); Self signed certificates If the client obtained a self signed peer certificate from MariaDB server the verification will fail, with the following exceptions: * If the connection between client and server is considered to be secure:, e.g. * a unix_socket is used for client server communication * hostname is localhost (Windows operating system), 127.0.0.1 or ::1 * a specified fingerprint matches the fingerprint of the peer certificate (see below) * a client can verify the certificate using account password, it's possible if * account has a password * authentication plugin is "secure without TLS", that is, one of mysql_native_password, ed25519 or parsec. Fingerprint verification of the peer certificate A fingerprint is a cryptographic hash (SHA-256, SHA-384 or SHA-512) of the peer certificate's binary data. Even if the fingerprint matches, an expired or revoked certificate will not be accepted. For security reasons support for MD5 and SHA1 has been removed. Technical details: ================== - Peer certificate verification call was removed from ma_tls_connect, instead it will be called directly after the handshake succeeded (my_auth.c) - mysql->net.tls_self_signed_error was replaced by mysql->net.tls_verify_status which contains the result of the peer certfificate verification: The verification status can be obtained with mariadb_get_infov using new parameter MARIADB_TLS_VERIFY_STATUS. unsigned int tls_verify_status; mariadb_get_infov(mysql, MARIADB_TLS_VERIFY_STATUS, &tls_verify_status); The result is a combination of the following flags: MARIADB_TLS_VERIFY_OK 0 MARIADB_TLS_VERIFY_TRUST 1 MARIADB_TLS_VERIFY_HOST 2 MARIADB_TLS_VERIFY_PERIOD 4 MARIADB_TLS_VERIFY_FINGERPRINT 8 MARIADB_TLS_VERIFY_REVOKED 16 MARIADB_TLS_VERIFY_UNKNOWN 32 - GnuTLS peer certificate verification callback was removed and replaced by gnutls_verify_peers2() api function, so the peer certificate validation will happen after handshake. - OpenSSL implementation will no longer use SSL_verify_result to check the validity of the peer certificate. Instead a callback function will be called during the handshake, which collects all certificate validation errors. - If the peer certificate is not trusted, hostname verification will be skipped. - Testing Added new test tls, which implements a python based dummy server, which allows to set different certificates and TLS options. Please note. that tests are expected to fail, since the server doesn't support further steps like user authentication etc. after the handshake. Prerequisite for running the tls test is Python3.
This commit is contained in:
@@ -219,12 +219,13 @@ MYSQL *my_test_connect(MYSQL *mysql,
|
||||
const char *db,
|
||||
unsigned int port,
|
||||
const char *unix_socket,
|
||||
unsigned long clientflag);
|
||||
unsigned long clientflag,
|
||||
my_bool auto_fingerprint);
|
||||
|
||||
static const char *schema = 0;
|
||||
static char *hostname = 0;
|
||||
static char *password = 0;
|
||||
static char fingerprint[65]= {0};
|
||||
static char fingerprint[129]= {0};
|
||||
static unsigned int port = 0;
|
||||
static unsigned int ssl_port = 0;
|
||||
static char *socketname = 0;
|
||||
@@ -542,7 +543,7 @@ MYSQL *test_connect(struct my_tests_st *test)
|
||||
}
|
||||
}
|
||||
if (!(my_test_connect(mysql, hostname, username, password,
|
||||
schema, port, socketname, (test) ? test->connect_flags:0)))
|
||||
schema, port, socketname, (test) ? test->connect_flags:0, 1)))
|
||||
{
|
||||
diag("Couldn't establish connection to server %s. Error (%d): %s",
|
||||
hostname, mysql_errno(mysql), mysql_error(mysql));
|
||||
@@ -654,12 +655,18 @@ MYSQL *my_test_connect(MYSQL *mysql,
|
||||
const char *db,
|
||||
unsigned int port,
|
||||
const char *unix_socket,
|
||||
unsigned long clientflag)
|
||||
unsigned long clientflag,
|
||||
my_bool auto_fingerprint)
|
||||
{
|
||||
char *have_fp;
|
||||
if (force_tls)
|
||||
mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &force_tls);
|
||||
if (fingerprint[0])
|
||||
mysql_get_optionv(mysql, MARIADB_OPT_SSL_FP, &have_fp);
|
||||
if (fingerprint[0] && auto_fingerprint)
|
||||
{
|
||||
printf("setting fingerprint\n");
|
||||
mysql_options(mysql, MARIADB_OPT_SSL_FP, fingerprint);
|
||||
}
|
||||
if (!mysql_real_connect(mysql, host, user, passwd, db, port, unix_socket, clientflag))
|
||||
{
|
||||
diag("error: %s", mysql_error(mysql));
|
||||
@@ -712,11 +719,12 @@ void run_tests(struct my_tests_st *test) {
|
||||
mysql_free_result(res);
|
||||
if (mysql_get_ssl_cipher(mysql))
|
||||
diag("Cipher in use: %s", mysql_get_ssl_cipher(mysql));
|
||||
mariadb_get_infov(mysql, MARIADB_TLS_PEER_CERT_INFO, &info);
|
||||
mariadb_get_infov(mysql, MARIADB_TLS_PEER_CERT_INFO, &info, 384);
|
||||
if (info)
|
||||
{
|
||||
strcpy(fingerprint, info->fingerprint);
|
||||
diag("Peer certificate fingerprint: %s", fingerprint);
|
||||
diag("Subject: %s", info->subject);
|
||||
diag("--------------------");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user