Skip to content

Commit 4aebdb6

Browse files
committed
fix certificate verification for GnuTLS
* don't verify trust unless requested * don't error about host of untrusted certificates * auto-verification replaces both TRUST and HOST
1 parent 10c67ee commit 4aebdb6

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

libmariadb/ma_tls.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ int ma_pvio_tls_verify_server_cert(MARIADB_TLS *ctls, unsigned int flags)
175175
ER(CR_SSL_CONNECTION_ERROR),
176176
"Peer certificate is not trusted");
177177
}
178-
/* Save original validation, since we might unset trust flag in
179-
my_auth */
178+
/* Save original validation */
180179
mysql->extension->tls_validation= mysql->net.tls_verify_status;
180+
mysql->net.tls_verify_status&= flags;
181181
return rc;
182182
}
183183

libmariadb/secure/gnutls.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ int ma_tls_verify_server_cert(MARIADB_TLS *ctls, unsigned int flags)
14591459
mysql->net.tls_verify_status|= MARIADB_TLS_VERIFY_PERIOD;
14601460
}
14611461

1462-
if ((flags & MARIADB_TLS_VERIFY_HOST))
1462+
if (flags & MARIADB_TLS_VERIFY_HOST)
14631463
{
14641464
gnutls_x509_crt_t cert= ma_get_cert(ctls);
14651465
int rc;
@@ -1478,14 +1478,15 @@ int ma_tls_verify_server_cert(MARIADB_TLS *ctls, unsigned int flags)
14781478

14791479
if (!rc)
14801480
{
1481-
my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
1482-
ER(CR_SSL_CONNECTION_ERROR),
1483-
"Certificate subject name doesn't match specified hostname");
1481+
if (!(mysql->net.tls_verify_status & MARIADB_TLS_VERIFY_TRUST))
1482+
my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
1483+
ER(CR_SSL_CONNECTION_ERROR),
1484+
"Certificate subject name doesn't match specified hostname");
14841485
mysql->net.tls_verify_status|= MARIADB_TLS_VERIFY_HOST;
14851486
}
14861487
}
14871488
end:
1488-
return (mysql->net.tls_verify_status > 0);
1489+
return mysql->net.tls_verify_status & flags;
14891490
}
14901491

14911492
const char *ma_tls_get_cipher(MARIADB_TLS *ctls)

plugins/auth/my_auth.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ static int send_change_user_packet(MCPVIO_EXT *mpvio,
267267
return res;
268268
}
269269

270+
#define MARIADB_TLS_VERIFY_AUTO (MARIADB_TLS_VERIFY_HOST | MARIADB_TLS_VERIFY_TRUST)
271+
270272
static int send_client_reply_packet(MCPVIO_EXT *mpvio,
271273
const uchar *data, int data_len)
272274
{
@@ -437,14 +439,14 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
437439

438440
if (mysql->options.extension->tls_verification_callback(mysql->net.pvio->ctls, verify_flags))
439441
{
440-
if (mysql->net.tls_verify_status > MARIADB_TLS_VERIFY_TRUST ||
442+
if (mysql->net.tls_verify_status > MARIADB_TLS_VERIFY_AUTO ||
441443
(mysql->options.ssl_ca || mysql->options.ssl_capath))
442444
goto error;
443445

444446
if (is_local_connection(mysql->net.pvio))
445447
{
446448
CLEAR_CLIENT_ERROR(mysql);
447-
mysql->net.tls_verify_status&= ~MARIADB_TLS_VERIFY_TRUST;
449+
mysql->net.tls_verify_status&= ~MARIADB_TLS_VERIFY_AUTO;
448450
}
449451
else if (!password_and_hashing(mysql, mpvio->plugin))
450452
goto error;

0 commit comments

Comments
 (0)