codeimprint 0.5.0a32__tar.gz → 0.5.0a35__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 (27) hide show
  1. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/CHANGELOG.md +57 -0
  2. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/PKG-INFO +4 -2
  3. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/README.pypi.md +3 -1
  4. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/pyproject.toml +1 -1
  5. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/__init__.py +1 -1
  6. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/api.py +20 -3
  7. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/chainseal.py +36 -12
  8. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/cli.py +279 -9
  9. codeimprint-0.5.0a35/src/codeimprint_cli/filelist.py +289 -0
  10. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/gitrepo.py +57 -0
  11. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/project.py +52 -0
  12. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/receipt.py +80 -12
  13. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/.gitignore +0 -0
  14. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/LICENSE +0 -0
  15. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/NOTICE +0 -0
  16. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint/__init__.py +0 -0
  17. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint/__main__.py +0 -0
  18. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/__main__.py +0 -0
  19. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/config.py +0 -0
  20. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/imprint_file.py +0 -0
  21. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/linecount.py +0 -0
  22. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/ownership.py +0 -0
  23. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/records.py +0 -0
  24. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/timestamp.py +0 -0
  25. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/transparency.py +0 -0
  26. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/trust.py +0 -0
  27. {codeimprint-0.5.0a32 → codeimprint-0.5.0a35}/src/codeimprint_cli/tsa_roots.py +0 -0
@@ -1,5 +1,62 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0a35 — Your own file list: check, prove, verify a file [CIM-BE-58-v1]
4
+
5
+ For engine 0.7.0a44.
6
+
7
+ - **New: `imprint check --files`** compares a commit (`HEAD`, or `--commit REV`) or the working
8
+ tree (`--worktree`) with a seal's file list (this folder's baseline, or `--seal ID`): files
9
+ added, removed, changed, with another mode, or listed in the seal without a hash. Everything
10
+ is hashed here; only the list is fetched (`GET /api/v1/imprints/{id}/files`, the project's
11
+ owner or its CI token). Exit 1 when files differ; in an automated build a warning and 0.
12
+ `--format json` gives the lists.
13
+ - **New: `imprint prove <file>`** writes `<name>.proof.json` (`-o FILE`): the file's kind, size,
14
+ SHA-256 and salt, its audit path, the server and the seal's public receipt. It reveals no other
15
+ file. A warning when the file here is not the sealed one.
16
+ - **New: `imprint verify-file <file> --proof P`**, no account needed: the receipt is verified
17
+ (keys from the proof's server, `--url` or `--keys FILE`), then the file is hashed and its
18
+ leaf checked against the attested root and count. Exit 0 VERIFIED, 1 NOT VERIFIED, 3 newer.
19
+ - Golden vectors set 3 checks its TSA tokens against its own test root
20
+ (`golden-3-tsa-root.pem`), as sets 1 and 2 do.
21
+
22
+ ## 0.5.0a34 — Seal every tracked file, in any language [CIM-BE-58-v1]
23
+
24
+ For engine 0.7.0a43. With an older engine a seal is Python-only, as before.
25
+
26
+ - **Every file.** `imprint seal` (Git, CI tokens, `--zip` and folders without Git) lists every
27
+ tracked file after only the exclude list and `.imprint/`: links (their target text),
28
+ executables and submodules (their commit) included, no size limit. Each file is hashed here
29
+ from Git's own copy (`git cat-file --batch`, read in parts), and only the SHA-256s, sizes and
30
+ modes are sent; Python files are still uploaded when the server asks for them. **The content
31
+ of a file that is not Python never leaves your machine.**
32
+ - **Checked before you sign.** The client rebuilds the root of the salted file list under the
33
+ seal's seed (`filelist.py`, scheme `sha256-leaf-v1+rfc6962`) and the commit commitment, and
34
+ refuses to sign a statement that differs ("nothing was signed").
35
+ - **A repository with no Python seals.** The result shows "Integrity: N files · Fingerprint:
36
+ none (Python only today)"; with Python, "Fingerprint: Python (M files)". `nothing_to_seal`
37
+ only when no file is left after the excludes. The old "CodeImprint seals Python source files
38
+ (.py) at present" is said only for an older server.
39
+ - **`imprint verify`** reads receipt format 5: attestation v3, log entry v3 (rebuilt with the
40
+ file root and the commit commitment) and chain signature v2 (signed over them), and a "files"
41
+ check (for an older seal: "Python-only seal (before engine 0.7.0a43)"). An unknown file
42
+ scheme is "newer", never a failure. Receipt format 6 is the next newer format.
43
+ - Tests: `test_every_file.py`, golden vectors set 3 (the engine's every-file seals, rebuilt with
44
+ this client's code).
45
+
46
+ ## 0.5.0a33 — Plan refusals are never silent [CIM-BE-53-v1]
47
+
48
+ For engine 0.7.0a40, which can enforce the Hello plan's limits (`CODEIMPRINT_BILLING_ENFORCE`).
49
+ Includes 0.5.0a32 (not tagged on its own).
50
+
51
+ - **New: a seal the plan refuses says so.** The server's `plan_limit_reached` (a new active
52
+ project too many) and `plan_automatic_sealing` (a CI token's seal on the free Hello plan)
53
+ are printed as "not sealed: <the server's message, with the upgrade link> [<code>]".
54
+ - In GitHub Actions: a warning annotation titled "CodeImprint plan", exit code 0 (an
55
+ automated build never fails on it).
56
+ - In a terminal: the same warning, exit code 2.
57
+ - `imprint token create` names the code too.
58
+ - Tests: `tests/test_plan_refusals.py`.
59
+
3
60
  ## 0.5.0a32 — Signed organisation requests [CIM-BE-48-v1]
4
61
 
5
62
  For engine 0.7.0a38, which needs them (audit 42f-01, 42f-03).
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codeimprint
3
- Version: 0.5.0a32
3
+ Version: 0.5.0a35
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
@@ -97,7 +97,9 @@ evidence, not proof), `imprint chain`, `imprint hook install`, `imprint identity
97
97
  `imprint seal` and `imprint check` upload the project's Python files to the CodeImprint
98
98
  server you signed in to, which deletes them as soon as it has sealed or checked them. A Git
99
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.
100
+ the server keeps those only as keyed hashes, with the seal. From 0.5.0a34 a seal covers every
101
+ file in any language: the client sends each file's SHA-256, size and mode, never the content
102
+ of a file that is not Python.
101
103
  Your developer key never leaves your machine: only its public half is sent.
102
104
 
103
105
  ## Licence
@@ -63,7 +63,9 @@ evidence, not proof), `imprint chain`, `imprint hook install`, `imprint identity
63
63
  `imprint seal` and `imprint check` upload the project's Python files to the CodeImprint
64
64
  server you signed in to, which deletes them as soon as it has sealed or checked them. A Git
65
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.
66
+ the server keeps those only as keyed hashes, with the seal. From 0.5.0a34 a seal covers every
67
+ file in any language: the client sends each file's SHA-256, size and mode, never the content
68
+ of a file that is not Python.
67
69
  Your developer key never leaves your machine: only its public half is sent.
68
70
 
69
71
  ## 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.0a32"
9
+ version = "0.5.0a35"
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.0a32"
8
+ __version__ = "0.5.0a35"
@@ -43,12 +43,18 @@ class NetworkError(Exception):
43
43
  """The server could not be reached."""
44
44
 
45
45
 
46
- def _multipart(fields: dict[str, str], file_name: str, file_bytes: bytes) -> tuple[bytes, str]:
46
+ def _multipart(fields: dict[str, str], file_name: str, file_bytes: bytes,
47
+ extra_file: tuple[str, str, bytes] | None = None) -> tuple[bytes, str]:
47
48
  boundary = f"codeimprint-{uuid.uuid4().hex}"
48
49
  parts = []
49
50
  for name, value in fields.items():
50
51
  parts.append(f'--{boundary}\r\nContent-Disposition: form-data; name="{name}"\r\n\r\n'
51
52
  f"{value}\r\n".encode())
53
+ if extra_file is not None: # (field, file name, bytes), JSON
54
+ field, fname, data = extra_file
55
+ parts.append(f'--{boundary}\r\nContent-Disposition: form-data; name="{field}"; '
56
+ f'filename="{fname}"\r\nContent-Type: application/json\r\n\r\n'.encode())
57
+ parts.append(data + b"\r\n")
52
58
  parts.append(f'--{boundary}\r\nContent-Disposition: form-data; name="file"; '
53
59
  f'filename="{file_name}"\r\nContent-Type: application/zip\r\n\r\n'.encode())
54
60
  parts.append(file_bytes)
@@ -132,11 +138,17 @@ class Client:
132
138
  return self._request("GET", "/health")
133
139
 
134
140
  def seal(self, zip_bytes: bytes, name: str | None = None, lines: dict | None = None,
135
- project_id: str | None = None) -> dict:
141
+ project_id: str | None = None, files_manifest: bytes | None = None) -> dict:
142
+ """A zip seal. ``files_manifest`` (engine 0.7.0a43): every file, hashed here, as
143
+ JSON; the zip then holds only the files to fingerprint."""
136
144
  fields = {k: v for k, v in (("name", name), ("project_id", project_id)) if v}
137
145
  if lines is not None:
138
146
  fields["lines"] = json.dumps(lines, sort_keys=True, separators=(",", ":"))
139
- body, ctype = _multipart(fields, "project.zip", zip_bytes)
147
+ extra = None
148
+ if files_manifest is not None:
149
+ fields["files_scheme"] = "sha256-leaf-v1+rfc6962"
150
+ extra = ("files_manifest", "files.json", files_manifest)
151
+ body, ctype = _multipart(fields, "project.zip", zip_bytes, extra)
140
152
  return self._request("POST", "/api/v1/seal", body, ctype)
141
153
 
142
154
  def _json(self, method: str, path: str, payload: dict | None = None) -> dict:
@@ -402,6 +414,11 @@ class Client:
402
414
  def public_imprint(self, imprint_id: str) -> dict:
403
415
  return self._request("GET", f"/api/v1/public/imprints/{quote(imprint_id)}")
404
416
 
417
+ def seal_files(self, imprint_id: str) -> dict:
418
+ """A seal's file list, for its owner (engine 0.7.0a44): paths, kinds, sizes and
419
+ hashes, the seed, the commit and tree. Nothing is sent but the request."""
420
+ return self._request("GET", f"/api/v1/imprints/{quote(imprint_id)}/files")
421
+
405
422
  # a seal's validity and certificate (engine 0.7.0a26) -----------------------------------
406
423
  def validity(self, imprint_id: str) -> dict:
407
424
  """A seal's validity now, as the server works it out: state, valid until, timeline
@@ -18,7 +18,7 @@ import json
18
18
  import time
19
19
  from pathlib import Path
20
20
 
21
- from . import gitrepo, linecount, trust
21
+ from . import filelist, gitrepo, linecount, trust
22
22
  from .api import ApiError
23
23
  from .imprint_file import canonical
24
24
 
@@ -131,7 +131,18 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
131
131
  files = [f for f in gitrepo.ls_tree(top, commit, under)
132
132
  if not f["path"].startswith(".imprint/")] # seals and receipts: not content
133
133
  lines = linecount.count_commit(top, commit, files, under).payload()
134
- pages = [files[i:i + PAGE] for i in range(0, len(files), PAGE)] or [[]]
134
+ # Engine 0.7.0a43: every tracked file is sealed. Each is hashed here, from Git's own
135
+ # copy of the commit; only the hashes are sent (Python files are still uploaded, to be
136
+ # fingerprinted, when the server asks for them).
137
+ listed = [f for f in gitrepo.ls_tree_all(top, commit, under)
138
+ if not f["path"].startswith(".imprint/")]
139
+ digests = gitrepo.hash_blobs(top, sorted({f["blob"] for f in listed
140
+ if f["mode"] != "submodule"}))
141
+ for f in listed:
142
+ if f["mode"] != "submodule":
143
+ f["sha256"], f["size"] = digests[f["blob"]]
144
+ entries = filelist.entries_of(listed, list(exclude or []))
145
+ pages = [listed[i:i + PAGE] for i in range(0, len(listed), PAGE)] or [[]]
135
146
  plan_id, resp = None, {}
136
147
  for i, page in enumerate(pages):
137
148
  body = {"files": page, "more": i < len(pages) - 1}
@@ -139,7 +150,8 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
139
150
  body["plan_id"] = plan_id
140
151
  else:
141
152
  body.update(tree=info["tree"], commit=commit, parents=info["parents"],
142
- ref=info["ref"], kind=kind, exclude=list(exclude or []), lines=lines)
153
+ ref=info["ref"], kind=kind, exclude=list(exclude or []), lines=lines,
154
+ files_scheme=filelist.SCHEME)
143
155
  if repository: # which repository this is (engine 0.7.0a23+)
144
156
  body["repository"] = repository
145
157
  try: # commit IDs only (engine 0.7.0a22+ keeps them keyed)
@@ -153,7 +165,10 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
153
165
  resp = client.plan(project, body)
154
166
  except ApiError as exc:
155
167
  if exc.code == "nothing_to_seal":
156
- raise NothingToSeal(len(files), _python(files), str(exc)) from exc
168
+ # Files are left after the excludes, so the server is older than 0.7.0a43
169
+ # and seals Python files only.
170
+ raise NothingToSeal(len(files), _python(files), str(exc),
171
+ older_server=bool(entries)) from exc
157
172
  raise
158
173
  if "release" in resp:
159
174
  rel = resp["release"]
@@ -167,8 +182,8 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
167
182
  return {"already": seal, "released": resp.get("already_released"),
168
183
  "commit": commit, "info": info, "engagement": resp.get("engagement")}
169
184
  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))
185
+ if resp.get("files") == 0 and "integrity_files" not in resp: # before 0.7.0a28
186
+ raise NothingToSeal(len(files), _python(files), older_server=True)
172
187
  need = resp["need"]
173
188
  sizes = {f["blob"]: f["size"] for f in files}
174
189
  size = sum(sizes.get(b, 0) for b in need)
@@ -191,26 +206,35 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
191
206
  if exc.code == "nothing_to_seal":
192
207
  raise NothingToSeal(said=str(exc)) from exc
193
208
  raise
209
+ statement = prep["statement"]
210
+ if statement.get("type") == "codeimprint.chain-seal.v2": # every file: check, then sign
211
+ filelist.check_statement(statement, entries, prep.get("files_seed"), commit,
212
+ info["tree"])
194
213
  result = client.finalise(project, prep["pending_id"], public_key(key),
195
- sign(key, prep["statement"]))
214
+ sign(key, statement))
196
215
  check_lines(lines, result)
197
216
  return {"result": result, "uploaded": len(need), "upload_bytes": size, "tag": tag,
198
- "files": resp.get("files", 0), "commit": commit, "info": info, "lines": lines}
217
+ "files": resp.get("files", 0), "commit": commit, "info": info, "lines": lines,
218
+ "integrity_files": resp.get("integrity_files")}
199
219
 
200
220
 
201
221
  NOTHING_TO_SEAL = ("Nothing to seal: no files matched. Check .gitignore, the exclude list in "
202
222
  ".imprint/config.json, and that you are in the project folder.")
203
- PYTHON_ONLY = " CodeImprint seals Python source files (.py) at present."
223
+ # Engine 0.7.0a43 seals every file, in any language; an older server seals Python files only.
224
+ OLDER_SERVER = (" This server is older than engine 0.7.0a43 and seals Python source files "
225
+ "(.py) only.")
204
226
 
205
227
 
206
228
  class NothingToSeal(RuntimeError):
207
229
  """A seal that would cover no file is never made (engine 0.7.0a28 answers 422
208
230
  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."""
231
+ ``tracked`` is the number of files Git tracks at the commit, of any kind;
232
+ ``older_server``: files were left, so the server seals Python files only."""
210
233
 
211
- def __init__(self, tracked: int = 0, python: int = 0, said: str | None = None) -> None:
234
+ def __init__(self, tracked: int = 0, python: int = 0, said: str | None = None,
235
+ older_server: bool = False) -> None:
212
236
  super().__init__((said or NOTHING_TO_SEAL)
213
- + (PYTHON_ONLY if tracked and not python else ""))
237
+ + (OLDER_SERVER if older_server and tracked and not python else ""))
214
238
 
215
239
 
216
240
  def check_lines(sent: dict, result: dict) -> None: