Skip to content

Commit fb9c110

Browse files
harinvadodariadahlerlend
authored andcommitted
Bug#27568278: CAN'T LOCATE SERVER PUBLIC KEY 'ROOT' WHEN
RUNNING MYSQL_UPGRADE Description: mysql_upgrade does not set MYSQL_SERVER_PUBLIC_KEY correctly. This leads to libmysqlclient not being able to read key from file. Solution: Update mysql_upgrade to set MYSQL_SERVER_PUBLIC_KEY properly when --server-public-key-path is specified.
1 parent 2c390cb commit fb9c110

File tree

4 files changed

+129
-9
lines changed

4 files changed

+129
-9
lines changed

client/base/mysql_connection_options.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <sstream>
3030
#include <vector>
3131

32+
#include "caching_sha2_passwordopt-vars.h"
3233
#include "client/base/abstract_options_provider.h"
3334
#include "client/base/abstract_program.h"
3435
#include "m_ctype.h"
@@ -159,12 +160,13 @@ MYSQL *Mysql_connection_options::create_connection() {
159160
mysql_options4(connection, MYSQL_OPT_CONNECT_ATTR_ADD, "program_name",
160161
this->m_program->get_name().c_str());
161162

162-
mysql_options(connection, MYSQL_SERVER_PUBLIC_KEY,
163-
this->get_null_or_string(this->m_user));
163+
if (this->m_server_public_key.has_value())
164+
set_server_public_key(connection,
165+
this->m_server_public_key.value().c_str());
164166

165167
if (this->m_get_server_public_key)
166-
mysql_options(connection, MYSQL_OPT_GET_SERVER_PUBLIC_KEY,
167-
(void *)&this->m_get_server_public_key);
168+
set_get_server_public_key_option(connection,
169+
&this->m_get_server_public_key);
168170

169171
if (!mysql_real_connect(
170172
connection, this->get_null_or_string(this->m_host),

include/caching_sha2_passwordopt-vars.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -29,12 +29,17 @@
2929
static char *opt_server_public_key = 0;
3030
static bool opt_get_server_public_key = false;
3131

32-
static void set_server_public_key(MYSQL *mysql) {
33-
if (opt_server_public_key && *opt_server_public_key)
32+
static void set_server_public_key(MYSQL *mysql,
33+
const char *server_public_key = NULL) {
34+
if (server_public_key && *server_public_key)
35+
mysql_options(mysql, MYSQL_SERVER_PUBLIC_KEY, server_public_key);
36+
else if (opt_server_public_key && *opt_server_public_key)
3437
mysql_options(mysql, MYSQL_SERVER_PUBLIC_KEY, opt_server_public_key);
3538
}
3639

37-
static void set_get_server_public_key_option(MYSQL *mysql) {
40+
static void set_get_server_public_key_option(
41+
MYSQL *mysql, const bool *get_server_public_key = NULL) {
3842
mysql_options(mysql, MYSQL_OPT_GET_SERVER_PUBLIC_KEY,
39-
&opt_get_server_public_key);
43+
get_server_public_key ? get_server_public_key
44+
: &opt_get_server_public_key);
4045
}

mysql-test/r/mysql_upgrade.result

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,103 @@ mtr.global_suppressions OK
155155
mtr.test_suppressions OK
156156
sys.sys_config OK
157157
SET GLOBAL autocommit = default;
158+
#
159+
# Bug #27568278: CAN'T LOCATE SERVER PUBLIC KEY 'ROOT' WHEN RUNNING MYSQL_UPGRADE
160+
#
161+
CREATE USER root_sha256@localhost IDENTIFIED WITH 'sha256_password';
162+
GRANT ALL ON *.* TO root_sha256@localhost WITH GRANT OPTION;
163+
Checking server version.
164+
Running queries to upgrade MySQL server.
165+
Upgrading system table data.
166+
Checking system database.
167+
mysql.columns_priv OK
168+
mysql.component OK
169+
mysql.db OK
170+
mysql.default_roles OK
171+
mysql.engine_cost OK
172+
mysql.func OK
173+
mysql.general_log OK
174+
mysql.global_grants OK
175+
mysql.gtid_executed OK
176+
mysql.help_category OK
177+
mysql.help_keyword OK
178+
mysql.help_relation OK
179+
mysql.help_topic OK
180+
mysql.innodb_index_stats OK
181+
mysql.innodb_table_stats OK
182+
mysql.password_history OK
183+
mysql.plugin OK
184+
mysql.procs_priv OK
185+
mysql.proxies_priv OK
186+
mysql.role_edges OK
187+
mysql.server_cost OK
188+
mysql.servers OK
189+
mysql.slave_master_info OK
190+
mysql.slave_relay_log_info OK
191+
mysql.slave_worker_info OK
192+
mysql.slow_log OK
193+
mysql.tables_priv OK
194+
mysql.time_zone OK
195+
mysql.time_zone_leap_second OK
196+
mysql.time_zone_name OK
197+
mysql.time_zone_transition OK
198+
mysql.time_zone_transition_type OK
199+
mysql.user OK
200+
The sys schema is already up to date (version 1.6.0).
201+
Checking databases.
202+
mtr.global_suppressions OK
203+
mtr.test_suppressions OK
204+
sys.sys_config OK
205+
Upgrade process completed successfully.
206+
Checking if update is needed.
207+
DROP USER root_sha256@localhost;
208+
CREATE USER root_caching_sha2@localhost IDENTIFIED WITH 'caching_sha2_password' BY 'abcd';
209+
GRANT ALL ON *.* TO root_caching_sha2@localhost WITH GRANT OPTION;
210+
mysql_upgrade: [Warning] Using a password on the command line interface can be insecure.
211+
Checking server version.
212+
Running queries to upgrade MySQL server.
213+
Upgrading system table data.
214+
Checking system database.
215+
mysql.columns_priv OK
216+
mysql.component OK
217+
mysql.db OK
218+
mysql.default_roles OK
219+
mysql.engine_cost OK
220+
mysql.func OK
221+
mysql.general_log OK
222+
mysql.global_grants OK
223+
mysql.gtid_executed OK
224+
mysql.help_category OK
225+
mysql.help_keyword OK
226+
mysql.help_relation OK
227+
mysql.help_topic OK
228+
mysql.innodb_index_stats OK
229+
mysql.innodb_table_stats OK
230+
mysql.password_history OK
231+
mysql.plugin OK
232+
mysql.procs_priv OK
233+
mysql.proxies_priv OK
234+
mysql.role_edges OK
235+
mysql.server_cost OK
236+
mysql.servers OK
237+
mysql.slave_master_info OK
238+
mysql.slave_relay_log_info OK
239+
mysql.slave_worker_info OK
240+
mysql.slow_log OK
241+
mysql.tables_priv OK
242+
mysql.time_zone OK
243+
mysql.time_zone_leap_second OK
244+
mysql.time_zone_name OK
245+
mysql.time_zone_transition OK
246+
mysql.time_zone_transition_type OK
247+
mysql.user OK
248+
The sys schema is already up to date (version 1.6.0).
249+
Checking databases.
250+
mtr.global_suppressions OK
251+
mtr.test_suppressions OK
252+
sys.sys_config OK
253+
Upgrade process completed successfully.
254+
Checking if update is needed.
255+
DROP USER root_caching_sha2@localhost;
158256

159257
End of tests

mysql-test/t/mysql_upgrade.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ SET GLOBAL autocommit = 0;
7474

7575
SET GLOBAL autocommit = default;
7676

77+
--echo #
78+
--echo # Bug #27568278: CAN'T LOCATE SERVER PUBLIC KEY 'ROOT' WHEN RUNNING MYSQL_UPGRADE
79+
--echo #
80+
81+
CREATE USER root_sha256@localhost IDENTIFIED WITH 'sha256_password';
82+
GRANT ALL ON *.* TO root_sha256@localhost WITH GRANT OPTION;
83+
--replace_regex /mysql.ndb_binlog_index.*$//
84+
--exec $MYSQL_UPGRADE --force -uroot_sha256 --protocol=tcp --ssl-mode=disabled 2>&1
85+
DROP USER root_sha256@localhost;
86+
87+
CREATE USER root_caching_sha2@localhost IDENTIFIED WITH 'caching_sha2_password' BY 'abcd';
88+
GRANT ALL ON *.* TO root_caching_sha2@localhost WITH GRANT OPTION;
89+
--replace_regex /mysql.ndb_binlog_index.*$//
90+
--exec $MYSQL_UPGRADE --force -uroot_caching_sha2 -pabcd --server-public-key-path=$MYSQL_TEST_DIR/std_data/rsa_public_key.pem --protocol=tcp --ssl-mode=disabled 2>&1
91+
DROP USER root_caching_sha2@localhost;
7792

7893
--source include/mysql_upgrade_cleanup.inc
7994

0 commit comments

Comments
 (0)