|
@@ -5,24 +5,6 @@ import (
|
|
|
"encoding/binary"
|
|
"encoding/binary"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-type HandshakePacket struct {
|
|
|
|
|
- PacketLength uint64
|
|
|
|
|
- SequenceId uint64
|
|
|
|
|
- ProtocolVersion uint64
|
|
|
|
|
- ServerVersion string
|
|
|
|
|
- ThreadId uint64
|
|
|
|
|
- AuthPluginDataPart1 []byte
|
|
|
|
|
- CapabilityFlags1 []byte
|
|
|
|
|
- Charset uint64
|
|
|
|
|
- Status []byte
|
|
|
|
|
- CapabilityFlags2 []byte
|
|
|
|
|
- AuthPluginDataLength uint64
|
|
|
|
|
- AuthPluginDataPart2 []byte
|
|
|
|
|
- AuthPluginName string
|
|
|
|
|
- CapabilityFlags *CapabilityFlags
|
|
|
|
|
- StatusFlags *StatusFlags
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
type CapabilityFlags struct {
|
|
type CapabilityFlags struct {
|
|
|
LongPassword bool
|
|
LongPassword bool
|
|
|
FoundRows bool
|
|
FoundRows bool
|
|
@@ -30,26 +12,26 @@ type CapabilityFlags struct {
|
|
|
ConnectWithDb bool
|
|
ConnectWithDb bool
|
|
|
NoSchema bool
|
|
NoSchema bool
|
|
|
Compress bool
|
|
Compress bool
|
|
|
- Odbc bool
|
|
|
|
|
|
|
+ ODBC bool
|
|
|
LocalFiles bool
|
|
LocalFiles bool
|
|
|
IgnoreSpace bool
|
|
IgnoreSpace bool
|
|
|
Protocol41 bool
|
|
Protocol41 bool
|
|
|
Interactive bool
|
|
Interactive bool
|
|
|
- Ssl bool
|
|
|
|
|
|
|
+ SSL bool
|
|
|
IgnoreSigpipe bool
|
|
IgnoreSigpipe bool
|
|
|
Transactions bool
|
|
Transactions bool
|
|
|
- Reserved bool
|
|
|
|
|
- Reserved2 bool
|
|
|
|
|
|
|
+ LegacyProtocol41 bool
|
|
|
|
|
+ SecureConnection bool
|
|
|
MultiStatements bool
|
|
MultiStatements bool
|
|
|
MultiResults bool
|
|
MultiResults bool
|
|
|
- PsMultiResults bool
|
|
|
|
|
|
|
+ PSMultiResults bool
|
|
|
PluginAuth bool
|
|
PluginAuth bool
|
|
|
ConnectAttrs bool
|
|
ConnectAttrs bool
|
|
|
PluginAuthLenEncClientData bool
|
|
PluginAuthLenEncClientData bool
|
|
|
CanHandleExpiredPasswords bool
|
|
CanHandleExpiredPasswords bool
|
|
|
SessionTrack bool
|
|
SessionTrack bool
|
|
|
DeprecateEOF bool
|
|
DeprecateEOF bool
|
|
|
- SslVerifyServerCert bool
|
|
|
|
|
|
|
+ SSLVerifyServerCert bool
|
|
|
OptionalResultSetMetadata bool
|
|
OptionalResultSetMetadata bool
|
|
|
RememberOptions bool
|
|
RememberOptions bool
|
|
|
}
|
|
}
|
|
@@ -62,16 +44,46 @@ type StatusFlags struct {
|
|
|
QueryNoIndexUsed bool
|
|
QueryNoIndexUsed bool
|
|
|
StatusCursorExists bool
|
|
StatusCursorExists bool
|
|
|
StatusLastRowSent bool
|
|
StatusLastRowSent bool
|
|
|
- StatusDbDropped bool
|
|
|
|
|
|
|
+ StatusDBDropped bool
|
|
|
StatusNoBackslashEscapes bool
|
|
StatusNoBackslashEscapes bool
|
|
|
StatusMetadataChanged bool
|
|
StatusMetadataChanged bool
|
|
|
QueryWasSlow bool
|
|
QueryWasSlow bool
|
|
|
- PsOutParams bool
|
|
|
|
|
|
|
+ PSOutParams bool
|
|
|
StatusInTransReadonly bool
|
|
StatusInTransReadonly bool
|
|
|
SessionStateChanged bool
|
|
SessionStateChanged bool
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (hs *HandshakePacket) decodeCapabilityFlags() {
|
|
|
|
|
|
|
+type HandshakePacket struct {
|
|
|
|
|
+ PacketLength uint64
|
|
|
|
|
+ SequenceID uint64
|
|
|
|
|
+ ProtocolVersion uint64
|
|
|
|
|
+ ServerVersion string
|
|
|
|
|
+ ThreadID uint64
|
|
|
|
|
+ AuthPluginDataPart1 []byte
|
|
|
|
|
+ CapabilityFlags1 []byte
|
|
|
|
|
+ Charset uint64
|
|
|
|
|
+ Status []byte
|
|
|
|
|
+ CapabilityFlags2 []byte
|
|
|
|
|
+ AuthPluginDataLength uint64
|
|
|
|
|
+ AuthPluginDataPart2 []byte
|
|
|
|
|
+ AuthPluginName string
|
|
|
|
|
+ CapabilityFlags *CapabilityFlags
|
|
|
|
|
+ StatusFlags *StatusFlags
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type HandshakeResponse struct {
|
|
|
|
|
+ ClientFlag *CapabilityFlags
|
|
|
|
|
+ MaxPacketSize uint64
|
|
|
|
|
+ CharacterSet uint64
|
|
|
|
|
+ Username string
|
|
|
|
|
+ AuthResponseLength uint64
|
|
|
|
|
+ AuthResponse string
|
|
|
|
|
+ Database string
|
|
|
|
|
+ ClientPluginName string
|
|
|
|
|
+ KeyValues map[string]string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (c *Conn) decodeCapabilityFlags(hs *HandshakePacket) {
|
|
|
hs.CapabilityFlags = &CapabilityFlags{
|
|
hs.CapabilityFlags = &CapabilityFlags{
|
|
|
LongPassword: (hs.CapabilityFlags1[0] & 1) > 0,
|
|
LongPassword: (hs.CapabilityFlags1[0] & 1) > 0,
|
|
|
FoundRows: (hs.CapabilityFlags1[0] & 2) > 0,
|
|
FoundRows: (hs.CapabilityFlags1[0] & 2) > 0,
|
|
@@ -79,32 +91,32 @@ func (hs *HandshakePacket) decodeCapabilityFlags() {
|
|
|
ConnectWithDb: (hs.CapabilityFlags1[0] & 8) > 0,
|
|
ConnectWithDb: (hs.CapabilityFlags1[0] & 8) > 0,
|
|
|
NoSchema: (hs.CapabilityFlags1[0] & 16) > 0,
|
|
NoSchema: (hs.CapabilityFlags1[0] & 16) > 0,
|
|
|
Compress: (hs.CapabilityFlags1[0] & 32) > 0,
|
|
Compress: (hs.CapabilityFlags1[0] & 32) > 0,
|
|
|
- Odbc: (hs.CapabilityFlags1[0] & 64) > 0,
|
|
|
|
|
|
|
+ ODBC: (hs.CapabilityFlags1[0] & 64) > 0,
|
|
|
LocalFiles: (hs.CapabilityFlags1[0] & 128) > 0,
|
|
LocalFiles: (hs.CapabilityFlags1[0] & 128) > 0,
|
|
|
IgnoreSpace: (hs.CapabilityFlags1[1] & 1) > 0,
|
|
IgnoreSpace: (hs.CapabilityFlags1[1] & 1) > 0,
|
|
|
Protocol41: (hs.CapabilityFlags1[1] & 2) > 0,
|
|
Protocol41: (hs.CapabilityFlags1[1] & 2) > 0,
|
|
|
Interactive: (hs.CapabilityFlags1[1] & 4) > 0,
|
|
Interactive: (hs.CapabilityFlags1[1] & 4) > 0,
|
|
|
- Ssl: (hs.CapabilityFlags1[1] & 8) > 0,
|
|
|
|
|
|
|
+ SSL: (hs.CapabilityFlags1[1] & 8) > 0,
|
|
|
IgnoreSigpipe: (hs.CapabilityFlags1[1] & 16) > 0,
|
|
IgnoreSigpipe: (hs.CapabilityFlags1[1] & 16) > 0,
|
|
|
Transactions: (hs.CapabilityFlags1[1] & 32) > 0,
|
|
Transactions: (hs.CapabilityFlags1[1] & 32) > 0,
|
|
|
- Reserved: (hs.CapabilityFlags1[1] & 64) > 0,
|
|
|
|
|
- Reserved2: (hs.CapabilityFlags1[1] & 128) > 0,
|
|
|
|
|
|
|
+ LegacyProtocol41: (hs.CapabilityFlags1[1] & 64) > 0,
|
|
|
|
|
+ SecureConnection: (hs.CapabilityFlags1[1] & 128) > 0,
|
|
|
MultiStatements: (hs.CapabilityFlags2[0] & 1) > 0,
|
|
MultiStatements: (hs.CapabilityFlags2[0] & 1) > 0,
|
|
|
MultiResults: (hs.CapabilityFlags2[0] & 2) > 0,
|
|
MultiResults: (hs.CapabilityFlags2[0] & 2) > 0,
|
|
|
- PsMultiResults: (hs.CapabilityFlags2[0] & 4) > 0,
|
|
|
|
|
|
|
+ PSMultiResults: (hs.CapabilityFlags2[0] & 4) > 0,
|
|
|
PluginAuth: (hs.CapabilityFlags2[0] & 8) > 0,
|
|
PluginAuth: (hs.CapabilityFlags2[0] & 8) > 0,
|
|
|
ConnectAttrs: (hs.CapabilityFlags2[0] & 16) > 0,
|
|
ConnectAttrs: (hs.CapabilityFlags2[0] & 16) > 0,
|
|
|
PluginAuthLenEncClientData: (hs.CapabilityFlags2[0] & 32) > 0,
|
|
PluginAuthLenEncClientData: (hs.CapabilityFlags2[0] & 32) > 0,
|
|
|
CanHandleExpiredPasswords: (hs.CapabilityFlags2[0] & 64) > 0,
|
|
CanHandleExpiredPasswords: (hs.CapabilityFlags2[0] & 64) > 0,
|
|
|
SessionTrack: (hs.CapabilityFlags2[0] & 128) > 0,
|
|
SessionTrack: (hs.CapabilityFlags2[0] & 128) > 0,
|
|
|
DeprecateEOF: (hs.CapabilityFlags2[1] & 1) > 0,
|
|
DeprecateEOF: (hs.CapabilityFlags2[1] & 1) > 0,
|
|
|
- SslVerifyServerCert: (hs.CapabilityFlags2[1] & 2) > 0,
|
|
|
|
|
|
|
+ SSLVerifyServerCert: (hs.CapabilityFlags2[1] & 2) > 0,
|
|
|
OptionalResultSetMetadata: (hs.CapabilityFlags2[1] & 4) > 0,
|
|
OptionalResultSetMetadata: (hs.CapabilityFlags2[1] & 4) > 0,
|
|
|
RememberOptions: (hs.CapabilityFlags2[1] & 8) > 0,
|
|
RememberOptions: (hs.CapabilityFlags2[1] & 8) > 0,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (hs *HandshakePacket) decodeStatusFlags() {
|
|
|
|
|
|
|
+func (c *Conn) decodeStatusFlags(hs *HandshakePacket) {
|
|
|
hs.StatusFlags = &StatusFlags{
|
|
hs.StatusFlags = &StatusFlags{
|
|
|
StatusInTrans: (hs.Status[0] & 1) > 0,
|
|
StatusInTrans: (hs.Status[0] & 1) > 0,
|
|
|
StatusAutocommit: (hs.Status[0] & 2) > 0,
|
|
StatusAutocommit: (hs.Status[0] & 2) > 0,
|
|
@@ -113,115 +125,106 @@ func (hs *HandshakePacket) decodeStatusFlags() {
|
|
|
QueryNoIndexUsed: (hs.Status[0] & 16) > 0,
|
|
QueryNoIndexUsed: (hs.Status[0] & 16) > 0,
|
|
|
StatusCursorExists: (hs.Status[0] & 32) > 0,
|
|
StatusCursorExists: (hs.Status[0] & 32) > 0,
|
|
|
StatusLastRowSent: (hs.Status[0] & 64) > 0,
|
|
StatusLastRowSent: (hs.Status[0] & 64) > 0,
|
|
|
- StatusDbDropped: (hs.Status[0] & 128) > 0,
|
|
|
|
|
|
|
+ StatusDBDropped: (hs.Status[0] & 128) > 0,
|
|
|
StatusNoBackslashEscapes: (hs.Status[1] & 1) > 0,
|
|
StatusNoBackslashEscapes: (hs.Status[1] & 1) > 0,
|
|
|
StatusMetadataChanged: (hs.Status[1] & 2) > 0,
|
|
StatusMetadataChanged: (hs.Status[1] & 2) > 0,
|
|
|
QueryWasSlow: (hs.Status[1] & 4) > 0,
|
|
QueryWasSlow: (hs.Status[1] & 4) > 0,
|
|
|
- PsOutParams: (hs.Status[1] & 8) > 0,
|
|
|
|
|
|
|
+ PSOutParams: (hs.Status[1] & 8) > 0,
|
|
|
StatusInTransReadonly: (hs.Status[1] & 16) > 0,
|
|
StatusInTransReadonly: (hs.Status[1] & 16) > 0,
|
|
|
SessionStateChanged: (hs.Status[1] & 32) > 0,
|
|
SessionStateChanged: (hs.Status[1] & 32) > 0,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (c *Conn) handshakePacket() (*HandshakePacket, error) {
|
|
|
|
|
|
|
+func (c *Conn) decodeHandshakePacket() error {
|
|
|
packet := HandshakePacket{}
|
|
packet := HandshakePacket{}
|
|
|
var err error
|
|
var err error
|
|
|
|
|
|
|
|
packet.PacketLength, err = c.getInt(TypeFixedInt, 3)
|
|
packet.PacketLength, err = c.getInt(TypeFixedInt, 3)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- packet.SequenceId, err = c.getInt(TypeFixedInt, 1)
|
|
|
|
|
|
|
+ packet.SequenceID, err = c.getInt(TypeFixedInt, 1)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
packet.ProtocolVersion, err = c.getInt(TypeFixedInt, 1)
|
|
packet.ProtocolVersion, err = c.getInt(TypeFixedInt, 1)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
packet.ServerVersion, err = c.getString(TypeNullTerminatedString, 0)
|
|
packet.ServerVersion, err = c.getString(TypeNullTerminatedString, 0)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- packet.ThreadId, err = c.getInt(TypeFixedInt, 4)
|
|
|
|
|
|
|
+ packet.ThreadID, err = c.getInt(TypeFixedInt, 4)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
packet.AuthPluginDataPart1, err = c.getBytes(8)
|
|
packet.AuthPluginDataPart1, err = c.getBytes(8)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
err = c.consumeBytes(1)
|
|
err = c.consumeBytes(1)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
packet.CapabilityFlags1, err = c.getBytes(2)
|
|
packet.CapabilityFlags1, err = c.getBytes(2)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
packet.Charset, err = c.getInt(TypeFixedInt, 1)
|
|
packet.Charset, err = c.getInt(TypeFixedInt, 1)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
packet.Status, err = c.getBytes(2)
|
|
packet.Status, err = c.getBytes(2)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- packet.decodeStatusFlags()
|
|
|
|
|
|
|
+ c.decodeStatusFlags(&packet)
|
|
|
|
|
|
|
|
packet.CapabilityFlags2, err = c.getBytes(2)
|
|
packet.CapabilityFlags2, err = c.getBytes(2)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- packet.decodeCapabilityFlags()
|
|
|
|
|
|
|
+ c.decodeCapabilityFlags(&packet)
|
|
|
|
|
|
|
|
packet.AuthPluginDataLength, err = c.getInt(TypeFixedInt, 1)
|
|
packet.AuthPluginDataLength, err = c.getInt(TypeFixedInt, 1)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
err = c.consumeBytes(10)
|
|
err = c.consumeBytes(10)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
packet.AuthPluginDataPart2, err = c.getBytes(packet.AuthPluginDataLength - 8)
|
|
packet.AuthPluginDataPart2, err = c.getBytes(packet.AuthPluginDataLength - 8)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
packet.AuthPluginName, err = c.getString(TypeNullTerminatedString, 0)
|
|
packet.AuthPluginName, err = c.getString(TypeNullTerminatedString, 0)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return &packet, nil
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ c.Handshake = &packet
|
|
|
|
|
|
|
|
-type HandshakeResponse struct {
|
|
|
|
|
- ClientFlag *CapabilityFlags
|
|
|
|
|
- MaxPacketSize uint64
|
|
|
|
|
- CharacterSet uint64
|
|
|
|
|
- Username string
|
|
|
|
|
- AuthResponseLength uint64
|
|
|
|
|
- AuthResponse string
|
|
|
|
|
- Database string
|
|
|
|
|
- ClientPluginName string
|
|
|
|
|
- KeyValues map[string]string
|
|
|
|
|
|
|
+ return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (hr *HandshakeResponse) encode(c *Conn) []byte {
|
|
|
|
|
|
|
+func (c *Conn) encodeHandshakeResponse() []byte {
|
|
|
|
|
+ hr := NewHandshakeResponse()
|
|
|
buf := bytes.NewBuffer(make([]byte, 0))
|
|
buf := bytes.NewBuffer(make([]byte, 0))
|
|
|
|
|
|
|
|
// Capabilities flag.
|
|
// Capabilities flag.
|
|
@@ -250,7 +253,7 @@ func (hr *HandshakeResponse) encode(c *Conn) []byte {
|
|
|
flags[0] |= 0x20
|
|
flags[0] |= 0x20
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if hr.ClientFlag.Odbc {
|
|
|
|
|
|
|
+ if hr.ClientFlag.ODBC {
|
|
|
flags[0] |= 0x40
|
|
flags[0] |= 0x40
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -270,7 +273,7 @@ func (hr *HandshakeResponse) encode(c *Conn) []byte {
|
|
|
flags[1] |= 0x4
|
|
flags[1] |= 0x4
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if hr.ClientFlag.Ssl {
|
|
|
|
|
|
|
+ if hr.ClientFlag.SSL {
|
|
|
flags[1] |= 0x8
|
|
flags[1] |= 0x8
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -282,11 +285,11 @@ func (hr *HandshakeResponse) encode(c *Conn) []byte {
|
|
|
flags[1] |= 0x20
|
|
flags[1] |= 0x20
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if hr.ClientFlag.Reserved {
|
|
|
|
|
|
|
+ if hr.ClientFlag.LegacyProtocol41 {
|
|
|
flags[1] |= 0x40
|
|
flags[1] |= 0x40
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if hr.ClientFlag.Reserved2 {
|
|
|
|
|
|
|
+ if hr.ClientFlag.SecureConnection {
|
|
|
flags[1] |= 0x80
|
|
flags[1] |= 0x80
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -298,7 +301,7 @@ func (hr *HandshakeResponse) encode(c *Conn) []byte {
|
|
|
flags[2] |= 0x2
|
|
flags[2] |= 0x2
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if hr.ClientFlag.PsMultiResults {
|
|
|
|
|
|
|
+ if hr.ClientFlag.PSMultiResults {
|
|
|
flags[2] |= 0x4
|
|
flags[2] |= 0x4
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -326,7 +329,7 @@ func (hr *HandshakeResponse) encode(c *Conn) []byte {
|
|
|
flags[3] |= 0x1
|
|
flags[3] |= 0x1
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if hr.ClientFlag.SslVerifyServerCert {
|
|
|
|
|
|
|
+ if hr.ClientFlag.SSLVerifyServerCert {
|
|
|
flags[3] |= 0x2
|
|
flags[3] |= 0x2
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -342,9 +345,7 @@ func (hr *HandshakeResponse) encode(c *Conn) []byte {
|
|
|
buf.Write(flags)
|
|
buf.Write(flags)
|
|
|
|
|
|
|
|
// Write MaxPacketSize
|
|
// Write MaxPacketSize
|
|
|
- mps := make([]byte, 4)
|
|
|
|
|
- binary.LittleEndian.PutUint32(mps, uint32(MaxPacketSize))
|
|
|
|
|
- buf.Write(mps)
|
|
|
|
|
|
|
+ //buf.Write()
|
|
|
|
|
|
|
|
// Write CharacterSet
|
|
// Write CharacterSet
|
|
|
cs := make([]byte, 2)
|
|
cs := make([]byte, 2)
|
|
@@ -358,8 +359,18 @@ func (hr *HandshakeResponse) encode(c *Conn) []byte {
|
|
|
u := append([]byte(hr.Username), NullByte)
|
|
u := append([]byte(hr.Username), NullByte)
|
|
|
buf.Write(u)
|
|
buf.Write(u)
|
|
|
|
|
|
|
|
|
|
+ salt := append(c.Handshake.AuthPluginDataPart1, c.Handshake.AuthPluginDataPart2...)
|
|
|
|
|
+ ar := c.cachingSha2Auth(salt, []byte(hr.AuthResponse))
|
|
|
if hr.ClientFlag.PluginAuthLenEncClientData {
|
|
if hr.ClientFlag.PluginAuthLenEncClientData {
|
|
|
-
|
|
|
|
|
|
|
+ buf.Write(c.encLenEncInt(uint64(len(ar))))
|
|
|
|
|
+ buf.Write(ar)
|
|
|
|
|
+ } else if hr.ClientFlag.SecureConnection {
|
|
|
|
|
+ l := make([]byte, 2)
|
|
|
|
|
+ binary.LittleEndian.PutUint16(l, uint16(len(ar)))
|
|
|
|
|
+ buf.Write(l[:1])
|
|
|
|
|
+ buf.Write(ar)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ buf.Write(append(ar, NullByte))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Write database name
|
|
// Write database name
|
|
@@ -381,7 +392,7 @@ func (hr *HandshakeResponse) encode(c *Conn) []byte {
|
|
|
return buf.Bytes()
|
|
return buf.Bytes()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (c *Conn) handshakeResponse() *HandshakeResponse {
|
|
|
|
|
|
|
+func NewHandshakeResponse() *HandshakeResponse {
|
|
|
return &HandshakeResponse{
|
|
return &HandshakeResponse{
|
|
|
ClientFlag: &CapabilityFlags{
|
|
ClientFlag: &CapabilityFlags{
|
|
|
LongPassword: true,
|
|
LongPassword: true,
|
|
@@ -389,37 +400,37 @@ func (c *Conn) handshakeResponse() *HandshakeResponse {
|
|
|
LongFlag: true,
|
|
LongFlag: true,
|
|
|
ConnectWithDb: true,
|
|
ConnectWithDb: true,
|
|
|
NoSchema: false,
|
|
NoSchema: false,
|
|
|
- Compress: true,
|
|
|
|
|
- Odbc: false,
|
|
|
|
|
|
|
+ Compress: false,
|
|
|
|
|
+ ODBC: false,
|
|
|
LocalFiles: false,
|
|
LocalFiles: false,
|
|
|
IgnoreSpace: true,
|
|
IgnoreSpace: true,
|
|
|
Protocol41: true,
|
|
Protocol41: true,
|
|
|
Interactive: true,
|
|
Interactive: true,
|
|
|
- Ssl: c.Config.SSL,
|
|
|
|
|
|
|
+ SSL: false,
|
|
|
IgnoreSigpipe: false,
|
|
IgnoreSigpipe: false,
|
|
|
Transactions: true,
|
|
Transactions: true,
|
|
|
- Reserved: false,
|
|
|
|
|
- Reserved2: false,
|
|
|
|
|
|
|
+ LegacyProtocol41: false,
|
|
|
|
|
+ SecureConnection: true,
|
|
|
MultiStatements: false,
|
|
MultiStatements: false,
|
|
|
MultiResults: false,
|
|
MultiResults: false,
|
|
|
- PsMultiResults: true,
|
|
|
|
|
- PluginAuth: true,
|
|
|
|
|
|
|
+ PSMultiResults: true,
|
|
|
|
|
+ PluginAuth: false,
|
|
|
ConnectAttrs: false,
|
|
ConnectAttrs: false,
|
|
|
- PluginAuthLenEncClientData: true,
|
|
|
|
|
|
|
+ PluginAuthLenEncClientData: false,
|
|
|
CanHandleExpiredPasswords: false,
|
|
CanHandleExpiredPasswords: false,
|
|
|
SessionTrack: true,
|
|
SessionTrack: true,
|
|
|
DeprecateEOF: true,
|
|
DeprecateEOF: true,
|
|
|
- SslVerifyServerCert: c.Config.VerifyCert,
|
|
|
|
|
|
|
+ SSLVerifyServerCert: false,
|
|
|
OptionalResultSetMetadata: true,
|
|
OptionalResultSetMetadata: true,
|
|
|
RememberOptions: true,
|
|
RememberOptions: true,
|
|
|
},
|
|
},
|
|
|
MaxPacketSize: MaxPacketSize,
|
|
MaxPacketSize: MaxPacketSize,
|
|
|
CharacterSet: 45,
|
|
CharacterSet: 45,
|
|
|
- Username: c.Config.User,
|
|
|
|
|
- AuthResponseLength: 4,
|
|
|
|
|
- AuthResponse: "root",
|
|
|
|
|
- Database: c.Config.Database,
|
|
|
|
|
- ClientPluginName: c.Handshake.AuthPluginName,
|
|
|
|
|
|
|
+ Username: "",
|
|
|
|
|
+ AuthResponseLength: 0,
|
|
|
|
|
+ AuthResponse: "",
|
|
|
|
|
+ Database: "",
|
|
|
|
|
+ ClientPluginName: "",
|
|
|
KeyValues: nil,
|
|
KeyValues: nil,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|