modelsign 1.1.0__tar.gz → 1.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.
Files changed (69) hide show
  1. {modelsign-1.1.0 → modelsign-1.3.0}/.github/workflows/ci.yml +1 -1
  2. modelsign-1.3.0/CHANGELOG.md +49 -0
  3. {modelsign-1.1.0 → modelsign-1.3.0}/PKG-INFO +58 -2
  4. {modelsign-1.1.0 → modelsign-1.3.0}/README.md +53 -1
  5. modelsign-1.3.0/docs/attestation.md +108 -0
  6. modelsign-1.3.0/docs/aws-kms.md +93 -0
  7. modelsign-1.3.0/docs/reviews/2026-12-03-v1.3.0.md +47 -0
  8. modelsign-1.3.0/docs/security-policy-follow-ons.md +30 -0
  9. modelsign-1.3.0/docs/superpowers/plans/2026-12-03-kms.md +11 -0
  10. modelsign-1.3.0/docs/superpowers/plans/2026-12-03-rfc3161.md +29 -0
  11. modelsign-1.3.0/docs/superpowers/specs/2026-12-03-kms-design.md +37 -0
  12. modelsign-1.3.0/docs/superpowers/specs/2026-12-03-rfc3161-design.md +31 -0
  13. modelsign-1.3.0/docs/timestamps.md +108 -0
  14. {modelsign-1.1.0 → modelsign-1.3.0}/pyproject.toml +10 -0
  15. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/__init__.py +1 -1
  16. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/api.py +59 -2
  17. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/approvals.py +19 -3
  18. modelsign-1.3.0/src/modelsign/attest.py +392 -0
  19. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/cli.py +133 -12
  20. modelsign-1.3.0/src/modelsign/crypto/aws_kms.py +80 -0
  21. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/crypto/keys.py +41 -7
  22. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/crypto/sign.py +15 -3
  23. modelsign-1.3.0/src/modelsign/crypto/signers.py +28 -0
  24. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/guard.py +13 -1
  25. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/sig.py +23 -5
  26. modelsign-1.3.0/src/modelsign/timestamps.py +227 -0
  27. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign.egg-info/PKG-INFO +58 -2
  28. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign.egg-info/SOURCES.txt +18 -1
  29. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign.egg-info/requires.txt +6 -0
  30. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_api.py +22 -0
  31. modelsign-1.3.0/tests/test_attest.py +277 -0
  32. modelsign-1.3.0/tests/test_digest_binding_review.py +42 -0
  33. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_keys.py +49 -0
  34. modelsign-1.3.0/tests/test_kms.py +224 -0
  35. modelsign-1.3.0/tests/test_timestamps.py +361 -0
  36. modelsign-1.1.0/CHANGELOG.md +0 -18
  37. {modelsign-1.1.0 → modelsign-1.3.0}/.github/FUNDING.yml +0 -0
  38. {modelsign-1.1.0 → modelsign-1.3.0}/.gitignore +0 -0
  39. {modelsign-1.1.0 → modelsign-1.3.0}/LICENSE +0 -0
  40. {modelsign-1.1.0 → modelsign-1.3.0}/action.yml +0 -0
  41. {modelsign-1.1.0 → modelsign-1.3.0}/setup.cfg +0 -0
  42. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/crypto/__init__.py +0 -0
  43. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/crypto/verify.py +0 -0
  44. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/formats/__init__.py +0 -0
  45. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/formats/directory.py +0 -0
  46. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/formats/single.py +0 -0
  47. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/identity/__init__.py +0 -0
  48. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/identity/canonical.py +0 -0
  49. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/identity/card.py +0 -0
  50. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/lineage.py +0 -0
  51. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/middleware/__init__.py +0 -0
  52. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/middleware/response.py +0 -0
  53. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign/oms.py +0 -0
  54. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign.egg-info/dependency_links.txt +0 -0
  55. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign.egg-info/entry_points.txt +0 -0
  56. {modelsign-1.1.0 → modelsign-1.3.0}/src/modelsign.egg-info/top_level.txt +0 -0
  57. {modelsign-1.1.0 → modelsign-1.3.0}/tests/conftest.py +0 -0
  58. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_approvals.py +0 -0
  59. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_canonical.py +0 -0
  60. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_card.py +0 -0
  61. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_cli.py +0 -0
  62. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_formats.py +0 -0
  63. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_guard.py +0 -0
  64. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_integration.py +0 -0
  65. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_lineage.py +0 -0
  66. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_middleware.py +0 -0
  67. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_oms.py +0 -0
  68. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_sig.py +0 -0
  69. {modelsign-1.1.0 → modelsign-1.3.0}/tests/test_sign_verify.py +0 -0
@@ -36,7 +36,7 @@ jobs:
36
36
  python-version: ${{ matrix.python-version }}
37
37
 
38
38
  - name: Install dependencies
39
- run: pip install -e ".[dev]"
39
+ run: pip install -e ".[dev,timestamp,aws-kms]"
40
40
 
41
41
  - name: Run tests
42
42
  run: pytest tests/ -v --tb=short
@@ -0,0 +1,49 @@
1
+ # Changelog
2
+
3
+ ## v1.3.0 (2026-12-03)
4
+
5
+ - Optional AWS KMS Ed25519 signing for models and approvals; pinned key/algorithm,
6
+ local verification of responses, offline verification, optional SDK dependency.
7
+ Experimental: tested through the SDK boundary, not against a live AWS key.
8
+ - Reject malformed attestation schemas and handle invalid Unicode as a controlled error.
9
+ - Malformed signature metadata fails verification instead of raising during digest generation.
10
+ - Key generation refuses incomplete or mismatched pairs, uses exclusive creation,
11
+ and restricts private-key permissions from the moment of creation.
12
+ - Keyring aliases cannot escape their directory; writes validate keys, reject symlink
13
+ destinations, and atomically replace entries without modifying hardlinked files.
14
+
15
+ - Runtime attestations (`modelsign.attest`): a serving process signs, per output,
16
+ a statement naming the verified model's signature digest and the output's hash.
17
+ - `VerifyResult.signature_digest` and `signer_key` (the key that verified), set on success.
18
+ - Attestations bind the verifying key, computed hash and identity hash; the
19
+ signature digest is carried as a label only, since it spans unauthenticated fields.
20
+ - `modelsign verify-attestation` for checking one against an output and a `.sig`.
21
+ - An attestation is a claim by the attestor key's holder, not proof of computation.
22
+
23
+ ## v1.2.0 (2026-12-03)
24
+
25
+ - Optional RFC 3161 timestamps binding a model signature and its current approval chain.
26
+ - `sign`/`approve --timestamp URL --tsa-ca FILE`; failures preserve the existing signature.
27
+ - Offline `verify --require-timestamp` and matching direct/installed guard policy.
28
+ - Explicit TSA roots, OpenSSL 3 verification, optional `timestamp` extra.
29
+ - Bounded HTTP responses and a hard total network deadline.
30
+ - Existing model signatures and lineage digests remain compatible.
31
+ - Tested with local test authorities and the external FreeTSA service.
32
+ - Timestamps do not implement revocation, archival validation or rollback prevention.
33
+
34
+ ## v1.0.0 (2026-03-25)
35
+
36
+ Initial release.
37
+
38
+ ### Features
39
+
40
+ - **Ed25519 model signing** with domain-prefixed messages (`modelsign-v1:`)
41
+ - **Model Identity Card** — structured, signed metadata (architecture, base model, training, eval metrics, provenance)
42
+ - **RFC 8785 canonical JSON** for deterministic, cross-platform signature verification
43
+ - **Streaming SHA-256** for large model files (1MB chunks, no full-file memory load)
44
+ - **Directory support** — sign multi-file models with recursive manifests
45
+ - **TOFU keyring** — trust-on-first-use with persistent trusted key store
46
+ - **CLI commands**: `sign`, `verify`, `inspect`, `keygen`, `keyring`, `version`
47
+ - **Python SDK** — all modules independently importable
48
+ - **Response signing middleware** (optional) for API endpoint authenticity
49
+ - **Version migration policy** — forward-compatible .sig format with semver checks
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: modelsign
3
- Version: 1.1.0
3
+ Version: 1.3.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,10 @@ 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"
27
+ Provides-Extra: aws-kms
28
+ Requires-Dist: boto3>=1.40.0; extra == "aws-kms"
25
29
  Provides-Extra: dev
26
30
  Requires-Dist: pytest>=7.0; extra == "dev"
27
31
  Requires-Dist: pytest-cov; extra == "dev"
@@ -212,6 +216,41 @@ them, and `--min-approvals` counts **distinct** approvers: one person in two
212
216
  roles is one person. Pinning specific approvers (`require_approval(keys=...)`)
213
217
  takes public key PEM paths or key bytes, not fingerprints.
214
218
 
219
+ ## Runtime attestations
220
+
221
+ A model signature says what the weights are, not which weights answered a
222
+ request. A serving process can close that gap by signing, for each output, a
223
+ statement that names the model it verified at load:
224
+
225
+ ```python
226
+ from modelsign.guard import require_verified
227
+ from modelsign.attest import Attestor, verify_attestation
228
+
229
+ result = require_verified("./model", pubkey="vendor.pem")
230
+ attestor = Attestor(result, key="serving.pem") # refuses an unverified model
231
+
232
+ attestation = attestor.attest(response_body, request=request_body) # log it, or return it
233
+ ```
234
+
235
+ ```bash
236
+ modelsign verify-attestation att.json --pubkey serving_pub.pem \
237
+ --output response.bin --model-sig model.sig --model-pubkey vendor.pem
238
+ ```
239
+
240
+ The statement carries what verification established about the model — the key
241
+ it verified under, the weights' hash and the hash of the identity card — plus
242
+ the SHA-256 of the output and optionally of the request, a nonce and the
243
+ attestor's key. `--model-pubkey` is what ties the attested model to a signer
244
+ you trust; `--model-sig` alone compares a label. It holds hashes
245
+ only, never the content. See [docs/attestation.md](docs/attestation.md) for
246
+ the exact format.
247
+
248
+ Be precise about what this proves: an attestation is a signed **claim by
249
+ whoever holds the serving key** that this output came from that model, and
250
+ evidence that neither was altered afterwards. It is not proof the computation
251
+ happened, which needs trusted hardware, and `issued_at` is the server's own
252
+ clock.
253
+
215
254
  ## OpenSSF Model Signing interoperability
216
255
 
217
256
  ```bash
@@ -318,9 +357,26 @@ Use OMS when you need keyless signing tied to a CI identity, a transparency log,
318
357
 
319
358
  - Key compromise — your key, your responsibility
320
359
  - Model safety, fairness, or legal compliance
321
- - Cryptographic timestamping; `signed_at` is metadata, not proof (no RFC 3161 timestamp)
360
+ - Revocation and historical archive validation; `signed_at` remains metadata. Optional RFC 3161 envelope timestamps are described below.
322
361
  - Pickle and deserialization attacks inside a correctly signed file
323
362
 
324
363
  ## License
325
364
 
326
365
  Apache 2.0
366
+
367
+ ## RFC 3161 timestamps (v1.2.0)
368
+
369
+ Optional timestamps bind the model signature and current approval chain to a
370
+ trusted TSA time. See [the timestamp guide](docs/timestamps.md) for installation,
371
+ `--timestamp`, `--require-timestamp`, explicit CA trust and offline verification.
372
+ Install with `pip install "modelsign[timestamp]==1.3.0"` and OpenSSL 3. `signed_at` remains
373
+ self-reported; timestamps do not implement key revocation or prevent replay of
374
+ older valid releases.
375
+
376
+ ## AWS KMS signing (experimental, v1.3.0)
377
+
378
+ An optional AWS KMS backend signs through an existing pure-Ed25519 key while
379
+ keeping verification offline. See [the KMS guide](docs/aws-kms.md) for the signer
380
+ interface, optional SDK extra, IAM requirements and 4,096-byte signing-message
381
+ limit. This backend has SDK-contract tests, not live AWS validation, and is
382
+ available through `pip install "modelsign[aws-kms]==1.3.0"`.
@@ -182,6 +182,41 @@ them, and `--min-approvals` counts **distinct** approvers: one person in two
182
182
  roles is one person. Pinning specific approvers (`require_approval(keys=...)`)
183
183
  takes public key PEM paths or key bytes, not fingerprints.
184
184
 
185
+ ## Runtime attestations
186
+
187
+ A model signature says what the weights are, not which weights answered a
188
+ request. A serving process can close that gap by signing, for each output, a
189
+ statement that names the model it verified at load:
190
+
191
+ ```python
192
+ from modelsign.guard import require_verified
193
+ from modelsign.attest import Attestor, verify_attestation
194
+
195
+ result = require_verified("./model", pubkey="vendor.pem")
196
+ attestor = Attestor(result, key="serving.pem") # refuses an unverified model
197
+
198
+ attestation = attestor.attest(response_body, request=request_body) # log it, or return it
199
+ ```
200
+
201
+ ```bash
202
+ modelsign verify-attestation att.json --pubkey serving_pub.pem \
203
+ --output response.bin --model-sig model.sig --model-pubkey vendor.pem
204
+ ```
205
+
206
+ The statement carries what verification established about the model — the key
207
+ it verified under, the weights' hash and the hash of the identity card — plus
208
+ the SHA-256 of the output and optionally of the request, a nonce and the
209
+ attestor's key. `--model-pubkey` is what ties the attested model to a signer
210
+ you trust; `--model-sig` alone compares a label. It holds hashes
211
+ only, never the content. See [docs/attestation.md](docs/attestation.md) for
212
+ the exact format.
213
+
214
+ Be precise about what this proves: an attestation is a signed **claim by
215
+ whoever holds the serving key** that this output came from that model, and
216
+ evidence that neither was altered afterwards. It is not proof the computation
217
+ happened, which needs trusted hardware, and `issued_at` is the server's own
218
+ clock.
219
+
185
220
  ## OpenSSF Model Signing interoperability
186
221
 
187
222
  ```bash
@@ -288,9 +323,26 @@ Use OMS when you need keyless signing tied to a CI identity, a transparency log,
288
323
 
289
324
  - Key compromise — your key, your responsibility
290
325
  - Model safety, fairness, or legal compliance
291
- - Cryptographic timestamping; `signed_at` is metadata, not proof (no RFC 3161 timestamp)
326
+ - Revocation and historical archive validation; `signed_at` remains metadata. Optional RFC 3161 envelope timestamps are described below.
292
327
  - Pickle and deserialization attacks inside a correctly signed file
293
328
 
294
329
  ## License
295
330
 
296
331
  Apache 2.0
332
+
333
+ ## RFC 3161 timestamps (v1.2.0)
334
+
335
+ Optional timestamps bind the model signature and current approval chain to a
336
+ trusted TSA time. See [the timestamp guide](docs/timestamps.md) for installation,
337
+ `--timestamp`, `--require-timestamp`, explicit CA trust and offline verification.
338
+ Install with `pip install "modelsign[timestamp]==1.3.0"` and OpenSSL 3. `signed_at` remains
339
+ self-reported; timestamps do not implement key revocation or prevent replay of
340
+ older valid releases.
341
+
342
+ ## AWS KMS signing (experimental, v1.3.0)
343
+
344
+ An optional AWS KMS backend signs through an existing pure-Ed25519 key while
345
+ keeping verification offline. See [the KMS guide](docs/aws-kms.md) for the signer
346
+ interface, optional SDK extra, IAM requirements and 4,096-byte signing-message
347
+ limit. This backend has SDK-contract tests, not live AWS validation, and is
348
+ available through `pip install "modelsign[aws-kms]==1.3.0"`.
@@ -0,0 +1,108 @@
1
+ # Runtime attestations
2
+
3
+ `modelsign.attest` binds a served output to the signed model behind it.
4
+
5
+ ## Making one
6
+
7
+ ```python
8
+ from modelsign.guard import require_verified
9
+ from modelsign.attest import Attestor
10
+
11
+ result = require_verified("./model", pubkey="vendor.pem")
12
+ attestor = Attestor(result, key="serving.pem")
13
+ attestation = attestor.attest(response_body, request=request_body)
14
+ ```
15
+
16
+ `Attestor` is built from a `VerifyResult` and refuses one that did not verify,
17
+ one that verified only against its own embedded key (`allow_untrusted=True`
18
+ opts out, and the statement then records `"trust": "embedded"`), and one with
19
+ no modelsign signature digest, such as an OMS bundle. Use a serving key that
20
+ is not the model-signing key: the two make different claims.
21
+
22
+ ## Format
23
+
24
+ ```json
25
+ {
26
+ "statement": {
27
+ "type": "modelsign-attestation",
28
+ "version": 1,
29
+ "model": {
30
+ "signer_key": "<base64 raw Ed25519 key the model verified under>",
31
+ "sha256": "sha256:<model or manifest hash, as computed>",
32
+ "identity_sha256": "sha256:<canonical JSON of the signed identity card>",
33
+ "name": "<name from the signed identity card>",
34
+ "trust": "pubkey | keyring | embedded",
35
+ "signature_digest": "sha256:<sig_digest of the model's .sig>"
36
+ },
37
+ "output_sha256": "sha256:<hex>",
38
+ "request_sha256": "sha256:<hex>",
39
+ "issued_at": "2026-12-03T17:00:00Z",
40
+ "nonce": "<32 hex chars>",
41
+ "attestor_key": "<base64 raw Ed25519 public key>"
42
+ },
43
+ "signature": "<base64 Ed25519 signature>"
44
+ }
45
+ ```
46
+
47
+ The signature is over `b"modelsign-attestation-v1\x00" + canonical_json(statement)`,
48
+ with RFC 8785 canonical JSON. `request_sha256` is present only when a request
49
+ was given.
50
+
51
+ `signer_key`, `sha256` and `identity_sha256` are the values verification
52
+ established: the key that did the verifying (not the one embedded in the
53
+ `.sig`), the hash computed from the bytes on disk, and the identity card the
54
+ signature covers. `signature_digest` is the digest lineage and approvals use.
55
+ It locates the `.sig`, but it also spans fields the model signature does not
56
+ authenticate (`signed_at`, the embedded public key, the `file` label, the
57
+ manifest listing), so someone able to edit the `.sig` can change it without
58
+ breaking verification. Treat it as a label, not as the binding.
59
+
60
+ Content is hashed as follows: `bytes` as they are, `str` as UTF-8, and any
61
+ other JSON value as its canonical encoding. The verifier must supply the same
62
+ form the server hashed.
63
+
64
+ ## Checking one
65
+
66
+ ```python
67
+ from modelsign.attest import verify_attestation
68
+
69
+ r = verify_attestation(attestation, pubkey="serving_pub.pem",
70
+ output=response_body, request=request_body,
71
+ model_sig="model.sig", model_pubkey="vendor.pem")
72
+ r.verified, r.output_checked, r.request_checked, r.model_checked, r.signer_checked
73
+ ```
74
+
75
+ ```bash
76
+ modelsign verify-attestation att.json --pubkey serving_pub.pem \
77
+ --output response.bin --request request.bin \
78
+ --model-sig model.sig --model-pubkey vendor.pem --json
79
+ ```
80
+
81
+ The key inside the attestation is never used to verify it; it must equal the
82
+ key you supply, compared on whole key bytes, and a non-canonical base64
83
+ encoding is refused. A bad attestation is a falsy result rather than an
84
+ exception. The signature alone shows the attestor made *some* statement, so
85
+ the result records which of output, request, model and signer were actually
86
+ compared. `model_sig` alone is compared as a label; with `model_pubkey` the
87
+ attested signer must be that key and the `.sig` must verify under it.
88
+ The CLI reads `--output` and `--request` as raw bytes.
89
+
90
+ ## What it does and does not establish
91
+
92
+ Established, given trust in the attestor key: its holder stated that this
93
+ output (and request) came from the model with this signature digest, and
94
+ neither the statement nor the hashed content has changed since.
95
+
96
+ Not established:
97
+
98
+ - that the computation happened as claimed. Whoever holds the serving key can
99
+ sign any statement; this format supplies no independent proof of execution.
100
+ - when it happened. `issued_at` is the attestor's own clock.
101
+ - that the model's signature is itself trustworthy. Check the `.sig` with
102
+ `modelsign verify` under your own key and approval policy.
103
+ - uniqueness. The nonce makes two attestations of one output distinct; it does
104
+ not stop an attestation from being presented twice.
105
+
106
+ Verification validates required v1 fields, digest encodings, nonce shape, and
107
+ the UTC timestamp syntax even for a signature-only check. Timestamp syntax
108
+ validation does not establish freshness or trust in the serving clock.
@@ -0,0 +1,93 @@
1
+ # AWS KMS signing (experimental)
2
+
3
+ Install with `pip install 'modelsign[aws-kms]==1.3.0'`. This backend has
4
+ SDK-contract tests but has not been validated against a live AWS key.
5
+ It uses an **existing** AWS KMS
6
+ `ECC_NIST_EDWARDS25519` / `SIGN_VERIFY` key and the `ED25519_SHA_512` algorithm.
7
+ It does not create keys, alter IAM, upload PEM keys, or fall back to a local key.
8
+
9
+ Authentication follows boto3's normal credential chain (for example a configured
10
+ profile, environment, or workload role). Use an approved account and region.
11
+ The principal needs `kms:GetPublicKey` and `kms:Sign` on the selected key.
12
+ AWS charges and regional algorithm availability are governed by your AWS account.
13
+
14
+ ```bash
15
+ modelsign sign model.safetensors --name Example \
16
+ --kms-key-id arn:aws:kms:REGION:ACCOUNT:key/KEY-ID --aws-region REGION
17
+ modelsign approve model.safetensors --role release \
18
+ --kms-key-id arn:aws:kms:REGION:ACCOUNT:key/APPROVER-KEY-ID --aws-region REGION
19
+ ```
20
+
21
+ `--key` and `--kms-key-id` are mutually exclusive. `--aws-region` requires the KMS
22
+ option; otherwise the SDK can choose a region from your configuration. Aliases
23
+ are accepted, but resolved once to a key ARN: each signer instance pins that ARN
24
+ and its exported public key, so alias retargeting does not change the instance.
25
+
26
+ The existing timestamp flags can be combined with KMS signing; install both
27
+ extras with `pip install 'modelsign[aws-kms,timestamp]==1.3.0'` and provide the TSA CA bundle.
28
+
29
+ ```python
30
+ from modelsign.api import sign_model
31
+ from modelsign.approvals import approve
32
+ from modelsign.crypto.aws_kms import AwsKmsSigner
33
+
34
+ signer = AwsKmsSigner("alias/modelsign", region_name="us-east-1")
35
+ sign_model("model.safetensors", name="Example", signer=signer)
36
+ approve("model.safetensors", role="release", signer=signer)
37
+ ```
38
+
39
+ ## Public key and verification
40
+
41
+ Obtain and authenticate the public key through your deployment's trusted channel.
42
+ For example, an administrator using their authenticated AWS account can export it:
43
+
44
+ ```python
45
+ from pathlib import Path
46
+ from cryptography.hazmat.primitives import serialization
47
+ from modelsign.crypto.aws_kms import AwsKmsSigner
48
+
49
+ signer = AwsKmsSigner("YOUR_KEY_ARN", region_name="YOUR_REGION")
50
+ Path("publisher-public.pem").write_bytes(signer.public_key().public_bytes(
51
+ serialization.Encoding.PEM, serialization.PublicFormat.SubjectPublicKeyInfo))
52
+ ```
53
+
54
+ Distribute that public key through an independently trusted channel. Verifiers
55
+ use the existing command, offline and without boto3 or AWS credentials:
56
+
57
+ ```bash
58
+ modelsign verify model.safetensors --pubkey publisher-public.pem
59
+ ```
60
+
61
+ An ARN is not a cryptographic trust anchor. Neither the ARN nor credentials are
62
+ automatically added to the identity card. KMS signs the exact ModelSign message:
63
+ the model hash and identity-card contents (or approval fields) go to AWS; model
64
+ weights and the signing private key do not leave their respective locations.
65
+
66
+ ## Compatibility and failure behavior
67
+
68
+ The signer interface exposes `public_key()` and `sign(message)` using pure Ed25519.
69
+ Local PEM keys and loaded Ed25519 keys remain supported. Model signature format,
70
+ approval messages, lineage, timestamp binding and offline verification stay the
71
+ same. Each returned signature is checked locally against the key embedded in the
72
+ result before a file is written.
73
+
74
+ AWS accepts at most **4,096 bytes** in RAW mode. That limit applies to the full
75
+ ModelSign signing message, including the identity card, not the model file.
76
+ Large cards are rejected with a clear error. This backend never substitutes a
77
+ prehashed message or Ed25519ph, which would break existing verification.
78
+
79
+ Unsupported keys, unexpected response key/algorithm, invalid returned signatures,
80
+ and service failures fail closed. Existing signature files are preserved on
81
+ signing or timestamp-request failure. SDK clients created by this backend use
82
+ 5-second connect and 15-second read timeouts with at most two attempts; caller-
83
+ supplied SDK clients retain their own configuration.
84
+
85
+ ## Test status
86
+
87
+ The implementation is tested using botocore Stubber with exact request parameters
88
+ and real local Ed25519 signatures returned at the SDK boundary. This exercises
89
+ local verification and policy, but **is not a live AWS KMS interoperability test**.
90
+ No production AWS account or key has been provisioned or used for this branch.
91
+
92
+ References: [AWS Sign](https://docs.aws.amazon.com/kms/latest/APIReference/API_Sign.html),
93
+ [AWS GetPublicKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_GetPublicKey.html).
@@ -0,0 +1,47 @@
1
+ # v1.3.0 release review
2
+
3
+ Scope: combined runtime attestations, optional AWS KMS signing, timestamp composition,
4
+ malformed-input handling, and the key-management paths used by these features.
5
+
6
+ ## Findings resolved
7
+
8
+ - Attestation verification accepted signed malformed statements with missing or invalid
9
+ required hashes, nonce, clock syntax, trust label, or non-integer version. These now fail.
10
+ - Lone-surrogate output text escaped the content-error boundary. It now produces a
11
+ controlled error on creation and a failed verification result on checking.
12
+ - Canonicalization of unsigned model-signature metadata could raise after successful
13
+ cryptographic verification. Envelope canonicalization now runs inside the malformed-input handler.
14
+ - Key generation could overwrite one half of an existing pair. Incomplete/mismatched
15
+ pairs now fail without replacement; creation is exclusive, with private mode 0600.
16
+ - Keyring aliases allowed path traversal. Aliases now permit only a leading ASCII
17
+ letter/digit followed by letters/digits, underscore, dot, or hyphen.
18
+ - Keyring writes followed destination symlinks/hardlinks. Symlinks are rejected;
19
+ validated PEMs are atomically replaced, preserving outside hardlinked files.
20
+
21
+ Regression tests reproduced failures before fixes. An independent read-only review
22
+ found the malformed-metadata exception; the follow-up review found no additional
23
+ important issues in the reviewed changes.
24
+
25
+ - Signature-reader field types are checked before use; numeric hashes and malformed
26
+ identity/approval/timestamp containers fail instead of crashing or passing through.
27
+
28
+ ## Verification and performance
29
+
30
+ The integrated end-to-end test covers KMS signing and approval (SDK stub with real
31
+ Ed25519 signatures), RFC 3161 timestamps from a local test authority, verified model
32
+ load, output/request attestation, and independent signer checks. Altered content
33
+ and wrong keys are rejected. No model bytes or keys are sent to live AWS.
34
+
35
+ A local Python 3.12 benchmark performed five rounds of 1,000 attest+verify operations
36
+ on a 1 KiB output. Median round-average: 0.113 ms per operation pair. This excludes
37
+ network calls and model inference and is not a cross-platform performance guarantee.
38
+ No cryptographic checks were removed for performance.
39
+
40
+ ## Boundaries
41
+
42
+ This is a bounded source/test review, not a claim that all possible bugs are exhausted.
43
+ The AWS backend remains experimental pending live interoperability validation.
44
+ Serving attestations are signed claims, with no execution proof, freshness policy,
45
+ or replay-prevention state. Caller-owned mutable verification results are not a
46
+ security boundary against code already executing in the serving process. No C2PA,
47
+ revocation feed, transparency log, or monotonic rollback policy is added here.
@@ -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,11 @@
1
+ # KMS implementation plan
2
+
3
+ Spec: ../specs/2026-12-03-kms-design.md
4
+
5
+ - [x] Write failing tests for signer API/approval and AWS SDK contract.
6
+ - [x] Add signer protocol/local resolution and optional AwsKmsSigner; verify returned signatures locally.
7
+ - [x] Add explicit API signer and mutually exclusive CLI AWS options; keep verification offline.
8
+ - [x] Run all tests/type checks, package validation, independent review and fix important findings.
9
+ - [x] Document setup/limitations, commit and push a separate draft PR. Do not publish this backend as a tested live AWS integration.
10
+
11
+ Validation: 277 tests passed; mypy passed for 23 source files; wheel and source archive passed twine check; independent review found no important defects. AWS responses are stubbed; no live AWS account/key was used.
@@ -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,37 @@
1
+ # KMS signing design
2
+
3
+ Scope: provider-neutral Ed25519 signer interface plus an optional AWS KMS backend,
4
+ on a separate branch after RFC 3161. No cloud key creation, IAM changes, automatic
5
+ PEM upload, remote verification dependency, KMS encryption or new signature format.
6
+ AWS is the default selected by Codex after asking for a provider preference.
7
+
8
+ A signer exposes `public_key() -> Ed25519PublicKey` and `sign(message: bytes) -> bytes`.
9
+ Existing loaded Ed25519 keys satisfy this interface; PEM paths keep working. The
10
+ API accepts an explicit `signer` argument mutually exclusive with `key`. The CLI
11
+ exposes `--kms-key-id` and optional `--aws-region` on sign and approve, mutually
12
+ exclusive with local --key. boto3 is an optional `aws-kms` extra, imported only when
13
+ creating an AWS client. Authentication uses the SDK's normal credential chain.
14
+
15
+ AWS backend: GetPublicKey must describe SIGN_VERIFY / ECC_NIST_EDWARDS25519 with
16
+ ED25519_SHA_512 support and valid Ed25519 SPKI. Resolve aliases once, pin the returned
17
+ key ARN, and use that ARN for every Sign call. Sign with MessageType RAW and
18
+ ED25519_SHA_512 only. Never prehash or use Ed25519ph as a workaround for the 4096-byte
19
+ AWS limit: reject oversized ModelSign messages. Require matching response ARN and
20
+ algorithm, then verify the returned signature locally against the pinned key before
21
+ accepting it. Network errors fail closed; no fallback to a local key.
22
+
23
+ Publish only the existing public key/signature fields. A KMS ARN is not a trust
24
+ anchor and is not automatically embedded in the signed identity. Verification stays
25
+ offline with existing trusted public-key policy; it needs neither AWS credentials
26
+ nor boto3. Keep approval messages and timestamp integration identical.
27
+
28
+ Validation: native keys and remote signer agree on messages; real cryptographic
29
+ signatures returned via botocore Stubber, with exact AWS request parameters; API,
30
+ CLI, approve and timestamp composition; alias resolution, wrong key/algorithm/SPKI,
31
+ service denial, missing SDK, invalid returned signature, message size boundary,
32
+ mutually exclusive key selection and preservation of files on failure. A stubbed
33
+ SDK test is not a live AWS integration test. No live account/key is configured or
34
+ created without explicit authorization.
35
+
36
+ References: https://docs.aws.amazon.com/kms/latest/APIReference/API_Sign.html and
37
+ https://docs.aws.amazon.com/kms/latest/APIReference/API_GetPublicKey.html
@@ -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/