codeimprint 0.5.0a31__tar.gz → 0.5.0a33__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.
Files changed (26) hide show
  1. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/CHANGELOG.md +30 -0
  2. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/PKG-INFO +5 -3
  3. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/README.pypi.md +4 -2
  4. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/pyproject.toml +1 -1
  5. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/__init__.py +1 -1
  6. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/api.py +11 -5
  7. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/cli.py +45 -2
  8. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/.gitignore +0 -0
  9. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/LICENSE +0 -0
  10. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/NOTICE +0 -0
  11. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint/__init__.py +0 -0
  12. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint/__main__.py +0 -0
  13. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/__main__.py +0 -0
  14. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/chainseal.py +0 -0
  15. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/config.py +0 -0
  16. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/gitrepo.py +0 -0
  17. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/imprint_file.py +0 -0
  18. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/linecount.py +0 -0
  19. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/ownership.py +0 -0
  20. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/project.py +0 -0
  21. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/receipt.py +0 -0
  22. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/records.py +0 -0
  23. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/timestamp.py +0 -0
  24. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/transparency.py +0 -0
  25. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/trust.py +0 -0
  26. {codeimprint-0.5.0a31 → codeimprint-0.5.0a33}/src/codeimprint_cli/tsa_roots.py +0 -0
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0a33 — Plan refusals are never silent [CIM-BE-53-v1]
4
+
5
+ For engine 0.7.0a40, which can enforce the Hello plan's limits (`CODEIMPRINT_BILLING_ENFORCE`).
6
+ Includes 0.5.0a32 (not tagged on its own).
7
+
8
+ - **New: a seal the plan refuses says so.** The server's `plan_limit_reached` (a new active
9
+ project too many) and `plan_automatic_sealing` (a CI token's seal on the free Hello plan)
10
+ are printed as "not sealed: <the server's message, with the upgrade link> [<code>]".
11
+ - In GitHub Actions: a warning annotation titled "CodeImprint plan", exit code 0 (an
12
+ automated build never fails on it).
13
+ - In a terminal: the same warning, exit code 2.
14
+ - `imprint token create` names the code too.
15
+ - Tests: `tests/test_plan_refusals.py`.
16
+
17
+ ## 0.5.0a32 — Signed organisation requests [CIM-BE-48-v1]
18
+
19
+ For engine 0.7.0a38, which needs them (audit 42f-01, 42f-03).
20
+
21
+ - **Changed: `imprint org domain` and `imprint org disclose` sign their request** with the
22
+ organisation's admin key: canonical JSON `{type, org, domain, at}` with
23
+ `codeimprint.org-domain-request.v1` or `codeimprint.org-disclosure-request.v1` and the
24
+ current UTC time. The disclosure document is now asked for with a POST. Older clients get
25
+ "No such organisation" from engine 0.7.0a38. With an engine before 0.7.0a38, `imprint org
26
+ domain` still works (the signature is ignored), but `imprint org disclose` gets 405 (those
27
+ engines serve the document only by GET): use 0.5.0a31 for it until the engine is updated.
28
+ - Docs: the README and the PyPI page say what a Git seal sends besides file contents (paths,
29
+ Git IDs, commit and repository IDs, kept as keyed hashes), and that only a seal signed
30
+ with your developer key cannot be forged by the operator (42e-07, 42e-08).
31
+ - Tests: `tests/test_org_commands.py`.
32
+
3
33
  ## 0.5.0a31 — Newer formats, expired identities, INT1 v2 [CIM-BE-45-v1]
4
34
 
5
35
  For engine 0.7.0a36.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codeimprint
3
- Version: 0.5.0a31
3
+ Version: 0.5.0a33
4
4
  Summary: CodeImprint: seal your code with a CodeImprint server (tamper-evident, logged and timestamped) and verify seals offline.
5
5
  Project-URL: Homepage, https://codeimprint.ai
6
6
  Project-URL: Hub, https://app.codeimprint.ai
@@ -94,8 +94,10 @@ evidence, not proof), `imprint chain`, `imprint hook install`, `imprint identity
94
94
 
95
95
  ## What leaves your machine
96
96
 
97
- `imprint seal` and `imprint check` upload the project's files to the CodeImprint server you
98
- signed in to, which fingerprints them and deletes them at once; only the Imprint is kept.
97
+ `imprint seal` and `imprint check` upload the project's Python files to the CodeImprint
98
+ server you signed in to, which deletes them as soon as it has sealed or checked them. A Git
99
+ seal also sends the paths and Git IDs of tracked files and the commit and repository IDs;
100
+ the server keeps those only as keyed hashes, with the seal.
99
101
  Your developer key never leaves your machine: only its public half is sent.
100
102
 
101
103
  ## Licence
@@ -60,8 +60,10 @@ evidence, not proof), `imprint chain`, `imprint hook install`, `imprint identity
60
60
 
61
61
  ## What leaves your machine
62
62
 
63
- `imprint seal` and `imprint check` upload the project's files to the CodeImprint server you
64
- signed in to, which fingerprints them and deletes them at once; only the Imprint is kept.
63
+ `imprint seal` and `imprint check` upload the project's Python files to the CodeImprint
64
+ server you signed in to, which deletes them as soon as it has sealed or checked them. A Git
65
+ seal also sends the paths and Git IDs of tracked files and the commit and repository IDs;
66
+ the server keeps those only as keyed hashes, with the seal.
65
67
  Your developer key never leaves your machine: only its public half is sent.
66
68
 
67
69
  ## Licence
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
  # Published on PyPI as `codeimprint`. The import package stays `codeimprint_cli` and the
7
7
  # command `imprint`.
8
8
  name = "codeimprint"
9
- version = "0.5.0a31"
9
+ version = "0.5.0a33"
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"
@@ -5,4 +5,4 @@ A thin client for a CodeImprint server: it zips a project, asks the server to se
5
5
  it, and verifies Imprint files offline. All analysis happens on the server.
6
6
  """
7
7
 
8
- __version__ = "0.5.0a31"
8
+ __version__ = "0.5.0a33"
@@ -447,17 +447,23 @@ class Client:
447
447
  return self._json("POST", "/api/v1/orgs", {"public_key": public_key,
448
448
  "signature": signature})
449
449
 
450
- def org_domain_challenge(self, org: str, domain: str, public_key: str) -> dict:
450
+ def org_domain_challenge(self, org: str, domain: str, public_key: str, at: str,
451
+ signature: str) -> dict:
452
+ """The admin's signed request (engine 0.7.0a38+)."""
451
453
  return self._json("POST", f"/api/v1/orgs/{quote(org)}/domains",
452
- {"domain": domain, "public_key": public_key})
454
+ {"domain": domain, "public_key": public_key, "at": at,
455
+ "signature": signature})
453
456
 
454
457
  def org_domain_verify(self, org: str, domain: str, signature: str) -> dict:
455
458
  return self._json("POST", f"/api/v1/orgs/{quote(org)}/domains/verify",
456
459
  {"domain": domain, "signature": signature})
457
460
 
458
- def org_disclosure_document(self, org: str, domain: str) -> dict:
459
- return self._json("GET", f"/api/v1/orgs/{quote(org)}/disclosures/document?domain="
460
- f"{quote(domain)}")
461
+ def org_disclosure_document(self, org: str, domain: str, public_key: str, at: str,
462
+ signature: str) -> dict:
463
+ """The admin's signed request (engine 0.7.0a38+; a GET before)."""
464
+ return self._json("POST", f"/api/v1/orgs/{quote(org)}/disclosures/document",
465
+ {"domain": domain, "public_key": public_key, "at": at,
466
+ "signature": signature})
461
467
 
462
468
  def org_disclose(self, org: str, domain: str, public_key: str, signature: str) -> dict:
463
469
  return self._json("POST", f"/api/v1/orgs/{quote(org)}/disclosures",
@@ -314,8 +314,31 @@ def _client(args, fallback_url: str | None = None) -> Client:
314
314
  return _signed_in(url, settings.token if settings.url else None)
315
315
 
316
316
 
317
+ # The server's plan refusals (engine 0.7.0a40, CIM-BE-53-v1): stable codes whose message
318
+ # names the upgrade page. Never silent: a warning in automated builds, an error elsewhere.
319
+ PLAN_REFUSALS = ("plan_limit_reached", "plan_automatic_sealing")
320
+
321
+
322
+ def _plan_refusal(exc: BaseException) -> ApiError | None:
323
+ """The server's plan refusal behind ``exc`` (an ApiError, or a SealFailed made from one)."""
324
+ for e in (exc, exc.__cause__):
325
+ if isinstance(e, ApiError) and e.code in PLAN_REFUSALS:
326
+ return e
327
+ return None
328
+
329
+
330
+ def _plan_warning(refusal: ApiError) -> None:
331
+ """The plan's refusal, said plainly: in GitHub Actions also an annotation of its own."""
332
+ text = f"not sealed: {refusal.message} [{refusal.code}]"
333
+ if os.environ.get("GITHUB_ACTIONS") == "true":
334
+ print(f"::warning title=CodeImprint plan::{text}")
335
+ print(f"imprint: warning: {text}", file=sys.stderr)
336
+
337
+
317
338
  def _explain(client: Client, exc: Exception, what: str) -> str:
318
339
  """``what: why``, with what to do when the server asks for a sign-in."""
340
+ if isinstance(exc, ApiError) and exc.code in PLAN_REFUSALS:
341
+ return f"{what}: {exc.message} [{exc.code}]"
319
342
  if isinstance(exc, ApiError) and exc.code == "token_scope":
320
343
  return (f"{what}: a CI token only seals and checks its own project. Sign in with "
321
344
  f"`imprint login` for this. The server said: {exc}")
@@ -1111,6 +1134,18 @@ def _now_iso() -> str:
1111
1134
  return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
1112
1135
 
1113
1136
 
1137
+ # The organisation admin's signed requests (engine 0.7.0a38): only the admin key's fresh
1138
+ # signature over {type, org, domain, at} gets a domain challenge or a disclosure document.
1139
+ ORG_DOMAIN_REQUEST = "codeimprint.org-domain-request.v1"
1140
+ ORG_DISCLOSURE_REQUEST = "codeimprint.org-disclosure-request.v1"
1141
+
1142
+
1143
+ def _org_request(key, kind: str, org: str, domain: str) -> tuple[str, str]:
1144
+ """(at, signature) for the admin's request; ``at`` is now, UTC."""
1145
+ at = _now_iso()
1146
+ return at, chainseal.sign(key, {"type": kind, "org": org, "domain": domain, "at": at})
1147
+
1148
+
1114
1149
  def _session_client(args) -> Client:
1115
1150
  settings = config.resolve(getattr(args, "url", None))
1116
1151
  if not settings.url:
@@ -1618,7 +1653,9 @@ def cmd_org(args) -> int:
1618
1653
  raise Abort(f"{args.action}: name the domain")
1619
1654
  try:
1620
1655
  if args.action == "domain":
1621
- ch = client.org_domain_challenge(org, args.target, pub)
1656
+ ch = client.org_domain_challenge(org, args.target, pub,
1657
+ *_org_request(key, ORG_DOMAIN_REQUEST, org,
1658
+ args.target))
1622
1659
  path = _challenge_path(org, _ascii_domain(ch["domain"]))
1623
1660
  path.parent.mkdir(parents=True, exist_ok=True)
1624
1661
  path.write_text(json.dumps(ch, indent=1) + "\n", encoding="utf-8")
@@ -1647,7 +1684,9 @@ def cmd_org(args) -> int:
1647
1684
  f"imprint org disclose {org} {ch['domain']}")
1648
1685
  return 0
1649
1686
  if args.action == "disclose":
1650
- doc = client.org_disclosure_document(org, args.target)
1687
+ doc = client.org_disclosure_document(org, args.target, pub,
1688
+ *_org_request(key, ORG_DISCLOSURE_REQUEST,
1689
+ org, args.target))
1651
1690
  _checked_digest(doc["document"], doc["digest"], doc["statement"])
1652
1691
  _say(f"Disclose {doc['document']['value']} for organisation {org}: from now on it "
1653
1692
  "is public, and the organisation is shown as \"verified domain "
@@ -2147,6 +2186,10 @@ def cmd_seal(args) -> int:
2147
2186
  data = _prepare_upload(args.path, "seal", client, args.yes)
2148
2187
  rc = _seal_zip(args, client, data, cfg.get("project_id"), _folder_lines(args.path))
2149
2188
  except SealFailed as exc:
2189
+ refusal = _plan_refusal(exc)
2190
+ if refusal is not None: # the plan said no: never silent (CIM-BE-53-v1)
2191
+ _plan_warning(refusal)
2192
+ return 0 if _ci() else 2
2150
2193
  if _ci(): # never break a build by surprise
2151
2194
  _warn(f"seal skipped — {exc}")
2152
2195
  return 0
File without changes
File without changes