chore: fix some validation issues
This commit is contained in:
@@ -30,6 +30,7 @@ func HashFileReader(r io.Reader) (string, error) {
|
||||
return base64.StdEncoding.EncodeToString(h.Sum(nil)), nil
|
||||
}
|
||||
|
||||
// we use argon2 for key hashing - since it won the key encryption "war"
|
||||
func HashKey(key string) (string, error) {
|
||||
salt := make([]byte, argonSaltLen)
|
||||
rand.Read(salt)
|
||||
@@ -46,8 +47,8 @@ func HashKey(key string) (string, error) {
|
||||
return encoded, nil
|
||||
}
|
||||
|
||||
func CompareKey(key, candidate string) bool {
|
||||
parts := strings.Split(candidate, ":")
|
||||
func CompareKey(storedKey, candidate string) bool {
|
||||
parts := strings.Split(storedKey, ":")
|
||||
if len(parts) != 3 {
|
||||
return false
|
||||
}
|
||||
@@ -65,7 +66,7 @@ func CompareKey(key, candidate string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
actual := argon2.IDKey([]byte(key), salt, argonTime, argonMemory, argonThreads, argonKeyLen)
|
||||
actual := argon2.IDKey([]byte(candidate), salt, argonTime, argonMemory, argonThreads, argonKeyLen)
|
||||
|
||||
return subtle.ConstantTimeCompare(actual, expected) == 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user