1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// UnPack parses the handshake sent by the client.
// https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse41
func (a *Auth) UnPack(payload []byte) error {
var err error
buf := common.ReadBuffer(payload)
if a.clientFlags, err = buf.ReadU32(); err != nil {
return fmt.Errorf("auth.unpack: can't read client flags")
}
if a.clientFlags&sqldb.CLIENT_PROTOCOL_41 == 0 {
return fmt.Errorf("auth.unpack: only support protocol 4.1")
}
if a.maxPacketSize, err = buf.ReadU32(); err != nil {
return fmt.Errorf("auth.unpack: can't read maxPacketSize")
}
if a.charset, err = buf.ReadU8(); err != nil {
return fmt.Errorf("auth.unpack: can't read charset")
}
if err = buf.ReadZero(23); err != nil {
return fmt.Errorf("auth.unpack: can't read 23zeros")
}
if a.user, err = buf.ReadStringNUL(); err != nil {
return fmt.Errorf("auth.unpack: can't read user")
}
if (a.clientFlags & sqldb.CLIENT_SECURE_CONNECTION) > 0 {
if a.authResponseLen, err = buf.ReadU8(); err != nil {
return fmt.Errorf("auth.unpack: can't read authResponse length")
}
if a.authResponse, err = buf.ReadBytes(int(a.authResponseLen)); err != nil {
return fmt.Errorf("auth.unpack: can't read authResponse")
}
} else {
if a.authResponse, err = buf.ReadBytes(20); err != nil {
return fmt.Errorf("auth.unpack: can't read authResponse")
}
if err = buf.ReadZero(1); err != nil {
return fmt.Errorf("auth.unpack: can't read authResponse")
}
}
if (a.clientFlags & sqldb.CLIENT_CONNECT_WITH_DB) > 0 {
if a.database, err = buf.ReadStringNUL(); err != nil {
return fmt.Errorf("auth.unpack: can't read dbname")
}
}
if (a.clientFlags & sqldb.CLIENT_PLUGIN_AUTH) > 0 {
if a.pluginName, err = buf.ReadStringNUL(); err != nil {
return fmt.Errorf("auth.unpack: can't read pluginName")
}
}
if a.pluginName != DefaultAuthPluginName {
return fmt.Errorf("invalid authPluginName, got %v but only support %v", a.pluginName, DefaultAuthPluginName)
}
return nil
}
|