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

Method readAuthData

IceFireDB-SQLite/pkg/mysql/server/handshake_resp.go:136–168  ·  view source on GitHub ↗
(data []byte, pos int)

Source from the content-addressed store, hash-verified

134}
135
136func (c *Conn) readAuthData(data []byte, pos int) (auth []byte, authLen int, newPos int, err error) {
137 // prevent 'panic: runtime error: index out of range' error
138 defer func() {
139 if recover() != nil {
140 err = NewDefaultError(ER_HANDSHAKE_ERROR)
141 }
142 }()
143
144 // length encoded data
145 if c.capability&CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA != 0 {
146 authData, isNULL, readBytes, err := LengthEncodedString(data[pos:])
147 if err != nil {
148 return nil, 0, 0, err
149 }
150 if isNULL {
151 // no auth length and no auth data, just \NUL, considered invalid auth data, and reject connection as MySQL does
152 return nil, 0, 0, NewDefaultError(ER_ACCESS_DENIED_ERROR, c.user, c.RemoteAddr().String(), MySQLErrName[ER_NO])
153 }
154 auth = authData
155 authLen = readBytes
156 } else if c.capability&CLIENT_SECURE_CONNECTION != 0 {
157 // auth length and auth
158 authLen = int(data[pos])
159 pos++
160 auth = data[pos : pos+authLen]
161 } else {
162 authLen = bytes.IndexByte(data[pos:], 0x00)
163 auth = data[pos : pos+authLen]
164 // account for last NUL
165 authLen++
166 }
167 return auth, authLen, pos, nil
168}
169
170// Public Key Retrieval
171// See: https://dev.mysql.com/doc/internals/en/public-key-retrieval.html

Callers 2

TestReadAuthDataFunction · 0.95
readHandshakeResponseMethod · 0.95

Calls 3

StringMethod · 0.65
NewDefaultErrorFunction · 0.50
LengthEncodedStringFunction · 0.50

Tested by 1

TestReadAuthDataFunction · 0.76