Skip to content

Commit f6b0dfe

Browse files
author
Joao Gramacho
committed
WL#10957: Binary log encryption at rest (Step 3)
Made mysqlbinlog to state that it cannot read encrypted log files. @ sql/binlog_istream.{h|cc} Added a new Error_type to Binlog_read_error specific to mysqlbinlog client program. @ sql/binlog_istream.cc Instead of trying to deserialize the encrypted reader, mysqlbinlog is now reporting it cannot read encrypted binary log files directly.
1 parent b186620 commit f6b0dfe

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

mysql-test/suite/rpl_nogtid/r/rpl_nogtid_encryption_read.result

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ ERROR HY000: Can't find key from keyring, please check in the server log if a ke
9898
UNINSTALL PLUGIN keyring_file;
9999
SHOW BINLOG EVENTS IN 'master-bin.000002';
100100
ERROR HY000: Failed to fetch key from keyring, please check if keyring plugin is loaded.
101+
# Part 5
102+
include/assert_grep.inc [mysqlbinlog reported it does not support reading encrypted log files]
101103
[connection slave]
102104
include/start_slave.inc
103105
include/rpl_end.inc

mysql-test/suite/rpl_nogtid/t/rpl_nogtid_encryption_read.test

+19
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
# After uninstalling the keyring_file plug-in, the server shall throw an error
6363
# when requested to access the encrypted binary log file.
6464
#
65+
# Part 5: mysqlbinlog is unable to dump encrypted binary logs
66+
#
67+
# Request mysqlbinlog to dump the content of the encrypted binary log file
68+
# and parse the output asserting that the expected error message was thrown.
69+
#
6570
#
6671
# This test case rely in two previously generated files:
6772
#
@@ -243,6 +248,20 @@ UNINSTALL PLUGIN keyring_file;
243248
--error ER_RPL_ENCRYPTION_FAILED_TO_FETCH_KEY
244249
--eval SHOW BINLOG EVENTS IN '$binlog_file'
245250

251+
--echo # Part 5
252+
--let $output_file= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.log
253+
--let $error_file= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.err
254+
--error 1
255+
--exec $MYSQL_BINLOG -F $binlog_file_path > $output_file 2> $error_file
256+
--let $assert_text= mysqlbinlog reported it does not support reading encrypted log files
257+
--let $assert_file= $error_file
258+
--let $assert_count= 1
259+
--let $assert_select= Reading encrypted log files directly is not supported
260+
--source include/assert_grep.inc
261+
--remove_file $output_file
262+
--remove_file $error_file
263+
264+
# Cleanup
246265
--remove_file $keyring_file
247266
--source include/rpl_connection_slave.inc
248267
--source include/start_slave.inc

sql/binlog_istream.cc

+7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ const char *Binlog_read_error::get_str() const {
5656
case CANNOT_GET_FILE_PASSWORD:
5757
return "Cannot get file password for encrypted replication log file, "
5858
"please check if keyring plugin is loaded";
59+
case READ_ENCRYPTED_LOG_FILE_IS_NOT_SUPPORTED:
60+
return "Reading encrypted log files directly is not supported.";
5961
default:
6062
/* There must be something wrong in the code if it reaches this branch. */
6163
DBUG_ASSERT(0);
@@ -134,6 +136,7 @@ bool Basic_binlog_ifile::read_binlog_magic() {
134136
*/
135137
if (memcmp(magic, Rpl_encryption_header::ENCRYPTION_MAGIC,
136138
Rpl_encryption_header::ENCRYPTION_MAGIC_SIZE) == 0) {
139+
#ifdef MYSQL_SERVER
137140
std::unique_ptr<Binlog_encryption_istream> encryption_istream{
138141
new Binlog_encryption_istream()};
139142
if (encryption_istream->open(std::move(m_istream), m_error))
@@ -146,6 +149,10 @@ bool Basic_binlog_ifile::read_binlog_magic() {
146149
if (m_istream->read(magic, BINLOG_MAGIC_SIZE) != BINLOG_MAGIC_SIZE) {
147150
DBUG_RETURN(m_error->set_type(Binlog_read_error::BAD_BINLOG_MAGIC));
148151
}
152+
#else
153+
DBUG_RETURN(m_error->set_type(
154+
Binlog_read_error::READ_ENCRYPTED_LOG_FILE_IS_NOT_SUPPORTED));
155+
#endif
149156
}
150157

151158
if (memcmp(magic, BINLOG_MAGIC, BINLOG_MAGIC_SIZE))

sql/binlog_istream.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class Binlog_read_error {
6161
// The binlog magic is incorrect
6262
BAD_BINLOG_MAGIC,
6363
INVALID_ENCRYPTION_HEADER,
64-
CANNOT_GET_FILE_PASSWORD
64+
CANNOT_GET_FILE_PASSWORD,
65+
READ_ENCRYPTED_LOG_FILE_IS_NOT_SUPPORTED
6566
};
6667

6768
Binlog_read_error() {}

0 commit comments

Comments
 (0)