IAM-15: timing-safe-vergleich-als-projektweite-coding-konvention (internal/timingsafe, coding-guideline, audit bestehender vergleichsstellen)

This commit is contained in:
sysops
2026-08-28 22:56:23 +02:00
parent 1b4c3db9b8
commit e46b8ed133
4 changed files with 142 additions and 2 deletions
+3 -2
View File
@@ -7,12 +7,13 @@ import (
"crypto/hmac"
"crypto/rand"
"crypto/sha1"
"crypto/subtle"
"encoding/base32"
"encoding/binary"
"fmt"
"net/url"
"time"
"gitea.perlbach24.de/scripte/nexarch/internal/timingsafe"
)
// StepSeconds ist das TOTP-Zeitfenster (RFC-6238-Standard: 30 Sekunden).
@@ -70,7 +71,7 @@ func Validate(secret, code string, t time.Time) (bool, error) {
for delta := -DefaultSkewSteps; delta <= DefaultSkewSteps; delta++ {
candidate := hotp(key, uint64(counter+int64(delta)))
if subtle.ConstantTimeCompare([]byte(candidate), []byte(code)) == 1 {
if timingsafe.EqualString(candidate, code) {
return true, nil
}
}