public void testBug21947042 ( ) throws Exception { Connection sslConn = null ; Properties props = new Properties ( ) ; props . setProperty ( "logger" , "StandardLogger" ) ; StandardLogger . startLoggingToBuffer ( ) ; try { int searchFrom = 0 ; int found = 0 ; sslConn = getConnectionWithProps ( props ) ; if ( versionMeetsMinimum ( 5 , 7 ) ) { assertTrue ( ( ( MySQLConnection ) sslConn ) . getUseSSL ( ) ) ; assertFalse ( ( ( MySQLConnection ) sslConn ) . getVerifyServerCertificate ( ) ) ; assertTrue ( ( ( MySQLConnection ) sslConn ) . getIO ( ) . isSSLEstablished ( ) ) ; } else { assertFalse ( ( ( MySQLConnection ) sslConn ) . getUseSSL ( ) ) ; assertTrue ( ( ( MySQLConnection ) sslConn ) . getVerifyServerCertificate ( ) ) ; assertFalse ( ( ( MySQLConnection ) sslConn ) . getIO ( ) . isSSLEstablished ( ) ) ; } ResultSet rset = sslConn . createStatement ( ) . executeQuery ( "SHOW STATUS LIKE 'ssl_cipher'" ) ; assertTrue ( rset . next ( ) ) ; String cipher = rset . getString ( 2 ) ; System . out . println ( "ssl_cipher=" + cipher ) ; rset = sslConn . createStatement ( ) . executeQuery ( "SHOW STATUS LIKE 'ssl_version'" ) ; assertTrue ( rset . next ( ) ) ; cipher = rset . getString ( 2 ) ; System . out . println ( "ssl_version=" + cipher ) ; sslConn . close ( ) ; String log = StandardLogger . getBuffer ( ) . toString ( ) ; found = log . indexOf ( Messages . getString ( "MysqlIO.SSLWarning" ) , searchFrom ) ; searchFrom = found + 1 ; if ( versionMeetsMinimum ( 5 , 7 ) ) { assertTrue ( found != - 1 ) ; } props . setProperty ( "useSSL" , "false" ) ; sslConn = getConnectionWithProps ( props ) ; assertFalse ( ( ( MySQLConnection ) sslConn ) . getUseSSL ( ) ) ; assertTrue ( ( ( MySQLConnection ) sslConn ) . getVerifyServerCertificate ( ) ) ; assertFalse ( ( ( MySQLConnection ) sslConn ) . getIO ( ) . isSSLEstablished ( ) ) ; rset = sslConn . createStatement ( ) . executeQuery ( "SHOW STATUS LIKE 'ssl_cipher'" ) ; assertTrue ( rset . next ( ) ) ; cipher = rset . getString ( 2 ) ; System . out . println ( "ssl_cipher=" + cipher ) ; rset = sslConn . createStatement ( ) . executeQuery ( "SHOW STATUS LIKE 'ssl_version'" ) ; assertTrue ( rset . next ( ) ) ; cipher = rset . getString ( 2 ) ; System . out . println ( "ssl_version=" + cipher ) ; sslConn . close ( ) ; log = StandardLogger . getBuffer ( ) . toString ( ) ; found = log . indexOf ( Messages . getString ( "MysqlIO.SSLWarning" ) , searchFrom ) ; if ( found != - 1 ) { searchFrom = found + 1 ; fail ( "Warning is not expected when useSSL is explicitly set to 'false'." ) ; } props . setProperty ( "useSSL" , "true" ) ; props . setProperty ( "trustCertificateKeyStoreUrl" , "file:src/testsuite/ssl-test-certs/test-cert-store" ) ; props . setProperty ( "trustCertificateKeyStoreType" , "JKS" ) ; props . setProperty ( "trustCertificateKeyStorePassword" , "password" ) ; sslConn = getConnectionWithProps ( props ) ; assertTrue ( ( ( MySQLConnection ) sslConn ) . getUseSSL ( ) ) ; assertTrue ( ( ( MySQLConnection ) sslConn ) . getVerifyServerCertificate ( ) ) ; assertTrue ( ( ( MySQLConnection ) sslConn ) . getIO ( ) . isSSLEstablished ( ) ) ; rset = sslConn . createStatement ( ) . executeQuery ( "SHOW STATUS LIKE 'ssl_cipher'" ) ; assertTrue ( rset . next ( ) ) ; cipher = rset . getString ( 2 ) ; System . out . println ( "ssl_cipher=" + cipher ) ; rset = sslConn . createStatement ( ) . executeQuery ( "SHOW STATUS LIKE 'ssl_version'" ) ; assertTrue ( rset . next ( ) ) ; cipher = rset . getString ( 2 ) ; System . out . println ( "ssl_version=" + cipher ) ; sslConn . close ( ) ; log = StandardLogger . getBuffer ( ) . toString ( ) ; found = log . indexOf ( Messages . getString ( "MysqlIO.SSLWarning" ) , searchFrom ) ; if ( found != - 1 ) { searchFrom = found + 1 ; fail ( "Warning is not expected when useSSL is explicitly set to 'false'." ) ; } } finally { StandardLogger . dropBuffer ( ) ; } }
Tests fix for BUG # 21947042 , PREFER TLS WHERE SUPPORTED BY MYSQL SERVER . Requires test certificates from testsuite/ssl-test-certs to be installed on the server being tested .