Skip to content

Commit 7df3e00

Browse files
committed
client - fix an initial handshake auth logic #2
1 parent 963974e commit 7df3e00

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

client/auth.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,18 @@ func (c *Conn) readInitialHandshake() error {
101101
if c.capability&CLIENT_SECURE_CONNECTION != 0 {
102102
// Rest of the plugin provided data (scramble)
103103

104+
// https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase_packets_protocol_handshake_v10.html
104105
// $len=MAX(13, length of auth-plugin-data - 8)
106+
//
107+
// https://github.com/mysql/mysql-server/blob/1bfe02bdad6604d54913c62614bde57a055c8332/sql/auth/sql_authentication.cc#L1641-L1642
108+
// the first packet *must* have at least 20 bytes of a scramble.
109+
// if a plugin provided less, we pad it to 20 with zeros
105110
rest := int(authPluginDataLen) - 8
106-
if max := 13; rest < max {
111+
if max := 12 + 1; rest < max {
107112
rest = max
108113
}
109-
if data[pos+rest-1] != 0 {
110-
return errors.Errorf("expect 0x00 after scramble, got %q", rune(data[pos]))
111-
}
112114

113-
authPluginDataPart2 := data[pos : pos+rest-1]
115+
authPluginDataPart2 := data[pos : pos+rest]
114116
pos += rest
115117

116118
c.salt = append(c.salt, authPluginDataPart2...)

0 commit comments

Comments
 (0)