Skip to content

Commit 8019edf

Browse files
authored
Remove usage of subtle.ConstantTimeCompare in validation (#8519)
While constant-time comparison is important in cryptographic algorithms, that's not what we're doing here. The validation random token is not intended to be secret in the same way as (say) a private key is: it's just meant to be random enough that it's unlikely to exist in DNS or on a webserver by chance. Possession of the random token does not give an attacker any advantages; they still need to control the domain itself, at which point they could get a random token of their own. Using subtle.ConstantTimeCompare is overkill and sets a bad example for places that truly do need to use it.
1 parent a8b4a43 commit 8019edf

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

va/dns.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package va
33
import (
44
"context"
55
"crypto/sha256"
6-
"crypto/subtle"
76
"encoding/base32"
87
"encoding/base64"
98
"errors"
@@ -122,7 +121,7 @@ func (va *ValidationAuthorityImpl) validateDNS(ctx context.Context, ident identi
122121
}
123122

124123
for _, element := range txts {
125-
if subtle.ConstantTimeCompare([]byte(element), []byte(authorizedKeysDigest)) == 1 {
124+
if element == authorizedKeysDigest {
126125
// Successful challenge validation
127126
return []core.ValidationRecord{{Hostname: ident.Value, ResolverAddrs: resolvers}}, nil
128127
}

va/tlsalpn.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"context"
66
"crypto/sha256"
7-
"crypto/subtle"
87
"crypto/tls"
98
"crypto/x509"
109
"crypto/x509/pkix"
@@ -367,7 +366,7 @@ func (va *ValidationAuthorityImpl) validateTLSALPN01(ctx context.Context, ident
367366
return validationRecords, badCertErr(
368367
"Received certificate with malformed acmeValidationV1 extension value.")
369368
}
370-
if subtle.ConstantTimeCompare(h[:], extValue) != 1 {
369+
if !bytes.Equal(h[:], extValue) {
371370
return validationRecords, badCertErr(fmt.Sprintf(
372371
"Received certificate with acmeValidationV1 extension value %s but expected %s.",
373372
hex.EncodeToString(extValue),

0 commit comments

Comments
 (0)