codeimprint 0.5.0a14__tar.gz → 0.5.0a15__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.0a14 → codeimprint-0.5.0a15}/CHANGELOG.md +22 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/PKG-INFO +13 -1
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/README.pypi.md +12 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/pyproject.toml +5 -3
- codeimprint-0.5.0a15/src/codeimprint/__init__.py +6 -0
- codeimprint-0.5.0a15/src/codeimprint/__main__.py +6 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/__init__.py +1 -1
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/api.py +15 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/chainseal.py +22 -4
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/cli.py +189 -13
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/.gitignore +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/LICENSE +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/NOTICE +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/__main__.py +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/config.py +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/gitrepo.py +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/imprint_file.py +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/linecount.py +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/ownership.py +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/project.py +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/receipt.py +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/records.py +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/timestamp.py +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/transparency.py +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/trust.py +0 -0
- {codeimprint-0.5.0a14 → codeimprint-0.5.0a15}/src/codeimprint_cli/tsa_roots.py +0 -0
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0a15 — Another device joins the project; `python -m codeimprint` [CIM-BE-30-v1]
|
|
4
|
+
|
|
5
|
+
For engine 0.7.0a20. Older engines still work, except for the new `imprint key` commands.
|
|
6
|
+
|
|
7
|
+
- **New: `imprint key`.** The same repository on any device is the same project (ADR 0007).
|
|
8
|
+
- `imprint key request` on the new device makes that device's own key and asks for it to
|
|
9
|
+
be added. `--label` names the device; the default is the computer's name.
|
|
10
|
+
- `imprint key approve [fingerprint]` on a device that already seals the project shows
|
|
11
|
+
the request (label, and whether it comes from your own account) and adds the key.
|
|
12
|
+
- `imprint key list` shows the project's keys and the requests waiting.
|
|
13
|
+
- `imprint key retire <fingerprint>` retires a key, for example of a lost device. It
|
|
14
|
+
refuses to retire the project's only key.
|
|
15
|
+
- **Changed messages:** when this machine has no project key, or its key is not one of the
|
|
16
|
+
project's keys, `seal` and `init` now point to `imprint key request` (0.5.0a14 said to
|
|
17
|
+
copy the key file). A cloned project that is not yours names `imprint key request` as the
|
|
18
|
+
way to ask to join.
|
|
19
|
+
- **New: `python -m codeimprint`** runs the same commands as `imprint`. Use it where the
|
|
20
|
+
`imprint` program cannot be started, for example when Windows Application Control blocks
|
|
21
|
+
it. The wheel gains a small `codeimprint` package that holds only this entry point.
|
|
22
|
+
- Signed requests are tied to the sign-in session; with an API token they are tied to none.
|
|
23
|
+
- Tests: `tests/test_keys.py`.
|
|
24
|
+
|
|
3
25
|
## 0.5.0a14 — Sign-in works for sealing; clearer messages for clones [CIM-BE-29-v2]
|
|
4
26
|
|
|
5
27
|
For engine 0.7.0a19. Older engines still work.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: codeimprint
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.0a15
|
|
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
|
|
@@ -52,6 +52,18 @@ seals offline. Learn more at [codeimprint.ai](https://codeimprint.ai).
|
|
|
52
52
|
pip install --pre codeimprint
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
**Windows: if `imprint` is blocked.** Some managed Windows machines refuse to start the
|
|
56
|
+
`imprint` program (Application Control or AppLocker: "This app has been blocked by your
|
|
57
|
+
system administrator"). Run the same commands through Python instead, which those
|
|
58
|
+
policies usually allow:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
python -m codeimprint seal .
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`python -m codeimprint <command>` is the same as `imprint <command>` everywhere. On
|
|
65
|
+
Windows `py -m codeimprint` works too.
|
|
66
|
+
|
|
55
67
|
## Get started
|
|
56
68
|
|
|
57
69
|
```bash
|
|
@@ -18,6 +18,18 @@ seals offline. Learn more at [codeimprint.ai](https://codeimprint.ai).
|
|
|
18
18
|
pip install --pre codeimprint
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
**Windows: if `imprint` is blocked.** Some managed Windows machines refuse to start the
|
|
22
|
+
`imprint` program (Application Control or AppLocker: "This app has been blocked by your
|
|
23
|
+
system administrator"). Run the same commands through Python instead, which those
|
|
24
|
+
policies usually allow:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
python -m codeimprint seal .
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`python -m codeimprint <command>` is the same as `imprint <command>` everywhere. On
|
|
31
|
+
Windows `py -m codeimprint` works too.
|
|
32
|
+
|
|
21
33
|
## Get started
|
|
22
34
|
|
|
23
35
|
```bash
|
|
@@ -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.0a15"
|
|
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"
|
|
@@ -45,12 +45,14 @@ Hub = "https://app.codeimprint.ai"
|
|
|
45
45
|
imprint = "codeimprint_cli.cli:main"
|
|
46
46
|
|
|
47
47
|
[tool.hatch.build.targets.wheel]
|
|
48
|
-
|
|
48
|
+
# codeimprint_cli is the client; codeimprint holds only `python -m codeimprint`.
|
|
49
|
+
packages = ["src/codeimprint_cli", "src/codeimprint"]
|
|
49
50
|
|
|
50
51
|
# The sdist holds only what builds the wheel: no tests, fixtures, workflows or repository
|
|
51
52
|
# tooling (pyproject.toml is always included). scripts/check_release.py polices it.
|
|
52
53
|
[tool.hatch.build.targets.sdist]
|
|
53
|
-
only-include = ["src/codeimprint_cli", "README.pypi.md", "CHANGELOG.md",
|
|
54
|
+
only-include = ["src/codeimprint_cli", "src/codeimprint", "README.pypi.md", "CHANGELOG.md",
|
|
55
|
+
"LICENSE", "NOTICE"]
|
|
54
56
|
|
|
55
57
|
[tool.pytest.ini_options]
|
|
56
58
|
testpaths = ["tests"]
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""`python -m codeimprint`: the `imprint` command, for machines where the `imprint` program
|
|
3
|
+
itself cannot be started (for example when Windows Application Control blocks it).
|
|
4
|
+
|
|
5
|
+
The client's code is the package `codeimprint_cli`; this package only holds the entry point.
|
|
6
|
+
"""
|
|
@@ -169,6 +169,21 @@ class Client:
|
|
|
169
169
|
return self._json("POST", f"/api/v1/projects/{quote(project)}/access",
|
|
170
170
|
{"public_key": public_key, "signature": signature})
|
|
171
171
|
|
|
172
|
+
# a new device joins the project (engine 0.7.0a20+) ---------------------------------------
|
|
173
|
+
def key_request(self, project: str, public_key: str, signature: str,
|
|
174
|
+
label: str | None = None) -> dict:
|
|
175
|
+
return self._json("POST", f"/api/v1/projects/{quote(project)}/keys/requests",
|
|
176
|
+
{"public_key": public_key, "signature": signature, "label": label})
|
|
177
|
+
|
|
178
|
+
def key_requests(self, project: str) -> dict:
|
|
179
|
+
return self._json("GET", f"/api/v1/projects/{quote(project)}/keys/requests")
|
|
180
|
+
|
|
181
|
+
def change_project_key(self, project: str, action: str, public_key: str,
|
|
182
|
+
signer_public_key: str, signature: str) -> dict:
|
|
183
|
+
return self._json("POST", f"/api/v1/projects/{quote(project)}/keys",
|
|
184
|
+
{"action": action, "public_key": public_key,
|
|
185
|
+
"signer_public_key": signer_public_key, "signature": signature})
|
|
186
|
+
|
|
172
187
|
def plan(self, project: str, payload: dict) -> dict:
|
|
173
188
|
return self._json("POST", f"/api/v1/projects/{quote(project)}/seal/plan", payload)
|
|
174
189
|
|
|
@@ -34,13 +34,31 @@ def public_key(key) -> str:
|
|
|
34
34
|
return trust.b64e(trust.public_raw(key))
|
|
35
35
|
|
|
36
36
|
|
|
37
|
+
def session_binding(token: str | None) -> str:
|
|
38
|
+
"""What ties a signed request to this sign-in: the SHA-256 of the session token (an API
|
|
39
|
+
token is not a session: the server then expects the hash of nothing)."""
|
|
40
|
+
session = token if token and token.startswith("cis_") else ""
|
|
41
|
+
return hashlib.sha256(session.encode()).hexdigest()
|
|
42
|
+
|
|
43
|
+
|
|
37
44
|
def access_proof(key, project: str, token: str | None) -> tuple[str, str]:
|
|
38
45
|
"""(public key, signature) showing that this session holds a project key: the key signs
|
|
39
|
-
{type, project, session},
|
|
40
|
-
proof works for this sign-in only."""
|
|
41
|
-
session = hashlib.sha256((token or "").encode()).hexdigest()
|
|
46
|
+
{type, project, session}, so the proof works for this sign-in only."""
|
|
42
47
|
return public_key(key), sign(key, {"type": "codeimprint.project-access.v1",
|
|
43
|
-
"project": project, "session":
|
|
48
|
+
"project": project, "session": session_binding(token)})
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def key_request_proof(key, project: str, token: str | None) -> tuple[str, str]:
|
|
52
|
+
"""(public key, signature) of a device asking for its key to be added to a project."""
|
|
53
|
+
pub = public_key(key)
|
|
54
|
+
return pub, sign(key, {"type": "codeimprint.project-key-request.v1", "project": project,
|
|
55
|
+
"public_key": pub, "session": session_binding(token)})
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def key_change(key, project: str, action: str, target_public_key: str) -> tuple[str, str]:
|
|
59
|
+
"""(signer public key, signature) of a project key adding or retiring another key."""
|
|
60
|
+
return public_key(key), sign(key, {"type": "codeimprint.project-key.v1", "project": project,
|
|
61
|
+
"action": action, "public_key": target_public_key})
|
|
44
62
|
|
|
45
63
|
|
|
46
64
|
def create_project(client, key, name: str | None = None) -> dict:
|
|
@@ -209,8 +209,8 @@ def _not_your_project(client: Client, project_id: str, key) -> str:
|
|
|
209
209
|
return (f"this folder's .imprint/config.json names project {project_id}, which is not on "
|
|
210
210
|
f"{client.url} or which your account is not part of (for example, it came with a "
|
|
211
211
|
"repository you cloned). To seal this code as a project of your own, run "
|
|
212
|
-
"`imprint init --new-project`. To join the existing project,
|
|
213
|
-
f"your developer key{mine}.")
|
|
212
|
+
"`imprint init --new-project`. To join the existing project, run `imprint key "
|
|
213
|
+
f"request`: its owner sees the request and can add your developer key{mine}.")
|
|
214
214
|
|
|
215
215
|
|
|
216
216
|
def _project_state(client: Client, project_id: str, key) -> str:
|
|
@@ -249,10 +249,9 @@ def _project_ready(client: Client, project_id: str, key) -> None:
|
|
|
249
249
|
if active and fp not in active:
|
|
250
250
|
raise SealFailed(
|
|
251
251
|
f"developer key {fp} on this machine is not a key of project {project_id} (its "
|
|
252
|
-
f"keys: {', '.join(active)}).
|
|
253
|
-
f"{
|
|
254
|
-
|
|
255
|
-
"contents. Nothing was uploaded.")
|
|
252
|
+
f"keys: {', '.join(active)}). Add this device to the project: run `imprint key "
|
|
253
|
+
f"request` here, then `imprint key approve {fp}` on a device that already seals "
|
|
254
|
+
"it. Nothing was uploaded.")
|
|
256
255
|
|
|
257
256
|
|
|
258
257
|
def _prepare_upload(path: str, action: str, client: Client, assume_yes: bool) -> bytes:
|
|
@@ -423,7 +422,8 @@ def cmd_init(args) -> int:
|
|
|
423
422
|
" To sign seals in CI, store the file's contents as the secret "
|
|
424
423
|
"CODEIMPRINT_DEVELOPER_KEY.")
|
|
425
424
|
if cfg.get("developer") != fp:
|
|
426
|
-
_warn(f"this project expects developer key {cfg['developer']}, not {fp}"
|
|
425
|
+
_warn(f"this project expects developer key {cfg['developer']}, not {fp}: to add "
|
|
426
|
+
"this device to the project run `imprint key request`")
|
|
427
427
|
if key is not None and not args.no_project:
|
|
428
428
|
_init_project(args, root, cfg_path, key)
|
|
429
429
|
if key is not None:
|
|
@@ -1387,14 +1387,14 @@ def _developer_key(required: bool = False, expected: str | None = None):
|
|
|
1387
1387
|
except ValueError as exc:
|
|
1388
1388
|
raise SealFailed(f"cannot read the developer key: {exc}") from exc
|
|
1389
1389
|
if key is None and required:
|
|
1390
|
-
path = trust.developer_key_path()
|
|
1391
1390
|
raise SealFailed(
|
|
1392
1391
|
"this project's seals are signed with a developer key"
|
|
1393
|
-
+ (f" ({expected})" if expected else "") + ", and this machine has none.
|
|
1394
|
-
|
|
1395
|
-
"
|
|
1396
|
-
"
|
|
1397
|
-
"
|
|
1392
|
+
+ (f" ({expected})" if expected else "") + ", and this machine has none. Add "
|
|
1393
|
+
"this device to the project: run `imprint key request` here (it makes this "
|
|
1394
|
+
"device's own key), then `imprint key approve` on a device that already seals it. "
|
|
1395
|
+
"In GitHub Actions, set the secret CODEIMPRINT_DEVELOPER_KEY to the contents of an "
|
|
1396
|
+
"approved key file. A new key from `imprint init` alone is a different key, which "
|
|
1397
|
+
"the project does not accept.")
|
|
1398
1398
|
return key
|
|
1399
1399
|
|
|
1400
1400
|
|
|
@@ -1693,6 +1693,169 @@ def cmd_seal(args) -> int:
|
|
|
1693
1693
|
return rc
|
|
1694
1694
|
|
|
1695
1695
|
|
|
1696
|
+
# -- a project's keys: another device joins (CIM-BE-30-v1; ADR 0007, section 7.4) -------------
|
|
1697
|
+
def _project_keys(client: Client, project_id: str) -> list[dict]:
|
|
1698
|
+
try:
|
|
1699
|
+
return client.public_project(project_id).get("keys") or []
|
|
1700
|
+
except (ApiError, NetworkError):
|
|
1701
|
+
return []
|
|
1702
|
+
|
|
1703
|
+
|
|
1704
|
+
def _device_label() -> str:
|
|
1705
|
+
import platform
|
|
1706
|
+
|
|
1707
|
+
return (" ".join(platform.node().split()) or "device")[:60]
|
|
1708
|
+
|
|
1709
|
+
|
|
1710
|
+
def _key_request(args, client: Client, project_id: str) -> int:
|
|
1711
|
+
key, how = trust.load_developer_key(), "found"
|
|
1712
|
+
if key is None:
|
|
1713
|
+
key, how = trust.create_developer_key(), "created"
|
|
1714
|
+
fp = trust.fingerprint(trust.public_raw(key))
|
|
1715
|
+
if any(k["fingerprint"] == fp and not k.get("valid_until")
|
|
1716
|
+
for k in _project_keys(client, project_id)):
|
|
1717
|
+
_say(f"Key {fp} is already a key of project {project_id}: this device can seal")
|
|
1718
|
+
return 0
|
|
1719
|
+
label = args.label or _device_label()
|
|
1720
|
+
try:
|
|
1721
|
+
client.key_request(project_id, *chainseal.key_request_proof(key, project_id, client.token),
|
|
1722
|
+
label)
|
|
1723
|
+
except ApiError as exc:
|
|
1724
|
+
if exc.status == 404 and exc.code != "project_not_found":
|
|
1725
|
+
raise Abort(f"{client.url} does not take key requests yet (it needs engine 0.7.0a20 "
|
|
1726
|
+
"or later)") from exc
|
|
1727
|
+
raise Abort(_explain(client, exc, "the request was not sent")) from exc
|
|
1728
|
+
except NetworkError as exc:
|
|
1729
|
+
raise Abort(f"the request was not sent: {exc}") from exc
|
|
1730
|
+
_say(f"Requested developer key {fp} ({how}: {trust.developer_key_path()}) asks to join "
|
|
1731
|
+
f"project {project_id}",
|
|
1732
|
+
f"Label {label} (shown to whoever approves; --label to choose)",
|
|
1733
|
+
f"Approve on a device that already seals this project: imprint key approve {fp}",
|
|
1734
|
+
"Waits 7 days. Until it is approved this device can verify and check, not seal.",
|
|
1735
|
+
" If the project is someone else's, its owner sees the request and decides.")
|
|
1736
|
+
return 0
|
|
1737
|
+
|
|
1738
|
+
|
|
1739
|
+
def _key_list(client: Client, project_id: str) -> int:
|
|
1740
|
+
keys = _project_keys(client, project_id)
|
|
1741
|
+
if not keys:
|
|
1742
|
+
raise Abort(f"no such project on {client.url}: {project_id}")
|
|
1743
|
+
mine = trust.load_developer_key()
|
|
1744
|
+
here = trust.fingerprint(trust.public_raw(mine)) if mine is not None else None
|
|
1745
|
+
_say(f"Project {project_id}")
|
|
1746
|
+
for k in keys:
|
|
1747
|
+
state = f"retired {k['valid_until']}" if k.get("valid_until") else "active"
|
|
1748
|
+
_say(f" {k['fingerprint']} {k.get('kind', 'developer'):<11} {state}"
|
|
1749
|
+
+ (" (this device)" if k["fingerprint"] == here else ""))
|
|
1750
|
+
try:
|
|
1751
|
+
waiting = client.key_requests(project_id)["requests"]
|
|
1752
|
+
except (ApiError, NetworkError):
|
|
1753
|
+
_say("Requests shown only to the project's own accounts (sign in with `imprint login`)")
|
|
1754
|
+
return 0
|
|
1755
|
+
_say(f"Requests {len(waiting)} waiting" + (":" if waiting else ""))
|
|
1756
|
+
for r in waiting:
|
|
1757
|
+
who = "your account" if r.get("same_account") else "another account"
|
|
1758
|
+
_say(f" {r['fingerprint']} {r.get('label') or '(no label)'} from {who}, "
|
|
1759
|
+
f"{r['requested_at']}, until {r['expires_at']}")
|
|
1760
|
+
return 0
|
|
1761
|
+
|
|
1762
|
+
|
|
1763
|
+
def _signing_project_key(client: Client, project_id: str):
|
|
1764
|
+
"""This device's key, which must be active on the project: only such a key can add or
|
|
1765
|
+
retire another."""
|
|
1766
|
+
key = trust.load_developer_key()
|
|
1767
|
+
fp = trust.fingerprint(trust.public_raw(key)) if key is not None else None
|
|
1768
|
+
active = [k["fingerprint"] for k in _project_keys(client, project_id)
|
|
1769
|
+
if not k.get("valid_until")]
|
|
1770
|
+
if fp is None or (active and fp not in active):
|
|
1771
|
+
raise Abort("this device's key is not a key of the project: run this on a device that "
|
|
1772
|
+
"already seals it" + (f" (its keys: {', '.join(active)})" if active else ""))
|
|
1773
|
+
return key
|
|
1774
|
+
|
|
1775
|
+
|
|
1776
|
+
def _key_approve(args, client: Client, project_id: str) -> int:
|
|
1777
|
+
key = _signing_project_key(client, project_id)
|
|
1778
|
+
try:
|
|
1779
|
+
waiting = client.key_requests(project_id)["requests"]
|
|
1780
|
+
except ApiError as exc:
|
|
1781
|
+
if exc.status == 404 and exc.code == "project_not_found":
|
|
1782
|
+
raise Abort(_not_your_project(client, project_id, key)) from exc
|
|
1783
|
+
raise Abort(_explain(client, exc, "could not read the requests")) from exc
|
|
1784
|
+
except NetworkError as exc:
|
|
1785
|
+
raise Abort(f"could not read the requests: {exc}") from exc
|
|
1786
|
+
wanted = (args.fingerprint or "").lower()
|
|
1787
|
+
found = [r for r in waiting if r["fingerprint"].startswith(wanted)]
|
|
1788
|
+
if not waiting:
|
|
1789
|
+
_say("No key requests are waiting on this project.")
|
|
1790
|
+
return 0
|
|
1791
|
+
if len(found) != 1:
|
|
1792
|
+
for r in waiting:
|
|
1793
|
+
who = "your account" if r.get("same_account") else "another account"
|
|
1794
|
+
_say(f" {r['fingerprint']} {r.get('label') or '(no label)'} from {who}, "
|
|
1795
|
+
f"{r['requested_at']}")
|
|
1796
|
+
raise Abort("name the key to approve: imprint key approve <fingerprint>"
|
|
1797
|
+
if not wanted or len(found) > 1 else f"no request from a key {wanted}")
|
|
1798
|
+
req = found[0]
|
|
1799
|
+
if trust.fingerprint(imprint_file.b64d(req["public_key"])) != req["fingerprint"]:
|
|
1800
|
+
raise Abort("the server sent a public key that does not match its fingerprint")
|
|
1801
|
+
who = "your own account" if req.get("same_account") else "ANOTHER account"
|
|
1802
|
+
_say(f"Request key {req['fingerprint']}, label: {req.get('label') or '(none)'}",
|
|
1803
|
+
f"From {who}, {req['requested_at']}",
|
|
1804
|
+
f"Adding it lets that device seal into project {project_id}.")
|
|
1805
|
+
_ask(args, "Add this key to the project?")
|
|
1806
|
+
try:
|
|
1807
|
+
client.change_project_key(project_id, "add", req["public_key"],
|
|
1808
|
+
*chainseal.key_change(key, project_id, "add",
|
|
1809
|
+
req["public_key"]))
|
|
1810
|
+
except (ApiError, NetworkError) as exc:
|
|
1811
|
+
raise Abort(_explain(client, exc, "the key was not added")) from exc
|
|
1812
|
+
_say(f"Added key {req['fingerprint']}: that device can seal into the project now")
|
|
1813
|
+
return 0
|
|
1814
|
+
|
|
1815
|
+
|
|
1816
|
+
def _key_retire(args, client: Client, project_id: str) -> int:
|
|
1817
|
+
key = _signing_project_key(client, project_id)
|
|
1818
|
+
wanted = (args.fingerprint or "").lower()
|
|
1819
|
+
if not wanted:
|
|
1820
|
+
raise Abort("name the key to retire: imprint key retire <fingerprint>")
|
|
1821
|
+
active = [k for k in _project_keys(client, project_id) if not k.get("valid_until")]
|
|
1822
|
+
found = [k for k in active if k["fingerprint"].startswith(wanted)]
|
|
1823
|
+
if len(found) != 1:
|
|
1824
|
+
raise Abort(f"no single active key of this project starts with {wanted}")
|
|
1825
|
+
if len(active) == 1:
|
|
1826
|
+
raise Abort("that is the project's only key: retiring it would leave nobody able to "
|
|
1827
|
+
"seal. Add another key first")
|
|
1828
|
+
target = found[0]
|
|
1829
|
+
_say(f"Retiring key {target['fingerprint']}: it can no longer seal into project "
|
|
1830
|
+
f"{project_id}. Its earlier seals stay valid. This cannot be undone.")
|
|
1831
|
+
_ask(args, "Retire this key?")
|
|
1832
|
+
try:
|
|
1833
|
+
client.change_project_key(project_id, "retire", target["public_key"],
|
|
1834
|
+
*chainseal.key_change(key, project_id, "retire",
|
|
1835
|
+
target["public_key"]))
|
|
1836
|
+
except (ApiError, NetworkError) as exc:
|
|
1837
|
+
raise Abort(_explain(client, exc, "the key was not retired")) from exc
|
|
1838
|
+
_say(f"Retired key {target['fingerprint']}")
|
|
1839
|
+
return 0
|
|
1840
|
+
|
|
1841
|
+
|
|
1842
|
+
def cmd_key(args) -> int:
|
|
1843
|
+
root = Path(args.path)
|
|
1844
|
+
cfg = project.load_config(root) if root.is_dir() else {}
|
|
1845
|
+
project_id = args.project or cfg.get("project_id")
|
|
1846
|
+
if not project_id:
|
|
1847
|
+
raise Abort("no project here: .imprint/config.json names none (run this in the "
|
|
1848
|
+
"project's folder, or pass --project <ID>)")
|
|
1849
|
+
client = _client(args)
|
|
1850
|
+
if args.action == "request":
|
|
1851
|
+
return _key_request(args, client, project_id)
|
|
1852
|
+
if args.action == "approve":
|
|
1853
|
+
return _key_approve(args, client, project_id)
|
|
1854
|
+
if args.action == "retire":
|
|
1855
|
+
return _key_retire(args, client, project_id)
|
|
1856
|
+
return _key_list(client, project_id)
|
|
1857
|
+
|
|
1858
|
+
|
|
1696
1859
|
# -- project names and the GitHub App (CIM-BE-19-v1) ---------------------------------------
|
|
1697
1860
|
def cmd_project(args) -> int:
|
|
1698
1861
|
key = _developer_key(required=True)
|
|
@@ -2017,6 +2180,19 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
2017
2180
|
"project of your own for it")
|
|
2018
2181
|
n.set_defaults(func=cmd_init)
|
|
2019
2182
|
|
|
2183
|
+
ky = sub.add_parser("key", help="the project's keys: add another device (request, then "
|
|
2184
|
+
"approve), list, retire")
|
|
2185
|
+
ky.add_argument("action", choices=["request", "approve", "list", "retire"])
|
|
2186
|
+
ky.add_argument("fingerprint", nargs="?",
|
|
2187
|
+
help="approve, retire: the key's fingerprint (or the start of it)")
|
|
2188
|
+
ky.add_argument("--path", default=".", help="the project's folder (default: here)")
|
|
2189
|
+
ky.add_argument("--project", help="project ID (default: .imprint/config.json)")
|
|
2190
|
+
ky.add_argument("--label", help="request: a name for this device, shown to whoever "
|
|
2191
|
+
"approves (default: the computer's name)")
|
|
2192
|
+
ky.add_argument("--yes", action="store_true", help="approve, retire: do not ask")
|
|
2193
|
+
ky.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
|
|
2194
|
+
ky.set_defaults(func=cmd_key)
|
|
2195
|
+
|
|
2020
2196
|
pj = sub.add_parser("project", help="the project's display name: rename")
|
|
2021
2197
|
pj.add_argument("action", choices=["rename"])
|
|
2022
2198
|
pj.add_argument("name", help="the new name (1-100 characters)")
|
|
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
|