Skip to content

Commit 4c04e51

Browse files
committed
Bug#28082093: LIBMYSQLCLIENT CONNECTING TO OLDER MYSQL 5
SERVERS RESULTS IN BAD HANDSHAKE If no default authentication method is specified via a mysql_options() libmysql will default to the "compiled in default", which is the client plugin for caching_sha2. This in itself is fine for a server that supports pluggable authentication (5.5+). But on older servers that do not have pluggable authentication expect the response to be either "mysql_native" or "old, aka. mysql_323". And if they receive any reply (caching_sha2's in this case) that doesn't conform to this they'd bail out with "Bad handshake" error. Unfortunately, the --default-auth option had no effect if the server won't advertise that it supports pluggable authentication, thus, even the --default-auth=mysql_native_password workaround won't do. Fixed by: 1. Making sure --default-auth on the client side works even for non-pluggable authentication servers. 2. If no --default-auth is specified instead of picking caching_sha2 as a compiled-in default the client will pick mysql_native instead iff the server doesn't support pluggagle authentication (<= 5.1). Unfortunately, only manual testing can be done since it'd require an actual live 5.1 server, so no regression test is added. Change-Id: Ifcaa6404503bf1ddaf7f21ddbdcc3d8767711787
1 parent f82e863 commit 4c04e51

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

sql-common/client.cc

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5663,11 +5663,24 @@ static mysql_state_machine_status authsm_begin_plugin_auth(
56635663
}
56645664

56655665
if (ctx->auth_plugin_name == nullptr || ctx->auth_plugin == nullptr) {
5666-
/*
5667-
If everything else fail we use the built in plugin
5668-
*/
5669-
ctx->auth_plugin = &caching_sha2_password_client_plugin;
5670-
ctx->auth_plugin_name = ctx->auth_plugin->name;
5666+
auth_plugin_t *client_plugin{nullptr};
5667+
if (mysql->options.extension && mysql->options.extension->default_auth &&
5668+
(client_plugin = (auth_plugin_t *)mysql_client_find_plugin(
5669+
mysql, mysql->options.extension->default_auth,
5670+
MYSQL_CLIENT_AUTHENTICATION_PLUGIN))) {
5671+
// try default_auth again in case CLIENT_PLUGIN_AUTH wasn't on.
5672+
ctx->auth_plugin_name = mysql->options.extension->default_auth;
5673+
ctx->auth_plugin = client_plugin;
5674+
} else {
5675+
/*
5676+
If everything else fail we use the built in plugin: caching sha if the
5677+
server is new enough or native if not.
5678+
*/
5679+
ctx->auth_plugin = (mysql->server_capabilities & CLIENT_PLUGIN_AUTH)
5680+
? &caching_sha2_password_client_plugin
5681+
: &native_password_client_plugin;
5682+
ctx->auth_plugin_name = ctx->auth_plugin->name;
5683+
}
56715684
}
56725685

56735686
if (check_plugin_enabled(mysql, ctx)) return STATE_MACHINE_FAILED;

0 commit comments

Comments
 (0)