app-init
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package mysqlserver
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"crypto/subtle"
|
||||
)
|
||||
|
||||
func nativePasswordToken(password string, scramble []byte) []byte {
|
||||
if password == "" {
|
||||
return []byte{}
|
||||
}
|
||||
if len(scramble) > 20 {
|
||||
scramble = scramble[:20]
|
||||
}
|
||||
hash1 := sha1.Sum([]byte(password))
|
||||
hash2 := sha1.Sum(hash1[:])
|
||||
h := sha1.New()
|
||||
h.Write(scramble)
|
||||
h.Write(hash2[:])
|
||||
hash3 := h.Sum(nil)
|
||||
out := make([]byte, 20)
|
||||
for i := 0; i < 20; i++ {
|
||||
out[i] = hash1[i] ^ hash3[i]
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func verifyNativePassword(password string, scramble, auth []byte) bool {
|
||||
if password == "" {
|
||||
return len(auth) == 0
|
||||
}
|
||||
want := nativePasswordToken(password, scramble)
|
||||
if len(auth) != len(want) {
|
||||
return false
|
||||
}
|
||||
return subtle.ConstantTimeCompare(auth, want) == 1
|
||||
}
|
||||
|
||||
func usernamesEqual(a, b string) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
return subtle.ConstantTimeCompare([]byte(a), []byte(b)) == 1
|
||||
}
|
||||
Reference in New Issue
Block a user