Skip to content

Commit 32158be

Browse files
committed
MDEV-29811 server advertises ssl even if it's unusable.
Abort startup, if SSL setup fails. Also, for the server always check that certificate matches private key (even if ssl_cert is not set, OpenSSL will try to use default one)
1 parent 34ff5ca commit 32158be

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FOUND 1 /\[ERROR\] SSL error: Unable to get certificate/ in errorlog.err
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--source include/not_embedded.inc
2+
--source include/have_ssl_communication.inc
3+
4+
--source include/shutdown_mysqld.inc
5+
6+
# Try to start the server, with bad values for some options.
7+
# Make sure, the starts fails, and expected message is in the error log
8+
9+
--let errorlog=$MYSQL_TMP_DIR/errorlog.err
10+
--let SEARCH_FILE=$errorlog
11+
12+
# Bad ssl-cert
13+
--error 1
14+
--exec $MYSQLD --defaults-group-suffix=.1 --defaults-file=$MYSQLTEST_VARDIR/my.cnf --ssl-cert=bad --log-error=$errorlog
15+
--let SEARCH_PATTERN=\[ERROR\] SSL error: Unable to get certificate
16+
--source include/search_pattern_in_file.inc
17+
--remove_file $SEARCH_FILE
18+
19+
--source include/start_mysqld.inc

sql/mysqld.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5037,10 +5037,9 @@ static void init_ssl()
50375037
DBUG_PRINT("info",("ssl_acceptor_fd: %p", ssl_acceptor_fd));
50385038
if (!ssl_acceptor_fd)
50395039
{
5040-
sql_print_warning("Failed to setup SSL");
5041-
sql_print_warning("SSL error: %s", sslGetErrString(error));
5042-
opt_use_ssl = 0;
5043-
have_ssl= SHOW_OPTION_DISABLED;
5040+
sql_print_error("Failed to setup SSL");
5041+
sql_print_error("SSL error: %s", sslGetErrString(error));
5042+
unireg_abort(1);
50445043
}
50455044
if (global_system_variables.log_warnings > 0)
50465045
{

vio/viosslfactories.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ sslGetErrString(enum enum_ssl_init_error e)
9797

9898
static int
9999
vio_set_cert_stuff(SSL_CTX *ctx, const char *cert_file, const char *key_file,
100-
enum enum_ssl_init_error* error)
100+
my_bool is_client, enum enum_ssl_init_error* error)
101101
{
102102
DBUG_ENTER("vio_set_cert_stuff");
103103
DBUG_PRINT("enter", ("ctx: %p cert_file: %s key_file: %s",
@@ -134,10 +134,10 @@ vio_set_cert_stuff(SSL_CTX *ctx, const char *cert_file, const char *key_file,
134134
}
135135

136136
/*
137-
If we are using DSA, we can copy the parameters from the private key
138-
Now we know that a key and cert have been set against the SSL context
137+
If certificate is used check if private key matches.
138+
Note, that server side has to use certificate.
139139
*/
140-
if (cert_file && !SSL_CTX_check_private_key(ctx))
140+
if ((cert_file != NULL || !is_client) && !SSL_CTX_check_private_key(ctx))
141141
{
142142
*error= SSL_INITERR_NOMATCH;
143143
DBUG_PRINT("error", ("%s",sslGetErrString(*error)));
@@ -288,7 +288,8 @@ new_VioSSLFd(const char *key_file, const char *cert_file,
288288
#endif
289289
}
290290

291-
if (vio_set_cert_stuff(ssl_fd->ssl_context, cert_file, key_file, error))
291+
if (vio_set_cert_stuff(ssl_fd->ssl_context, cert_file, key_file,
292+
is_client_method, error))
292293
{
293294
DBUG_PRINT("error", ("vio_set_cert_stuff failed"));
294295
goto err2;

0 commit comments

Comments
 (0)