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

Method genAuthResponse

IceFireDB-SQLite/pkg/mysql/client/auth.go:107–131  ·  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

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