Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.

Commit 50b949a

Browse files
elemountDiego
authored and
Diego
committed
Fix mysql_clear_password plugin on auth switch panic. (go-sql-driver#646)
Fixes go-sql-driver#636
1 parent 8135eeb commit 50b949a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packets.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,9 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
359359
// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchResponse
360360
func (mc *mysqlConn) writeOldAuthPacket(cipher []byte) error {
361361
// User password
362-
scrambleBuff := scrambleOldPassword(cipher, []byte(mc.cfg.Passwd))
362+
// https://dev.mysql.com/doc/internals/en/old-password-authentication.html
363+
// Old password authentication only need and will need 8-byte challenge.
364+
scrambleBuff := scrambleOldPassword(cipher[:8], []byte(mc.cfg.Passwd))
363365

364366
// Calculate the packet length and add a tailing 0
365367
pktLen := len(scrambleBuff) + 1
@@ -399,7 +401,9 @@ func (mc *mysqlConn) writeClearAuthPacket() error {
399401
// Native password authentication method
400402
// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchResponse
401403
func (mc *mysqlConn) writeNativeAuthPacket(cipher []byte) error {
402-
scrambleBuff := scramblePassword(cipher, []byte(mc.cfg.Passwd))
404+
// https://dev.mysql.com/doc/internals/en/secure-password-authentication.html
405+
// Native password authentication only need and will need 20-byte challenge.
406+
scrambleBuff := scramblePassword(cipher[0:20], []byte(mc.cfg.Passwd))
403407

404408
// Calculate the packet length and add a tailing 0
405409
pktLen := len(scrambleBuff)
@@ -502,7 +506,7 @@ func (mc *mysqlConn) readResultOK() ([]byte, error) {
502506
if len(data) > 1 {
503507
pluginEndIndex := bytes.IndexByte(data, 0x00)
504508
plugin := string(data[1:pluginEndIndex])
505-
cipher := data[pluginEndIndex+1 : len(data)-1]
509+
cipher := data[pluginEndIndex+1:]
506510

507511
switch plugin {
508512
case "mysql_old_password":

0 commit comments

Comments
 (0)