codeimprint 0.5.0a30__tar.gz → 0.5.0a31__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.
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/CHANGELOG.md +39 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/PKG-INFO +1 -1
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/pyproject.toml +1 -1
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/__init__.py +1 -1
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/cli.py +71 -13
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/imprint_file.py +12 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/ownership.py +9 -4
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/receipt.py +105 -4
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/records.py +4 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/.gitignore +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/LICENSE +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/NOTICE +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/README.pypi.md +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint/__init__.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint/__main__.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/__main__.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/api.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/chainseal.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/config.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/gitrepo.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/linecount.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/project.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/timestamp.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/transparency.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/trust.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a31}/src/codeimprint_cli/tsa_roots.py +0 -0
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0a31 — Newer formats, expired identities, INT1 v2 [CIM-BE-45-v1]
|
|
4
|
+
|
|
5
|
+
For engine 0.7.0a36.
|
|
6
|
+
|
|
7
|
+
- **New: a seal or record in a newer format than this client is not called a failure.**
|
|
8
|
+
Before any other check, `imprint verify` looks for a receipt format above 4, an attestation
|
|
9
|
+
statement, log entry, checkpoint, timestamps record or record type it
|
|
10
|
+
has never seen (a well-formed `codeimprint.<name>.v<N>`), and an ID with an unknown prefix
|
|
11
|
+
of the known shape (three letters and a digit, such as `IMP2-`). Any of them gives one
|
|
12
|
+
result: `Result NEWER FORMAT` and "This seal uses a newer format than this client
|
|
13
|
+
understands. Upgrade: pip install --pre -U codeimprint" ("This record uses …" for an
|
|
14
|
+
ownership record). It is not verified, and it is not FAIL.
|
|
15
|
+
- **New exit code 3** for that result, and `--json` `status` `"NEWER"` (with `message` and
|
|
16
|
+
`newer`, what was newer). In an automated build (GitHub Actions, GitLab CI, Bitbucket
|
|
17
|
+
Pipelines) it is a warning (`::warning::` in GitHub Actions) and the exit code is 0, so a
|
|
18
|
+
build is never broken by a newer seal. Documented in `imprint verify --help` and in a new
|
|
19
|
+
exit-code table in the README.
|
|
20
|
+
- **New: `--json` of `imprint verify` also has `status`** (`VERIFIED` or `NOT VERIFIED`) next
|
|
21
|
+
to `valid`.
|
|
22
|
+
- A seal or record in a known format that does not verify still FAILs, as before.
|
|
23
|
+
- Sealing, release records, records the client signs and `imprint ownership` give the same
|
|
24
|
+
upgrade message when the server answers in a newer format (sealing: a warning in an
|
|
25
|
+
automated build, as before; `imprint ownership` exits 3). Commands that take a seal's ID
|
|
26
|
+
say it too for an ID with an unknown prefix of the known shape.
|
|
27
|
+
- **Changed: an identity record that has expired is WARN "expired on <date>"** (YYYY-MM-DD),
|
|
28
|
+
not FAIL: it was valid when it was used. The same online (`identity status`). Revoked
|
|
29
|
+
identities, bad signatures and everything else stay as they were.
|
|
30
|
+
- **New: integration authorisations `codeimprint.integration.v2`** (INT1, the same signature
|
|
31
|
+
roles as v1): the GitHub installation and repository are salted commitments, not GitHub's
|
|
32
|
+
IDs. `imprint verify` shows an integration record (v1 or v2) as its own check, which also
|
|
33
|
+
requires the integration and owner signatures to be by the keys the record names; for v2
|
|
34
|
+
"installation and repository: committed (private)". v1 records stay valid.
|
|
35
|
+
- **Changed: `imprint seal --name`** is "a private label for this seal (never in the public
|
|
36
|
+
seal)": the engine no longer writes the name into the sealed Imprint.
|
|
37
|
+
- Tests: `tests/test_newer_format.py`, `tests/test_identity.py`, `tests/test_golden_vectors.py`
|
|
38
|
+
(the identity record of the golden vectors is WARN, not FAIL, in 2036).
|
|
39
|
+
- Tests: a second set of golden vectors (engine 0.7.0a36: an INT1 v2 record and a zip seal made
|
|
40
|
+
with a name), verified now and in 2036 (`tests/test_golden_vectors_2.py`).
|
|
41
|
+
|
|
3
42
|
## 0.5.0a30 — `imprint github link` warns about sealing twice [CIM-BE-44-v1]
|
|
4
43
|
|
|
5
44
|
For engine 0.7.0a35 (works with any engine).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: codeimprint
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.0a31
|
|
4
4
|
Summary: CodeImprint: seal your code with a CodeImprint server (tamper-evident, logged and timestamped) and verify seals offline.
|
|
5
5
|
Project-URL: Homepage, https://codeimprint.ai
|
|
6
6
|
Project-URL: Hub, https://app.codeimprint.ai
|
|
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
|
|
|
6
6
|
# Published on PyPI as `codeimprint`. The import package stays `codeimprint_cli` and the
|
|
7
7
|
# command `imprint`.
|
|
8
8
|
name = "codeimprint"
|
|
9
|
-
version = "0.5.
|
|
9
|
+
version = "0.5.0a31"
|
|
10
10
|
description = "CodeImprint: seal your code with a CodeImprint server (tamper-evident, logged and timestamped) and verify seals offline."
|
|
11
11
|
readme = "README.pypi.md"
|
|
12
12
|
license = "Apache-2.0"
|
|
@@ -267,12 +267,26 @@ def _ci() -> bool:
|
|
|
267
267
|
or bool(env.get("BITBUCKET_BUILD_NUMBER")))
|
|
268
268
|
|
|
269
269
|
|
|
270
|
-
def _warn(message: str) -> None:
|
|
270
|
+
def _warn(message: str, json_out: bool = False) -> None:
|
|
271
|
+
"""A warning; in GitHub Actions also an annotation (on stderr when stdout is JSON)."""
|
|
271
272
|
if os.environ.get("GITHUB_ACTIONS") == "true":
|
|
272
|
-
print(f"::warning::CodeImprint: {message}")
|
|
273
|
+
print(f"::warning::CodeImprint: {message}", file=sys.stderr if json_out else sys.stdout)
|
|
273
274
|
print(f"imprint: warning: {message}", file=sys.stderr)
|
|
274
275
|
|
|
275
276
|
|
|
277
|
+
EXIT_NEWER = 3 # `imprint verify`: a newer format than this client understands
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _newer(checks: list[receipt.Check]) -> receipt.Check | None:
|
|
281
|
+
return next((c for c in checks if c.status == receipt.NEWER), None)
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def _bad_id(text: str, message: str) -> Abort:
|
|
285
|
+
"""The error for an ID that is not of the expected kind; an ID of a newer kind says
|
|
286
|
+
to upgrade instead."""
|
|
287
|
+
return Abort(receipt.newer_message("ID") if imprint_file.is_newer_id(text) else message)
|
|
288
|
+
|
|
289
|
+
|
|
276
290
|
CI_TOKEN_PREFIX = "cit_" # a per-account CI token (`imprint token create`)
|
|
277
291
|
|
|
278
292
|
|
|
@@ -1117,8 +1131,11 @@ def _checked(client: Client, rec: dict, what: str) -> None:
|
|
|
1117
1131
|
if problems:
|
|
1118
1132
|
raise Abort("the server's attestation keys changed unexpectedly (" + "; ".join(problems)
|
|
1119
1133
|
+ ")")
|
|
1120
|
-
|
|
1121
|
-
|
|
1134
|
+
checks = receipt.verify(rec, keys, anchors=_anchors(argparse.Namespace(tsa_certs=None)))
|
|
1135
|
+
newer = _newer(checks)
|
|
1136
|
+
if newer:
|
|
1137
|
+
raise Abort(newer.detail)
|
|
1138
|
+
bad = _failed(checks)
|
|
1122
1139
|
if bad:
|
|
1123
1140
|
raise Abort(f"the {what} does not verify (" + "; ".join(
|
|
1124
1141
|
f"{c.name}: {c.detail}" for c in bad) + ")")
|
|
@@ -1492,10 +1509,11 @@ def cmd_ownership(args) -> int:
|
|
|
1492
1509
|
anchors=_anchors(argparse.Namespace(tsa_certs=None)))
|
|
1493
1510
|
except (ApiError, NetworkError) as exc:
|
|
1494
1511
|
raise Abort(f"cannot read the ownership listing: {exc}") from exc
|
|
1512
|
+
code = 1 if _failed(checks) else EXIT_NEWER if _newer(checks) else 0
|
|
1495
1513
|
if args.json:
|
|
1496
1514
|
print(json.dumps({"ownership": view, "checks": [c.as_dict() for c in checks]},
|
|
1497
1515
|
indent=1))
|
|
1498
|
-
return
|
|
1516
|
+
return code
|
|
1499
1517
|
_say(f"Project {project_id}", f"Ownership {view['label']}")
|
|
1500
1518
|
for label in view.get("licence_claims") or []:
|
|
1501
1519
|
_say(f"Licence {label}")
|
|
@@ -1519,7 +1537,7 @@ def cmd_ownership(args) -> int:
|
|
|
1519
1537
|
"Checked here: every record's receipt and signatures, the claim rules, and each "
|
|
1520
1538
|
"seal's coverage. Not checked: that the server listed every record, the evidence "
|
|
1521
1539
|
"behind identities, organisation key windows, legal validity.")
|
|
1522
|
-
return
|
|
1540
|
+
return code
|
|
1523
1541
|
|
|
1524
1542
|
|
|
1525
1543
|
# -- organisations and contributors (ADR 0002 steps 1.9-1.12) -------------------------------
|
|
@@ -1779,7 +1797,7 @@ def cmd_export(args) -> int:
|
|
|
1779
1797
|
client = _client(args)
|
|
1780
1798
|
iid = imprint_file.clean_id(args.imprint_id)
|
|
1781
1799
|
if not imprint_file.is_valid_id(iid):
|
|
1782
|
-
raise
|
|
1800
|
+
raise _bad_id(iid, f"not a valid Imprint ID: {args.imprint_id}")
|
|
1783
1801
|
try:
|
|
1784
1802
|
doc = client.export(iid)
|
|
1785
1803
|
except (ApiError, NetworkError) as exc:
|
|
@@ -1844,6 +1862,8 @@ def _accept(args, client: Client, result: dict) -> tuple[list, list, list[receip
|
|
|
1844
1862
|
+ "; ".join(problems) + "); not saved")
|
|
1845
1863
|
anchors = _anchors(args)
|
|
1846
1864
|
checks = receipt.verify(result["receipt"], keys, doc, anchors=anchors)
|
|
1865
|
+
if _newer(checks):
|
|
1866
|
+
raise SealFailed(f"{_newer(checks).detail} (not saved)")
|
|
1847
1867
|
bad = _failed(checks)
|
|
1848
1868
|
if bad:
|
|
1849
1869
|
raise SealFailed("the seal does not verify (" + "; ".join(
|
|
@@ -1944,6 +1964,8 @@ def _seal_zip(args, client: Client, data: bytes, project_id: str | None,
|
|
|
1944
1964
|
signer = None
|
|
1945
1965
|
checks = receipt.verify(result["receipt"], keys, result["imprint"],
|
|
1946
1966
|
anchors=_anchors(args))
|
|
1967
|
+
if _newer(checks):
|
|
1968
|
+
raise SealFailed(f"{_newer(checks).detail} (not saved)")
|
|
1947
1969
|
bad = _failed(checks)
|
|
1948
1970
|
if bad:
|
|
1949
1971
|
raise SealFailed("the signed receipt does not verify (" + "; ".join(
|
|
@@ -2046,6 +2068,8 @@ def _finish_release(args, client: Client, root: Path, out: dict, key) -> None:
|
|
|
2046
2068
|
raise SealFailed("the server's attestation keys changed unexpectedly ("
|
|
2047
2069
|
+ "; ".join(problems) + "); not saved")
|
|
2048
2070
|
checks = receipt.verify(rec, keys, None, anchors=_anchors(args))
|
|
2071
|
+
if _newer(checks):
|
|
2072
|
+
raise SealFailed(f"{_newer(checks).detail} (not saved)")
|
|
2049
2073
|
bad = _failed(checks)
|
|
2050
2074
|
if bad:
|
|
2051
2075
|
raise SealFailed("the release record does not verify (" + "; ".join(
|
|
@@ -2576,7 +2600,7 @@ def _engagement_join(args) -> int:
|
|
|
2576
2600
|
def cmd_deliver(args) -> int:
|
|
2577
2601
|
"""`imprint deliver IMP1-… [--note …] [--to-client]`: a vendor delivers a seal."""
|
|
2578
2602
|
if not imprint_file.is_valid_id(args.seal):
|
|
2579
|
-
raise
|
|
2603
|
+
raise _bad_id(args.seal, f"not a fingerprint ID (IMP1-…): {args.seal}")
|
|
2580
2604
|
iid = imprint_file.clean_id(args.seal)
|
|
2581
2605
|
client = _client(args, _server_from_project(Path(".")))
|
|
2582
2606
|
if client.auth in ("none", "expired"):
|
|
@@ -2604,7 +2628,7 @@ def cmd_deliver(args) -> int:
|
|
|
2604
2628
|
def cmd_accept(args) -> int:
|
|
2605
2629
|
"""`imprint accept IMP1-…`: the project owner accepts a seal its vendor delivered."""
|
|
2606
2630
|
if not imprint_file.is_valid_id(args.seal):
|
|
2607
|
-
raise
|
|
2631
|
+
raise _bad_id(args.seal, f"not a fingerprint ID (IMP1-…): {args.seal}")
|
|
2608
2632
|
iid = imprint_file.clean_id(args.seal)
|
|
2609
2633
|
client = _session_client(args)
|
|
2610
2634
|
try:
|
|
@@ -2966,7 +2990,7 @@ def _validity(client: Client, iid: str) -> dict | None:
|
|
|
2966
2990
|
def cmd_certificate(args) -> int:
|
|
2967
2991
|
"""`imprint certificate IMP1-… [-o file.pdf]`: download a seal's certificate (PDF)."""
|
|
2968
2992
|
if not imprint_file.is_valid_id(args.seal):
|
|
2969
|
-
raise
|
|
2993
|
+
raise _bad_id(args.seal, f"not a fingerprint ID (IMP1-…): {args.seal}")
|
|
2970
2994
|
iid = imprint_file.clean_id(args.seal)
|
|
2971
2995
|
client = _client(args, _server_from_project(Path(".")))
|
|
2972
2996
|
# The server answers everyone but the owner like a seal that does not exist, so say here
|
|
@@ -3096,17 +3120,39 @@ def _file_only(doc: dict) -> list[receipt.Check]:
|
|
|
3096
3120
|
"transparency log (run `imprint seal`)")]
|
|
3097
3121
|
|
|
3098
3122
|
|
|
3123
|
+
def _newer_result(args, iid: str | None, why: str, message: str) -> int:
|
|
3124
|
+
"""A seal or record in a newer format than this client: not verified here, and not a
|
|
3125
|
+
failure either (42b-01). Exit code 3; in an automated build a warning and exit 0."""
|
|
3126
|
+
if args.json:
|
|
3127
|
+
print(json.dumps({"imprint_id": iid, "valid": False, "status": receipt.NEWER,
|
|
3128
|
+
"message": message, "newer": why,
|
|
3129
|
+
"checks": [receipt.Check("format", receipt.NEWER, message).as_dict()]},
|
|
3130
|
+
indent=2))
|
|
3131
|
+
else:
|
|
3132
|
+
_say(f"Imprint {iid}", "", f"{receipt.NEWER:<5} {'format':<20} {why}", "",
|
|
3133
|
+
"Result NEWER FORMAT (not verified by this client)", f" {message}")
|
|
3134
|
+
if _ci():
|
|
3135
|
+
_warn(message, json_out=args.json)
|
|
3136
|
+
return 0
|
|
3137
|
+
return EXIT_NEWER
|
|
3138
|
+
|
|
3139
|
+
|
|
3099
3140
|
def cmd_verify(args) -> int:
|
|
3100
3141
|
if not args.target:
|
|
3101
3142
|
default = Path(".imprint") / "baseline.imprint"
|
|
3102
3143
|
if not default.is_file():
|
|
3103
3144
|
args.verify_parser.error("the following arguments are required: target")
|
|
3104
3145
|
args.target = str(default)
|
|
3146
|
+
if not Path(args.target).is_file() and imprint_file.is_newer_id(args.target):
|
|
3147
|
+
iid = imprint_file.clean_id(args.target)
|
|
3148
|
+
return _newer_result(args, iid, f"ID prefix {iid.split('-', 1)[0]}",
|
|
3149
|
+
receipt.newer_message())
|
|
3105
3150
|
doc, rec, root = _load_target(args)
|
|
3106
3151
|
found = getattr(args, "found_opening", None)
|
|
3107
3152
|
checks: list[receipt.Check] = []
|
|
3108
3153
|
state = None # the seal's validity now (--online only)
|
|
3109
|
-
|
|
3154
|
+
why = receipt.newer_format(rec) if rec is not None else None
|
|
3155
|
+
client = _client(args, _server_from_project(root)) if args.online and not why else None
|
|
3110
3156
|
if rec is None and client is not None:
|
|
3111
3157
|
iid = imprint_file.clean_id(args.target) if doc is None else (
|
|
3112
3158
|
imprint_file.verify_document(doc)["id"])
|
|
@@ -3122,6 +3168,10 @@ def cmd_verify(args) -> int:
|
|
|
3122
3168
|
raise Abort(f"no public record for {iid}: {exc}") from exc
|
|
3123
3169
|
except NetworkError as exc:
|
|
3124
3170
|
raise Abort(str(exc)) from exc
|
|
3171
|
+
why = receipt.newer_format(rec) if rec is not None else None
|
|
3172
|
+
if why: # before any other check (42b-01)
|
|
3173
|
+
return _newer_result(args, rec.get("imprint_id"), why, receipt.newer_message(
|
|
3174
|
+
"record" if "record" in rec else "seal"))
|
|
3125
3175
|
opening = _opening_for(args, rec, found)
|
|
3126
3176
|
if rec is None:
|
|
3127
3177
|
checks = _file_only(doc)
|
|
@@ -3164,6 +3214,7 @@ def cmd_verify(args) -> int:
|
|
|
3164
3214
|
elsewhere = any(c.name == "repository" and c.status == receipt.WARN for c in checks)
|
|
3165
3215
|
if args.json:
|
|
3166
3216
|
print(json.dumps({"imprint_id": iid, "valid": valid,
|
|
3217
|
+
"status": "VERIFIED" if valid else "NOT VERIFIED",
|
|
3167
3218
|
"issued_for_this_repository": (
|
|
3168
3219
|
False if elsewhere else True if any(
|
|
3169
3220
|
c.name == "repository" for c in checks) else None),
|
|
@@ -3339,7 +3390,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
3339
3390
|
s = sub.add_parser("seal", help="seal a project on the server; saves .imprint/baseline.imprint "
|
|
3340
3391
|
"and its receipt")
|
|
3341
3392
|
s.add_argument("path", nargs="?", default=".")
|
|
3342
|
-
s.add_argument("--name", help="
|
|
3393
|
+
s.add_argument("--name", help="a private label for this seal (never in the public seal)")
|
|
3343
3394
|
s.add_argument("--hub-url", help="hub for the verify link and badge (default: "
|
|
3344
3395
|
"CODEIMPRINT_HUB_URL, else the hub the server names)")
|
|
3345
3396
|
s.add_argument("-o", "--output", help="where to save the Imprint")
|
|
@@ -3502,7 +3553,14 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
3502
3553
|
c.add_argument("--yes", action="store_true", help="do not ask before uploading (CI)")
|
|
3503
3554
|
c.set_defaults(func=cmd_check)
|
|
3504
3555
|
|
|
3505
|
-
v = sub.add_parser("verify", help="verify a seal offline: .imprint file, receipt or ID"
|
|
3556
|
+
v = sub.add_parser("verify", help="verify a seal offline: .imprint file, receipt or ID",
|
|
3557
|
+
epilog="Exit codes: 0 VERIFIED; 1 NOT VERIFIED (a check failed, or a "
|
|
3558
|
+
"warning with --strict); 2 a usage or other error; 3 a newer "
|
|
3559
|
+
"format than this client understands (\"This seal uses a newer "
|
|
3560
|
+
"format than this client understands. Upgrade: pip install --pre "
|
|
3561
|
+
"-U codeimprint\"; --json status NEWER). In an automated build "
|
|
3562
|
+
"(GitHub Actions, GitLab CI, Bitbucket Pipelines) a newer format "
|
|
3563
|
+
"is a warning and exits 0.")
|
|
3506
3564
|
v.add_argument("target", nargs="?",
|
|
3507
3565
|
help=".imprint file, .receipt.json file or Imprint ID (default: "
|
|
3508
3566
|
".imprint/baseline.imprint in this folder)")
|
|
@@ -10,6 +10,7 @@ from __future__ import annotations
|
|
|
10
10
|
import base64
|
|
11
11
|
import hashlib
|
|
12
12
|
import json
|
|
13
|
+
import re
|
|
13
14
|
from pathlib import Path
|
|
14
15
|
|
|
15
16
|
FORMAT = "imprint"
|
|
@@ -81,6 +82,17 @@ def is_valid_id(text: str, prefixes: tuple[str, ...] = (ID_PREFIX,)) -> bool:
|
|
|
81
82
|
and _check_for(parts[0], body) == parts[5])
|
|
82
83
|
|
|
83
84
|
|
|
85
|
+
def is_newer_id(text: str) -> bool:
|
|
86
|
+
"""An ID of the known shape whose prefix (three letters, then a digit, like IMP2) this
|
|
87
|
+
client does not know: a newer format, not a mistyped or forged ID. Its check character
|
|
88
|
+
cannot be checked here (a new prefix may compute it another way)."""
|
|
89
|
+
parts = clean_id(text).split("-") if isinstance(text, str) else []
|
|
90
|
+
return (len(parts) == 6 and re.fullmatch(r"[A-Z]{3}[0-9]", parts[0]) is not None
|
|
91
|
+
and parts[0] not in ALL_PREFIXES
|
|
92
|
+
and all(len(p) == 4 and set(p) <= set(ALPHABET) for p in parts[1:5])
|
|
93
|
+
and len(parts[5]) == 1 and parts[5] in ALPHABET)
|
|
94
|
+
|
|
95
|
+
|
|
84
96
|
def verify_document(doc: dict) -> dict:
|
|
85
97
|
"""Return a status dict; ``valid`` is True only if every present check passes."""
|
|
86
98
|
if not isinstance(doc, dict) or doc.get("format") != FORMAT:
|
|
@@ -97,7 +97,8 @@ class _Verifier:
|
|
|
97
97
|
self.checks.append(Check(name, FAIL, detail))
|
|
98
98
|
|
|
99
99
|
def record(self, rid: str) -> dict | None:
|
|
100
|
-
"""A verified record receipt (fetched once), or None after a FAIL
|
|
100
|
+
"""A verified record receipt (fetched once), or None after a FAIL (or a record in a
|
|
101
|
+
newer format than this client: not verified here, and not a failure)."""
|
|
101
102
|
if rid in self.cache:
|
|
102
103
|
return self.cache[rid]
|
|
103
104
|
try:
|
|
@@ -106,9 +107,13 @@ class _Verifier:
|
|
|
106
107
|
self.fail(rid, f"cannot fetch: {exc}")
|
|
107
108
|
self.cache[rid] = None
|
|
108
109
|
return None
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if
|
|
110
|
+
checks = receipt.verify(rec, self.keys, anchors=self.anchors)
|
|
111
|
+
newer = next((c for c in checks if c.status == receipt.NEWER), None)
|
|
112
|
+
bad = [c for c in checks if c.status == FAIL]
|
|
113
|
+
if newer:
|
|
114
|
+
self.checks.append(Check(rid, receipt.NEWER, newer.detail))
|
|
115
|
+
rec = None
|
|
116
|
+
elif bad:
|
|
112
117
|
self.fail(rid, "; ".join(f"{c.name}: {c.detail}" for c in bad))
|
|
113
118
|
rec = None
|
|
114
119
|
self.cache[rid] = rec
|
|
@@ -9,6 +9,7 @@ trusts; ``verify_online`` adds the checks that need the server's current log.
|
|
|
9
9
|
from __future__ import annotations
|
|
10
10
|
|
|
11
11
|
import hashlib
|
|
12
|
+
import re
|
|
12
13
|
from dataclasses import asdict, dataclass
|
|
13
14
|
from datetime import datetime, timedelta, timezone
|
|
14
15
|
|
|
@@ -23,6 +24,11 @@ CONFIRM_WITHIN = timedelta(hours=1) # a TSA time further after the seal is r
|
|
|
23
24
|
AGREE_WITHIN = timedelta(hours=1) # valid tokens of one subject further apart: FAIL
|
|
24
25
|
|
|
25
26
|
PASS, FAIL, WARN = "PASS", "FAIL", "WARN"
|
|
27
|
+
# A seal or record in a format newer than this client: not verified here, and never reported
|
|
28
|
+
# as a failure (42b-01). Its own result, exit code and --json status.
|
|
29
|
+
NEWER = "NEWER"
|
|
30
|
+
UPGRADE = "Upgrade: pip install --pre -U codeimprint"
|
|
31
|
+
RECEIPT_VERSION = 4 # the newest receipt format this client reads
|
|
26
32
|
|
|
27
33
|
|
|
28
34
|
@dataclass
|
|
@@ -47,6 +53,57 @@ def checkpoint_digest(checkpoint: dict) -> bytes:
|
|
|
47
53
|
RELEASE = "codeimprint.release.v1"
|
|
48
54
|
|
|
49
55
|
|
|
56
|
+
def newer_message(what: str = "seal") -> str:
|
|
57
|
+
return f"This {what} uses a newer format than this client understands. {UPGRADE}"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# Every statement, entry and document type this client knows. A well-formed type that is not
|
|
61
|
+
# one of them (codeimprint.<name>.v<N>) is a newer format; anything else is malformed.
|
|
62
|
+
KNOWN_TYPES = frozenset({
|
|
63
|
+
"codeimprint.attestation.v1", "codeimprint.attestation.v2", "codeimprint.log-entry.v1",
|
|
64
|
+
"codeimprint.log-entry.v2", "codeimprint.checkpoint.v1", "codeimprint.timestamps.v1",
|
|
65
|
+
RELEASE, "codeimprint.chain-seal.v1", records.RECORD_SIGN, *records.TYPES})
|
|
66
|
+
_TYPE = re.compile(r"codeimprint\.[a-z][a-z0-9-]*\.v[1-9][0-9]*")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _unknown_type(value) -> bool:
|
|
70
|
+
return isinstance(value, str) and bool(_TYPE.fullmatch(value)) and value not in KNOWN_TYPES
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def newer_format(receipt: dict) -> str | None:
|
|
74
|
+
"""What in this receipt is newer than this client knows (receipt format, statement, log
|
|
75
|
+
entry, checkpoint or record type, ID prefix), or None. Checked before anything else: a
|
|
76
|
+
newer seal must not read like a forged one."""
|
|
77
|
+
if not isinstance(receipt, dict):
|
|
78
|
+
return None
|
|
79
|
+
version = receipt.get("version")
|
|
80
|
+
if isinstance(version, int) and not isinstance(version, bool) and version > RECEIPT_VERSION:
|
|
81
|
+
return f"receipt format {version} (this client reads up to {RECEIPT_VERSION})"
|
|
82
|
+
|
|
83
|
+
def at(*path):
|
|
84
|
+
node = receipt
|
|
85
|
+
for key in path:
|
|
86
|
+
node = node.get(key) if isinstance(node, dict) else None
|
|
87
|
+
return node
|
|
88
|
+
|
|
89
|
+
for label, value in (
|
|
90
|
+
("attestation", at("attestation", "statement", "type")),
|
|
91
|
+
("log entry", at("log", "leaf", "type")),
|
|
92
|
+
("checkpoint", at("log", "checkpoint", "statement", "type")),
|
|
93
|
+
("timestamps record", at("timestamps", "seal", "record", "statement", "type")),
|
|
94
|
+
("timestamps record", at("log", "checkpoint", "timestamps", "record", "statement",
|
|
95
|
+
"type")),
|
|
96
|
+
# A record whose two type fields disagree is malformed, not newer.
|
|
97
|
+
("record type", at("record", "type") if at("record", "type") == at(
|
|
98
|
+
"record", "document", "type") else None)):
|
|
99
|
+
if _unknown_type(value):
|
|
100
|
+
return f"{label} {value}"
|
|
101
|
+
iid = receipt.get("imprint_id")
|
|
102
|
+
if isinstance(iid, str) and imprint_file.is_newer_id(iid):
|
|
103
|
+
return f"ID prefix {imprint_file.clean_id(iid).split('-', 1)[0]}"
|
|
104
|
+
return None
|
|
105
|
+
|
|
106
|
+
|
|
50
107
|
def _record(receipt: dict) -> Check:
|
|
51
108
|
"""Receipt format 4: an ownership record. Its digest, typed ID, attestation fields and
|
|
52
109
|
owner signatures must all follow from the record document."""
|
|
@@ -226,9 +283,11 @@ def _identity(receipt: dict, now: datetime) -> Check | None:
|
|
|
226
283
|
until = _time(doc["valid_until"])
|
|
227
284
|
except (KeyError, ValueError):
|
|
228
285
|
return Check("identity", FAIL, "the identity record has no validity window")
|
|
229
|
-
if until <= now:
|
|
230
|
-
return Check("identity", FAIL, f"expired at {doc['valid_until']}")
|
|
231
286
|
subject = f" as {doc['subject']}" if doc.get("subject") else ""
|
|
287
|
+
if until <= now: # it was valid when it was used (42b-02): a warning
|
|
288
|
+
return Check("identity", WARN, f"expired on {until:%Y-%m-%d}: key {doc['key']} "
|
|
289
|
+
f"was verified at level {doc['level']} "
|
|
290
|
+
f"({doc['provider']}{subject}) until then")
|
|
232
291
|
return Check("identity", PASS, f"key {doc['key']} verified at level {doc['level']} "
|
|
233
292
|
f"({doc['provider']}{subject}) until {doc['valid_until']}")
|
|
234
293
|
if rec.get("type") == "codeimprint.org-member.v1":
|
|
@@ -260,6 +319,42 @@ def _identity(receipt: dict, now: datetime) -> Check | None:
|
|
|
260
319
|
return None
|
|
261
320
|
|
|
262
321
|
|
|
322
|
+
INTEGRATION_V1 = "codeimprint.integration.v1"
|
|
323
|
+
INTEGRATION_V2 = "codeimprint.integration.v2" # no raw forge IDs: salted commitments
|
|
324
|
+
_INTEGRATION_V2_FIELDS = {"type", "project", "integration", "installation_commitment",
|
|
325
|
+
"repository_commitment", "key", "public_key", "scope",
|
|
326
|
+
"authorised_by"}
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def _integration(receipt: dict) -> Check | None:
|
|
330
|
+
"""An integration authorisation (INT1): the owner's key authorises a key held by
|
|
331
|
+
CodeImprint for a forge integration, and both sign. v1 names the installation and the
|
|
332
|
+
repository; v2 publishes only salted commitments to them (v1 records stay valid). The
|
|
333
|
+
signatures themselves are verified by ``_record``."""
|
|
334
|
+
rec = receipt.get("record") or {}
|
|
335
|
+
if rec.get("type") not in (INTEGRATION_V1, INTEGRATION_V2):
|
|
336
|
+
return None
|
|
337
|
+
doc = rec.get("document") or {}
|
|
338
|
+
if rec["type"] == INTEGRATION_V2:
|
|
339
|
+
if set(doc) != _INTEGRATION_V2_FIELDS or not (
|
|
340
|
+
_hex64(doc["installation_commitment"]) and _hex64(doc["repository_commitment"])):
|
|
341
|
+
return Check("integration", FAIL, "not an integration authorisation: other fields, "
|
|
342
|
+
"or a commitment that is not a SHA-256")
|
|
343
|
+
where = "installation and repository: committed (private)"
|
|
344
|
+
else:
|
|
345
|
+
where = f"installation {doc.get('installation')}, repository {doc.get('repository')}"
|
|
346
|
+
roles = {s.get("role"): s.get("fingerprint") for s in receipt.get("signatures") or []}
|
|
347
|
+
if (roles.get("integration"), roles.get("owner")) != (doc.get("key"),
|
|
348
|
+
doc.get("authorised_by")):
|
|
349
|
+
return Check("integration", FAIL, "the integration and owner signatures are not by the "
|
|
350
|
+
"keys the record names")
|
|
351
|
+
scope = doc.get("scope")
|
|
352
|
+
scope = ", ".join(scope) if isinstance(scope, list) and scope else "none"
|
|
353
|
+
return Check("integration", PASS, f"{doc.get('integration')} key {doc.get('key')} "
|
|
354
|
+
f"authorised by owner key {doc.get('authorised_by')} for "
|
|
355
|
+
f"project {doc.get('project')}; scope {scope}; {where}")
|
|
356
|
+
|
|
357
|
+
|
|
263
358
|
def key_checks(receipt: dict, client) -> list[Check]:
|
|
264
359
|
"""Online: the identity status of a record, and whether a seal's signer keys were reported
|
|
265
360
|
compromised before the seal (a seal signed from then on is flagged)."""
|
|
@@ -283,9 +378,11 @@ def key_checks(receipt: dict, client) -> list[Check]:
|
|
|
283
378
|
None)
|
|
284
379
|
if mine is None:
|
|
285
380
|
return [Check("identity status", FAIL, "the server does not list this identity")]
|
|
381
|
+
if mine["status"] == "expired": # as offline: a warning, not a failure
|
|
382
|
+
return [Check("identity status", WARN,
|
|
383
|
+
f"expired on {str(mine.get('valid_until'))[:10]}")]
|
|
286
384
|
if mine["status"] != "valid":
|
|
287
385
|
why = {"revoked": f"revoked by {mine.get('revoked_by')}",
|
|
288
|
-
"expired": f"expired at {mine['valid_until']}",
|
|
289
386
|
"suspect": f"bound after the key was reported compromised "
|
|
290
387
|
f"({s.get('compromised_since')})"}.get(mine["status"],
|
|
291
388
|
mine["status"])
|
|
@@ -650,6 +747,10 @@ def verify(receipt: dict, keys: list[dict], doc: dict | None = None,
|
|
|
650
747
|
"""Every offline check. ``developer`` is the fingerprint the project expects to sign;
|
|
651
748
|
``anchors`` the trusted TSA roots (default: the pinned ones); ``opening`` what a lineage
|
|
652
749
|
record's commitment is said to commit to."""
|
|
750
|
+
newer = newer_format(receipt)
|
|
751
|
+
if newer: # before any other check (42b-01)
|
|
752
|
+
return [Check("format", NEWER, newer_message(
|
|
753
|
+
"record" if isinstance(receipt, dict) and "record" in receipt else "seal"))]
|
|
653
754
|
now = now or datetime.now(timezone.utc)
|
|
654
755
|
anchors = timestamp.pinned_anchors() if anchors is None else anchors
|
|
655
756
|
if not keys:
|
|
@@ -658,7 +759,7 @@ def verify(receipt: dict, keys: list[dict], doc: dict | None = None,
|
|
|
658
759
|
"--online` once, or pass --keys FILE")]
|
|
659
760
|
if "record" in receipt: # receipt format 4
|
|
660
761
|
checks = [_record(receipt), _attestation(receipt, keys), _log(receipt, keys)]
|
|
661
|
-
typed = _identity(receipt, now)
|
|
762
|
+
typed = _identity(receipt, now) or _integration(receipt)
|
|
662
763
|
if typed:
|
|
663
764
|
checks.insert(1, typed)
|
|
664
765
|
link = _lineage(receipt)
|
|
@@ -43,6 +43,10 @@ TYPES: dict[str, RecordType] = {
|
|
|
43
43
|
"codeimprint.disclosure.v1": RecordType("DSC1", "disclosure", ("record",), ("admin",)),
|
|
44
44
|
"codeimprint.integration.v1": RecordType("INT1", "integration", (),
|
|
45
45
|
("integration", "owner")),
|
|
46
|
+
# The same authorisation without the forge's installation and repository IDs in clear:
|
|
47
|
+
# salted commitments to each (engine 0.7.0a36). v1 records stay valid.
|
|
48
|
+
"codeimprint.integration.v2": RecordType("INT1", "integration", (),
|
|
49
|
+
("integration", "owner")),
|
|
46
50
|
# Clone lineage: a declared link is signed by the clone's project key (role child); a
|
|
47
51
|
# detected link is the server's own. The origin is never a reference field.
|
|
48
52
|
"codeimprint.lineage.v1": RecordType("LIN1", "lineage", ("child_seal",)),
|
|
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
|
|
File without changes
|