feat(assessment): record capture hints and keep one window per attempt

This commit is contained in:
shira committed 2026-10-11 13:16:52 +03:00
1 parent c975a0d506
commit bb917bf62e
108 files changed
+6649 -139

No files matched your search

@@ -34,6 +34,8 @@ const (
labelSignalNetwork = "lincodex/assessment/signal-network/v1"
labelResultCursor = "lincodex/assessment/result-history-cursor/v1"
labelWatermark = "lincodex/assessment/watermark/v1"
labelSignalAgent = "lincodex/assessment/signal-agent/v1"
labelWorkClient = "lincodex/assessment/work-client/v1"
)
// Keyring computes the keyed digests of the anonymous identity operations:
@@ -55,6 +57,8 @@ type Keyring struct {
signalNetworkKey []byte
resultCursorKey []byte
watermarkKey []byte
signalAgentKey []byte
workClientKey []byte
}
// NewKeyring derives the purpose keys from secret.
@@ -76,6 +80,8 @@ func NewKeyring(secret []byte) (*Keyring, error) {
signalNetworkKey: derive(secret, labelSignalNetwork),
resultCursorKey: derive(secret, labelResultCursor),
watermarkKey: derive(secret, labelWatermark),
signalAgentKey: derive(secret, labelSignalAgent),
workClientKey: derive(secret, labelWorkClient),
}, nil
}
@@ -242,3 +248,23 @@ func (keyring *Keyring) AssessmentWatermarkSeed(attemptID uuid.UUID) domain.Asse
mac.Write(attemptID[:])
return domain.AssessmentWatermarkSeed(mac.Sum(nil))
}
// AssessmentAgentDigest identifies the User-Agent of a request inside one
// attempt. The digest changes with the attempt, so it cannot link attempts or
// fingerprint a browser across them, and the raw value is never stored.
func (keyring *Keyring) AssessmentAgentDigest(attemptID uuid.UUID, userAgent string) domain.AssessmentDigest {
mac := hmac.New(sha256.New, keyring.signalAgentKey)
mac.Write(attemptID[:])
mac.Write([]byte(userAgent))
return domain.AssessmentDigest(mac.Sum(nil))
}
// AssessmentWorkClientDigest identifies the open page that holds the work
// session of an attempt from the identifier the page generated. The digest
// binds the attempt, so the value is not reusable and not linkable.
func (keyring *Keyring) AssessmentWorkClientDigest(attemptID uuid.UUID, clientID string) domain.AssessmentDigest {
mac := hmac.New(sha256.New, keyring.workClientKey)
mac.Write(attemptID[:])
mac.Write([]byte(clientID))
return domain.AssessmentDigest(mac.Sum(nil))
}