-
Notifications
You must be signed in to change notification settings - Fork 0
/
initial_handshake.go
57 lines (41 loc) · 1.7 KB
/
initial_handshake.go
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
55
56
57
package server
// see: https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase_packets_protocol_handshake_v10.html
func (c *Conn) writeInitialHandshake() error {
data := make([]byte, 4)
//min version 10
data = append(data, 10)
//server version[00]
data = append(data, c.serverConf.serverVersion...)
data = append(data, 0x00)
//connection id
data = append(data, byte(c.connectionID), byte(c.connectionID>>8), byte(c.connectionID>>16), byte(c.connectionID>>24))
//auth-plugin-data-part-1
data = append(data, c.salt[0:8]...)
//filter 0x00 byte, terminating the first part of a scramble
data = append(data, 0x00)
defaultFlag := c.serverConf.capability
//capability flag lower 2 bytes, using default capability here
data = append(data, byte(defaultFlag), byte(defaultFlag>>8))
//charset
data = append(data, c.serverConf.collationId)
//status
data = append(data, byte(c.status), byte(c.status>>8))
//capability flag upper 2 bytes, using default capability here
data = append(data, byte(defaultFlag>>16), byte(defaultFlag>>24))
// server supports CLIENT_PLUGIN_AUTH and CLIENT_SECURE_CONNECTION
data = append(data, byte(8+12+1))
//reserved 10 [00]
data = append(data, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
//auth-plugin-data-part-2
data = append(data, c.salt[8:]...)
// second part of the password cipher [mininum 13 bytes],
// where len=MAX(13, length of auth-plugin-data - 8)
// add \NUL to terminate the string
data = append(data, 0x00)
// auth plugin name
data = append(data, c.serverConf.defaultAuthMethod...)
// EOF if MySQL version (>= 5.5.7 and < 5.5.10) or (>= 5.6.0 and < 5.6.2)
// \NUL otherwise, so we use \NUL
data = append(data, 0)
return c.WritePacket(data)
}