summaryrefslogtreecommitdiff
path: root/sql-common
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2015-06-09 14:08:44 +0300
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2015-06-09 16:08:14 +0300
commit4ef74979969ac9339d0d42c11a6f26632e6776f1 (patch)
tree51a06e7d049d6bb4a45b93b560983d8f22854cec /sql-common
parent56e2d8318bf37fc12702cc788033cf763e911c90 (diff)
downloadmariadb-git-4ef74979969ac9339d0d42c11a6f26632e6776f1.tar.gz
MDEV-7937: Enforce SSL when --ssl client option is used
Using --ssl-verify-server-cert and --ssl[-*] implies that the ssl connection is required. The mysql client will now print an error if ssl is required, but the server can not handle a ssl connection.
Diffstat (limited to 'sql-common')
-rw-r--r--sql-common/client.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/sql-common/client.c b/sql-common/client.c
index ac372a437ba..01f73974f61 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -1801,6 +1801,7 @@ mysql_ssl_set(MYSQL *mysql __attribute__((unused)) ,
mysql->options.ssl_ca= strdup_if_not_null(ca);
mysql->options.ssl_capath= strdup_if_not_null(capath);
mysql->options.ssl_cipher= strdup_if_not_null(cipher);
+ mysql->options.use_ssl= TRUE;
#endif /* HAVE_OPENSSL && !EMBEDDED_LIBRARY */
DBUG_RETURN(0);
}
@@ -2491,13 +2492,10 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
mysql->client_flag|= CLIENT_MULTI_RESULTS;
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
- if (mysql->options.ssl_key || mysql->options.ssl_cert ||
- mysql->options.ssl_ca || mysql->options.ssl_capath ||
- mysql->options.ssl_cipher)
- mysql->options.use_ssl= 1;
if (mysql->options.use_ssl)
mysql->client_flag|= CLIENT_SSL;
#endif /* HAVE_OPENSSL && !EMBEDDED_LIBRARY*/
+
if (mpvio->db)
mysql->client_flag|= CLIENT_CONNECT_WITH_DB;
@@ -2526,6 +2524,23 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
end= buff+5;
}
#ifdef HAVE_OPENSSL
+
+ /*
+ If client uses ssl and client also has to verify the server
+ certificate, a ssl connection is required.
+ If the server does not support ssl, we abort the connection.
+ */
+ if (mysql->options.use_ssl &&
+ (mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT) &&
+ !(mysql->server_capabilities & CLIENT_SSL))
+ {
+ set_mysql_extended_error(mysql, CR_SSL_CONNECTION_ERROR, unknown_sqlstate,
+ ER(CR_SSL_CONNECTION_ERROR),
+ "SSL is required, but the server does not "
+ "support it");
+ goto error;
+ }
+
if (mysql->client_flag & CLIENT_SSL)
{
/* Do the SSL layering. */