codeimprint 0.5.0a23__tar.gz → 0.5.0a26__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.0a23 → codeimprint-0.5.0a26}/CHANGELOG.md +59 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/PKG-INFO +1 -1
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/pyproject.toml +1 -1
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/__init__.py +1 -1
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/api.py +51 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/chainseal.py +37 -5
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/cli.py +278 -1
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/receipt.py +16 -1
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/.gitignore +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/LICENSE +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/NOTICE +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/README.pypi.md +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint/__init__.py +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint/__main__.py +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/__main__.py +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/config.py +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/gitrepo.py +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/imprint_file.py +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/linecount.py +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/ownership.py +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/project.py +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/records.py +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/timestamp.py +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/transparency.py +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/trust.py +0 -0
- {codeimprint-0.5.0a23 → codeimprint-0.5.0a26}/src/codeimprint_cli/tsa_roots.py +0 -0
|
@@ -1,5 +1,64 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0a26 — Engagement decisions [CIM-BE-38-v2]
|
|
4
|
+
|
|
5
|
+
For engine 0.7.0a30.
|
|
6
|
+
|
|
7
|
+
- **Changed: the takeover baseline is shown in the server's words**: "Matches the handover",
|
|
8
|
+
"Same content, different history" or "No shared history with the handover" (never
|
|
9
|
+
"differs"). `imprint seal` also shows it when the vendor's first tree was already sealed
|
|
10
|
+
(the existing seal is then the baseline).
|
|
11
|
+
- **Changed: a vendor's scoped key is found by fingerprint.** The public key list leaves it
|
|
12
|
+
out unless the engagement is public, so `imprint seal` (before sending anything) and
|
|
13
|
+
`imprint verify --online` (the "project key" check) ask for that one key. Clients before
|
|
14
|
+
0.5.0a26 fail that check for seals signed by a hidden scoped key.
|
|
15
|
+
- `imprint deliver --to-client` shows the server's answer when it is refused: certificate
|
|
16
|
+
details needed (with the hub's page), not an invited account, or more than 5 e-mails in 24
|
|
17
|
+
hours.
|
|
18
|
+
- Tests: `tests/test_engagements.py`.
|
|
19
|
+
|
|
20
|
+
## 0.5.0a25 — Working with vendors and clients [CIM-BE-38-v1]
|
|
21
|
+
|
|
22
|
+
For engine 0.7.0a29. Older engines answer the new commands with 404.
|
|
23
|
+
|
|
24
|
+
- **New: `imprint engagement`.**
|
|
25
|
+
- `create --vendor "<name>" [--days N]` (you own the project): an engagement and its token,
|
|
26
|
+
shown once, with the steps to send your vendor.
|
|
27
|
+
- `create --client "<name>" --email <address>` (you are the vendor).
|
|
28
|
+
- `list`, `show <eng_…>`, `end <eng_…> [--handover IMP1-… | --no-handover]`,
|
|
29
|
+
`public <eng_…> on|off`. With an engagement token, `list` shows the token's own
|
|
30
|
+
engagement.
|
|
31
|
+
- `join` (the vendor, with the engagement token in `CODEIMPRINT_TOKEN`): this machine's
|
|
32
|
+
developer key becomes the engagement's key, and `.imprint/config.json` names the project
|
|
33
|
+
and the engagement.
|
|
34
|
+
- **New: `imprint deliver <IMP1-…> [--note …]`**: with the engagement token, tell the project
|
|
35
|
+
owner a seal is delivered; with `--to-client` (signed in, vendor-led), e-mail your client a
|
|
36
|
+
link to accept it.
|
|
37
|
+
- **New: `imprint accept <IMP1-…>`**: the project owner accepts a delivered seal.
|
|
38
|
+
- **Changed: `imprint seal` with an engagement token** prints "Sealed by <vendor> (named by
|
|
39
|
+
the project owner), engagement eng_…", and for a new vendor's first seal whether it
|
|
40
|
+
matches the previous vendor's handover.
|
|
41
|
+
- README: "Working with vendors and clients". Tests: `tests/test_engagements.py`.
|
|
42
|
+
|
|
43
|
+
## 0.5.0a24 — Empty seals are refused; a tip to name a project [CIM-BE-37-v1]
|
|
44
|
+
|
|
45
|
+
For engine 0.7.0a28. Older engines still work.
|
|
46
|
+
|
|
47
|
+
- **Changed: `imprint seal` refuses a seal that would cover no file.** "Nothing to seal: no
|
|
48
|
+
files matched. Check .gitignore, the exclude list in .imprint/config.json, and that you
|
|
49
|
+
are in the project folder." The exit code is 2; nothing is sent beyond the plan and
|
|
50
|
+
nothing is logged. With engine 0.7.0a28 the server refuses it (`422 nothing_to_seal`); for
|
|
51
|
+
an older server the client stops when the plan counts no file. When files matched but
|
|
52
|
+
hold nothing to seal, the server's own sentence is shown ("Nothing to seal: the files that
|
|
53
|
+
matched contain no code to seal."). When the repository has
|
|
54
|
+
files but none is a Python file, the message adds that CodeImprint seals Python source
|
|
55
|
+
files at present. **In an automated build** (GitHub Actions, GitLab CI, Bitbucket
|
|
56
|
+
Pipelines) it is a warning and the build goes on, as with every seal that cannot be made.
|
|
57
|
+
The Git hook skips such a commit instead of queueing it.
|
|
58
|
+
- **New: a tip after sealing** when the project has no name: "Tip: name this project in the
|
|
59
|
+
hub (or run `imprint project rename <name>`)". Shown only when the server says so.
|
|
60
|
+
- No engine or algorithm code. Tests: `tests/test_empty_seal.py`.
|
|
61
|
+
|
|
3
62
|
## 0.5.0a23 — `imprint verify` says VERIFIED [CIM-BE-36-v2]
|
|
4
63
|
|
|
5
64
|
- **Changed: the result line of `imprint verify`** reads `Result VERIFIED`, `Result
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: codeimprint
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.0a26
|
|
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.0a26"
|
|
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"
|
|
@@ -215,6 +215,51 @@ class Client:
|
|
|
215
215
|
def revoke_token(self, token_id: str) -> dict:
|
|
216
216
|
return self._json("POST", f"/api/v1/me/tokens/{quote(token_id)}/revoke", {})
|
|
217
217
|
|
|
218
|
+
# client–vendor engagements (engine 0.7.0a29) ------------------------------------------
|
|
219
|
+
def create_engagement(self, project: str, mode: str, party_name: str,
|
|
220
|
+
party_email: str | None = None, days: int = 90) -> dict:
|
|
221
|
+
body = {"mode": mode, "party_name": party_name, "days": days}
|
|
222
|
+
if party_email:
|
|
223
|
+
body["party_email"] = party_email
|
|
224
|
+
return self._json("POST", f"/api/v1/projects/{quote(project)}/engagements", body)
|
|
225
|
+
|
|
226
|
+
def engagements(self, project: str | None = None) -> list[dict]:
|
|
227
|
+
path = (f"/api/v1/projects/{quote(project)}/engagements" if project
|
|
228
|
+
else "/api/v1/me/engagements")
|
|
229
|
+
return self._request("GET", path).get("items") or []
|
|
230
|
+
|
|
231
|
+
def engagement(self, engagement_id: str) -> dict:
|
|
232
|
+
return self._request("GET", f"/api/v1/engagements/{quote(engagement_id)}")
|
|
233
|
+
|
|
234
|
+
def my_engagement(self) -> dict:
|
|
235
|
+
"""The engagement of the engagement token in use (the vendor's view)."""
|
|
236
|
+
return self._request("GET", "/api/v1/engagement")
|
|
237
|
+
|
|
238
|
+
def end_engagement(self, engagement_id: str, handover: str | None = None,
|
|
239
|
+
no_handover: bool = False) -> dict:
|
|
240
|
+
return self._json("POST", f"/api/v1/engagements/{quote(engagement_id)}/end",
|
|
241
|
+
{"handover": handover, "no_handover": no_handover})
|
|
242
|
+
|
|
243
|
+
def engagement_visibility(self, engagement_id: str, public: bool) -> dict:
|
|
244
|
+
return self._json("POST", f"/api/v1/engagements/{quote(engagement_id)}/visibility",
|
|
245
|
+
{"public": public})
|
|
246
|
+
|
|
247
|
+
def engagement_key(self, public_key: str, signature: str) -> dict:
|
|
248
|
+
return self._json("POST", "/api/v1/engagement/key",
|
|
249
|
+
{"public_key": public_key, "signature": signature})
|
|
250
|
+
|
|
251
|
+
def deliver(self, seal_id: str, note: str | None = None, to_client: bool = False,
|
|
252
|
+
engagement: str | None = None) -> dict:
|
|
253
|
+
body: dict = {"to_client": to_client}
|
|
254
|
+
if note:
|
|
255
|
+
body["note"] = note
|
|
256
|
+
if engagement:
|
|
257
|
+
body["engagement"] = engagement
|
|
258
|
+
return self._json("POST", f"/api/v1/seals/{quote(seal_id)}/deliver", body)
|
|
259
|
+
|
|
260
|
+
def accept(self, seal_id: str) -> dict:
|
|
261
|
+
return self._json("POST", f"/api/v1/seals/{quote(seal_id)}/accept", {})
|
|
262
|
+
|
|
218
263
|
def lineage(self, record_id: str) -> dict:
|
|
219
264
|
"""A lineage record (LIN1): its public record and, when this account may see it,
|
|
220
265
|
the opening of its commitment (engine 0.7.0a21+)."""
|
|
@@ -263,6 +308,12 @@ class Client:
|
|
|
263
308
|
def public_project(self, project: str) -> dict:
|
|
264
309
|
return self._json("GET", f"/api/v1/public/projects/{quote(project)}")
|
|
265
310
|
|
|
311
|
+
def public_project_key(self, project: str, fingerprint: str) -> dict:
|
|
312
|
+
"""One key of a project by fingerprint (engine 0.7.0a30): the public key list leaves
|
|
313
|
+
out a vendor's scoped key unless its engagement is public."""
|
|
314
|
+
return self._json("GET", f"/api/v1/public/projects/{quote(project)}/keys/"
|
|
315
|
+
f"{quote(fingerprint)}")
|
|
316
|
+
|
|
266
317
|
def public_chain(self, project: str, after: int | None = None) -> dict:
|
|
267
318
|
query = f"?after={int(after)}" if after is not None else ""
|
|
268
319
|
return self._json("GET", f"/api/v1/public/projects/{quote(project)}/chain{query}")
|
|
@@ -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),
|
|
@@ -159,8 +165,10 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
|
|
|
159
165
|
# earlier engines: already_sealed is the seal's ID.
|
|
160
166
|
seal = resp["id"] if resp["already_sealed"] is True else resp["already_sealed"]
|
|
161
167
|
return {"already": seal, "released": resp.get("already_released"),
|
|
162
|
-
"commit": commit, "info": info}
|
|
168
|
+
"commit": commit, "info": info, "engagement": resp.get("engagement")}
|
|
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"
|
|
@@ -430,7 +430,7 @@ def _project_ready(client: Client, project_id: str, key, root: Path | None = Non
|
|
|
430
430
|
+ (MOVE_HINT if fp in active and not settled else ""))
|
|
431
431
|
if keys is None:
|
|
432
432
|
return ident
|
|
433
|
-
if active and fp not in active:
|
|
433
|
+
if active and fp not in active and not _scoped_key(client, project_id, fp):
|
|
434
434
|
raise SealFailed(
|
|
435
435
|
f"developer key {fp} on this machine is not a key of project {project_id} (its "
|
|
436
436
|
f"keys: {', '.join(active)}). Add this device to the project: run `imprint key "
|
|
@@ -439,6 +439,16 @@ def _project_ready(client: Client, project_id: str, key, root: Path | None = Non
|
|
|
439
439
|
return ident
|
|
440
440
|
|
|
441
441
|
|
|
442
|
+
def _scoped_key(client: Client, project_id: str, fp: str) -> bool:
|
|
443
|
+
"""A vendor's engagement key is not on the public key list (engine 0.7.0a30) unless the
|
|
444
|
+
engagement is public: ask for it by fingerprint."""
|
|
445
|
+
try:
|
|
446
|
+
k = client.public_project_key(project_id, fp)
|
|
447
|
+
except (ApiError, NetworkError):
|
|
448
|
+
return False
|
|
449
|
+
return isinstance(k, dict) and k.get("fingerprint") == fp and not k.get("valid_until")
|
|
450
|
+
|
|
451
|
+
|
|
442
452
|
def _other_repository(client: Client, cfg: dict, root: Path) -> None:
|
|
443
453
|
"""For a machine without a developer key: refuse, with the one sentence, when this is not
|
|
444
454
|
the repository the folder's project lives in. Otherwise say nothing (the caller then
|
|
@@ -458,6 +468,8 @@ def _other_repository(client: Client, cfg: dict, root: Path) -> None:
|
|
|
458
468
|
def _prepare_upload(path: str, action: str, client: Client, assume_yes: bool) -> bytes:
|
|
459
469
|
sel = project.select_files(path)
|
|
460
470
|
if sel.count == 0:
|
|
471
|
+
if action == "seal": # a seal of nothing is never made
|
|
472
|
+
raise SealFailed(chainseal.NOTHING_TO_SEAL + chainseal.PYTHON_ONLY)
|
|
461
473
|
raise Abort(f"no Python files to send under {sel.root} (check .gitignore and "
|
|
462
474
|
".imprint/config.json excludes)")
|
|
463
475
|
data = project.build_zip(sel)
|
|
@@ -994,6 +1006,9 @@ def _hook_run(args, root: Path) -> int:
|
|
|
994
1006
|
try:
|
|
995
1007
|
out = chainseal.seal_commit(client, root, cfg["project_id"], item["commit"],
|
|
996
1008
|
item["kind"], key, cfg.get("exclude"))
|
|
1009
|
+
except chainseal.NothingToSeal as exc: # not queued: it would never seal
|
|
1010
|
+
warn(f"seal of {item['commit'][:12]} skipped: {exc}")
|
|
1011
|
+
continue
|
|
997
1012
|
except Exception as exc: # noqa: BLE001 — a hook never blocks a commit or push
|
|
998
1013
|
chainseal.save_queue(root, queue[i:])
|
|
999
1014
|
return warn(f"seal of {item['commit'][:12]} queued ({len(queue) - i} waiting): "
|
|
@@ -1825,12 +1840,20 @@ def _finish(args, client: Client, root: Path, result: dict, keys: list,
|
|
|
1825
1840
|
"Timestamps")
|
|
1826
1841
|
for c in stamps:
|
|
1827
1842
|
_say(f" {c.status:<5} {c.name.removeprefix('timestamp').strip() or '-':<10} {c.detail}")
|
|
1843
|
+
eng = result.get("engagement")
|
|
1844
|
+
if eng: # a vendor's seal (engine 0.7.0a29)
|
|
1845
|
+
_say(f"Sealed by {eng['sealed_by']} ({eng['named_by']}), engagement {eng['id']}")
|
|
1846
|
+
if eng.get("taken_over"):
|
|
1847
|
+
_say(f"Baseline {_baseline_text(eng)}")
|
|
1828
1848
|
_say(f"Signed {'developer key ' + signer if signer else 'not signed by you'}",
|
|
1829
1849
|
f"Saved {out}",
|
|
1830
1850
|
f"Receipt {rec_path}",
|
|
1831
1851
|
_verify_line(iid, hub, out))
|
|
1832
1852
|
if hub:
|
|
1833
1853
|
_say("", "README badge:", imprint_file.badge(iid, hub, client.url))
|
|
1854
|
+
if result.get("project_named") is False: # engine 0.7.0a28: the project has no name
|
|
1855
|
+
_say("", "Tip: name this project in the hub (or run `imprint project rename <name>`): "
|
|
1856
|
+
"the name appears on its seal page, badge and certificate.")
|
|
1834
1857
|
_say("", SEAL_NOTE)
|
|
1835
1858
|
_step_summary(iid, rec, stamps, signer, hub)
|
|
1836
1859
|
return 0
|
|
@@ -1858,6 +1881,8 @@ def _seal_zip(args, client: Client, data: bytes, project_id: str | None,
|
|
|
1858
1881
|
if lines is not None:
|
|
1859
1882
|
chainseal.check_lines(lines, result)
|
|
1860
1883
|
except (ApiError, NetworkError) as exc:
|
|
1884
|
+
if isinstance(exc, ApiError) and exc.code == "nothing_to_seal":
|
|
1885
|
+
raise SealFailed(str(exc) or chainseal.NOTHING_TO_SEAL) from exc
|
|
1861
1886
|
raise SealFailed(_explain(client, exc, "sealing failed")) from exc
|
|
1862
1887
|
except RuntimeError as exc:
|
|
1863
1888
|
raise SealFailed(str(exc)) from exc
|
|
@@ -1941,6 +1966,9 @@ def _seal_git(args, client: Client, root: Path, cfg: dict) -> int:
|
|
|
1941
1966
|
if "already" in out:
|
|
1942
1967
|
_say(f"Already sealed: {out['already']} (commit {commit[:12]}: this tree is "
|
|
1943
1968
|
"already in the project's chain; no new seal, nothing logged)")
|
|
1969
|
+
eng = out.get("engagement") or {}
|
|
1970
|
+
if eng.get("taken_over"): # a new vendor's baseline is that seal
|
|
1971
|
+
_say(f"Baseline {_baseline_text(eng)}")
|
|
1944
1972
|
continue
|
|
1945
1973
|
chainseal.record(root, out["result"], commit, out["info"]["ref"])
|
|
1946
1974
|
if i < len(commits) - 1:
|
|
@@ -2286,6 +2314,221 @@ def cmd_token(args) -> int:
|
|
|
2286
2314
|
return 0
|
|
2287
2315
|
|
|
2288
2316
|
|
|
2317
|
+
# -- client–vendor engagements (engine 0.7.0a29) ---------------------------------------------
|
|
2318
|
+
ENGAGEMENT_KEY = "codeimprint.engagement-key.v1"
|
|
2319
|
+
|
|
2320
|
+
|
|
2321
|
+
BASELINE = {"matches": "Matches the handover",
|
|
2322
|
+
"same_content": "Same content, different history",
|
|
2323
|
+
"no_shared_history": "No shared history with the handover"}
|
|
2324
|
+
|
|
2325
|
+
|
|
2326
|
+
def _baseline_text(eng: dict) -> str:
|
|
2327
|
+
"""The takeover baseline as the server words it (older servers: its result code)."""
|
|
2328
|
+
said = eng.get("taken_over_text") or BASELINE.get(eng.get("taken_over"),
|
|
2329
|
+
str(eng.get("taken_over")))
|
|
2330
|
+
return f"taken over from the previous vendor: {said}"
|
|
2331
|
+
|
|
2332
|
+
|
|
2333
|
+
def _engagement_lines(e: dict) -> list[str]:
|
|
2334
|
+
party = e["party"]
|
|
2335
|
+
who = party.get("name") or "(erased)"
|
|
2336
|
+
lines = [f"Engagement {e['id']} {e['status']} "
|
|
2337
|
+
+ ("client-led" if e["mode"] == "client_led" else "vendor-led"),
|
|
2338
|
+
f" Project {e['project_id']}",
|
|
2339
|
+
f" {party['role'].capitalize():<9} {who} ({party['named_by']}"
|
|
2340
|
+
+ (f"; confirmed by email ({party['confirmed_by_email']})"
|
|
2341
|
+
if party.get("confirmed_by_email") else "") + ")"]
|
|
2342
|
+
if party.get("email"):
|
|
2343
|
+
lines.append(f" Email {party['email']}")
|
|
2344
|
+
if e.get("token"):
|
|
2345
|
+
lines.append(f" Token {e['token']['id']} {e['token']['status']}, expires "
|
|
2346
|
+
f"{e['token']['expires_at']}")
|
|
2347
|
+
if e["mode"] == "client_led":
|
|
2348
|
+
lines.append(f" Repository {'set by the first seal' if e['home'] == 'set' else 'not set yet'}")
|
|
2349
|
+
lines.append(f" Public {'shown on the public seal pages' if e['public'] else 'no'}")
|
|
2350
|
+
lines += [f" {ev['at'][:10]} {ev['text']}" + (f" [{ev['seal']}]" if ev.get("seal") else "")
|
|
2351
|
+
for ev in e["events"]]
|
|
2352
|
+
return lines
|
|
2353
|
+
|
|
2354
|
+
|
|
2355
|
+
def _project_of(args) -> str | None:
|
|
2356
|
+
root = Path(getattr(args, "path", ".") or ".")
|
|
2357
|
+
cfg = project.load_config(root) if root.is_dir() else {}
|
|
2358
|
+
return args.project or cfg.get("project_id")
|
|
2359
|
+
|
|
2360
|
+
|
|
2361
|
+
def cmd_engagement(args) -> int:
|
|
2362
|
+
"""`imprint engagement create | list | show | end | public | join`."""
|
|
2363
|
+
if args.action == "join":
|
|
2364
|
+
return _engagement_join(args)
|
|
2365
|
+
if args.action == "list" and config.resolve(getattr(args, "url", None)).token and \
|
|
2366
|
+
str(config.resolve(getattr(args, "url", None)).token).startswith(CI_TOKEN_PREFIX):
|
|
2367
|
+
client = _client(args)
|
|
2368
|
+
try:
|
|
2369
|
+
mine = client.my_engagement()
|
|
2370
|
+
except (ApiError, NetworkError) as exc:
|
|
2371
|
+
raise Abort(_explain(client, exc, "cannot read the engagement")) from exc
|
|
2372
|
+
if args.json:
|
|
2373
|
+
print(json.dumps(mine, indent=2))
|
|
2374
|
+
return 0
|
|
2375
|
+
_say(*_engagement_lines(mine))
|
|
2376
|
+
return 0
|
|
2377
|
+
client = _session_client(args)
|
|
2378
|
+
try:
|
|
2379
|
+
if args.action == "create":
|
|
2380
|
+
return _engagement_create(args, client)
|
|
2381
|
+
if args.action == "list":
|
|
2382
|
+
items = client.engagements(args.project)
|
|
2383
|
+
if args.json:
|
|
2384
|
+
print(json.dumps(items, indent=2))
|
|
2385
|
+
return 0
|
|
2386
|
+
if not items:
|
|
2387
|
+
_say("No engagements. Start one with `imprint engagement create --vendor "
|
|
2388
|
+
"<name>` (your vendor) or `--client <name> --email <address>` (your "
|
|
2389
|
+
"client).")
|
|
2390
|
+
for e in items:
|
|
2391
|
+
_say(*_engagement_lines(e), "")
|
|
2392
|
+
return 0
|
|
2393
|
+
if not args.target:
|
|
2394
|
+
raise Abort(f"name the engagement: imprint engagement {args.action} <eng_…> (see "
|
|
2395
|
+
"`imprint engagement list`)")
|
|
2396
|
+
if args.action == "show":
|
|
2397
|
+
e = client.engagement(args.target)
|
|
2398
|
+
elif args.action == "end":
|
|
2399
|
+
e = client.end_engagement(args.target, args.handover, args.no_handover)
|
|
2400
|
+
_say("Ended. Its token no longer works and the vendor's keys are retired; the "
|
|
2401
|
+
"history stays.")
|
|
2402
|
+
else:
|
|
2403
|
+
if args.state not in ("on", "off"):
|
|
2404
|
+
raise Abort("say on or off: imprint engagement public <eng_…> on")
|
|
2405
|
+
e = client.engagement_visibility(args.target, args.state == "on")
|
|
2406
|
+
except (ApiError, NetworkError) as exc:
|
|
2407
|
+
raise Abort(_explain(client, exc, "the engagement request failed")) from exc
|
|
2408
|
+
if args.json:
|
|
2409
|
+
print(json.dumps(e, indent=2))
|
|
2410
|
+
return 0
|
|
2411
|
+
_say(*_engagement_lines(e))
|
|
2412
|
+
return 0
|
|
2413
|
+
|
|
2414
|
+
|
|
2415
|
+
def _engagement_create(args, client: Client) -> int:
|
|
2416
|
+
project_id = _project_of(args)
|
|
2417
|
+
if not project_id:
|
|
2418
|
+
raise Abort("no project: run this in the project's folder, or pass --project")
|
|
2419
|
+
if bool(args.vendor) == bool(args.client):
|
|
2420
|
+
raise Abort("name one party: --vendor <name> (you own the project) or --client <name> "
|
|
2421
|
+
"--email <address> (you are the vendor)")
|
|
2422
|
+
if args.client and not args.email:
|
|
2423
|
+
raise Abort("--client needs --email: the client accepts deliveries through a link "
|
|
2424
|
+
"sent there")
|
|
2425
|
+
if not 1 <= args.days <= 365:
|
|
2426
|
+
raise Abort("--days is 1 to 365: an engagement token always expires")
|
|
2427
|
+
made = client.create_engagement(project_id, "client_led" if args.vendor else "vendor_led",
|
|
2428
|
+
args.vendor or args.client, args.email, args.days)
|
|
2429
|
+
_say(*_engagement_lines(made))
|
|
2430
|
+
if made.get("token_value"):
|
|
2431
|
+
_say("", f"Token {made['token_value']}",
|
|
2432
|
+
" Shown once: copy it now. It is not saved on this machine or shown again.",
|
|
2433
|
+
"", "Send the vendor these steps (and the token, in a safe way):", "",
|
|
2434
|
+
made.get("setup", ""))
|
|
2435
|
+
else:
|
|
2436
|
+
_say("", f"Deliver a seal with: imprint deliver <IMP1-…> --to-client "
|
|
2437
|
+
f"(an e-mail asks {made['party']['name']} to accept it)",
|
|
2438
|
+
"The e-mail names you by your certificate details (set them in the hub), else "
|
|
2439
|
+
"your sign-in's handle, else the project's name.")
|
|
2440
|
+
return 0
|
|
2441
|
+
|
|
2442
|
+
|
|
2443
|
+
def _engagement_join(args) -> int:
|
|
2444
|
+
"""With an engagement token: this machine's developer key becomes the engagement's key,
|
|
2445
|
+
and this repository's .imprint/config.json names the project."""
|
|
2446
|
+
client = _client(args)
|
|
2447
|
+
if client.auth != "ci":
|
|
2448
|
+
raise Abort("set CODEIMPRINT_TOKEN to the engagement token the project owner gave you "
|
|
2449
|
+
"(`export CODEIMPRINT_TOKEN=cit_…`), then run this again")
|
|
2450
|
+
try:
|
|
2451
|
+
mine = client.my_engagement()
|
|
2452
|
+
except (ApiError, NetworkError) as exc:
|
|
2453
|
+
raise Abort(_explain(client, exc, "cannot read the engagement")) from exc
|
|
2454
|
+
root = Path(args.path)
|
|
2455
|
+
cfg = project.load_config(root) if root.is_dir() else {}
|
|
2456
|
+
if cfg.get("project_id") and cfg["project_id"] != mine["project_id"]:
|
|
2457
|
+
raise Abort(f"this folder is set up for project {cfg['project_id']}; the engagement "
|
|
2458
|
+
f"token is for project {mine['project_id']}. Join from the repository you "
|
|
2459
|
+
"work on for this client.")
|
|
2460
|
+
key = trust.load_developer_key() or trust.create_developer_key()
|
|
2461
|
+
pub = chainseal.public_key(key)
|
|
2462
|
+
statement = {"type": ENGAGEMENT_KEY, "project": mine["project_id"],
|
|
2463
|
+
"engagement": mine["id"], "public_key": pub}
|
|
2464
|
+
try:
|
|
2465
|
+
client.engagement_key(pub, chainseal.sign(key, statement))
|
|
2466
|
+
except (ApiError, NetworkError) as exc:
|
|
2467
|
+
raise Abort(_explain(client, exc, "cannot add your key to the engagement")) from exc
|
|
2468
|
+
fp = trust.fingerprint(trust.public_raw(key))
|
|
2469
|
+
cfg.update(version=cfg.get("version", 1), project_id=mine["project_id"], developer=fp,
|
|
2470
|
+
engagement=mine["id"])
|
|
2471
|
+
cfg.setdefault("exclude", [])
|
|
2472
|
+
(root / project.CONFIG_DIR).mkdir(parents=True, exist_ok=True)
|
|
2473
|
+
(root / project.CONFIG_DIR / project.CONFIG_FILE).write_text(
|
|
2474
|
+
json.dumps(cfg, indent=2) + "\n", encoding="utf-8")
|
|
2475
|
+
_say(f"Joined engagement {mine['id']} as {mine['party']['name']} "
|
|
2476
|
+
f"({mine['party']['named_by']})",
|
|
2477
|
+
f"Project {mine['project_id']}"
|
|
2478
|
+
+ (f" ({mine['project_name']})" if mine.get("project_name") else ""),
|
|
2479
|
+
f"Key {fp} (this machine's developer key; it seals for this engagement only)",
|
|
2480
|
+
f"Config {root / project.CONFIG_DIR / project.CONFIG_FILE}",
|
|
2481
|
+
"", "Next: `imprint seal` here. The first seal sets this repository as the "
|
|
2482
|
+
"engagement's; later seals must come from it.")
|
|
2483
|
+
return 0
|
|
2484
|
+
|
|
2485
|
+
|
|
2486
|
+
def cmd_deliver(args) -> int:
|
|
2487
|
+
"""`imprint deliver IMP1-… [--note …] [--to-client]`: a vendor delivers a seal."""
|
|
2488
|
+
if not imprint_file.is_valid_id(args.seal):
|
|
2489
|
+
raise Abort(f"not a fingerprint ID (IMP1-…): {args.seal}")
|
|
2490
|
+
iid = imprint_file.clean_id(args.seal)
|
|
2491
|
+
client = _client(args, _server_from_project(Path(".")))
|
|
2492
|
+
if client.auth in ("none", "expired"):
|
|
2493
|
+
raise Abort(f"you are not signed in to {client.url}: use the engagement token "
|
|
2494
|
+
"(CODEIMPRINT_TOKEN) or run `imprint login`")
|
|
2495
|
+
try:
|
|
2496
|
+
out = client.deliver(iid, args.note, args.to_client, args.engagement)
|
|
2497
|
+
except ApiError as exc:
|
|
2498
|
+
if exc.status == 404:
|
|
2499
|
+
raise Abort(f"cannot deliver {iid}: {client.url} has no such seal, or it is not a "
|
|
2500
|
+
"seal of your project or engagement") from exc
|
|
2501
|
+
raise Abort(_explain(client, exc, f"cannot deliver {iid}")) from exc
|
|
2502
|
+
except NetworkError as exc:
|
|
2503
|
+
raise Abort(str(exc)) from exc
|
|
2504
|
+
_say(f"Delivered {out['text']}")
|
|
2505
|
+
if out.get("sent_to"):
|
|
2506
|
+
_say(f"Sent an acceptance link to {out['sent_to']} (it works once and expires "
|
|
2507
|
+
f"{out['link_expires_at'][:10]})")
|
|
2508
|
+
else:
|
|
2509
|
+
_say(" The project owner accepts it with `imprint accept "
|
|
2510
|
+
f"{iid}`.")
|
|
2511
|
+
return 0
|
|
2512
|
+
|
|
2513
|
+
|
|
2514
|
+
def cmd_accept(args) -> int:
|
|
2515
|
+
"""`imprint accept IMP1-…`: the project owner accepts a seal its vendor delivered."""
|
|
2516
|
+
if not imprint_file.is_valid_id(args.seal):
|
|
2517
|
+
raise Abort(f"not a fingerprint ID (IMP1-…): {args.seal}")
|
|
2518
|
+
iid = imprint_file.clean_id(args.seal)
|
|
2519
|
+
client = _session_client(args)
|
|
2520
|
+
try:
|
|
2521
|
+
out = client.accept(iid)
|
|
2522
|
+
except ApiError as exc:
|
|
2523
|
+
if exc.status == 404:
|
|
2524
|
+
raise Abort(f"cannot accept {iid}: no such seal in one of your projects") from exc
|
|
2525
|
+
raise Abort(_explain(client, exc, f"cannot accept {iid}")) from exc
|
|
2526
|
+
except NetworkError as exc:
|
|
2527
|
+
raise Abort(str(exc)) from exc
|
|
2528
|
+
_say(f"Accepted {out['text']}")
|
|
2529
|
+
return 0
|
|
2530
|
+
|
|
2531
|
+
|
|
2289
2532
|
def cmd_project(args) -> int:
|
|
2290
2533
|
if args.action == "move":
|
|
2291
2534
|
return _project_move(args)
|
|
@@ -2879,6 +3122,40 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
2879
3122
|
pj.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
|
|
2880
3123
|
pj.set_defaults(func=cmd_project)
|
|
2881
3124
|
|
|
3125
|
+
en = sub.add_parser("engagement", help="work with a vendor or a client: create, list, show, "
|
|
3126
|
+
"end, public, join")
|
|
3127
|
+
en.add_argument("action", choices=["create", "list", "show", "end", "public", "join"])
|
|
3128
|
+
en.add_argument("target", nargs="?", help="show, end, public: the engagement's ID (eng_…)")
|
|
3129
|
+
en.add_argument("state", nargs="?", help="public: on or off")
|
|
3130
|
+
en.add_argument("--vendor", help="create: your vendor's name (you own the project)")
|
|
3131
|
+
en.add_argument("--client", help="create: your client's name (you are the vendor)")
|
|
3132
|
+
en.add_argument("--email", help="create --client: where the client's acceptance links go")
|
|
3133
|
+
en.add_argument("--days", type=int, default=90,
|
|
3134
|
+
help="create --vendor: how long the engagement token lasts, 1 to 365")
|
|
3135
|
+
en.add_argument("--project", help="the project (default: .imprint/config.json)")
|
|
3136
|
+
en.add_argument("--path", default=".", help="the project's folder (default: here)")
|
|
3137
|
+
en.add_argument("--handover", metavar="IMP1_ID",
|
|
3138
|
+
help="end: the seal marked as handed over (default: the vendor's latest)")
|
|
3139
|
+
en.add_argument("--no-handover", action="store_true", help="end: no handover marker")
|
|
3140
|
+
en.add_argument("--json", action="store_true")
|
|
3141
|
+
en.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
|
|
3142
|
+
en.set_defaults(func=cmd_engagement)
|
|
3143
|
+
|
|
3144
|
+
dl = sub.add_parser("deliver", help="deliver a seal: to the project's owner (engagement "
|
|
3145
|
+
"token) or to your client (--to-client)")
|
|
3146
|
+
dl.add_argument("seal", metavar="IMP1_ID")
|
|
3147
|
+
dl.add_argument("--note", help="a short note (at most 500 characters)")
|
|
3148
|
+
dl.add_argument("--to-client", action="store_true",
|
|
3149
|
+
help="vendor-led: e-mail your client a link to accept it")
|
|
3150
|
+
dl.add_argument("--engagement", help="--to-client: which engagement, when there are several")
|
|
3151
|
+
dl.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
|
|
3152
|
+
dl.set_defaults(func=cmd_deliver)
|
|
3153
|
+
|
|
3154
|
+
ac = sub.add_parser("accept", help="accept a seal your vendor delivered (project owner)")
|
|
3155
|
+
ac.add_argument("seal", metavar="IMP1_ID")
|
|
3156
|
+
ac.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
|
|
3157
|
+
ac.set_defaults(func=cmd_accept)
|
|
3158
|
+
|
|
2882
3159
|
gh = sub.add_parser("github", help="the GitHub App: link this repository's project to your "
|
|
2883
3160
|
"developer key")
|
|
2884
3161
|
gh.add_argument("action", choices=["link"])
|
|
@@ -689,6 +689,21 @@ def _consistent(a: dict, b: dict, proof_hex: list[str]) -> bool:
|
|
|
689
689
|
return False
|
|
690
690
|
|
|
691
691
|
|
|
692
|
+
def _key_by_fingerprint(client, project: str, fingerprint: str) -> dict | None:
|
|
693
|
+
"""A key the public list leaves out (a vendor's scoped key, engine 0.7.0a30), asked for
|
|
694
|
+
by the fingerprint the seal's record already names. None when there is no such key or
|
|
695
|
+
the server is older."""
|
|
696
|
+
if not hasattr(client, "public_project_key"):
|
|
697
|
+
return None
|
|
698
|
+
try:
|
|
699
|
+
k = client.public_project_key(project, fingerprint)
|
|
700
|
+
except Exception: # noqa: BLE001 — an older server, or no such key: the check fails
|
|
701
|
+
return None
|
|
702
|
+
# Only that key: an answer about anything else proves nothing.
|
|
703
|
+
ok = isinstance(k, dict) and k.get("fingerprint") == fingerprint and k.get("valid_from")
|
|
704
|
+
return k if ok else None
|
|
705
|
+
|
|
706
|
+
|
|
692
707
|
def verify_online(receipt: dict, client, keys: list[dict],
|
|
693
708
|
anchors: list | None = None) -> list[Check]:
|
|
694
709
|
"""Check the receipt against the server's current log (``client`` is an api.Client)."""
|
|
@@ -751,7 +766,7 @@ def verify_online(receipt: dict, client, keys: list[dict],
|
|
|
751
766
|
attested = receipt["attestation"]["statement"]["attested_at"]
|
|
752
767
|
keys_now = {k["fingerprint"]: k
|
|
753
768
|
for k in client.public_project(signed_for).get("keys", [])}
|
|
754
|
-
k = keys_now.get(signer)
|
|
769
|
+
k = keys_now.get(signer) or _key_by_fingerprint(client, signed_for, signer)
|
|
755
770
|
if k and k["valid_from"] <= attested and (not k["valid_until"]
|
|
756
771
|
or attested <= k["valid_until"]):
|
|
757
772
|
checks.append(Check("project key", PASS, f"{signer} was a key of project "
|
|
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
|