@rightkit/release 0.6.52 → 0.6.55
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.
- package/README.md +6 -1
- package/adapter-env.mjs +16 -105
- package/admission-host.mjs +14 -1
- package/bin/darwin/rightkit-swap +0 -0
- package/bin/rightkit-gate.mjs +585 -404
- package/broker-admission.mjs +122 -2
- package/build-launch.mjs +52 -58
- package/build-release.mjs +2 -2
- package/cargo-ledger.mjs +24 -5
- package/cargo-target-shim.mjs +54 -23
- package/cargo-target.mjs +2 -2
- package/carried-adapter-run.mjs +7 -8
- package/carried-cargo-run.mjs +1 -1
- package/ci-compile-admission.mjs +1 -1
- package/clippy-route.mjs +65 -18
- package/compile-inputs.mjs +91 -15
- package/cross-targets.mjs +5 -3
- package/deps-cargo-lock.mjs +1 -1
- package/deterministic-scans.mjs +789 -259
- package/development.mjs +33 -7
- package/direct-receipt.mjs +3 -5
- package/feature-coverage.mjs +45 -9
- package/feature-partition.mjs +204 -0
- package/feature-sets.mjs +113 -0
- package/gate-acceptance.mjs +187 -115
- package/gate-seam.mjs +352 -0
- package/gate-serve.mjs +34 -2
- package/gate-stages.mjs +6 -2
- package/ghsa-audit.mjs +19 -4
- package/heavy-command.mjs +5 -4
- package/install-tauri-authenticode.mjs +73 -4
- package/ios-dev.mjs +3 -3
- package/ios-package-recipe.mjs +6 -6
- package/linux-setup.mjs +3 -2
- package/local-publish.mjs +113 -17
- package/lock-identity.mjs +24 -100
- package/managed-cargo.mjs +3 -3
- package/managed-root-guard.mjs +2 -2
- package/managed-roots.mjs +3 -3
- package/native-adapters.mjs +41 -244
- package/native-helpers.mjs +1 -1
- package/ownership-mandatory-set.json +16 -0
- package/pack-digest.mjs +1 -1
- package/package-recipe-targets.mjs +19 -11
- package/package.json +2 -2
- package/publication-gate.mjs +29 -6
- package/publish-cargo.mjs +4 -5
- package/publish-local-cargo.mjs +77 -1
- package/qualification-verify.mjs +76 -49
- package/receipt-signature.mjs +104 -0
- package/recipe-build.mjs +15 -2
- package/release-switch-registry.json +4 -0
- package/release-switch-scan.mjs +13 -10
- package/rightkit-versions.json +184 -170
- package/scan-digest.mjs +43 -14
- package/seam-broker.mjs +168 -0
- package/snapshot-check.mjs +4 -1
- package/snapshot-dependency-reuse.mjs +1 -1
- package/snapshot-metadata.mjs +24 -35
- package/snapshot.mjs +328 -49
- package/stage-commands.mjs +59 -5
- package/stage-ledger.mjs +2 -2
- package/{carried-cargo.mjs → stage-seam.mjs} +118 -70
- package/stage-sidecar.mjs +9 -7
- package/tauri-bundle-marker.mjs +5 -2
- package/tauri-locked.mjs +1 -1
- package/tool-build.mjs +8 -6
- package/unit-gate.mjs +40 -10
- package/broker-handshake.mjs +0 -160
- package/broker-wire.mjs +0 -278
- package/build-ownership.mjs +0 -1578
- package/cargo-shapes.mjs +0 -332
- package/cargo-width.mjs +0 -49
- package/carrier-census.mjs +0 -124
- package/clippy-equivalence.mjs +0 -202
- package/freshness-census.mjs +0 -405
- package/handle-revocation.mjs +0 -100
- package/handle-revocation.rust-vector.json +0 -1
- package/handle-revocation.vectors.json +0 -53
- package/legion-freeze-consumer.mjs +0 -241
- package/linux-qualifier.mjs +0 -83
- package/native-tool-planning.mjs +0 -94
- package/owner-process-proof.mjs +0 -14
- package/ownership-mark.mjs +0 -191
- package/ownership-recover.mjs +0 -78
- package/pnpm-adapter-grammar.mjs +0 -226
- package/provenance-verify.mjs +0 -413
- package/snapshot-broker.mjs +0 -808
- package/snapshot-request.mjs +0 -722
- package/unit-list-compile.mjs +0 -356
package/provenance-verify.mjs
DELETED
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
// Verifies a RustRight broker job receipt's signed provenance envelope in pure JS (node:crypto only), exactly as
|
|
2
|
-
// rustright-protocol's attestation.rs `verify_receipt` does, so a hosted runner with no broker can authenticate the receipts a local
|
|
3
|
-
// gate run embedded in its qualification. Never trusts a value from the receipt that the caller can pin instead.
|
|
4
|
-
import { createHash, createPublicKey, verify } from "node:crypto";
|
|
5
|
-
|
|
6
|
-
export const PROVENANCE_SCHEMA = "rustright.provenance.v1";
|
|
7
|
-
export const PROVENANCE_DOMAIN = "rustright-provenance-v1";
|
|
8
|
-
export const QUALIFICATION_NONCE_DOMAIN = "rightkit-qualification-v1";
|
|
9
|
-
export const CARRIED_CALL_NONCE_DOMAIN = "rightkit-carried-call-v1";
|
|
10
|
-
/** The environment variable that carries a release-bound stage's nonce. It is no carrier variable: every carried call, a Cargo call or an
|
|
11
|
-
* adapter job (a pnpm, node, swift or QA step), derives its own per-call nonce from it (carriedCallNonce) and the broker client never
|
|
12
|
-
* sees the stage nonce itself; no step takes it as its RUSTRIGHT_ATTEST_NONCE (local-publish.mjs). */
|
|
13
|
-
export const ATTEST_STAGE_NONCE_ENV = "RIGHTKIT_ATTEST_STAGE_NONCE";
|
|
14
|
-
|
|
15
|
-
export class ProvenanceError extends Error {
|
|
16
|
-
constructor(code, message) { super(message); this.name = "ProvenanceError"; this.code = code; }
|
|
17
|
-
}
|
|
18
|
-
const refuse = (code, message) => { throw new ProvenanceError(code, message); };
|
|
19
|
-
|
|
20
|
-
const sha256Hex = (data) => createHash("sha256").update(data).digest("hex");
|
|
21
|
-
const isRecord = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
22
|
-
|
|
23
|
-
function writeString(text, out) {
|
|
24
|
-
let s = '"';
|
|
25
|
-
for (const ch of text) {
|
|
26
|
-
const code = ch.codePointAt(0);
|
|
27
|
-
if (ch === '"') s += '\\"';
|
|
28
|
-
else if (ch === "\\") s += "\\\\";
|
|
29
|
-
else if (code < 0x20) s += `\\u${code.toString(16).padStart(4, "0")}`;
|
|
30
|
-
else s += ch;
|
|
31
|
-
}
|
|
32
|
-
out.push(`${s}"`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function writeCanonical(value, out) {
|
|
36
|
-
if (value === null) out.push("null");
|
|
37
|
-
else if (typeof value === "boolean") out.push(value ? "true" : "false");
|
|
38
|
-
else if (typeof value === "number") {
|
|
39
|
-
// Integers only: serde_json prints floats with its own algorithm, and an integer beyond 2^53 was already corrupted by JSON.parse.
|
|
40
|
-
// Either would make a signature fail for the wrong reason, so refuse loudly instead.
|
|
41
|
-
if (!Number.isSafeInteger(value)) refuse("canonical", "canonical JSON takes only safe integers");
|
|
42
|
-
out.push(String(value));
|
|
43
|
-
} else if (typeof value === "string") writeString(value, out);
|
|
44
|
-
else if (Array.isArray(value)) {
|
|
45
|
-
out.push("[");
|
|
46
|
-
value.forEach((item, index) => { if (index > 0) out.push(","); writeCanonical(item, out); });
|
|
47
|
-
out.push("]");
|
|
48
|
-
} else if (isRecord(value)) {
|
|
49
|
-
// Rust sorts by the UTF-8 bytes of the key; JavaScript's default sort is by UTF-16 code unit and differs above U+FFFF.
|
|
50
|
-
const keys = Object.keys(value).sort((a, b) => Buffer.compare(Buffer.from(a, "utf8"), Buffer.from(b, "utf8")));
|
|
51
|
-
out.push("{");
|
|
52
|
-
keys.forEach((key, index) => { if (index > 0) out.push(","); writeString(key, out); out.push(":"); writeCanonical(value[key], out); });
|
|
53
|
-
out.push("}");
|
|
54
|
-
} else refuse("canonical", `canonical JSON cannot carry a ${typeof value}`);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Canonical JSON: keys sorted by byte order, no whitespace, strings escape only `"`, `\` and control characters < 0x20 (\u00xx lower-case). */
|
|
58
|
-
export function canonicalJson(value) {
|
|
59
|
-
const out = [];
|
|
60
|
-
writeCanonical(value, out);
|
|
61
|
-
return out.join("");
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** The exact bytes the broker signs for a payload. */
|
|
65
|
-
export function signedBytes(payload) {
|
|
66
|
-
return Buffer.from(`${PROVENANCE_DOMAIN}\n${canonicalJson(payload)}`, "utf8");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const HEX = /^(?:[0-9a-fA-F]{2})+$/;
|
|
70
|
-
const keyFromSec1 = (publicKeyHex) => {
|
|
71
|
-
if (typeof publicKeyHex !== "string" || !HEX.test(publicKeyHex)) refuse("pin", "pinned public key is not hex");
|
|
72
|
-
const bytes = Buffer.from(publicKeyHex, "hex");
|
|
73
|
-
if (bytes.length !== 65 || bytes[0] !== 0x04) refuse("pin", "pinned public key is not an uncompressed SEC1 P-256 point");
|
|
74
|
-
try {
|
|
75
|
-
return createPublicKey({ key: { kty: "EC", crv: "P-256", x: bytes.subarray(1, 33).toString("base64url"), y: bytes.subarray(33, 65).toString("base64url") }, format: "jwk" });
|
|
76
|
-
} catch { return refuse("pin", "pinned public key is not a P-256 point"); }
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Verifies receipt.provenance against pins the caller holds (never from the receipt) and what this invocation expects. Every check
|
|
81
|
-
* fails closed (throws ProvenanceError with a stable `code`) and returns the signed payload on success.
|
|
82
|
-
* pins: { publicKey (SEC1 uncompressed hex), keyId, host, brokerDigest }
|
|
83
|
-
* expected: { jobId, nonce, requestDigest? } requestDigest is checked only when the caller can recompute it.
|
|
84
|
-
*/
|
|
85
|
-
export function verifyProvenance(receipt, pins, expected) {
|
|
86
|
-
const envelope = receipt?.provenance;
|
|
87
|
-
if (!isRecord(envelope)) refuse("legacy", "the receipt has no provenance envelope");
|
|
88
|
-
if (envelope.schema !== PROVENANCE_SCHEMA) refuse("schema", "unknown provenance schema");
|
|
89
|
-
const payload = envelope.payload;
|
|
90
|
-
if (!isRecord(payload)) refuse("malformed", "payload is missing");
|
|
91
|
-
const signature = envelope.signature;
|
|
92
|
-
if (!isRecord(signature)) refuse("malformed", "signature is missing");
|
|
93
|
-
if (signature.alg !== "ES256") refuse("alg", "signature algorithm must be ES256");
|
|
94
|
-
if (!isRecord(pins) || typeof pins.publicKey !== "string" || !HEX.test(pins.publicKey)) refuse("pin", "pinned public key is not hex");
|
|
95
|
-
if (sha256Hex(Buffer.from(pins.publicKey, "hex")) !== pins.keyId) refuse("pin", "pinned key id does not match the pinned public key");
|
|
96
|
-
if (signature.keyId !== pins.keyId || payload.keyId !== pins.keyId) refuse("key", "the receipt was not signed by the pinned key");
|
|
97
|
-
const key = keyFromSec1(pins.publicKey);
|
|
98
|
-
if (typeof signature.value !== "string" || !/^[0-9a-fA-F]+$/.test(signature.value)) refuse("signature", "signature is not hex");
|
|
99
|
-
if (signature.value.length !== 128) refuse("signature", "signature is not 64 bytes r||s");
|
|
100
|
-
let good = false;
|
|
101
|
-
try { good = verify("sha256", signedBytes(payload), { key, dsaEncoding: "ieee-p1363" }, Buffer.from(signature.value, "hex")); } catch (error) { if (error instanceof ProvenanceError) throw error; }
|
|
102
|
-
if (!good) refuse("signature", "signature does not verify");
|
|
103
|
-
if (payload.host !== pins.host) refuse("host", "signed for another host");
|
|
104
|
-
if (payload.broker?.brokerDigest !== pins.brokerDigest) refuse("runtime", "signed by another broker runtime");
|
|
105
|
-
if (typeof expected?.jobId !== "string" || payload.jobId !== expected.jobId || receipt.id !== expected.jobId) refuse("job", "the receipt is for another job");
|
|
106
|
-
if (typeof expected.nonce !== "string" || payload.nonce !== expected.nonce) refuse("nonce", "the nonce is not the one this invocation sent");
|
|
107
|
-
if (expected.requestDigest !== undefined && payload.requestDigest !== expected.requestDigest) refuse("request", "the request digest is not the one this invocation computed");
|
|
108
|
-
return payload;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// ---- GB-10 / GB-11 / GB-50: the rest of rustright-protocol attestation.rs `verify_receipt` and `verify_receipt_strict`, case for case ----
|
|
112
|
-
// `verifyProvenance` above is the signature, pins, job, nonce and request-digest half. The functions below are the coverage half: a field the receipt carries
|
|
113
|
-
// and the signature does not cover (or the reverse) is refused like a changed one. `verifyReceiptLenient` = both halves (`verify_receipt`);
|
|
114
|
-
// `verifyReceiptStrict` adds the signed result evidence and the BR19 shape (`verify_receipt_strict`), which a gate applies to every compile receipt. The vector
|
|
115
|
-
// docs/contracts/receipt-vectors.v1.json (test-support/vectors/, pinned) is judged here case for case, lenient and strict.
|
|
116
|
-
export const STAGE_EVIDENCE_FIELDS = Object.freeze(["freshness", "attribution", "toolchain"]);
|
|
117
|
-
export const RESULT_EVIDENCE_FIELDS = Object.freeze(["exit", "signal", "timingsMs", "diagnosticsPath"]);
|
|
118
|
-
export const RESULT_TIMING_FIELDS = Object.freeze(["admission", "queue", "bind", "cargo", "afterExitBind", "diagnostics"]);
|
|
119
|
-
export const BR19_EVIDENCE_FIELDS = Object.freeze(["profile", "stage", "resources", "environment"]);
|
|
120
|
-
export const BR19_RESOURCE_FIELDS = Object.freeze(["grantedJobs", "memoryReservation", "priority"]);
|
|
121
|
-
export const RETIRED_RESULT_FIELDS = Object.freeze(["verdict", "refreshed"]);
|
|
122
|
-
const SNAPSHOT_EVIDENCE_NAMES = Object.freeze(["requestId", "brokerVersion", "executor", "commit", "snapshot", "declaredInputDigests", "ownership", "outputDir"]);
|
|
123
|
-
|
|
124
|
-
const equalValue = (a, b) => (a === undefined || b === undefined ? a === b : canonicalJson(a) === canonicalJson(b));
|
|
125
|
-
const isU64 = (v) => Number.isSafeInteger(v) && v >= 0;
|
|
126
|
-
|
|
127
|
-
function covered(receipt, payload, key, fields, what) {
|
|
128
|
-
const evidence = payload[key];
|
|
129
|
-
if (evidence !== undefined) {
|
|
130
|
-
for (const name of fields) if (!equalValue(receipt[name], isRecord(evidence) ? evidence[name] : undefined)) refuse("evidence", `receipt ${name} differs from signed ${what}`);
|
|
131
|
-
} else {
|
|
132
|
-
const name = fields.find((f) => receipt[f] !== undefined);
|
|
133
|
-
if (name !== undefined) refuse("evidence", `receipt ${name} is not covered by signed ${what}`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/** The coverage half of `verify_receipt`: signed snapshot evidence and nested children equal the receipt's copies; stage, result and BR19 evidence are never one-sided; the retired verdict fields are refused. */
|
|
138
|
-
export function verifyReceiptCoverage(receipt, payload) {
|
|
139
|
-
const snapshotEvidence = payload.snapshotEvidence;
|
|
140
|
-
if (snapshotEvidence !== undefined) {
|
|
141
|
-
for (const name of SNAPSHOT_EVIDENCE_NAMES) if (!isRecord(snapshotEvidence) || snapshotEvidence[name] === undefined || !equalValue(receipt[name], snapshotEvidence[name])) refuse("evidence", `receipt ${name} differs from signed snapshot evidence`);
|
|
142
|
-
if (!equalValue(receipt.nestedChildren, snapshotEvidence.nestedChildren)) refuse("evidence", "receipt nestedChildren differs from signed snapshot evidence");
|
|
143
|
-
}
|
|
144
|
-
covered(receipt, payload, "stageEvidence", STAGE_EVIDENCE_FIELDS, "stage evidence");
|
|
145
|
-
covered(receipt, payload, "resultEvidence", RESULT_EVIDENCE_FIELDS, "result evidence");
|
|
146
|
-
covered(receipt, payload, "br19Evidence", BR19_EVIDENCE_FIELDS, "BR19 evidence");
|
|
147
|
-
const receiptClass = Object.hasOwn(receipt, "failureClass");
|
|
148
|
-
const signedClass = isRecord(payload.result) && Object.hasOwn(payload.result, "failureClass");
|
|
149
|
-
if (receiptClass !== signedClass || (receiptClass && !equalValue(receipt.failureClass, payload.result.failureClass))) refuse("evidence", "receipt failureClass differs from the signed result");
|
|
150
|
-
// RustRight treats a missing postChecks and null as equivalent for older receipts.
|
|
151
|
-
if (!equalValue(receipt.postChecks ?? null, payload.result?.postChecks ?? null)) refuse("evidence", "receipt postChecks differs from the signed result");
|
|
152
|
-
for (const name of RETIRED_RESULT_FIELDS) {
|
|
153
|
-
if (receipt[name] !== undefined || (isRecord(payload.resultEvidence) && payload.resultEvidence[name] !== undefined)) refuse("evidence", `receipt ${name} is a retired verdict-reuse field`);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** `verify_receipt`: the signature half and the coverage half. Returns the signed payload. */
|
|
158
|
-
export function verifyReceiptLenient(receipt, pins, expected) {
|
|
159
|
-
const payload = verifyProvenance(receipt, pins, expected);
|
|
160
|
-
verifyReceiptCoverage(receipt, payload);
|
|
161
|
-
return payload;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/** GB-10 `verify_result_evidence`: the signed payload carries `resultEvidence` with exactly exit, signal, timingsMs, diagnosticsPath (null is a value; a missing or extra key is not), timingsMs exactly the six phases, every receipt copy equal. */
|
|
165
|
-
export function verifyResultEvidence(receipt, payload) {
|
|
166
|
-
const evidence = payload.resultEvidence;
|
|
167
|
-
if (!isRecord(evidence)) refuse("evidence", "the signed payload carries no result evidence");
|
|
168
|
-
const extra = Object.keys(evidence).find((name) => !RESULT_EVIDENCE_FIELDS.includes(name));
|
|
169
|
-
if (extra !== undefined) refuse("evidence", `signed result evidence carries an unknown field ${extra}`);
|
|
170
|
-
for (const name of RESULT_EVIDENCE_FIELDS) {
|
|
171
|
-
if (evidence[name] === undefined) refuse("evidence", `signed result evidence lacks ${name}`);
|
|
172
|
-
if (!equalValue(receipt[name], evidence[name])) refuse("evidence", `receipt ${name} differs from signed result evidence`);
|
|
173
|
-
}
|
|
174
|
-
const timings = evidence.timingsMs;
|
|
175
|
-
if (!isRecord(timings)) refuse("evidence", "signed result evidence timingsMs is not an object");
|
|
176
|
-
if (Object.keys(timings).length !== RESULT_TIMING_FIELDS.length || RESULT_TIMING_FIELDS.some((name) => !(timings[name] === null || isU64(timings[name])))) refuse("evidence", "signed result evidence timingsMs must hold exactly the contract phases as numbers or null");
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const isUnknownValue = (v) => isRecord(v) && Object.keys(v).length === 2 && v.state === "UNKNOWN" && typeof v.reason === "string" && v.reason !== "";
|
|
180
|
-
const nonEmptyString = (v) => typeof v === "string" && v !== "";
|
|
181
|
-
|
|
182
|
-
/** GB-11 `verify_br19_evidence`: signed `br19Evidence` has exactly profile, stage, resources, environment, equal to the receipt's copies, each well formed (a value or `{state:"UNKNOWN",reason}`; never absent, never an invented zero). */
|
|
183
|
-
export function verifyBr19Evidence(receipt, payload) {
|
|
184
|
-
const evidence = payload.br19Evidence;
|
|
185
|
-
if (!isRecord(evidence)) refuse("evidence", "the signed payload carries no BR19 evidence");
|
|
186
|
-
const extra = Object.keys(evidence).find((name) => !BR19_EVIDENCE_FIELDS.includes(name));
|
|
187
|
-
if (extra !== undefined) refuse("evidence", `signed BR19 evidence carries an unknown field ${extra}`);
|
|
188
|
-
for (const name of BR19_EVIDENCE_FIELDS) {
|
|
189
|
-
if (evidence[name] === undefined) refuse("evidence", `signed BR19 evidence lacks ${name}`);
|
|
190
|
-
if (!equalValue(receipt[name], evidence[name])) refuse("evidence", `receipt ${name} differs from signed BR19 evidence`);
|
|
191
|
-
}
|
|
192
|
-
const bad = (what) => refuse("evidence", `signed BR19 evidence ${what}`);
|
|
193
|
-
if (!nonEmptyString(evidence.profile)) bad("profile is not a non-empty string");
|
|
194
|
-
if (!isRecord(evidence.stage) || !nonEmptyString(evidence.stage.name) || !nonEmptyString(evidence.stage.source)) bad("stage needs a name and a source");
|
|
195
|
-
const resources = isRecord(evidence.resources) ? evidence.resources : {};
|
|
196
|
-
for (const name of BR19_RESOURCE_FIELDS) {
|
|
197
|
-
const value = resources[name];
|
|
198
|
-
if (value === undefined) bad(`resources lacks ${name}`);
|
|
199
|
-
const typed = name === "priority" ? nonEmptyString(value) : isU64(value);
|
|
200
|
-
if (!typed && !isUnknownValue(value)) bad(`resources.${name} is neither a value nor UNKNOWN with a reason`);
|
|
201
|
-
}
|
|
202
|
-
const environment = isRecord(evidence.environment) ? evidence.environment : {};
|
|
203
|
-
const names = (key) => Array.isArray(environment[key]) && environment[key].every(nonEmptyString);
|
|
204
|
-
if (!(typeof environment.digest === "string" && /^[0-9a-f]{64}$/.test(environment.digest) && names("forwarded") && names("dropped"))) bad("environment needs a 64-hex digest and forwarded and dropped name lists");
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export const FAILURE_CLASSES = Object.freeze(["admission", "compile", "test", "tool", "cancelled", "timeout", "broker"]);
|
|
208
|
-
/** Validate an optional signed failure class; verifyReceiptCoverage binds the receipt copy. */
|
|
209
|
-
export function verifyFailureClass(receipt, payload) {
|
|
210
|
-
const signed = isRecord(payload.result) && Object.hasOwn(payload.result, "failureClass");
|
|
211
|
-
const copy = Object.hasOwn(receipt, "failureClass");
|
|
212
|
-
if (signed !== copy || (signed && !equalValue(receipt.failureClass, payload.result.failureClass))) refuse("evidence", "receipt failureClass differs from the signed result");
|
|
213
|
-
if (signed && payload.result.failureClass !== null && !FAILURE_CLASSES.includes(payload.result.failureClass)) refuse("evidence", "signed failureClass is neither null nor a recognized class");
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const POST_CHECK_FIELDS = Object.freeze(["schema", "ran", "failed", "inputClosure", "inputBoundary", "verified"]);
|
|
217
|
-
/** Validate signed post-run checks. Snapshot callers additionally require applicable, signed boundary evidence. */
|
|
218
|
-
export function verifyPostChecks(receipt, payload, { snapshotAttested = false } = {}) {
|
|
219
|
-
const checks = payload.result?.postChecks ?? null;
|
|
220
|
-
if (!equalValue(receipt.postChecks ?? null, checks)) refuse("evidence", "receipt postChecks differs from the signed result");
|
|
221
|
-
if (checks === null) return null;
|
|
222
|
-
const bad = () => refuse("evidence", "the signed result's postChecks is malformed");
|
|
223
|
-
if (!isRecord(checks) || Object.keys(checks).length !== POST_CHECK_FIELDS.length || POST_CHECK_FIELDS.some((key) => !Object.hasOwn(checks, key))) bad();
|
|
224
|
-
if (checks.schema !== "rustright.post-checks.v1" || typeof checks.ran !== "boolean" || typeof checks.verified !== "boolean" || !Array.isArray(checks.failed) || !checks.failed.every((name) => ["freshness", "projection", "toolchainIdentity"].includes(name))) bad();
|
|
225
|
-
if (!["verified", "inputs-mutated", "unverified", "not-applicable"].includes(checks.inputClosure) || !["intact", "violated", "unverified", "unrequested", "not-applicable"].includes(checks.inputBoundary)) bad();
|
|
226
|
-
const boundary = payload.inputBoundary?.status;
|
|
227
|
-
if (typeof boundary === "string" && boundary !== checks.inputBoundary) refuse("evidence", "postChecks.inputBoundary differs from the signed inputBoundary");
|
|
228
|
-
if (snapshotAttested && (checks.inputClosure === "not-applicable" || checks.inputBoundary === "not-applicable" || typeof boundary !== "string" || boundary !== checks.inputBoundary)) refuse("evidence", "snapshot postChecks lacks applicable signed input boundary or closure evidence");
|
|
229
|
-
const verified = checks.ran && checks.failed.length === 0 && ["verified", "not-applicable"].includes(checks.inputClosure) && ["intact", "unrequested", "not-applicable"].includes(checks.inputBoundary);
|
|
230
|
-
if (checks.verified !== verified) refuse("evidence", "the signed postChecks.verified does not follow from its checks");
|
|
231
|
-
if (payload.result?.failureClass === "compile" && !(checks.ran && checks.failed.length === 0)) refuse("evidence", "a signed compile failure whose post-run checks did not all run and pass");
|
|
232
|
-
return checks;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/** `verify_receipt_strict`: `verifyReceiptLenient`, then the signed result evidence and the BR19 shape. A gate applies it to every compile receipt, never the lenient form alone. */
|
|
236
|
-
export function verifyReceiptStrict(receipt, pins, expected) {
|
|
237
|
-
const payload = verifyReceiptLenient(receipt, pins, expected);
|
|
238
|
-
verifyResultEvidence(receipt, payload);
|
|
239
|
-
verifyBr19Evidence(receipt, payload);
|
|
240
|
-
verifyFailureClass(receipt, payload);
|
|
241
|
-
verifyPostChecks(receipt, payload);
|
|
242
|
-
return payload;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// ---- RA-03: the cause evidence the broker signs inside `freshness` (rustright-broker cargo_evidence.rs, schema rustright.cause-evidence.v1) ----
|
|
246
|
-
// A census that counts rebuilt units proves nothing about WHY they were rebuilt. The broker therefore signs `freshness.causeEvidence`: a state (complete | incomplete |
|
|
247
|
-
// unavailable), a verdict (explained | unexplained | unknown), the basis the verdict rests on, the typed gaps and the counts. `verifyCauseEvidence` reads it and refuses what
|
|
248
|
-
// is missing, of a schema this gate does not read, or not coherent with itself and with the census fields beside it; `requireExplainedCauses` then refuses every verdict but
|
|
249
|
-
// `explained`. An `unknown` verdict is a typed refusal, never read as zero unexplained units, and a broker that signs no causeEvidence (one that predates the schema) is
|
|
250
|
-
// refused as well: nothing here relaxes for an older installed broker. One implementation serves every caller, so no second copy of the rule can drift.
|
|
251
|
-
export const CAUSE_EVIDENCE_SCHEMA = "rustright.cause-evidence.v1";
|
|
252
|
-
/** The refusal codes of a verdict that is not `explained` (the other cause-evidence refusals are `evidence`, like every malformed signed field). */
|
|
253
|
-
export const CAUSE_UNKNOWN = "cause-unknown";
|
|
254
|
-
export const CAUSE_UNEXPLAINED = "cause-unexplained";
|
|
255
|
-
/** cargo_evidence.rs EXPLAINED_CAUSES (the same 10, in the broker's order): the only causes that explain a rebuilt unit; any other (including `unexplained`, `fingerprint-missing` and one this list does not know) does not. */
|
|
256
|
-
export const EXPLAINED_CAUSES = Object.freeze([
|
|
257
|
-
"first-build", "toolchain-changed", "source-or-dependency-changed", "env-rustflags-profile-features-or-target-changed",
|
|
258
|
-
"generation-change", "authorized-eviction", "new-unit", "new-namespace",
|
|
259
|
-
// A unit missing its recorded fingerprint row while its package has a fingerprint dir under another build (rustright judge step 0, cargo_evidence.rs same_package_other_build).
|
|
260
|
-
"after-failed-build", "fingerprint-changed",
|
|
261
|
-
]);
|
|
262
|
-
const CAUSE_STATES = Object.freeze(["complete", "incomplete", "unavailable"]);
|
|
263
|
-
const CAUSE_VERDICTS = Object.freeze(["explained", "unexplained", "unknown"]);
|
|
264
|
-
const CAUSE_BASES = Object.freeze(["reasons", "census-nothing-rebuilt", "nothing-compiled", "none"]);
|
|
265
|
-
const CAUSE_COUNT_FIELDS = Object.freeze(["rows", "rowsDropped", "units", "unexplained", "uncovered"]);
|
|
266
|
-
const shownValue = (v) => { let text; try { text = JSON.stringify(v); } catch { text = undefined; } return text === undefined ? "absent" : text.slice(0, 80); };
|
|
267
|
-
/** cargo_evidence.rs `counted`: a count in a freshness object is a whole number, or a flag standing for one (`true` is one); anything else is no count. */
|
|
268
|
-
const censusCount = (freshness, name) => { const v = freshness[name]; if (typeof v === "boolean") return v ? 1 : 0; return isU64(v) ? v : null; };
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Reads `freshness.causeEvidence` of a compile's signed (compact) freshness and returns `{ schema, state, verdict, basis, unavailable, gaps, counts, unexplainedUnits,
|
|
272
|
-
* unexplainedUnitsTruncated, unexplainedCount }`. Refuses (ProvenanceError `evidence`) when it is absent or null, not an object, of any schema but
|
|
273
|
-
* rustright.cause-evidence.v1, or when any field is missing or mistyped; when its state, verdict, basis, gaps and counts do not agree with one another
|
|
274
|
-
* (a verdict of `explained` needs no unexplained unit and no gap; `unknown` is the verdict of unexplained == 0 with a gap; the unit lists and their truncation counts add up
|
|
275
|
-
* to the counts; truncated reasons and uncovered units are named as gaps); when a basis that read no reasons carries counts, or claims a census the freshness fields
|
|
276
|
-
* do not show (`census-nothing-rebuilt` needs `available: true` and `notFresh: 0`; `nothing-compiled` needs `available: false` with that reason); when the sibling
|
|
277
|
-
* `unexplainedCount` is not the projection (`null` exactly when the verdict is unknown, else the unexplained count); and, for a basis of `reasons`, when `causeCounts`
|
|
278
|
-
* is missing or disagrees with the counts. It judges nothing: see `requireExplainedCauses`.
|
|
279
|
-
*/
|
|
280
|
-
export function verifyCauseEvidence(freshness) {
|
|
281
|
-
if (!isRecord(freshness)) refuse("evidence", "the receipt carries no freshness object to read cause evidence from");
|
|
282
|
-
const cause = freshness.causeEvidence;
|
|
283
|
-
if (cause === undefined || cause === null) refuse("evidence", `freshness carries no causeEvidence: the broker did not say why its units were rebuilt, so nothing is concluded from it (a broker that does not sign ${CAUSE_EVIDENCE_SCHEMA} is refused, never trusted as if it had)`);
|
|
284
|
-
const bad = (what) => refuse("evidence", `freshness causeEvidence ${what}`);
|
|
285
|
-
if (!isRecord(cause)) bad("is not an object");
|
|
286
|
-
if (cause.schema !== CAUSE_EVIDENCE_SCHEMA) bad(`names the schema ${shownValue(cause.schema)}, which this gate does not read (it reads ${CAUSE_EVIDENCE_SCHEMA} only)`);
|
|
287
|
-
const { state, verdict, basis, unavailable, gaps, counts } = cause;
|
|
288
|
-
if (!CAUSE_STATES.includes(state)) bad(`has the unknown state ${shownValue(state)}`);
|
|
289
|
-
if (!CAUSE_VERDICTS.includes(verdict)) bad(`has the unknown verdict ${shownValue(verdict)}`);
|
|
290
|
-
if (!CAUSE_BASES.includes(basis)) bad(`has the unknown basis ${shownValue(basis)}`);
|
|
291
|
-
if (typeof cause.historyMigrationNeeded !== "boolean") bad("does not say whether the history needs migration");
|
|
292
|
-
if (!(unavailable === null || nonEmptyString(unavailable))) bad("unavailable is neither null nor a reason");
|
|
293
|
-
if (!Array.isArray(gaps) || !gaps.every(nonEmptyString)) bad("gaps is not a list of reasons");
|
|
294
|
-
if (!isRecord(counts) || CAUSE_COUNT_FIELDS.some((name) => !isU64(counts[name]))) bad(`counts needs ${CAUSE_COUNT_FIELDS.join(", ")} as whole numbers`);
|
|
295
|
-
for (const [list, truncated, total] of [["unexplainedUnits", "unexplainedUnitsTruncated", counts.unexplained], ["uncoveredUnits", "uncoveredUnitsTruncated", counts.uncovered]]) {
|
|
296
|
-
if (!Array.isArray(cause[list]) || !cause[list].every((label) => typeof label === "string") || !isU64(cause[truncated])) bad(`${list} and ${truncated} are not a list of labels and a count`);
|
|
297
|
-
if (cause[list].length + cause[truncated] !== total) bad(`${list} (${cause[list].length}) and ${truncated} (${cause[truncated]}) do not add up to counts (${total})`);
|
|
298
|
-
}
|
|
299
|
-
const hasGap = (name) => gaps.includes(name);
|
|
300
|
-
const unexplained = counts.unexplained;
|
|
301
|
-
if (basis === "reasons") {
|
|
302
|
-
if (unavailable !== null) bad("names an unavailability reason although its reasons were read");
|
|
303
|
-
if (state !== (gaps.length === 0 ? "complete" : "incomplete")) bad(`state ${state} disagrees with its gaps (${gaps.length})`);
|
|
304
|
-
const expected = unexplained > 0 ? "unexplained" : gaps.length > 0 ? "unknown" : "explained";
|
|
305
|
-
if (verdict !== expected) bad(`verdict ${verdict} disagrees with its ${unexplained} unexplained unit(s) and ${gaps.length} gap(s) (${expected})`);
|
|
306
|
-
if (unexplained > counts.units || counts.units > counts.rows) bad("counts are not nested (unexplained <= units <= rows)");
|
|
307
|
-
if ((counts.rowsDropped > 0) !== hasGap("reasons-truncated")) bad("rowsDropped and the reasons-truncated gap disagree");
|
|
308
|
-
if ((counts.uncovered > 0) !== hasGap("rebuilt-unit-without-reason")) bad("uncovered and the rebuilt-unit-without-reason gap disagree");
|
|
309
|
-
} else {
|
|
310
|
-
if (state !== "unavailable") bad(`state ${state} is not unavailable although no reasons were read (basis ${basis})`);
|
|
311
|
-
if (!nonEmptyString(unavailable)) bad("states no reason why its reasons were not read");
|
|
312
|
-
if (CAUSE_COUNT_FIELDS.some((name) => counts[name] !== 0)) bad(`counts reasons that were never read (basis ${basis})`);
|
|
313
|
-
if (basis === "none") {
|
|
314
|
-
if (verdict !== "unknown" || !hasGap("log-not-read")) bad("basis none is the typed unknown: verdict unknown with the log-not-read gap");
|
|
315
|
-
} else {
|
|
316
|
-
if (verdict !== "explained" || gaps.length !== 0) bad(`basis ${basis} is an explained verdict with no gap`);
|
|
317
|
-
if (basis === "nothing-compiled" && !(freshness.available === false && freshness.reason === "nothing-compiled")) bad("claims nothing was compiled but the census does not say so");
|
|
318
|
-
if (basis === "census-nothing-rebuilt" && !(freshness.available === true && censusCount(freshness, "notFresh") === 0 && (censusCount(freshness, "parseErrors") ?? 0) === 0 && (censusCount(freshness, "notFreshPackagesTruncated") ?? 0) === 0)) bad("claims the census rebuilt nothing but the census does not prove it (available, notFresh 0, no parse errors, no truncated list)");
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
const projected = verdict === "unknown" ? null : unexplained;
|
|
322
|
-
if (freshness.unexplainedCount !== projected) refuse("evidence", `freshness unexplainedCount (${shownValue(freshness.unexplainedCount)}) is not the projection of causeEvidence (${projected === null ? "null, because the verdict is unknown" : projected})`);
|
|
323
|
-
if (basis === "reasons") {
|
|
324
|
-
const causes = freshness.causeCounts;
|
|
325
|
-
if (!isRecord(causes) || !Object.values(causes).every(isU64)) refuse("evidence", "freshness causeCounts is missing or not a count per cause although causeEvidence read reasons");
|
|
326
|
-
let total = 0; let unexplainedRows = 0;
|
|
327
|
-
for (const [name, n] of Object.entries(causes)) { total += n; if (!EXPLAINED_CAUSES.includes(name)) unexplainedRows += n; }
|
|
328
|
-
if (total !== counts.rows) refuse("evidence", `freshness causeCounts add up to ${total} reason(s), not causeEvidence counts.rows (${counts.rows})`);
|
|
329
|
-
if ((unexplainedRows > 0) !== (unexplained > 0) || unexplained > unexplainedRows) refuse("evidence", `freshness causeCounts name ${unexplainedRows} row(s) without an explained cause, which cannot give ${unexplained} unexplained unit(s)`);
|
|
330
|
-
}
|
|
331
|
-
return {
|
|
332
|
-
schema: cause.schema, state, verdict, basis, unavailable, gaps: [...gaps], counts: { ...counts },
|
|
333
|
-
unexplainedUnits: [...cause.unexplainedUnits], unexplainedUnitsTruncated: cause.unexplainedUnitsTruncated, unexplainedCount: projected,
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* The gate's warm judgment over a compile's signed freshness: `verifyCauseEvidence`, then a refusal for every verdict but `explained`. `unknown` (a quiet, caller-logged
|
|
339
|
-
* or artifact-running root whose log was not read, dropped output, an unattributable or uncovered unit) is refused as `cause-unknown`; `unexplained` (a unit
|
|
340
|
-
* rebuilt with no explained cause) as `cause-unexplained`, naming the units the receipt kept. Returns the verified evidence only when the verdict is `explained`.
|
|
341
|
-
*/
|
|
342
|
-
export function requireExplainedCauses(freshness) {
|
|
343
|
-
const cause = verifyCauseEvidence(freshness);
|
|
344
|
-
if (cause.verdict === "unknown") {
|
|
345
|
-
const why = cause.unavailable ?? cause.gaps[0] ?? "unknown";
|
|
346
|
-
refuse(CAUSE_UNKNOWN, `the broker could not say why its rebuilt units were rebuilt (${why}${cause.gaps.length > 0 ? `; gaps: ${cause.gaps.join(", ")}` : ""}): cause evidence is mandatory for a compile, and an unknown cause is never read as no unexplained unit, so the call is unverified`);
|
|
347
|
-
}
|
|
348
|
-
if (cause.verdict === "unexplained") {
|
|
349
|
-
const named = cause.unexplainedUnits.slice(0, 5).map((label) => label.slice(0, 120)).join("; ");
|
|
350
|
-
refuse(CAUSE_UNEXPLAINED, `${cause.counts.unexplained} rebuilt unit(s) have no explained cause (${named}${cause.counts.unexplained > 5 || cause.unexplainedUnitsTruncated > 0 ? "; more not listed" : ""}): a rebuild the broker cannot explain is not a success`);
|
|
351
|
-
}
|
|
352
|
-
return cause;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// ---- GB-50: the full attribution a Clippy (or check) route needs, read from the signed detail descriptor, never from the compact counts ----
|
|
356
|
-
export const STAGE_EVIDENCE_SCHEMA = "rustright.stage-evidence/1";
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* `rustright_protocol::attestation::verify_attribution_detail(receipt, file_bytes)`, case for case (vector attribution-detail-vectors.v1.json). `receipt` is a
|
|
360
|
-
* receipt `verifyReceiptStrict` already accepted (so its compact `attribution`, `toolchain` and the descriptor's sha256 are signed) and `bytes` the evidence file the
|
|
361
|
-
* descriptor names. Checks in order: the descriptor is present and `bytes` hash to its sha256 (`detail`); the schema is rustright.stage-evidence/1 (`schema`); the
|
|
362
|
-
* file's `id` is this receipt's request (`job`) and its `toolchain` the receipt's (`evidence`); its attribution is available, `truncated` is exactly 0 in the file and in
|
|
363
|
-
* the compact twin (`truncated`); every row names package, target and kind with numeric errors and warnings; the compact `units`, `packages`, `errors`, `warnings`,
|
|
364
|
-
* `otherMessages` and `freshUnits` equal the values recomputed from the rows. Returns `{ rows, failedUnits }`. Counts alone never pass.
|
|
365
|
-
*/
|
|
366
|
-
export function verifyAttributionDetail(receipt, bytes) {
|
|
367
|
-
const compact = receipt?.attribution;
|
|
368
|
-
if (!isRecord(compact)) refuse("evidence", "the receipt carries no attribution");
|
|
369
|
-
const descriptor = compact.detail;
|
|
370
|
-
if (!isRecord(descriptor) || typeof descriptor.sha256 !== "string" || typeof descriptor.path !== "string") refuse("detail", "the attribution names no evidence file");
|
|
371
|
-
if (sha256Hex(bytes) !== descriptor.sha256) refuse("detail", "the evidence file is not the one the receipt signed");
|
|
372
|
-
let document;
|
|
373
|
-
try { document = JSON.parse(Buffer.from(bytes).toString("utf8")); } catch { refuse("malformed", "the evidence file is not JSON"); }
|
|
374
|
-
if (!isRecord(document) || document.schema !== STAGE_EVIDENCE_SCHEMA) refuse("schema", "unknown stage evidence schema");
|
|
375
|
-
if (typeof document.id !== "string" || document.id !== receipt.id) refuse("job", "the evidence file is for another request");
|
|
376
|
-
if (typeof document.toolchain !== "string" || document.toolchain !== receipt.toolchain) refuse("evidence", "the evidence file names another toolchain than the receipt");
|
|
377
|
-
const attribution = document.attribution;
|
|
378
|
-
if (!isRecord(attribution) || attribution.available !== true) refuse("evidence", "the evidence file holds no available attribution");
|
|
379
|
-
if (!isU64(attribution.truncated)) refuse("evidence", "the evidence file does not say whether the attribution is complete");
|
|
380
|
-
if (attribution.truncated !== 0 || compact.truncated !== 0) refuse("truncated", "the attribution is truncated or its completeness is not stated");
|
|
381
|
-
const rows = attribution.units;
|
|
382
|
-
if (!Array.isArray(rows)) refuse("evidence", "the evidence file holds no unit rows");
|
|
383
|
-
const packages = new Set(); let errors = 0; let warnings = 0; let other = 0; let fresh = 0; let failedUnits = 0;
|
|
384
|
-
for (const row of rows) {
|
|
385
|
-
const text = (name) => (isRecord(row) && typeof row[name] === "string" && row[name] !== "" ? row[name] : null);
|
|
386
|
-
const count = (name) => (isRecord(row) && isU64(row[name]) ? row[name] : null);
|
|
387
|
-
const [pkg, target, kind, e, w] = [text("package"), text("target"), text("kind"), count("errors"), count("warnings")];
|
|
388
|
-
if (pkg === null || target === null || kind === null || e === null || w === null) refuse("evidence", "a unit row lacks its package, target, kind, errors or warnings");
|
|
389
|
-
packages.add(pkg); errors += e; warnings += w; other += count("otherMessages") ?? 0; fresh += row.fresh === true ? 1 : 0; failedUnits += e > 0 ? 1 : 0;
|
|
390
|
-
}
|
|
391
|
-
const derived = { units: rows.length, packages: packages.size, errors, warnings, otherMessages: other, freshUnits: fresh };
|
|
392
|
-
for (const [name, value] of Object.entries(derived)) if (compact[name] !== value) refuse("evidence", `the receipt's compact attribution ${name} disagrees with the evidence file's rows`);
|
|
393
|
-
return { rows, failedUnits };
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/** The stage nonce a unit gate run sets (RIGHTKIT_ATTEST_STAGE_NONCE) for the broker jobs of one stage; the hosted admission recomputes it from
|
|
397
|
-
* what it knows of the dispatched commit, so a receipt of another commit, tree, unit or stage cannot match. 64 lowercase hex. */
|
|
398
|
-
export function qualificationNonce({ commit, tree, unit, stage }) {
|
|
399
|
-
return sha256Hex(`${QUALIFICATION_NONCE_DOMAIN}\n${commit}\n${tree}\n${unit}\n${stage}`);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
/** The nonce of one carried cargo call of a stage (rightkit#1301 B8): derived from the stage nonce, the directory of the repository the call
|
|
403
|
-
* runs in (`.` or `crates/x`, posix, relative) and the argv it sends (the locked words, no `cargo`), so a call's receipt binds the stage,
|
|
404
|
-
* the directory and the command, and a stage nonce is never itself a carrier nonce. 64 lowercase hex. The gate derives it per call
|
|
405
|
-
* (snapshot-broker.mjs carryBrokerCargo) and the hosted admission recomputes it from each stage row. */
|
|
406
|
-
export function carriedCallNonce({ stageNonce, cwd, argv }) {
|
|
407
|
-
return sha256Hex(`${CARRIED_CALL_NONCE_DOMAIN}\n${stageNonce}\n${cwd}\n${canonicalJson([...argv])}`);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/** Broker request ids the client prints (`rustright: request <id>`) in one command's output. */
|
|
411
|
-
export function brokerRequestIds(text) {
|
|
412
|
-
return [...String(text ?? "").matchAll(/^rustright: request ([0-9a-f-]{36})/gm)].map((m) => m[1]);
|
|
413
|
-
}
|