codeimprint 0.5.0a21__tar.gz → 0.5.0a24__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.0a24}/CHANGELOG.md +54 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/PKG-INFO +1 -1
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/pyproject.toml +1 -1
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/__init__.py +1 -1
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/api.py +26 -4
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/chainseal.py +36 -4
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/cli.py +81 -6
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/imprint_file.py +5 -5
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/.gitignore +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/LICENSE +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/NOTICE +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/README.pypi.md +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint/__init__.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint/__main__.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/__main__.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/config.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/gitrepo.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/linecount.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/ownership.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/project.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/receipt.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/records.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/timestamp.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/transparency.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/trust.py +0 -0
- {codeimprint-0.5.0a21 → codeimprint-0.5.0a24}/src/codeimprint_cli/tsa_roots.py +0 -0
|
@@ -1,5 +1,59 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0a24 — Empty seals are refused; a tip to name a project [CIM-BE-37-v1]
|
|
4
|
+
|
|
5
|
+
For engine 0.7.0a28. Older engines still work.
|
|
6
|
+
|
|
7
|
+
- **Changed: `imprint seal` refuses a seal that would cover no file.** "Nothing to seal: no
|
|
8
|
+
files matched. Check .gitignore, the exclude list in .imprint/config.json, and that you
|
|
9
|
+
are in the project folder." The exit code is 2; nothing is sent beyond the plan and
|
|
10
|
+
nothing is logged. With engine 0.7.0a28 the server refuses it (`422 nothing_to_seal`); for
|
|
11
|
+
an older server the client stops when the plan counts no file. When files matched but
|
|
12
|
+
hold nothing to seal, the server's own sentence is shown ("Nothing to seal: the files that
|
|
13
|
+
matched contain no code to seal."). When the repository has
|
|
14
|
+
files but none is a Python file, the message adds that CodeImprint seals Python source
|
|
15
|
+
files at present. **In an automated build** (GitHub Actions, GitLab CI, Bitbucket
|
|
16
|
+
Pipelines) it is a warning and the build goes on, as with every seal that cannot be made.
|
|
17
|
+
The Git hook skips such a commit instead of queueing it.
|
|
18
|
+
- **New: a tip after sealing** when the project has no name: "Tip: name this project in the
|
|
19
|
+
hub (or run `imprint project rename <name>`)". Shown only when the server says so.
|
|
20
|
+
- No engine or algorithm code. Tests: `tests/test_empty_seal.py`.
|
|
21
|
+
|
|
22
|
+
## 0.5.0a23 — `imprint verify` says VERIFIED [CIM-BE-36-v2]
|
|
23
|
+
|
|
24
|
+
- **Changed: the result line of `imprint verify`** reads `Result VERIFIED`, `Result
|
|
25
|
+
NOT VERIFIED (N check(s) failed)` or `Result NOT VERIFIED with --strict (N
|
|
26
|
+
warning(s))`. Before, it said VALID / NOT VALID. "Valid" is now used for a seal's validity
|
|
27
|
+
only (`Validity Valid until <date>`, with `--online`), so the two are never confused.
|
|
28
|
+
**Exit codes and `--json` are unchanged** (`"valid": true` or `false` stays as it is). A
|
|
29
|
+
script that reads the text `Result VALID` must read `Result VERIFIED` instead; a
|
|
30
|
+
script that uses the exit code or `--json` needs no change.
|
|
31
|
+
- Tests: `tests/test_certificate.py`.
|
|
32
|
+
|
|
33
|
+
## 0.5.0a22 — Seal certificate, live validity, the server's own badge [CIM-BE-36-v1]
|
|
34
|
+
|
|
35
|
+
For engine 0.7.0a26. Older engines still work, except for `imprint certificate` (they answer
|
|
36
|
+
that the seal is not found) and the validity lines (not shown).
|
|
37
|
+
|
|
38
|
+
- **New: `imprint certificate <fingerprint ID> [-o file.pdf]`.** Downloads the seal
|
|
39
|
+
certificate (a one-page PDF made by the server) and saves it as `certificate-<ID>.pdf` in
|
|
40
|
+
the current folder, or where `-o` says. It is for the owner of the seal's project: signed in
|
|
41
|
+
with `imprint login`, or with that project's CI token. Without a sign-in the command says so
|
|
42
|
+
and asks the server nothing; when the server has no such seal, or the seal is not one of
|
|
43
|
+
your projects', it says that (the server answers both alike, on purpose).
|
|
44
|
+
- **Changed: `imprint verify --online`** adds two lines under the result, in the server's own
|
|
45
|
+
words: `Integrity Sealed <date>, unchanged since` and `Validity Valid until <date>` (or
|
|
46
|
+
`Validity lapsed on <date>`). Validity is worked out live by the server and is not part of
|
|
47
|
+
the signed seal, so offline nothing is shown, and the checks and the exit code are
|
|
48
|
+
unchanged. `--json` adds `validity` (the server's answer, or `null`).
|
|
49
|
+
- **Changed: the README badge that `imprint seal` prints** is the server's own badge
|
|
50
|
+
(`<server>/api/v1/public/imprints/<ID>/badge.svg`): it shows the project's name, when you
|
|
51
|
+
made it public, and the seal's state. Before, it was a static badge from a third-party
|
|
52
|
+
badge service that showed the ID. A badge already in a README keeps working; replace it
|
|
53
|
+
with the new line when you like.
|
|
54
|
+
- No engine or algorithm code: the client downloads and prints. Tests:
|
|
55
|
+
`tests/test_certificate.py`, `tests/test_branding.py`.
|
|
56
|
+
|
|
3
57
|
## 0.5.0a21 — A CI token's check is for its own project [CIM-BE-35-v2]
|
|
4
58
|
|
|
5
59
|
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.0a24
|
|
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.0a24"
|
|
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",
|
|
@@ -19,6 +19,7 @@ import time
|
|
|
19
19
|
from pathlib import Path
|
|
20
20
|
|
|
21
21
|
from . import gitrepo, linecount, trust
|
|
22
|
+
from .api import ApiError
|
|
22
23
|
from .imprint_file import canonical
|
|
23
24
|
|
|
24
25
|
PAGE = 5000 # files per plan request
|
|
@@ -148,7 +149,12 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
|
|
|
148
149
|
pass # the seal does not depend on them
|
|
149
150
|
if kind == "release" and tag:
|
|
150
151
|
body.update(tag=tag, public_tag=public_tag)
|
|
151
|
-
|
|
152
|
+
try:
|
|
153
|
+
resp = client.plan(project, body)
|
|
154
|
+
except ApiError as exc:
|
|
155
|
+
if exc.code == "nothing_to_seal":
|
|
156
|
+
raise NothingToSeal(len(files), _python(files), str(exc)) from exc
|
|
157
|
+
raise
|
|
152
158
|
if "release" in resp:
|
|
153
159
|
rel = resp["release"]
|
|
154
160
|
result = client.finalise(project, rel["pending_id"], public_key(key),
|
|
@@ -161,6 +167,8 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
|
|
|
161
167
|
return {"already": seal, "released": resp.get("already_released"),
|
|
162
168
|
"commit": commit, "info": info}
|
|
163
169
|
plan_id = resp.get("plan_id", plan_id)
|
|
170
|
+
if resp.get("files") == 0: # an engine before 0.7.0a28 would seal nothing
|
|
171
|
+
raise NothingToSeal(len(files), _python(files))
|
|
164
172
|
need = resp["need"]
|
|
165
173
|
sizes = {f["blob"]: f["size"] for f in files}
|
|
166
174
|
size = sum(sizes.get(b, 0) for b in need)
|
|
@@ -175,9 +183,14 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
|
|
|
175
183
|
batch_size += len(data)
|
|
176
184
|
if batch:
|
|
177
185
|
client.upload_blobs(project, batch)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
186
|
+
try:
|
|
187
|
+
prep = client.prepare(project, plan_id)
|
|
188
|
+
if "job_id" in prep:
|
|
189
|
+
prep = _wait(client, prep["job_id"])
|
|
190
|
+
except ApiError as exc:
|
|
191
|
+
if exc.code == "nothing_to_seal":
|
|
192
|
+
raise NothingToSeal(said=str(exc)) from exc
|
|
193
|
+
raise
|
|
181
194
|
result = client.finalise(project, prep["pending_id"], public_key(key),
|
|
182
195
|
sign(key, prep["statement"]))
|
|
183
196
|
check_lines(lines, result)
|
|
@@ -185,6 +198,21 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
|
|
|
185
198
|
"files": resp.get("files", 0), "commit": commit, "info": info, "lines": lines}
|
|
186
199
|
|
|
187
200
|
|
|
201
|
+
NOTHING_TO_SEAL = ("Nothing to seal: no files matched. Check .gitignore, the exclude list in "
|
|
202
|
+
".imprint/config.json, and that you are in the project folder.")
|
|
203
|
+
PYTHON_ONLY = " CodeImprint seals Python source files (.py) at present."
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
class NothingToSeal(RuntimeError):
|
|
207
|
+
"""A seal that would cover no file is never made (engine 0.7.0a28 answers 422
|
|
208
|
+
nothing_to_seal; for an older engine the client stops here, before anything is sent).
|
|
209
|
+
``tracked`` is the number of files Git tracks at the commit, of any kind."""
|
|
210
|
+
|
|
211
|
+
def __init__(self, tracked: int = 0, python: int = 0, said: str | None = None) -> None:
|
|
212
|
+
super().__init__((said or NOTHING_TO_SEAL)
|
|
213
|
+
+ (PYTHON_ONLY if tracked and not python else ""))
|
|
214
|
+
|
|
215
|
+
|
|
188
216
|
def check_lines(sent: dict, result: dict) -> None:
|
|
189
217
|
"""The Imprint you signed carries the count this client sent (older servers keep none)."""
|
|
190
218
|
kept = (result.get("imprint") or {}).get("lines")
|
|
@@ -193,6 +221,10 @@ def check_lines(sent: dict, result: dict) -> None:
|
|
|
193
221
|
"counted; the seal is logged, but report this")
|
|
194
222
|
|
|
195
223
|
|
|
224
|
+
def _python(files: list[dict]) -> int:
|
|
225
|
+
return sum(1 for f in files if f["path"].endswith(".py"))
|
|
226
|
+
|
|
227
|
+
|
|
196
228
|
# -- local state ---------------------------------------------------------------------------
|
|
197
229
|
def _state(root: Path) -> Path:
|
|
198
230
|
path = gitrepo.git_dir(root) / "codeimprint"
|
|
@@ -458,6 +458,8 @@ def _other_repository(client: Client, cfg: dict, root: Path) -> None:
|
|
|
458
458
|
def _prepare_upload(path: str, action: str, client: Client, assume_yes: bool) -> bytes:
|
|
459
459
|
sel = project.select_files(path)
|
|
460
460
|
if sel.count == 0:
|
|
461
|
+
if action == "seal": # a seal of nothing is never made
|
|
462
|
+
raise SealFailed(chainseal.NOTHING_TO_SEAL + chainseal.PYTHON_ONLY)
|
|
461
463
|
raise Abort(f"no Python files to send under {sel.root} (check .gitignore and "
|
|
462
464
|
".imprint/config.json excludes)")
|
|
463
465
|
data = project.build_zip(sel)
|
|
@@ -994,6 +996,9 @@ def _hook_run(args, root: Path) -> int:
|
|
|
994
996
|
try:
|
|
995
997
|
out = chainseal.seal_commit(client, root, cfg["project_id"], item["commit"],
|
|
996
998
|
item["kind"], key, cfg.get("exclude"))
|
|
999
|
+
except chainseal.NothingToSeal as exc: # not queued: it would never seal
|
|
1000
|
+
warn(f"seal of {item['commit'][:12]} skipped: {exc}")
|
|
1001
|
+
continue
|
|
997
1002
|
except Exception as exc: # noqa: BLE001 — a hook never blocks a commit or push
|
|
998
1003
|
chainseal.save_queue(root, queue[i:])
|
|
999
1004
|
return warn(f"seal of {item['commit'][:12]} queued ({len(queue) - i} waiting): "
|
|
@@ -1830,7 +1835,10 @@ def _finish(args, client: Client, root: Path, result: dict, keys: list,
|
|
|
1830
1835
|
f"Receipt {rec_path}",
|
|
1831
1836
|
_verify_line(iid, hub, out))
|
|
1832
1837
|
if hub:
|
|
1833
|
-
_say("", "README badge:", imprint_file.badge(iid, hub))
|
|
1838
|
+
_say("", "README badge:", imprint_file.badge(iid, hub, client.url))
|
|
1839
|
+
if result.get("project_named") is False: # engine 0.7.0a28: the project has no name
|
|
1840
|
+
_say("", "Tip: name this project in the hub (or run `imprint project rename <name>`): "
|
|
1841
|
+
"the name appears on its seal page, badge and certificate.")
|
|
1834
1842
|
_say("", SEAL_NOTE)
|
|
1835
1843
|
_step_summary(iid, rec, stamps, signer, hub)
|
|
1836
1844
|
return 0
|
|
@@ -1858,6 +1866,8 @@ def _seal_zip(args, client: Client, data: bytes, project_id: str | None,
|
|
|
1858
1866
|
if lines is not None:
|
|
1859
1867
|
chainseal.check_lines(lines, result)
|
|
1860
1868
|
except (ApiError, NetworkError) as exc:
|
|
1869
|
+
if isinstance(exc, ApiError) and exc.code == "nothing_to_seal":
|
|
1870
|
+
raise SealFailed(str(exc) or chainseal.NOTHING_TO_SEAL) from exc
|
|
1861
1871
|
raise SealFailed(_explain(client, exc, "sealing failed")) from exc
|
|
1862
1872
|
except RuntimeError as exc:
|
|
1863
1873
|
raise SealFailed(str(exc)) from exc
|
|
@@ -2557,6 +2567,55 @@ def _trusted_keys(args, root: Path, client: Client | None,
|
|
|
2557
2567
|
return []
|
|
2558
2568
|
|
|
2559
2569
|
|
|
2570
|
+
def _validity(client: Client, iid: str) -> dict | None:
|
|
2571
|
+
"""A seal's validity now, from the server (`imprint verify --online`). None from a server
|
|
2572
|
+
that does not have it (before 0.7.0a26) or cannot be reached: validity is worked out
|
|
2573
|
+
live by the server, so offline there is nothing to show."""
|
|
2574
|
+
try:
|
|
2575
|
+
state = client.validity(iid)
|
|
2576
|
+
return state if isinstance(state.get("wording"), dict) else None
|
|
2577
|
+
except (ApiError, NetworkError, AttributeError):
|
|
2578
|
+
return None
|
|
2579
|
+
|
|
2580
|
+
|
|
2581
|
+
def cmd_certificate(args) -> int:
|
|
2582
|
+
"""`imprint certificate IMP1-… [-o file.pdf]`: download a seal's certificate (PDF)."""
|
|
2583
|
+
if not imprint_file.is_valid_id(args.seal):
|
|
2584
|
+
raise Abort(f"not a fingerprint ID (IMP1-…): {args.seal}")
|
|
2585
|
+
iid = imprint_file.clean_id(args.seal)
|
|
2586
|
+
client = _client(args, _server_from_project(Path(".")))
|
|
2587
|
+
# The server answers everyone but the owner like a seal that does not exist, so say here
|
|
2588
|
+
# what it will not say: that nobody is signed in.
|
|
2589
|
+
if client.auth == "none":
|
|
2590
|
+
raise Abort(f"you are not signed in to {client.url}: run `imprint login` first. A "
|
|
2591
|
+
"seal's certificate is for the owner of its project.")
|
|
2592
|
+
if client.auth == "expired":
|
|
2593
|
+
raise Abort(f"your sign-in to {client.url} has expired: run `imprint login` again.")
|
|
2594
|
+
try:
|
|
2595
|
+
pdf = client.certificate(iid)
|
|
2596
|
+
except ApiError as exc:
|
|
2597
|
+
if exc.status == 404:
|
|
2598
|
+
scope = (" A CI token reaches the seals of its own project only."
|
|
2599
|
+
if client.auth == "ci" else "")
|
|
2600
|
+
raise Abort(f"no certificate for {iid}: {client.url} has no such seal, or it is "
|
|
2601
|
+
f"not a seal of one of your projects.{scope} If your sign-in has "
|
|
2602
|
+
"ended, run `imprint login` again.") from exc
|
|
2603
|
+
raise Abort(_explain(client, exc, f"cannot download the certificate for {iid}")) \
|
|
2604
|
+
from exc
|
|
2605
|
+
except NetworkError as exc:
|
|
2606
|
+
raise Abort(str(exc)) from exc
|
|
2607
|
+
out = Path(args.out or f"certificate-{iid}.pdf")
|
|
2608
|
+
try:
|
|
2609
|
+
out.parent.mkdir(parents=True, exist_ok=True)
|
|
2610
|
+
out.write_bytes(pdf)
|
|
2611
|
+
except OSError as exc:
|
|
2612
|
+
raise Abort(f"cannot write {out}: {exc}") from exc
|
|
2613
|
+
_say(f"Certificate {out}",
|
|
2614
|
+
" A summary of the seal record; the record itself is the evidence "
|
|
2615
|
+
f"(`imprint verify {iid}`).")
|
|
2616
|
+
return 0
|
|
2617
|
+
|
|
2618
|
+
|
|
2560
2619
|
def _server_from_project(root: Path) -> str | None:
|
|
2561
2620
|
path = root / project.CONFIG_DIR / trust.PROJECT_KEYS
|
|
2562
2621
|
try:
|
|
@@ -2661,6 +2720,7 @@ def cmd_verify(args) -> int:
|
|
|
2661
2720
|
doc, rec, root = _load_target(args)
|
|
2662
2721
|
found = getattr(args, "found_opening", None)
|
|
2663
2722
|
checks: list[receipt.Check] = []
|
|
2723
|
+
state = None # the seal's validity now (--online only)
|
|
2664
2724
|
client = _client(args, _server_from_project(root)) if args.online else None
|
|
2665
2725
|
if rec is None and client is not None:
|
|
2666
2726
|
iid = imprint_file.clean_id(args.target) if doc is None else (
|
|
@@ -2703,6 +2763,8 @@ def cmd_verify(args) -> int:
|
|
|
2703
2763
|
except (ApiError, NetworkError, KeyError) as exc:
|
|
2704
2764
|
checks.append(receipt.Check("log consistency", receipt.FAIL,
|
|
2705
2765
|
f"cannot check the live log: {exc}"))
|
|
2766
|
+
if client is not None and "record" not in rec:
|
|
2767
|
+
state = _validity(client, iid)
|
|
2706
2768
|
if here is not None:
|
|
2707
2769
|
checks.append(here)
|
|
2708
2770
|
if elsewhere: # say nothing about where the seal does belong
|
|
@@ -2720,16 +2782,21 @@ def cmd_verify(args) -> int:
|
|
|
2720
2782
|
"issued_for_this_repository": (
|
|
2721
2783
|
False if elsewhere else True if any(
|
|
2722
2784
|
c.name == "repository" for c in checks) else None),
|
|
2785
|
+
"validity": state if valid else None,
|
|
2723
2786
|
"checks": [c.as_dict() for c in checks]}, indent=2))
|
|
2724
2787
|
else:
|
|
2725
2788
|
_say(f"{'Record ' if rec and 'record' in rec else 'Imprint'} {iid}", "")
|
|
2726
2789
|
for c in checks:
|
|
2727
2790
|
_say(f"{c.status:<5} {c.name:<20} {c.detail}")
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
f"NOT
|
|
2731
|
-
|
|
2732
|
-
|
|
2791
|
+
# "Verified" is about the checks. "Valid" is kept for a seal's validity alone.
|
|
2792
|
+
verdict = ("VERIFIED" if valid else
|
|
2793
|
+
f"NOT VERIFIED ({len(failed)} check(s) failed)" if failed else
|
|
2794
|
+
f"NOT VERIFIED with --strict ({len(warned)} warning(s))")
|
|
2795
|
+
_say("", f"Result {verdict}", *([f" {NOT_ISSUED}"] if elsewhere else []))
|
|
2796
|
+
if valid and state: # the server's own wording, as the seal page shows
|
|
2797
|
+
_say(f"Integrity {state['wording']['integrity']}",
|
|
2798
|
+
f"Validity {state['wording']['validity']}")
|
|
2799
|
+
_say("", SEAL_NOTE)
|
|
2733
2800
|
return 0 if valid else 1
|
|
2734
2801
|
|
|
2735
2802
|
|
|
@@ -3031,6 +3098,14 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
3031
3098
|
ln.add_argument("--json", action="store_true")
|
|
3032
3099
|
ln.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
|
|
3033
3100
|
ln.set_defaults(func=cmd_lineage)
|
|
3101
|
+
|
|
3102
|
+
ce = sub.add_parser("certificate", help="download a seal's certificate (PDF): for the "
|
|
3103
|
+
"owner of the seal's project")
|
|
3104
|
+
ce.add_argument("seal", metavar="FINGERPRINT_ID", help="the seal's ID (IMP1-…)")
|
|
3105
|
+
ce.add_argument("-o", "--out", metavar="FILE",
|
|
3106
|
+
help="where to save it (default: certificate-<ID>.pdf in this folder)")
|
|
3107
|
+
ce.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
|
|
3108
|
+
ce.set_defaults(func=cmd_certificate)
|
|
3034
3109
|
return p
|
|
3035
3110
|
|
|
3036
3111
|
|
|
@@ -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
|