Skip to content

Commit 13e9f2d

Browse files
committed
MDEV-37143 mariabackup fails on Windows with "SSL certificate is self-signed"
This is the same as MDEV-35368, which was previously incompletely fixed (on *nix-only, for unix socket connections) This time, we fix it compatibly to Connector/C, by not verifying server certificate for local connections, which, in addition to socket and named pipe, are also "127.0.0.1" and "::1", and on Windows "localhost" as well. The corresponding code in Connector/C is was added by 1287c901dc8515823d28edcebfe4be65e6c5a6b3. It remain a good question whether mariabackup should use SSL at all since all it does are local connections, for "BACKUP STAGE" stuff.
1 parent ef9adb5 commit 13e9f2d

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

mysql-test/suite/mariabackup/backup_ssl.result

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ DROP USER backup_user;
1515
# MDEV-32473 --disable-ssl doesn't disable it
1616
#
1717
# tcp skip-ssl
18+
#
19+
# MDEV-37143 Mariadb-backup fails on Windows with SSL certificate is self-signed error
20+
#
21+
# do not fail with passwordless with default protocol
22+
# do not fail with passwordless with 127.0.0.1 TCP

mysql-test/suite/mariabackup/backup_ssl.test

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ echo # MDEV-31855 validate ssl certificates using client password in the interna
1919
echo #;
2020
# fails to connect, passwordless root
2121
echo # tcp ssl ssl-verify-server-cert;
22+
let $host=;
23+
if ($MARIADB_UPGRADE_EXE) {
24+
# On Windows, we need host different from "127.0.0.1","::1" or "localhost"
25+
# to trigger self-signed error
26+
let $host=--host=127.0.0.2;
27+
}
2228
error 1;
23-
exec $XTRABACKUP --no-defaults --protocol=tcp --user=root --port=$MASTER_MYPORT --backup --target-dir=$targetdir;
29+
exec $XTRABACKUP --no-defaults $host --protocol=tcp --user=root --port=$MASTER_MYPORT --backup --target-dir=$targetdir;
2430

2531
--echo #
2632
--echo # MDEV-32473 --disable-ssl doesn't disable it
@@ -29,3 +35,17 @@ exec $XTRABACKUP --no-defaults --protocol=tcp --user=root --port=$MASTER_MYPORT
2935
echo # tcp skip-ssl;
3036
exec $XTRABACKUP --no-defaults --protocol=tcp --user=root --skip-ssl --port=$MASTER_MYPORT --backup --target-dir=$targetdir;
3137
rmdir $targetdir;
38+
39+
--echo #
40+
--echo # MDEV-37143 Mariadb-backup fails on Windows with SSL certificate is self-signed error
41+
--echo #
42+
--echo # do not fail with passwordless with default protocol
43+
let $port_or_socket=--socket=$MASTER_MYSOCK;
44+
if ($MARIADB_UPGRADE_EXE) { # windows
45+
let $port_or_socket=--port=$MASTER_MYPORT;
46+
}
47+
exec $XTRABACKUP --no-defaults --user=root --backup $port_or_socket --target-dir=$targetdir;
48+
rmdir $targetdir;
49+
--echo # do not fail with passwordless with 127.0.0.1 TCP
50+
exec $XTRABACKUP --no-defaults --host=127.0.0.1 --protocol=tcp --port=$MASTER_MYPORT --user=root --backup --target-dir=$targetdir;
51+
rmdir $targetdir;

sql-common/client.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,29 @@ static int send_change_user_packet(MCPVIO_EXT *mpvio,
19941994
return res;
19951995
}
19961996

1997+
/**
1998+
Checks if self-signed certificate error should be ignored.
1999+
*/
2000+
static my_bool is_local_connection(const char *hostname, enum enum_vio_type viotype)
2001+
{
2002+
const char *local_host_names[]= {
2003+
#ifdef _WIN32
2004+
"localhost",
2005+
#endif
2006+
"127.0.0.1", "::1"};
2007+
size_t i;
2008+
2009+
if (viotype != VIO_TYPE_TCPIP || !hostname)
2010+
return TRUE;
2011+
2012+
for (i= 0; i < array_elements(local_host_names); i++)
2013+
{
2014+
if (strcmp(hostname, local_host_names[i]) == 0)
2015+
return TRUE;
2016+
}
2017+
return FALSE;
2018+
}
2019+
19972020
#define MAX_CONNECTION_ATTR_STORAGE_LENGTH 65536
19982021

19992022
/**
@@ -2122,6 +2145,7 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
21222145
enum enum_ssl_init_error ssl_init_error;
21232146
const char *cert_error;
21242147
unsigned long ssl_error;
2148+
my_bool is_local;
21252149

21262150
/*
21272151
Send mysql->client_flag, max_packet_size - unencrypted otherwise
@@ -2169,10 +2193,11 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
21692193
}
21702194
DBUG_PRINT("info", ("IO layer change done!"));
21712195

2196+
is_local= is_local_connection(mysql->host, vio_type);
21722197
/* Verify server cert */
21732198
if ((!mysql->options.extension ||
21742199
!mysql->options.extension->tls_allow_invalid_server_cert) &&
2175-
ssl_verify_server_cert(mysql, &cert_error, vio_type == VIO_TYPE_SOCKET))
2200+
ssl_verify_server_cert(mysql, &cert_error, is_local))
21762201
{
21772202
set_mysql_extended_error(mysql, CR_SSL_CONNECTION_ERROR, unknown_sqlstate,
21782203
ER(CR_SSL_CONNECTION_ERROR), cert_error);
@@ -2181,14 +2206,13 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
21812206
if (mysql->tls_self_signed_error)
21822207
{
21832208
/*
2184-
If the transport is secure (see opt_require_secure_transport) we
2185-
allow a self-signed cert as we know it came from the server.
2209+
If connection is local, we allow self-signed cert.
21862210
21872211
If no password or plugin uses insecure protocol - refuse the cert.
21882212
21892213
Otherwise one last cert check after auth.
21902214
*/
2191-
if (vio_type == VIO_TYPE_SOCKET)
2215+
if (is_local)
21922216
mysql->tls_self_signed_error= 0;
21932217
else if (!mysql->passwd || !mysql->passwd[0] ||
21942218
!mpvio->plugin->hash_password_bin)

0 commit comments

Comments
 (0)