feat(assessment): watermark the task text of real attempts

This commit is contained in:
shira committed 2026-10-11 10:44:30 +03:00
1 parent 24b64d698a
commit c975a0d506
57 files changed
+2429 -92

No files matched your search

@@ -33,6 +33,7 @@ const (
labelSignalSession = "lincodex/assessment/signal-session/v1"
labelSignalNetwork = "lincodex/assessment/signal-network/v1"
labelResultCursor = "lincodex/assessment/result-history-cursor/v1"
labelWatermark = "lincodex/assessment/watermark/v1"
)
// Keyring computes the keyed digests of the anonymous identity operations:
@@ -53,6 +54,7 @@ type Keyring struct {
signalSessionKey []byte
signalNetworkKey []byte
resultCursorKey []byte
watermarkKey []byte
}
// NewKeyring derives the purpose keys from secret.
@@ -73,6 +75,7 @@ func NewKeyring(secret []byte) (*Keyring, error) {
signalSessionKey: derive(secret, labelSignalSession),
signalNetworkKey: derive(secret, labelSignalNetwork),
resultCursorKey: derive(secret, labelResultCursor),
watermarkKey: derive(secret, labelWatermark),
}, nil
}
@@ -229,3 +232,13 @@ func (keyring *Keyring) AssessmentNetworkDigest(attemptID uuid.UUID, clientKey s
mac.Write([]byte(clientKey))
return domain.AssessmentDigest(mac.Sum(nil))
}
// AssessmentWatermarkSeed is the secret stream that marks the task text of one
// attempt. It is derived under a key of its own, so it cannot be computed from
// an idempotency scope or a digest, and it is never sent to a client: the
// visible code and the invisible mark are read from it on the server.
func (keyring *Keyring) AssessmentWatermarkSeed(attemptID uuid.UUID) domain.AssessmentWatermarkSeed {
mac := hmac.New(sha256.New, keyring.watermarkKey)
mac.Write(attemptID[:])
return domain.AssessmentWatermarkSeed(mac.Sum(nil))
}