Skip to content

Commit

Permalink
merge with upstream master
Browse files Browse the repository at this point in the history
  • Loading branch information
glarwood committed May 13, 2019
2 parents 7124322 + d466f72 commit a7f362c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.20.1](https://github.com/shyiko/mysql-binlog-connector-java/compare/0.20.0...0.20.1) - 2019-05-12

### Added
- `mysql_native_password` auth support + SSL (Azure) ([#274](https://github.com/shyiko/mysql-binlog-connector-java/pull/274)).

## [0.20.0](https://github.com/shyiko/mysql-binlog-connector-java/compare/0.19.1...0.20.0) - 2019-04-20

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ private void ensureEventDataDeserializer(EventType eventType,
private void authenticate(GreetingPacket greetingPacket) throws IOException {
int collation = greetingPacket.getServerCollation();
int packetNumber = 1;

boolean usingSSLSocket = false;
if (sslMode != SSLMode.DISABLED) {
boolean serverSupportsSSL = (greetingPacket.getServerCapabilities() & ClientCapabilities.SSL) != 0;
if (!serverSupportsSSL && (sslMode == SSLMode.REQUIRED || sslMode == SSLMode.VERIFY_CA ||
Expand All @@ -709,6 +711,7 @@ private void authenticate(GreetingPacket greetingPacket) throws IOException {
DEFAULT_REQUIRED_SSL_MODE_SOCKET_FACTORY :
DEFAULT_VERIFY_CA_SSL_MODE_SOCKET_FACTORY;
channel.upgradeToSSL(sslSocketFactory, null);
usingSSLSocket = true;
}
}
AuthenticateCommand authenticateCommand = new AuthenticateCommand(schema, username, password,
Expand All @@ -723,14 +726,14 @@ private void authenticate(GreetingPacket greetingPacket) throws IOException {
throw new AuthenticationException(errorPacket.getErrorMessage(), errorPacket.getErrorCode(),
errorPacket.getSqlState());
} else if (authenticationResult[0] == (byte) 0xFE) {
switchAuthentication(authenticationResult);
switchAuthentication(authenticationResult, usingSSLSocket);
} else {
throw new AuthenticationException("Unexpected authentication result (" + authenticationResult[0] + ")");
}
}
}

private void switchAuthentication(byte[] authenticationResult) throws IOException {
private void switchAuthentication(byte[] authenticationResult, boolean usingSSLSocket) throws IOException {
/*
Azure-MySQL likes to tell us to switch authentication methods, even though
we haven't advertised that we support any. It uses this for some-odd
Expand All @@ -744,7 +747,7 @@ private void switchAuthentication(byte[] authenticationResult) throws IOExceptio
String scramble = buffer.readZeroTerminatedString();

Command switchCommand = new AuthenticateNativePasswordCommand(scramble, password);
channel.writeBuffered(switchCommand, 3);
channel.write(switchCommand, (usingSSLSocket ? 4 : 3));
byte[] authResult = channel.read();

if (authResult[0] != (byte) 0x00) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,22 @@ public byte[] read() throws IOException {

public void write(Command command, int packetNumber) throws IOException {
byte[] body = command.toByteArray();
outputStream.writeInteger(body.length, 3); // packet length
outputStream.writeInteger(packetNumber, 1);
outputStream.write(body, 0, body.length);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
buffer.writeInteger(body.length, 3); // packet length
buffer.writeInteger(packetNumber, 1);
buffer.write(body, 0, body.length);
outputStream.write(buffer.toByteArray());
// though it has no effect in case of default (underlying) output stream (SocketOutputStream),
// it may be necessary in case of non-default one
outputStream.flush();
}

/*
Azure's MySQL has bizarre network properties that force us to write an
auth-response challenge in one shot, lest their hair catch on fire and
forcibly disconnect us.
/**
* @deprecated use {@link #write(Command, int)} instead
*/
@Deprecated
public void writeBuffered(Command command, int packetNumber) throws IOException {
byte[] body = command.toByteArray();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
buffer.writeInteger(body.length, 3); // packet length
buffer.writeInteger(packetNumber, 1);
buffer.write(body, 0, body.length);
buffer.flush();
socket.getOutputStream().write(buffer.toByteArray());
write(command, packetNumber);
}

public void write(Command command) throws IOException {
Expand Down

0 comments on commit a7f362c

Please sign in to comment.