Skip to content

Commit ed044a3

Browse files
committed
Compare HMACs in constant time to mitigate timing attack
1 parent 8888a49 commit ed044a3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

go/channelling/server/users.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"crypto/hmac"
2727
"crypto/rand"
2828
"crypto/sha256"
29+
"crypto/subtle"
2930
"crypto/tls"
3031
"crypto/x509"
3132
"crypto/x509/pkix"
@@ -95,7 +96,7 @@ func (uh *UsersSharedsecretHandler) Validate(snr *SessionNonceRequest, request *
9596
}
9697

9798
secret := uh.createHMAC(snr.UseridCombo)
98-
if snr.Secret != secret {
99+
if subtle.ConstantTimeCompare([]byte(snr.Secret), []byte(secret)) != 1 {
99100
return "", errors.New("invalid secret")
100101
}
101102

0 commit comments

Comments
 (0)