Files
zeekay ae739655bb feat: post-quantum identity + connection layer
- identity_pq.go: PQ identity primitives
- conn_pq.go: PQ-aware connection wrapping
- node_codec.go: protocol codec for PQ-aware nodes
- handshake/: PQ handshake protocol
- docs/: design notes
- coverage_*_test.go: comprehensive test suite
- go.mod: bump crypto, drop zap-proto/http (decomplected), add circl/accel
2026-06-01 13:47:19 -07:00

65 lines
2.0 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright (C) 2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package handshake
import (
"testing"
"time"
)
// TestReplayCacheTTLExpiry verifies entries past the TTL no longer
// count as seen. The two-generation design retains entries between
// ttl and 2×ttl seconds; we step past 3×ttl to guarantee the entry
// has cycled out of both `active` and `frozen`.
func TestReplayCacheTTLExpiry(t *testing.T) {
c := NewReplayCache()
cur := time.Unix(1_700_000_000, 0)
c.now = func() time.Time { return cur }
c.ttl = time.Second
c.frozenAt = cur
id := bytesToArr32(bytesPattern(0x01, IDLen))
rnd := bytesToArr16(bytesPattern(0x02, ClientRandLen))
if c.SeenOrAdd(id, rnd) {
t.Fatal("fresh entry flagged as seen")
}
if !c.SeenOrAdd(id, rnd) {
t.Fatal("immediate replay not detected")
}
// Step past ttl to trigger the first rotation (key moves from
// active to frozen but is still remembered).
cur = cur.Add(2 * time.Second)
if !c.SeenOrAdd(id, rnd) {
t.Fatal("entry within 2×ttl should still be remembered")
}
// Step past ttl AGAIN to trigger the second rotation (key drops
// out of frozen). Now the cache has fully forgotten the entry.
cur = cur.Add(2 * time.Second)
if c.SeenOrAdd(id, rnd) {
t.Fatal("expired entry still flagged after two rotations")
}
}
// TestReplayCacheTimestampWindow verifies the §11 ±30s window.
func TestReplayCacheTimestampWindow(t *testing.T) {
c := NewReplayCache()
cur := time.Unix(1_700_000_000, 0)
c.now = func() time.Time { return cur }
if err := c.CheckTimestamp(uint64(cur.UnixNano())); err != nil {
t.Fatalf("current ts refused: %v", err)
}
if err := c.CheckTimestamp(uint64(cur.Add(20 * time.Second).UnixNano())); err != nil {
t.Fatalf("+20s ts refused: %v", err)
}
if err := c.CheckTimestamp(uint64(cur.Add(31 * time.Second).UnixNano())); err == nil {
t.Fatal("+31s ts admitted")
}
if err := c.CheckTimestamp(uint64(cur.Add(-31 * time.Second).UnixNano())); err == nil {
t.Fatal("-31s ts admitted")
}
}