Skip to content

Commit

Permalink
[CONJ-394] mysql_native_password wrong seed when in default authentic…
Browse files Browse the repository at this point in the history
…ation isn't mysql_native_password + no password correction
  • Loading branch information
rusher committed Dec 14, 2016
1 parent f775a29 commit eede9bd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public SendClearPasswordAuthPacket(String password, byte[] authData, int packSeq
*/
public void send(OutputStream os) throws IOException {
PacketOutputStream writer = (PacketOutputStream) os;
if (password == null || password.equals("")) {
writer.writeEmptyPacket(packSeq);
return;
}
writer.startPacket(packSeq);
writer.write(password.getBytes());
writer.write(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import java.io.IOException;
import java.io.OutputStream;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

public class SendNativePasswordAuthPacket extends AbstractAuthSwitchSendResponsePacket implements InterfaceAuthSwitchSendResponsePacket {

Expand All @@ -70,8 +71,21 @@ public SendNativePasswordAuthPacket(String password, byte[] authData, int packSe
public void send(OutputStream os) throws IOException {
PacketOutputStream writer = (PacketOutputStream) os;
try {
if (password == null || password.equals("")) {
writer.writeEmptyPacket(packSeq);
return;
}

writer.startPacket(packSeq);
writer.write(Utils.encryptPassword(password, authData));

byte[] seed;
if (authData.length > 0) {
//Seed is ended with a null byte value.
seed = Arrays.copyOfRange(authData, 0, authData.length - 1);
} else {
seed = new byte[0];
}
writer.write(Utils.encryptPassword(password, seed));
writer.finishPacketWithoutRelease(false);
writer.releaseBuffer();
} catch (NoSuchAlgorithmException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
package org.mariadb.jdbc.internal.packet.send;

import org.mariadb.jdbc.internal.stream.PacketOutputStream;
import org.mariadb.jdbc.internal.util.Utils;

import java.io.IOException;
import java.io.OutputStream;
Expand All @@ -67,8 +68,13 @@ public SendOldPasswordAuthPacket(String password, byte[] authData, int packSeq)
*/
public void send(OutputStream os) throws IOException {
PacketOutputStream pos = (PacketOutputStream) os;
if (password == null || password.equals("")) {
pos.writeEmptyPacket(packSeq);
return;
}
pos.startPacket(packSeq);
pos.writeByteArray(cryptOldFormatPassword(password, new String(authData))).writeByte((byte) 0x00);
byte[] seed = Utils.copyWithLength(authData, 8);
pos.writeByteArray(cryptOldFormatPassword(password, new String(seed))).writeByte((byte) 0x00);
pos.finishPacketWithoutRelease(false);
pos.releaseBuffer();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static InterfaceAuthSwitchSendResponsePacket processAuthPlugin(ReadPacket
case MYSQL_NATIVE_PASSWORD:
return new SendNativePasswordAuthPacket(password, authData, seqNo);
case MYSQL_OLD_PASSWORD:
return new SendOldPasswordAuthPacket(password, Utils.copyWithLength(authData, 8), seqNo);
return new SendOldPasswordAuthPacket(password, authData, seqNo);
case MYSQL_CLEAR_PASSWORD:
return new SendClearPasswordAuthPacket(password, authData, seqNo);
case DIALOG:
Expand Down

0 comments on commit eede9bd

Please sign in to comment.