feat(identity): confirm the email address with a six-digit code from the message
This commit is contained in:
1 parent
c94434cd09
commit
d365a05c96
87 files changed
+4764
-224
No files matched your search
@@ -25,6 +25,7 @@ const (
|
||||
labelEmailBucket = "lincodex/identity/email-bucket/v1"
|
||||
labelClientBucket = "lincodex/identity/client-bucket/v1"
|
||||
labelTokenBucket = "lincodex/identity/verification-token-bucket/v1"
|
||||
labelVerificationCode = "lincodex/identity/verification-code/v1"
|
||||
labelSessionCSRF = "lincodex/identity/session-csrf/v1"
|
||||
labelCandidateView = "lincodex/identity/candidate-view/v1"
|
||||
|
||||
@@ -45,6 +46,7 @@ type Keyring struct {
|
||||
bucketKey []byte
|
||||
clientKey []byte
|
||||
tokenKey []byte
|
||||
codeKey []byte
|
||||
sessionCSRFKey []byte
|
||||
candidateViewKey []byte
|
||||
answerKey []byte
|
||||
@@ -64,6 +66,7 @@ func NewKeyring(secret []byte) (*Keyring, error) {
|
||||
bucketKey: derive(secret, labelEmailBucket),
|
||||
clientKey: derive(secret, labelClientBucket),
|
||||
tokenKey: derive(secret, labelTokenBucket),
|
||||
codeKey: derive(secret, labelVerificationCode),
|
||||
sessionCSRFKey: derive(secret, labelSessionCSRF),
|
||||
candidateViewKey: derive(secret, labelCandidateView),
|
||||
answerKey: derive(secret, labelAnswerFingerprint),
|
||||
@@ -148,6 +151,26 @@ func (keyring *Keyring) VerificationTokenBucket(rawToken string) string {
|
||||
return "identity:verification-token:" + hex.EncodeToString(mac.Sum(nil))
|
||||
}
|
||||
|
||||
// VerificationCodeDigest keys a six-digit verification code under the code
|
||||
// purpose key. The code space holds only a million values, so an unkeyed digest
|
||||
// could be reversed by enumeration; the keyed digest cannot be checked offline
|
||||
// without the server secret.
|
||||
func (keyring *Keyring) VerificationCodeDigest(code domain.VerificationCode) domain.VerificationCodeHash {
|
||||
mac := hmac.New(sha256.New, keyring.codeKey)
|
||||
mac.Write([]byte(code.Reveal()))
|
||||
return domain.VerificationCodeHash(mac.Sum(nil))
|
||||
}
|
||||
|
||||
// VerifyVerificationCode compares a supplied code with a stored digest in
|
||||
// constant time.
|
||||
func (keyring *Keyring) VerifyVerificationCode(code domain.VerificationCode, stored domain.VerificationCodeHash) bool {
|
||||
if code.IsZero() || stored.IsZero() {
|
||||
return false
|
||||
}
|
||||
computed := keyring.VerificationCodeDigest(code)
|
||||
return hmac.Equal(computed[:], stored[:])
|
||||
}
|
||||
|
||||
// SessionCSRF derives a synchronizer token for exactly one session. The
|
||||
// purpose key and message are both domain-separated from every other keyring
|
||||
// use, and only the encoded result is returned to the HTTP adapter.
|
||||
|
||||
Reference in new issue
Block a user