Bug #81223 REPLICATION IS USING SSL REGARDLESS MASTER_SSL OPTION
Submitted: 28 Apr 2016 13:09 Modified: 5 Aug 2016 14:44
Reporter: João Gramacho Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:5.7.11 OS:Any
Assigned to: CPU Architecture:Any

[28 Apr 2016 13:09] João Gramacho
Description:
While investigating BUG#22616245 it was noticed that since the push with the commit id 1bf8bc77a115b84ea8066b7b7b3175518c5810cc the slave is always using SSL/TLS when the servers support it, regardless of MASTER_SSL option.

How to repeat:
Apply the diff below and run:

$ ./mtr --mem rpl_ssl 
...
rpl_topology=1->2
connection master;
Assertion text: 'Without MASTER_SSL, the slave should be connected to the master without SSL/TLS'
Assertion condition: '"SSL/TLS" = "TCP/IP"'
Assertion condition, interpolated: '"SSL/TLS" = "TCP/IP"'
Assertion result: '0'

diff --git a/mysql-test/suite/rpl/t/rpl_ssl.test b/mysql-test/suite/rpl/t/rpl_ssl.test
index d141d78..7905068 100644
--- a/mysql-test/suite/rpl/t/rpl_ssl.test
+++ b/mysql-test/suite/rpl/t/rpl_ssl.test
@@ -2,6 +2,20 @@
 source include/have_ssl_communication.inc;
 source include/master-slave.inc;
 
+# Default replication setup at master-slave.inc does not set MASTER_SSL
+--connection slave
+--let $current_master_ssl= query_get_value(SHOW SLAVE STATUS, Master_SSL_Allowed, 1)
+--let $assert_text= Master_SSL_Allowed should be NO by default
+--let $assert_cond= "$current_master_ssl" = "NO"
+--source include/assert.inc
+
+# The slave should be initially connected to the master without SSL/TLS
+--connection master
+--let $connection_type= `SELECT CONNECTION_TYPE FROM performance_schema.threads WHERE PROCESSLIST_COMMAND = "Binlog Dump"`
+--let $assert_text= Without MASTER_SSL, the slave should be connected to the master without SSL/TLS
+--let $assert_cond= "$connection_type" = "TCP/IP"
+--source include/assert.inc
+
 # create a user for replication that requires ssl encryption
 connection master;
 set @orig_sql_mode= @@sql_mode;

Suggested fix:
If MASTER_SSL is not configured, the slave should not connect using SSL/TLS.

diff --git a/sql/rpl_slave.cc b/sql/rpl_slave.cc
index d3d50b2..3540e13 100644
--- a/sql/rpl_slave.cc
+++ b/sql/rpl_slave.cc
@@ -8630,6 +8630,7 @@ static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
 #ifdef HAVE_OPENSSL
   if (mi->ssl)
   {
+    /* The channel is configured to use SSL */
     mysql_ssl_set(mysql,
                   mi->ssl_key[0]?mi->ssl_key:0,
                   mi->ssl_cert[0]?mi->ssl_cert:0,
@@ -8655,6 +8656,12 @@ static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
       ssl_mode= SSL_MODE_REQUIRED;
     mysql_options(mysql, MYSQL_OPT_SSL_MODE, &ssl_mode);
   }
+  else
+  {
+    /* The channel is not configured to use SSL */
+    enum mysql_ssl_mode ssl_mode= SSL_MODE_DISABLED;
+    mysql_options(mysql, MYSQL_OPT_SSL_MODE, &ssl_mode);
+  }
 #endif
 
   /*
[5 Aug 2016 14:44] David Moss
Posted by developer:
 
Thank you for your feedback, this has been fixed in upcoming versions and the following was added to the 5.7.14 changelog:
Slaves running MySQL version 5.7.11 and later were always using SSL/TLS when the server supported it, regardless of the MASTER_SSL option. This was due to the addition of the --ssl-mode option, which defaults to preferring an SSL connection. The fix ensures that slaves do not use SSL when MASTER_SSL=0.
[23 Aug 2016 11:16] David Moss
Bug number added to change log. Unsetting flags.