frank
04/22/2023, 4:00 AMBasic Auth.
with User Hashed and I was checking the validation function for check if it's timing-attack
safe.
I saw, that uses the equals(byte [] a, byte [] a2)
method to validate credentials. So I think it would be timing-attack
vulnerable.
Validate function:
public fun authenticate(credential: UserPasswordCredential): UserIdPrincipal? {
val userPasswordHash = table[credential.name]
if (userPasswordHash != null && digester(credential.password) contentEquals userPasswordHash) {
return UserIdPrincipal(credential.name)
}
return null
}
Any alternative in Ktor lib
or I'm wrong?Arjan van Wieringen
04/22/2023, 2:27 PMchiroptical
04/22/2023, 4:39 PMcontentEquals
constant time?frank
04/23/2023, 3:11 AMcontentEquals
if is constant-time.
Looking the code, I would say that in the first if
is time-attack vulnerable. I'm wrong?
@IntrinsicCandidate
public static boolean equals(byte[] a, byte[] a2) {
if (a==a2)
return true;
if (a==null || a2==null)
return false;
int length = a.length;
if (a2.length != length)
return false;
return ArraysSupport.mismatch(a, a2, length) < 0;
}
Arjan van Wieringen
04/23/2023, 7:10 AM