codeimprint 0.5.0a21__tar.gz → 0.5.0a23__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.0a21 → codeimprint-0.5.0a23}/CHANGELOG.md +35 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/PKG-INFO +1 -1
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/pyproject.toml +1 -1
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/__init__.py +1 -1
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/api.py +26 -4
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/cli.py +71 -6
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/imprint_file.py +5 -5
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/.gitignore +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/LICENSE +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/NOTICE +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/README.pypi.md +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint/__init__.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint/__main__.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/__main__.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/chainseal.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/config.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/gitrepo.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/linecount.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/ownership.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/project.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/receipt.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/records.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/timestamp.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/transparency.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/trust.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a23}/src/codeimprint_cli/tsa_roots.py +0 -0
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0a23 — `imprint verify` says VERIFIED [CIM-BE-36-v2]
|
|
4
|
+
|
|
5
|
+
- **Changed: the result line of `imprint verify`** reads `Result VERIFIED`, `Result
|
|
6
|
+
NOT VERIFIED (N check(s) failed)` or `Result NOT VERIFIED with --strict (N
|
|
7
|
+
warning(s))`. Before, it said VALID / NOT VALID. "Valid" is now used for a seal's validity
|
|
8
|
+
only (`Validity Valid until <date>`, with `--online`), so the two are never confused.
|
|
9
|
+
**Exit codes and `--json` are unchanged** (`"valid": true` or `false` stays as it is). A
|
|
10
|
+
script that reads the text `Result VALID` must read `Result VERIFIED` instead; a
|
|
11
|
+
script that uses the exit code or `--json` needs no change.
|
|
12
|
+
- Tests: `tests/test_certificate.py`.
|
|
13
|
+
|
|
14
|
+
## 0.5.0a22 — Seal certificate, live validity, the server's own badge [CIM-BE-36-v1]
|
|
15
|
+
|
|
16
|
+
For engine 0.7.0a26. Older engines still work, except for `imprint certificate` (they answer
|
|
17
|
+
that the seal is not found) and the validity lines (not shown).
|
|
18
|
+
|
|
19
|
+
- **New: `imprint certificate <fingerprint ID> [-o file.pdf]`.** Downloads the seal
|
|
20
|
+
certificate (a one-page PDF made by the server) and saves it as `certificate-<ID>.pdf` in
|
|
21
|
+
the current folder, or where `-o` says. It is for the owner of the seal's project: signed in
|
|
22
|
+
with `imprint login`, or with that project's CI token. Without a sign-in the command says so
|
|
23
|
+
and asks the server nothing; when the server has no such seal, or the seal is not one of
|
|
24
|
+
your projects', it says that (the server answers both alike, on purpose).
|
|
25
|
+
- **Changed: `imprint verify --online`** adds two lines under the result, in the server's own
|
|
26
|
+
words: `Integrity Sealed <date>, unchanged since` and `Validity Valid until <date>` (or
|
|
27
|
+
`Validity lapsed on <date>`). Validity is worked out live by the server and is not part of
|
|
28
|
+
the signed seal, so offline nothing is shown, and the checks and the exit code are
|
|
29
|
+
unchanged. `--json` adds `validity` (the server's answer, or `null`).
|
|
30
|
+
- **Changed: the README badge that `imprint seal` prints** is the server's own badge
|
|
31
|
+
(`<server>/api/v1/public/imprints/<ID>/badge.svg`): it shows the project's name, when you
|
|
32
|
+
made it public, and the seal's state. Before, it was a static badge from a third-party
|
|
33
|
+
badge service that showed the ID. A badge already in a README keeps working; replace it
|
|
34
|
+
with the new line when you like.
|
|
35
|
+
- No engine or algorithm code: the client downloads and prints. Tests:
|
|
36
|
+
`tests/test_certificate.py`, `tests/test_branding.py`.
|
|
37
|
+
|
|
3
38
|
## 0.5.0a21 — A CI token's check is for its own project [CIM-BE-35-v2]
|
|
4
39
|
|
|
5
40
|
For engine 0.7.0a25, where a CI token checks against, and signs, seals of its own project
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: codeimprint
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.0a23
|
|
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.0a23"
|
|
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"
|
|
@@ -81,7 +81,16 @@ class Client:
|
|
|
81
81
|
|
|
82
82
|
def _request(self, method: str, path: str, body: bytes | None = None,
|
|
83
83
|
content_type: str | None = None) -> dict:
|
|
84
|
-
|
|
84
|
+
raw = self._open(method, path, body, content_type)
|
|
85
|
+
try:
|
|
86
|
+
return json.loads(raw.decode("utf-8"))
|
|
87
|
+
except ValueError as exc:
|
|
88
|
+
raise NetworkError(f"{self.url} did not answer with JSON") from exc
|
|
89
|
+
|
|
90
|
+
def _open(self, method: str, path: str, body: bytes | None = None,
|
|
91
|
+
content_type: str | None = None, accept: str = "application/json") -> bytes:
|
|
92
|
+
"""The answer's bytes. An error answer raises ApiError with the server's own code."""
|
|
93
|
+
headers = {"Accept": accept, "User-Agent": USER_AGENT}
|
|
85
94
|
if content_type:
|
|
86
95
|
headers["Content-Type"] = content_type
|
|
87
96
|
if self.token:
|
|
@@ -91,7 +100,7 @@ class Client:
|
|
|
91
100
|
req = urllib.request.Request(self.url + path, data=body, headers=headers, method=method)
|
|
92
101
|
try:
|
|
93
102
|
with _OPENER.open(req, timeout=self.timeout) as res:
|
|
94
|
-
return
|
|
103
|
+
return res.read()
|
|
95
104
|
except urllib.error.HTTPError as exc:
|
|
96
105
|
self._access_problem(exc)
|
|
97
106
|
code, message = "http_error", exc.reason or "Request failed"
|
|
@@ -104,8 +113,6 @@ class Client:
|
|
|
104
113
|
except (urllib.error.URLError, TimeoutError, ConnectionError) as exc:
|
|
105
114
|
reason = getattr(exc, "reason", exc)
|
|
106
115
|
raise NetworkError(f"could not reach {self.url}: {reason}") from exc
|
|
107
|
-
except ValueError as exc:
|
|
108
|
-
raise NetworkError(f"{self.url} did not answer with JSON") from exc
|
|
109
116
|
|
|
110
117
|
def _access_problem(self, exc: urllib.error.HTTPError) -> None:
|
|
111
118
|
"""Turn Cloudflare Access's answers (a redirect to its login, or its own 401/403
|
|
@@ -322,6 +329,21 @@ class Client:
|
|
|
322
329
|
def public_imprint(self, imprint_id: str) -> dict:
|
|
323
330
|
return self._request("GET", f"/api/v1/public/imprints/{quote(imprint_id)}")
|
|
324
331
|
|
|
332
|
+
# a seal's validity and certificate (engine 0.7.0a26) -----------------------------------
|
|
333
|
+
def validity(self, imprint_id: str) -> dict:
|
|
334
|
+
"""A seal's validity now, as the server works it out: state, valid until, timeline
|
|
335
|
+
and the wording to show."""
|
|
336
|
+
return self._request("GET", f"/api/v1/public/imprints/{quote(imprint_id)}/validity")
|
|
337
|
+
|
|
338
|
+
def certificate(self, seal_id: str) -> bytes:
|
|
339
|
+
"""A seal's certificate (PDF). The server gives it to the owner of the seal's project
|
|
340
|
+
and answers everyone else like a seal that does not exist."""
|
|
341
|
+
pdf = self._open("GET", f"/api/v1/seals/{quote(seal_id)}/certificate.pdf",
|
|
342
|
+
accept="application/pdf")
|
|
343
|
+
if not pdf.startswith(b"%PDF-"):
|
|
344
|
+
raise NetworkError(f"{self.url} did not answer with a PDF")
|
|
345
|
+
return pdf
|
|
346
|
+
|
|
325
347
|
# ownership claims and coverage (engine 0.7.0a4) --------------------------------------
|
|
326
348
|
def claim_prepare(self, project: str, document: dict) -> dict:
|
|
327
349
|
return self._json("POST", f"/api/v1/projects/{quote(project)}/claims/prepare",
|
|
@@ -1830,7 +1830,7 @@ def _finish(args, client: Client, root: Path, result: dict, keys: list,
|
|
|
1830
1830
|
f"Receipt {rec_path}",
|
|
1831
1831
|
_verify_line(iid, hub, out))
|
|
1832
1832
|
if hub:
|
|
1833
|
-
_say("", "README badge:", imprint_file.badge(iid, hub))
|
|
1833
|
+
_say("", "README badge:", imprint_file.badge(iid, hub, client.url))
|
|
1834
1834
|
_say("", SEAL_NOTE)
|
|
1835
1835
|
_step_summary(iid, rec, stamps, signer, hub)
|
|
1836
1836
|
return 0
|
|
@@ -2557,6 +2557,55 @@ def _trusted_keys(args, root: Path, client: Client | None,
|
|
|
2557
2557
|
return []
|
|
2558
2558
|
|
|
2559
2559
|
|
|
2560
|
+
def _validity(client: Client, iid: str) -> dict | None:
|
|
2561
|
+
"""A seal's validity now, from the server (`imprint verify --online`). None from a server
|
|
2562
|
+
that does not have it (before 0.7.0a26) or cannot be reached: validity is worked out
|
|
2563
|
+
live by the server, so offline there is nothing to show."""
|
|
2564
|
+
try:
|
|
2565
|
+
state = client.validity(iid)
|
|
2566
|
+
return state if isinstance(state.get("wording"), dict) else None
|
|
2567
|
+
except (ApiError, NetworkError, AttributeError):
|
|
2568
|
+
return None
|
|
2569
|
+
|
|
2570
|
+
|
|
2571
|
+
def cmd_certificate(args) -> int:
|
|
2572
|
+
"""`imprint certificate IMP1-… [-o file.pdf]`: download a seal's certificate (PDF)."""
|
|
2573
|
+
if not imprint_file.is_valid_id(args.seal):
|
|
2574
|
+
raise Abort(f"not a fingerprint ID (IMP1-…): {args.seal}")
|
|
2575
|
+
iid = imprint_file.clean_id(args.seal)
|
|
2576
|
+
client = _client(args, _server_from_project(Path(".")))
|
|
2577
|
+
# The server answers everyone but the owner like a seal that does not exist, so say here
|
|
2578
|
+
# what it will not say: that nobody is signed in.
|
|
2579
|
+
if client.auth == "none":
|
|
2580
|
+
raise Abort(f"you are not signed in to {client.url}: run `imprint login` first. A "
|
|
2581
|
+
"seal's certificate is for the owner of its project.")
|
|
2582
|
+
if client.auth == "expired":
|
|
2583
|
+
raise Abort(f"your sign-in to {client.url} has expired: run `imprint login` again.")
|
|
2584
|
+
try:
|
|
2585
|
+
pdf = client.certificate(iid)
|
|
2586
|
+
except ApiError as exc:
|
|
2587
|
+
if exc.status == 404:
|
|
2588
|
+
scope = (" A CI token reaches the seals of its own project only."
|
|
2589
|
+
if client.auth == "ci" else "")
|
|
2590
|
+
raise Abort(f"no certificate for {iid}: {client.url} has no such seal, or it is "
|
|
2591
|
+
f"not a seal of one of your projects.{scope} If your sign-in has "
|
|
2592
|
+
"ended, run `imprint login` again.") from exc
|
|
2593
|
+
raise Abort(_explain(client, exc, f"cannot download the certificate for {iid}")) \
|
|
2594
|
+
from exc
|
|
2595
|
+
except NetworkError as exc:
|
|
2596
|
+
raise Abort(str(exc)) from exc
|
|
2597
|
+
out = Path(args.out or f"certificate-{iid}.pdf")
|
|
2598
|
+
try:
|
|
2599
|
+
out.parent.mkdir(parents=True, exist_ok=True)
|
|
2600
|
+
out.write_bytes(pdf)
|
|
2601
|
+
except OSError as exc:
|
|
2602
|
+
raise Abort(f"cannot write {out}: {exc}") from exc
|
|
2603
|
+
_say(f"Certificate {out}",
|
|
2604
|
+
" A summary of the seal record; the record itself is the evidence "
|
|
2605
|
+
f"(`imprint verify {iid}`).")
|
|
2606
|
+
return 0
|
|
2607
|
+
|
|
2608
|
+
|
|
2560
2609
|
def _server_from_project(root: Path) -> str | None:
|
|
2561
2610
|
path = root / project.CONFIG_DIR / trust.PROJECT_KEYS
|
|
2562
2611
|
try:
|
|
@@ -2661,6 +2710,7 @@ def cmd_verify(args) -> int:
|
|
|
2661
2710
|
doc, rec, root = _load_target(args)
|
|
2662
2711
|
found = getattr(args, "found_opening", None)
|
|
2663
2712
|
checks: list[receipt.Check] = []
|
|
2713
|
+
state = None # the seal's validity now (--online only)
|
|
2664
2714
|
client = _client(args, _server_from_project(root)) if args.online else None
|
|
2665
2715
|
if rec is None and client is not None:
|
|
2666
2716
|
iid = imprint_file.clean_id(args.target) if doc is None else (
|
|
@@ -2703,6 +2753,8 @@ def cmd_verify(args) -> int:
|
|
|
2703
2753
|
except (ApiError, NetworkError, KeyError) as exc:
|
|
2704
2754
|
checks.append(receipt.Check("log consistency", receipt.FAIL,
|
|
2705
2755
|
f"cannot check the live log: {exc}"))
|
|
2756
|
+
if client is not None and "record" not in rec:
|
|
2757
|
+
state = _validity(client, iid)
|
|
2706
2758
|
if here is not None:
|
|
2707
2759
|
checks.append(here)
|
|
2708
2760
|
if elsewhere: # say nothing about where the seal does belong
|
|
@@ -2720,16 +2772,21 @@ def cmd_verify(args) -> int:
|
|
|
2720
2772
|
"issued_for_this_repository": (
|
|
2721
2773
|
False if elsewhere else True if any(
|
|
2722
2774
|
c.name == "repository" for c in checks) else None),
|
|
2775
|
+
"validity": state if valid else None,
|
|
2723
2776
|
"checks": [c.as_dict() for c in checks]}, indent=2))
|
|
2724
2777
|
else:
|
|
2725
2778
|
_say(f"{'Record ' if rec and 'record' in rec else 'Imprint'} {iid}", "")
|
|
2726
2779
|
for c in checks:
|
|
2727
2780
|
_say(f"{c.status:<5} {c.name:<20} {c.detail}")
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
f"NOT
|
|
2731
|
-
|
|
2732
|
-
|
|
2781
|
+
# "Verified" is about the checks. "Valid" is kept for a seal's validity alone.
|
|
2782
|
+
verdict = ("VERIFIED" if valid else
|
|
2783
|
+
f"NOT VERIFIED ({len(failed)} check(s) failed)" if failed else
|
|
2784
|
+
f"NOT VERIFIED with --strict ({len(warned)} warning(s))")
|
|
2785
|
+
_say("", f"Result {verdict}", *([f" {NOT_ISSUED}"] if elsewhere else []))
|
|
2786
|
+
if valid and state: # the server's own wording, as the seal page shows
|
|
2787
|
+
_say(f"Integrity {state['wording']['integrity']}",
|
|
2788
|
+
f"Validity {state['wording']['validity']}")
|
|
2789
|
+
_say("", SEAL_NOTE)
|
|
2733
2790
|
return 0 if valid else 1
|
|
2734
2791
|
|
|
2735
2792
|
|
|
@@ -3031,6 +3088,14 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
3031
3088
|
ln.add_argument("--json", action="store_true")
|
|
3032
3089
|
ln.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
|
|
3033
3090
|
ln.set_defaults(func=cmd_lineage)
|
|
3091
|
+
|
|
3092
|
+
ce = sub.add_parser("certificate", help="download a seal's certificate (PDF): for the "
|
|
3093
|
+
"owner of the seal's project")
|
|
3094
|
+
ce.add_argument("seal", metavar="FINGERPRINT_ID", help="the seal's ID (IMP1-…)")
|
|
3095
|
+
ce.add_argument("-o", "--out", metavar="FILE",
|
|
3096
|
+
help="where to save it (default: certificate-<ID>.pdf in this folder)")
|
|
3097
|
+
ce.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
|
|
3098
|
+
ce.set_defaults(func=cmd_certificate)
|
|
3034
3099
|
return p
|
|
3035
3100
|
|
|
3036
3101
|
|
|
@@ -122,8 +122,8 @@ def save(doc: dict, path: str | Path) -> Path:
|
|
|
122
122
|
return out
|
|
123
123
|
|
|
124
124
|
|
|
125
|
-
def badge(imprint_id_text: str, public_url: str) -> str:
|
|
126
|
-
"""README badge Markdown
|
|
127
|
-
|
|
128
|
-
return (f"[}/i/{imprint_id_text})")
|
|
125
|
+
def badge(imprint_id_text: str, public_url: str, server_url: str) -> str:
|
|
126
|
+
"""README badge Markdown: the server's own badge for the seal (the project's public name
|
|
127
|
+
and the seal's state, drawn by the server), linking to the seal's page on the hub."""
|
|
128
|
+
return (f"[}/api/v1/public/imprints/"
|
|
129
|
+
f"{imprint_id_text}/badge.svg)]({public_url.rstrip('/')}/i/{imprint_id_text})")
|
|
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
|
|
File without changes
|
|
File without changes
|