owenloop 0.4.1 → 0.5.1
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/CHANGELOG.md +71 -0
- package/README.md +182 -53
- package/bin/owenloop.mjs +50 -2
- package/dist/packages/work/src/agent/brief.d.ts +176 -0
- package/dist/packages/work/src/agent/brief.js +197 -0
- package/dist/packages/work/src/agent/loop.d.ts +141 -0
- package/dist/packages/work/src/agent/loop.js +669 -0
- package/dist/packages/work/src/agent/model-policy.d.ts +49 -0
- package/dist/packages/work/src/agent/model-policy.js +138 -0
- package/dist/packages/work/src/agent/workdir.d.ts +210 -0
- package/dist/packages/work/src/agent/workdir.js +319 -0
- package/dist/packages/work/src/bundle/cache.d.ts +92 -0
- package/dist/packages/work/src/bundle/cache.js +338 -0
- package/dist/packages/work/src/bundle/fetch.d.ts +87 -0
- package/dist/packages/work/src/bundle/fetch.js +345 -0
- package/dist/packages/work/src/bundle/types.d.ts +164 -0
- package/dist/packages/work/src/bundle/types.js +1 -0
- package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
- package/dist/packages/work/src/consumed-verifier.js +205 -0
- package/dist/packages/work/src/credentials/owenloop.d.ts +11 -0
- package/dist/packages/work/src/credentials/owenloop.js +28 -0
- package/dist/packages/work/src/credentials/reader.d.ts +36 -0
- package/dist/packages/work/src/credentials/reader.js +32 -0
- package/dist/packages/work/src/credentials/resolve.d.ts +19 -0
- package/dist/packages/work/src/credentials/resolve.js +56 -0
- package/dist/packages/work/src/exec/instructions.d.ts +99 -0
- package/dist/packages/work/src/exec/instructions.js +323 -0
- package/dist/packages/work/src/exec/loop.d.ts +40 -0
- package/dist/packages/work/src/exec/loop.js +332 -0
- package/dist/packages/work/src/exec/payload.d.ts +29 -0
- package/dist/packages/work/src/exec/payload.js +54 -0
- package/dist/packages/work/src/exec/receipt.d.ts +41 -0
- package/dist/packages/work/src/exec/receipt.js +32 -0
- package/dist/packages/work/src/exec/runner.d.ts +71 -0
- package/dist/packages/work/src/exec/runner.js +256 -0
- package/dist/packages/work/src/harness/child-env.d.ts +100 -0
- package/dist/packages/work/src/harness/child-env.js +134 -0
- package/dist/packages/work/src/harness/claude.d.ts +140 -0
- package/dist/packages/work/src/harness/claude.js +837 -0
- package/dist/packages/work/src/harness/codex.d.ts +111 -0
- package/dist/packages/work/src/harness/codex.js +1024 -0
- package/dist/packages/work/src/harness/contract.d.ts +308 -0
- package/dist/packages/work/src/harness/contract.js +32 -0
- package/dist/packages/work/src/harness/fake.d.ts +59 -0
- package/dist/packages/work/src/harness/fake.js +91 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.d.ts +108 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.js +351 -0
- package/dist/packages/work/src/harness/permissions.d.ts +75 -0
- package/dist/packages/work/src/harness/permissions.js +182 -0
- package/dist/packages/work/src/harness/registry.d.ts +47 -0
- package/dist/packages/work/src/harness/registry.js +45 -0
- package/dist/packages/work/src/harness/session-store.d.ts +181 -0
- package/dist/packages/work/src/harness/session-store.js +523 -0
- package/dist/packages/work/src/harness/types.d.ts +29 -0
- package/dist/packages/work/src/harness/types.js +14 -0
- package/dist/packages/work/src/harnesses.d.ts +38 -0
- package/dist/packages/work/src/harnesses.js +38 -0
- package/dist/packages/work/src/hold/loop.d.ts +36 -0
- package/dist/packages/work/src/hold/loop.js +23 -0
- package/dist/packages/work/src/hold/mcp.d.ts +75 -0
- package/dist/packages/work/src/hold/mcp.js +264 -0
- package/dist/packages/work/src/hub/client.d.ts +23 -0
- package/dist/packages/work/src/hub/client.js +91 -0
- package/dist/packages/work/src/hub/types.d.ts +326 -0
- package/dist/packages/work/src/hub/types.js +26 -0
- package/dist/packages/work/src/lease/loop.d.ts +94 -0
- package/dist/packages/work/src/lease/loop.js +277 -0
- package/dist/packages/work/src/main.d.ts +1 -0
- package/dist/packages/work/src/main.js +48 -0
- package/dist/packages/work/src/mcp/server.d.ts +125 -0
- package/dist/packages/work/src/mcp/server.js +320 -0
- package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
- package/dist/packages/work/src/owenloop-bin.js +18 -0
- package/dist/packages/work/src/roles/agent-run.d.ts +124 -0
- package/dist/packages/work/src/roles/agent-run.js +529 -0
- package/dist/packages/work/src/roles/exec.d.ts +48 -0
- package/dist/packages/work/src/roles/exec.js +228 -0
- package/dist/packages/work/src/roles/hold.d.ts +72 -0
- package/dist/packages/work/src/roles/hold.js +363 -0
- package/dist/packages/work/src/roles/join.d.ts +18 -0
- package/dist/packages/work/src/roles/join.js +204 -0
- package/dist/packages/work/src/roles/lint.d.ts +58 -0
- package/dist/packages/work/src/roles/lint.js +234 -0
- package/dist/packages/work/src/roles/prepare.d.ts +1 -0
- package/dist/packages/work/src/roles/prepare.js +249 -0
- package/dist/packages/work/src/roles/release.d.ts +48 -0
- package/dist/packages/work/src/roles/release.js +137 -0
- package/dist/packages/work/src/roles/sessions.d.ts +61 -0
- package/dist/packages/work/src/roles/sessions.js +180 -0
- package/dist/packages/work/src/roles/settings.d.ts +6 -0
- package/dist/packages/work/src/roles/settings.js +71 -0
- package/dist/packages/work/src/roles/shift.d.ts +13 -0
- package/dist/packages/work/src/roles/shift.js +250 -0
- package/dist/packages/work/src/roles/signals.d.ts +55 -0
- package/dist/packages/work/src/roles/signals.js +62 -0
- package/dist/packages/work/src/settings/provision.d.ts +21 -0
- package/dist/packages/work/src/settings/provision.js +47 -0
- package/dist/packages/work/src/settings/settings.d.ts +136 -0
- package/dist/packages/work/src/settings/settings.js +155 -0
- package/dist/packages/work/src/shift/client.d.ts +24 -0
- package/dist/packages/work/src/shift/client.js +124 -0
- package/dist/packages/work/src/shift/loop.d.ts +131 -0
- package/dist/packages/work/src/shift/loop.js +751 -0
- package/dist/packages/work/src/shift/protocol.d.ts +95 -0
- package/dist/packages/work/src/shift/protocol.js +24 -0
- package/dist/packages/work/src/shift/routing.d.ts +35 -0
- package/dist/packages/work/src/shift/routing.js +50 -0
- package/dist/packages/work/src/shift/runtime.d.ts +45 -0
- package/dist/packages/work/src/shift/runtime.js +337 -0
- package/dist/packages/work/src/shift/server.d.ts +23 -0
- package/dist/packages/work/src/shift/server.js +716 -0
- package/dist/packages/work/src/shift/spawn.d.ts +109 -0
- package/dist/packages/work/src/shift/spawn.js +158 -0
- package/dist/packages/work/src/shift/state.d.ts +79 -0
- package/dist/packages/work/src/shift/state.js +385 -0
- package/dist/packages/work/src/submit-proof.d.ts +36 -0
- package/dist/packages/work/src/submit-proof.js +93 -0
- package/dist/packages/work/src/usage.d.ts +6 -0
- package/dist/packages/work/src/usage.js +175 -0
- package/dist/src/add.d.ts +189 -0
- package/dist/src/add.js +300 -0
- package/dist/src/archive.d.ts +97 -0
- package/dist/src/archive.js +591 -0
- package/dist/src/bundle/index.d.ts +64 -0
- package/dist/src/bundle/index.js +508 -0
- package/dist/src/bundle/manifest.d.ts +50 -0
- package/dist/src/bundle/manifest.js +435 -0
- package/dist/src/bundle/runtime.d.ts +26 -0
- package/dist/src/bundle/runtime.js +64 -0
- package/dist/src/bundle/tar.d.ts +62 -0
- package/dist/src/bundle/tar.js +238 -0
- package/dist/src/bundle/types.d.ts +105 -0
- package/dist/src/bundle/types.js +21 -0
- package/dist/{cli.d.ts → src/cli.d.ts} +92 -7
- package/dist/src/cli.js +5968 -0
- package/dist/{credentials.d.ts → src/credentials.d.ts} +22 -15
- package/dist/{credentials.js → src/credentials.js} +35 -31
- package/dist/src/crypto/allowed-signers.d.ts +68 -0
- package/dist/src/crypto/allowed-signers.js +307 -0
- package/dist/src/crypto/canonical.d.ts +8 -0
- package/dist/src/crypto/canonical.js +92 -0
- package/dist/src/crypto/chain.d.ts +65 -0
- package/dist/src/crypto/chain.js +377 -0
- package/dist/src/crypto/dsse.d.ts +209 -0
- package/dist/src/crypto/dsse.js +282 -0
- package/dist/src/crypto/enrollment.d.ts +78 -0
- package/dist/src/crypto/enrollment.js +186 -0
- package/dist/src/crypto/index.d.ts +48 -0
- package/dist/src/crypto/index.js +44 -0
- package/dist/src/crypto/keys.d.ts +258 -0
- package/dist/src/crypto/keys.js +908 -0
- package/dist/src/crypto/org-root.d.ts +33 -0
- package/dist/src/crypto/org-root.js +78 -0
- package/dist/src/crypto/origin-rules.d.ts +56 -0
- package/dist/src/crypto/origin-rules.js +143 -0
- package/dist/src/crypto/policy-floor.d.ts +98 -0
- package/dist/src/crypto/policy-floor.js +353 -0
- package/dist/src/crypto/records.d.ts +316 -0
- package/dist/src/crypto/records.js +157 -0
- package/dist/src/crypto/scope.d.ts +49 -0
- package/dist/src/crypto/scope.js +83 -0
- package/dist/src/crypto/ssh.d.ts +171 -0
- package/dist/src/crypto/ssh.js +396 -0
- package/dist/src/crypto/submission.d.ts +33 -0
- package/dist/src/crypto/submission.js +47 -0
- package/dist/src/crypto/trust-roots.d.ts +29 -0
- package/dist/src/crypto/trust-roots.js +39 -0
- package/dist/src/crypto/verify-consumed.d.ts +67 -0
- package/dist/src/crypto/verify-consumed.js +259 -0
- package/dist/src/crypto/verify-origin.d.ts +50 -0
- package/dist/src/crypto/verify-origin.js +151 -0
- package/dist/src/crypto/verify-publication.d.ts +60 -0
- package/dist/src/crypto/verify-publication.js +150 -0
- package/dist/{defs.d.ts → src/defs.d.ts} +24 -1
- package/dist/{defs.js → src/defs.js} +181 -61
- package/dist/{engine.d.ts → src/engine.d.ts} +105 -9
- package/dist/{engine.js → src/engine.js} +251 -47
- package/dist/{factory.d.ts → src/factory.d.ts} +16 -0
- package/dist/{factory.js → src/factory.js} +16 -4
- package/dist/src/global-config.d.ts +59 -0
- package/dist/src/global-config.js +84 -0
- package/dist/{hub.d.ts → src/hub.d.ts} +280 -31
- package/dist/{hub.js → src/hub.js} +493 -52
- package/dist/src/index.d.ts +47 -0
- package/dist/src/index.js +41 -0
- package/dist/src/install.d.ts +538 -0
- package/dist/src/install.js +1981 -0
- package/dist/src/lock.d.ts +38 -0
- package/dist/src/lock.js +325 -0
- package/dist/src/mcp/serve.d.ts +109 -0
- package/dist/{mcp → src/mcp}/serve.js +335 -75
- package/dist/{mcp → src/mcp}/server.d.ts +6 -9
- package/dist/{mcp → src/mcp}/server.js +18 -10
- package/dist/{model.d.ts → src/model.d.ts} +15 -0
- package/dist/{model.js → src/model.js} +112 -2
- package/dist/src/order-resolver.d.ts +184 -0
- package/dist/src/order-resolver.js +252 -0
- package/dist/src/package-version.d.ts +10 -0
- package/dist/src/package-version.js +42 -0
- package/dist/{paths.d.ts → src/paths.d.ts} +14 -1
- package/dist/{paths.js → src/paths.js} +18 -0
- package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
- package/dist/src/schemas/index.d.ts +1416 -0
- package/dist/src/schemas/index.js +31 -0
- package/dist/src/schemas/order.v1.schema.json +106 -0
- package/dist/src/schemas/origin.v1.schema.json +68 -0
- package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
- package/dist/src/schemas/publication.v1.schema.json +31 -0
- package/dist/src/schemas/revocation.v1.schema.json +39 -0
- package/dist/src/schemas/submission.v1.schema.json +61 -0
- package/dist/src/store/def-source.d.ts +52 -0
- package/dist/src/store/def-source.js +335 -0
- package/dist/src/store/index-file.d.ts +69 -0
- package/dist/src/store/index-file.js +151 -0
- package/dist/src/store/index.d.ts +27 -0
- package/dist/src/store/index.js +22 -0
- package/dist/src/store/ingestor.d.ts +43 -0
- package/dist/src/store/ingestor.js +211 -0
- package/dist/src/store/install.d.ts +228 -0
- package/dist/src/store/install.js +555 -0
- package/dist/src/store/instruction-source.d.ts +49 -0
- package/dist/src/store/instruction-source.js +298 -0
- package/dist/src/store/origin-evidence.d.ts +21 -0
- package/dist/src/store/origin-evidence.js +66 -0
- package/dist/src/store/pre-commit-verifier.d.ts +68 -0
- package/dist/src/store/pre-commit-verifier.js +418 -0
- package/dist/src/store/resolve.d.ts +138 -0
- package/dist/src/store/resolve.js +363 -0
- package/dist/src/store/types.d.ts +288 -0
- package/dist/src/store/types.js +356 -0
- package/dist/{types.d.ts → src/types.d.ts} +58 -24
- package/dist/{untar.d.ts → src/untar.d.ts} +8 -23
- package/dist/src/untar.js +38 -0
- package/dist/{util.d.ts → src/util.d.ts} +3 -2
- package/dist/{util.js → src/util.js} +3 -2
- package/dist/{owenwork.d.ts → src/work-settings.d.ts} +22 -22
- package/dist/{owenwork.js → src/work-settings.js} +27 -27
- package/docs/agent-runner.md +86 -0
- package/docs/authoring.md +150 -59
- package/docs/bundles.md +250 -0
- package/docs/cli.md +1758 -163
- package/docs/crypto.md +816 -0
- package/docs/design.md +374 -52
- package/docs/embedding.md +135 -27
- package/docs/wire-contracts.md +380 -0
- package/examples/workflows/{command-worker.yaml → command-executor.yaml} +15 -15
- package/examples/workflows/compile-dev-playbook.yaml +338 -0
- package/examples/workflows/judges/gate-sharpness.md +39 -0
- package/examples/workflows/judges/security.md +34 -0
- package/package.json +22 -8
- package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
- package/plugins/claude-code/plugin/.mcp.json +14 -0
- package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
- package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
- package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
- package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
- package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
- package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
- package/plugins/codex/.agents/plugins/marketplace.json +21 -0
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
- package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
- package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
- package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
- package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
- package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
- package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
- package/dist/add.d.ts +0 -384
- package/dist/add.js +0 -834
- package/dist/cli.js +0 -3270
- package/dist/index.d.ts +0 -32
- package/dist/index.js +0 -23
- package/dist/lock.d.ts +0 -80
- package/dist/lock.js +0 -217
- package/dist/mcp/serve.d.ts +0 -84
- package/dist/untar.js +0 -164
- /package/dist/{schema.d.ts → src/schema.d.ts} +0 -0
- /package/dist/{schema.js → src/schema.js} +0 -0
- /package/dist/{store.d.ts → src/store.d.ts} +0 -0
- /package/dist/{store.js → src/store.js} +0 -0
- /package/dist/{types.js → src/types.js} +0 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consume-side verification for dynamic artifact values.
|
|
3
|
+
*
|
|
4
|
+
* A consuming driver receives values and signed submission envelopes from an
|
|
5
|
+
* untrusted transport. This module verifies the envelope first, then checks the
|
|
6
|
+
* signed submission record, the delivered value digest, the expected version,
|
|
7
|
+
* and the producer's locally anchored enrollment chain and scope. Every trust
|
|
8
|
+
* input is explicit; this module performs no filesystem, network, or clock I/O.
|
|
9
|
+
*/
|
|
10
|
+
import { decodeBase64Strict, DSSE_SSH_NAMESPACE, dsseVerifySubmission, DsseEnvelopeError } from "./dsse.js";
|
|
11
|
+
import { publicKeyDescriptor } from "./keys.js";
|
|
12
|
+
import { createSshSigner, SshSignerError } from "./ssh.js";
|
|
13
|
+
import { enrollmentGrantSchema, submissionSchema } from "../schemas/index.js";
|
|
14
|
+
import { summarizeIssues, validateValue } from "../schema.js";
|
|
15
|
+
import { valueDigestHex } from "./canonical.js";
|
|
16
|
+
import { validateProducer } from "./chain.js";
|
|
17
|
+
function invalid(reason) {
|
|
18
|
+
return { kind: 'invalid', reason };
|
|
19
|
+
}
|
|
20
|
+
function unverifiable(reason) {
|
|
21
|
+
return { kind: 'unverifiable', reason };
|
|
22
|
+
}
|
|
23
|
+
function isRecord(value) {
|
|
24
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
function principalText(value) {
|
|
27
|
+
if (!isRecord(value) || typeof value.kind !== 'string' || typeof value.id !== 'string')
|
|
28
|
+
return undefined;
|
|
29
|
+
return `${value.kind}:${value.id}`;
|
|
30
|
+
}
|
|
31
|
+
function parseEnvelope(raw) {
|
|
32
|
+
let envelope;
|
|
33
|
+
try {
|
|
34
|
+
envelope = JSON.parse(raw);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return invalid('signature: submission proof is not valid JSON');
|
|
38
|
+
}
|
|
39
|
+
if (!isRecord(envelope))
|
|
40
|
+
return invalid('signature: submission proof is not a JSON object');
|
|
41
|
+
if (typeof envelope.payload !== 'string')
|
|
42
|
+
return invalid("signature: submission proof is missing a string 'payload'");
|
|
43
|
+
let payload;
|
|
44
|
+
try {
|
|
45
|
+
payload = decodeBase64Strict(envelope.payload, { allowEmpty: true });
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return invalid(`signature: submission proof payload is not valid Base64: ${error.message}`);
|
|
49
|
+
}
|
|
50
|
+
let decoded;
|
|
51
|
+
try {
|
|
52
|
+
decoded = JSON.parse(payload.toString('utf8'));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return invalid('signature: submission proof payload is not valid JSON');
|
|
56
|
+
}
|
|
57
|
+
if (!isRecord(decoded))
|
|
58
|
+
return invalid('signature: submission proof payload is not a JSON object');
|
|
59
|
+
if (typeof decoded.producerKeyId !== 'string' || decoded.producerKeyId === '') {
|
|
60
|
+
return invalid("signature: submission record is missing a string 'producerKeyId'");
|
|
61
|
+
}
|
|
62
|
+
return { envelope, recordHint: decoded };
|
|
63
|
+
}
|
|
64
|
+
function candidateFromGrant(raw, targetKeyId) {
|
|
65
|
+
let envelope;
|
|
66
|
+
try {
|
|
67
|
+
envelope = JSON.parse(Buffer.from(raw).toString('utf8'));
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return { kind: 'skip' };
|
|
71
|
+
}
|
|
72
|
+
if (!isRecord(envelope) || typeof envelope.payload !== 'string')
|
|
73
|
+
return { kind: 'skip' };
|
|
74
|
+
let payload;
|
|
75
|
+
try {
|
|
76
|
+
payload = decodeBase64Strict(envelope.payload, { allowEmpty: true });
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return { kind: 'skip' };
|
|
80
|
+
}
|
|
81
|
+
let decoded;
|
|
82
|
+
try {
|
|
83
|
+
decoded = JSON.parse(payload.toString('utf8'));
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return { kind: 'skip' };
|
|
87
|
+
}
|
|
88
|
+
if (!isRecord(decoded))
|
|
89
|
+
return { kind: 'skip' };
|
|
90
|
+
const shape = validateValue(enrollmentGrantSchema, decoded);
|
|
91
|
+
if (!shape.valid) {
|
|
92
|
+
const newKey = decoded.newKey;
|
|
93
|
+
if (!isRecord(newKey) || newKey.keyid !== targetKeyId)
|
|
94
|
+
return { kind: 'skip' };
|
|
95
|
+
return invalid(`chain: producer grant for '${targetKeyId}' does not match schema: ${summarizeIssues(shape.issues)}`);
|
|
96
|
+
}
|
|
97
|
+
const grant = decoded;
|
|
98
|
+
if (grant.newKey.keyid !== targetKeyId)
|
|
99
|
+
return { kind: 'skip' };
|
|
100
|
+
const principal = principalText(grant.principal);
|
|
101
|
+
if (principal === undefined)
|
|
102
|
+
return invalid(`chain: producer grant for '${targetKeyId}' has an invalid principal`);
|
|
103
|
+
try {
|
|
104
|
+
const descriptor = publicKeyDescriptor(grant.newKey.openSshPublicKey);
|
|
105
|
+
if (descriptor.keyid !== targetKeyId) {
|
|
106
|
+
return invalid(`chain: producer grant for '${targetKeyId}' carries public key '${descriptor.keyid}'`);
|
|
107
|
+
}
|
|
108
|
+
return { keyid: descriptor.keyid, principal, publicKey: descriptor.openSshPublicKey };
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
return invalid(`chain: producer grant for '${targetKeyId}' has an invalid public key: ${error instanceof Error ? error.message : String(error)}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function deriveCandidate(input, targetKeyId) {
|
|
115
|
+
if (input.orgRootPublicKey.trim() === '')
|
|
116
|
+
return unverifiable('prerequisite: no org-root anchor is configured');
|
|
117
|
+
let root;
|
|
118
|
+
try {
|
|
119
|
+
root = publicKeyDescriptor(input.orgRootPublicKey);
|
|
120
|
+
if (root.keyid === targetKeyId)
|
|
121
|
+
return { keyid: root.keyid, principal: 'org-root', publicKey: root.openSshPublicKey };
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// validateProducer returns the complete, named root failure after the
|
|
125
|
+
// signature candidate has been attempted; retain a prerequisite verdict.
|
|
126
|
+
return unverifiable('prerequisite: the org-root anchor is not a valid public key');
|
|
127
|
+
}
|
|
128
|
+
if (!Array.isArray(input.grants) || input.grants.length === 0) {
|
|
129
|
+
return unverifiable('prerequisite: no enrollment roster is configured');
|
|
130
|
+
}
|
|
131
|
+
const matches = [];
|
|
132
|
+
for (const grant of input.grants) {
|
|
133
|
+
const candidate = candidateFromGrant(grant, targetKeyId);
|
|
134
|
+
if ('kind' in candidate) {
|
|
135
|
+
if (candidate.kind === 'skip')
|
|
136
|
+
continue;
|
|
137
|
+
return candidate;
|
|
138
|
+
}
|
|
139
|
+
matches.push(candidate);
|
|
140
|
+
}
|
|
141
|
+
if (matches.length > 1)
|
|
142
|
+
return invalid(`chain: enrollment roster contains more than one producer grant for '${targetKeyId}'`);
|
|
143
|
+
const candidate = matches[0];
|
|
144
|
+
return candidate === undefined
|
|
145
|
+
? invalid(`chain: producer key '${targetKeyId}' is not present in the local enrollment roster`)
|
|
146
|
+
: candidate;
|
|
147
|
+
}
|
|
148
|
+
function makeSigner(options, candidate) {
|
|
149
|
+
const factory = options.signerForPrincipal ?? ((args) => createSshSigner({
|
|
150
|
+
namespace: options.namespace ?? DSSE_SSH_NAMESPACE,
|
|
151
|
+
verify: args,
|
|
152
|
+
}));
|
|
153
|
+
try {
|
|
154
|
+
return factory({ principal: candidate.principal, allowedSignersText: `${candidate.principal} ${candidate.publicKey}\n` });
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
if (error instanceof SshSignerError)
|
|
158
|
+
return unverifiable(`prerequisite: submission verification setup failed: ${error.message}`);
|
|
159
|
+
return unverifiable(`prerequisite: submission verification setup failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function chainOptions(options) {
|
|
163
|
+
return {
|
|
164
|
+
...(options.signerForPrincipal === undefined ? {} : { signerForPrincipal: options.signerForPrincipal }),
|
|
165
|
+
...(options.namespace === undefined ? {} : { namespace: options.namespace }),
|
|
166
|
+
...(options.maxChainDepth === undefined ? {} : { maxChainDepth: options.maxChainDepth }),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/** Verify one consumed value and its producer's enrollment/scope evidence. */
|
|
170
|
+
export async function verifyConsumed(input, options = {}) {
|
|
171
|
+
if (input.proof === undefined)
|
|
172
|
+
return { kind: 'absent' };
|
|
173
|
+
if (!Number.isInteger(input.at) || input.at < 0)
|
|
174
|
+
return invalid(`prerequisite: validation instant '${String(input.at)}' is not a non-negative integer`);
|
|
175
|
+
const parsed = parseEnvelope(input.proof);
|
|
176
|
+
if ('kind' in parsed)
|
|
177
|
+
return parsed;
|
|
178
|
+
const targetKeyId = parsed.recordHint.producerKeyId;
|
|
179
|
+
const candidate = deriveCandidate(input, targetKeyId);
|
|
180
|
+
if ('kind' in candidate)
|
|
181
|
+
return candidate;
|
|
182
|
+
const signer = makeSigner(options, candidate);
|
|
183
|
+
if ('kind' in signer)
|
|
184
|
+
return signer;
|
|
185
|
+
let record;
|
|
186
|
+
let verifiedKeyId;
|
|
187
|
+
try {
|
|
188
|
+
const result = await dsseVerifySubmission(parsed.envelope, signer, { threshold: 1 });
|
|
189
|
+
const verified = result.signers[0];
|
|
190
|
+
if (verified === undefined)
|
|
191
|
+
return invalid('signature: submission signature produced no verified signer');
|
|
192
|
+
verifiedKeyId = verified.keyid;
|
|
193
|
+
const decoded = JSON.parse(result.payloadBytes.toString('utf8'));
|
|
194
|
+
const shape = validateValue(submissionSchema, decoded);
|
|
195
|
+
if (!shape.valid)
|
|
196
|
+
return invalid(`signature: submission record does not match schema: ${summarizeIssues(shape.issues)}`);
|
|
197
|
+
record = decoded;
|
|
198
|
+
if (verified.keyid !== record.producerKeyId) {
|
|
199
|
+
return invalid(`signature: verified producer key '${verified.keyid}' does not match record producerKeyId '${record.producerKeyId}'`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
if (error instanceof SshSignerError)
|
|
204
|
+
return unverifiable(`prerequisite: ${error.message}`);
|
|
205
|
+
if (error instanceof DsseEnvelopeError)
|
|
206
|
+
return invalid(`signature: submission signature verification failed: ${error.message}`);
|
|
207
|
+
return invalid(`signature: submission signature verification failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
signer.dispose?.();
|
|
211
|
+
}
|
|
212
|
+
const produced = record.produced.find((entry) => entry.artifact === input.path);
|
|
213
|
+
if (produced === undefined)
|
|
214
|
+
return invalid(`signature: signed submission record does not cover artifact '${input.path}'`);
|
|
215
|
+
let deliveredDigest;
|
|
216
|
+
try {
|
|
217
|
+
deliveredDigest = valueDigestHex(input.value);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
return invalid(`value-digest: delivered artifact '${input.path}' cannot be canonically represented: ${error instanceof Error ? error.message : String(error)}`);
|
|
221
|
+
}
|
|
222
|
+
if (deliveredDigest !== produced.valueDigest) {
|
|
223
|
+
return invalid(`value-digest: delivered artifact '${input.path}' has digest '${deliveredDigest}', signed digest is '${produced.valueDigest}'`);
|
|
224
|
+
}
|
|
225
|
+
if (input.expectedVersion !== undefined && produced.version !== input.expectedVersion) {
|
|
226
|
+
return invalid(`version: artifact '${input.path}' has signed version ${produced.version}, expected version ${input.expectedVersion}`);
|
|
227
|
+
}
|
|
228
|
+
if (record.timestamp > input.at) {
|
|
229
|
+
options.warn?.(`producer-claimed timestamp for artifact '${input.path}' is ${record.timestamp - input.at} ms ahead of local clock; timestamp is not used for revocation`);
|
|
230
|
+
}
|
|
231
|
+
let chain;
|
|
232
|
+
try {
|
|
233
|
+
const chainInput = {
|
|
234
|
+
targetKeyId: record.producerKeyId,
|
|
235
|
+
orgRootPublicKey: input.orgRootPublicKey,
|
|
236
|
+
grants: input.grants,
|
|
237
|
+
...(input.revocations === undefined ? {} : { revocations: input.revocations }),
|
|
238
|
+
at: input.at,
|
|
239
|
+
demand: input.demand,
|
|
240
|
+
};
|
|
241
|
+
const chainValidate = options.chainValidator ?? validateProducer;
|
|
242
|
+
chain = await chainValidate(chainInput, chainOptions(options));
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
return unverifiable(`prerequisite: producer enrollment-chain validation could not run: ${error instanceof Error ? error.message : String(error)}`);
|
|
246
|
+
}
|
|
247
|
+
if (chain.kind === 'unverifiable')
|
|
248
|
+
return { kind: 'unverifiable', reason: `chain: ${chain.reason}` };
|
|
249
|
+
if (chain.kind === 'invalid') {
|
|
250
|
+
const link = chain.reason.includes('outside the effective scope') ? 'scope' : 'chain';
|
|
251
|
+
return invalid(`${link}: ${chain.reason}`);
|
|
252
|
+
}
|
|
253
|
+
if (input.expectedVersion === undefined) {
|
|
254
|
+
return unverifiable(`version: artifact '${input.path}' has a valid historical proof, but the claim omitted its authoritative expected version`);
|
|
255
|
+
}
|
|
256
|
+
return { kind: 'verified', producerKeyId: verifiedKeyId, principal: chain.principal, version: produced.version };
|
|
257
|
+
}
|
|
258
|
+
/** Alias matching the other record verifier names. */
|
|
259
|
+
export const verifyConsumedArtifact = verifyConsumed;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Origin-sidecar verification for workflow definitions.
|
|
3
|
+
*
|
|
4
|
+
* An origin sidecar is optional, so absence is distinct from an unsigned
|
|
5
|
+
* publication. A present sidecar is either a verified signed statement or a
|
|
6
|
+
* hard failure: the hub or another relay cannot turn an unrecognized origin
|
|
7
|
+
* shape into a successful result.
|
|
8
|
+
*/
|
|
9
|
+
import type { Signer } from './ssh.ts';
|
|
10
|
+
import type { OriginSource } from './records.ts';
|
|
11
|
+
export type OriginVerdict = {
|
|
12
|
+
kind: 'verified';
|
|
13
|
+
source: OriginSource;
|
|
14
|
+
attesterKeyId: string;
|
|
15
|
+
principal: string;
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'absent';
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'unverifiable';
|
|
20
|
+
reason: string;
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'invalid';
|
|
23
|
+
reason: string;
|
|
24
|
+
};
|
|
25
|
+
export interface VerifyOriginInput {
|
|
26
|
+
/** Digest computed by bundle ingestion for the bytes being installed. */
|
|
27
|
+
bundleDigest: string;
|
|
28
|
+
/** The raw `.origin.dsse` sidecar bytes. Omit when no origin is supplied. */
|
|
29
|
+
dsseBytes?: Uint8Array;
|
|
30
|
+
/** Resolved local allowed_signers text. */
|
|
31
|
+
allowedSignersText?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface VerifyOriginOptions {
|
|
34
|
+
/** Test seam and future signer seam for candidate-principal verification. */
|
|
35
|
+
signerForPrincipal?: (args: {
|
|
36
|
+
principal: string;
|
|
37
|
+
allowedSignersText: string;
|
|
38
|
+
}) => Pick<Signer, 'verify'> & {
|
|
39
|
+
dispose?: () => void;
|
|
40
|
+
};
|
|
41
|
+
namespace?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Verify one origin sidecar using the record's attester key-id only as a
|
|
45
|
+
* candidate-selection hint. The verified signer descriptor remains the
|
|
46
|
+
* authority, and the digest is checked against the bundle after verification.
|
|
47
|
+
*/
|
|
48
|
+
export declare function verifyOrigin(input: VerifyOriginInput, options?: VerifyOriginOptions): Promise<OriginVerdict>;
|
|
49
|
+
/** Alias naming the sidecar explicitly for callers at filesystem boundaries. */
|
|
50
|
+
export declare const verifyOriginSidecar: typeof verifyOrigin;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Origin-sidecar verification for workflow definitions.
|
|
3
|
+
*
|
|
4
|
+
* An origin sidecar is optional, so absence is distinct from an unsigned
|
|
5
|
+
* publication. A present sidecar is either a verified signed statement or a
|
|
6
|
+
* hard failure: the hub or another relay cannot turn an unrecognized origin
|
|
7
|
+
* shape into a successful result.
|
|
8
|
+
*/
|
|
9
|
+
import { keyidFromBlob } from "./keys.js";
|
|
10
|
+
import { decodeBase64Strict, DSSE_SSH_NAMESPACE, dsseVerifyOrigin, DsseEnvelopeError, } from "./dsse.js";
|
|
11
|
+
import { parseAllowedSigners } from "./allowed-signers.js";
|
|
12
|
+
import { createSshSigner, SshSignerError } from "./ssh.js";
|
|
13
|
+
import { originSchema } from "../schemas/index.js";
|
|
14
|
+
import { validateValue, summarizeIssues } from "../schema.js";
|
|
15
|
+
function invalid(reason) {
|
|
16
|
+
return { kind: 'invalid', reason };
|
|
17
|
+
}
|
|
18
|
+
function unverifiable(reason) {
|
|
19
|
+
return { kind: 'unverifiable', reason };
|
|
20
|
+
}
|
|
21
|
+
function asRecord(value) {
|
|
22
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Decode only what candidate selection needs. The record is still
|
|
26
|
+
* unauthenticated here; the complete schema check happens after DSSE
|
|
27
|
+
* verification, so an untrusted source branch cannot authorize a signer.
|
|
28
|
+
*/
|
|
29
|
+
function decodeOriginRecord(envelope) {
|
|
30
|
+
if (typeof envelope !== 'object' || envelope === null || Array.isArray(envelope)) {
|
|
31
|
+
return invalid('origin sidecar is not a JSON object');
|
|
32
|
+
}
|
|
33
|
+
const payload = envelope['payload'];
|
|
34
|
+
if (typeof payload !== 'string')
|
|
35
|
+
return invalid("origin sidecar is missing a string 'payload'");
|
|
36
|
+
let payloadBytes;
|
|
37
|
+
try {
|
|
38
|
+
payloadBytes = decodeBase64Strict(payload, { allowEmpty: true });
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return invalid(`origin payload is not valid Base64: ${error.message}`);
|
|
42
|
+
}
|
|
43
|
+
let decoded;
|
|
44
|
+
try {
|
|
45
|
+
decoded = JSON.parse(payloadBytes.toString('utf8'));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return invalid('origin payload is not valid JSON');
|
|
49
|
+
}
|
|
50
|
+
if (!asRecord(decoded))
|
|
51
|
+
return invalid('origin payload is not a JSON object');
|
|
52
|
+
if (typeof decoded.attesterKeyId !== 'string') {
|
|
53
|
+
return invalid("origin record is missing a string 'attesterKeyId'");
|
|
54
|
+
}
|
|
55
|
+
return { record: decoded, payloadBytes };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Verify one origin sidecar using the record's attester key-id only as a
|
|
59
|
+
* candidate-selection hint. The verified signer descriptor remains the
|
|
60
|
+
* authority, and the digest is checked against the bundle after verification.
|
|
61
|
+
*/
|
|
62
|
+
export async function verifyOrigin(input, options = {}) {
|
|
63
|
+
if (input.dsseBytes === undefined)
|
|
64
|
+
return { kind: 'absent' };
|
|
65
|
+
if (input.allowedSignersText === undefined) {
|
|
66
|
+
return unverifiable('no allowed_signers trust root was resolved');
|
|
67
|
+
}
|
|
68
|
+
let envelope;
|
|
69
|
+
try {
|
|
70
|
+
envelope = JSON.parse(Buffer.from(input.dsseBytes).toString('utf8'));
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return invalid('origin sidecar is not valid JSON');
|
|
74
|
+
}
|
|
75
|
+
const decoded = decodeOriginRecord(envelope);
|
|
76
|
+
if ('kind' in decoded)
|
|
77
|
+
return decoded;
|
|
78
|
+
const { record } = decoded;
|
|
79
|
+
const attesterKeyId = record.attesterKeyId;
|
|
80
|
+
const parsed = parseAllowedSigners(input.allowedSignersText);
|
|
81
|
+
if (parsed.errors.length > 0) {
|
|
82
|
+
return unverifiable(`allowed_signers policy is malformed: ${parsed.errors.map((error) => `line ${error.line}: ${error.message}`).join('; ')}`);
|
|
83
|
+
}
|
|
84
|
+
if (parsed.entries.length === 0)
|
|
85
|
+
return unverifiable('allowed_signers policy has no signer entries');
|
|
86
|
+
const candidates = parsed.entries.filter((entry) => keyidFromBlob(entry.keyBlob) === attesterKeyId);
|
|
87
|
+
if (candidates.length === 0) {
|
|
88
|
+
return invalid(`origin signer key '${attesterKeyId}' is not present in allowed_signers`);
|
|
89
|
+
}
|
|
90
|
+
const makeSigner = options.signerForPrincipal ?? ((args) => createSshSigner({
|
|
91
|
+
namespace: options.namespace ?? DSSE_SSH_NAMESPACE,
|
|
92
|
+
verify: args,
|
|
93
|
+
}));
|
|
94
|
+
let sawCryptographicMiss = false;
|
|
95
|
+
for (const candidate of candidates) {
|
|
96
|
+
for (const principal of candidate.principals) {
|
|
97
|
+
let signer;
|
|
98
|
+
try {
|
|
99
|
+
signer = makeSigner({ principal, allowedSignersText: input.allowedSignersText });
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (error instanceof SshSignerError)
|
|
103
|
+
return unverifiable(error.message);
|
|
104
|
+
return unverifiable(`origin verification setup failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const result = await dsseVerifyOrigin(envelope, signer, { threshold: 1 });
|
|
108
|
+
const verified = result.signers[0];
|
|
109
|
+
if (verified === undefined)
|
|
110
|
+
return invalid('origin signature produced no verified signer');
|
|
111
|
+
const shape = validateValue(originSchema, record);
|
|
112
|
+
if (!shape.valid) {
|
|
113
|
+
return invalid(`origin record does not match schema: ${summarizeIssues(shape.issues)}`);
|
|
114
|
+
}
|
|
115
|
+
const originRecord = record;
|
|
116
|
+
if (verified.keyid !== originRecord.attesterKeyId) {
|
|
117
|
+
return invalid(`origin signer key '${verified.keyid}' does not match record attesterKeyId '${originRecord.attesterKeyId}'`);
|
|
118
|
+
}
|
|
119
|
+
if (originRecord.digest !== input.bundleDigest) {
|
|
120
|
+
return invalid(`origin digest '${originRecord.digest}' does not match bundle digest '${input.bundleDigest}'`);
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
kind: 'verified',
|
|
124
|
+
source: originRecord.source,
|
|
125
|
+
attesterKeyId: verified.keyid,
|
|
126
|
+
principal: verified.principal,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
if (error instanceof SshSignerError)
|
|
131
|
+
return unverifiable(error.message);
|
|
132
|
+
if (error instanceof DsseEnvelopeError) {
|
|
133
|
+
if (error.message.startsWith('DSSE verification failed:')) {
|
|
134
|
+
sawCryptographicMiss = true;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
return invalid(`origin verification failed: ${error.message}`);
|
|
138
|
+
}
|
|
139
|
+
return invalid(`origin verification failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
signer.dispose?.();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (sawCryptographicMiss)
|
|
147
|
+
return invalid('origin signature could not be verified by an allowed signer');
|
|
148
|
+
return invalid('origin signature did not verify');
|
|
149
|
+
}
|
|
150
|
+
/** Alias naming the sidecar explicitly for callers at filesystem boundaries. */
|
|
151
|
+
export const verifyOriginSidecar = verifyOrigin;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Publication-sidecar verification for workflow definitions.
|
|
3
|
+
*
|
|
4
|
+
* This module returns four deliberately distinct states. `unsigned` means no
|
|
5
|
+
* publication sidecar was supplied. `unverifiable` means the local trust
|
|
6
|
+
* machinery cannot perform verification. `invalid` means a sidecar was present
|
|
7
|
+
* but the signed statement or its binding to the bundle failed. Only
|
|
8
|
+
* `verified` is a successful signature decision.
|
|
9
|
+
*/
|
|
10
|
+
import type { Signer } from './ssh.ts';
|
|
11
|
+
/** The local driver policy vocabulary. */
|
|
12
|
+
export type DefPolicy = 'enforce' | 'warn' | 'off';
|
|
13
|
+
export declare function isDefPolicy(value: unknown): value is DefPolicy;
|
|
14
|
+
export type DefVerdict = {
|
|
15
|
+
kind: 'verified';
|
|
16
|
+
publisherKeyId: string;
|
|
17
|
+
principal: string;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'unsigned';
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'unverifiable';
|
|
22
|
+
reason: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'invalid';
|
|
25
|
+
reason: string;
|
|
26
|
+
};
|
|
27
|
+
export interface VerifyPublicationInput {
|
|
28
|
+
/** Digest computed by bundle ingestion for the bytes being installed. */
|
|
29
|
+
bundleDigest: string;
|
|
30
|
+
/** The raw `.dsse` sidecar bytes. Omit for an unsigned bundle. */
|
|
31
|
+
dsseBytes?: Uint8Array;
|
|
32
|
+
/** Resolved local allowed_signers text. */
|
|
33
|
+
allowedSignersText?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface VerifyPublicationOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Test seam and future signer seam. The default constructs an SSHSIG signer
|
|
38
|
+
* for the candidate principal and keeps OpenSSH as the authorization
|
|
39
|
+
* authority.
|
|
40
|
+
*/
|
|
41
|
+
signerForPrincipal?: (args: {
|
|
42
|
+
principal: string;
|
|
43
|
+
allowedSignersText: string;
|
|
44
|
+
}) => Pick<Signer, 'verify'> & {
|
|
45
|
+
dispose?: () => void;
|
|
46
|
+
};
|
|
47
|
+
namespace?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Verify one publication sidecar using the key-id index principal resolution
|
|
51
|
+
* strategy. The record's publisherKeyId selects the allowed_signers key, then
|
|
52
|
+
* each principal attached to that key is tried until OpenSSH accepts one.
|
|
53
|
+
*
|
|
54
|
+
* The key-id lookup is only a candidate-selection optimization: the returned
|
|
55
|
+
* signer descriptor is still checked against the signed record after DSSE
|
|
56
|
+
* verification. The record's unauthenticated contents never authorize a key.
|
|
57
|
+
*/
|
|
58
|
+
export declare function verifyPublication(input: VerifyPublicationInput, options?: VerifyPublicationOptions): Promise<DefVerdict>;
|
|
59
|
+
/** Alias naming the sidecar explicitly for callers at filesystem boundaries. */
|
|
60
|
+
export declare const verifyPublicationSidecar: typeof verifyPublication;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Publication-sidecar verification for workflow definitions.
|
|
3
|
+
*
|
|
4
|
+
* This module returns four deliberately distinct states. `unsigned` means no
|
|
5
|
+
* publication sidecar was supplied. `unverifiable` means the local trust
|
|
6
|
+
* machinery cannot perform verification. `invalid` means a sidecar was present
|
|
7
|
+
* but the signed statement or its binding to the bundle failed. Only
|
|
8
|
+
* `verified` is a successful signature decision.
|
|
9
|
+
*/
|
|
10
|
+
import { keyidFromBlob } from "./keys.js";
|
|
11
|
+
import { decodeBase64Strict, DSSE_SSH_NAMESPACE, dsseVerifyPublication, DsseEnvelopeError, } from "./dsse.js";
|
|
12
|
+
import { parseAllowedSigners } from "./allowed-signers.js";
|
|
13
|
+
import { createSshSigner, SshSignerError } from "./ssh.js";
|
|
14
|
+
import { publicationSchema } from "../schemas/index.js";
|
|
15
|
+
import { validateValue, summarizeIssues } from "../schema.js";
|
|
16
|
+
export function isDefPolicy(value) {
|
|
17
|
+
return value === 'enforce' || value === 'warn' || value === 'off';
|
|
18
|
+
}
|
|
19
|
+
function invalid(reason) {
|
|
20
|
+
return { kind: 'invalid', reason };
|
|
21
|
+
}
|
|
22
|
+
function unverifiable(reason) {
|
|
23
|
+
return { kind: 'unverifiable', reason };
|
|
24
|
+
}
|
|
25
|
+
function asRecord(value) {
|
|
26
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
27
|
+
}
|
|
28
|
+
/** Decode the untrusted publication payload for candidate selection and checks. */
|
|
29
|
+
function decodePublicationRecord(envelope) {
|
|
30
|
+
if (typeof envelope !== 'object' || envelope === null || Array.isArray(envelope)) {
|
|
31
|
+
return invalid('publication sidecar is not a JSON object');
|
|
32
|
+
}
|
|
33
|
+
const payload = envelope['payload'];
|
|
34
|
+
if (typeof payload !== 'string')
|
|
35
|
+
return invalid("publication sidecar is missing a string 'payload'");
|
|
36
|
+
let payloadBytes;
|
|
37
|
+
try {
|
|
38
|
+
payloadBytes = decodeBase64Strict(payload, { allowEmpty: true });
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return invalid(`publication payload is not valid Base64: ${error.message}`);
|
|
42
|
+
}
|
|
43
|
+
let decoded;
|
|
44
|
+
try {
|
|
45
|
+
decoded = JSON.parse(payloadBytes.toString('utf8'));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return invalid('publication payload is not valid JSON');
|
|
49
|
+
}
|
|
50
|
+
if (!asRecord(decoded))
|
|
51
|
+
return invalid('publication payload is not a JSON object');
|
|
52
|
+
const shape = validateValue(publicationSchema, decoded);
|
|
53
|
+
if (!shape.valid)
|
|
54
|
+
return invalid(`publication record does not match schema: ${summarizeIssues(shape.issues)}`);
|
|
55
|
+
return { record: decoded, payloadBytes };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Verify one publication sidecar using the key-id index principal resolution
|
|
59
|
+
* strategy. The record's publisherKeyId selects the allowed_signers key, then
|
|
60
|
+
* each principal attached to that key is tried until OpenSSH accepts one.
|
|
61
|
+
*
|
|
62
|
+
* The key-id lookup is only a candidate-selection optimization: the returned
|
|
63
|
+
* signer descriptor is still checked against the signed record after DSSE
|
|
64
|
+
* verification. The record's unauthenticated contents never authorize a key.
|
|
65
|
+
*/
|
|
66
|
+
export async function verifyPublication(input, options = {}) {
|
|
67
|
+
if (input.dsseBytes === undefined)
|
|
68
|
+
return { kind: 'unsigned' };
|
|
69
|
+
if (input.allowedSignersText === undefined) {
|
|
70
|
+
return unverifiable('no allowed_signers trust root was resolved');
|
|
71
|
+
}
|
|
72
|
+
let envelope;
|
|
73
|
+
try {
|
|
74
|
+
envelope = JSON.parse(Buffer.from(input.dsseBytes).toString('utf8'));
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return invalid('publication sidecar is not valid JSON');
|
|
78
|
+
}
|
|
79
|
+
const decoded = decodePublicationRecord(envelope);
|
|
80
|
+
if ('kind' in decoded)
|
|
81
|
+
return decoded;
|
|
82
|
+
const { record } = decoded;
|
|
83
|
+
const parsed = parseAllowedSigners(input.allowedSignersText);
|
|
84
|
+
if (parsed.errors.length > 0) {
|
|
85
|
+
return unverifiable(`allowed_signers policy is malformed: ${parsed.errors.map((error) => `line ${error.line}: ${error.message}`).join('; ')}`);
|
|
86
|
+
}
|
|
87
|
+
if (parsed.entries.length === 0)
|
|
88
|
+
return unverifiable('allowed_signers policy has no signer entries');
|
|
89
|
+
// Option (b): publisherKeyId and allowed_signers key fingerprints share the
|
|
90
|
+
// keyidFromBlob SHA256:<unpadded-base64> convention. This keeps verification
|
|
91
|
+
// to one OpenSSH attempt for the normal one-principal case.
|
|
92
|
+
const candidates = parsed.entries.filter((entry) => keyidFromBlob(entry.keyBlob) === record.publisherKeyId);
|
|
93
|
+
if (candidates.length === 0) {
|
|
94
|
+
return invalid(`publication signer key '${record.publisherKeyId}' is not present in allowed_signers`);
|
|
95
|
+
}
|
|
96
|
+
const makeSigner = options.signerForPrincipal ?? ((args) => createSshSigner({
|
|
97
|
+
namespace: options.namespace ?? DSSE_SSH_NAMESPACE,
|
|
98
|
+
verify: args,
|
|
99
|
+
}));
|
|
100
|
+
let sawCryptographicMiss = false;
|
|
101
|
+
for (const candidate of candidates) {
|
|
102
|
+
for (const principal of candidate.principals) {
|
|
103
|
+
let signer;
|
|
104
|
+
try {
|
|
105
|
+
signer = makeSigner({ principal, allowedSignersText: input.allowedSignersText });
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
if (error instanceof SshSignerError)
|
|
109
|
+
return unverifiable(error.message);
|
|
110
|
+
return unverifiable(`publication verification setup failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
const result = await dsseVerifyPublication(envelope, signer, { threshold: 1 });
|
|
114
|
+
const verified = result.signers[0];
|
|
115
|
+
if (verified === undefined)
|
|
116
|
+
return invalid('publication signature produced no verified signer');
|
|
117
|
+
if (verified.keyid !== record.publisherKeyId) {
|
|
118
|
+
return invalid(`publication signer key '${verified.keyid}' does not match record publisherKeyId '${record.publisherKeyId}'`);
|
|
119
|
+
}
|
|
120
|
+
if (record.digest !== input.bundleDigest) {
|
|
121
|
+
return invalid(`publication digest '${record.digest}' does not match bundle digest '${input.bundleDigest}'`);
|
|
122
|
+
}
|
|
123
|
+
return { kind: 'verified', publisherKeyId: verified.keyid, principal: verified.principal };
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (error instanceof SshSignerError)
|
|
127
|
+
return unverifiable(error.message);
|
|
128
|
+
if (error instanceof DsseEnvelopeError) {
|
|
129
|
+
// A malformed envelope is an invalid present signature. Only the
|
|
130
|
+
// explicit threshold miss is the cryptographic-miss form that can be
|
|
131
|
+
// retried with another principal attached to the same key.
|
|
132
|
+
if (error.message.startsWith('DSSE verification failed:')) {
|
|
133
|
+
sawCryptographicMiss = true;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
return invalid(`publication verification failed: ${error.message}`);
|
|
137
|
+
}
|
|
138
|
+
return invalid(`publication verification failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
signer.dispose?.();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (sawCryptographicMiss)
|
|
146
|
+
return invalid('publication signature could not be verified by an allowed signer');
|
|
147
|
+
return invalid('publication signature did not verify');
|
|
148
|
+
}
|
|
149
|
+
/** Alias naming the sidecar explicitly for callers at filesystem boundaries. */
|
|
150
|
+
export const verifyPublicationSidecar = verifyPublication;
|