modelsign 1.1.0__tar.gz → 1.2.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.
- {modelsign-1.1.0 → modelsign-1.2.0}/.github/workflows/ci.yml +1 -1
- {modelsign-1.1.0 → modelsign-1.2.0}/CHANGELOG.md +11 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/PKG-INFO +13 -2
- {modelsign-1.1.0 → modelsign-1.2.0}/README.md +10 -1
- modelsign-1.2.0/docs/security-policy-follow-ons.md +30 -0
- modelsign-1.2.0/docs/superpowers/plans/2026-12-03-rfc3161.md +29 -0
- modelsign-1.2.0/docs/superpowers/specs/2026-12-03-rfc3161-design.md +31 -0
- modelsign-1.2.0/docs/timestamps.md +108 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/pyproject.toml +5 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/__init__.py +1 -1
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/api.py +27 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/approvals.py +6 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/cli.py +22 -6
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/guard.py +13 -1
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/sig.py +4 -2
- modelsign-1.2.0/src/modelsign/timestamps.py +227 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign.egg-info/PKG-INFO +13 -2
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign.egg-info/SOURCES.txt +7 -1
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign.egg-info/requires.txt +3 -0
- modelsign-1.2.0/tests/test_timestamps.py +317 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/.github/FUNDING.yml +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/.gitignore +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/LICENSE +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/action.yml +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/setup.cfg +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/crypto/__init__.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/crypto/keys.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/crypto/sign.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/crypto/verify.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/formats/__init__.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/formats/directory.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/formats/single.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/identity/__init__.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/identity/canonical.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/identity/card.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/lineage.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/middleware/__init__.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/middleware/response.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign/oms.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign.egg-info/dependency_links.txt +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign.egg-info/entry_points.txt +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/src/modelsign.egg-info/top_level.txt +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/conftest.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_api.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_approvals.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_canonical.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_card.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_cli.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_formats.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_guard.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_integration.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_keys.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_lineage.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_middleware.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_oms.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_sig.py +0 -0
- {modelsign-1.1.0 → modelsign-1.2.0}/tests/test_sign_verify.py +0 -0
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v1.2.0 (2026-12-03)
|
|
4
|
+
|
|
5
|
+
- Optional RFC 3161 timestamps binding a model signature and its current approval chain.
|
|
6
|
+
- `sign`/`approve --timestamp URL --tsa-ca FILE`; failures preserve the existing signature.
|
|
7
|
+
- Offline `verify --require-timestamp` and matching direct/installed guard policy.
|
|
8
|
+
- Explicit TSA roots, OpenSSL 3 verification, optional `timestamp` extra.
|
|
9
|
+
- Bounded HTTP responses and a hard total network deadline.
|
|
10
|
+
- Existing model signatures and lineage digests remain compatible.
|
|
11
|
+
- Tested with local test authorities and the external FreeTSA service.
|
|
12
|
+
- Timestamps do not implement revocation, archival validation or rollback prevention.
|
|
13
|
+
|
|
3
14
|
## v1.0.0 (2026-03-25)
|
|
4
15
|
|
|
5
16
|
Initial release.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: modelsign
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: Sign AI models with identity. Verify anywhere. Part of the AURE Provenance stack by Constant Systems.
|
|
5
5
|
Author-email: James Kerr <qj@constantqj.com>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -22,6 +22,8 @@ Requires-Dist: click>=8.0
|
|
|
22
22
|
Requires-Dist: rfc8785>=0.1.2
|
|
23
23
|
Provides-Extra: middleware
|
|
24
24
|
Requires-Dist: fastapi>=0.100; extra == "middleware"
|
|
25
|
+
Provides-Extra: timestamp
|
|
26
|
+
Requires-Dist: asn1crypto>=1.5.1; extra == "timestamp"
|
|
25
27
|
Provides-Extra: dev
|
|
26
28
|
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
27
29
|
Requires-Dist: pytest-cov; extra == "dev"
|
|
@@ -318,9 +320,18 @@ Use OMS when you need keyless signing tied to a CI identity, a transparency log,
|
|
|
318
320
|
|
|
319
321
|
- Key compromise — your key, your responsibility
|
|
320
322
|
- Model safety, fairness, or legal compliance
|
|
321
|
-
-
|
|
323
|
+
- Revocation and historical archive validation; `signed_at` remains metadata. Optional RFC 3161 envelope timestamps are described below.
|
|
322
324
|
- Pickle and deserialization attacks inside a correctly signed file
|
|
323
325
|
|
|
324
326
|
## License
|
|
325
327
|
|
|
326
328
|
Apache 2.0
|
|
329
|
+
|
|
330
|
+
## RFC 3161 timestamps (v1.2.0)
|
|
331
|
+
|
|
332
|
+
Optional timestamps bind the model signature and current approval chain to a
|
|
333
|
+
trusted TSA time. See [the timestamp guide](docs/timestamps.md) for installation,
|
|
334
|
+
`--timestamp`, `--require-timestamp`, explicit CA trust and offline verification.
|
|
335
|
+
Install with `pip install "modelsign[timestamp]==1.2.0"` and OpenSSL 3. `signed_at` remains
|
|
336
|
+
self-reported; timestamps do not implement key revocation or prevent replay of
|
|
337
|
+
older valid releases. KMS signing is separate work.
|
|
@@ -288,9 +288,18 @@ Use OMS when you need keyless signing tied to a CI identity, a transparency log,
|
|
|
288
288
|
|
|
289
289
|
- Key compromise — your key, your responsibility
|
|
290
290
|
- Model safety, fairness, or legal compliance
|
|
291
|
-
-
|
|
291
|
+
- Revocation and historical archive validation; `signed_at` remains metadata. Optional RFC 3161 envelope timestamps are described below.
|
|
292
292
|
- Pickle and deserialization attacks inside a correctly signed file
|
|
293
293
|
|
|
294
294
|
## License
|
|
295
295
|
|
|
296
296
|
Apache 2.0
|
|
297
|
+
|
|
298
|
+
## RFC 3161 timestamps (v1.2.0)
|
|
299
|
+
|
|
300
|
+
Optional timestamps bind the model signature and current approval chain to a
|
|
301
|
+
trusted TSA time. See [the timestamp guide](docs/timestamps.md) for installation,
|
|
302
|
+
`--timestamp`, `--require-timestamp`, explicit CA trust and offline verification.
|
|
303
|
+
Install with `pip install "modelsign[timestamp]==1.2.0"` and OpenSSL 3. `signed_at` remains
|
|
304
|
+
self-reported; timestamps do not implement key revocation or prevent replay of
|
|
305
|
+
older valid releases. KMS signing is separate work.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Follow-on policy work (not implemented in the RFC 3161 branch)
|
|
2
|
+
|
|
3
|
+
Keep these independent of KMS signing. Do not market timestamping as revocation,
|
|
4
|
+
rollback prevention, or global transparency.
|
|
5
|
+
|
|
6
|
+
1. Signed model identity and security epoch: add a stable, namespace-scoped
|
|
7
|
+
model_id and nonnegative integer security_version inside the signed card.
|
|
8
|
+
Deployments can enforce an explicit floor; stateful high-water marks require
|
|
9
|
+
atomic locking, persistence, tenant/key scoping, recovery and an explicit
|
|
10
|
+
administrative downgrade procedure. Never order versions using signed_at.
|
|
11
|
+
A first-use cache alone cannot detect an initial replay, and deleting/resetting
|
|
12
|
+
it loses its protection. Require trusted publisher identity before updating it.
|
|
13
|
+
2. Root-signed trust bundles: schema must bind issuer, audience, bundle sequence,
|
|
14
|
+
issuance/expiry, full public-key identity and key-status policy. Freshness needs
|
|
15
|
+
a trusted clock and/or externally pinned bundle sequence; signed issue times
|
|
16
|
+
alone do not prevent replay within the validity window. Revocation policy must
|
|
17
|
+
distinguish compromise from administrative retirement. A conservative
|
|
18
|
+
key_compromise policy can reject all artifacts, including historical ones.
|
|
19
|
+
A timestamp is an upper bound on signature existence: it does not prove signing
|
|
20
|
+
happened after a key's valid_from time or establish the actual compromise time.
|
|
21
|
+
Interval policy must account for TSA accuracy, not compare bare strings.
|
|
22
|
+
3. Transparency: inclusion in a signed tree proves membership in that particular
|
|
23
|
+
tree, not global visibility, freshness, uniqueness or freedom from split views.
|
|
24
|
+
Those properties require pinned/witnessed checkpoints, consistency proofs,
|
|
25
|
+
freshness policy and/or gossip. An older valid inclusion proof is replayable.
|
|
26
|
+
Store external proof appendages outside their own hashed payload to avoid
|
|
27
|
+
self-reference; keep the exact envelope digest and log identity explicit.
|
|
28
|
+
|
|
29
|
+
No trust-bundle schema, commercial hosting promise or compliance claim is shipped
|
|
30
|
+
here. Those are separate designs with separate failure-mode tests.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# RFC 3161 Implementation Plan
|
|
2
|
+
|
|
3
|
+
Goal: optional trusted timestamps with offline fail-closed policy, isolated from KMS.
|
|
4
|
+
Spec: ../specs/2026-12-03-rfc3161-design.md
|
|
5
|
+
|
|
6
|
+
- [x] Add failing behavioral tests using local OpenSSL TSA and real certificates.
|
|
7
|
+
- [x] Implement timestamps.py: envelope digest, nonce request, bounded HTTP transport, DER parsing, offline OpenSSL verification; add optional timestamp field excluded from lineage digest.
|
|
8
|
+
- [x] Integrate timestamp/tsa_ca arguments into sign_model and approve before writing, and require_timestamp/tsa_ca into verify_model, CLI and direct/installed guards. Reject unsupported fallbacks.
|
|
9
|
+
- [x] Test old signatures/lineage, approval mutation, wire validation, key trust, failure atomicity, and CLI/guard policy. Run full pytest and mypy.
|
|
10
|
+
- [x] Document dependency, trust and historical-validation limits, build/check distributions, review branch, commit and push branch without merging or publishing.
|
|
11
|
+
|
|
12
|
+
Review focus: untrusted embedded TSA root; rollback versus truncation; guards silently falling back to unsigned/OMS; nonce replay; treating signed_at as proven time.
|
|
13
|
+
|
|
14
|
+
## Execution and review evidence
|
|
15
|
+
|
|
16
|
+
Baseline: 225 tests passed. New missing-policy, CLI and guard tests failed before
|
|
17
|
+
implementation. Expanded guard test caught missing installed-policy propagation;
|
|
18
|
+
fixed and rerun. Independent reviewer found one P2: socket inactivity timeout did
|
|
19
|
+
not bound a slow response. Reproduced with a failing slow-drip test; HTTP transport
|
|
20
|
+
now runs in a killable worker with a total deadline, including DNS and headers.
|
|
21
|
+
The regression passed. Review found no other important issues. Added explicit
|
|
22
|
+
ambient-root isolation, ESS-binding mismatch and critical-extension checks too.
|
|
23
|
+
|
|
24
|
+
Implementation decisions: explicit CA roots and OpenSSL 3 + optional asn1crypto;
|
|
25
|
+
current-time certificate validation (no archive/revocation claim); one current
|
|
26
|
+
envelope timestamp replaced/cleared when approvals change; process-bounded HTTP
|
|
27
|
+
acquisition. Deferred: historical revocation/archive support, transparency, trust
|
|
28
|
+
bundles and monotonic version policy, all documented separately as nonfeatures.
|
|
29
|
+
No KMS work and no release publication.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# RFC 3161 timestamp design
|
|
2
|
+
|
|
3
|
+
Scope: timestamps only; no KMS, runtime attestations, revocation engine, compliance exports or release publication. Implement on `feature/rfc3161-timestamps`. Existing model signatures, approval messages and parent digests remain unchanged.
|
|
4
|
+
|
|
5
|
+
## Approach
|
|
6
|
+
|
|
7
|
+
Use optional `asn1crypto` for RFC 3161 request/response parsing and OpenSSL 3 `ts -verify` for CMS signatures, ESS signer binding, timestamp EKU and certificate-chain verification. Reimplementing PKI/CMS in Python is unnecessary security-sensitive work; a cloud-specific TSA SDK would bind users to a service. These are implementation choices made by Codex under the user's direction to build without further questions.
|
|
8
|
+
|
|
9
|
+
## Format and binding
|
|
10
|
+
|
|
11
|
+
Add optional top-level `timestamp = {type: "rfc3161", token: <base64 DER CMS ContentInfo>}`. Exclude this appendage from `sig_digest`, just as approvals are excluded today, preserving lineage and approvals. The SHA-256 message imprint covers domain-separated canonical JSON containing the existing `sig_digest` and the entire current approvals list. This binds the token to the current approval sequence. An approval with `--timestamp` replaces the envelope timestamp; an approval without it clears the now-stale timestamp. Preserve the file unchanged if obtaining or verifying a requested timestamp fails.
|
|
12
|
+
|
|
13
|
+
A timestamp is evidence that the envelope existed by the TSA time, not the exact signing time or evidence of no compromise. It cannot detect rollback to an earlier valid timestamped envelope, nor removal of the timestamp unless the verifier requires one. It does not validate approver trust; existing approval policies remain separate.
|
|
14
|
+
|
|
15
|
+
## Trust, network and policy
|
|
16
|
+
|
|
17
|
+
`sign` and `approve`: `--timestamp URL --tsa-ca FILE`. Require explicit trusted TSA CA PEM bundle before contacting a service. Send only a SHA-256 imprint and random nonce, with certificate request, over HTTP(S); no model bytes or key material. HTTP is supported by RFC 3161; signed response, matching nonce/imprint and CA trust are mandatory. Reject redirects, bad content types, failed statuses, oversized responses and timeouts. Bound response to 1 MiB and network/subprocess timeouts to 15 seconds.
|
|
18
|
+
|
|
19
|
+
`verify`: `--require-timestamp --tsa-ca FILE`. A supplied CA also requests validation of any present token; without timestamp policy/CA the timestamp is explicitly unchecked. Requiring a timestamp without a trusted CA fails closed. API and direct/installed guards carry identical policy. Timestamp requirements reject unsigned/OMS fallback paths rather than silently bypassing the policy.
|
|
20
|
+
|
|
21
|
+
Verification is offline. Explicit CA roots only; no fetching intermediates or revocation data. OpenSSL checks chain validity at current verification time; also require the TSA signer certificate valid at genTime, reject future genTime beyond five-minute clock tolerance and non-SHA256 imprints. This initial version deliberately does not accept expired certificate chains based solely on a claimed historical time. Archive validation and revocation evidence are separate work.
|
|
22
|
+
|
|
23
|
+
## Dependencies and compatibility
|
|
24
|
+
|
|
25
|
+
Python 3.9+ retained. `modelsign[timestamp]` installs asn1crypto; normal signing/verifying still works without it or OpenSSL. OpenSSL 3 executable selected from PATH or MODELSIGN_OPENSSL. Older verifiers ignore timestamps and cannot enforce the new policy. No model format major bump; no package release in this branch.
|
|
26
|
+
|
|
27
|
+
## Verification
|
|
28
|
+
|
|
29
|
+
Local test TSA with real RSA/X.509 certificates and OpenSSL-issued tokens; no external service required. Test trust rejection, wrong nonce/imprint, CMS tampering, TSA EKU, future time, malformed/oversized responses, missing token/dependencies, no partial write, approval binding and lineage invariance, CLI JSON/exit codes, guards and fallback policies. Run full suite, mypy and package builds.
|
|
30
|
+
|
|
31
|
+
References: https://www.rfc-editor.org/rfc/rfc3161 and https://docs.openssl.org/3.0/man1/openssl-ts/
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# RFC 3161 envelope timestamps
|
|
2
|
+
|
|
3
|
+
Available in ModelSign 1.2.0. Install with `pip install "modelsign[timestamp]==1.2.0"`.
|
|
4
|
+
It requires OpenSSL 3 on PATH; on macOS with Homebrew, for example:
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
export MODELSIGN_OPENSSL=/opt/homebrew/opt/openssl@3/bin/openssl
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Obtain a TSA CA bundle independently and choose an RFC 3161 endpoint you trust.
|
|
11
|
+
No public TSA is contacted by default. The request sends a SHA-256 message imprint
|
|
12
|
+
and random nonce, not model bytes, identity-card contents or private keys.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
modelsign sign model.safetensors --name Example --key publisher.pem \
|
|
16
|
+
--timestamp https://tsa.example/timestamp --tsa-ca trusted-tsa-roots.pem
|
|
17
|
+
modelsign approve model.safetensors --role release --key approver.pem \
|
|
18
|
+
--timestamp https://tsa.example/timestamp --tsa-ca trusted-tsa-roots.pem
|
|
19
|
+
modelsign verify model.safetensors --pubkey publisher-public.pem \
|
|
20
|
+
--require-timestamp --tsa-ca trusted-tsa-roots.pem --json
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from modelsign.guard import require_verified, install
|
|
25
|
+
require_verified("model.safetensors", pubkey="publisher-public.pem",
|
|
26
|
+
require_timestamp=True, tsa_ca="trusted-tsa-roots.pem")
|
|
27
|
+
# Or apply the same policy to the existing Hub/local-loader integrations:
|
|
28
|
+
install(pubkey="publisher-public.pem", require_timestamp=True,
|
|
29
|
+
tsa_ca="trusted-tsa-roots.pem")
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Timestamp policy does not replace publisher trust or approval/quorum policies.
|
|
33
|
+
`--require-timestamp` fails without a valid token and explicitly supplied TSA CA
|
|
34
|
+
bundle. Supplying `--tsa-ca` without requiring a token validates one if present.
|
|
35
|
+
With neither option, timestamps are unchecked and the result's `timestamp` is
|
|
36
|
+
null. Old signatures remain readable. Old ModelSign versions cannot enforce this
|
|
37
|
+
policy. OMS and unsigned fallback paths are blocked when timestamps are required.
|
|
38
|
+
|
|
39
|
+
## Exact binding
|
|
40
|
+
|
|
41
|
+
The optional field appended to the `.sig` JSON is:
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{"timestamp": {"type": "rfc3161", "token": "<base64 DER CMS ContentInfo>"}}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The RFC 3161 SHA-256 message imprint is the hash of:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
b"modelsign-rfc3161-envelope-v1\x00" + canonical_json({
|
|
51
|
+
"signature_digest": sig_digest(sig),
|
|
52
|
+
"approvals": sig.approvals or []
|
|
53
|
+
})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`canonical_json` is RFC 8785. `sig_digest` retains its existing definition except
|
|
57
|
+
that it excludes the new timestamp field, as it already excludes approvals.
|
|
58
|
+
The original model signature, existing approval signatures, and lineage digests
|
|
59
|
+
therefore do not change. The exact approval records, including order and their
|
|
60
|
+
signatures, are bound by the timestamp.
|
|
61
|
+
|
|
62
|
+
Approving with `--timestamp` obtains a new token for the updated chain. Approving
|
|
63
|
+
without it clears the stale envelope token. Archive older envelopes separately
|
|
64
|
+
if their earlier timestamps matter. A failed TSA request or verification leaves
|
|
65
|
+
the existing `.sig` untouched; the approval/signing operation reports failure.
|
|
66
|
+
|
|
67
|
+
## What a successful check establishes
|
|
68
|
+
|
|
69
|
+
The trusted TSA asserts that the envelope existed by `gen_time`, subject to the
|
|
70
|
+
reported TSA accuracy and your trust in that authority. `signed_at` and
|
|
71
|
+
`approved_at` remain self-reported metadata; the timestamp does not turn either
|
|
72
|
+
into an authenticated event time. It also does not validate approval identities.
|
|
73
|
+
|
|
74
|
+
The verifier checks the SHA-256 imprint, CMS/ESS signature and certificate binding,
|
|
75
|
+
time-stamping EKU, explicit CA chain, signer certificate validity at `gen_time`,
|
|
76
|
+
and rejects timestamps more than five minutes into the future. Acquisition also
|
|
77
|
+
checks the random nonce. OpenSSL validates the certificate chain at the current
|
|
78
|
+
verification time. Verification makes no network requests and does not retrieve
|
|
79
|
+
OCSP/CRLs/intermediate certificates. Include required intermediates in the token
|
|
80
|
+
or an appropriately managed trust bundle; only supply CA certificates you trust.
|
|
81
|
+
Expired chains fail: this is not archival validation or a revocation system.
|
|
82
|
+
|
|
83
|
+
A remaining token detects edits to or truncation of its bound approval chain.
|
|
84
|
+
It cannot detect replacement with an older valid timestamped envelope. Removing
|
|
85
|
+
the token is detected only if the deployment requires one. An external release
|
|
86
|
+
floor, authenticated state or witnessed transparency checkpoint is separate policy.
|
|
87
|
+
|
|
88
|
+
HTTP(S) is supported; HTTP relies on the signed TSA response for authenticity.
|
|
89
|
+
Redirects are rejected, HTTP response bodies are limited to 1 MiB, and network
|
|
90
|
+
acquisition has a 15-second total deadline enforced by an isolated, killable
|
|
91
|
+
HTTP worker. OpenSSL subprocesses also have 15-second timeouts. No TLS verification is
|
|
92
|
+
disabled. Use an approved endpoint rather than one supplied by an untrusted model.
|
|
93
|
+
|
|
94
|
+
## Development checks
|
|
95
|
+
|
|
96
|
+
Install `pip install '.[dev,timestamp]'`, ensure OpenSSL 3 is selected, then run
|
|
97
|
+
`pytest` and `mypy`. The timestamp suite runs a local TSA with generated test
|
|
98
|
+
certificates; it needs no external service or production credentials.
|
|
99
|
+
|
|
100
|
+
## External interoperability check
|
|
101
|
+
|
|
102
|
+
On 2026-12-03 the release was tested against `https://freetsa.org/tsr` using
|
|
103
|
+
the CA certificate obtained from `https://freetsa.org/files/cacert.pem`, whose
|
|
104
|
+
SHA-256 matched the authority's published fingerprint:
|
|
105
|
+
`2151b61137ffa86bf664691ba67e7da0b19f98c758e3d228d5d8ebf27e044438`.
|
|
106
|
+
Both model-signing and approval timestamps verified; removing the approval from
|
|
107
|
+
the timestamped envelope was rejected. This interoperability check is not a
|
|
108
|
+
guarantee of the service's future availability or an endorsement for every policy.
|
|
@@ -26,6 +26,7 @@ dependencies = [
|
|
|
26
26
|
|
|
27
27
|
[project.optional-dependencies]
|
|
28
28
|
middleware = ["fastapi>=0.100"]
|
|
29
|
+
timestamp = ["asn1crypto>=1.5.1"]
|
|
29
30
|
dev = ["pytest>=7.0", "pytest-cov", "mypy"]
|
|
30
31
|
|
|
31
32
|
[project.scripts]
|
|
@@ -57,3 +58,7 @@ ignore_missing_imports = true
|
|
|
57
58
|
|
|
58
59
|
[tool.pytest.ini_options]
|
|
59
60
|
testpaths = ["tests"]
|
|
61
|
+
|
|
62
|
+
[[tool.mypy.overrides]]
|
|
63
|
+
module = ["asn1crypto.*"]
|
|
64
|
+
ignore_missing_imports = true
|
|
@@ -86,6 +86,9 @@ class VerifyResult:
|
|
|
86
86
|
path, so a file cannot be added, removed or moved within it.
|
|
87
87
|
"""
|
|
88
88
|
|
|
89
|
+
timestamp: Optional[dict] = None
|
|
90
|
+
"""Verified TSA result, or None when timestamp policy was not checked."""
|
|
91
|
+
|
|
89
92
|
@property
|
|
90
93
|
def trusted(self) -> bool:
|
|
91
94
|
"""True only when the signing identity was checked against a known key."""
|
|
@@ -155,6 +158,8 @@ def sign_model(
|
|
|
155
158
|
sig_path: Path | str | None = None,
|
|
156
159
|
parent: Path | str | SigFile | None = None,
|
|
157
160
|
write: bool = True,
|
|
161
|
+
timestamp: str | None = None,
|
|
162
|
+
tsa_ca: Path | str | None = None,
|
|
158
163
|
) -> SigFile:
|
|
159
164
|
"""Sign a model file or directory and return the signature.
|
|
160
165
|
|
|
@@ -165,6 +170,9 @@ def sign_model(
|
|
|
165
170
|
digest is recorded in the card as ``parent_signature``, which
|
|
166
171
|
:mod:`modelsign.lineage` walks. An explicit ``parent_signature`` already
|
|
167
172
|
in the card wins.
|
|
173
|
+
|
|
174
|
+
``timestamp`` is an RFC 3161 endpoint; it requires a trusted ``tsa_ca``
|
|
175
|
+
PEM bundle. The token is validated before any signature file is written.
|
|
168
176
|
"""
|
|
169
177
|
model_path = Path(model_path).expanduser()
|
|
170
178
|
if not model_path.exists():
|
|
@@ -217,6 +225,9 @@ def sign_model(
|
|
|
217
225
|
manifest=manifest,
|
|
218
226
|
)
|
|
219
227
|
|
|
228
|
+
if timestamp is not None:
|
|
229
|
+
from modelsign.timestamps import request_timestamp
|
|
230
|
+
sig.timestamp = request_timestamp(sig, url=timestamp, tsa_ca=tsa_ca)
|
|
220
231
|
if write:
|
|
221
232
|
write_sig(sig, bundle_sig_path)
|
|
222
233
|
return sig
|
|
@@ -252,6 +263,8 @@ def verify_model(
|
|
|
252
263
|
keyring_dir: Path | str | None = None,
|
|
253
264
|
require_trusted: bool = True,
|
|
254
265
|
require_name_binding: bool = True,
|
|
266
|
+
require_timestamp: bool = False,
|
|
267
|
+
tsa_ca: Path | str | None = None,
|
|
255
268
|
) -> VerifyResult:
|
|
256
269
|
"""Verify a model against its signature.
|
|
257
270
|
|
|
@@ -268,6 +281,10 @@ def verify_model(
|
|
|
268
281
|
single file is rejected, because that format leaves the filename out of
|
|
269
282
|
the signed message. Pass False only for old signatures you cannot
|
|
270
283
|
re-sign.
|
|
284
|
+
|
|
285
|
+
``require_timestamp`` requires an RFC 3161 token for the current envelope
|
|
286
|
+
and an explicit ``tsa_ca`` bundle. Supplying just the bundle checks a token
|
|
287
|
+
if present. Verification is offline and separate from key revocation.
|
|
271
288
|
"""
|
|
272
289
|
model_path = Path(model_path).expanduser()
|
|
273
290
|
sig_file = Path(sig_path).expanduser() if sig_path else default_sig_path(model_path)
|
|
@@ -432,8 +449,18 @@ def verify_model(
|
|
|
432
449
|
paths_bound=paths_bound,
|
|
433
450
|
)
|
|
434
451
|
|
|
452
|
+
timestamp_result = None
|
|
453
|
+
if require_timestamp or (tsa_ca is not None and sig.timestamp is not None):
|
|
454
|
+
from modelsign.timestamps import TimestampError, verify_timestamp
|
|
455
|
+
try:
|
|
456
|
+
timestamp_result = verify_timestamp(sig, tsa_ca=tsa_ca)
|
|
457
|
+
except (TimestampError, ValueError, TypeError) as e:
|
|
458
|
+
return VerifyResult(verified=False, model=str(model_path),
|
|
459
|
+
error="timestamp", detail=str(e))
|
|
460
|
+
|
|
435
461
|
return VerifyResult(
|
|
436
462
|
verified=True,
|
|
463
|
+
timestamp=timestamp_result,
|
|
437
464
|
model=str(model_path),
|
|
438
465
|
sha256=f"sha256:{model_hash}",
|
|
439
466
|
fingerprint=fingerprint,
|
|
@@ -141,6 +141,8 @@ def approve(
|
|
|
141
141
|
approver: str = "",
|
|
142
142
|
sig_path: Path | str | None = None,
|
|
143
143
|
when: str | None = None,
|
|
144
|
+
timestamp: str | None = None,
|
|
145
|
+
tsa_ca: Path | str | None = None,
|
|
144
146
|
) -> Approval:
|
|
145
147
|
"""Append an approval to a model's signature.
|
|
146
148
|
|
|
@@ -200,6 +202,10 @@ def approve(
|
|
|
200
202
|
}
|
|
201
203
|
existing.append(record)
|
|
202
204
|
sig.approvals = existing
|
|
205
|
+
sig.timestamp = None # The previous token binds the previous approval chain.
|
|
206
|
+
if timestamp is not None:
|
|
207
|
+
from modelsign.timestamps import request_timestamp
|
|
208
|
+
sig.timestamp = request_timestamp(sig, url=timestamp, tsa_ca=tsa_ca)
|
|
203
209
|
write_sig(sig, sig_file)
|
|
204
210
|
|
|
205
211
|
return Approval(
|
|
@@ -145,7 +145,9 @@ def _find_pubkey_for_private(priv_path: Path) -> Path:
|
|
|
145
145
|
default=None,
|
|
146
146
|
help="Signature of the model this was derived from; recorded as parent_signature.",
|
|
147
147
|
)
|
|
148
|
-
|
|
148
|
+
@click.option("--timestamp", default=None, help="RFC 3161 TSA URL (requires --tsa-ca).")
|
|
149
|
+
@click.option("--tsa-ca", default=None, help="Trusted TSA CA PEM bundle.")
|
|
150
|
+
def sign(model_path, name, identity_file, key_path, out_path, parent_sig, timestamp, tsa_ca):
|
|
149
151
|
"""Sign a model file or directory."""
|
|
150
152
|
model_path = Path(model_path)
|
|
151
153
|
|
|
@@ -170,13 +172,14 @@ def sign(model_path, name, identity_file, key_path, out_path, parent_sig):
|
|
|
170
172
|
key=key_path,
|
|
171
173
|
sig_path=sig_path,
|
|
172
174
|
parent=parent_sig,
|
|
175
|
+
timestamp=timestamp,
|
|
176
|
+
tsa_ca=tsa_ca,
|
|
173
177
|
)
|
|
174
178
|
except VerifyError as e:
|
|
175
179
|
click.echo(f"Error: {e}", err=True)
|
|
176
180
|
sys.exit(1)
|
|
177
181
|
except ValueError as e:
|
|
178
|
-
|
|
179
|
-
click.echo(f"Error: invalid identity card: {e}", err=True)
|
|
182
|
+
click.echo(f"Error: {e}", err=True)
|
|
180
183
|
sys.exit(1)
|
|
181
184
|
except Exception as e:
|
|
182
185
|
click.echo(f"Error: {e}", err=True)
|
|
@@ -243,10 +246,12 @@ _FAILURE_LINES = {
|
|
|
243
246
|
default=False,
|
|
244
247
|
help="Accept a modelsign 1.x signature, which does not cover the filename.",
|
|
245
248
|
)
|
|
249
|
+
@click.option("--require-timestamp", is_flag=True, help="Require a trusted RFC 3161 timestamp of the current envelope.")
|
|
250
|
+
@click.option("--tsa-ca", default=None, help="Trusted TSA CA PEM bundle for offline verification.")
|
|
246
251
|
def verify(
|
|
247
252
|
model_path, sig_path, pubkey_path, output_json, quiet, require_trusted,
|
|
248
253
|
allow_embedded_key, required_roles, approver_keys, min_approvals,
|
|
249
|
-
allow_unbound_name,
|
|
254
|
+
allow_unbound_name, require_timestamp, tsa_ca,
|
|
250
255
|
):
|
|
251
256
|
"""Verify a signed model file or directory."""
|
|
252
257
|
model_path = Path(model_path)
|
|
@@ -258,6 +263,8 @@ def verify(
|
|
|
258
263
|
pubkey=pubkey_path,
|
|
259
264
|
require_trusted=not allow_embedded_key,
|
|
260
265
|
require_name_binding=not allow_unbound_name,
|
|
266
|
+
require_timestamp=require_timestamp,
|
|
267
|
+
tsa_ca=tsa_ca,
|
|
261
268
|
)
|
|
262
269
|
except VerifyError as e:
|
|
263
270
|
if not quiet:
|
|
@@ -309,6 +316,7 @@ def verify(
|
|
|
309
316
|
"fingerprint": result.fingerprint,
|
|
310
317
|
"trust": trust_label,
|
|
311
318
|
"signed_at": result.signed_at,
|
|
319
|
+
"timestamp": result.timestamp,
|
|
312
320
|
"identity": result.identity,
|
|
313
321
|
"approvals": [
|
|
314
322
|
{"role": a.role, "approver": a.approver, "key": a.key_fingerprint}
|
|
@@ -331,7 +339,11 @@ def verify(
|
|
|
331
339
|
):
|
|
332
340
|
if identity.get(field_name):
|
|
333
341
|
click.echo(f" {label + ':':<13} {identity[field_name]}")
|
|
334
|
-
click.echo(f" Signed: {result.signed_at} (
|
|
342
|
+
click.echo(f" Signed: {result.signed_at} (self-reported metadata)")
|
|
343
|
+
if result.timestamp:
|
|
344
|
+
click.echo(f" TSA time: {result.timestamp['gen_time']} (envelope existed by this time)")
|
|
345
|
+
else:
|
|
346
|
+
click.echo(" Timestamp: not verified")
|
|
335
347
|
click.echo(f" Key: {result.fingerprint} ({trust_label})")
|
|
336
348
|
for approval in approvals:
|
|
337
349
|
who = approval.approver or approval.trusted_alias or approval.key_fingerprint
|
|
@@ -596,7 +608,9 @@ def lineage(model_path, sig_path, search, pubkey_path, require_complete, output_
|
|
|
596
608
|
@click.option("--role", required=True, help="What is being approved, e.g. 'release-manager'.")
|
|
597
609
|
@click.option("--approver", default="", help="Who is approving, for the record.")
|
|
598
610
|
@click.option("--sig", "sig_path", default=None, help="Path to .sig file (default: MODEL.sig).")
|
|
599
|
-
|
|
611
|
+
@click.option("--timestamp", default=None, help="RFC 3161 TSA URL (requires --tsa-ca).")
|
|
612
|
+
@click.option("--tsa-ca", default=None, help="Trusted TSA CA PEM bundle.")
|
|
613
|
+
def approve(model_path, key_path, role, approver, sig_path, timestamp, tsa_ca):
|
|
600
614
|
"""Countersign a model's signature as an approver.
|
|
601
615
|
|
|
602
616
|
An approval is appended to the .sig and signed over that signature's
|
|
@@ -613,6 +627,8 @@ def approve(model_path, key_path, role, approver, sig_path):
|
|
|
613
627
|
role=role,
|
|
614
628
|
approver=approver,
|
|
615
629
|
sig_path=sig_path,
|
|
630
|
+
timestamp=timestamp,
|
|
631
|
+
tsa_ca=tsa_ca,
|
|
616
632
|
)
|
|
617
633
|
except (ApprovalError, VerifyError, ValueError) as e:
|
|
618
634
|
click.echo(f"Error: {e}", err=True)
|
|
@@ -46,6 +46,8 @@ def require_verified(
|
|
|
46
46
|
keyring_dir: Path | str | None = None,
|
|
47
47
|
allow_embedded: bool = False,
|
|
48
48
|
allow_unbound_names: bool = False,
|
|
49
|
+
require_timestamp: bool = False,
|
|
50
|
+
tsa_ca: Path | str | None = None,
|
|
49
51
|
) -> VerifyResult:
|
|
50
52
|
"""Verify a model or raise :class:`LoadBlocked`.
|
|
51
53
|
|
|
@@ -66,6 +68,8 @@ def require_verified(
|
|
|
66
68
|
keyring_dir=keyring_dir,
|
|
67
69
|
require_trusted=not allow_embedded,
|
|
68
70
|
require_name_binding=not allow_unbound_names,
|
|
71
|
+
require_timestamp=require_timestamp,
|
|
72
|
+
tsa_ca=tsa_ca,
|
|
69
73
|
)
|
|
70
74
|
except VerifyError as e:
|
|
71
75
|
raise LoadBlocked(f"refused {Path(model_path).name}: {e}") from e
|
|
@@ -99,9 +103,13 @@ class _HubGuard:
|
|
|
99
103
|
keyring_dir=self.policy.get("keyring_dir"),
|
|
100
104
|
allow_embedded=bool(self.policy.get("allow_embedded", False)),
|
|
101
105
|
allow_unbound_names=bool(self.policy.get("allow_unbound_names", False)),
|
|
106
|
+
require_timestamp=bool(self.policy.get("require_timestamp", False)),
|
|
107
|
+
tsa_ca=self.policy.get("tsa_ca"),
|
|
102
108
|
)
|
|
103
109
|
|
|
104
110
|
def _check_oms(self, path: Path, bundle: Path) -> None:
|
|
111
|
+
if self.policy.get("require_timestamp"):
|
|
112
|
+
raise LoadBlocked("RFC 3161 timestamp policy is not supported for OMS bundles")
|
|
105
113
|
try:
|
|
106
114
|
result = verify_bundle(
|
|
107
115
|
path,
|
|
@@ -118,7 +126,7 @@ class _HubGuard:
|
|
|
118
126
|
)
|
|
119
127
|
|
|
120
128
|
def _unsigned(self, path: Path, unsigned: list[Path] | None = None) -> None:
|
|
121
|
-
if self.allow_unsigned:
|
|
129
|
+
if self.allow_unsigned and not self.policy.get("require_timestamp"):
|
|
122
130
|
return
|
|
123
131
|
if unsigned:
|
|
124
132
|
names = ", ".join(sorted(str(f.relative_to(path)) for f in unsigned[:5]))
|
|
@@ -386,6 +394,8 @@ def install(
|
|
|
386
394
|
allow_embedded: bool = False,
|
|
387
395
|
allow_unsigned: bool = False,
|
|
388
396
|
allow_unbound_names: bool = False,
|
|
397
|
+
require_timestamp: bool = False,
|
|
398
|
+
tsa_ca: Path | str | None = None,
|
|
389
399
|
allow_per_file: bool = False,
|
|
390
400
|
cover_local: bool = True,
|
|
391
401
|
) -> None:
|
|
@@ -412,6 +422,8 @@ def install(
|
|
|
412
422
|
"allow_unbound_names": allow_unbound_names,
|
|
413
423
|
"allow_per_file": allow_per_file,
|
|
414
424
|
"cover_local": cover_local,
|
|
425
|
+
"require_timestamp": require_timestamp,
|
|
426
|
+
"tsa_ca": tsa_ca,
|
|
415
427
|
}
|
|
416
428
|
|
|
417
429
|
if _active is not None:
|
|
@@ -32,6 +32,7 @@ class SigFile:
|
|
|
32
32
|
identity: dict
|
|
33
33
|
manifest: Optional[dict] = None
|
|
34
34
|
approvals: Optional[list] = None
|
|
35
|
+
timestamp: Optional[dict] = None
|
|
35
36
|
|
|
36
37
|
|
|
37
38
|
def write_sig(sig: SigFile, path: Path) -> None:
|
|
@@ -93,6 +94,7 @@ def read_sig(path: Path, validate_fingerprint: bool = False) -> SigFile:
|
|
|
93
94
|
identity=data["identity"],
|
|
94
95
|
manifest=data.get("manifest"),
|
|
95
96
|
approvals=data.get("approvals"),
|
|
97
|
+
timestamp=data.get("timestamp"),
|
|
96
98
|
)
|
|
97
99
|
|
|
98
100
|
if validate_fingerprint:
|
|
@@ -132,13 +134,13 @@ def sig_digest(sig: "SigFile | Path | str") -> str:
|
|
|
132
134
|
if not isinstance(sig, SigFile):
|
|
133
135
|
sig = read_sig(Path(sig))
|
|
134
136
|
|
|
135
|
-
# Everything the signature is, except
|
|
137
|
+
# Everything the signature is, except approvals and timestamps appended later —
|
|
136
138
|
# those must not change a digest that children already recorded. The full
|
|
137
139
|
# public key is included rather than the 8-hex display fingerprint, which
|
|
138
140
|
# is 32 bits and not collision-resistant.
|
|
139
141
|
payload = {
|
|
140
142
|
k: v
|
|
141
143
|
for k, v in asdict(sig).items()
|
|
142
|
-
if k
|
|
144
|
+
if k not in ("approvals", "timestamp") and v is not None
|
|
143
145
|
}
|
|
144
146
|
return "sha256:" + hashlib.sha256(canonical_json(payload)).hexdigest()
|