@tinfoilsh/verifier 2.0.0-rc.4 → 2.0.0-rc.6
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 +48 -10
- package/dist/document/collateral/collateral.d.ts +2 -0
- package/dist/document/collateral/collateral.d.ts.map +1 -1
- package/dist/document/collateral/collateral.js +8 -1
- package/dist/document/collateral/collateral.js.map +1 -1
- package/dist/document/collateral/container.js +16 -0
- package/dist/document/collateral/container.js.map +1 -0
- package/dist/document/collateral/sigstore.d.ts +2 -0
- package/dist/document/collateral/sigstore.d.ts.map +1 -1
- package/dist/document/collateral/sigstore.js +1 -1
- package/dist/document/collateral/sigstore.js.map +1 -1
- package/dist/document/document.d.ts +6 -0
- package/dist/document/document.d.ts.map +1 -1
- package/dist/document/document.js +13 -0
- package/dist/document/document.js.map +1 -1
- package/dist/errors.d.ts +16 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +11 -9
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/internal/endorsement/approval.js +1 -2
- package/dist/internal/endorsement/approval.js.map +1 -1
- package/dist/internal/endorsement/container.js +73 -0
- package/dist/internal/endorsement/container.js.map +1 -0
- package/dist/internal/quote/config.js +17 -4
- package/dist/internal/quote/config.js.map +1 -1
- package/dist/internal/quote/legacy.js +12 -11
- package/dist/internal/quote/legacy.js.map +1 -1
- package/dist/internal/quote/quote.js +56 -4
- package/dist/internal/quote/quote.js.map +1 -1
- package/dist/internal/runtime/config.js +11 -33
- package/dist/internal/runtime/config.js.map +1 -1
- package/dist/internal/runtime/provenance.js +52 -0
- package/dist/internal/runtime/provenance.js.map +1 -0
- package/dist/internal/sigstore/certificate.js +5 -4
- package/dist/internal/sigstore/certificate.js.map +1 -1
- package/dist/report.d.ts +203 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +244 -0
- package/dist/report.js.map +1 -0
- package/dist/verification.d.ts +100 -36
- package/dist/verification.d.ts.map +1 -1
- package/dist/verification.js +91 -37
- package/dist/verification.js.map +1 -1
- package/dist/verifier.d.ts +130 -67
- package/dist/verifier.d.ts.map +1 -1
- package/dist/verifier.js +300 -140
- package/dist/verifier.js.map +1 -1
- package/dist/version.js +2 -2
- package/dist/version.js.map +1 -1
- package/package.json +2 -3
package/dist/verifier.js
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _Verifier_instances, _Verifier_policy, _Verifier_prov, _Verifier_configVerifier, _Verifier_freshnessVerifier, _Verifier_roots, _Verifier_requirePin, _Verifier_requiresConfigCollateral, _Verifier_codeReferences, _Verifier_witnessedAt, _Verifier_referencePins, _Verifier_configReferences, _Verifier_resolveConfig, _Verifier_resolveRuntime, _Verifier_resolvePlatform, _Verifier_approvedAt;
|
|
12
|
+
var _Verifier_instances, _Verifier_policy, _Verifier_prov, _Verifier_configVerifier, _Verifier_freshnessVerifier, _Verifier_roots, _Verifier_verify, _Verifier_requirePin, _Verifier_requiresConfigCollateral, _Verifier_codeReferences, _Verifier_witnessedAt, _Verifier_referencePins, _Verifier_configReferences, _Verifier_resolveConfig, _Verifier_authenticateContainers, _Verifier_resolveRuntime, _Verifier_resolvePlatform, _Verifier_approvedAt;
|
|
13
13
|
/**
|
|
14
14
|
* The v3 verifier: parses and binds a document, authenticates its reference
|
|
15
15
|
* values, authenticates the CPU quote, assembles the expected state and
|
|
@@ -22,7 +22,8 @@ import { InvalidInputError, parse as parseDocument } from "./document/document.j
|
|
|
22
22
|
import { UsageError, VerificationError, VerifyError } from "./errors.js";
|
|
23
23
|
import { sha256, toHex, utf8 } from "./internal/bytes.js";
|
|
24
24
|
import { decodeLowerHex } from "./internal/canonical.js";
|
|
25
|
-
import { ConfigVerifier, FreshnessVerifier, KIND_PLATFORM, KIND_RUNTIME,
|
|
25
|
+
import { ConfigVerifier, FreshnessVerifier, KIND_PLATFORM, KIND_RUNTIME, parseConfigName, PLATFORM_ARTIFACT_NAME, PUBLIC_REGISTRY_ID, publicSigningKeys, validateConfigPins, validateRegistryIDs, } from "./internal/endorsement/approval.js";
|
|
26
|
+
import { authenticateContainers } from "./internal/endorsement/container.js";
|
|
26
27
|
import { authenticateFreshness, MAX_FRESHNESS_AGE_MS } from "./internal/endorsement/freshness.js";
|
|
27
28
|
import { ProvenanceClient } from "./internal/endorsement/provenance.js";
|
|
28
29
|
import { parseReference } from "./internal/endorsement/reference.js";
|
|
@@ -30,12 +31,13 @@ import { authenticateRuntime } from "./internal/endorsement/runtime.js";
|
|
|
30
31
|
import { strictParse } from "./internal/json/index.js";
|
|
31
32
|
import { ARTIFACT_FORMAT, ARTIFACT_FORMAT_V2, parse as parseArtifact } from "./internal/policy/artifact.js";
|
|
32
33
|
import * as quote from "./internal/quote/quote.js";
|
|
33
|
-
import { configRuntime } from "./internal/runtime/config.js";
|
|
34
|
+
import { configRuntime, MAX_CONFIG_SIZE } from "./internal/runtime/config.js";
|
|
34
35
|
import { decodeManifest, parseManifest } from "./internal/runtime/manifest.js";
|
|
35
36
|
import * as semver from "./internal/semver.js";
|
|
36
37
|
import { pinnedKeys } from "./internal/sigstore/keyed.js";
|
|
37
38
|
import { cloneExpected, REGISTER_SIZE } from "./measurement.js";
|
|
38
|
-
import {
|
|
39
|
+
import { measuredKeys, ReportBuilder } from "./report.js";
|
|
40
|
+
import { verifiedFactsOf } from "./verification.js";
|
|
39
41
|
/** Only this module holds the token the constructor requires, so untyped code that calls it is refused. */
|
|
40
42
|
const BUILT_HERE = Symbol("Verifier");
|
|
41
43
|
/** Calls the private constructor; the class assigns it, as the only place the constructor can be called. */
|
|
@@ -63,17 +65,20 @@ export class Verifier {
|
|
|
63
65
|
__classPrivateFieldSet(this, _Verifier_roots, parts.roots, "f");
|
|
64
66
|
this.freshnessMaxAgeMs = parts.policy.freshnessMaxAgeMs;
|
|
65
67
|
this.pinnedRegisters = parts.policy.pinnedRegisters === undefined ? undefined : Object.freeze(cloneExpected(parts.policy.pinnedRegisters));
|
|
66
|
-
this.callerAuthorizesConfig = parts.policy.embedded.configReference !== undefined || parts.policy.configAuthorizer !== undefined;
|
|
67
68
|
// The properties describe the policy the verifier enforces, so neither can be changed after it is built.
|
|
68
69
|
Object.freeze(this);
|
|
69
70
|
}
|
|
70
71
|
/**
|
|
71
|
-
* Builds a verifier
|
|
72
|
-
* Tinfoil's public
|
|
73
|
-
*
|
|
72
|
+
* Builds a verifier that trusts configs as `config` selects and applies
|
|
73
|
+
* `policy`. Undefined `config` selects Tinfoil's public registry, and an
|
|
74
|
+
* undefined or empty `policy` keeps every default: the embedded production
|
|
75
|
+
* trust roots, Tinfoil's public artifact signing keys and a seven-day
|
|
76
|
+
* freshness bound. Both are copied, so later changes by the caller have no
|
|
77
|
+
* effect. Throws UsageError for an invalid field, an unknown `kind` among
|
|
78
|
+
* them.
|
|
74
79
|
*/
|
|
75
|
-
static async create(
|
|
76
|
-
return buildVerifier(
|
|
80
|
+
static async create(config, policy) {
|
|
81
|
+
return buildVerifier(config, policy, {});
|
|
77
82
|
}
|
|
78
83
|
/**
|
|
79
84
|
* Throws UsageError, without a document or network I/O, for a pin that
|
|
@@ -96,13 +101,23 @@ export class Verifier {
|
|
|
96
101
|
/**
|
|
97
102
|
* Appraises a nonce-bound v3 document against `pin` at the current time.
|
|
98
103
|
* The document's collateral decides which part of `pin` applies.
|
|
104
|
+
*
|
|
105
|
+
* A document that it accepts resolves to a {@link VerificationReport}
|
|
106
|
+
* whose `verifiedFacts` hold what the document proved; the caller must
|
|
107
|
+
* bind its traffic to the keys in them and enforce their
|
|
108
|
+
* `freshnessExpiresAt`. A document that it rejects rejects with a
|
|
109
|
+
* {@link VerificationError} whose `report` shows the step that failed and
|
|
110
|
+
* what the steps before it established. A {@link UsageError} carries no
|
|
111
|
+
* report, because it reports a mistake in the caller's code rather than a
|
|
112
|
+
* rejected document.
|
|
99
113
|
*/
|
|
100
114
|
async verifyV3(docBytes, nonce, pin) {
|
|
101
115
|
return this.verifyV3At(docBytes, nonce, pin, new Date());
|
|
102
116
|
}
|
|
103
117
|
/**
|
|
104
118
|
* Like {@link verifyV3}, but `verificationTime` replaces the clock in every
|
|
105
|
-
* time-bound check (freshness, vendor certificate and CRL validity)
|
|
119
|
+
* time-bound check (freshness, vendor certificate and CRL validity), and
|
|
120
|
+
* the report's `metadata.verifiedAt` reports it.
|
|
106
121
|
*/
|
|
107
122
|
async verifyV3At(docBytes, nonce, pin, verificationTime) {
|
|
108
123
|
if (!(verificationTime instanceof Date) || !Number.isFinite(verificationTime.getTime())) {
|
|
@@ -115,51 +130,108 @@ export class Verifier {
|
|
|
115
130
|
usage(() => parseReference(repo));
|
|
116
131
|
__classPrivateFieldGet(this, _Verifier_instances, "m", _Verifier_referencePins).call(this, project);
|
|
117
132
|
const now = new Date(verificationTime.getTime());
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
133
|
+
const metadata = { verifier: { name: VERIFIER_NAME, version: VERIFIER_VERSION }, verifiedAt: now };
|
|
134
|
+
const steps = new ReportBuilder();
|
|
135
|
+
let verified;
|
|
136
|
+
try {
|
|
137
|
+
verified = await __classPrivateFieldGet(this, _Verifier_instances, "m", _Verifier_verify).call(this, docBytes, nonce, repo, project, now, steps);
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
// A usage error passes through without a report; a step's rejection
|
|
141
|
+
// becomes a VerificationError at its layer that carries the report.
|
|
142
|
+
if (!(err instanceof StepFailure))
|
|
125
143
|
throw err;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (project === "" && repo !== "") {
|
|
132
|
-
throw new Error("document carries config registry collateral, but only a GitHub repository is pinned");
|
|
133
|
-
}
|
|
134
|
-
return __classPrivateFieldGet(this, _Verifier_instances, "m", _Verifier_configReferences).call(this, doc, project, now);
|
|
135
|
-
case FORMAT_V2:
|
|
136
|
-
if (repo === "" && project !== "" && !__classPrivateFieldGet(this, _Verifier_instances, "m", _Verifier_requiresConfigCollateral).call(this)) {
|
|
137
|
-
throw new Error("document carries GitHub repository collateral, but only a registry project is pinned");
|
|
138
|
-
}
|
|
139
|
-
return __classPrivateFieldGet(this, _Verifier_instances, "m", _Verifier_codeReferences).call(this, doc, repo, now);
|
|
140
|
-
default:
|
|
141
|
-
throw new Error(`unsupported collateral format ${JSON.stringify(doc.collateralFormat())}`);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
const authenticated = await at("quote", () => quote.authenticate(doc.cpuEvidence(), doc.cpuEndorsements(), now, { dangerousTestOnlyRoots: __classPrivateFieldGet(this, _Verifier_roots, "f") }));
|
|
145
|
-
const assembled = await at("policy", () => quote.assemble(doc, refs.quote, __classPrivateFieldGet(this, _Verifier_policy, "f").pinnedRegisters, authenticated));
|
|
146
|
-
await at("policy", () => quote.validate(assembled));
|
|
147
|
-
return verificationOf({
|
|
148
|
-
configRepo: refs.artifact.repo,
|
|
149
|
-
codeDigest: refs.artifact.digest,
|
|
150
|
-
codeTag: refs.artifact.tag,
|
|
151
|
-
codeMeasurement: assembled.codeMeasurement,
|
|
152
|
-
enclaveMeasurement: authenticated.measurement,
|
|
153
|
-
cryptoMaterial: doc.cryptoMaterialItems(),
|
|
154
|
-
config: refs.config,
|
|
155
|
-
runtime: refs.config === undefined ? undefined : refs.artifact,
|
|
156
|
-
platform: refs.platform,
|
|
157
|
-
freshnessExpiresAt: new Date(Math.min(refs.freshnessExpiresAt?.getTime() ?? Infinity, authenticated.expiresAt.getTime())),
|
|
158
|
-
metadata: { verifier: { name: VERIFIER_NAME, version: VERIFIER_VERSION }, verifiedAt: now },
|
|
159
|
-
});
|
|
144
|
+
// The step names its layer, so its message is the failing check's own, without the error's prefix.
|
|
145
|
+
const report = steps.failed(err.layer, err.message, metadata);
|
|
146
|
+
throw new VerificationError(err.message, { layer: err.layer, report, cause: err.cause });
|
|
147
|
+
}
|
|
148
|
+
return steps.passedAll(verified, metadata);
|
|
160
149
|
}
|
|
161
150
|
}
|
|
162
|
-
_Verifier_policy = new WeakMap(), _Verifier_prov = new WeakMap(), _Verifier_configVerifier = new WeakMap(), _Verifier_freshnessVerifier = new WeakMap(), _Verifier_roots = new WeakMap(), _Verifier_instances = new WeakSet(),
|
|
151
|
+
_Verifier_policy = new WeakMap(), _Verifier_prov = new WeakMap(), _Verifier_configVerifier = new WeakMap(), _Verifier_freshnessVerifier = new WeakMap(), _Verifier_roots = new WeakMap(), _Verifier_instances = new WeakSet(), _Verifier_verify =
|
|
152
|
+
/**
|
|
153
|
+
* The verification itself: it records in `steps` each step that passes,
|
|
154
|
+
* and the facts that the step establishes, from the values that the step
|
|
155
|
+
* already computes. A rejection is a {@link StepFailure}.
|
|
156
|
+
*/
|
|
157
|
+
async function _Verifier_verify(docBytes, nonce, repo, project, now, steps) {
|
|
158
|
+
const { doc, measured } = await at("envelope", async () => {
|
|
159
|
+
let parsed;
|
|
160
|
+
try {
|
|
161
|
+
parsed = await parseDocument(docBytes, nonce);
|
|
162
|
+
}
|
|
163
|
+
catch (err) {
|
|
164
|
+
if (err instanceof InvalidInputError)
|
|
165
|
+
throw new UsageError(err.message, { cause: err });
|
|
166
|
+
throw err;
|
|
167
|
+
}
|
|
168
|
+
return { doc: parsed, measured: await measuredKeys(parsed.cryptoMaterialItems()) };
|
|
169
|
+
});
|
|
170
|
+
steps.passed("envelope");
|
|
171
|
+
steps.measured = measured;
|
|
172
|
+
const refs = await at("provenance", async () => {
|
|
173
|
+
switch (doc.collateralFormat()) {
|
|
174
|
+
case FORMAT_V3:
|
|
175
|
+
if (project === "" && repo !== "") {
|
|
176
|
+
throw new Error("document carries config registry collateral, but only a GitHub repository is pinned");
|
|
177
|
+
}
|
|
178
|
+
return __classPrivateFieldGet(this, _Verifier_instances, "m", _Verifier_configReferences).call(this, doc, project, now);
|
|
179
|
+
case FORMAT_V2:
|
|
180
|
+
if (repo === "" && project !== "" && !__classPrivateFieldGet(this, _Verifier_instances, "m", _Verifier_requiresConfigCollateral).call(this)) {
|
|
181
|
+
throw new Error("document carries GitHub repository collateral, but only a registry project is pinned");
|
|
182
|
+
}
|
|
183
|
+
return __classPrivateFieldGet(this, _Verifier_instances, "m", _Verifier_codeReferences).call(this, doc, repo, now);
|
|
184
|
+
default:
|
|
185
|
+
throw new Error(`unsupported collateral format ${JSON.stringify(doc.collateralFormat())}`);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
if (embedded(refs)) {
|
|
189
|
+
steps.set("provenance", "skipped", "the verifier embeds every reference value, so there is no endorsement to authenticate");
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
steps.passed("provenance");
|
|
193
|
+
}
|
|
194
|
+
steps.expected = {
|
|
195
|
+
configRepo: refs.artifact.repo,
|
|
196
|
+
artifact: refs.artifact,
|
|
197
|
+
...(refs.config === undefined ? {} : { config: refs.config }),
|
|
198
|
+
...(refs.platform === undefined ? {} : { platform: refs.platform }),
|
|
199
|
+
};
|
|
200
|
+
const code = quote.codeMeasurement(refs.quote, doc.cpuEvidence().format);
|
|
201
|
+
if (code !== undefined)
|
|
202
|
+
steps.expected.codeMeasurement = code;
|
|
203
|
+
const authenticated = await at("quote", () => quote.authenticate(doc.cpuEvidence(), doc.cpuEndorsements(), now, { dangerousTestOnlyRoots: __classPrivateFieldGet(this, _Verifier_roots, "f") }));
|
|
204
|
+
steps.passed("quote");
|
|
205
|
+
steps.measured.cpu = { measurement: authenticated.measurement };
|
|
206
|
+
const expected = steps.expected;
|
|
207
|
+
const assembled = await at("policy", async () => {
|
|
208
|
+
try {
|
|
209
|
+
return await quote.assemble(doc, refs.quote, __classPrivateFieldGet(this, _Verifier_policy, "f").pinnedRegisters, authenticated);
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
// The registers were resolved before the failure, so the report shows them.
|
|
213
|
+
if (!(err instanceof quote.ResolvedError))
|
|
214
|
+
throw err;
|
|
215
|
+
expected.measurement = err.expected;
|
|
216
|
+
throw err.cause;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
expected.measurement = assembled.expected;
|
|
220
|
+
await at("policy", () => quote.validate(assembled));
|
|
221
|
+
steps.passed("policy");
|
|
222
|
+
return verifiedFactsOf({
|
|
223
|
+
configRepo: refs.artifact.repo,
|
|
224
|
+
codeDigest: refs.artifact.digest,
|
|
225
|
+
codeTag: refs.artifact.tag,
|
|
226
|
+
codeMeasurement: assembled.codeMeasurement,
|
|
227
|
+
enclaveMeasurement: authenticated.measurement,
|
|
228
|
+
cryptoMaterial: doc.cryptoMaterialItems(),
|
|
229
|
+
config: refs.config,
|
|
230
|
+
runtime: refs.config === undefined ? undefined : refs.artifact,
|
|
231
|
+
platform: refs.platform,
|
|
232
|
+
freshnessExpiresAt: new Date(Math.min(refs.freshnessExpiresAt?.getTime() ?? Infinity, authenticated.expiresAt.getTime())),
|
|
233
|
+
});
|
|
234
|
+
}, _Verifier_requirePin = function _Verifier_requirePin(repo, project) {
|
|
163
235
|
const p = __classPrivateFieldGet(this, _Verifier_policy, "f");
|
|
164
236
|
if (repo !== "" || project !== "" || p.embedded.configReference !== undefined || p.configAuthorizer !== undefined || p.configKeysPinned || p.configRegistryIDs !== undefined)
|
|
165
237
|
return;
|
|
@@ -242,6 +314,7 @@ async function _Verifier_witnessedAt(doc, id, what, artifact, now) {
|
|
|
242
314
|
usage(() => validateConfigPins({ ...pins, now, maxAgeMs: 0, futureSkewMs: 0 }));
|
|
243
315
|
const { expected, config } = await __classPrivateFieldGet(this, _Verifier_instances, "m", _Verifier_resolveConfig).call(this, doc, pins, now);
|
|
244
316
|
const digest = decodeLowerHex("config digest", config.digest, 32);
|
|
317
|
+
await __classPrivateFieldGet(this, _Verifier_instances, "m", _Verifier_authenticateContainers).call(this, doc, config.digest);
|
|
245
318
|
const { manifest, artifact } = await __classPrivateFieldGet(this, _Verifier_instances, "m", _Verifier_resolveRuntime).call(this, doc, expected, now);
|
|
246
319
|
const { platform, platformArtifact } = await __classPrivateFieldGet(this, _Verifier_instances, "m", _Verifier_resolvePlatform).call(this, doc, now);
|
|
247
320
|
const runtime = manifest.measurements ?? { formatVersion: 0n };
|
|
@@ -272,7 +345,7 @@ async function _Verifier_resolveConfig(doc, pins, now) {
|
|
|
272
345
|
await authorizer({ ...material, config: config.slice(), ...(material.issuer === undefined ? {} : { issuer: material.issuer.slice() }) });
|
|
273
346
|
}
|
|
274
347
|
catch (err) {
|
|
275
|
-
throw new
|
|
348
|
+
throw new StepFailure("provenance", `authorizing config: ${message(err)}`, err);
|
|
276
349
|
}
|
|
277
350
|
const digest = toHex(await sha256(config));
|
|
278
351
|
return { expected: configRuntime(config), config: { source: "policy", name: "", digest, reference: "", signingKeyHint: "", registryID: "" } };
|
|
@@ -327,6 +400,26 @@ async function _Verifier_resolveConfig(doc, pins, now) {
|
|
|
327
400
|
...(approved.signatureTime === undefined ? {} : { signatureTime: approved.signatureTime }),
|
|
328
401
|
},
|
|
329
402
|
};
|
|
403
|
+
}, _Verifier_authenticateContainers =
|
|
404
|
+
/**
|
|
405
|
+
* Authenticates the container builds that the config with the verified
|
|
406
|
+
* `digest` requires. It reads them from config bytes that have that digest:
|
|
407
|
+
* the caller's, or else the document's. Without such bytes there is nothing
|
|
408
|
+
* to check.
|
|
409
|
+
*/
|
|
410
|
+
async function _Verifier_authenticateContainers(doc, digest) {
|
|
411
|
+
let config = __classPrivateFieldGet(this, _Verifier_policy, "f").embedded.configReference?.bytes;
|
|
412
|
+
if (config === undefined) {
|
|
413
|
+
try {
|
|
414
|
+
config = doc.configEndorsement().config;
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
if (config === undefined || config.length === 0 || toHex(await sha256(config)) !== digest)
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
await authenticateContainers(__classPrivateFieldGet(this, _Verifier_prov, "f"), config, (imageDigest) => doc.containerProvenance(imageDigest));
|
|
330
423
|
}, _Verifier_resolveRuntime = async function _Verifier_resolveRuntime(doc, expected, now) {
|
|
331
424
|
const embedded = __classPrivateFieldGet(this, _Verifier_policy, "f").embedded.runtime;
|
|
332
425
|
if (embedded !== undefined) {
|
|
@@ -376,59 +469,46 @@ async function _Verifier_approvedAt(doc, id, kind, what, artifact, now) {
|
|
|
376
469
|
(() => {
|
|
377
470
|
construct = (parts) => new Verifier(BUILT_HERE, parts);
|
|
378
471
|
})();
|
|
379
|
-
/** Validates
|
|
380
|
-
async function assemble(
|
|
472
|
+
/** Validates the config trust and the policy, resolves the trust material and assembles the verifier. */
|
|
473
|
+
async function assemble(config, policy, roots) {
|
|
381
474
|
const prov = roots.sigstore ? await ProvenanceClient.fromJSON(roots.sigstore) : await ProvenanceClient.default();
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
const embedded = options.embeddedReferences === undefined ? {} : await embeddedOf(options.embeddedReferences);
|
|
390
|
-
if (embedded.configReference !== undefined && configKeys !== undefined) {
|
|
391
|
-
throw new UsageError("embedded config and config signing keys select conflicting trust sources");
|
|
392
|
-
}
|
|
393
|
-
if (options.configAuthorizer !== undefined && (embedded.configReference !== undefined || configKeys !== undefined)) {
|
|
394
|
-
throw new UsageError("config authorizer conflicts with embedded config or config signing keys");
|
|
395
|
-
}
|
|
396
|
-
const configRegistryIDs = options.configRegistryIDs === undefined ? undefined : usage(() => registryIDsOf(options.configRegistryIDs));
|
|
397
|
-
if (configRegistryIDs !== undefined && (embedded.configReference !== undefined || options.configAuthorizer !== undefined)) {
|
|
398
|
-
throw new UsageError("config authority pins require endorsement verification");
|
|
399
|
-
}
|
|
400
|
-
if (configRegistryIDs !== undefined && configKeys !== undefined) {
|
|
401
|
-
throw new UsageError("config registry ID policy requires Tinfoil registry root verification");
|
|
402
|
-
}
|
|
403
|
-
if (embedded.runtime !== undefined && embedded.platform !== undefined && freshnessKeys !== undefined) {
|
|
404
|
-
throw new UsageError("freshness signing keys have no endorsed artifact to verify");
|
|
405
|
-
}
|
|
475
|
+
if (policy !== undefined && (typeof policy !== "object" || policy === null))
|
|
476
|
+
throw new UsageError("policy must be an object");
|
|
477
|
+
const pinnedRegisters = policy?.pinnedRegisters === undefined ? undefined : validPins(policy.pinnedRegisters);
|
|
478
|
+
const freshnessMaxAgeMs = freshnessBound(policy?.freshnessMaxAgeMs);
|
|
479
|
+
// The artifacts come first, so that an embedded config can check an embedded runtime against itself.
|
|
480
|
+
const artifacts = await artifactTrustOf(policy?.artifacts);
|
|
481
|
+
const trust = await configTrustOf(config, artifacts.runtime);
|
|
406
482
|
const publicKeys = await publicSigningKeys();
|
|
407
483
|
// Without caller-pinned config keys, the public keys are the registry
|
|
408
484
|
// roots as well: they issue the signing certificates of certified approvals.
|
|
409
485
|
const registryKeys = roots.registryRoots === undefined ? publicKeys : await keysOf("registry roots", roots.registryRoots);
|
|
410
|
-
const configVerifier = configKeys === undefined ? new ConfigVerifier(prov.root, registryKeys, registryKeys) : new ConfigVerifier(prov.root, configKeys);
|
|
411
|
-
const freshnessVerifier = new FreshnessVerifier(prov.root, freshnessKeys ?? publicKeys);
|
|
412
|
-
const
|
|
413
|
-
embedded
|
|
486
|
+
const configVerifier = trust.configKeys === undefined ? new ConfigVerifier(prov.root, registryKeys, registryKeys) : new ConfigVerifier(prov.root, trust.configKeys);
|
|
487
|
+
const freshnessVerifier = new FreshnessVerifier(prov.root, artifacts.freshnessKeys ?? publicKeys);
|
|
488
|
+
const settings = {
|
|
489
|
+
embedded: {
|
|
490
|
+
...(trust.configReference === undefined ? {} : { configReference: trust.configReference }),
|
|
491
|
+
...(artifacts.runtime === undefined ? {} : { runtime: artifacts.runtime }),
|
|
492
|
+
...(artifacts.platform === undefined ? {} : { platform: artifacts.platform }),
|
|
493
|
+
},
|
|
414
494
|
pinnedRegisters,
|
|
415
495
|
freshnessMaxAgeMs,
|
|
416
|
-
configAuthorizer:
|
|
417
|
-
configRegistryIDs,
|
|
418
|
-
configKeysPinned: configKeys !== undefined,
|
|
419
|
-
freshnessKeysPinned: freshnessKeys !== undefined,
|
|
496
|
+
configAuthorizer: trust.configAuthorizer,
|
|
497
|
+
configRegistryIDs: trust.configRegistryIDs,
|
|
498
|
+
configKeysPinned: trust.configKeys !== undefined,
|
|
499
|
+
freshnessKeysPinned: artifacts.freshnessKeys !== undefined,
|
|
420
500
|
};
|
|
421
|
-
return construct({ policy, prov, configVerifier, freshnessVerifier, roots: { amd: roots.amd, intel: roots.intel } });
|
|
501
|
+
return construct({ policy: settings, prov, configVerifier, freshnessVerifier, roots: { amd: roots.amd, intel: roots.intel } });
|
|
422
502
|
}
|
|
423
503
|
/**
|
|
424
|
-
* @internal Validates the
|
|
425
|
-
* where an absent root selects the embedded
|
|
426
|
-
* is a UsageError. {@link Verifier.create} is
|
|
427
|
-
* Not exported from the package entry.
|
|
504
|
+
* @internal Validates the config trust and the policy and assembles the
|
|
505
|
+
* verifier under `roots`, where an absent root selects the embedded
|
|
506
|
+
* production anchor; any failure is a UsageError. {@link Verifier.create} is
|
|
507
|
+
* this with no roots injected. Not exported from the package entry.
|
|
428
508
|
*/
|
|
429
|
-
export async function buildVerifier(
|
|
509
|
+
export async function buildVerifier(config, policy, roots) {
|
|
430
510
|
try {
|
|
431
|
-
return await assemble(
|
|
511
|
+
return await assemble(config, policy, roots);
|
|
432
512
|
}
|
|
433
513
|
catch (err) {
|
|
434
514
|
if (err instanceof UsageError)
|
|
@@ -436,6 +516,101 @@ export async function buildVerifier(options, roots) {
|
|
|
436
516
|
throw new UsageError(message(err), { cause: err });
|
|
437
517
|
}
|
|
438
518
|
}
|
|
519
|
+
/** Validates and copies `artifacts`; undefined selects the endorsed artifacts under Tinfoil's keys. */
|
|
520
|
+
async function artifactTrustOf(artifacts) {
|
|
521
|
+
if (artifacts === undefined)
|
|
522
|
+
return {};
|
|
523
|
+
switch (kindOf(artifacts, "artifact trust")) {
|
|
524
|
+
case "endorsedArtifacts": {
|
|
525
|
+
const a = artifacts;
|
|
526
|
+
return a.freshnessKeys === undefined ? {} : { freshnessKeys: await keysOf("freshness signing keys", a.freshnessKeys) };
|
|
527
|
+
}
|
|
528
|
+
case "embeddedArtifacts": {
|
|
529
|
+
const a = artifacts;
|
|
530
|
+
const runtime = optionalBytes("embedded runtime", a.runtime);
|
|
531
|
+
const platform = optionalBytes("embedded platform", a.platform);
|
|
532
|
+
if (runtime === undefined && platform === undefined)
|
|
533
|
+
throw new UsageError("embedded artifacts must contain a runtime or a platform");
|
|
534
|
+
if (runtime !== undefined && platform !== undefined && a.freshnessKeys !== undefined) {
|
|
535
|
+
throw new UsageError("freshness signing keys have no endorsed artifact to verify");
|
|
536
|
+
}
|
|
537
|
+
const freshnessKeys = a.freshnessKeys === undefined ? undefined : await keysOf("freshness signing keys", a.freshnessKeys);
|
|
538
|
+
if (runtime !== undefined)
|
|
539
|
+
decodeManifest(runtime);
|
|
540
|
+
if (platform !== undefined && parseArtifact(platform).format !== ARTIFACT_FORMAT_V2) {
|
|
541
|
+
throw new UsageError("embedded platform requires platform-endorsements/v2");
|
|
542
|
+
}
|
|
543
|
+
return {
|
|
544
|
+
...(freshnessKeys === undefined ? {} : { freshnessKeys }),
|
|
545
|
+
...(runtime === undefined ? {} : { runtime }),
|
|
546
|
+
...(platform === undefined ? {} : { platform }),
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
default:
|
|
550
|
+
throw new UsageError(`artifact trust must have kind "endorsedArtifacts" or "embeddedArtifacts", not ${describeKind(artifacts)}`);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Validates and copies `config`; undefined selects the public registry. An
|
|
555
|
+
* embedded config is checked against `embeddedRuntime`, the caller's own
|
|
556
|
+
* runtime manifest when it embeds one: both come from the caller, so a
|
|
557
|
+
* manifest that the config doesn't pin is rejected here rather than at
|
|
558
|
+
* verification.
|
|
559
|
+
*/
|
|
560
|
+
async function configTrustOf(config, embeddedRuntime) {
|
|
561
|
+
if (config === undefined)
|
|
562
|
+
return {};
|
|
563
|
+
switch (kindOf(config, "config trust")) {
|
|
564
|
+
case "registries":
|
|
565
|
+
return { configRegistryIDs: usage(() => registryIDsOf(config.ids)) };
|
|
566
|
+
case "configSigningKeys":
|
|
567
|
+
return { configKeys: await keysOf("config signing keys", config.keys) };
|
|
568
|
+
case "configAuthorizer": {
|
|
569
|
+
const authorize = config.authorize;
|
|
570
|
+
if (typeof authorize !== "function")
|
|
571
|
+
throw new UsageError("config authorizer must be a function");
|
|
572
|
+
return { configAuthorizer: authorize };
|
|
573
|
+
}
|
|
574
|
+
case "embeddedConfig":
|
|
575
|
+
case "embeddedConfigReference": {
|
|
576
|
+
const reference = await configReferenceOf(config);
|
|
577
|
+
if (reference.name !== "")
|
|
578
|
+
usage(() => parseConfigName(reference.name));
|
|
579
|
+
usage(() => decodeLowerHex("config digest", reference.digest, 32));
|
|
580
|
+
usage(() => validateRuntimeReference(reference.runtime));
|
|
581
|
+
if (embeddedRuntime !== undefined)
|
|
582
|
+
await parseManifest(embeddedRuntime, reference.runtime);
|
|
583
|
+
return { configReference: reference };
|
|
584
|
+
}
|
|
585
|
+
default:
|
|
586
|
+
throw new UsageError(`config trust must have kind "registries", "configSigningKeys", "configAuthorizer", "embeddedConfig" or "embeddedConfigReference", not ${describeKind(config)}`);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
/** The `kind` of a sum-type value that untyped code may have passed as anything; a non-object is a UsageError. */
|
|
590
|
+
function kindOf(value, what) {
|
|
591
|
+
if (typeof value !== "object" || value === null)
|
|
592
|
+
throw new UsageError(`${what} must be an object with a kind`);
|
|
593
|
+
return value.kind;
|
|
594
|
+
}
|
|
595
|
+
/** How an unknown `kind` is named in an error. */
|
|
596
|
+
function describeKind(value) {
|
|
597
|
+
const kind = value.kind;
|
|
598
|
+
if (kind === undefined)
|
|
599
|
+
return "a value without one";
|
|
600
|
+
if (typeof kind === "string")
|
|
601
|
+
return JSON.stringify(kind);
|
|
602
|
+
if (typeof kind === "number" || typeof kind === "boolean" || typeof kind === "bigint" || kind === null)
|
|
603
|
+
return String(kind);
|
|
604
|
+
return `a ${typeof kind}`;
|
|
605
|
+
}
|
|
606
|
+
/** A copy of caller-supplied bytes, or undefined when they are absent; anything but a Uint8Array is a UsageError. */
|
|
607
|
+
function optionalBytes(what, bytes) {
|
|
608
|
+
if (bytes === undefined)
|
|
609
|
+
return undefined;
|
|
610
|
+
if (!(bytes instanceof Uint8Array))
|
|
611
|
+
throw new UsageError(`${what} must be a Uint8Array`);
|
|
612
|
+
return bytes.slice();
|
|
613
|
+
}
|
|
439
614
|
/** The parts of `pin`, "" when unset. A bare string is refused, not read as an empty pin. */
|
|
440
615
|
function pinOf(pin) {
|
|
441
616
|
if (typeof pin !== "object" || pin === null)
|
|
@@ -452,6 +627,18 @@ function registryIDsOf(registryIDs) {
|
|
|
452
627
|
validateRegistryIDs(registryIDs);
|
|
453
628
|
return [...registryIDs];
|
|
454
629
|
}
|
|
630
|
+
/**
|
|
631
|
+
* A step's rejection of the document at `layer`, which `verifyV3At` reports
|
|
632
|
+
* as a {@link VerificationError} with the same message and cause once the
|
|
633
|
+
* report is complete.
|
|
634
|
+
*/
|
|
635
|
+
class StepFailure extends Error {
|
|
636
|
+
constructor(layer, message, cause) {
|
|
637
|
+
super(message);
|
|
638
|
+
this.layer = layer;
|
|
639
|
+
this.cause = cause;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
455
642
|
/**
|
|
456
643
|
* Runs one pipeline step; an error that is not already classified is
|
|
457
644
|
* attributed to `layer`. That includes the verifier's own failures inside
|
|
@@ -463,11 +650,19 @@ async function at(layer, step) {
|
|
|
463
650
|
return await step();
|
|
464
651
|
}
|
|
465
652
|
catch (err) {
|
|
466
|
-
if (err instanceof VerifyError)
|
|
653
|
+
if (err instanceof VerifyError || err instanceof StepFailure)
|
|
467
654
|
throw err;
|
|
468
|
-
throw new
|
|
655
|
+
throw new StepFailure(layer, message(err), err);
|
|
469
656
|
}
|
|
470
657
|
}
|
|
658
|
+
/**
|
|
659
|
+
* Whether the caller embedded every reference value in the verifier, so
|
|
660
|
+
* that provenance authenticated nothing: the config, the runtime and the
|
|
661
|
+
* platform.
|
|
662
|
+
*/
|
|
663
|
+
function embedded(refs) {
|
|
664
|
+
return refs.config?.source === "embedded" && refs.artifact.source === "embedded" && refs.platform?.source === "embedded";
|
|
665
|
+
}
|
|
471
666
|
/** Runs a caller-input check; its failure is a UsageError. */
|
|
472
667
|
function usage(check) {
|
|
473
668
|
try {
|
|
@@ -518,6 +713,8 @@ function freshnessBound(maxAgeMs) {
|
|
|
518
713
|
return maxAgeMs;
|
|
519
714
|
}
|
|
520
715
|
async function keysOf(what, pems) {
|
|
716
|
+
if (!Array.isArray(pems) || pems.some((pem) => typeof pem !== "string"))
|
|
717
|
+
throw new UsageError(`${what} must be a list of PEM strings`);
|
|
521
718
|
if (pems.length === 0)
|
|
522
719
|
throw new UsageError(`${what} must not be empty`);
|
|
523
720
|
try {
|
|
@@ -528,56 +725,19 @@ async function keysOf(what, pems) {
|
|
|
528
725
|
}
|
|
529
726
|
}
|
|
530
727
|
/**
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
* the caller, so a runtime manifest the reference does not pin is rejected
|
|
534
|
-
* here rather than at verification.
|
|
535
|
-
*/
|
|
536
|
-
async function embeddedOf(refs) {
|
|
537
|
-
if (refs.config === undefined && refs.runtime === undefined && refs.platform === undefined) {
|
|
538
|
-
throw new UsageError("embedded references must contain at least one component");
|
|
539
|
-
}
|
|
540
|
-
const configReference = refs.config === undefined ? undefined : await configReferenceOf(refs.config);
|
|
541
|
-
if (configReference !== undefined) {
|
|
542
|
-
const reference = configReference;
|
|
543
|
-
if (reference.name !== "")
|
|
544
|
-
usage(() => parseConfigName(reference.name));
|
|
545
|
-
usage(() => decodeLowerHex("config digest", reference.digest, 32));
|
|
546
|
-
usage(() => validateRuntimeReference(reference.runtime));
|
|
547
|
-
if (refs.runtime !== undefined)
|
|
548
|
-
await parseManifest(refs.runtime, reference.runtime);
|
|
549
|
-
}
|
|
550
|
-
if (refs.runtime !== undefined)
|
|
551
|
-
decodeManifest(refs.runtime);
|
|
552
|
-
if (refs.platform !== undefined && parseArtifact(refs.platform).format !== ARTIFACT_FORMAT_V2) {
|
|
553
|
-
throw new UsageError("embedded platform requires platform-endorsements/v2");
|
|
554
|
-
}
|
|
555
|
-
return {
|
|
556
|
-
...(configReference === undefined ? {} : { configReference }),
|
|
557
|
-
...(refs.runtime === undefined ? {} : { runtime: refs.runtime.slice() }),
|
|
558
|
-
...(refs.platform === undefined ? {} : { platform: refs.platform.slice() }),
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* The config reference an embedded config settles to: derived from its
|
|
563
|
-
* bytes, or a copy of the caller's digest and runtime pin. The type admits
|
|
564
|
-
* one form or the other; an object from untyped code that has both or
|
|
565
|
-
* neither is refused.
|
|
728
|
+
* The config reference that an embedded config settles to: derived from its
|
|
729
|
+
* bytes, or a copy of the caller's digest and runtime pin.
|
|
566
730
|
*/
|
|
567
731
|
async function configReferenceOf(config) {
|
|
568
|
-
if (
|
|
569
|
-
throw new UsageError("embedded config must be an object");
|
|
570
|
-
const hasBytes = config.bytes !== undefined;
|
|
571
|
-
const hasDigest = config.digest !== undefined;
|
|
572
|
-
if (hasBytes === hasDigest)
|
|
573
|
-
throw new UsageError("embedded config is either its bytes or its digest and runtime pin, not both or neither");
|
|
574
|
-
if (hasBytes) {
|
|
732
|
+
if (config.kind === "embeddedConfig") {
|
|
575
733
|
const { name, bytes } = config;
|
|
576
734
|
if (!(bytes instanceof Uint8Array))
|
|
577
735
|
throw new UsageError("embedded config bytes must be a Uint8Array");
|
|
736
|
+
if (name !== undefined && typeof name !== "string")
|
|
737
|
+
throw new UsageError("embedded config name must be a string");
|
|
578
738
|
// Copied once so the digest and the runtime pin come from the same bytes, whatever the caller does to its buffer meanwhile.
|
|
579
739
|
const copy = bytes.slice();
|
|
580
|
-
return { name: name ?? "", digest: toHex(await sha256(copy)), runtime: usage(() => configRuntime(copy)) };
|
|
740
|
+
return { name: name ?? "", digest: toHex(await sha256(copy)), runtime: usage(() => configRuntime(copy)), bytes: copy };
|
|
581
741
|
}
|
|
582
742
|
return usage(() => referenceCopyOf(config));
|
|
583
743
|
}
|