codeimprint 0.5.0a15__tar.gz → 0.5.0a16__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.0a15 → codeimprint-0.5.0a16}/CHANGELOG.md +30 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/PKG-INFO +1 -1
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/pyproject.toml +1 -1
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/__init__.py +1 -1
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/api.py +5 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/cli.py +103 -4
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/imprint_file.py +1 -1
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/receipt.py +105 -7
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/records.py +3 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/.gitignore +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/LICENSE +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/NOTICE +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/README.pypi.md +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint/__init__.py +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint/__main__.py +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/__main__.py +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/chainseal.py +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/config.py +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/gitrepo.py +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/linecount.py +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/ownership.py +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/project.py +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/timestamp.py +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/transparency.py +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/trust.py +0 -0
- {codeimprint-0.5.0a15 → codeimprint-0.5.0a16}/src/codeimprint_cli/tsa_roots.py +0 -0
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0a16 — Lineage records (LIN1) verify offline [CIM-BE-31-v1]
|
|
4
|
+
|
|
5
|
+
For engine 0.7.0a21. Older engines still work; they have no lineage records.
|
|
6
|
+
|
|
7
|
+
- **New record type: `LIN1`** (`codeimprint.lineage.v1`), the link between a project that
|
|
8
|
+
was cloned or forked and its origin. The public record never names the origin: it holds
|
|
9
|
+
a salted commitment. `imprint verify` now knows the type:
|
|
10
|
+
- the record, its typed ID and its place in the log, as for every record;
|
|
11
|
+
- a new `lineage` check: a declared link names the clone and its seal and has exactly one
|
|
12
|
+
signature, role `child`; a detected link is the server's own record, unsigned, and
|
|
13
|
+
names nobody;
|
|
14
|
+
- a new `opening` check when the opening is at hand: it must give the record's
|
|
15
|
+
commitment (SHA-256 of the canonical `{salt, project, seal}`; a detected link adds the
|
|
16
|
+
clone). A wrong project, seal or salt fails;
|
|
17
|
+
- with `--online`, a declared link's signing key must have been a key of the clone's
|
|
18
|
+
project when the record was attested (`project key`).
|
|
19
|
+
- **New: `imprint verify --opening FILE`** checks an opening you were given against a
|
|
20
|
+
lineage record. With `--online` and a sign-in, `imprint verify LIN1-…` asks the server
|
|
21
|
+
for the opening too; the server gives it only to an account that is part of both
|
|
22
|
+
projects, or that declared the link.
|
|
23
|
+
- **New: `imprint lineage show <LIN1-ID>`** prints a link as far as your account may see
|
|
24
|
+
it. `--out FILE` saves the record and its opening; `imprint verify FILE` checks both
|
|
25
|
+
offline. `--json` prints the server's answer.
|
|
26
|
+
- Not in this release: declaring a link from the client (`imprint init --new-project`
|
|
27
|
+
does not make one yet) and anything about detection.
|
|
28
|
+
- A link says that two projects share an origin and which was sealed earlier. It does not
|
|
29
|
+
say who wrote the code and it changes no ownership claim.
|
|
30
|
+
- Tests: `tests/test_lineage.py`, with real records from engine 0.7.0a21
|
|
31
|
+
(`tests/fixtures/lineage-engine.json`).
|
|
32
|
+
|
|
3
33
|
## 0.5.0a15 — Another device joins the project; `python -m codeimprint` [CIM-BE-30-v1]
|
|
4
34
|
|
|
5
35
|
For engine 0.7.0a20. Older engines still work, except for the new `imprint key` commands.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: codeimprint
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.0a16
|
|
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.0a16"
|
|
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"
|
|
@@ -175,6 +175,11 @@ class Client:
|
|
|
175
175
|
return self._json("POST", f"/api/v1/projects/{quote(project)}/keys/requests",
|
|
176
176
|
{"public_key": public_key, "signature": signature, "label": label})
|
|
177
177
|
|
|
178
|
+
def lineage(self, record_id: str) -> dict:
|
|
179
|
+
"""A lineage record (LIN1): its public record and, when this account may see it,
|
|
180
|
+
the opening of its commitment (engine 0.7.0a21+)."""
|
|
181
|
+
return self._json("GET", f"/api/v1/lineage/{quote(record_id)}")
|
|
182
|
+
|
|
178
183
|
def key_requests(self, project: str) -> dict:
|
|
179
184
|
return self._json("GET", f"/api/v1/projects/{quote(project)}/keys/requests")
|
|
180
185
|
|
|
@@ -2002,6 +2002,12 @@ def _load_target(args) -> tuple[dict | None, dict | None, Path]:
|
|
|
2002
2002
|
rec_path = Path(args.receipt) if args.receipt else receipt_path_for(target)
|
|
2003
2003
|
rec = imprint_file.load(rec_path) if rec_path.is_file() else None
|
|
2004
2004
|
return data, rec, _project_root(target)
|
|
2005
|
+
if isinstance(data, dict) and isinstance(data.get("receipt"), dict) \
|
|
2006
|
+
and receipt.is_lineage(data["receipt"]):
|
|
2007
|
+
# What `imprint lineage show --out` saved: the record and, when this account
|
|
2008
|
+
# may see it, the opening of its commitment.
|
|
2009
|
+
args.found_opening = data.get("opening")
|
|
2010
|
+
return None, data["receipt"], _project_root(target)
|
|
2005
2011
|
if isinstance(data, dict) and "attestation" in data:
|
|
2006
2012
|
doc_path = target.with_name(target.name.removesuffix(".receipt.json") + ".imprint")
|
|
2007
2013
|
doc = imprint_file.load(doc_path) if doc_path.is_file() else None
|
|
@@ -2067,6 +2073,80 @@ def _server_from_project(root: Path) -> str | None:
|
|
|
2067
2073
|
return None
|
|
2068
2074
|
|
|
2069
2075
|
|
|
2076
|
+
def _fetch_lineage(client: Client, record_id: str) -> tuple[dict, dict | None]:
|
|
2077
|
+
"""A lineage record and, for an account that may see it, its opening. Without a
|
|
2078
|
+
sign-in (or on an older server) the public record alone."""
|
|
2079
|
+
if client.auth in ("token", "session"):
|
|
2080
|
+
try:
|
|
2081
|
+
answer = client.lineage(record_id)
|
|
2082
|
+
return answer["receipt"], answer.get("opening")
|
|
2083
|
+
except (ApiError, KeyError):
|
|
2084
|
+
pass
|
|
2085
|
+
return client.public_record(record_id), None
|
|
2086
|
+
|
|
2087
|
+
|
|
2088
|
+
def _opening_for(args, rec: dict | None, found: dict | None) -> dict | None:
|
|
2089
|
+
"""The opening to check a lineage record's commitment against: --opening FILE, else
|
|
2090
|
+
the one that came with the record."""
|
|
2091
|
+
if not getattr(args, "opening", None):
|
|
2092
|
+
return found
|
|
2093
|
+
if rec is None or not receipt.is_lineage(rec):
|
|
2094
|
+
raise Abort("--opening is for lineage records (LIN1)")
|
|
2095
|
+
try:
|
|
2096
|
+
data = json.loads(Path(args.opening).read_text(encoding="utf-8"))
|
|
2097
|
+
except (OSError, ValueError) as exc:
|
|
2098
|
+
raise Abort(f"cannot read {args.opening}: {exc}") from exc
|
|
2099
|
+
if not isinstance(data, dict):
|
|
2100
|
+
raise Abort(f"{args.opening} does not hold an opening")
|
|
2101
|
+
return data["opening"] if "receipt" in data and "opening" in data else data
|
|
2102
|
+
|
|
2103
|
+
|
|
2104
|
+
def cmd_lineage(args) -> int:
|
|
2105
|
+
"""`imprint lineage show LIN1-…`: a lineage record as this account may see it."""
|
|
2106
|
+
if not imprint_file.is_valid_id(args.record, ("LIN1",)):
|
|
2107
|
+
raise Abort(f"not a lineage record ID (LIN1-…): {args.record}")
|
|
2108
|
+
rid = imprint_file.clean_id(args.record)
|
|
2109
|
+
client = _client(args, _server_from_project(Path(".")))
|
|
2110
|
+
try:
|
|
2111
|
+
answer = client.lineage(rid)
|
|
2112
|
+
except (ApiError, NetworkError) as exc:
|
|
2113
|
+
raise Abort(_explain(client, exc, f"cannot read {rid}")) from exc
|
|
2114
|
+
saved = imprint_file.save(answer, args.out) if args.out else None
|
|
2115
|
+
if args.json:
|
|
2116
|
+
print(json.dumps(answer, indent=2))
|
|
2117
|
+
return 0
|
|
2118
|
+
doc = answer["receipt"]["record"]["document"]
|
|
2119
|
+
opening = answer.get("opening") or {}
|
|
2120
|
+
clone = opening.get("child") or (
|
|
2121
|
+
{"project": doc["child"], "seal": doc["child_seal"]} if "child" in doc else None)
|
|
2122
|
+
_say(f"Record {rid}",
|
|
2123
|
+
f"Link {answer['basis']} {answer['relation']}, signals "
|
|
2124
|
+
f"{', '.join(answer['signals'])}, {answer['at']}")
|
|
2125
|
+
if clone:
|
|
2126
|
+
_say(f"Clone project {clone['project']}, seal {clone['seal']}")
|
|
2127
|
+
else:
|
|
2128
|
+
_say("Clone not named in the public record")
|
|
2129
|
+
if opening:
|
|
2130
|
+
origin = opening["parent"]
|
|
2131
|
+
_say(f"Origin project {origin['project']}, "
|
|
2132
|
+
+ (f"seal {origin['seal']}" if origin.get("seal") else "no seal named")
|
|
2133
|
+
+ (" (as declared)" if answer["basis"] == "declared" else ""))
|
|
2134
|
+
checks = opening.get("checks")
|
|
2135
|
+
if checks:
|
|
2136
|
+
_say("Declared the origin project "
|
|
2137
|
+
+ ("is" if checks.get("parent_known") else "is not") + " on this server; "
|
|
2138
|
+
"the seal named "
|
|
2139
|
+
+ ("is" if checks.get("parent_seal_in_parent") else "is not") + " one of its seals")
|
|
2140
|
+
else:
|
|
2141
|
+
_say("Origin not shown: the public record holds a commitment only. Both sides "
|
|
2142
|
+
"are shown to an account that is part of both projects.")
|
|
2143
|
+
if saved:
|
|
2144
|
+
_say(f"Saved {saved} (check it offline: imprint verify {saved})")
|
|
2145
|
+
_say("", "A link says that two projects share an origin and which was sealed earlier; "
|
|
2146
|
+
"it does not say who wrote the code.")
|
|
2147
|
+
return 0
|
|
2148
|
+
|
|
2149
|
+
|
|
2070
2150
|
def _file_only(doc: dict) -> list[receipt.Check]:
|
|
2071
2151
|
status = imprint_file.verify_document(doc)
|
|
2072
2152
|
sig = ("not signed" if not status["signed"] else
|
|
@@ -2087,20 +2167,25 @@ def cmd_verify(args) -> int:
|
|
|
2087
2167
|
args.verify_parser.error("the following arguments are required: target")
|
|
2088
2168
|
args.target = str(default)
|
|
2089
2169
|
doc, rec, root = _load_target(args)
|
|
2170
|
+
found = getattr(args, "found_opening", None)
|
|
2090
2171
|
checks: list[receipt.Check] = []
|
|
2091
2172
|
client = _client(args, _server_from_project(root)) if args.online else None
|
|
2092
2173
|
if rec is None and client is not None:
|
|
2093
2174
|
iid = imprint_file.clean_id(args.target) if doc is None else (
|
|
2094
2175
|
imprint_file.verify_document(doc)["id"])
|
|
2176
|
+
prefix = iid.split("-", 1)[0]
|
|
2095
2177
|
try:
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2178
|
+
if prefix == "LIN1":
|
|
2179
|
+
rec, found = _fetch_lineage(client, iid)
|
|
2180
|
+
else:
|
|
2181
|
+
rec = (client.public_record(iid) if prefix in imprint_file.RECORD_PREFIXES
|
|
2182
|
+
else client.public_imprint(iid))
|
|
2099
2183
|
except ApiError as exc:
|
|
2100
2184
|
if doc is None:
|
|
2101
2185
|
raise Abort(f"no public record for {iid}: {exc}") from exc
|
|
2102
2186
|
except NetworkError as exc:
|
|
2103
2187
|
raise Abort(str(exc)) from exc
|
|
2188
|
+
opening = _opening_for(args, rec, found)
|
|
2104
2189
|
if rec is None:
|
|
2105
2190
|
checks = _file_only(doc)
|
|
2106
2191
|
iid = imprint_file.verify_document(doc)["id"]
|
|
@@ -2115,7 +2200,7 @@ def cmd_verify(args) -> int:
|
|
|
2115
2200
|
f"also trusting {extra} certificate(s) from "
|
|
2116
2201
|
f"{args.tsa_certs}, beyond the pinned roots"))
|
|
2117
2202
|
checks += receipt.verify(rec, keys, doc, developer=args.developer or developer,
|
|
2118
|
-
anchors=anchors)
|
|
2203
|
+
anchors=anchors, opening=opening)
|
|
2119
2204
|
if client is not None and keys:
|
|
2120
2205
|
try:
|
|
2121
2206
|
checks += receipt.verify_online(rec, client, keys, anchors)
|
|
@@ -2395,9 +2480,23 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
2395
2480
|
v.add_argument("--url", help="server URL for --online")
|
|
2396
2481
|
v.add_argument("--tsa-certs", metavar="FILE",
|
|
2397
2482
|
help="also trust the time-stamping authorities in this PEM bundle")
|
|
2483
|
+
v.add_argument("--opening", metavar="FILE",
|
|
2484
|
+
help="a lineage record (LIN1): check that this opening ({parent: {project, "
|
|
2485
|
+
"seal}, salt}) gives the record's commitment")
|
|
2398
2486
|
v.add_argument("--strict", action="store_true", help="treat warnings as failures")
|
|
2399
2487
|
v.add_argument("--json", action="store_true")
|
|
2400
2488
|
v.set_defaults(func=cmd_verify, verify_parser=v)
|
|
2489
|
+
|
|
2490
|
+
ln = sub.add_parser("lineage", help="a lineage record (LIN1): the link between a clone "
|
|
2491
|
+
"and its origin, as far as you may see it")
|
|
2492
|
+
ln.add_argument("action", choices=["show"])
|
|
2493
|
+
ln.add_argument("record", help="the record's ID (LIN1-…)")
|
|
2494
|
+
ln.add_argument("-o", "--out", metavar="FILE",
|
|
2495
|
+
help="save the record (and its opening, when shown to you) to verify "
|
|
2496
|
+
"offline with `imprint verify FILE`")
|
|
2497
|
+
ln.add_argument("--json", action="store_true")
|
|
2498
|
+
ln.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
|
|
2499
|
+
ln.set_defaults(func=cmd_lineage)
|
|
2401
2500
|
return p
|
|
2402
2501
|
|
|
2403
2502
|
|
|
@@ -17,7 +17,7 @@ ID_PREFIX = "IMP1"
|
|
|
17
17
|
RELEASE_PREFIX = "REL1" # release records: same shape, own namespace
|
|
18
18
|
BODY_CHECKED = (ID_PREFIX, RELEASE_PREFIX) # frozen: check character over the body only
|
|
19
19
|
RECORD_PREFIXES = ("IDT1", "REV1", "MBR1", "END1", "CLM1", "XFR1", "ASG1", "DCL1", "CTB1",
|
|
20
|
-
"NTC1", "DSC1", "INT1")
|
|
20
|
+
"NTC1", "DSC1", "INT1", "LIN1") # records: check over prefix + body
|
|
21
21
|
ALL_PREFIXES = BODY_CHECKED + RECORD_PREFIXES
|
|
22
22
|
ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ" # Crockford Base32: no I, L, O, U
|
|
23
23
|
|
|
@@ -86,6 +86,94 @@ def _record(receipt: dict) -> Check:
|
|
|
86
86
|
return Check("record", PASS, f"{rtype.kind} record; {who}")
|
|
87
87
|
|
|
88
88
|
|
|
89
|
+
LINEAGE = "codeimprint.lineage.v1"
|
|
90
|
+
_LINEAGE_FIELDS = {
|
|
91
|
+
"declared": {"type", "basis", "relation", "child", "child_seal", "signals",
|
|
92
|
+
"parent_commitment", "declared_at"},
|
|
93
|
+
"detected": {"type", "basis", "relation", "signals", "link_commitment", "detected_at"},
|
|
94
|
+
}
|
|
95
|
+
_RELATIONS = ("clone", "fork", "continuation", "delivery")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _hex64(value) -> bool:
|
|
99
|
+
return isinstance(value, str) and len(value) == 64 and not set(value) - set(
|
|
100
|
+
"0123456789abcdef")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def is_lineage(receipt: dict) -> bool:
|
|
104
|
+
return ((receipt or {}).get("record") or {}).get("type") == LINEAGE
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _lineage(receipt: dict) -> Check | None:
|
|
108
|
+
"""A lineage record (LIN1) links a clone to its origin. A declared link names the clone
|
|
109
|
+
and its seal and is signed by one key, role child. A detected link is the server's own
|
|
110
|
+
record and names nobody. Neither names the origin: that is a salted commitment, which
|
|
111
|
+
``_opening`` checks when the opening is at hand. The signatures themselves are verified
|
|
112
|
+
by ``_record``."""
|
|
113
|
+
if not is_lineage(receipt):
|
|
114
|
+
return None
|
|
115
|
+
doc = receipt["record"].get("document") or {}
|
|
116
|
+
basis = doc.get("basis")
|
|
117
|
+
if not isinstance(basis, str) or set(doc) != _LINEAGE_FIELDS.get(basis):
|
|
118
|
+
return Check("lineage", FAIL, "not a declared or detected link, or it holds other "
|
|
119
|
+
"fields")
|
|
120
|
+
signals = doc["signals"]
|
|
121
|
+
if doc["relation"] not in _RELATIONS or not isinstance(signals, list) or not signals \
|
|
122
|
+
or not all(isinstance(s, str) for s in signals):
|
|
123
|
+
return Check("lineage", FAIL, "unknown relation or signals")
|
|
124
|
+
if not _hex64(doc["parent_commitment" if basis == "declared" else "link_commitment"]):
|
|
125
|
+
return Check("lineage", FAIL, "the commitment is not a SHA-256")
|
|
126
|
+
sigs = receipt.get("signatures") or []
|
|
127
|
+
how = f"{doc['relation']} link, signals {', '.join(signals)}"
|
|
128
|
+
if basis == "declared":
|
|
129
|
+
if [s.get("role") for s in sigs] != ["child"]:
|
|
130
|
+
return Check("lineage", FAIL, "a declared link has one signature, role child")
|
|
131
|
+
return Check("lineage", PASS,
|
|
132
|
+
f"declared {how}: project {doc['child']} at seal {doc['child_seal']}, "
|
|
133
|
+
f"signed by key {sigs[0].get('fingerprint')}; the origin is a "
|
|
134
|
+
"commitment")
|
|
135
|
+
if sigs:
|
|
136
|
+
return Check("lineage", FAIL, "a detected link has no owner signature")
|
|
137
|
+
return Check("lineage", PASS, f"detected {how}: the server's own record; neither "
|
|
138
|
+
"project is named, the link is a commitment")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _opening(receipt: dict, opening) -> Check:
|
|
142
|
+
"""Does the opening give the record's commitment? ``parent_commitment`` is SHA-256 of
|
|
143
|
+
canonical JSON {salt, project, seal} (the origin); ``link_commitment`` adds the clone as
|
|
144
|
+
child and child_seal."""
|
|
145
|
+
doc = receipt["record"]["document"]
|
|
146
|
+
declared = doc.get("basis") == "declared"
|
|
147
|
+
shape = "the opening is {parent: {project, seal}, salt}" + (
|
|
148
|
+
"" if declared else ", with child: {project, seal}")
|
|
149
|
+
try:
|
|
150
|
+
salt, project, seal = opening["salt"], opening["parent"]["project"], opening[
|
|
151
|
+
"parent"]["seal"]
|
|
152
|
+
child = opening.get("child") if declared else opening["child"]
|
|
153
|
+
clone = None if child is None else (child["project"], child["seal"])
|
|
154
|
+
except (AttributeError, KeyError, TypeError):
|
|
155
|
+
return Check("opening", FAIL, shape)
|
|
156
|
+
if not all(isinstance(v, str) for v in (salt, project)) or not isinstance(
|
|
157
|
+
seal, (str, type(None))) or (clone and not all(isinstance(v, str) for v in clone)):
|
|
158
|
+
return Check("opening", FAIL, shape)
|
|
159
|
+
body = {"salt": salt, "project": project, "seal": seal}
|
|
160
|
+
if declared:
|
|
161
|
+
if clone is not None and clone != (doc.get("child"), doc.get("child_seal")):
|
|
162
|
+
return Check("opening", FAIL, "the opening names another clone than the record")
|
|
163
|
+
expected = doc.get("parent_commitment")
|
|
164
|
+
else:
|
|
165
|
+
body.update(child=clone[0], child_seal=clone[1])
|
|
166
|
+
expected = doc.get("link_commitment")
|
|
167
|
+
if hashlib.sha256(canonical(body)).hexdigest() != expected:
|
|
168
|
+
return Check("opening", FAIL, "the opening does not give the record's commitment: "
|
|
169
|
+
"another project, seal or salt")
|
|
170
|
+
origin = f"origin project {project}, " + (f"seal {seal}" if seal else "no seal named")
|
|
171
|
+
if declared:
|
|
172
|
+
return Check("opening", PASS, f"the commitment opens to {origin}")
|
|
173
|
+
return Check("opening", PASS, f"the commitment opens to clone project {clone[0]}, seal "
|
|
174
|
+
f"{clone[1]}, and {origin}")
|
|
175
|
+
|
|
176
|
+
|
|
89
177
|
def _release(receipt: dict) -> Check:
|
|
90
178
|
"""A release record: its digest is SHA-256 of the release document, which names the
|
|
91
179
|
labelled seal; the chain must say the same."""
|
|
@@ -552,9 +640,10 @@ def _time_order(receipt: dict, infos: list[timestamp.TokenInfo], now: datetime)
|
|
|
552
640
|
|
|
553
641
|
def verify(receipt: dict, keys: list[dict], doc: dict | None = None,
|
|
554
642
|
developer: str | None = None, now: datetime | None = None,
|
|
555
|
-
anchors: list | None = None) -> list[Check]:
|
|
643
|
+
anchors: list | None = None, opening: dict | None = None) -> list[Check]:
|
|
556
644
|
"""Every offline check. ``developer`` is the fingerprint the project expects to sign;
|
|
557
|
-
``anchors`` the trusted TSA roots (default: the pinned ones)
|
|
645
|
+
``anchors`` the trusted TSA roots (default: the pinned ones); ``opening`` what a lineage
|
|
646
|
+
record's commitment is said to commit to."""
|
|
558
647
|
now = now or datetime.now(timezone.utc)
|
|
559
648
|
anchors = timestamp.pinned_anchors() if anchors is None else anchors
|
|
560
649
|
if not keys:
|
|
@@ -566,6 +655,11 @@ def verify(receipt: dict, keys: list[dict], doc: dict | None = None,
|
|
|
566
655
|
typed = _identity(receipt, now)
|
|
567
656
|
if typed:
|
|
568
657
|
checks.insert(1, typed)
|
|
658
|
+
link = _lineage(receipt)
|
|
659
|
+
if link:
|
|
660
|
+
checks.insert(1, link)
|
|
661
|
+
if opening is not None and link.status == PASS:
|
|
662
|
+
checks.insert(2, _opening(receipt, opening))
|
|
569
663
|
tokens, infos = _timestamps(receipt, keys, anchors)
|
|
570
664
|
return checks + tokens + [_time_order(receipt, infos, now)]
|
|
571
665
|
checks = [_digest(receipt, doc), _attestation(receipt, keys),
|
|
@@ -642,19 +736,23 @@ def verify_online(receipt: dict, client, keys: list[dict],
|
|
|
642
736
|
f"entry #{index} was added after entry #{index - 1}"))
|
|
643
737
|
|
|
644
738
|
chain = receipt.get("chain") or {}
|
|
645
|
-
signer = chain_signer(receipt)
|
|
646
|
-
if
|
|
739
|
+
signer, signed_for = chain_signer(receipt), chain.get("project")
|
|
740
|
+
if is_lineage(receipt): # a declared link: the clone's project key signed
|
|
741
|
+
doc, sigs = receipt["record"]["document"], receipt.get("signatures") or []
|
|
742
|
+
if doc.get("basis") == "declared" and len(sigs) == 1:
|
|
743
|
+
signer, signed_for = sigs[0].get("fingerprint"), doc.get("child")
|
|
744
|
+
if signed_for and signer and hasattr(client, "public_project"):
|
|
647
745
|
attested = receipt["attestation"]["statement"]["attested_at"]
|
|
648
746
|
keys_now = {k["fingerprint"]: k
|
|
649
|
-
for k in client.public_project(
|
|
747
|
+
for k in client.public_project(signed_for).get("keys", [])}
|
|
650
748
|
k = keys_now.get(signer)
|
|
651
749
|
if k and k["valid_from"] <= attested and (not k["valid_until"]
|
|
652
750
|
or attested <= k["valid_until"]):
|
|
653
751
|
checks.append(Check("project key", PASS, f"{signer} was a key of project "
|
|
654
|
-
f"{
|
|
752
|
+
f"{signed_for} at {attested}"))
|
|
655
753
|
else:
|
|
656
754
|
checks.append(Check("project key", FAIL, f"{signer} was not a key of project "
|
|
657
|
-
f"{
|
|
755
|
+
f"{signed_for} at {attested}"))
|
|
658
756
|
rel = receipt.get("release")
|
|
659
757
|
if rel:
|
|
660
758
|
try:
|
|
@@ -43,6 +43,9 @@ TYPES: dict[str, RecordType] = {
|
|
|
43
43
|
"codeimprint.disclosure.v1": RecordType("DSC1", "disclosure", ("record",), ("admin",)),
|
|
44
44
|
"codeimprint.integration.v1": RecordType("INT1", "integration", (),
|
|
45
45
|
("integration", "owner")),
|
|
46
|
+
# Clone lineage: a declared link is signed by the clone's project key (role child); a
|
|
47
|
+
# detected link is the server's own. The origin is never a reference field.
|
|
48
|
+
"codeimprint.lineage.v1": RecordType("LIN1", "lineage", ("child_seal",)),
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
|
|
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
|