Browse Source

Compare HMACs in constant time to mitigate timing attack

pull/309/head
Leon Klingele 9 years ago
parent
commit
ed044a3d8b
  1. 3
      go/channelling/server/users.go

3
go/channelling/server/users.go

@ -26,6 +26,7 @@ import ( @@ -26,6 +26,7 @@ import (
"crypto/hmac"
"crypto/rand"
"crypto/sha256"
"crypto/subtle"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
@ -95,7 +96,7 @@ func (uh *UsersSharedsecretHandler) Validate(snr *SessionNonceRequest, request * @@ -95,7 +96,7 @@ func (uh *UsersSharedsecretHandler) Validate(snr *SessionNonceRequest, request *
}
secret := uh.createHMAC(snr.UseridCombo)
if snr.Secret != secret {
if subtle.ConstantTimeCompare([]byte(snr.Secret), []byte(secret)) != 1 {
return "", errors.New("invalid secret")
}

Loading…
Cancel
Save