mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-10 11:36:06 +08:00
Use constant time (#430)
This commit is contained in:
committed by
Victor Vrantchan
parent
ee3f43d4c6
commit
b857046412
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/subtle"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
@@ -796,7 +797,7 @@ func HasCN(db *boltdepot.Depot, cn string, allowTime int, cert *x509.Certificate
|
||||
certKey := []byte(cert.Subject.CommonName + "." + cert.SerialNumber.String())
|
||||
certCandidate := bucket.Get(certKey)
|
||||
if certCandidate != nil {
|
||||
hasCN = bytes.Compare(certCandidate, cert.Raw) == 0
|
||||
hasCN = 1 == subtle.ConstantTimeCompare(certCandidate, cert.Raw)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
package password
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"crypto/sha512"
|
||||
"crypto/subtle"
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
@@ -50,7 +50,7 @@ func SaltedSHA512PBKDF2(plaintext string) (SaltedSHA512PBKDF2Dictionary, error)
|
||||
// password dictionary.
|
||||
func Verify(plaintext string, h SaltedSHA512PBKDF2Dictionary) error {
|
||||
hashed := pbkdf2.Key([]byte(plaintext), h.Salt, h.Iterations, macKeyLen, sha512.New)
|
||||
if !bytes.Equal(h.Entropy, hashed) {
|
||||
if 1 == subtle.ConstantTimeCompare(h.Entropy, hashed) {
|
||||
return ErrNoMatch
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user