MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / genAuthResponse

Method genAuthResponse

IceFireDB-SQLProxy/pkg/mysql/client/auth.go:106–130  ·  view source on GitHub ↗

generate auth response data according to auth plugin NOTE: the returned boolean value indicates whether to add a \NUL to the end of data. it is quite tricky because MySQL server expects different formats of responses in different auth situations. here the \NUL needs to be added when sending back

(authData []byte)

Source from the content-addressed store, hash-verified

104// here the \NUL needs to be added when sending back the empty password or cleartext password in 'sha256_password'
105// authentication.
106func (c *Conn) genAuthResponse(authData []byte) ([]byte, bool, error) {
107 // password hashing
108 switch c.authPluginName {
109 case AUTH_NATIVE_PASSWORD:
110 return CalcPassword(authData[:20], []byte(c.password)), false, nil
111 case AUTH_CACHING_SHA2_PASSWORD:
112 return CalcCachingSha2Password(authData, c.password), false, nil
113 case AUTH_SHA256_PASSWORD:
114 if len(c.password) == 0 {
115 return nil, true, nil
116 }
117 if c.tlsConfig != nil || c.proto == "unix" {
118 // write cleartext auth packet
119 // see: https://dev.mysql.com/doc/refman/8.0/en/sha256-pluggable-authentication.html
120 return []byte(c.password), true, nil
121 } else {
122 // request public key from server
123 // see: https://dev.mysql.com/doc/internals/en/public-key-retrieval.html
124 return []byte{1}, false, nil
125 }
126 default:
127 // not reachable
128 return nil, false, fmt.Errorf("auth plugin '%s' is not supported", c.authPluginName)
129 }
130}
131
132// See: http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse
133func (c *Conn) writeAuthHandshake() error {

Callers 2

handleAuthResultMethod · 0.95
writeAuthHandshakeMethod · 0.95

Calls 2

CalcPasswordFunction · 0.50
CalcCachingSha2PasswordFunction · 0.50

Tested by

no test coverage detected