Constant-Time RFC 6238 Drift Windows Without Timing Leaks
Physical turnstiles and kiosk tablets rarely share sub-millisecond NTP synchronization with attendee smartphones. Instead of widening static token lifetimes and inviting screenshot forwarding, our verification engine signs short 30-to-60-second step payloads and evaluates a strict ±1 step grace window.
Every candidate signature is compared strictly via constant-time byte evaluation, ensuring attackers cannot infer partial HMAC digests across high-throughput stadium gates.
func VerifyDynamicToken(parsed *DynamicTokenPayload, venueID uuid.UUID, secretKey string, ttlSeconds int) (bool, bool) { nowUnix := time.Now().UTC().Unix() currentStep := nowUnix / int64(ttlSeconds) tokenStep := parsed.Timestamp / int64(ttlSeconds) for _, stepCandidate := range []int64{tokenStep, currentStep, currentStep - 1, currentStep + 1} { signPayload := fmt.Sprintf("%s:%s:%d", parsed.TokenID, venueID.String(), stepCandidate) expectedSig := SignHMACSHA256(signPayload, secretKey)[:16] if ConstantTimeCompareStrings(parsed.Signature, expectedSig) { isExpired := (nowUnix - parsed.Timestamp) > int64(ttlSeconds*2) return true, isExpired } } return false, false}Two-Tier Double-Spend Immunity at the Edge
When two devices scan the same optical challenge simultaneously, naive database reads create a classic time-of-check to time-of-use race condition. Before running Haversine math or enclave checks, setsig acquires a distributed atomic single-use lock at the edge.
Once verified, the session is persisted into an immutable append-only verification ledger with a strict per-workspace uniqueness guarantee, reducing replay surface to zero.
// Duplicate or concurrent scan rejected atomically at the edge// POST https://api.setsig.com/v1/sessions/verify -> 409 Conflict{ "error_code": "ERR_REPLAY_DETECTED", "message": "This token has already been consumed (replay attack detected)", "localized_message": "This token has already been consumed.", "locale": "en"}