@freedomofpress/sigstore-browser 0.1.13 → 0.1.15
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/.github/workflows/conformance.yml +1 -1
- package/.github/workflows/publish.yml +1 -1
- package/README.md +20 -16
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -1
- package/dist/bundle.js +66 -1
- package/dist/bundle.js.map +1 -1
- package/dist/interfaces.d.ts +17 -2
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js +14 -0
- package/dist/interfaces.js.map +1 -1
- package/dist/policy.d.ts +3 -3
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +4 -4
- package/dist/policy.js.map +1 -1
- package/dist/sigstore.d.ts +8 -8
- package/dist/sigstore.d.ts.map +1 -1
- package/dist/sigstore.js +159 -362
- package/dist/sigstore.js.map +1 -1
- package/dist/timestamp/tsa.d.ts +6 -2
- package/dist/timestamp/tsa.d.ts.map +1 -1
- package/dist/timestamp/tsa.js +15 -18
- package/dist/timestamp/tsa.js.map +1 -1
- package/dist/tlog/body.d.ts +3 -1
- package/dist/tlog/body.d.ts.map +1 -1
- package/dist/tlog/body.js +18 -5
- package/dist/tlog/body.js.map +1 -1
- package/dist/tlog/checkpoint.d.ts +2 -2
- package/dist/tlog/checkpoint.d.ts.map +1 -1
- package/dist/tlog/checkpoint.js +17 -95
- package/dist/tlog/checkpoint.js.map +1 -1
- package/dist/tlog/dsse.d.ts +3 -2
- package/dist/tlog/dsse.d.ts.map +1 -1
- package/dist/tlog/dsse.js +8 -5
- package/dist/tlog/dsse.js.map +1 -1
- package/dist/tlog/hashedrekord.d.ts +3 -2
- package/dist/tlog/hashedrekord.d.ts.map +1 -1
- package/dist/tlog/hashedrekord.js +8 -5
- package/dist/tlog/hashedrekord.js.map +1 -1
- package/dist/tlog/intoto.d.ts +3 -2
- package/dist/tlog/intoto.d.ts.map +1 -1
- package/dist/tlog/intoto.js +3 -1
- package/dist/tlog/intoto.js.map +1 -1
- package/package.json +2 -2
- package/src/bundle.ts +87 -0
- package/src/ed25519.browser.test.ts +76 -0
- package/src/index.browser.test.ts +46 -1
- package/src/interfaces.ts +29 -2
- package/src/policy.ts +5 -5
- package/src/security.browser.test.ts +249 -0
- package/src/sigstore.ts +191 -497
- package/src/timestamp/tsa.ts +29 -28
- package/src/tlog/body.ts +24 -5
- package/src/tlog/checkpoint.ts +22 -122
- package/src/tlog/dsse.ts +12 -6
- package/src/tlog/hashedrekord.ts +14 -8
- package/src/tlog/intoto.ts +5 -2
- package/src/verify.browser.test.ts +281 -0
- package/test/fixtures/rekor2.ts +14 -0
- package/test/fixtures/sigstore.ts +13 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { base64ToUint8Array, canonicalize, hexToUint8Array, Uint8ArrayToBase64, Uint8ArrayToHex } from "@freedomofpress/crypto-browser";
|
|
2
|
+
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
3
|
+
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { bundle, digestHex, identity, issuer, trustRoot } from "../test/fixtures/sigstore.js";
|
|
6
|
+
import { assertBundle, type TLogEntry } from "./bundle.js";
|
|
7
|
+
import type { RawLog } from "./interfaces.js";
|
|
8
|
+
import { AllOf, AnyOf } from "./policy.js";
|
|
9
|
+
import { SigstoreVerifier, type SigstoreVerifierOptions } from "./sigstore.js";
|
|
10
|
+
import { verifyBundleTimestamp } from "./timestamp/tsa.js";
|
|
11
|
+
import { X509Certificate } from "./x509/cert.js";
|
|
12
|
+
|
|
13
|
+
// Keep real timestamp verification by default; individual tests supply already-verified
|
|
14
|
+
// timestamps to isolate threshold accounting from the separately tested cryptography.
|
|
15
|
+
vi.mock("./timestamp/tsa.js", async (importOriginal) => {
|
|
16
|
+
const actual = await importOriginal<typeof import("./timestamp/tsa.js")>();
|
|
17
|
+
return { ...actual, verifyBundleTimestamp: vi.fn(actual.verifyBundleTimestamp) };
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
vi.mocked(verifyBundleTimestamp).mockReset();
|
|
22
|
+
vi.restoreAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const digest = hexToUint8Array(digestHex);
|
|
26
|
+
const signingTime = new Date(Number(bundle().verificationMaterial.tlogEntries[0].integratedTime) * 1000);
|
|
27
|
+
const verify = (v: SigstoreVerifier, b = bundle(), data = digest) =>
|
|
28
|
+
v.verifyArtifact(identity, issuer, b, data, true);
|
|
29
|
+
|
|
30
|
+
async function verifier(options: SigstoreVerifierOptions = {}) {
|
|
31
|
+
const v = new SigstoreVerifier(options);
|
|
32
|
+
await v.loadSigstoreRoot(trustRoot());
|
|
33
|
+
return v;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Real SET signatures over the fixture's body, with independent test log keys.
|
|
37
|
+
async function signedLog(): Promise<{ log: RawLog; entry: TLogEntry }> {
|
|
38
|
+
const secret = ed25519.utils.randomSecretKey();
|
|
39
|
+
const spki = new Uint8Array([0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00, ...ed25519.getPublicKey(secret)]);
|
|
40
|
+
const logID = new Uint8Array(await crypto.subtle.digest("SHA-256", spki));
|
|
41
|
+
const log: RawLog = {
|
|
42
|
+
baseUrl: "https://log.test",
|
|
43
|
+
hashAlgorithm: "SHA2_256",
|
|
44
|
+
publicKey: { rawBytes: Uint8ArrayToBase64(spki), keyDetails: "PKIX_ED25519", validFor: { start: "2025-01-01T00:00:00Z" } },
|
|
45
|
+
logId: { keyId: Uint8ArrayToBase64(logID) },
|
|
46
|
+
};
|
|
47
|
+
const entry = bundle().verificationMaterial.tlogEntries[0];
|
|
48
|
+
entry.logId = log.logId;
|
|
49
|
+
delete entry.inclusionProof;
|
|
50
|
+
const signed = new TextEncoder().encode(canonicalize({
|
|
51
|
+
body: entry.canonicalizedBody,
|
|
52
|
+
integratedTime: Number(entry.integratedTime),
|
|
53
|
+
logIndex: Number(entry.logIndex),
|
|
54
|
+
logID: Uint8ArrayToHex(logID),
|
|
55
|
+
}));
|
|
56
|
+
entry.inclusionPromise = { signedEntryTimestamp: Uint8ArrayToBase64(ed25519.sign(signed, secret)) };
|
|
57
|
+
return { log, entry };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const operatorCases = [
|
|
61
|
+
{ name: "anonymous authorities retain threshold-one support", operators: ["", ""], threshold: 1, passes: true },
|
|
62
|
+
{ name: "anonymous authorities cannot establish independence", operators: ["", ""], threshold: 2, passes: false },
|
|
63
|
+
{ name: "anonymous plus named does not count twice", operators: ["", "a.test"], threshold: 2, passes: false },
|
|
64
|
+
{ name: "named plus anonymous does not count twice", operators: ["a.test", ""], threshold: 2, passes: false },
|
|
65
|
+
{ name: "multiple keys from one named operator count once", operators: ["a.test", "a.test"], threshold: 2, passes: false },
|
|
66
|
+
{ name: "distinct named operators satisfy the threshold", operators: ["a.test", "b.test"], threshold: 2, passes: true },
|
|
67
|
+
{ name: "an anonymous authority cannot add a third operator", operators: ["a.test", "", "b.test"], threshold: 3, passes: false },
|
|
68
|
+
{ name: "an anonymous authority does not invalidate two named operators", operators: ["a.test", "", "b.test"], threshold: 2, passes: true },
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
describe("Operator thresholds", () => {
|
|
72
|
+
let signedLogs: Awaited<ReturnType<typeof signedLog>>[];
|
|
73
|
+
beforeAll(async () => { signedLogs = await Promise.all([signedLog(), signedLog(), signedLog()]); });
|
|
74
|
+
|
|
75
|
+
it.each(operatorCases)("Rekor: $name", async ({ operators, threshold, passes }) => {
|
|
76
|
+
const root = trustRoot();
|
|
77
|
+
root.tlogs = operators.map((operator, i) => ({ ...signedLogs[i].log, operator: operator || undefined }));
|
|
78
|
+
const b = bundle();
|
|
79
|
+
b.mediaType = "application/vnd.dev.sigstore.bundle+json;version=0.1";
|
|
80
|
+
b.verificationMaterial.tlogEntries = operators.map((_, i) => signedLogs[i].entry);
|
|
81
|
+
const v = new SigstoreVerifier({ tlogThreshold: threshold });
|
|
82
|
+
await v.loadSigstoreRoot(root);
|
|
83
|
+
const result = verify(v, b);
|
|
84
|
+
if (passes) await expect(result).resolves.toBe(true);
|
|
85
|
+
else await expect(result).rejects.toThrow("Not enough verified transparency logs");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it.each(operatorCases)("CT: $name", async ({ operators, threshold, passes }) => {
|
|
89
|
+
const v = await verifier({ ctlogThreshold: threshold });
|
|
90
|
+
// SCT verification itself is covered by the real fixture tests.
|
|
91
|
+
vi.spyOn(v, "verifySCT").mockResolvedValue(new Set(operators));
|
|
92
|
+
const result = verify(v);
|
|
93
|
+
if (passes) await expect(result).resolves.toBe(true);
|
|
94
|
+
else await expect(result).rejects.toThrow("Not enough verified CT log operators");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it.each(operatorCases)("TSA: $name", async ({ operators, threshold, passes }) => {
|
|
98
|
+
vi.mocked(verifyBundleTimestamp).mockResolvedValue(operators.map((operator) => ({ signingTime, operator })));
|
|
99
|
+
const result = verify(await verifier({ tsaThreshold: threshold }));
|
|
100
|
+
if (passes) await expect(result).resolves.toBe(true);
|
|
101
|
+
else await expect(result).rejects.toThrow("Not enough verified TSA operators");
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("Small input hardening", () => {
|
|
106
|
+
it("awaits asynchronous custom policies and policy combinators", async () => {
|
|
107
|
+
const v = await verifier();
|
|
108
|
+
const rejection = {
|
|
109
|
+
verify: async () => { throw new Error("asynchronous policy rejected"); },
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
await expect(v.verifyArtifactPolicy(rejection, bundle(), digest, true))
|
|
113
|
+
.rejects.toThrow("asynchronous policy rejected");
|
|
114
|
+
await expect(v.verifyArtifactPolicy(new AllOf([rejection]), bundle(), digest, true))
|
|
115
|
+
.rejects.toThrow("asynchronous policy rejected");
|
|
116
|
+
await expect(v.verifyArtifactPolicy(new AnyOf([rejection]), bundle(), digest, true))
|
|
117
|
+
.rejects.toThrow("0 of 1 policies succeeded");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("rejects malformed authority validity periods while loading the root", async () => {
|
|
121
|
+
for (let i = 0; i < 4; i++) {
|
|
122
|
+
const root = trustRoot();
|
|
123
|
+
const periods = [
|
|
124
|
+
root.tlogs[0].publicKey.validFor,
|
|
125
|
+
root.ctlogs[0].publicKey.validFor,
|
|
126
|
+
root.certificateAuthorities[0].validFor,
|
|
127
|
+
root.timestampAuthorities[0].validFor,
|
|
128
|
+
];
|
|
129
|
+
periods[i].start = "not-a-date";
|
|
130
|
+
await expect(new SigstoreVerifier().loadSigstoreRoot(root))
|
|
131
|
+
.rejects.toThrow("Invalid authority validity period");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const root = trustRoot();
|
|
135
|
+
root.tlogs[0].publicKey.validFor = {
|
|
136
|
+
start: "2026-01-02T00:00:00Z",
|
|
137
|
+
end: "2026-01-01T00:00:00Z",
|
|
138
|
+
};
|
|
139
|
+
await expect(new SigstoreVerifier().loadSigstoreRoot(root))
|
|
140
|
+
.rejects.toThrow("Invalid authority validity period");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("requires non-negative safe-integer thresholds", () => {
|
|
144
|
+
for (const key of ["tlogThreshold", "ctlogThreshold", "tsaThreshold"] as const) {
|
|
145
|
+
for (const value of [NaN, Infinity, -Infinity, -1, 0.5, Number.MAX_SAFE_INTEGER + 1, "2"]) {
|
|
146
|
+
expect(() => new SigstoreVerifier({ [key]: value } as SigstoreVerifierOptions)).toThrow(`${key} must be a non-negative safe integer`);
|
|
147
|
+
}
|
|
148
|
+
for (const value of [0, 1, 2]) expect(() => new SigstoreVerifier({ [key]: value })).not.toThrow();
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("rejects digest-only inputs that are not 32 bytes", async () => {
|
|
153
|
+
const v = await verifier();
|
|
154
|
+
for (const length of [0, 31, 33, 64]) {
|
|
155
|
+
await expect(verify(v, bundle(), new Uint8Array(length))).rejects.toThrow("SHA-256 digest must be exactly 32 bytes");
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("rejects oversized or unrepresentable log numbers before cryptography", () => {
|
|
160
|
+
for (const field of ["logIndex", "integratedTime"] as const) {
|
|
161
|
+
for (const value of ["9".repeat(10000), "9223372036854775808", "-1", "1.5"]) {
|
|
162
|
+
const b = bundle();
|
|
163
|
+
b.verificationMaterial.tlogEntries[0][field] = value;
|
|
164
|
+
expect(() => assertBundle(b)).toThrow("Invalid bundle");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const unsafe = bundle();
|
|
168
|
+
unsafe.verificationMaterial.tlogEntries[0].logIndex = "9007199254740993";
|
|
169
|
+
expect(() => assertBundle(unsafe)).toThrow("inclusion promise");
|
|
170
|
+
const invalidDate = bundle();
|
|
171
|
+
invalidDate.verificationMaterial.tlogEntries[0].integratedTime = "8640000000001";
|
|
172
|
+
expect(() => assertBundle(invalidDate)).toThrow("integratedTime");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("bounds proof integers and sibling counts while preserving full int64 precision", () => {
|
|
176
|
+
for (const field of ["logIndex", "treeSize"] as const) {
|
|
177
|
+
const b = bundle();
|
|
178
|
+
const proof = b.verificationMaterial.tlogEntries[0].inclusionProof;
|
|
179
|
+
if (!proof) throw new Error("Fixture must contain an inclusion proof");
|
|
180
|
+
proof[field] = "9223372036854775808";
|
|
181
|
+
expect(() => assertBundle(b)).toThrow("inclusion proof");
|
|
182
|
+
}
|
|
183
|
+
const b = bundle();
|
|
184
|
+
const entry = b.verificationMaterial.tlogEntries[0];
|
|
185
|
+
const proof = entry.inclusionProof;
|
|
186
|
+
if (!proof) throw new Error("Fixture must contain an inclusion proof");
|
|
187
|
+
delete entry.inclusionPromise;
|
|
188
|
+
entry.logIndex = "9223372036854775806";
|
|
189
|
+
proof.logIndex = entry.logIndex;
|
|
190
|
+
proof.treeSize = "9223372036854775807";
|
|
191
|
+
proof.hashes = Array(63).fill(Uint8ArrayToBase64(new Uint8Array(32)));
|
|
192
|
+
expect(() => assertBundle(b)).not.toThrow();
|
|
193
|
+
proof.hashes.push(proof.hashes[0]);
|
|
194
|
+
expect(() => assertBundle(b)).toThrow("inclusion proof");
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("enforces the timestamp cap through the exported helper too", async () => {
|
|
198
|
+
await expect(verifyBundleTimestamp({ rfc3161Timestamps: Array(33).fill({ signedTimestamp: "AA==" }) }, digest, []))
|
|
199
|
+
.rejects.toThrow("Invalid bundle: rfc3161Timestamps");
|
|
200
|
+
await expect(verifyBundleTimestamp(undefined, digest, [])).resolves.toEqual([]);
|
|
201
|
+
await expect(verifyBundleTimestamp({}, digest, [])).resolves.toEqual([]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("bounds encoded bundle data and certificate-chain length", async () => {
|
|
205
|
+
const oversized = "A".repeat(16 * 1024 * 1024 + 1);
|
|
206
|
+
const b = bundle();
|
|
207
|
+
if (!b.dsseEnvelope) throw new Error("Fixture must contain a DSSE envelope");
|
|
208
|
+
b.dsseEnvelope.payload = oversized;
|
|
209
|
+
expect(() => assertBundle(b)).toThrow("Invalid bundle");
|
|
210
|
+
await expect(verifyBundleTimestamp(
|
|
211
|
+
{ rfc3161Timestamps: [{ signedTimestamp: oversized }] },
|
|
212
|
+
digest,
|
|
213
|
+
[],
|
|
214
|
+
)).rejects.toThrow("Invalid bundle");
|
|
215
|
+
|
|
216
|
+
const chained = bundle();
|
|
217
|
+
const cert = chained.verificationMaterial.certificate;
|
|
218
|
+
if (!cert) throw new Error("Fixture must contain a certificate");
|
|
219
|
+
delete chained.verificationMaterial.certificate;
|
|
220
|
+
chained.verificationMaterial.x509CertificateChain = {
|
|
221
|
+
certificates: Array(33).fill(cert),
|
|
222
|
+
};
|
|
223
|
+
expect(() => assertBundle(chained)).toThrow("Invalid bundle: certificate");
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("rejects malformed or excessive subjects and digest maps", async () => {
|
|
227
|
+
const v = await verifier();
|
|
228
|
+
const b = bundle();
|
|
229
|
+
const cert = b.verificationMaterial.certificate;
|
|
230
|
+
const env = b.dsseEnvelope;
|
|
231
|
+
if (!cert || !env) throw new Error("Fixture must contain a certificate and DSSE envelope");
|
|
232
|
+
const signingCert = X509Certificate.parse(base64ToUint8Array(cert.rawBytes));
|
|
233
|
+
const signature = base64ToUint8Array(env.signatures[0].sig);
|
|
234
|
+
// Isolate parsing of authenticated payloads; the real bundle tests exercise all trust checks.
|
|
235
|
+
vi.spyOn(v as unknown as { verifyBundle: () => Promise<{ signingCert: X509Certificate; signature: Uint8Array }> }, "verifyBundle")
|
|
236
|
+
.mockResolvedValue({ signingCert, signature });
|
|
237
|
+
const subject = { digest: { sha256: digestHex } };
|
|
238
|
+
for (const payload of [null, {}, { subject: [] }, { subject: Array(1025).fill(subject) }]) {
|
|
239
|
+
env.payload = Uint8ArrayToBase64(new TextEncoder().encode(JSON.stringify(payload)));
|
|
240
|
+
await expect(verify(v, b)).rejects.toThrow("DSSE payload must have between 1 and 1024 subjects");
|
|
241
|
+
}
|
|
242
|
+
for (const invalid of [null, { digest: [] }, { digest: Object.fromEntries(Array.from({ length: 33 }, (_, i) => [`hash${i}`, "00"])) }]) {
|
|
243
|
+
env.payload = Uint8ArrayToBase64(new TextEncoder().encode(JSON.stringify({ subject: [invalid, subject] })));
|
|
244
|
+
await expect(verify(v, b)).rejects.toThrow("Invalid DSSE subject digest map");
|
|
245
|
+
}
|
|
246
|
+
env.payload = Uint8ArrayToBase64(new TextEncoder().encode(JSON.stringify({ subject: [{ digest: { sha256: 123 } }] })));
|
|
247
|
+
await expect(verify(v, b)).rejects.toThrow("does not match any subject");
|
|
248
|
+
});
|
|
249
|
+
});
|