codeimprint 0.5.0a30__tar.gz → 0.5.0a32__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.0a32}/CHANGELOG.md +55 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/PKG-INFO +5 -3
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/README.pypi.md +4 -2
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/pyproject.toml +1 -1
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/__init__.py +1 -1
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/api.py +11 -5
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/cli.py +89 -15
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/imprint_file.py +12 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/ownership.py +9 -4
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/receipt.py +105 -4
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/records.py +4 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/.gitignore +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/LICENSE +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/NOTICE +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint/__init__.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint/__main__.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/__main__.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/chainseal.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/config.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/gitrepo.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/linecount.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/project.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/timestamp.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/transparency.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/trust.py +0 -0
- {codeimprint-0.5.0a30 → codeimprint-0.5.0a32}/src/codeimprint_cli/tsa_roots.py +0 -0
|
@@ -1,5 +1,60 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0a32 — Signed organisation requests [CIM-BE-48-v1]
|
|
4
|
+
|
|
5
|
+
For engine 0.7.0a38, which needs them (audit 42f-01, 42f-03).
|
|
6
|
+
|
|
7
|
+
- **Changed: `imprint org domain` and `imprint org disclose` sign their request** with the
|
|
8
|
+
organisation's admin key: canonical JSON `{type, org, domain, at}` with
|
|
9
|
+
`codeimprint.org-domain-request.v1` or `codeimprint.org-disclosure-request.v1` and the
|
|
10
|
+
current UTC time. The disclosure document is now asked for with a POST. Older clients get
|
|
11
|
+
"No such organisation" from engine 0.7.0a38. With an engine before 0.7.0a38, `imprint org
|
|
12
|
+
domain` still works (the signature is ignored), but `imprint org disclose` gets 405 (those
|
|
13
|
+
engines serve the document only by GET): use 0.5.0a31 for it until the engine is updated.
|
|
14
|
+
- Docs: the README and the PyPI page say what a Git seal sends besides file contents (paths,
|
|
15
|
+
Git IDs, commit and repository IDs, kept as keyed hashes), and that only a seal signed
|
|
16
|
+
with your developer key cannot be forged by the operator (42e-07, 42e-08).
|
|
17
|
+
- Tests: `tests/test_org_commands.py`.
|
|
18
|
+
|
|
19
|
+
## 0.5.0a31 — Newer formats, expired identities, INT1 v2 [CIM-BE-45-v1]
|
|
20
|
+
|
|
21
|
+
For engine 0.7.0a36.
|
|
22
|
+
|
|
23
|
+
- **New: a seal or record in a newer format than this client is not called a failure.**
|
|
24
|
+
Before any other check, `imprint verify` looks for a receipt format above 4, an attestation
|
|
25
|
+
statement, log entry, checkpoint, timestamps record or record type it
|
|
26
|
+
has never seen (a well-formed `codeimprint.<name>.v<N>`), and an ID with an unknown prefix
|
|
27
|
+
of the known shape (three letters and a digit, such as `IMP2-`). Any of them gives one
|
|
28
|
+
result: `Result NEWER FORMAT` and "This seal uses a newer format than this client
|
|
29
|
+
understands. Upgrade: pip install --pre -U codeimprint" ("This record uses …" for an
|
|
30
|
+
ownership record). It is not verified, and it is not FAIL.
|
|
31
|
+
- **New exit code 3** for that result, and `--json` `status` `"NEWER"` (with `message` and
|
|
32
|
+
`newer`, what was newer). In an automated build (GitHub Actions, GitLab CI, Bitbucket
|
|
33
|
+
Pipelines) it is a warning (`::warning::` in GitHub Actions) and the exit code is 0, so a
|
|
34
|
+
build is never broken by a newer seal. Documented in `imprint verify --help` and in a new
|
|
35
|
+
exit-code table in the README.
|
|
36
|
+
- **New: `--json` of `imprint verify` also has `status`** (`VERIFIED` or `NOT VERIFIED`) next
|
|
37
|
+
to `valid`.
|
|
38
|
+
- A seal or record in a known format that does not verify still FAILs, as before.
|
|
39
|
+
- Sealing, release records, records the client signs and `imprint ownership` give the same
|
|
40
|
+
upgrade message when the server answers in a newer format (sealing: a warning in an
|
|
41
|
+
automated build, as before; `imprint ownership` exits 3). Commands that take a seal's ID
|
|
42
|
+
say it too for an ID with an unknown prefix of the known shape.
|
|
43
|
+
- **Changed: an identity record that has expired is WARN "expired on <date>"** (YYYY-MM-DD),
|
|
44
|
+
not FAIL: it was valid when it was used. The same online (`identity status`). Revoked
|
|
45
|
+
identities, bad signatures and everything else stay as they were.
|
|
46
|
+
- **New: integration authorisations `codeimprint.integration.v2`** (INT1, the same signature
|
|
47
|
+
roles as v1): the GitHub installation and repository are salted commitments, not GitHub's
|
|
48
|
+
IDs. `imprint verify` shows an integration record (v1 or v2) as its own check, which also
|
|
49
|
+
requires the integration and owner signatures to be by the keys the record names; for v2
|
|
50
|
+
"installation and repository: committed (private)". v1 records stay valid.
|
|
51
|
+
- **Changed: `imprint seal --name`** is "a private label for this seal (never in the public
|
|
52
|
+
seal)": the engine no longer writes the name into the sealed Imprint.
|
|
53
|
+
- Tests: `tests/test_newer_format.py`, `tests/test_identity.py`, `tests/test_golden_vectors.py`
|
|
54
|
+
(the identity record of the golden vectors is WARN, not FAIL, in 2036).
|
|
55
|
+
- Tests: a second set of golden vectors (engine 0.7.0a36: an INT1 v2 record and a zip seal made
|
|
56
|
+
with a name), verified now and in 2036 (`tests/test_golden_vectors_2.py`).
|
|
57
|
+
|
|
3
58
|
## 0.5.0a30 — `imprint github link` warns about sealing twice [CIM-BE-44-v1]
|
|
4
59
|
|
|
5
60
|
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.0a32
|
|
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
|
|
@@ -94,8 +94,10 @@ evidence, not proof), `imprint chain`, `imprint hook install`, `imprint identity
|
|
|
94
94
|
|
|
95
95
|
## What leaves your machine
|
|
96
96
|
|
|
97
|
-
`imprint seal` and `imprint check` upload the project's files to the CodeImprint
|
|
98
|
-
signed in to, which
|
|
97
|
+
`imprint seal` and `imprint check` upload the project's Python files to the CodeImprint
|
|
98
|
+
server you signed in to, which deletes them as soon as it has sealed or checked them. A Git
|
|
99
|
+
seal also sends the paths and Git IDs of tracked files and the commit and repository IDs;
|
|
100
|
+
the server keeps those only as keyed hashes, with the seal.
|
|
99
101
|
Your developer key never leaves your machine: only its public half is sent.
|
|
100
102
|
|
|
101
103
|
## Licence
|
|
@@ -60,8 +60,10 @@ evidence, not proof), `imprint chain`, `imprint hook install`, `imprint identity
|
|
|
60
60
|
|
|
61
61
|
## What leaves your machine
|
|
62
62
|
|
|
63
|
-
`imprint seal` and `imprint check` upload the project's files to the CodeImprint
|
|
64
|
-
signed in to, which
|
|
63
|
+
`imprint seal` and `imprint check` upload the project's Python files to the CodeImprint
|
|
64
|
+
server you signed in to, which deletes them as soon as it has sealed or checked them. A Git
|
|
65
|
+
seal also sends the paths and Git IDs of tracked files and the commit and repository IDs;
|
|
66
|
+
the server keeps those only as keyed hashes, with the seal.
|
|
65
67
|
Your developer key never leaves your machine: only its public half is sent.
|
|
66
68
|
|
|
67
69
|
## Licence
|
|
@@ -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.0a32"
|
|
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"
|
|
@@ -447,17 +447,23 @@ class Client:
|
|
|
447
447
|
return self._json("POST", "/api/v1/orgs", {"public_key": public_key,
|
|
448
448
|
"signature": signature})
|
|
449
449
|
|
|
450
|
-
def org_domain_challenge(self, org: str, domain: str, public_key: str
|
|
450
|
+
def org_domain_challenge(self, org: str, domain: str, public_key: str, at: str,
|
|
451
|
+
signature: str) -> dict:
|
|
452
|
+
"""The admin's signed request (engine 0.7.0a38+)."""
|
|
451
453
|
return self._json("POST", f"/api/v1/orgs/{quote(org)}/domains",
|
|
452
|
-
{"domain": domain, "public_key": public_key
|
|
454
|
+
{"domain": domain, "public_key": public_key, "at": at,
|
|
455
|
+
"signature": signature})
|
|
453
456
|
|
|
454
457
|
def org_domain_verify(self, org: str, domain: str, signature: str) -> dict:
|
|
455
458
|
return self._json("POST", f"/api/v1/orgs/{quote(org)}/domains/verify",
|
|
456
459
|
{"domain": domain, "signature": signature})
|
|
457
460
|
|
|
458
|
-
def org_disclosure_document(self, org: str, domain: str
|
|
459
|
-
|
|
460
|
-
|
|
461
|
+
def org_disclosure_document(self, org: str, domain: str, public_key: str, at: str,
|
|
462
|
+
signature: str) -> dict:
|
|
463
|
+
"""The admin's signed request (engine 0.7.0a38+; a GET before)."""
|
|
464
|
+
return self._json("POST", f"/api/v1/orgs/{quote(org)}/disclosures/document",
|
|
465
|
+
{"domain": domain, "public_key": public_key, "at": at,
|
|
466
|
+
"signature": signature})
|
|
461
467
|
|
|
462
468
|
def org_disclose(self, org: str, domain: str, public_key: str, signature: str) -> dict:
|
|
463
469
|
return self._json("POST", f"/api/v1/orgs/{quote(org)}/disclosures",
|
|
@@ -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
|
|
|
@@ -1097,6 +1111,18 @@ def _now_iso() -> str:
|
|
|
1097
1111
|
return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
1098
1112
|
|
|
1099
1113
|
|
|
1114
|
+
# The organisation admin's signed requests (engine 0.7.0a38): only the admin key's fresh
|
|
1115
|
+
# signature over {type, org, domain, at} gets a domain challenge or a disclosure document.
|
|
1116
|
+
ORG_DOMAIN_REQUEST = "codeimprint.org-domain-request.v1"
|
|
1117
|
+
ORG_DISCLOSURE_REQUEST = "codeimprint.org-disclosure-request.v1"
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
def _org_request(key, kind: str, org: str, domain: str) -> tuple[str, str]:
|
|
1121
|
+
"""(at, signature) for the admin's request; ``at`` is now, UTC."""
|
|
1122
|
+
at = _now_iso()
|
|
1123
|
+
return at, chainseal.sign(key, {"type": kind, "org": org, "domain": domain, "at": at})
|
|
1124
|
+
|
|
1125
|
+
|
|
1100
1126
|
def _session_client(args) -> Client:
|
|
1101
1127
|
settings = config.resolve(getattr(args, "url", None))
|
|
1102
1128
|
if not settings.url:
|
|
@@ -1117,8 +1143,11 @@ def _checked(client: Client, rec: dict, what: str) -> None:
|
|
|
1117
1143
|
if problems:
|
|
1118
1144
|
raise Abort("the server's attestation keys changed unexpectedly (" + "; ".join(problems)
|
|
1119
1145
|
+ ")")
|
|
1120
|
-
|
|
1121
|
-
|
|
1146
|
+
checks = receipt.verify(rec, keys, anchors=_anchors(argparse.Namespace(tsa_certs=None)))
|
|
1147
|
+
newer = _newer(checks)
|
|
1148
|
+
if newer:
|
|
1149
|
+
raise Abort(newer.detail)
|
|
1150
|
+
bad = _failed(checks)
|
|
1122
1151
|
if bad:
|
|
1123
1152
|
raise Abort(f"the {what} does not verify (" + "; ".join(
|
|
1124
1153
|
f"{c.name}: {c.detail}" for c in bad) + ")")
|
|
@@ -1492,10 +1521,11 @@ def cmd_ownership(args) -> int:
|
|
|
1492
1521
|
anchors=_anchors(argparse.Namespace(tsa_certs=None)))
|
|
1493
1522
|
except (ApiError, NetworkError) as exc:
|
|
1494
1523
|
raise Abort(f"cannot read the ownership listing: {exc}") from exc
|
|
1524
|
+
code = 1 if _failed(checks) else EXIT_NEWER if _newer(checks) else 0
|
|
1495
1525
|
if args.json:
|
|
1496
1526
|
print(json.dumps({"ownership": view, "checks": [c.as_dict() for c in checks]},
|
|
1497
1527
|
indent=1))
|
|
1498
|
-
return
|
|
1528
|
+
return code
|
|
1499
1529
|
_say(f"Project {project_id}", f"Ownership {view['label']}")
|
|
1500
1530
|
for label in view.get("licence_claims") or []:
|
|
1501
1531
|
_say(f"Licence {label}")
|
|
@@ -1519,7 +1549,7 @@ def cmd_ownership(args) -> int:
|
|
|
1519
1549
|
"Checked here: every record's receipt and signatures, the claim rules, and each "
|
|
1520
1550
|
"seal's coverage. Not checked: that the server listed every record, the evidence "
|
|
1521
1551
|
"behind identities, organisation key windows, legal validity.")
|
|
1522
|
-
return
|
|
1552
|
+
return code
|
|
1523
1553
|
|
|
1524
1554
|
|
|
1525
1555
|
# -- organisations and contributors (ADR 0002 steps 1.9-1.12) -------------------------------
|
|
@@ -1600,7 +1630,9 @@ def cmd_org(args) -> int:
|
|
|
1600
1630
|
raise Abort(f"{args.action}: name the domain")
|
|
1601
1631
|
try:
|
|
1602
1632
|
if args.action == "domain":
|
|
1603
|
-
ch = client.org_domain_challenge(org, args.target, pub
|
|
1633
|
+
ch = client.org_domain_challenge(org, args.target, pub,
|
|
1634
|
+
*_org_request(key, ORG_DOMAIN_REQUEST, org,
|
|
1635
|
+
args.target))
|
|
1604
1636
|
path = _challenge_path(org, _ascii_domain(ch["domain"]))
|
|
1605
1637
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
1606
1638
|
path.write_text(json.dumps(ch, indent=1) + "\n", encoding="utf-8")
|
|
@@ -1629,7 +1661,9 @@ def cmd_org(args) -> int:
|
|
|
1629
1661
|
f"imprint org disclose {org} {ch['domain']}")
|
|
1630
1662
|
return 0
|
|
1631
1663
|
if args.action == "disclose":
|
|
1632
|
-
doc = client.org_disclosure_document(org, args.target
|
|
1664
|
+
doc = client.org_disclosure_document(org, args.target, pub,
|
|
1665
|
+
*_org_request(key, ORG_DISCLOSURE_REQUEST,
|
|
1666
|
+
org, args.target))
|
|
1633
1667
|
_checked_digest(doc["document"], doc["digest"], doc["statement"])
|
|
1634
1668
|
_say(f"Disclose {doc['document']['value']} for organisation {org}: from now on it "
|
|
1635
1669
|
"is public, and the organisation is shown as \"verified domain "
|
|
@@ -1779,7 +1813,7 @@ def cmd_export(args) -> int:
|
|
|
1779
1813
|
client = _client(args)
|
|
1780
1814
|
iid = imprint_file.clean_id(args.imprint_id)
|
|
1781
1815
|
if not imprint_file.is_valid_id(iid):
|
|
1782
|
-
raise
|
|
1816
|
+
raise _bad_id(iid, f"not a valid Imprint ID: {args.imprint_id}")
|
|
1783
1817
|
try:
|
|
1784
1818
|
doc = client.export(iid)
|
|
1785
1819
|
except (ApiError, NetworkError) as exc:
|
|
@@ -1844,6 +1878,8 @@ def _accept(args, client: Client, result: dict) -> tuple[list, list, list[receip
|
|
|
1844
1878
|
+ "; ".join(problems) + "); not saved")
|
|
1845
1879
|
anchors = _anchors(args)
|
|
1846
1880
|
checks = receipt.verify(result["receipt"], keys, doc, anchors=anchors)
|
|
1881
|
+
if _newer(checks):
|
|
1882
|
+
raise SealFailed(f"{_newer(checks).detail} (not saved)")
|
|
1847
1883
|
bad = _failed(checks)
|
|
1848
1884
|
if bad:
|
|
1849
1885
|
raise SealFailed("the seal does not verify (" + "; ".join(
|
|
@@ -1944,6 +1980,8 @@ def _seal_zip(args, client: Client, data: bytes, project_id: str | None,
|
|
|
1944
1980
|
signer = None
|
|
1945
1981
|
checks = receipt.verify(result["receipt"], keys, result["imprint"],
|
|
1946
1982
|
anchors=_anchors(args))
|
|
1983
|
+
if _newer(checks):
|
|
1984
|
+
raise SealFailed(f"{_newer(checks).detail} (not saved)")
|
|
1947
1985
|
bad = _failed(checks)
|
|
1948
1986
|
if bad:
|
|
1949
1987
|
raise SealFailed("the signed receipt does not verify (" + "; ".join(
|
|
@@ -2046,6 +2084,8 @@ def _finish_release(args, client: Client, root: Path, out: dict, key) -> None:
|
|
|
2046
2084
|
raise SealFailed("the server's attestation keys changed unexpectedly ("
|
|
2047
2085
|
+ "; ".join(problems) + "); not saved")
|
|
2048
2086
|
checks = receipt.verify(rec, keys, None, anchors=_anchors(args))
|
|
2087
|
+
if _newer(checks):
|
|
2088
|
+
raise SealFailed(f"{_newer(checks).detail} (not saved)")
|
|
2049
2089
|
bad = _failed(checks)
|
|
2050
2090
|
if bad:
|
|
2051
2091
|
raise SealFailed("the release record does not verify (" + "; ".join(
|
|
@@ -2576,7 +2616,7 @@ def _engagement_join(args) -> int:
|
|
|
2576
2616
|
def cmd_deliver(args) -> int:
|
|
2577
2617
|
"""`imprint deliver IMP1-… [--note …] [--to-client]`: a vendor delivers a seal."""
|
|
2578
2618
|
if not imprint_file.is_valid_id(args.seal):
|
|
2579
|
-
raise
|
|
2619
|
+
raise _bad_id(args.seal, f"not a fingerprint ID (IMP1-…): {args.seal}")
|
|
2580
2620
|
iid = imprint_file.clean_id(args.seal)
|
|
2581
2621
|
client = _client(args, _server_from_project(Path(".")))
|
|
2582
2622
|
if client.auth in ("none", "expired"):
|
|
@@ -2604,7 +2644,7 @@ def cmd_deliver(args) -> int:
|
|
|
2604
2644
|
def cmd_accept(args) -> int:
|
|
2605
2645
|
"""`imprint accept IMP1-…`: the project owner accepts a seal its vendor delivered."""
|
|
2606
2646
|
if not imprint_file.is_valid_id(args.seal):
|
|
2607
|
-
raise
|
|
2647
|
+
raise _bad_id(args.seal, f"not a fingerprint ID (IMP1-…): {args.seal}")
|
|
2608
2648
|
iid = imprint_file.clean_id(args.seal)
|
|
2609
2649
|
client = _session_client(args)
|
|
2610
2650
|
try:
|
|
@@ -2966,7 +3006,7 @@ def _validity(client: Client, iid: str) -> dict | None:
|
|
|
2966
3006
|
def cmd_certificate(args) -> int:
|
|
2967
3007
|
"""`imprint certificate IMP1-… [-o file.pdf]`: download a seal's certificate (PDF)."""
|
|
2968
3008
|
if not imprint_file.is_valid_id(args.seal):
|
|
2969
|
-
raise
|
|
3009
|
+
raise _bad_id(args.seal, f"not a fingerprint ID (IMP1-…): {args.seal}")
|
|
2970
3010
|
iid = imprint_file.clean_id(args.seal)
|
|
2971
3011
|
client = _client(args, _server_from_project(Path(".")))
|
|
2972
3012
|
# The server answers everyone but the owner like a seal that does not exist, so say here
|
|
@@ -3096,17 +3136,39 @@ def _file_only(doc: dict) -> list[receipt.Check]:
|
|
|
3096
3136
|
"transparency log (run `imprint seal`)")]
|
|
3097
3137
|
|
|
3098
3138
|
|
|
3139
|
+
def _newer_result(args, iid: str | None, why: str, message: str) -> int:
|
|
3140
|
+
"""A seal or record in a newer format than this client: not verified here, and not a
|
|
3141
|
+
failure either (42b-01). Exit code 3; in an automated build a warning and exit 0."""
|
|
3142
|
+
if args.json:
|
|
3143
|
+
print(json.dumps({"imprint_id": iid, "valid": False, "status": receipt.NEWER,
|
|
3144
|
+
"message": message, "newer": why,
|
|
3145
|
+
"checks": [receipt.Check("format", receipt.NEWER, message).as_dict()]},
|
|
3146
|
+
indent=2))
|
|
3147
|
+
else:
|
|
3148
|
+
_say(f"Imprint {iid}", "", f"{receipt.NEWER:<5} {'format':<20} {why}", "",
|
|
3149
|
+
"Result NEWER FORMAT (not verified by this client)", f" {message}")
|
|
3150
|
+
if _ci():
|
|
3151
|
+
_warn(message, json_out=args.json)
|
|
3152
|
+
return 0
|
|
3153
|
+
return EXIT_NEWER
|
|
3154
|
+
|
|
3155
|
+
|
|
3099
3156
|
def cmd_verify(args) -> int:
|
|
3100
3157
|
if not args.target:
|
|
3101
3158
|
default = Path(".imprint") / "baseline.imprint"
|
|
3102
3159
|
if not default.is_file():
|
|
3103
3160
|
args.verify_parser.error("the following arguments are required: target")
|
|
3104
3161
|
args.target = str(default)
|
|
3162
|
+
if not Path(args.target).is_file() and imprint_file.is_newer_id(args.target):
|
|
3163
|
+
iid = imprint_file.clean_id(args.target)
|
|
3164
|
+
return _newer_result(args, iid, f"ID prefix {iid.split('-', 1)[0]}",
|
|
3165
|
+
receipt.newer_message())
|
|
3105
3166
|
doc, rec, root = _load_target(args)
|
|
3106
3167
|
found = getattr(args, "found_opening", None)
|
|
3107
3168
|
checks: list[receipt.Check] = []
|
|
3108
3169
|
state = None # the seal's validity now (--online only)
|
|
3109
|
-
|
|
3170
|
+
why = receipt.newer_format(rec) if rec is not None else None
|
|
3171
|
+
client = _client(args, _server_from_project(root)) if args.online and not why else None
|
|
3110
3172
|
if rec is None and client is not None:
|
|
3111
3173
|
iid = imprint_file.clean_id(args.target) if doc is None else (
|
|
3112
3174
|
imprint_file.verify_document(doc)["id"])
|
|
@@ -3122,6 +3184,10 @@ def cmd_verify(args) -> int:
|
|
|
3122
3184
|
raise Abort(f"no public record for {iid}: {exc}") from exc
|
|
3123
3185
|
except NetworkError as exc:
|
|
3124
3186
|
raise Abort(str(exc)) from exc
|
|
3187
|
+
why = receipt.newer_format(rec) if rec is not None else None
|
|
3188
|
+
if why: # before any other check (42b-01)
|
|
3189
|
+
return _newer_result(args, rec.get("imprint_id"), why, receipt.newer_message(
|
|
3190
|
+
"record" if "record" in rec else "seal"))
|
|
3125
3191
|
opening = _opening_for(args, rec, found)
|
|
3126
3192
|
if rec is None:
|
|
3127
3193
|
checks = _file_only(doc)
|
|
@@ -3164,6 +3230,7 @@ def cmd_verify(args) -> int:
|
|
|
3164
3230
|
elsewhere = any(c.name == "repository" and c.status == receipt.WARN for c in checks)
|
|
3165
3231
|
if args.json:
|
|
3166
3232
|
print(json.dumps({"imprint_id": iid, "valid": valid,
|
|
3233
|
+
"status": "VERIFIED" if valid else "NOT VERIFIED",
|
|
3167
3234
|
"issued_for_this_repository": (
|
|
3168
3235
|
False if elsewhere else True if any(
|
|
3169
3236
|
c.name == "repository" for c in checks) else None),
|
|
@@ -3339,7 +3406,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
3339
3406
|
s = sub.add_parser("seal", help="seal a project on the server; saves .imprint/baseline.imprint "
|
|
3340
3407
|
"and its receipt")
|
|
3341
3408
|
s.add_argument("path", nargs="?", default=".")
|
|
3342
|
-
s.add_argument("--name", help="
|
|
3409
|
+
s.add_argument("--name", help="a private label for this seal (never in the public seal)")
|
|
3343
3410
|
s.add_argument("--hub-url", help="hub for the verify link and badge (default: "
|
|
3344
3411
|
"CODEIMPRINT_HUB_URL, else the hub the server names)")
|
|
3345
3412
|
s.add_argument("-o", "--output", help="where to save the Imprint")
|
|
@@ -3502,7 +3569,14 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
3502
3569
|
c.add_argument("--yes", action="store_true", help="do not ask before uploading (CI)")
|
|
3503
3570
|
c.set_defaults(func=cmd_check)
|
|
3504
3571
|
|
|
3505
|
-
v = sub.add_parser("verify", help="verify a seal offline: .imprint file, receipt or ID"
|
|
3572
|
+
v = sub.add_parser("verify", help="verify a seal offline: .imprint file, receipt or ID",
|
|
3573
|
+
epilog="Exit codes: 0 VERIFIED; 1 NOT VERIFIED (a check failed, or a "
|
|
3574
|
+
"warning with --strict); 2 a usage or other error; 3 a newer "
|
|
3575
|
+
"format than this client understands (\"This seal uses a newer "
|
|
3576
|
+
"format than this client understands. Upgrade: pip install --pre "
|
|
3577
|
+
"-U codeimprint\"; --json status NEWER). In an automated build "
|
|
3578
|
+
"(GitHub Actions, GitLab CI, Bitbucket Pipelines) a newer format "
|
|
3579
|
+
"is a warning and exits 0.")
|
|
3506
3580
|
v.add_argument("target", nargs="?",
|
|
3507
3581
|
help=".imprint file, .receipt.json file or Imprint ID (default: "
|
|
3508
3582
|
".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
|