@@ -646,7 +646,7 @@ private GreetingPacket receiveGreeting() throws IOException {
646
646
}
647
647
648
648
private void enableHeartbeat () throws IOException {
649
- channel .write (new QueryCommand ("set @master_heartbeat_period=" + heartbeatInterval * 1000000 ));
649
+ channel .writeBuffered (new QueryCommand ("set @master_heartbeat_period=" + heartbeatInterval * 1000000 ));
650
650
byte [] statementResult = channel .read ();
651
651
if (statementResult [0 ] == (byte ) 0xFF /* error */ ) {
652
652
byte [] bytes = Arrays .copyOfRange (statementResult , 1 , statementResult .length );
@@ -669,7 +669,7 @@ private void requestBinaryLogStream() throws IOException {
669
669
dumpBinaryLogCommand = new DumpBinaryLogCommand (serverId , binlogFilename , binlogPosition );
670
670
}
671
671
}
672
- channel .write (dumpBinaryLogCommand );
672
+ channel .writeBuffered (dumpBinaryLogCommand );
673
673
}
674
674
675
675
private void ensureEventDataDeserializer (EventType eventType ,
@@ -692,6 +692,8 @@ private void ensureEventDataDeserializer(EventType eventType,
692
692
private void authenticate (GreetingPacket greetingPacket ) throws IOException {
693
693
int collation = greetingPacket .getServerCollation ();
694
694
int packetNumber = 1 ;
695
+
696
+ boolean usingSSLSocket = false ;
695
697
if (sslMode != SSLMode .DISABLED ) {
696
698
boolean serverSupportsSSL = (greetingPacket .getServerCapabilities () & ClientCapabilities .SSL ) != 0 ;
697
699
if (!serverSupportsSSL && (sslMode == SSLMode .REQUIRED || sslMode == SSLMode .VERIFY_CA ||
@@ -701,7 +703,7 @@ private void authenticate(GreetingPacket greetingPacket) throws IOException {
701
703
if (serverSupportsSSL ) {
702
704
SSLRequestCommand sslRequestCommand = new SSLRequestCommand ();
703
705
sslRequestCommand .setCollation (collation );
704
- channel .write (sslRequestCommand , packetNumber ++);
706
+ channel .writeBuffered (sslRequestCommand , packetNumber ++);
705
707
SSLSocketFactory sslSocketFactory =
706
708
this .sslSocketFactory != null ?
707
709
this .sslSocketFactory :
@@ -710,12 +712,13 @@ private void authenticate(GreetingPacket greetingPacket) throws IOException {
710
712
DEFAULT_VERIFY_CA_SSL_MODE_SOCKET_FACTORY ;
711
713
channel .upgradeToSSL (sslSocketFactory ,
712
714
sslMode == SSLMode .VERIFY_IDENTITY ? new TLSHostnameVerifier () : null );
715
+ usingSSLSocket = true ;
713
716
}
714
717
}
715
718
AuthenticateCommand authenticateCommand = new AuthenticateCommand (schema , username , password ,
716
719
greetingPacket .getScramble ());
717
720
authenticateCommand .setCollation (collation );
718
- channel .write (authenticateCommand , packetNumber );
721
+ channel .writeBuffered (authenticateCommand , packetNumber );
719
722
byte [] authenticationResult = channel .read ();
720
723
if (authenticationResult [0 ] != (byte ) 0x00 /* ok */ ) {
721
724
if (authenticationResult [0 ] == (byte ) 0xFF /* error */ ) {
@@ -724,14 +727,14 @@ private void authenticate(GreetingPacket greetingPacket) throws IOException {
724
727
throw new AuthenticationException (errorPacket .getErrorMessage (), errorPacket .getErrorCode (),
725
728
errorPacket .getSqlState ());
726
729
} else if (authenticationResult [0 ] == (byte ) 0xFE ) {
727
- switchAuthentication (authenticationResult );
730
+ switchAuthentication (authenticationResult , usingSSLSocket );
728
731
} else {
729
732
throw new AuthenticationException ("Unexpected authentication result (" + authenticationResult [0 ] + ")" );
730
733
}
731
734
}
732
735
}
733
736
734
- private void switchAuthentication (byte [] authenticationResult ) throws IOException {
737
+ private void switchAuthentication (byte [] authenticationResult , boolean usingSSLSocket ) throws IOException {
735
738
/*
736
739
Azure-MySQL likes to tell us to switch authentication methods, even though
737
740
we haven't advertised that we support any. It uses this for some-odd
@@ -745,7 +748,7 @@ private void switchAuthentication(byte[] authenticationResult) throws IOExceptio
745
748
String scramble = buffer .readZeroTerminatedString ();
746
749
747
750
Command switchCommand = new AuthenticateNativePasswordCommand (scramble , password );
748
- channel .writeBuffered (switchCommand , 3 );
751
+ channel .writeBuffered (switchCommand , ( usingSSLSocket ? 4 : 3 ) );
749
752
byte [] authResult = channel .read ();
750
753
751
754
if (authResult [0 ] != (byte ) 0x00 ) {
@@ -787,7 +790,7 @@ public void run() {
787
790
connectionLost = System .currentTimeMillis () - eventLastSeen > keepAliveInterval ;
788
791
} else {
789
792
try {
790
- channel .write (new PingCommand ());
793
+ channel .writeBuffered (new PingCommand ());
791
794
} catch (IOException e ) {
792
795
connectionLost = true ;
793
796
}
@@ -891,7 +894,7 @@ public boolean isConnected() {
891
894
}
892
895
893
896
private String fetchGtidPurged () throws IOException {
894
- channel .write (new QueryCommand ("show global variables like 'gtid_purged'" ));
897
+ channel .writeBuffered (new QueryCommand ("show global variables like 'gtid_purged'" ));
895
898
ResultSetRowPacket [] resultSet = readResultSet ();
896
899
if (resultSet .length != 0 ) {
897
900
return resultSet [0 ].getValue (1 ).toUpperCase ();
@@ -901,7 +904,7 @@ private String fetchGtidPurged() throws IOException {
901
904
902
905
private void fetchBinlogFilenameAndPosition () throws IOException {
903
906
ResultSetRowPacket [] resultSet ;
904
- channel .write (new QueryCommand ("show master status" ));
907
+ channel .writeBuffered (new QueryCommand ("show master status" ));
905
908
resultSet = readResultSet ();
906
909
if (resultSet .length == 0 ) {
907
910
throw new IOException ("Failed to determine binlog filename/position" );
@@ -912,7 +915,7 @@ private void fetchBinlogFilenameAndPosition() throws IOException {
912
915
}
913
916
914
917
private ChecksumType fetchBinlogChecksum () throws IOException {
915
- channel .write (new QueryCommand ("show global variables like 'binlog_checksum'" ));
918
+ channel .writeBuffered (new QueryCommand ("show global variables like 'binlog_checksum'" ));
916
919
ResultSetRowPacket [] resultSet = readResultSet ();
917
920
if (resultSet .length == 0 ) {
918
921
return ChecksumType .NONE ;
@@ -921,7 +924,7 @@ private ChecksumType fetchBinlogChecksum() throws IOException {
921
924
}
922
925
923
926
private void confirmSupportOfChecksum (ChecksumType checksumType ) throws IOException {
924
- channel .write (new QueryCommand ("set @master_binlog_checksum= @@global.binlog_checksum" ));
927
+ channel .writeBuffered (new QueryCommand ("set @master_binlog_checksum= @@global.binlog_checksum" ));
925
928
byte [] statementResult = channel .read ();
926
929
if (statementResult [0 ] == (byte ) 0xFF /* error */ ) {
927
930
byte [] bytes = Arrays .copyOfRange (statementResult , 1 , statementResult .length );
0 commit comments