feat(assessment): add the review band of attempt signals and the disclosed collector
This commit is contained in:
1 parent
68286af8b7
commit
b3c6dc870b
124 files changed
+13522
-633
No files matched your search
@@ -2,9 +2,12 @@ package identity
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
)
|
||||
|
||||
func TestCandidateViewPseudonymKeyIsPurposeDerived(t *testing.T) {
|
||||
@@ -54,3 +57,69 @@ func TestCandidateViewPseudonymKeyRequiresValidKeyring(t *testing.T) {
|
||||
t.Fatal("CandidateViewPseudonymKey() accepted a nil keyring")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssessmentAnswerFingerprintIsKeyedDeterministicAndScoped(t *testing.T) {
|
||||
keyring, err := NewKeyring(bytes.Repeat([]byte{1}, MinKeySecretBytes))
|
||||
if err != nil {
|
||||
t.Fatalf("NewKeyring() error = %v", err)
|
||||
}
|
||||
other, err := NewKeyring(bytes.Repeat([]byte{2}, MinKeySecretBytes))
|
||||
if err != nil {
|
||||
t.Fatalf("NewKeyring(other) error = %v", err)
|
||||
}
|
||||
family, otherFamily := uuid.New(), uuid.New()
|
||||
answer := []byte(`{"format":"number","number":42}`)
|
||||
first := keyring.AssessmentAnswerFingerprint(family, 1, answer)
|
||||
if first.IsZero() || first != keyring.AssessmentAnswerFingerprint(family, 1, answer) {
|
||||
t.Fatal("the same family version and answer must give the same non-zero fingerprint")
|
||||
}
|
||||
for name, different := range map[string]domain.AssessmentDigest{
|
||||
"another answer": keyring.AssessmentAnswerFingerprint(family, 1, []byte(`{"format":"number","number":43}`)),
|
||||
"another family": keyring.AssessmentAnswerFingerprint(otherFamily, 1, answer),
|
||||
"another family version": keyring.AssessmentAnswerFingerprint(family, 2, answer),
|
||||
"another secret": other.AssessmentAnswerFingerprint(family, 1, answer),
|
||||
} {
|
||||
if different == first {
|
||||
t.Errorf("%s gave the same fingerprint", name)
|
||||
}
|
||||
}
|
||||
plain := sha256.Sum256(append(append(family[:], 0, 0, 0, 1), answer...))
|
||||
if first == domain.AssessmentDigest(plain) {
|
||||
t.Fatal("the fingerprint is a plain hash and can be checked without the server secret")
|
||||
}
|
||||
if keyring.AssessmentDigestKeyVersion() < 1 {
|
||||
t.Fatal("the digest key version must be positive")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssessmentSessionAndNetworkDigestsAreBoundToTheAttempt(t *testing.T) {
|
||||
keyring, err := NewKeyring(bytes.Repeat([]byte{1}, MinKeySecretBytes))
|
||||
if err != nil {
|
||||
t.Fatalf("NewKeyring() error = %v", err)
|
||||
}
|
||||
attempt, otherAttempt, session, otherSession := uuid.New(), uuid.New(), uuid.New(), uuid.New()
|
||||
sessionDigest := keyring.AssessmentSessionDigest(attempt, session)
|
||||
if sessionDigest != keyring.AssessmentSessionDigest(attempt, session) {
|
||||
t.Fatal("the session digest is not deterministic")
|
||||
}
|
||||
if sessionDigest == keyring.AssessmentSessionDigest(otherAttempt, session) {
|
||||
t.Fatal("one session has the same digest in two attempts, so attempts could be linked")
|
||||
}
|
||||
if sessionDigest == keyring.AssessmentSessionDigest(attempt, otherSession) {
|
||||
t.Fatal("two sessions of one attempt have the same digest")
|
||||
}
|
||||
networkDigest := keyring.AssessmentNetworkDigest(attempt, "198.51.100.0")
|
||||
if networkDigest != keyring.AssessmentNetworkDigest(attempt, "198.51.100.0") {
|
||||
t.Fatal("the network digest is not deterministic")
|
||||
}
|
||||
if networkDigest == keyring.AssessmentNetworkDigest(otherAttempt, "198.51.100.0") {
|
||||
t.Fatal("one network has the same digest in two attempts, so attempts could be linked")
|
||||
}
|
||||
if networkDigest == keyring.AssessmentNetworkDigest(attempt, "198.51.100.1") {
|
||||
t.Fatal("two client networks have the same digest")
|
||||
}
|
||||
// Each purpose has its own key: the same bytes under another purpose differ.
|
||||
if sessionDigest == keyring.AssessmentNetworkDigest(attempt, string(session[:])) {
|
||||
t.Fatal("session and network digests share a key")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user