@countinghouse/ch-local 0.0.0-stage → 1.0.0
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/LICENSE +202 -0
- package/README.md +361 -2
- package/bin/ch-local.js +472 -0
- package/clients/claude-code/.claude-plugin/plugin.json +6 -0
- package/clients/claude-code/.mcp.json +11 -0
- package/clients/claude-code/bin/launch.js +235 -0
- package/clients/claude-code/bin/win-acl.js +420 -0
- package/clients/claude-code/skills/ci-failure-triage/SKILL.md +21 -0
- package/clients/claude-code/skills/countinghouse-module/SKILL.md +177 -0
- package/clients/claude-code/skills/countinghouse-setup/SKILL.md +74 -0
- package/lib/allowlist.js +65 -0
- package/lib/aside.js +16 -0
- package/lib/atomic.js +45 -0
- package/lib/auto-apply.js +245 -0
- package/lib/auto-upgrade.js +98 -0
- package/lib/availability.js +307 -0
- package/lib/ceiling.js +280 -0
- package/lib/clean-text.js +20 -0
- package/lib/cli-change.js +38 -0
- package/lib/client-conditions-fixtures.js +143 -0
- package/lib/client-conditions.js +656 -0
- package/lib/clients.js +179 -0
- package/lib/command-line.js +202 -0
- package/lib/conditions-command.js +116 -0
- package/lib/control.js +134 -0
- package/lib/credential-store.js +414 -0
- package/lib/credentials-command.js +344 -0
- package/lib/daemon-requests.js +137 -0
- package/lib/daemon.js +888 -0
- package/lib/describe-module.js +137 -0
- package/lib/description-check.js +175 -0
- package/lib/failed-json.js +43 -0
- package/lib/gc.js +274 -0
- package/lib/github-token.js +57 -0
- package/lib/handoff-io.js +73 -0
- package/lib/held-back.js +116 -0
- package/lib/hidden-input.js +64 -0
- package/lib/history.js +49 -0
- package/lib/home.js +372 -0
- package/lib/in-place.js +1036 -0
- package/lib/install-plan.js +142 -0
- package/lib/install.js +846 -0
- package/lib/installed-description.js +153 -0
- package/lib/integrity.js +7 -0
- package/lib/lock.js +456 -0
- package/lib/lockfile-rules.js +98 -0
- package/lib/machine.js +20 -0
- package/lib/module-credentials.js +403 -0
- package/lib/module-record.js +298 -0
- package/lib/module-roles.js +44 -0
- package/lib/module-seams.js +26 -0
- package/lib/module-store.js +202 -0
- package/lib/module-values.js +334 -0
- package/lib/names.js +31 -0
- package/lib/next-steps.js +8 -0
- package/lib/node-check.js +56 -0
- package/lib/npm-fetch.js +123 -0
- package/lib/npm-release.js +99 -0
- package/lib/npm-upgrade.js +146 -0
- package/lib/npm.js +41 -0
- package/lib/outside-edits.js +162 -0
- package/lib/own-applied.js +175 -0
- package/lib/own-command.js +380 -0
- package/lib/own-file.js +120 -0
- package/lib/own-record.js +96 -0
- package/lib/own-tree.js +336 -0
- package/lib/pack-table.js +290 -0
- package/lib/packs-command.js +570 -0
- package/lib/packs.js +219 -0
- package/lib/pins.js +64 -0
- package/lib/pipe-probe.js +82 -0
- package/lib/plain-read.js +63 -0
- package/lib/private-file.js +90 -0
- package/lib/private-write.js +33 -0
- package/lib/provenance.js +234 -0
- package/lib/record.js +82 -0
- package/lib/registry.js +22 -0
- package/lib/release-pins.js +350 -0
- package/lib/release-pins.json +4225 -0
- package/lib/release-tags.js +12 -0
- package/lib/release.js +36 -0
- package/lib/restart-command.js +161 -0
- package/lib/rollback.js +227 -0
- package/lib/run-liveness.js +15 -0
- package/lib/runtime-log.js +287 -0
- package/lib/sandbox-support.js +17 -0
- package/lib/semver-order.js +40 -0
- package/lib/session-socket.js +69 -0
- package/lib/session-table.js +238 -0
- package/lib/session.js +281 -0
- package/lib/settings-command.js +82 -0
- package/lib/settings.js +564 -0
- package/lib/shim-binary.js +152 -0
- package/lib/shim-config.js +159 -0
- package/lib/shim-install.js +365 -0
- package/lib/sigstore/README.md +44 -0
- package/lib/sigstore/npm-keys.json +18 -0
- package/lib/sigstore/trusted-root.json +126 -0
- package/lib/snippets.js +76 -0
- package/lib/start.js +721 -0
- package/lib/store-files.js +48 -0
- package/lib/store-paths.js +33 -0
- package/lib/swap-preload.js +38 -0
- package/lib/tar.js +220 -0
- package/lib/uninstall.js +314 -0
- package/lib/unpack.js +41 -0
- package/lib/upgrade-stamp.js +63 -0
- package/lib/upgrade.js +281 -0
- package/lib/watch.js +40 -0
- package/lib/win-acl.js +420 -0
- package/node_modules/@sigstore/bundle/LICENSE +202 -0
- package/node_modules/@sigstore/bundle/README.md +19 -0
- package/node_modules/@sigstore/bundle/dist/build.d.ts +18 -0
- package/node_modules/@sigstore/bundle/dist/build.js +100 -0
- package/node_modules/@sigstore/bundle/dist/bundle.d.ts +74 -0
- package/node_modules/@sigstore/bundle/dist/bundle.js +24 -0
- package/node_modules/@sigstore/bundle/dist/error.d.ts +4 -0
- package/node_modules/@sigstore/bundle/dist/error.js +25 -0
- package/node_modules/@sigstore/bundle/dist/index.d.ts +8 -0
- package/node_modules/@sigstore/bundle/dist/index.js +43 -0
- package/node_modules/@sigstore/bundle/dist/serialized.d.ts +74 -0
- package/node_modules/@sigstore/bundle/dist/serialized.js +49 -0
- package/node_modules/@sigstore/bundle/dist/utility.d.ts +14 -0
- package/node_modules/@sigstore/bundle/dist/utility.js +2 -0
- package/node_modules/@sigstore/bundle/dist/validate.d.ts +7 -0
- package/node_modules/@sigstore/bundle/dist/validate.js +199 -0
- package/node_modules/@sigstore/bundle/package.json +35 -0
- package/node_modules/@sigstore/core/LICENSE +202 -0
- package/node_modules/@sigstore/core/README.md +10 -0
- package/node_modules/@sigstore/core/dist/asn1/error.d.ts +4 -0
- package/node_modules/@sigstore/core/dist/asn1/error.js +24 -0
- package/node_modules/@sigstore/core/dist/asn1/index.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/asn1/index.js +20 -0
- package/node_modules/@sigstore/core/dist/asn1/length.d.ts +3 -0
- package/node_modules/@sigstore/core/dist/asn1/length.js +62 -0
- package/node_modules/@sigstore/core/dist/asn1/obj.d.ts +14 -0
- package/node_modules/@sigstore/core/dist/asn1/obj.js +155 -0
- package/node_modules/@sigstore/core/dist/asn1/parse.d.ts +6 -0
- package/node_modules/@sigstore/core/dist/asn1/parse.js +124 -0
- package/node_modules/@sigstore/core/dist/asn1/tag.d.ts +16 -0
- package/node_modules/@sigstore/core/dist/asn1/tag.js +89 -0
- package/node_modules/@sigstore/core/dist/crypto.d.ts +6 -0
- package/node_modules/@sigstore/core/dist/crypto.js +69 -0
- package/node_modules/@sigstore/core/dist/dsse.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/dsse.js +29 -0
- package/node_modules/@sigstore/core/dist/encoding.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/encoding.js +27 -0
- package/node_modules/@sigstore/core/dist/index.d.ts +9 -0
- package/node_modules/@sigstore/core/dist/index.js +66 -0
- package/node_modules/@sigstore/core/dist/json.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/json.js +60 -0
- package/node_modules/@sigstore/core/dist/oid.d.ts +3 -0
- package/node_modules/@sigstore/core/dist/oid.js +20 -0
- package/node_modules/@sigstore/core/dist/pem.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/pem.js +43 -0
- package/node_modules/@sigstore/core/dist/rfc3161/error.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/rfc3161/error.js +21 -0
- package/node_modules/@sigstore/core/dist/rfc3161/index.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/rfc3161/index.js +20 -0
- package/node_modules/@sigstore/core/dist/rfc3161/timestamp.d.ts +36 -0
- package/node_modules/@sigstore/core/dist/rfc3161/timestamp.js +212 -0
- package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.d.ts +12 -0
- package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.js +72 -0
- package/node_modules/@sigstore/core/dist/stream.d.ts +21 -0
- package/node_modules/@sigstore/core/dist/stream.js +117 -0
- package/node_modules/@sigstore/core/dist/x509/cert.d.ts +43 -0
- package/node_modules/@sigstore/core/dist/x509/cert.js +245 -0
- package/node_modules/@sigstore/core/dist/x509/ext.d.ts +41 -0
- package/node_modules/@sigstore/core/dist/x509/ext.js +146 -0
- package/node_modules/@sigstore/core/dist/x509/index.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/x509/index.js +23 -0
- package/node_modules/@sigstore/core/dist/x509/sct.d.ts +25 -0
- package/node_modules/@sigstore/core/dist/x509/sct.js +158 -0
- package/node_modules/@sigstore/core/package.json +31 -0
- package/node_modules/@sigstore/protobuf-specs/LICENSE +202 -0
- package/node_modules/@sigstore/protobuf-specs/README.md +5 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.d.ts +44 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.js +59 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.d.ts +64 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.js +174 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.d.ts +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.js +141 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.d.ts +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.js +35 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.d.ts +1309 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.js +2191 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.d.ts +113 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.js +29 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.d.ts +23 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.js +55 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.d.ts +43 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.js +81 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.d.ts +22 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.js +56 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.d.ts +35 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.js +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.d.ts +146 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.js +103 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.d.ts +304 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.js +612 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.d.ts +33 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.js +55 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.d.ts +144 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.js +137 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.d.ts +386 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.js +284 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.d.ts +191 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.js +281 -0
- package/node_modules/@sigstore/protobuf-specs/dist/index.d.ts +6 -0
- package/node_modules/@sigstore/protobuf-specs/dist/index.js +37 -0
- package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.d.ts +4 -0
- package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.js +35 -0
- package/node_modules/@sigstore/protobuf-specs/package.json +35 -0
- package/node_modules/@sigstore/verify/README.md +9 -0
- package/node_modules/@sigstore/verify/dist/bundle/dsse.d.ts +12 -0
- package/node_modules/@sigstore/verify/dist/bundle/dsse.js +44 -0
- package/node_modules/@sigstore/verify/dist/bundle/index.d.ts +4 -0
- package/node_modules/@sigstore/verify/dist/bundle/index.js +59 -0
- package/node_modules/@sigstore/verify/dist/bundle/message.d.ts +13 -0
- package/node_modules/@sigstore/verify/dist/bundle/message.js +54 -0
- package/node_modules/@sigstore/verify/dist/error.d.ts +16 -0
- package/node_modules/@sigstore/verify/dist/error.js +34 -0
- package/node_modules/@sigstore/verify/dist/index.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/index.js +28 -0
- package/node_modules/@sigstore/verify/dist/key/certificate.d.ts +21 -0
- package/node_modules/@sigstore/verify/dist/key/certificate.js +216 -0
- package/node_modules/@sigstore/verify/dist/key/index.d.ts +10 -0
- package/node_modules/@sigstore/verify/dist/key/index.js +75 -0
- package/node_modules/@sigstore/verify/dist/key/sct.d.ts +4 -0
- package/node_modules/@sigstore/verify/dist/key/sct.js +78 -0
- package/node_modules/@sigstore/verify/dist/policy.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/policy.js +50 -0
- package/node_modules/@sigstore/verify/dist/shared.types.d.ts +50 -0
- package/node_modules/@sigstore/verify/dist/shared.types.js +2 -0
- package/node_modules/@sigstore/verify/dist/timestamp/index.d.ts +11 -0
- package/node_modules/@sigstore/verify/dist/timestamp/index.js +24 -0
- package/node_modules/@sigstore/verify/dist/timestamp/tsa.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/timestamp/tsa.js +63 -0
- package/node_modules/@sigstore/verify/dist/tlog/checkpoint.d.ts +11 -0
- package/node_modules/@sigstore/verify/dist/tlog/checkpoint.js +154 -0
- package/node_modules/@sigstore/verify/dist/tlog/dsse.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/tlog/dsse.js +106 -0
- package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.js +94 -0
- package/node_modules/@sigstore/verify/dist/tlog/index.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/tlog/index.js +92 -0
- package/node_modules/@sigstore/verify/dist/tlog/intoto.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/intoto.js +62 -0
- package/node_modules/@sigstore/verify/dist/tlog/merkle.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/merkle.js +104 -0
- package/node_modules/@sigstore/verify/dist/tlog/set.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/set.js +60 -0
- package/node_modules/@sigstore/verify/dist/trust/filter.d.ts +8 -0
- package/node_modules/@sigstore/verify/dist/trust/filter.js +23 -0
- package/node_modules/@sigstore/verify/dist/trust/index.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/trust/index.js +90 -0
- package/node_modules/@sigstore/verify/dist/trust/trust.types.d.ts +29 -0
- package/node_modules/@sigstore/verify/dist/trust/trust.types.js +2 -0
- package/node_modules/@sigstore/verify/dist/verifier.d.ts +31 -0
- package/node_modules/@sigstore/verify/dist/verifier.js +160 -0
- package/node_modules/@sigstore/verify/package.json +36 -0
- package/package.json +37 -4
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Provenance for an upgrade from npm (docs/development/auto-upgrade.md,
|
|
3
|
+
// "Provenance: exactly what is checked"). A version's attestations, as the
|
|
4
|
+
// registry serves them (/-/npm/v1/attestations/<name>@<version>), must hold
|
|
5
|
+
// exactly one SLSA provenance and one npm publish attestation.
|
|
6
|
+
// - Each is read from the parsed bundle the verifier checks, never the raw
|
|
7
|
+
// JSON: a DSSE envelope, and exactly one Rekor entry with an inclusion
|
|
8
|
+
// promise (the signed entry timestamp covers the integrated time; a proof
|
|
9
|
+
// alone doesn't), else PROVENANCE_LOG.
|
|
10
|
+
// - The SLSA provenance must be signed by a Fulcio certificate, verified by
|
|
11
|
+
// @sigstore/verify against the root's CAs and logs, and no key. The
|
|
12
|
+
// publish attestation must be signed by npm's key, verified against the
|
|
13
|
+
// root's logs and npm's keys, and no CA: anyone can get a certificate.
|
|
14
|
+
// - A CA or a key the trust lacks is PROVENANCE_UNKNOWN_ROOT ("can't verify
|
|
15
|
+
// yet"); a known key outside its window, and any other failure, is
|
|
16
|
+
// PROVENANCE_CHAIN.
|
|
17
|
+
// - The certificate's identity: the issuer and Fulcio's build signer URI
|
|
18
|
+
// (.9), runner (.11), repository URI (.12), ref (.14), repository and owner
|
|
19
|
+
// IDs (.15, .17) and trigger (.20) by the verifier's policy, and the SAN by
|
|
20
|
+
// equality here. Then the predicate must agree with it, the provenance's
|
|
21
|
+
// statement be in-toto v1 and the publish one v0.1 (as npm writes them),
|
|
22
|
+
// and both subjects be pkg:npm/<name>@<version> with the tarball's sha512.
|
|
23
|
+
// Any mismatch is PROVENANCE_IDENTITY.
|
|
24
|
+
// - The log times are read only after verification passes.
|
|
25
|
+
// The trusted root and npm's keys are the ones shipped in lib/sigstore,
|
|
26
|
+
// unless a test passes its own `trust` as an argument: nothing in the
|
|
27
|
+
// environment, argv or a file chooses them.
|
|
28
|
+
// The Sigstore libraries are loaded when a verification runs, never when
|
|
29
|
+
// this module is: start reaches it (through upgrade and npm-upgrade), and
|
|
30
|
+
// what it serves must not depend on them loading.
|
|
31
|
+
const sigstore = () => Object.assign({}, require('@sigstore/verify'), require('@sigstore/bundle'), require('@sigstore/protobuf-specs'));
|
|
32
|
+
|
|
33
|
+
const PROVENANCE = 'https://slsa.dev/provenance/v1';
|
|
34
|
+
const PUBLISH = 'https://github.com/npm/attestation/tree/main/specs/publish/v0.1';
|
|
35
|
+
const ISSUER = 'https://token.actions.githubusercontent.com';
|
|
36
|
+
const BUILD_TYPE = 'https://slsa-framework.github.io/github-actions-buildtypes/workflow/v1';
|
|
37
|
+
const REGISTRY = 'https://registry.npmjs.org';
|
|
38
|
+
// npm writes its SLSA provenance as Statement/v1, its publish attestation as
|
|
39
|
+
// Statement/v0.1 (as its live attestations show: test/fixtures/attestations)
|
|
40
|
+
const STATEMENT_V1 = 'https://in-toto.io/Statement/v1';
|
|
41
|
+
const STATEMENT_V01 = 'https://in-toto.io/Statement/v0.1';
|
|
42
|
+
|
|
43
|
+
const failure = (code, message) => Object.assign(new Error(message), {code});
|
|
44
|
+
const {TAG_PREFIX, tagFor} = require('./release-tags');
|
|
45
|
+
|
|
46
|
+
// npm's key list ({keys: [{keyid, keytype, key, expires}]}) -> the verifier's
|
|
47
|
+
// {keyid: PublicKey}, each valid until its `expires`
|
|
48
|
+
function npmPublicKeys(list) {
|
|
49
|
+
const {PublicKey} = sigstore();
|
|
50
|
+
const keys = {};
|
|
51
|
+
for (const k of (list && Array.isArray(list.keys)) ? list.keys : []) {
|
|
52
|
+
if (k == null || typeof k.keyid !== 'string' || typeof k.key !== 'string' || k.keytype !== 'ecdsa-sha2-nistp256') continue;
|
|
53
|
+
keys[k.keyid] = PublicKey.fromJSON({rawBytes: k.key, keyDetails: 'PKIX_ECDSA_P256_SHA_256',
|
|
54
|
+
validFor: Object.assign({start: '1970-01-01T00:00:00Z'}, k.expires != null ? {end: k.expires} : {})});
|
|
55
|
+
}
|
|
56
|
+
return keys;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// a trusted root (its protobuf JSON) and npm's key list -> the two trust
|
|
60
|
+
// materials, each holding only what its attestation may be signed by (the
|
|
61
|
+
// review of #41):
|
|
62
|
+
// - provenance: the root's CAs, logs and CT logs, and no key, so only a
|
|
63
|
+
// Fulcio certificate verifies;
|
|
64
|
+
// - publish: the root's logs, no CA, and npm's keys alone, so only npm's key
|
|
65
|
+
// verifies (anyone can get a Sigstore certificate).
|
|
66
|
+
function trustMaterial(trustedRoot, npmKeys) {
|
|
67
|
+
const {toTrustMaterial, TrustedRoot} = sigstore();
|
|
68
|
+
const noCAs = Object.assign({}, trustedRoot, {certificateAuthorities: []});
|
|
69
|
+
return {
|
|
70
|
+
provenance: toTrustMaterial(TrustedRoot.fromJSON(trustedRoot), {}),
|
|
71
|
+
publish: toTrustMaterial(TrustedRoot.fromJSON(noCAs), npmPublicKeys(npmKeys))
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let bundled = null;
|
|
76
|
+
const bundledTrust = () => {
|
|
77
|
+
if (bundled == null) bundled = trustMaterial(require('./sigstore/trusted-root.json'), require('./sigstore/npm-keys.json'));
|
|
78
|
+
return bundled;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// DER UTF8String of s (with DER's long length form): how Fulcio encodes its
|
|
82
|
+
// extensions' values
|
|
83
|
+
const utf8Der = (s) => {
|
|
84
|
+
const body = Buffer.from(s, 'utf8');
|
|
85
|
+
if (body.length < 0x80) return Buffer.concat([Buffer.from([0x0c, body.length]), body]);
|
|
86
|
+
const len = [];
|
|
87
|
+
for (let v = body.length; v > 0; v >>= 8) len.unshift(v & 0xff);
|
|
88
|
+
return Buffer.concat([Buffer.from([0x0c, 0x80 | len.length, ...len]), body]);
|
|
89
|
+
};
|
|
90
|
+
const fulcio = (n, value) => ({oid: {id: [1, 3, 6, 1, 4, 1, 57264, 1, n]}, value: utf8Der(value)});
|
|
91
|
+
const purl = (name, version) => `pkg:npm/${name.replace(/^@/, '%40')}@${version}`;
|
|
92
|
+
const SHA512 = /^sha512-[A-Za-z0-9+/]{86}==$/;
|
|
93
|
+
|
|
94
|
+
function pinProblem(pin, version) {
|
|
95
|
+
if (pin == null || typeof pin !== 'object') return 'no pin';
|
|
96
|
+
if (pin.version !== version) return `the pin is for ${pin.version}, not ${version}`;
|
|
97
|
+
if (typeof pin.integrity !== 'string' || !SHA512.test(pin.integrity)) return 'the pin has no sha512 integrity';
|
|
98
|
+
if (typeof pin.tag !== 'string' || !/^[A-Za-z0-9_.-]+$/.test(pin.tag)) return 'the pin names no tag';
|
|
99
|
+
const why = identityProblem(pin);
|
|
100
|
+
if (why != null) return why;
|
|
101
|
+
// exactly its workflow's prefix and its version, for every pin, ch-local's
|
|
102
|
+
// own (built in memory by lib/npm-release.js) included
|
|
103
|
+
const want = tagFor(pin.workflow, version);
|
|
104
|
+
if (want == null) return `the pin's workflow ${pin.workflow} builds no release`;
|
|
105
|
+
if (pin.tag !== want) return `the pin's tag is ${pin.tag}, not ${want}`;
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
function identityProblem(id) {
|
|
109
|
+
if (typeof id.repository !== 'string' || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(id.repository)) return 'no repository';
|
|
110
|
+
for (const k of ['repositoryId', 'ownerId']) if (!Number.isSafeInteger(id[k]) || id[k] <= 0) return `${k} is not a positive integer`;
|
|
111
|
+
if (typeof id.workflow !== 'string' || !/^\.github\/workflows\/[A-Za-z0-9_.-]+\.ya?ml$/.test(id.workflow)) return 'no workflow';
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// a raw bundle -> {parsed, entity}: what the verifier checks, and what is read
|
|
116
|
+
// afterwards (the review of #41: never the raw JSON, which the parsed bundle
|
|
117
|
+
// may differ from); its content must be a DSSE envelope, and exactly one log
|
|
118
|
+
// entry, with an inclusion promise
|
|
119
|
+
function parse(raw, what, key) {
|
|
120
|
+
const {bundleFromJSON, toSignedEntity} = sigstore();
|
|
121
|
+
let parsed;
|
|
122
|
+
try {
|
|
123
|
+
parsed = bundleFromJSON(raw);
|
|
124
|
+
} catch (e) {
|
|
125
|
+
throw failure('PROVENANCE_CHAIN', `${what} is not a valid bundle (${e.message})`);
|
|
126
|
+
}
|
|
127
|
+
if (parsed.content == null || parsed.content.$case !== 'dsseEnvelope') throw failure('PROVENANCE_CHAIN', `${what} is not a DSSE envelope`);
|
|
128
|
+
const material = parsed.verificationMaterial != null && parsed.verificationMaterial.content != null ? parsed.verificationMaterial.content.$case : null;
|
|
129
|
+
if (material !== key) throw failure('PROVENANCE_CHAIN', `${what} must be signed by ${key === 'certificate' ? 'a Fulcio certificate' : 'npm\'s key'}, not ${material}`);
|
|
130
|
+
const entries = parsed.verificationMaterial.tlogEntries;
|
|
131
|
+
if (!Array.isArray(entries) || entries.length !== 1) throw failure('PROVENANCE_LOG', `${what} has ${Array.isArray(entries) ? entries.length : 'no'} log entries, not exactly one`);
|
|
132
|
+
if (entries[0] == null || entries[0].inclusionPromise == null) throw failure('PROVENANCE_LOG', `${what}'s log entry has no inclusion promise`);
|
|
133
|
+
let entity;
|
|
134
|
+
try {
|
|
135
|
+
entity = toSignedEntity(parsed);
|
|
136
|
+
} catch (e) {
|
|
137
|
+
throw failure('PROVENANCE_CHAIN', `${what} is not a valid bundle (${e.message})`);
|
|
138
|
+
}
|
|
139
|
+
return {parsed, entity, entry: entries[0]};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// verified by the trust -> the signer; failures as PROVENANCE_* codes
|
|
143
|
+
function verifyEntity(entity, trust, policy, what) {
|
|
144
|
+
const {Verifier} = sigstore();
|
|
145
|
+
try {
|
|
146
|
+
return new Verifier(trust).verify(entity, policy);
|
|
147
|
+
} catch (e) {
|
|
148
|
+
if (e != null && e.name === 'PolicyError') throw failure('PROVENANCE_IDENTITY', `${what}: ${e.message}`);
|
|
149
|
+
const cause = e != null && e.cause != null ? String(e.cause.message) : '';
|
|
150
|
+
if (e != null && e.code === 'CERTIFICATE_ERROR' && /certificate path found/.test(cause)) throw failure('PROVENANCE_UNKNOWN_ROOT', `${what} is signed under a CA this ch-local does not know`);
|
|
151
|
+
// a key the list lacks; one it holds, used outside its window, is a
|
|
152
|
+
// chain failure (the review of #41)
|
|
153
|
+
if (e != null && e.code === 'PUBLIC_KEY_ERROR' && /key not found/.test(String(e.message))) throw failure('PROVENANCE_UNKNOWN_ROOT', `${what} is signed by a key this ch-local does not know`);
|
|
154
|
+
const detail = (e && e.code ? e.code + ': ' : '') + (e && e.message);
|
|
155
|
+
throw failure('PROVENANCE_CHAIN', `${what} did not verify (${detail})`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function statementOf(parsed, type, what) {
|
|
160
|
+
try {
|
|
161
|
+
const st = JSON.parse(Buffer.from(parsed.content.dsseEnvelope.payload).toString('utf8'));
|
|
162
|
+
if (st == null || st._type !== type) throw new Error(`not an in-toto ${type} statement`);
|
|
163
|
+
return st;
|
|
164
|
+
} catch (e) {
|
|
165
|
+
throw failure('PROVENANCE_IDENTITY', `${what}'s statement could not be read (${e.message})`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function subjectOk(st, name, version, sha512Hex) {
|
|
170
|
+
return Array.isArray(st.subject) && st.subject.length === 1 && st.subject[0] != null && st.subject[0].name === purl(name, version) &&
|
|
171
|
+
st.subject[0].digest != null && st.subject[0].digest.sha512 === sha512Hex;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const sameJson = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
175
|
+
|
|
176
|
+
// {name, version, integrity, identity: {repository, repositoryId, ownerId,
|
|
177
|
+
// workflow, ref}, attestations, trust?} -> {builtAt, publishedAt}
|
|
178
|
+
function verifyAttestations({name, version, integrity, identity, attestations, trust = null}) {
|
|
179
|
+
if (typeof integrity !== 'string' || !SHA512.test(integrity)) throw failure('PIN_INCOMPLETE', `${name}@${version}: no sha512 integrity`);
|
|
180
|
+
const why = identity != null ? identityProblem(identity) : 'no identity';
|
|
181
|
+
if (why != null || typeof identity.ref !== 'string' || !/^refs\/(tags|heads)\/[A-Za-z0-9_./-]+$/.test(identity.ref)) throw failure('PIN_INCOMPLETE', `${name}@${version}: ${why || 'no ref'}`);
|
|
182
|
+
const list = attestations != null && Array.isArray(attestations.attestations) ? attestations.attestations : [];
|
|
183
|
+
const of = (type) => list.filter((a) => a != null && a.predicateType === type);
|
|
184
|
+
if (of(PROVENANCE).length !== 1 || of(PUBLISH).length !== 1) throw failure('NO_PROVENANCE', `${name}@${version} has no provenance`);
|
|
185
|
+
const material = trust != null ? trust : bundledTrust();
|
|
186
|
+
const sha512Hex = Buffer.from(integrity.slice('sha512-'.length), 'base64').toString('hex');
|
|
187
|
+
const {ref} = identity;
|
|
188
|
+
const repoUrl = `https://github.com/${identity.repository}`;
|
|
189
|
+
const san = `${repoUrl}/${identity.workflow}@${ref}`;
|
|
190
|
+
|
|
191
|
+
// the SLSA provenance: a Fulcio certificate, its chain, then its identity:
|
|
192
|
+
// the verifier's policy for the issuer and the OIDs (the build signer URI,
|
|
193
|
+
// .9, among them), and the SAN compared exactly here (the verifier's own
|
|
194
|
+
// SAN check is a pattern, not an equality)
|
|
195
|
+
const prov = parse(of(PROVENANCE)[0].bundle, 'the provenance', 'certificate');
|
|
196
|
+
const signer = verifyEntity(prov.entity, material.provenance, {
|
|
197
|
+
extensions: {issuer: ISSUER},
|
|
198
|
+
oids: [fulcio(9, san), fulcio(11, 'github-hosted'), fulcio(12, repoUrl), fulcio(14, ref), fulcio(15, String(identity.repositoryId)), fulcio(17, String(identity.ownerId)), fulcio(20, 'push')]
|
|
199
|
+
}, 'the provenance');
|
|
200
|
+
if (signer.identity == null || signer.identity.subjectAlternativeName !== san) {
|
|
201
|
+
throw failure('PROVENANCE_IDENTITY', `the provenance was signed by ${signer.identity != null ? signer.identity.subjectAlternativeName : 'no identity'}, not ${san}`);
|
|
202
|
+
}
|
|
203
|
+
const st = statementOf(prov.parsed, STATEMENT_V1, 'the provenance');
|
|
204
|
+
if (st.predicateType !== PROVENANCE || !subjectOk(st, name, version, sha512Hex)) throw failure('PROVENANCE_IDENTITY', `the provenance is not for ${name}@${version} with this tarball`);
|
|
205
|
+
const def = st.predicate != null ? st.predicate.buildDefinition : null;
|
|
206
|
+
const wf = def != null && def.externalParameters != null ? def.externalParameters.workflow : null;
|
|
207
|
+
const gh = def != null && def.internalParameters != null ? def.internalParameters.github : null;
|
|
208
|
+
if (def == null || def.buildType !== BUILD_TYPE || !sameJson(wf, {ref, repository: repoUrl, path: identity.workflow}) || gh == null || gh.event_name !== 'push') {
|
|
209
|
+
throw failure('PROVENANCE_IDENTITY', 'the provenance\'s predicate does not agree with its certificate');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// npm's publish attestation: npm's key, and nothing else
|
|
213
|
+
const pub = parse(of(PUBLISH)[0].bundle, 'the publish attestation', 'publicKey');
|
|
214
|
+
verifyEntity(pub.entity, material.publish, undefined, 'the publish attestation');
|
|
215
|
+
const ps = statementOf(pub.parsed, STATEMENT_V01, 'the publish attestation');
|
|
216
|
+
if (ps.predicateType !== PUBLISH || !subjectOk(ps, name, version, sha512Hex) || !sameJson(ps.predicate, {name, version, registry: REGISTRY})) {
|
|
217
|
+
throw failure('PROVENANCE_IDENTITY', `the publish attestation is not npm's for ${name}@${version} with this tarball`);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// the log times, from the parsed bundles, only now
|
|
221
|
+
const seconds = (e) => new Date(Number(e.integratedTime) * 1000);
|
|
222
|
+
return {builtAt: seconds(prov.entry), publishedAt: seconds(pub.entry)};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// {name, version, pin, attestations, trust?} -> {builtAt, publishedAt}: a
|
|
226
|
+
// release's package, built from its pinned repository's workflow at its tag
|
|
227
|
+
function verifyRelease({name, version, pin, attestations, trust = null}) {
|
|
228
|
+
const why = pinProblem(pin, version);
|
|
229
|
+
if (why != null) throw failure('PIN_INCOMPLETE', `${name}@${version}: ${why}`);
|
|
230
|
+
return verifyAttestations({name, version, integrity: pin.integrity, attestations, trust,
|
|
231
|
+
identity: {repository: pin.repository, repositoryId: pin.repositoryId, ownerId: pin.ownerId, workflow: pin.workflow, ref: `refs/tags/${pin.tag}`}});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
module.exports = {verifyRelease, verifyAttestations, trustMaterial, npmPublicKeys, tagFor, TAG_PREFIX, PROVENANCE, PUBLISH};
|
package/lib/record.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// <home>/packs.json: what the home holds (reviewer, 2026-11-12).
|
|
3
|
+
// {runtime: {versions: {name: version}},
|
|
4
|
+
// packs: {<pack>: {packages: {name: version}, credentials: [variable, ...]}},
|
|
5
|
+
// unreleased: true|false, release: {version, security: null | {fixes}},
|
|
6
|
+
// held?: {<pack>: {packages, credentials, installedUnder: <ch-local version>, withdrawn?: true, relisted?: true}}, at}
|
|
7
|
+
// held: packs a rollback's restored release does not have (lib/rollback.js),
|
|
8
|
+
// and packs an upgrade's release withdrew (withdrawn: true; lib/install.js's
|
|
9
|
+
// runtime-only path), relisted once a later release lists one again (its
|
|
10
|
+
// files kept, for add-pack). None is started, loaded or counted as installed.
|
|
11
|
+
// unreleased is true once anything was installed with --unreleased-pins, and
|
|
12
|
+
// stays so until a clean install from a release.
|
|
13
|
+
const fs = require('node:fs');
|
|
14
|
+
const {writeAtomic} = require('./atomic');
|
|
15
|
+
const {chLocal} = require('./command-line');
|
|
16
|
+
|
|
17
|
+
// -> the record, or null when nothing is installed. Throws when it cannot be read.
|
|
18
|
+
function readRecord(where) {
|
|
19
|
+
if (where.journal != null && fs.existsSync(where.journal)) {
|
|
20
|
+
throw new Error(`a rollback was interrupted; run \`${chLocal(where, 'rollback')}\` to finish it`);
|
|
21
|
+
}
|
|
22
|
+
let raw;
|
|
23
|
+
try {
|
|
24
|
+
raw = fs.readFileSync(where.packs, 'utf8');
|
|
25
|
+
} catch (err) {
|
|
26
|
+
if (err.code === 'ENOENT') {
|
|
27
|
+
// Only an unreleased development launcher wrote installed.json.
|
|
28
|
+
if (where.installed == null) return null;
|
|
29
|
+
let old = null;
|
|
30
|
+
try { old = JSON.parse(fs.readFileSync(where.installed, 'utf8')); } catch (e) { if (e.code === 'ENOENT') return null; }
|
|
31
|
+
const pack = old != null && typeof old.pack === 'string' ? old.pack : '<name>';
|
|
32
|
+
throw Object.assign(new Error(`this home was made by an earlier development ch-local; run \`${chLocal(where, `install --pack ${pack} --from <dir>`)}\` again`), {code: 'RECORD_EARLIER_DEV', reason: 'this home was made by an earlier development ch-local'});
|
|
33
|
+
}
|
|
34
|
+
throw Object.assign(new Error(`${where.packs} is not readable (${err.code}); ${require('./module-record').ioAdvice(where.packs)}`), {code: 'RECORD_IO', reason: `${where.packs} is not readable (${err.code})`});
|
|
35
|
+
}
|
|
36
|
+
let r;
|
|
37
|
+
try { r = JSON.parse(raw); } catch (err) { r = null; }
|
|
38
|
+
const isObject = (x) => x != null && typeof x === 'object' && !Array.isArray(x);
|
|
39
|
+
// names and versions as a release writes them: a pack's name and a
|
|
40
|
+
// version become directory names (packs in place), so nothing else passes
|
|
41
|
+
const {VERSION, PACKAGE, PACK} = require('./names');
|
|
42
|
+
const versions = (x) => isObject(x) && Object.entries(x).every(([n, v]) => typeof v === 'string' && VERSION.test(v) && PACKAGE.test(n));
|
|
43
|
+
const pack = (p) => isObject(p) && versions(p.packages) && Array.isArray(p.credentials) && p.credentials.every((c) => typeof c === 'string');
|
|
44
|
+
const heldOk = (h) => h === undefined || (isObject(h) && Object.values(h).every((p) => pack(p) && typeof p.installedUnder === 'string' && (p.withdrawn === undefined || p.withdrawn === true) && (p.relisted === undefined || p.relisted === true) && !(p.withdrawn === true && p.relisted === true)));
|
|
45
|
+
const releaseOk = (x) => x == null || (isObject(x) && (x.version == null || typeof x.version === 'string') && (x.security == null || (isObject(x.security) && typeof x.security.fixes === 'string')));
|
|
46
|
+
const packNames = (o) => o === undefined || Object.keys(o).every((n) => PACK.test(n));
|
|
47
|
+
// the native shim install placed (lib/shim-install.js), when it did
|
|
48
|
+
const shimOk = (x) => x === undefined || (isObject(x) && typeof x.package === 'string' && PACKAGE.test(x.package) && typeof x.version === 'string' && VERSION.test(x.version));
|
|
49
|
+
if (!isObject(r) || !isObject(r.packs) || !isObject(r.runtime) || !versions(r.runtime.versions) || !Object.values(r.packs).every(pack) || !heldOk(r.held) || !releaseOk(r.release)
|
|
50
|
+
|| !packNames(r.packs) || !packNames(r.held) || !shimOk(r.shim)) {
|
|
51
|
+
throw Object.assign(new Error(`${where.packs} is not a ch-local record; run \`${chLocal(where, 'install')}\` again`), {code: 'RECORD_FORMAT', reason: `${where.packs} is not a ch-local record`});
|
|
52
|
+
}
|
|
53
|
+
return {runtime: r.runtime, packs: r.packs, unreleased: r.unreleased === true, release: r.release != null ? r.release : null, ...(r.held !== undefined ? {held: r.held} : {}), ...(r.shim !== undefined ? {shim: {package: r.shim.package, version: r.shim.version}} : {}), at: r.at};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function writeRecord(where, record) {
|
|
57
|
+
writeAtomic(where.packs, JSON.stringify({...record, at: new Date().toISOString()}, null, 2) + '\n');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Every package a home's packs hold -> version.
|
|
61
|
+
function packVersions(record) {
|
|
62
|
+
const out = {};
|
|
63
|
+
for (const p of Object.values(record.packs)) Object.assign(out, p.packages);
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const {own} = require('./module-record');
|
|
68
|
+
|
|
69
|
+
// The record without its held packs (withHeld's base; held packs are never
|
|
70
|
+
// dropped from a record that is kept: lib/install.js carriedHeld).
|
|
71
|
+
function withoutHeld(record) {
|
|
72
|
+
const {held: _held, ...rest} = record;
|
|
73
|
+
void _held;
|
|
74
|
+
return rest;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The record with exactly these held packs (none: no held field).
|
|
78
|
+
function withHeld(record, held) {
|
|
79
|
+
return {...withoutHeld(record), ...(held != null && Object.keys(held).length > 0 ? {held} : {})};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
module.exports = {readRecord, writeRecord, packVersions, own, withHeld};
|
package/lib/registry.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The npm registry, asked only by `ch-local upgrade` (spec §2: the only command
|
|
3
|
+
// that contacts it besides install, and only when the user runs it), and by
|
|
4
|
+
// start's automatic check when the user has turned automatic upgrades on
|
|
5
|
+
// (lib/auto-upgrade.js; packs in place, part 2).
|
|
6
|
+
const REGISTRY = 'https://registry.npmjs.org/';
|
|
7
|
+
|
|
8
|
+
// [names] -> {name: latest version | null when npm does not have it}.
|
|
9
|
+
// signal: an AbortSignal that abandons the lookups (start's automatic check).
|
|
10
|
+
async function latestVersions(names, io, {signal} = {}) {
|
|
11
|
+
const one = async (name) => {
|
|
12
|
+
const res = await io.fetch(REGISTRY + name.replace('/', '%2F'), {headers: {accept: 'application/vnd.npm.install-v1+json'}, ...(signal != null ? {signal} : {})});
|
|
13
|
+
if (res.status === 404) return null;
|
|
14
|
+
if (!res.ok) throw new Error(`the npm registry answered ${res.status} for ${name}`);
|
|
15
|
+
const body = await res.json();
|
|
16
|
+
return body != null && body['dist-tags'] != null && typeof body['dist-tags'].latest === 'string' ? body['dist-tags'].latest : null;
|
|
17
|
+
};
|
|
18
|
+
const latest = await Promise.all(names.map(one));
|
|
19
|
+
return Object.fromEntries(names.map((name, i) => [name, latest[i]]));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = {latestVersions};
|