feat(sync): paginate Android sync with change tokens
Lint / Lint (push) Successful in 1m8s
Tests / Go backend (push) Failing after 1m23s
Tests / Dashboard checks (push) Failing after 38s
Docker / Docker Build & Push (push) Failing after 6m29s

This commit is contained in:
Gabriel20xx committed 2026-10-20 15:27:53 +00:00
1 parent 0ff94f9b10
commit 97c237be80
76 files changed
+3401 -851

No files matched your search

+10 -7
View File
@@ -52,19 +52,22 @@ func TOTPProvisioningURI(issuer, account, secret string) string {
return "otpauth://totp/" + url.PathEscape(label) + "?" + query.Encode()
}
// VerifyTOTP checks a six-digit token with a one-period clock-skew window.
func VerifyTOTP(secret, token string, now time.Time) bool {
// VerifyTOTP checks a six-digit token with a one-period clock-skew window and
// returns the matching time step. A caller must atomically record that step
// before accepting the code so it cannot be used twice.
func VerifyTOTP(secret, token string, now time.Time) (int64, bool) {
secret = normalizeTOTPSecret(secret)
token = normalizeTOTPToken(token)
if secret == "" || len(token) != TOTPDigits {
return false
return -1, false
}
key, err := base32.StdEncoding.WithPadding(base32.NoPadding).DecodeString(secret)
if err != nil || len(key) == 0 {
return false
return -1, false
}
period := now.Unix() / int64(TOTPPeriod/time.Second)
for offset := int64(-TOTPWindow); offset <= TOTPWindow; offset++ {
// Prefer the current step if a six-digit collision occurs in the window.
for _, offset := range [...]int64{0, -1, 1} {
if period+offset < 0 {
continue
}
@@ -80,10 +83,10 @@ func VerifyTOTP(secret, token string, now time.Time) bool {
uint32(digest[index+3])
candidate := fmt.Sprintf("%06d", value%1000000)
if subtle.ConstantTimeCompare([]byte(candidate), []byte(token)) == 1 {
return true
return period + offset, true
}
}
return false
return -1, false
}
func normalizeTOTPSecret(value string) string {