@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,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Verifier = exports.toTrustMaterial = exports.VerificationError = exports.PolicyError = exports.toSignedEntity = void 0;
|
|
4
|
+
/* istanbul ignore file */
|
|
5
|
+
/*
|
|
6
|
+
Copyright 2023 The Sigstore Authors.
|
|
7
|
+
|
|
8
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
you may not use this file except in compliance with the License.
|
|
10
|
+
You may obtain a copy of the License at
|
|
11
|
+
|
|
12
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
|
|
14
|
+
Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
See the License for the specific language governing permissions and
|
|
18
|
+
limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
var bundle_1 = require("./bundle");
|
|
21
|
+
Object.defineProperty(exports, "toSignedEntity", { enumerable: true, get: function () { return bundle_1.toSignedEntity; } });
|
|
22
|
+
var error_1 = require("./error");
|
|
23
|
+
Object.defineProperty(exports, "PolicyError", { enumerable: true, get: function () { return error_1.PolicyError; } });
|
|
24
|
+
Object.defineProperty(exports, "VerificationError", { enumerable: true, get: function () { return error_1.VerificationError; } });
|
|
25
|
+
var trust_1 = require("./trust");
|
|
26
|
+
Object.defineProperty(exports, "toTrustMaterial", { enumerable: true, get: function () { return trust_1.toTrustMaterial; } });
|
|
27
|
+
var verifier_1 = require("./verifier");
|
|
28
|
+
Object.defineProperty(exports, "Verifier", { enumerable: true, get: function () { return verifier_1.Verifier; } });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { X509Certificate } from '@sigstore/core';
|
|
2
|
+
import { CertAuthority } from '../trust';
|
|
3
|
+
export declare function verifyCertificateChain(timestamp: Date, leaf: X509Certificate, certificateAuthorities: CertAuthority[]): X509Certificate[];
|
|
4
|
+
interface CertificateChainVerifierOptions {
|
|
5
|
+
trustedCerts: X509Certificate[];
|
|
6
|
+
untrustedCert: X509Certificate;
|
|
7
|
+
timestamp: Date;
|
|
8
|
+
}
|
|
9
|
+
export declare class CertificateChainVerifier {
|
|
10
|
+
private untrustedCert;
|
|
11
|
+
private trustedCerts;
|
|
12
|
+
private localCerts;
|
|
13
|
+
private timestamp;
|
|
14
|
+
constructor(opts: CertificateChainVerifierOptions);
|
|
15
|
+
verify(): X509Certificate[];
|
|
16
|
+
private sort;
|
|
17
|
+
private buildPaths;
|
|
18
|
+
private findIssuer;
|
|
19
|
+
private checkPath;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CertificateChainVerifier = void 0;
|
|
4
|
+
exports.verifyCertificateChain = verifyCertificateChain;
|
|
5
|
+
const error_1 = require("../error");
|
|
6
|
+
const trust_1 = require("../trust");
|
|
7
|
+
function verifyCertificateChain(timestamp, leaf, certificateAuthorities) {
|
|
8
|
+
// Filter list of trusted CAs to those which are valid for the given
|
|
9
|
+
// timestamp
|
|
10
|
+
const cas = (0, trust_1.filterCertAuthorities)(certificateAuthorities, timestamp);
|
|
11
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
12
|
+
let error;
|
|
13
|
+
for (const ca of cas) {
|
|
14
|
+
try {
|
|
15
|
+
const verifier = new CertificateChainVerifier({
|
|
16
|
+
trustedCerts: ca.certChain,
|
|
17
|
+
untrustedCert: leaf,
|
|
18
|
+
timestamp,
|
|
19
|
+
});
|
|
20
|
+
return verifier.verify();
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
error = err;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// If we failed to verify the certificate chain for all of the trusted
|
|
27
|
+
// CAs, throw the last error we encountered.
|
|
28
|
+
throw new error_1.VerificationError({
|
|
29
|
+
code: 'CERTIFICATE_ERROR',
|
|
30
|
+
message: 'Failed to verify certificate chain',
|
|
31
|
+
cause: error,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
class CertificateChainVerifier {
|
|
35
|
+
untrustedCert;
|
|
36
|
+
trustedCerts;
|
|
37
|
+
localCerts;
|
|
38
|
+
timestamp;
|
|
39
|
+
constructor(opts) {
|
|
40
|
+
this.untrustedCert = opts.untrustedCert;
|
|
41
|
+
this.trustedCerts = opts.trustedCerts;
|
|
42
|
+
this.localCerts = dedupeCertificates([
|
|
43
|
+
...opts.trustedCerts,
|
|
44
|
+
opts.untrustedCert,
|
|
45
|
+
]);
|
|
46
|
+
this.timestamp = opts.timestamp;
|
|
47
|
+
}
|
|
48
|
+
verify() {
|
|
49
|
+
// Construct certificate path from leaf to root
|
|
50
|
+
const certificatePath = this.sort();
|
|
51
|
+
// Perform validation checks on each certificate in the path
|
|
52
|
+
this.checkPath(certificatePath);
|
|
53
|
+
const validForDate = certificatePath.every((cert) => cert.validForDate(this.timestamp));
|
|
54
|
+
if (!validForDate) {
|
|
55
|
+
throw new error_1.VerificationError({
|
|
56
|
+
code: 'CERTIFICATE_ERROR',
|
|
57
|
+
message: 'certificate is not valid or expired at the specified date',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// Return verified certificate path
|
|
61
|
+
return certificatePath;
|
|
62
|
+
}
|
|
63
|
+
sort() {
|
|
64
|
+
const leafCert = this.untrustedCert;
|
|
65
|
+
// Construct all possible paths from the leaf
|
|
66
|
+
let paths = this.buildPaths(leafCert);
|
|
67
|
+
// Filter for paths which contain a trusted certificate
|
|
68
|
+
paths = paths.filter((path) => path.some((cert) => this.trustedCerts.includes(cert)));
|
|
69
|
+
if (paths.length === 0) {
|
|
70
|
+
throw new error_1.VerificationError({
|
|
71
|
+
code: 'CERTIFICATE_ERROR',
|
|
72
|
+
message: 'no trusted certificate path found',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
// Find the shortest of possible paths
|
|
76
|
+
/* istanbul ignore next */
|
|
77
|
+
const path = paths.reduce((prev, curr) => prev.length < curr.length ? prev : curr);
|
|
78
|
+
// Construct chain from shortest path
|
|
79
|
+
// Removes the last certificate in the path, which will be a second copy
|
|
80
|
+
// of the root certificate given that the root is self-signed.
|
|
81
|
+
return [leafCert, ...path].slice(0, -1);
|
|
82
|
+
}
|
|
83
|
+
// Recursively build all possible paths from the leaf to the root
|
|
84
|
+
buildPaths(certificate) {
|
|
85
|
+
const paths = [];
|
|
86
|
+
const issuers = this.findIssuer(certificate);
|
|
87
|
+
if (issuers.length === 0) {
|
|
88
|
+
throw new error_1.VerificationError({
|
|
89
|
+
code: 'CERTIFICATE_ERROR',
|
|
90
|
+
message: 'no valid certificate path found',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
for (let i = 0; i < issuers.length; i++) {
|
|
94
|
+
const issuer = issuers[i];
|
|
95
|
+
// Base case - issuer is self
|
|
96
|
+
if (issuer.equals(certificate)) {
|
|
97
|
+
paths.push([certificate]);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
// Recursively build path for the issuer
|
|
101
|
+
const subPaths = this.buildPaths(issuer);
|
|
102
|
+
// Construct paths by appending the issuer to each subpath
|
|
103
|
+
for (let j = 0; j < subPaths.length; j++) {
|
|
104
|
+
paths.push([issuer, ...subPaths[j]]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return paths;
|
|
108
|
+
}
|
|
109
|
+
// Return all possible issuers for the given certificate
|
|
110
|
+
findIssuer(certificate) {
|
|
111
|
+
let issuers = [];
|
|
112
|
+
let keyIdentifier;
|
|
113
|
+
// Exit early if the certificate is self-signed
|
|
114
|
+
if (certificate.subject.equals(certificate.issuer)) {
|
|
115
|
+
if (certificate.verify()) {
|
|
116
|
+
return [certificate];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// If the certificate has an authority key identifier, use that
|
|
120
|
+
// to find the issuer
|
|
121
|
+
if (certificate.extAuthorityKeyID) {
|
|
122
|
+
keyIdentifier = certificate.extAuthorityKeyID.keyIdentifier;
|
|
123
|
+
// TODO: Add support for authorityCertIssuer/authorityCertSerialNumber
|
|
124
|
+
// though Fulcio doesn't appear to use these
|
|
125
|
+
}
|
|
126
|
+
// Find possible issuers by comparing the authorityKeyID/subjectKeyID
|
|
127
|
+
// or issuer/subject. Potential issuers are added to the result array.
|
|
128
|
+
this.localCerts.forEach((possibleIssuer) => {
|
|
129
|
+
if (keyIdentifier) {
|
|
130
|
+
/* istanbul ignore else */
|
|
131
|
+
if (possibleIssuer.extSubjectKeyID) {
|
|
132
|
+
if (possibleIssuer.extSubjectKeyID.keyIdentifier.equals(keyIdentifier)) {
|
|
133
|
+
issuers.push(possibleIssuer);
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Fallback to comparing certificate issuer and subject if
|
|
139
|
+
// subjectKey/authorityKey extensions are not present
|
|
140
|
+
if (possibleIssuer.subject.equals(certificate.issuer)) {
|
|
141
|
+
issuers.push(possibleIssuer);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
// Remove any issuers which fail to verify the certificate
|
|
145
|
+
issuers = issuers.filter((issuer) => {
|
|
146
|
+
try {
|
|
147
|
+
return certificate.verify(issuer);
|
|
148
|
+
}
|
|
149
|
+
catch (ex) {
|
|
150
|
+
/* istanbul ignore next - should never error */
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return issuers;
|
|
155
|
+
}
|
|
156
|
+
checkPath(path) {
|
|
157
|
+
/* istanbul ignore if */
|
|
158
|
+
if (path.length < 1) {
|
|
159
|
+
throw new error_1.VerificationError({
|
|
160
|
+
code: 'CERTIFICATE_ERROR',
|
|
161
|
+
message: 'certificate chain must contain at least one certificate',
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
// Ensure that all certificates beyond the leaf are CAs
|
|
165
|
+
const validCAs = path.slice(1).every((cert) => cert.isCA);
|
|
166
|
+
if (!validCAs) {
|
|
167
|
+
throw new error_1.VerificationError({
|
|
168
|
+
code: 'CERTIFICATE_ERROR',
|
|
169
|
+
message: 'intermediate certificate is not a CA',
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
// Certificate's issuer must match the subject of the next certificate
|
|
173
|
+
// in the chain
|
|
174
|
+
for (let i = path.length - 2; i >= 0; i--) {
|
|
175
|
+
/* istanbul ignore if */
|
|
176
|
+
if (!path[i].issuer.equals(path[i + 1].subject)) {
|
|
177
|
+
throw new error_1.VerificationError({
|
|
178
|
+
code: 'CERTIFICATE_ERROR',
|
|
179
|
+
message: 'incorrect certificate name chaining',
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Check pathlength constraints
|
|
184
|
+
for (let i = 0; i < path.length; i++) {
|
|
185
|
+
const cert = path[i];
|
|
186
|
+
// If the certificate is a CA, check the path length
|
|
187
|
+
if (cert.extBasicConstraints?.isCA) {
|
|
188
|
+
const pathLength = cert.extBasicConstraints.pathLenConstraint;
|
|
189
|
+
// The path length, if set, indicates how many intermediate
|
|
190
|
+
// certificates (NOT including the leaf) are allowed to follow. The
|
|
191
|
+
// pathLength constraint of any intermediate CA certificate MUST be
|
|
192
|
+
// greater than or equal to it's own depth in the chain (with an
|
|
193
|
+
// adjustment for the leaf certificate)
|
|
194
|
+
if (pathLength !== undefined && pathLength < i - 1) {
|
|
195
|
+
throw new error_1.VerificationError({
|
|
196
|
+
code: 'CERTIFICATE_ERROR',
|
|
197
|
+
message: 'path length constraint exceeded',
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
exports.CertificateChainVerifier = CertificateChainVerifier;
|
|
205
|
+
// Remove duplicate certificates from the array
|
|
206
|
+
function dedupeCertificates(certs) {
|
|
207
|
+
for (let i = 0; i < certs.length; i++) {
|
|
208
|
+
for (let j = i + 1; j < certs.length; j++) {
|
|
209
|
+
if (certs[i].equals(certs[j])) {
|
|
210
|
+
certs.splice(j, 1);
|
|
211
|
+
j--;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return certs;
|
|
216
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { X509Certificate } from '@sigstore/core';
|
|
2
|
+
import { VerifiedSCTProvider } from './sct';
|
|
3
|
+
import type { Signer } from '../shared.types';
|
|
4
|
+
import type { TrustMaterial } from '../trust';
|
|
5
|
+
export type CertificateVerificationResult = {
|
|
6
|
+
signer: Signer;
|
|
7
|
+
scts: VerifiedSCTProvider[];
|
|
8
|
+
};
|
|
9
|
+
export declare function verifyPublicKey(hint: string, timestamps: Date[], trustMaterial: TrustMaterial): Signer;
|
|
10
|
+
export declare function verifyCertificate(leaf: X509Certificate, timestamps: Date[], trustMaterial: TrustMaterial): CertificateVerificationResult;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyPublicKey = verifyPublicKey;
|
|
4
|
+
exports.verifyCertificate = verifyCertificate;
|
|
5
|
+
/*
|
|
6
|
+
Copyright 2023 The Sigstore Authors.
|
|
7
|
+
|
|
8
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
you may not use this file except in compliance with the License.
|
|
10
|
+
You may obtain a copy of the License at
|
|
11
|
+
|
|
12
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
|
|
14
|
+
Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
See the License for the specific language governing permissions and
|
|
18
|
+
limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
const core_1 = require("@sigstore/core");
|
|
21
|
+
const error_1 = require("../error");
|
|
22
|
+
const certificate_1 = require("./certificate");
|
|
23
|
+
const sct_1 = require("./sct");
|
|
24
|
+
const OID_FULCIO_ISSUER_V1 = '1.3.6.1.4.1.57264.1.1';
|
|
25
|
+
const OID_FULCIO_ISSUER_V2 = '1.3.6.1.4.1.57264.1.8';
|
|
26
|
+
function verifyPublicKey(hint, timestamps, trustMaterial) {
|
|
27
|
+
const key = trustMaterial.publicKey(hint);
|
|
28
|
+
timestamps.forEach((timestamp) => {
|
|
29
|
+
if (!key.validFor(timestamp)) {
|
|
30
|
+
throw new error_1.VerificationError({
|
|
31
|
+
code: 'PUBLIC_KEY_ERROR',
|
|
32
|
+
message: `Public key is not valid for timestamp: ${timestamp.toISOString()}`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return { key: key.publicKey };
|
|
37
|
+
}
|
|
38
|
+
function verifyCertificate(leaf, timestamps, trustMaterial) {
|
|
39
|
+
// Check that leaf certificate chains to a trusted CA
|
|
40
|
+
let path = [];
|
|
41
|
+
timestamps.forEach((timestamp) => {
|
|
42
|
+
path = (0, certificate_1.verifyCertificateChain)(timestamp, leaf, trustMaterial.certificateAuthorities);
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
scts: (0, sct_1.verifySCTs)(path[0], path[1], trustMaterial.ctlogs),
|
|
46
|
+
signer: getSigner(path[0]),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function getSigner(cert) {
|
|
50
|
+
let issuer;
|
|
51
|
+
const issuerExtension = cert.extension(OID_FULCIO_ISSUER_V2);
|
|
52
|
+
/* istanbul ignore next */
|
|
53
|
+
if (issuerExtension) {
|
|
54
|
+
issuer = issuerExtension.valueObj.subs?.[0]?.value.toString('ascii');
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
issuer = cert.extension(OID_FULCIO_ISSUER_V1)?.value.toString('ascii');
|
|
58
|
+
}
|
|
59
|
+
const oids = cert.extensions.map((ext) => {
|
|
60
|
+
const oid = ext.subs[0].toOID();
|
|
61
|
+
return {
|
|
62
|
+
oid: { id: oid.split('.').map(Number) },
|
|
63
|
+
value: ext.subs[ext.subs.length - 1].value,
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
const identity = {
|
|
67
|
+
extensions: { issuer },
|
|
68
|
+
subjectAlternativeName: cert.subjectAltName,
|
|
69
|
+
oids,
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
key: core_1.crypto.createPublicKey(cert.publicKey),
|
|
73
|
+
identity,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { X509Certificate } from '@sigstore/core';
|
|
2
|
+
import type { TLogAuthority } from '../trust';
|
|
3
|
+
export type VerifiedSCTProvider = Buffer;
|
|
4
|
+
export declare function verifySCTs(cert: X509Certificate, issuer: X509Certificate, ctlogs: TLogAuthority[]): VerifiedSCTProvider[];
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifySCTs = verifySCTs;
|
|
4
|
+
/*
|
|
5
|
+
Copyright 2023 The Sigstore Authors.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
const core_1 = require("@sigstore/core");
|
|
20
|
+
const error_1 = require("../error");
|
|
21
|
+
const trust_1 = require("../trust");
|
|
22
|
+
function verifySCTs(cert, issuer, ctlogs) {
|
|
23
|
+
let extSCT;
|
|
24
|
+
// Verifying the SCT requires that we remove the SCT extension and
|
|
25
|
+
// re-encode the TBS structure to DER -- this value is part of the data
|
|
26
|
+
// over which the signature is calculated. Since this is a destructive action
|
|
27
|
+
// we create a copy of the certificate so we can remove the SCT extension
|
|
28
|
+
// without affecting the original certificate.
|
|
29
|
+
const clone = cert.clone();
|
|
30
|
+
// Intentionally not using the findExtension method here because we want to
|
|
31
|
+
// remove the the SCT extension from the certificate before calculating the
|
|
32
|
+
// PreCert structure
|
|
33
|
+
for (let i = 0; i < clone.extensions.length; i++) {
|
|
34
|
+
const ext = clone.extensions[i];
|
|
35
|
+
if (ext.subs[0].toOID() === core_1.EXTENSION_OID_SCT) {
|
|
36
|
+
extSCT = new core_1.X509SCTExtension(ext);
|
|
37
|
+
// Remove the extension from the certificate
|
|
38
|
+
clone.extensions.splice(i, 1);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// No SCT extension found to verify
|
|
43
|
+
if (!extSCT) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
// Found an SCT extension but it has no SCTs
|
|
47
|
+
/* istanbul ignore if -- too difficult to fabricate test case for this */
|
|
48
|
+
if (extSCT.signedCertificateTimestamps.length === 0) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
// Construct the PreCert structure
|
|
52
|
+
// https://www.rfc-editor.org/rfc/rfc6962#section-3.2
|
|
53
|
+
const preCert = new core_1.ByteStream();
|
|
54
|
+
// Calculate hash of the issuer's public key
|
|
55
|
+
const issuerId = core_1.crypto.digest('sha256', issuer.publicKey);
|
|
56
|
+
preCert.appendView(issuerId);
|
|
57
|
+
// Re-encodes the certificate to DER after removing the SCT extension
|
|
58
|
+
const tbs = clone.tbsCertificate.toDER();
|
|
59
|
+
preCert.appendUint24(tbs.length);
|
|
60
|
+
preCert.appendView(tbs);
|
|
61
|
+
// Calculate and return the verification results for each SCT
|
|
62
|
+
return extSCT.signedCertificateTimestamps.map((sct) => {
|
|
63
|
+
// Find the ctlog instance that corresponds to the SCT's logID
|
|
64
|
+
const validCTLogs = (0, trust_1.filterTLogAuthorities)(ctlogs, {
|
|
65
|
+
logID: sct.logID,
|
|
66
|
+
targetDate: sct.datetime,
|
|
67
|
+
});
|
|
68
|
+
// See if the SCT is valid for any of the CT logs
|
|
69
|
+
const verified = validCTLogs.some((log) => sct.verify(preCert.buffer, log.publicKey));
|
|
70
|
+
if (!verified) {
|
|
71
|
+
throw new error_1.VerificationError({
|
|
72
|
+
code: 'CERTIFICATE_ERROR',
|
|
73
|
+
message: 'SCT verification failed',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return sct.logID;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CertificateExtensions } from './shared.types';
|
|
2
|
+
import type { ObjectIdentifierValuePair } from '@sigstore/protobuf-specs';
|
|
3
|
+
export declare function verifySubjectAlternativeName(policyIdentity: string, signerIdentity: string | undefined): void;
|
|
4
|
+
export declare function verifyExtensions(policyExtensions: CertificateExtensions, signerExtensions?: CertificateExtensions): void;
|
|
5
|
+
export declare function verifyOIDs(policyOIDs: ObjectIdentifierValuePair[], signerOIDs?: ObjectIdentifierValuePair[]): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifySubjectAlternativeName = verifySubjectAlternativeName;
|
|
4
|
+
exports.verifyExtensions = verifyExtensions;
|
|
5
|
+
exports.verifyOIDs = verifyOIDs;
|
|
6
|
+
const error_1 = require("./error");
|
|
7
|
+
// Verifies that the signer's SAN matches the policy identity. The
|
|
8
|
+
// policyIdentity is treated as a JavaScript regular expression pattern and
|
|
9
|
+
// tested against the full signerIdentity string. For exact matching, use
|
|
10
|
+
// anchored patterns (e.g. '^user@example\\.com$').
|
|
11
|
+
function verifySubjectAlternativeName(policyIdentity, signerIdentity) {
|
|
12
|
+
if (signerIdentity === undefined || !signerIdentity.match(policyIdentity)) {
|
|
13
|
+
throw new error_1.PolicyError({
|
|
14
|
+
code: 'UNTRUSTED_SIGNER_ERROR',
|
|
15
|
+
message: `certificate identity error - expected ${policyIdentity}, got ${signerIdentity}`,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function verifyExtensions(policyExtensions, signerExtensions = {}) {
|
|
20
|
+
let key;
|
|
21
|
+
for (key in policyExtensions) {
|
|
22
|
+
if (signerExtensions[key] !== policyExtensions[key]) {
|
|
23
|
+
throw new error_1.PolicyError({
|
|
24
|
+
code: 'UNTRUSTED_SIGNER_ERROR',
|
|
25
|
+
message: `invalid certificate extension - expected ${key}=${policyExtensions[key]}, got ${key}=${signerExtensions[key]}`,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function verifyOIDs(policyOIDs, signerOIDs = []) {
|
|
31
|
+
for (const policyOID of policyOIDs) {
|
|
32
|
+
const match = signerOIDs.find((signerOID) => oidEquals(policyOID.oid?.id, signerOID.oid?.id) &&
|
|
33
|
+
policyOID.value.equals(signerOID.value));
|
|
34
|
+
if (!match) {
|
|
35
|
+
/* istanbul ignore next */
|
|
36
|
+
const oid = policyOID.oid?.id.join('.') ?? '<unknown>';
|
|
37
|
+
throw new error_1.PolicyError({
|
|
38
|
+
code: 'UNTRUSTED_SIGNER_ERROR',
|
|
39
|
+
message: `invalid certificate extension - missing OID ${oid}`,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function oidEquals(a, b) {
|
|
45
|
+
/* istanbul ignore if */
|
|
46
|
+
if (a === undefined || b === undefined) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
50
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { TransparencyLogEntry } from '@sigstore/bundle';
|
|
2
|
+
import type { RFC3161Timestamp, X509Certificate, crypto } from '@sigstore/core';
|
|
3
|
+
import type { ObjectIdentifierValuePair } from '@sigstore/protobuf-specs';
|
|
4
|
+
export type CertificateExtensionName = 'issuer';
|
|
5
|
+
export type CertificateExtensions = {
|
|
6
|
+
[key in CertificateExtensionName]?: string;
|
|
7
|
+
};
|
|
8
|
+
export type CertificateIdentity = {
|
|
9
|
+
subjectAlternativeName?: string;
|
|
10
|
+
extensions?: CertificateExtensions;
|
|
11
|
+
oids?: ObjectIdentifierValuePair[];
|
|
12
|
+
};
|
|
13
|
+
export type VerificationPolicy = CertificateIdentity;
|
|
14
|
+
export type Signer = {
|
|
15
|
+
key: crypto.KeyObject;
|
|
16
|
+
identity?: CertificateIdentity;
|
|
17
|
+
};
|
|
18
|
+
export type Timestamp = {
|
|
19
|
+
$case: 'timestamp-authority';
|
|
20
|
+
timestamp: RFC3161Timestamp;
|
|
21
|
+
} | {
|
|
22
|
+
$case: 'transparency-log';
|
|
23
|
+
tlogEntry: TransparencyLogEntry;
|
|
24
|
+
};
|
|
25
|
+
export type VerificationKey = {
|
|
26
|
+
$case: 'public-key';
|
|
27
|
+
hint: string;
|
|
28
|
+
} | {
|
|
29
|
+
$case: 'certificate';
|
|
30
|
+
certificate: X509Certificate;
|
|
31
|
+
};
|
|
32
|
+
export type SignatureContent = {
|
|
33
|
+
signature: Buffer;
|
|
34
|
+
compareSignature(signature: Buffer): boolean;
|
|
35
|
+
compareDigest(digest: Buffer): boolean;
|
|
36
|
+
verifySignature(key: crypto.KeyObject): boolean;
|
|
37
|
+
};
|
|
38
|
+
export type TimestampProvider = {
|
|
39
|
+
timestamps: Timestamp[];
|
|
40
|
+
};
|
|
41
|
+
export type SignatureProvider = {
|
|
42
|
+
signature: SignatureContent;
|
|
43
|
+
};
|
|
44
|
+
export type KeyProvider = {
|
|
45
|
+
key: VerificationKey;
|
|
46
|
+
};
|
|
47
|
+
export type TLogEntryProvider = {
|
|
48
|
+
tlogEntries: TransparencyLogEntry[];
|
|
49
|
+
};
|
|
50
|
+
export type SignedEntity = SignatureProvider & KeyProvider & TimestampProvider & TLogEntryProvider;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RFC3161Timestamp } from '@sigstore/core';
|
|
2
|
+
import type { TransparencyLogEntry } from '@sigstore/bundle';
|
|
3
|
+
import type { CertAuthority } from '../trust';
|
|
4
|
+
export type TimestampType = 'transparency-log' | 'timestamp-authority';
|
|
5
|
+
export type TimestampVerificationResult = {
|
|
6
|
+
type: TimestampType;
|
|
7
|
+
logID: Buffer;
|
|
8
|
+
timestamp: Date;
|
|
9
|
+
};
|
|
10
|
+
export declare function getTSATimestamp(timestamp: RFC3161Timestamp, data: Buffer, timestampAuthorities: CertAuthority[]): TimestampVerificationResult;
|
|
11
|
+
export declare function getTLogTimestamp(entry: TransparencyLogEntry): TimestampVerificationResult | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTSATimestamp = getTSATimestamp;
|
|
4
|
+
exports.getTLogTimestamp = getTLogTimestamp;
|
|
5
|
+
const tsa_1 = require("./tsa");
|
|
6
|
+
function getTSATimestamp(timestamp, data, timestampAuthorities) {
|
|
7
|
+
(0, tsa_1.verifyRFC3161Timestamp)(timestamp, data, timestampAuthorities);
|
|
8
|
+
return {
|
|
9
|
+
type: 'timestamp-authority',
|
|
10
|
+
logID: timestamp.signerSerialNumber,
|
|
11
|
+
timestamp: timestamp.signingTime,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function getTLogTimestamp(entry) {
|
|
15
|
+
// Only entries with an inclusion promise provide a verifiable timestamp
|
|
16
|
+
if (!entry.inclusionPromise) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
type: 'transparency-log',
|
|
21
|
+
logID: entry.logId.keyId,
|
|
22
|
+
timestamp: new Date(Number(entry.integratedTime) * 1000),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyRFC3161Timestamp = verifyRFC3161Timestamp;
|
|
4
|
+
const core_1 = require("@sigstore/core");
|
|
5
|
+
const error_1 = require("../error");
|
|
6
|
+
const certificate_1 = require("../key/certificate");
|
|
7
|
+
const trust_1 = require("../trust");
|
|
8
|
+
function verifyRFC3161Timestamp(timestamp, data, timestampAuthorities) {
|
|
9
|
+
const signingTime = timestamp.signingTime;
|
|
10
|
+
// Filter for CAs which were valid at the time of signing
|
|
11
|
+
timestampAuthorities = (0, trust_1.filterCertAuthorities)(timestampAuthorities, signingTime);
|
|
12
|
+
// Filter for CAs which match serial and issuer embedded in the timestamp
|
|
13
|
+
timestampAuthorities = filterCAsBySerialAndIssuer(timestampAuthorities, {
|
|
14
|
+
serialNumber: timestamp.signerSerialNumber,
|
|
15
|
+
issuer: timestamp.signerIssuer,
|
|
16
|
+
});
|
|
17
|
+
// Check that we can verify the timestamp with AT LEAST ONE of the remaining
|
|
18
|
+
// CAs
|
|
19
|
+
const verified = timestampAuthorities.some((ca) => {
|
|
20
|
+
try {
|
|
21
|
+
verifyTimestampForCA(timestamp, data, ca);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
if (!verified) {
|
|
29
|
+
throw new error_1.VerificationError({
|
|
30
|
+
code: 'TIMESTAMP_ERROR',
|
|
31
|
+
message: 'timestamp could not be verified',
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function verifyTimestampForCA(timestamp, data, ca) {
|
|
36
|
+
const [leaf, ...cas] = ca.certChain;
|
|
37
|
+
const signingKey = core_1.crypto.createPublicKey(leaf.publicKey);
|
|
38
|
+
const signingTime = timestamp.signingTime;
|
|
39
|
+
// Verify the certificate chain for the provided CA
|
|
40
|
+
try {
|
|
41
|
+
new certificate_1.CertificateChainVerifier({
|
|
42
|
+
untrustedCert: leaf,
|
|
43
|
+
trustedCerts: cas,
|
|
44
|
+
timestamp: signingTime,
|
|
45
|
+
}).verify();
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
throw new error_1.VerificationError({
|
|
49
|
+
code: 'TIMESTAMP_ERROR',
|
|
50
|
+
message: 'invalid certificate chain',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// Check that the signing certificate's key can be used to verify the
|
|
54
|
+
// timestamp signature.
|
|
55
|
+
timestamp.verify(data, signingKey);
|
|
56
|
+
}
|
|
57
|
+
// Filters the list of CAs to those which have a leaf signing certificate which
|
|
58
|
+
// matches the given serial number and issuer.
|
|
59
|
+
function filterCAsBySerialAndIssuer(timestampAuthorities, criteria) {
|
|
60
|
+
return timestampAuthorities.filter((ca) => ca.certChain.length > 0 &&
|
|
61
|
+
core_1.crypto.bufferEqual(ca.certChain[0].serialNumber, criteria.serialNumber) &&
|
|
62
|
+
core_1.crypto.bufferEqual(ca.certChain[0].issuer, criteria.issuer));
|
|
63
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TLogAuthority } from '../trust';
|
|
2
|
+
import type { TLogEntryWithInclusionProof } from '@sigstore/bundle';
|
|
3
|
+
export declare function verifyCheckpoint(entry: TLogEntryWithInclusionProof, tlogs: TLogAuthority[]): LogCheckpoint;
|
|
4
|
+
export declare class LogCheckpoint {
|
|
5
|
+
readonly origin: string;
|
|
6
|
+
readonly logSize: bigint;
|
|
7
|
+
readonly logHash: Buffer;
|
|
8
|
+
readonly rest: string[];
|
|
9
|
+
constructor(origin: string, logSize: bigint, logHash: Buffer, rest: string[]);
|
|
10
|
+
static fromString(note: string): LogCheckpoint;
|
|
11
|
+
}
|