strix-verify 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- strix_verify-0.3.0/CHANGELOG.md +95 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/PKG-INFO +3 -3
- {strix_verify-0.2.0 → strix_verify-0.3.0}/pyproject.toml +2 -2
- {strix_verify-0.2.0 → strix_verify-0.3.0}/src/strix_verify/__init__.py +57 -11
- {strix_verify-0.2.0 → strix_verify-0.3.0}/src/strix_verify/jwks.py +8 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/src/strix_verify/models.py +20 -2
- {strix_verify-0.2.0 → strix_verify-0.3.0}/src/strix_verify/payload.py +42 -1
- strix_verify-0.3.0/tests/test_compliance_mode_null.py +50 -0
- strix_verify-0.3.0/tests/test_declaration_refusals.py +87 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/tests/test_verify.py +92 -19
- strix_verify-0.2.0/.coverage.claude.pid24539.XY1Ytvgx.H88aIe1rrr5h +0 -0
- strix_verify-0.2.0/CHANGELOG.md +0 -51
- {strix_verify-0.2.0 → strix_verify-0.3.0}/.gitignore +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/PARITY-BACKLOG.md +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/README.md +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/RELEASING.md +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/SCOPE.md +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/src/strix_verify/client.py +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/src/strix_verify/compliance.py +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/src/strix_verify/hashing.py +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/src/strix_verify/signature.py +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/tests/conftest.py +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/tests/test_compliance.py +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/tests/test_conformance_vectors.py +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/tests/test_hashing.py +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/tests/test_jwks.py +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/tests/test_payload.py +0 -0
- {strix_verify-0.2.0 → strix_verify-0.3.0}/tests/test_signature.py +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `strix-verify` are documented here. This project
|
|
4
|
+
follows semantic versioning (pre-1.0: minor bumps may add functionality or
|
|
5
|
+
fix correctness issues that change verification outcomes).
|
|
6
|
+
|
|
7
|
+
## [0.3.0] — 2026-11-11 (unreleased)
|
|
8
|
+
|
|
9
|
+
### Added — algorithm and schema-version declaration refusals (#2835, #2836)
|
|
10
|
+
|
|
11
|
+
`verify_evidence_record` now refuses, before any key lookup or signature check:
|
|
12
|
+
|
|
13
|
+
- an explicit `signatureAlgorithm` other than exactly `"Ed25519"` (case-sensitive)
|
|
14
|
+
→ `SignatureStatus.UNSUPPORTED_ALGORITHM`;
|
|
15
|
+
- an explicit `declaredSchemaVersion`, or a record-level `schemaVersion` on the
|
|
16
|
+
reconstruction path, other than `1` / `"1"` → `SignatureStatus.UNSUPPORTED_SCHEMA_VERSION`.
|
|
17
|
+
`"1.0"`, `"v1"`, `2`, booleans and objects are refused; nothing is normalized into 1.
|
|
18
|
+
|
|
19
|
+
A refused record is never VERIFIED and never reported as a signature failure. An
|
|
20
|
+
absent declaration is the legacy case and is read under the fixed Ed25519 rule.
|
|
21
|
+
The two new enum members are additive; a caller that switches exhaustively on
|
|
22
|
+
`SignatureStatus` must handle them. Contract: `docs/gates/SE-V1-ALGORITHM-METADATA.md`.
|
|
23
|
+
New `declaration_refusal(record)` helper is exported. Tests run every vector in
|
|
24
|
+
`conformance/corpus/se_v1` (`tests/test_declaration_refusals.py`).
|
|
25
|
+
|
|
26
|
+
### Fixed — explicit `tenantId: null` was rewritten to `""` (correctness)
|
|
27
|
+
|
|
28
|
+
Single-tenant Academy records are signed with `"tenantId":null`. The payload
|
|
29
|
+
builder coerced it to `""`, so those records failed signature verification here
|
|
30
|
+
while the JS reference verified them (corpus vector `se1-pos-04`). Only a missing
|
|
31
|
+
key now collapses to `""`, matching the JS reference.
|
|
32
|
+
|
|
33
|
+
## [0.2.1] — 2026-06-05
|
|
34
|
+
|
|
35
|
+
### Fixed — `complianceMode: null` records crashed the parser (correctness)
|
|
36
|
+
|
|
37
|
+
`RegulatoryContext.complianceMode` was typed as a required `str`. Real records
|
|
38
|
+
carry an explicit JSON `null` there — including production record **5686** — so
|
|
39
|
+
the pydantic model raised `Input should be a valid string (input_value=None)` at
|
|
40
|
+
parse time, **before** any signature check ran. `strix verify 5686` therefore
|
|
41
|
+
errored out instead of verifying.
|
|
42
|
+
|
|
43
|
+
`complianceMode` now accepts `str | None` and round-trips a present-but-null
|
|
44
|
+
value back as JSON `null`, matching the JS reference verifier
|
|
45
|
+
(`@strixgov/verifier`'s `buildCanonicalPayload`). Coercing `null → ""` would have
|
|
46
|
+
changed the canonical bytes and broken the signature, so this is a
|
|
47
|
+
**verifier-tolerance fix, not a schema change**: the bytes for a string
|
|
48
|
+
`complianceMode` are unchanged, and the `""` default still applies only when the
|
|
49
|
+
key is absent. Regression test added (`tests/test_compliance_mode_null.py`).
|
|
50
|
+
|
|
51
|
+
## [0.2.0] — 2026-05-31
|
|
52
|
+
|
|
53
|
+
### Fixed — Academy-form record verification (correctness)
|
|
54
|
+
|
|
55
|
+
`build_canonical_payload` previously reconstructed **only** the Console
|
|
56
|
+
canonical form (string `schemaVersion`/`evidenceId`, `complianceMode`-first
|
|
57
|
+
`regulatoryContext`). It therefore could **not** verify records signed in the
|
|
58
|
+
Academy form — approximately 4,450 historical Academy records — and would have
|
|
59
|
+
reported them as signature failures.
|
|
60
|
+
|
|
61
|
+
This release adds the SE v1 **dual-form discriminator**, matching the JS
|
|
62
|
+
reference verifier (`@strixgov/verifier`):
|
|
63
|
+
|
|
64
|
+
- Records with `sourceApp == "academy-platform"` now serialize `schemaVersion`
|
|
65
|
+
and `evidenceId` as JSON **numbers**, with a `euAiActArticle12`-first
|
|
66
|
+
`regulatoryContext`.
|
|
67
|
+
- Console records are unchanged (JSON strings, `complianceMode`-first).
|
|
68
|
+
- Added the `signedPayload` reconstruction-free passthrough (v1.10.0): when a
|
|
69
|
+
record carries the original signed bytes, they are returned verbatim.
|
|
70
|
+
- Canonical output now uses `ensure_ascii=False` for byte-parity with the JS
|
|
71
|
+
reference on non-ASCII fields.
|
|
72
|
+
|
|
73
|
+
The Console path is byte-for-byte unchanged (the prior golden-vector test
|
|
74
|
+
remains the canary and still passes).
|
|
75
|
+
|
|
76
|
+
### Added — cross-language conformance
|
|
77
|
+
|
|
78
|
+
This verifier is now pinned to the JS reference against a shared,
|
|
79
|
+
language-neutral fixture
|
|
80
|
+
(`packages/strixgov-verifier/test/fixtures/se-v1-conformance-vectors.json`).
|
|
81
|
+
Both implementations read the same fixture and must agree byte-for-byte; a CI
|
|
82
|
+
lane (`SE v1 Cross-Language Conformance`) enforces this on Python 3.10–3.12 and
|
|
83
|
+
Node 20–24. See `tests/test_conformance_vectors.py`.
|
|
84
|
+
|
|
85
|
+
### Notes
|
|
86
|
+
|
|
87
|
+
- No new dependencies. No API changes to `verify_evidence` / `verify_evidence_record`.
|
|
88
|
+
- The golden vectors were not modified; the implementation was corrected to
|
|
89
|
+
match them.
|
|
90
|
+
|
|
91
|
+
## [0.1.0]
|
|
92
|
+
|
|
93
|
+
Initial release. Independent SE v1 verification (Ed25519 + SHA-256), JWKS
|
|
94
|
+
resolution, two-layer verification model, EU AI Act compliance-flag derivation.
|
|
95
|
+
Console canonical form only.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: strix-verify
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Independent verification of Strix governance evidence records. Ed25519 + SHA-256 only. No Strix tooling or account required. Public source at github.com/strixgov/strix.
|
|
5
5
|
Project-URL: Homepage, https://strixgov.com
|
|
6
6
|
Project-URL: Repository, https://github.com/strixgov/strix
|
|
7
|
-
Project-URL: Documentation, https://strixgov.com/docs
|
|
7
|
+
Project-URL: Documentation, https://www.strixgov.com/docs
|
|
8
8
|
Author: Strix Platform Team
|
|
9
9
|
License: MIT
|
|
10
10
|
Keywords: ai-safety,ed25519,evidence,governance,proof,strix,verification
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "strix-verify"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
description = "Independent verification of Strix governance evidence records. Ed25519 + SHA-256 only. No Strix tooling or account required. Public source at github.com/strixgov/strix."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "MIT" }
|
|
@@ -42,7 +42,7 @@ dev = [
|
|
|
42
42
|
[project.urls]
|
|
43
43
|
Homepage = "https://strixgov.com"
|
|
44
44
|
Repository = "https://github.com/strixgov/strix"
|
|
45
|
-
Documentation = "https://strixgov.com/docs
|
|
45
|
+
Documentation = "https://www.strixgov.com/docs"
|
|
46
46
|
|
|
47
47
|
[tool.hatch.build.targets.wheel]
|
|
48
48
|
packages = ["src/strix_verify"]
|
|
@@ -43,10 +43,10 @@ from .compliance import derive_compliance_flags
|
|
|
43
43
|
from .hashing import verify_hash
|
|
44
44
|
from .jwks import DEFAULT_JWKS_BASE, JWKSFetchError, KeyNotFoundError, resolve_key
|
|
45
45
|
from .models import CanonicalPayload, SignatureStatus, VerificationResult
|
|
46
|
-
from .payload import build_canonical_payload
|
|
46
|
+
from .payload import build_canonical_payload, declaration_refusal
|
|
47
47
|
from .signature import verify_signature
|
|
48
48
|
|
|
49
|
-
__version__ = "0.
|
|
49
|
+
__version__ = "0.3.0"
|
|
50
50
|
__all__ = [
|
|
51
51
|
"verify_evidence",
|
|
52
52
|
"verify_evidence_record",
|
|
@@ -54,6 +54,7 @@ __all__ = [
|
|
|
54
54
|
"SignatureStatus",
|
|
55
55
|
"CanonicalPayload",
|
|
56
56
|
"build_canonical_payload",
|
|
57
|
+
"declaration_refusal",
|
|
57
58
|
"verify_signature",
|
|
58
59
|
"verify_hash",
|
|
59
60
|
"resolve_key",
|
|
@@ -145,13 +146,33 @@ def verify_evidence_record(
|
|
|
145
146
|
result.signing_key_id = signing_key_id
|
|
146
147
|
|
|
147
148
|
if not signature or not signing_key_id:
|
|
148
|
-
# Legacy unsigned record
|
|
149
|
+
# Legacy unsigned record. With no signature there is nothing to
|
|
150
|
+
# authenticate evidenceHash (it is producer-computed over decision
|
|
151
|
+
# content, not recomputable from the envelope — see Step 5), so
|
|
152
|
+
# hash_valid is False. Mirrors the JS reference hashValid = signatureValid
|
|
153
|
+
# (signatureValid is false here). We do NOT recompute sha256(envelope);
|
|
154
|
+
# that comparison can never hold by design.
|
|
149
155
|
result.signature_valid = SignatureStatus.LEGACY_UNSIGNED
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
result.hash_valid = False
|
|
157
|
+
result.compliance = derive_compliance_flags(
|
|
158
|
+
result.signature_valid, result.hash_valid,
|
|
159
|
+
result.chain_valid, result.signature_present,
|
|
160
|
+
)
|
|
161
|
+
return result
|
|
162
|
+
|
|
163
|
+
# Step 1b — Declaration refusals (#2835 / #2836). Decided BEFORE any key
|
|
164
|
+
# lookup or signature work: a record declaring an unsupported algorithm or
|
|
165
|
+
# schema version is never VERIFIED and never counted as a signature
|
|
166
|
+
# failure. Contract: docs/gates/SE-V1-ALGORITHM-METADATA.md.
|
|
167
|
+
refusal = declaration_refusal(record)
|
|
168
|
+
if refusal is not None:
|
|
169
|
+
result.signature_valid = SignatureStatus(refusal)
|
|
170
|
+
result.hash_valid = False
|
|
171
|
+
result.error = (
|
|
172
|
+
f"Declared signatureAlgorithm {record.get('signatureAlgorithm')!r} is not exactly 'Ed25519'."
|
|
173
|
+
if refusal == "UNSUPPORTED_ALGORITHM"
|
|
174
|
+
else "Declared schema version is not 1."
|
|
175
|
+
)
|
|
155
176
|
result.compliance = derive_compliance_flags(
|
|
156
177
|
result.signature_valid, result.hash_valid,
|
|
157
178
|
result.chain_valid, result.signature_present,
|
|
@@ -173,6 +194,21 @@ def verify_evidence_record(
|
|
|
173
194
|
result.signature_valid = SignatureStatus.ERROR
|
|
174
195
|
result.error = str(e)
|
|
175
196
|
return result
|
|
197
|
+
except ValueError as e:
|
|
198
|
+
# decode_jwk_to_public_key (via resolve_key) raises ValueError when a
|
|
199
|
+
# kid resolves to a JWK of the wrong key type/curve (e.g. an RSA key
|
|
200
|
+
# under a kid the record expects to be Ed25519). This is the "wrong
|
|
201
|
+
# signature algorithm" case, not "key not found" — but it is still
|
|
202
|
+
# honestly UNVERIFIABLE (we cannot verify with this key), never a
|
|
203
|
+
# crash. Mirrors the Node reference (packages/strixgov-verifier)
|
|
204
|
+
# UNSUPPORTED_ALGORITHM classification.
|
|
205
|
+
result.signature_valid = SignatureStatus.UNVERIFIABLE_KEY
|
|
206
|
+
result.error = str(e)
|
|
207
|
+
result.compliance = derive_compliance_flags(
|
|
208
|
+
result.signature_valid, result.hash_valid,
|
|
209
|
+
result.chain_valid, result.signature_present,
|
|
210
|
+
)
|
|
211
|
+
return result
|
|
176
212
|
|
|
177
213
|
# Step 3 — Reconstruct canonical payload
|
|
178
214
|
canonical = build_canonical_payload(record)
|
|
@@ -182,9 +218,19 @@ def verify_evidence_record(
|
|
|
182
218
|
sig_ok = verify_signature(canonical_json, signature, public_key)
|
|
183
219
|
result.signature_valid = SignatureStatus.VERIFIED if sig_ok else SignatureStatus.COMPLIANCE_VIOLATION
|
|
184
220
|
|
|
185
|
-
# Step 5 —
|
|
186
|
-
|
|
187
|
-
|
|
221
|
+
# Step 5 — Hash validity = signature validity.
|
|
222
|
+
# evidenceHash is the producer's hash of the underlying governance decision
|
|
223
|
+
# CONTENT (e.g. Academy's 8-field computeEvidenceHash; Console's
|
|
224
|
+
# sha256(canonicalize(decision content))). It is a field INSIDE the signed
|
|
225
|
+
# 13-field canonical, authenticated by the Ed25519 signature — it is NOT
|
|
226
|
+
# sha256(canonical_envelope) and a verifier cannot independently recompute
|
|
227
|
+
# it without the producer's content preimage. The canonical JS reference is
|
|
228
|
+
# explicit: "SHA-256(signing_envelope) !== evidenceHash by design; the
|
|
229
|
+
# signature check is the sole integrity gate" (packages/strixgov-verifier/
|
|
230
|
+
# src/index.mjs:472-477 → result.hashValid = result.signatureValid). A
|
|
231
|
+
# tampered evidenceHash changes the signed bytes and flips the signature to
|
|
232
|
+
# invalid, which correctly drops this to False. (strix verify 5686, 2026-06.)
|
|
233
|
+
result.hash_valid = sig_ok
|
|
188
234
|
|
|
189
235
|
# Step 6 — Layer 2: Deployment context checks (SE-14: from stored fields only)
|
|
190
236
|
if expected_environment is not None:
|
|
@@ -84,6 +84,14 @@ def resolve_key(
|
|
|
84
84
|
Raises:
|
|
85
85
|
KeyNotFoundError: If the key is not found in JWKS or extra_keys.
|
|
86
86
|
JWKSFetchError: If the JWKS endpoint cannot be reached.
|
|
87
|
+
ValueError: If the kid resolves to a JWK of the wrong key type/curve
|
|
88
|
+
(e.g. an RSA or EC key under a kid the record expects to be
|
|
89
|
+
Ed25519). Raised by decode_jwk_to_public_key on the final line —
|
|
90
|
+
this function selects by kid FIRST and validates the key material
|
|
91
|
+
SECOND, so a wrong-algorithm JWK under a legitimate kid reaches the
|
|
92
|
+
decoder. Callers MUST handle this: verify_evidence_record's original
|
|
93
|
+
crash (fixed 2026-08-04) came from handling exactly the two
|
|
94
|
+
exceptions documented above and no more.
|
|
87
95
|
"""
|
|
88
96
|
url = f"{jwks_base.rstrip('/')}/.well-known/strix-jwks.json?kid={kid}"
|
|
89
97
|
try:
|
|
@@ -61,13 +61,29 @@ class SignatureStatus(str, Enum):
|
|
|
61
61
|
ERROR = "ERROR"
|
|
62
62
|
"""Verification could not complete due to a network or parsing error."""
|
|
63
63
|
|
|
64
|
+
UNSUPPORTED_ALGORITHM = "UNSUPPORTED_ALGORITHM"
|
|
65
|
+
"""The record declares a signatureAlgorithm other than exactly "Ed25519".
|
|
66
|
+
Refused before key lookup; not a signature failure (issue #2835)."""
|
|
67
|
+
|
|
68
|
+
UNSUPPORTED_SCHEMA_VERSION = "UNSUPPORTED_SCHEMA_VERSION"
|
|
69
|
+
"""The record declares a schema version other than 1 / "1".
|
|
70
|
+
Refused before key lookup; not a signature failure (issue #2836)."""
|
|
71
|
+
|
|
64
72
|
|
|
65
73
|
# ── Regulatory Context ─────────────────────────────────────────────────────────
|
|
66
74
|
|
|
67
75
|
class RegulatoryContext(BaseModel):
|
|
68
76
|
"""EU AI Act compliance flags — always derived, never asserted."""
|
|
69
77
|
|
|
70
|
-
|
|
78
|
+
# complianceMode can be an explicit JSON null on real records (e.g. prod
|
|
79
|
+
# record 5686). The JS reference (buildCanonicalPayload) preserves a
|
|
80
|
+
# present-but-null complianceMode and serializes it back as `null`, so the
|
|
81
|
+
# model MUST accept None and round-trip it — coercing null→"" would change
|
|
82
|
+
# the canonical bytes and break the signature. The "" default applies only
|
|
83
|
+
# when the key is absent (payload.py passes "" in that case). Accepting None
|
|
84
|
+
# is a verifier-tolerance fix, not a schema change: the bytes for a string
|
|
85
|
+
# complianceMode are unchanged. (strix verify 5686 incident, 2026-06.)
|
|
86
|
+
compliance_mode: str | None = Field(default="", alias="complianceMode")
|
|
71
87
|
eu_ai_act_article12: bool = Field(default=False, alias="euAiActArticle12")
|
|
72
88
|
eu_ai_act_article14: bool = Field(default=False, alias="euAiActArticle14")
|
|
73
89
|
eu_ai_act_article28: bool = Field(default=False, alias="euAiActArticle28")
|
|
@@ -96,7 +112,9 @@ class CanonicalPayload(BaseModel):
|
|
|
96
112
|
created_at: str = Field(alias="createdAt")
|
|
97
113
|
signing_key_id: str = Field(alias="signingKeyId")
|
|
98
114
|
environment: str
|
|
99
|
-
|
|
115
|
+
# str | None: an explicit JSON null is part of the signed bytes for
|
|
116
|
+
# single-tenant Academy records (corpus vector se1-pos-04).
|
|
117
|
+
tenant_id: str | None = Field(alias="tenantId")
|
|
100
118
|
regulatory_context: RegulatoryContext = Field(alias="regulatoryContext")
|
|
101
119
|
|
|
102
120
|
# Dual-form discriminator (v1.3) — mirrors buildCanonicalPayload in
|
|
@@ -67,8 +67,49 @@ def build_canonical_payload(record: dict[str, Any]) -> CanonicalPayload:
|
|
|
67
67
|
createdAt=record.get("createdAt") or "",
|
|
68
68
|
signingKeyId=record.get("signingKeyId") or "",
|
|
69
69
|
environment=record.get("environment") or "",
|
|
70
|
-
|
|
70
|
+
# Mirror the JS reference `record.tenantId === undefined ? "" : record.tenantId`:
|
|
71
|
+
# only a MISSING key collapses to ""; an explicit JSON null is preserved.
|
|
72
|
+
# Academy single-tenant records were signed with tenantId:null, and
|
|
73
|
+
# {"tenantId":""} is different bytes (corpus vector se1-pos-04).
|
|
74
|
+
tenantId="" if "tenantId" not in record else record["tenantId"],
|
|
71
75
|
regulatoryContext=regulatory_context,
|
|
72
76
|
is_academy_form=is_academy,
|
|
73
77
|
signed_payload=signed_payload,
|
|
74
78
|
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _is_schema_v1(value: Any) -> bool:
|
|
82
|
+
"""Exactly 1 / "1". bool is excluded explicitly (in Python True == 1). A
|
|
83
|
+
JSON 1.0 is the number 1 in JS, so it is accepted too. Nothing else is
|
|
84
|
+
normalized into 1: "1.0", "v1", " 1", 2, "2", objects are all refused."""
|
|
85
|
+
if isinstance(value, bool):
|
|
86
|
+
return False
|
|
87
|
+
if isinstance(value, (int, float)):
|
|
88
|
+
return value == 1
|
|
89
|
+
return value == "1"
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def declaration_refusal(record: dict[str, Any]) -> str | None:
|
|
93
|
+
"""
|
|
94
|
+
Return "UNSUPPORTED_SCHEMA_VERSION", "UNSUPPORTED_ALGORITHM", or None.
|
|
95
|
+
|
|
96
|
+
Issues #2835 / #2836; contract docs/gates/SE-V1-ALGORITHM-METADATA.md.
|
|
97
|
+
Schema version is checked first, then algorithm, both before any key
|
|
98
|
+
lookup. `declaredSchemaVersion` is always checked; the record-level
|
|
99
|
+
`schemaVersion` only on the reconstruction path, because when the signed
|
|
100
|
+
bytes travel as `signedPayload` that field is an unsigned projection of
|
|
101
|
+
them. An absent/null `signatureAlgorithm` is the legacy case, read under
|
|
102
|
+
the fixed Ed25519 rule.
|
|
103
|
+
"""
|
|
104
|
+
signed_payload = record.get("signedPayload")
|
|
105
|
+
has_signed_bytes = isinstance(signed_payload, str) and len(signed_payload) > 0
|
|
106
|
+
declarations = [record.get("declaredSchemaVersion")]
|
|
107
|
+
if not has_signed_bytes:
|
|
108
|
+
declarations.append(record.get("schemaVersion"))
|
|
109
|
+
for declared in declarations:
|
|
110
|
+
if declared is not None and not _is_schema_v1(declared):
|
|
111
|
+
return "UNSUPPORTED_SCHEMA_VERSION"
|
|
112
|
+
algorithm = record.get("signatureAlgorithm")
|
|
113
|
+
if algorithm is not None and algorithm != "Ed25519":
|
|
114
|
+
return "UNSUPPORTED_ALGORITHM"
|
|
115
|
+
return None
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Regression: prod record 5686 carries regulatoryContext.complianceMode = null.
|
|
2
|
+
|
|
3
|
+
The pydantic RegulatoryContext model typed complianceMode as a required str, so
|
|
4
|
+
the verification pipeline CRASHED at parse time ("Input should be a valid string,
|
|
5
|
+
input_value=None") before any signature check. The JS reference preserves a
|
|
6
|
+
present-but-null complianceMode and serializes it back as JSON `null`, so the
|
|
7
|
+
Python model must accept None and round-trip it (coercing null→"" would change
|
|
8
|
+
the canonical bytes and break the signature).
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from strix_verify.models import RegulatoryContext, CanonicalPayload
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _payload(rc: RegulatoryContext) -> CanonicalPayload:
|
|
15
|
+
return CanonicalPayload(
|
|
16
|
+
schemaVersion="1",
|
|
17
|
+
evidenceId="5686",
|
|
18
|
+
evidenceHash="e" * 64,
|
|
19
|
+
proofChainHash="p" * 64,
|
|
20
|
+
capabilityId="admin.updateMemberRole",
|
|
21
|
+
action="allow",
|
|
22
|
+
actorId="u",
|
|
23
|
+
actorRole="owner",
|
|
24
|
+
createdAt="2026-05-26T00:00:00.000Z",
|
|
25
|
+
signingKeyId="strix-prod-2026-05",
|
|
26
|
+
environment="production",
|
|
27
|
+
tenantId="academy prod",
|
|
28
|
+
regulatoryContext=rc,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_compliance_mode_null_parses_without_crash():
|
|
33
|
+
rc = RegulatoryContext(complianceMode=None)
|
|
34
|
+
assert rc.compliance_mode is None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_compliance_mode_null_reconstructs_as_json_null():
|
|
38
|
+
canon = _payload(RegulatoryContext(complianceMode=None)).to_canonical_json()
|
|
39
|
+
assert '"complianceMode":null' in canon
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_compliance_mode_string_is_byte_unchanged():
|
|
43
|
+
canon = _payload(RegulatoryContext(complianceMode="eu-ai-act")).to_canonical_json()
|
|
44
|
+
assert '"complianceMode":"eu-ai-act"' in canon
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_compliance_mode_absent_defaults_to_empty_string():
|
|
48
|
+
# Absent key (not explicit null) keeps the historical "" default.
|
|
49
|
+
rc = RegulatoryContext()
|
|
50
|
+
assert rc.compliance_mode == ""
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Declaration refusals (issues #2835 / #2836) against the shared SE v1 corpus.
|
|
3
|
+
|
|
4
|
+
Every vector in conformance/corpus/se_v1 is run through verify_evidence_record
|
|
5
|
+
with key resolution patched to the vector's own public key. A refusal vector
|
|
6
|
+
must report its exact refusal status, decided BEFORE key lookup (proved by a
|
|
7
|
+
resolver that raises if it is ever called). Contract:
|
|
8
|
+
docs/gates/SE-V1-ALGORITHM-METADATA.md.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from unittest.mock import patch
|
|
14
|
+
|
|
15
|
+
import pytest
|
|
16
|
+
|
|
17
|
+
from strix_verify import declaration_refusal, verify_evidence_record
|
|
18
|
+
from strix_verify.models import SignatureStatus
|
|
19
|
+
from strix_verify.signature import decode_jwk_to_public_key
|
|
20
|
+
|
|
21
|
+
_REPO_ROOT = Path(__file__).resolve().parents[3]
|
|
22
|
+
_CORPUS = _REPO_ROOT / "conformance" / "corpus" / "se_v1"
|
|
23
|
+
|
|
24
|
+
_STATUS = {
|
|
25
|
+
"VERIFIED": SignatureStatus.VERIFIED,
|
|
26
|
+
"SIGNATURE_INVALID": SignatureStatus.COMPLIANCE_VIOLATION,
|
|
27
|
+
"UNSUPPORTED_ALGORITHM": SignatureStatus.UNSUPPORTED_ALGORITHM,
|
|
28
|
+
"UNSUPPORTED_SCHEMA_VERSION": SignatureStatus.UNSUPPORTED_SCHEMA_VERSION,
|
|
29
|
+
}
|
|
30
|
+
_REFUSALS = {"UNSUPPORTED_ALGORITHM", "UNSUPPORTED_SCHEMA_VERSION"}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _vectors():
|
|
34
|
+
index = json.loads((_CORPUS / "index.json").read_text(encoding="utf-8"))
|
|
35
|
+
out = []
|
|
36
|
+
for entry in index["vectors"]:
|
|
37
|
+
v = json.loads((_CORPUS / entry["relative_path"]).read_text(encoding="utf-8"))
|
|
38
|
+
out.append(pytest.param(v, id=entry["vector_id"]))
|
|
39
|
+
return out
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_corpus_has_refusal_vectors():
|
|
43
|
+
statuses = {p.values[0]["expected"]["status"] for p in _vectors()}
|
|
44
|
+
assert _REFUSALS <= statuses
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@pytest.mark.parametrize("vector", _vectors())
|
|
48
|
+
def test_corpus_vector_status(vector):
|
|
49
|
+
record = dict(vector["record"], signature=vector["verification_inputs"]["signature_b64url"])
|
|
50
|
+
jwk = vector["verification_inputs"]["jwks"]["keys"][0]
|
|
51
|
+
expected = vector["expected"]["status"]
|
|
52
|
+
if expected in _REFUSALS:
|
|
53
|
+
resolver = patch("strix_verify.resolve_key", side_effect=AssertionError("key lookup reached"))
|
|
54
|
+
else:
|
|
55
|
+
resolver = patch("strix_verify.resolve_key", return_value=decode_jwk_to_public_key(jwk))
|
|
56
|
+
with resolver:
|
|
57
|
+
result = verify_evidence_record(record)
|
|
58
|
+
assert result.signature_valid == _STATUS[expected]
|
|
59
|
+
assert result.verified is (expected == "VERIFIED")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@pytest.mark.parametrize("alg", ["RS256", "ed25519", "", 25519, "Ed25519 "])
|
|
63
|
+
def test_algorithm_refused(alg):
|
|
64
|
+
assert declaration_refusal({"signatureAlgorithm": alg}) == "UNSUPPORTED_ALGORITHM"
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@pytest.mark.parametrize("ver", ["1.0", "v1", " 1", 2, "2", True, {"v": 1}])
|
|
68
|
+
def test_declared_schema_version_refused(ver):
|
|
69
|
+
assert declaration_refusal({"declaredSchemaVersion": ver}) == "UNSUPPORTED_SCHEMA_VERSION"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_accepted_declarations():
|
|
73
|
+
assert declaration_refusal({}) is None
|
|
74
|
+
assert declaration_refusal({"signatureAlgorithm": "Ed25519", "declaredSchemaVersion": "1",
|
|
75
|
+
"schemaVersion": "1"}) is None
|
|
76
|
+
assert declaration_refusal({"schemaVersion": 1}) is None # Academy numeric form
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_schema_refusal_precedes_algorithm():
|
|
80
|
+
assert declaration_refusal({"schemaVersion": "2", "signatureAlgorithm": "RS256"}) == \
|
|
81
|
+
"UNSUPPORTED_SCHEMA_VERSION"
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_record_schema_version_ignored_when_signed_bytes_present():
|
|
85
|
+
assert declaration_refusal({"schemaVersion": "2", "signedPayload": "{}"}) is None
|
|
86
|
+
assert declaration_refusal({"declaredSchemaVersion": "2", "signedPayload": "{}"}) == \
|
|
87
|
+
"UNSUPPORTED_SCHEMA_VERSION"
|
|
@@ -20,7 +20,6 @@ Covers:
|
|
|
20
20
|
- Error propagation from JWKS fetch failure
|
|
21
21
|
"""
|
|
22
22
|
|
|
23
|
-
import pytest
|
|
24
23
|
from unittest.mock import patch
|
|
25
24
|
|
|
26
25
|
from strix_verify import verify_evidence_record
|
|
@@ -106,6 +105,23 @@ def test_jwks_fetch_error_produces_error_status(signed_record):
|
|
|
106
105
|
assert result.error is not None
|
|
107
106
|
|
|
108
107
|
|
|
108
|
+
def test_wrong_key_algorithm_produces_unverifiable_status(signed_record):
|
|
109
|
+
"""A kid resolving to a non-Ed25519 JWK (e.g. RSA) must not crash the
|
|
110
|
+
caller — decode_jwk_to_public_key raises ValueError for this case, and
|
|
111
|
+
verify_evidence_record must catch it and classify it as UNVERIFIABLE_KEY,
|
|
112
|
+
the same honest floor as an unresolved key. Regression for a real defect
|
|
113
|
+
found 2026-08-04: this ValueError previously propagated uncaught."""
|
|
114
|
+
with patch(
|
|
115
|
+
"strix_verify.resolve_key",
|
|
116
|
+
side_effect=ValueError("Expected OKP/Ed25519 key, got kty=RSA crv=None"),
|
|
117
|
+
):
|
|
118
|
+
result = verify_evidence_record(signed_record)
|
|
119
|
+
|
|
120
|
+
assert result.signature_valid == SignatureStatus.UNVERIFIABLE_KEY
|
|
121
|
+
assert result.compliance.article28_provider_obligations is False
|
|
122
|
+
assert result.error is not None
|
|
123
|
+
|
|
124
|
+
|
|
109
125
|
# ── Hash failures ──────────────────────────────────────────────────────────────
|
|
110
126
|
|
|
111
127
|
def test_tampered_payload_hash_fails(signed_record, public_key):
|
|
@@ -124,13 +140,14 @@ def test_tampered_payload_hash_fails(signed_record, public_key):
|
|
|
124
140
|
|
|
125
141
|
def test_missing_hash_skips_hash_check(public_key, test_jwk, private_key):
|
|
126
142
|
"""
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
143
|
+
A record signed without an evidenceHash field still verifies, and hash_valid
|
|
144
|
+
mirrors signature validity (True) — evidenceHash presence does not gate the
|
|
145
|
+
verdict because the hash is authenticated by the signature, never recomputed
|
|
146
|
+
from the envelope (JS reference index.mjs:472-477).
|
|
130
147
|
|
|
131
148
|
Note: removing evidenceHash from an already-signed record that contained it
|
|
132
149
|
changes the canonical payload and breaks the signature. This test uses a
|
|
133
|
-
record signed without evidenceHash to
|
|
150
|
+
record signed without evidenceHash to exercise the absent-field path.
|
|
134
151
|
"""
|
|
135
152
|
import base64
|
|
136
153
|
from strix_verify.payload import build_canonical_payload
|
|
@@ -158,8 +175,66 @@ def test_missing_hash_skips_hash_check(public_key, test_jwk, private_key):
|
|
|
158
175
|
with patch_resolve_key(public_key):
|
|
159
176
|
result = verify_evidence_record(record)
|
|
160
177
|
|
|
178
|
+
# hash_valid mirrors signature validity (evidenceHash is authenticated by
|
|
179
|
+
# the signature, never independently recomputed from the envelope — JS
|
|
180
|
+
# reference index.mjs:472-477). A signed record verifies regardless of
|
|
181
|
+
# whether it carried an evidenceHash field.
|
|
161
182
|
assert result.signature_valid == SignatureStatus.VERIFIED
|
|
162
|
-
assert result.hash_valid is
|
|
183
|
+
assert result.hash_valid is True
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def test_production_shaped_evidence_hash_verifies(public_key, test_jwk, private_key):
|
|
187
|
+
"""Production-shaped record: evidenceHash is an opaque decision-content hash
|
|
188
|
+
(NOT sha256 of the canonical envelope), validly signed → VERIFIED, hash_valid
|
|
189
|
+
True, Article 12 True.
|
|
190
|
+
|
|
191
|
+
This is the regression guard for the strix verify 5686 incident: real records
|
|
192
|
+
carry a producer-computed evidenceHash that is authenticated by the signature
|
|
193
|
+
and is NOT recomputable from the envelope. The previous envelope-recompute
|
|
194
|
+
model reported hash_valid False (and Article 12 False) on every such record.
|
|
195
|
+
"""
|
|
196
|
+
import base64
|
|
197
|
+
import hashlib
|
|
198
|
+
from strix_verify.payload import build_canonical_payload
|
|
199
|
+
|
|
200
|
+
def sign_payload(pk, payload):
|
|
201
|
+
sig = pk.sign(payload.encode("utf-8"))
|
|
202
|
+
return base64.urlsafe_b64encode(sig).rstrip(b"=").decode()
|
|
203
|
+
|
|
204
|
+
# An opaque decision-content hash — deliberately NOT sha256(canonical-empty).
|
|
205
|
+
decision_content_hash = hashlib.sha256(
|
|
206
|
+
b"capabilityId|actorId|actorRole|action|reason|source|timestamp"
|
|
207
|
+
).hexdigest()
|
|
208
|
+
|
|
209
|
+
record = {
|
|
210
|
+
"evidenceId": 5686,
|
|
211
|
+
"evidenceHash": decision_content_hash,
|
|
212
|
+
"proofChainHash": "pc" * 32,
|
|
213
|
+
"capabilityId": "admin.updateMemberRole",
|
|
214
|
+
"action": "allow",
|
|
215
|
+
"actorId": "user-001",
|
|
216
|
+
"actorRole": "owner",
|
|
217
|
+
"createdAt": "2026-05-26T00:00:00.000Z",
|
|
218
|
+
"signingKeyId": test_jwk["kid"],
|
|
219
|
+
"environment": "production",
|
|
220
|
+
"tenantId": "academy prod",
|
|
221
|
+
"regulatoryContext": {
|
|
222
|
+
"complianceMode": "eu-ai-act",
|
|
223
|
+
"euAiActArticle12": True,
|
|
224
|
+
"euAiActArticle14": True,
|
|
225
|
+
"euAiActArticle28": True,
|
|
226
|
+
},
|
|
227
|
+
}
|
|
228
|
+
record["signature"] = sign_payload(
|
|
229
|
+
private_key, build_canonical_payload(record).to_canonical_json()
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
with patch_resolve_key(public_key):
|
|
233
|
+
result = verify_evidence_record(record)
|
|
234
|
+
|
|
235
|
+
assert result.signature_valid == SignatureStatus.VERIFIED
|
|
236
|
+
assert result.hash_valid is True # authenticated by signature, not recomputed
|
|
237
|
+
assert result.compliance.article12_tamper_resistant is True
|
|
163
238
|
|
|
164
239
|
|
|
165
240
|
# ── Legacy unsigned ────────────────────────────────────────────────────────────
|
|
@@ -185,14 +260,18 @@ def test_legacy_unsigned_record():
|
|
|
185
260
|
assert result.compliance.article28_provider_obligations is False
|
|
186
261
|
|
|
187
262
|
|
|
188
|
-
def
|
|
189
|
-
"""Legacy unsigned record
|
|
190
|
-
from strix_verify.hashing import compute_evidence_hash
|
|
191
|
-
from strix_verify.payload import build_canonical_payload
|
|
263
|
+
def test_legacy_unsigned_record_hash_not_authenticated():
|
|
264
|
+
"""Legacy unsigned record → hash_valid False.
|
|
192
265
|
|
|
266
|
+
Contract (JS reference index.mjs:472-477): evidenceHash is producer-computed
|
|
267
|
+
over decision content and authenticated SOLELY by the Ed25519 signature; it
|
|
268
|
+
is not independently recomputable from the canonical envelope. With no
|
|
269
|
+
signature there is nothing to authenticate it, so hash_valid is False
|
|
270
|
+
(hashValid = signatureValid, and signatureValid is LEGACY_UNSIGNED here).
|
|
271
|
+
"""
|
|
193
272
|
record = {
|
|
194
273
|
"evidenceId": 1,
|
|
195
|
-
"evidenceHash": "", #
|
|
274
|
+
"evidenceHash": "ev" * 32, # opaque producer hash; not envelope-derived
|
|
196
275
|
"capabilityId": "test",
|
|
197
276
|
"action": "APPROVED",
|
|
198
277
|
"actorId": "user-001",
|
|
@@ -202,17 +281,11 @@ def test_legacy_record_with_hash_verifies_hash():
|
|
|
202
281
|
"tenantId": "tenant-001",
|
|
203
282
|
}
|
|
204
283
|
|
|
205
|
-
# Step 2: compute hash with empty evidenceHash (non-circular)
|
|
206
|
-
canonical_for_hash = build_canonical_payload(record)
|
|
207
|
-
evidence_hash = compute_evidence_hash(canonical_for_hash.to_canonical_json())
|
|
208
|
-
|
|
209
|
-
# Step 3: store the hash and rebuild canonical
|
|
210
|
-
record["evidenceHash"] = evidence_hash
|
|
211
|
-
|
|
212
284
|
result = verify_evidence_record(record)
|
|
213
285
|
|
|
214
286
|
assert result.signature_valid == SignatureStatus.LEGACY_UNSIGNED
|
|
215
|
-
assert result.hash_valid is
|
|
287
|
+
assert result.hash_valid is False
|
|
288
|
+
assert result.compliance.article12_tamper_resistant is False
|
|
216
289
|
|
|
217
290
|
|
|
218
291
|
# ── Layer 2: Deployment context (SE-14) ───────────────────────────────────────
|
|
Binary file
|
strix_verify-0.2.0/CHANGELOG.md
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to `strix-verify` are documented here. This project
|
|
4
|
-
follows semantic versioning (pre-1.0: minor bumps may add functionality or
|
|
5
|
-
fix correctness issues that change verification outcomes).
|
|
6
|
-
|
|
7
|
-
## [0.2.0] — 2026-05-31
|
|
8
|
-
|
|
9
|
-
### Fixed — Academy-form record verification (correctness)
|
|
10
|
-
|
|
11
|
-
`build_canonical_payload` previously reconstructed **only** the Console
|
|
12
|
-
canonical form (string `schemaVersion`/`evidenceId`, `complianceMode`-first
|
|
13
|
-
`regulatoryContext`). It therefore could **not** verify records signed in the
|
|
14
|
-
Academy form — approximately 4,450 historical Academy records — and would have
|
|
15
|
-
reported them as signature failures.
|
|
16
|
-
|
|
17
|
-
This release adds the SE v1 **dual-form discriminator**, matching the JS
|
|
18
|
-
reference verifier (`@strixgov/verifier`):
|
|
19
|
-
|
|
20
|
-
- Records with `sourceApp == "academy-platform"` now serialize `schemaVersion`
|
|
21
|
-
and `evidenceId` as JSON **numbers**, with a `euAiActArticle12`-first
|
|
22
|
-
`regulatoryContext`.
|
|
23
|
-
- Console records are unchanged (JSON strings, `complianceMode`-first).
|
|
24
|
-
- Added the `signedPayload` reconstruction-free passthrough (v1.10.0): when a
|
|
25
|
-
record carries the original signed bytes, they are returned verbatim.
|
|
26
|
-
- Canonical output now uses `ensure_ascii=False` for byte-parity with the JS
|
|
27
|
-
reference on non-ASCII fields.
|
|
28
|
-
|
|
29
|
-
The Console path is byte-for-byte unchanged (the prior golden-vector test
|
|
30
|
-
remains the canary and still passes).
|
|
31
|
-
|
|
32
|
-
### Added — cross-language conformance
|
|
33
|
-
|
|
34
|
-
This verifier is now pinned to the JS reference against a shared,
|
|
35
|
-
language-neutral fixture
|
|
36
|
-
(`packages/strixgov-verifier/test/fixtures/se-v1-conformance-vectors.json`).
|
|
37
|
-
Both implementations read the same fixture and must agree byte-for-byte; a CI
|
|
38
|
-
lane (`SE v1 Cross-Language Conformance`) enforces this on Python 3.10–3.12 and
|
|
39
|
-
Node 20–24. See `tests/test_conformance_vectors.py`.
|
|
40
|
-
|
|
41
|
-
### Notes
|
|
42
|
-
|
|
43
|
-
- No new dependencies. No API changes to `verify_evidence` / `verify_evidence_record`.
|
|
44
|
-
- The golden vectors were not modified; the implementation was corrected to
|
|
45
|
-
match them.
|
|
46
|
-
|
|
47
|
-
## [0.1.0]
|
|
48
|
-
|
|
49
|
-
Initial release. Independent SE v1 verification (Ed25519 + SHA-256), JWKS
|
|
50
|
-
resolution, two-layer verification model, EU AI Act compliance-flag derivation.
|
|
51
|
-
Console canonical form only.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|