Skip to content

Commit 8263733

Browse files
committed
Check length of auth method switch payload for detecting old protocol.
Single 0xfe byte of the payload means it's an Old Authentication Method Switch Request Packet. See http://imysql.com/mysql-internal-manual/connection-phase-packets.html
1 parent a1919e6 commit 8263733

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/MySqlConnector/Serialization/MySqlSession.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,18 @@ public async Task ConnectAsync(ConnectionSettings cs, IOBehavior ioBehavior, Can
242242
// if server doesn't support the authentication fast path, it will send a new challenge
243243
if (payload.HeaderByte == AuthenticationMethodSwitchRequestPayload.Signature)
244244
{
245-
await SwitchAuthenticationAsync(cs, payload, ioBehavior, cancellationToken).ConfigureAwait(false);
246-
payload = await ReceiveReplyAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
245+
if (payload.ArraySegment.Count == 1)
246+
{
247+
// Single 0xfe byte of the payload means it's an Old Authentication Method Switch Request Packet.
248+
// See http://imysql.com/mysql-internal-manual/connection-phase-packets.html
249+
// It's old protocol so MySqlConnector doesn't support it.
250+
throw new NotSupportedException("Old Authentication Method Switch is not supported. Use new password hash format of 41-byte in MySQL server, not old format of 16-byte.");
251+
}
252+
else
253+
{
254+
await SwitchAuthenticationAsync(cs, payload, ioBehavior, cancellationToken).ConfigureAwait(false);
255+
payload = await ReceiveReplyAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
256+
}
247257
}
248258

249259
OkPayload.Create(payload);

0 commit comments

Comments
 (0)