mergeseal 0.1.0 → 0.2.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/CHANGELOG.md +11 -0
- package/CONTRIBUTING.md +64 -2
- package/README.md +29 -6
- package/dist/cli-contract.d.ts +2 -0
- package/dist/cli-contract.js +8 -0
- package/dist/cli.js +24 -0
- package/dist/coding/git.js +5 -0
- package/dist/intoto.d.ts +34 -1
- package/dist/intoto.js +316 -13
- package/dist/keyless/asn1.d.ts +26 -0
- package/dist/keyless/asn1.js +269 -0
- package/dist/keyless/bundle.d.ts +52 -0
- package/dist/keyless/bundle.js +163 -0
- package/dist/keyless/cli.d.ts +11 -0
- package/dist/keyless/cli.js +182 -0
- package/dist/keyless/errors.d.ts +17 -0
- package/dist/keyless/errors.js +29 -0
- package/dist/keyless/fulcio.d.ts +13 -0
- package/dist/keyless/fulcio.js +104 -0
- package/dist/keyless/index.d.ts +16 -0
- package/dist/keyless/index.js +12 -0
- package/dist/keyless/oidc.d.ts +29 -0
- package/dist/keyless/oidc.js +130 -0
- package/dist/keyless/x509.d.ts +91 -0
- package/dist/keyless/x509.js +670 -0
- package/dist/portable/index.d.ts +5 -2
- package/dist/portable/index.js +4 -1
- package/docs/aaif-sandbox-thesis.md +51 -0
- package/docs/cli-contract.md +27 -2
- package/docs/intoto-predicate-v1.md +155 -0
- package/docs/ucan-biscuit.md +3 -1
- package/package.json +5 -1
- package/spec/intoto/mergeseal_receipt_v1.proto +47 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyless seal: an ephemeral Ed25519 key, a Fulcio certificate, and a
|
|
3
|
+
* DSSE envelope over the payload. The private key is not returned.
|
|
4
|
+
* Verification uses the supplied root and does not open a socket.
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2026 MergeSeal
|
|
7
|
+
* MergeSeal <team@mergeseal.dev>
|
|
8
|
+
*/
|
|
9
|
+
export declare const KEYLESS_MEDIA_TYPE = "application/vnd.dev.mergeseal.keyless.v1+json";
|
|
10
|
+
export declare const KEYLESS_PAYLOAD_TYPE = "application/vnd.dev.mergeseal.keyless.v1";
|
|
11
|
+
export type KeylessBundle = {
|
|
12
|
+
readonly mediaType: typeof KEYLESS_MEDIA_TYPE;
|
|
13
|
+
readonly dsseEnvelope: {
|
|
14
|
+
readonly payload: string;
|
|
15
|
+
readonly payloadType: typeof KEYLESS_PAYLOAD_TYPE;
|
|
16
|
+
readonly signatures: readonly [
|
|
17
|
+
{
|
|
18
|
+
readonly keyid: string;
|
|
19
|
+
readonly sig: string;
|
|
20
|
+
}
|
|
21
|
+
];
|
|
22
|
+
};
|
|
23
|
+
readonly verificationMaterial: {
|
|
24
|
+
readonly certificateChain: readonly string[];
|
|
25
|
+
readonly certificateIdentity: string;
|
|
26
|
+
readonly certificateOidcIssuer: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export type SealResult = {
|
|
30
|
+
readonly bundle: KeylessBundle;
|
|
31
|
+
readonly certificateIdentity: string;
|
|
32
|
+
readonly certificateOidcIssuer: string;
|
|
33
|
+
};
|
|
34
|
+
export declare function sealKeyless(input: {
|
|
35
|
+
readonly payload: Uint8Array;
|
|
36
|
+
readonly fulcioUrl: string;
|
|
37
|
+
readonly requestUrl: string;
|
|
38
|
+
readonly requestToken: string;
|
|
39
|
+
readonly audience: string;
|
|
40
|
+
readonly ephemeralSeed?: Uint8Array;
|
|
41
|
+
}): Promise<SealResult>;
|
|
42
|
+
export declare function verifyKeyless(input: {
|
|
43
|
+
readonly bundle: unknown;
|
|
44
|
+
readonly nowMs: number;
|
|
45
|
+
readonly rootPem: string;
|
|
46
|
+
readonly identity: string | undefined;
|
|
47
|
+
readonly identityPattern: string | undefined;
|
|
48
|
+
readonly issuer: string;
|
|
49
|
+
}): {
|
|
50
|
+
readonly certificateIdentity: string;
|
|
51
|
+
readonly certificateOidcIssuer: string;
|
|
52
|
+
};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyless seal: an ephemeral Ed25519 key, a Fulcio certificate, and a
|
|
3
|
+
* DSSE envelope over the payload. The private key is not returned.
|
|
4
|
+
* Verification uses the supplied root and does not open a socket.
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2026 MergeSeal
|
|
7
|
+
* MergeSeal <team@mergeseal.dev>
|
|
8
|
+
*/
|
|
9
|
+
import { dssePreAuthEncoding } from "../intoto.js";
|
|
10
|
+
import { bytesEqual, toHex, utf8 } from "../v1_1/bytes.js";
|
|
11
|
+
import { generateKeyPair, keyPairFromSeed, signMessage, verifyMessage, } from "../v1_1/ed25519.js";
|
|
12
|
+
import { decodeBase64, encodeBase64 } from "./asn1.js";
|
|
13
|
+
import { KeylessUsageError, KeylessVerifyError } from "./errors.js";
|
|
14
|
+
import { requestFulcioChain } from "./fulcio.js";
|
|
15
|
+
import { readGithubActionsToken, requestOidcJwt } from "./oidc.js";
|
|
16
|
+
import { chainTrusts, linkedChain, publicKeyPem } from "./x509.js";
|
|
17
|
+
export const KEYLESS_MEDIA_TYPE = "application/vnd.dev.mergeseal.keyless.v1+json";
|
|
18
|
+
export const KEYLESS_PAYLOAD_TYPE = "application/vnd.dev.mergeseal.keyless.v1";
|
|
19
|
+
export async function sealKeyless(input) {
|
|
20
|
+
const jwt = await requestOidcJwt({
|
|
21
|
+
requestUrl: input.requestUrl,
|
|
22
|
+
requestToken: input.requestToken,
|
|
23
|
+
audience: input.audience,
|
|
24
|
+
});
|
|
25
|
+
const token = readGithubActionsToken(jwt, input.audience);
|
|
26
|
+
const pair = input.ephemeralSeed === undefined
|
|
27
|
+
? generateKeyPair()
|
|
28
|
+
: keyPairFromSeed(input.ephemeralSeed);
|
|
29
|
+
const proof = signMessage(pair.privateKey, utf8(token.subject));
|
|
30
|
+
const chain = await requestFulcioChain({
|
|
31
|
+
fulcioUrl: input.fulcioUrl,
|
|
32
|
+
jwt,
|
|
33
|
+
publicKeyPem: publicKeyPem(pair.publicKeyBytes),
|
|
34
|
+
proofOfPossession: proof,
|
|
35
|
+
});
|
|
36
|
+
const linked = linkedChain(chain, undefined);
|
|
37
|
+
if (!bytesEqual(linked.publicKey, pair.publicKeyBytes)) {
|
|
38
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
39
|
+
}
|
|
40
|
+
if (!linked.names.includes(token.certificateIdentity)) {
|
|
41
|
+
throw new KeylessVerifyError("identity");
|
|
42
|
+
}
|
|
43
|
+
if (linked.issuer !== token.issuer) {
|
|
44
|
+
throw new KeylessVerifyError("issuer");
|
|
45
|
+
}
|
|
46
|
+
const payloadType = KEYLESS_PAYLOAD_TYPE;
|
|
47
|
+
const signature = signMessage(pair.privateKey, dssePreAuthEncoding(payloadType, input.payload));
|
|
48
|
+
const bundle = {
|
|
49
|
+
mediaType: KEYLESS_MEDIA_TYPE,
|
|
50
|
+
dsseEnvelope: {
|
|
51
|
+
payload: encodeBase64(input.payload),
|
|
52
|
+
payloadType,
|
|
53
|
+
signatures: [
|
|
54
|
+
{ keyid: toHex(pair.publicKeyBytes), sig: encodeBase64(signature) },
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
verificationMaterial: {
|
|
58
|
+
certificateChain: chain,
|
|
59
|
+
certificateIdentity: token.certificateIdentity,
|
|
60
|
+
certificateOidcIssuer: token.issuer,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
bundle,
|
|
65
|
+
certificateIdentity: token.certificateIdentity,
|
|
66
|
+
certificateOidcIssuer: token.issuer,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function verifyKeyless(input) {
|
|
70
|
+
const material = readBundle(input.bundle);
|
|
71
|
+
const leaf = chainTrusts(material.chain, input.rootPem, input.nowMs);
|
|
72
|
+
const certificateIdentity = matchIdentity(leaf.names, input.identity, input.identityPattern);
|
|
73
|
+
if (leaf.issuer !== input.issuer) {
|
|
74
|
+
throw new KeylessVerifyError("issuer");
|
|
75
|
+
}
|
|
76
|
+
const authenticated = dssePreAuthEncoding(material.payloadType, material.payload);
|
|
77
|
+
if (!verifyMessage(leaf.publicKey, authenticated, material.signature) ||
|
|
78
|
+
(material.keyId.length > 0 && material.keyId !== toHex(leaf.publicKey))) {
|
|
79
|
+
throw new KeylessVerifyError("bad_signature");
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
certificateIdentity,
|
|
83
|
+
certificateOidcIssuer: leaf.issuer,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function matchIdentity(names, identity, pattern) {
|
|
87
|
+
if ((identity === undefined) === (pattern === undefined)) {
|
|
88
|
+
throw new KeylessUsageError("pass --certificate-identity or --certificate-identity-regexp");
|
|
89
|
+
}
|
|
90
|
+
if (identity !== undefined) {
|
|
91
|
+
if (!names.includes(identity)) {
|
|
92
|
+
throw new KeylessVerifyError("identity");
|
|
93
|
+
}
|
|
94
|
+
return identity;
|
|
95
|
+
}
|
|
96
|
+
if (pattern === undefined || pattern.length < 1 || pattern.length > 256) {
|
|
97
|
+
throw new KeylessUsageError("certificate identity regexp is invalid");
|
|
98
|
+
}
|
|
99
|
+
let expression;
|
|
100
|
+
try {
|
|
101
|
+
expression = new RegExp(pattern, "u");
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
throw new KeylessUsageError("certificate identity regexp is invalid");
|
|
105
|
+
}
|
|
106
|
+
const found = names.find((name) => fullMatch(expression, name));
|
|
107
|
+
if (found === undefined) {
|
|
108
|
+
throw new KeylessVerifyError("identity");
|
|
109
|
+
}
|
|
110
|
+
return found;
|
|
111
|
+
}
|
|
112
|
+
function fullMatch(expression, name) {
|
|
113
|
+
const match = expression.exec(name);
|
|
114
|
+
return match !== null && match.index === 0 && match[0] === name;
|
|
115
|
+
}
|
|
116
|
+
function readBundle(value) {
|
|
117
|
+
if (!isRecord(value) || value.mediaType !== KEYLESS_MEDIA_TYPE) {
|
|
118
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
119
|
+
}
|
|
120
|
+
if (!isRecord(value.dsseEnvelope) || !isRecord(value.verificationMaterial)) {
|
|
121
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
122
|
+
}
|
|
123
|
+
const envelope = value.dsseEnvelope;
|
|
124
|
+
const material = value.verificationMaterial;
|
|
125
|
+
if (typeof envelope.payload !== "string" ||
|
|
126
|
+
envelope.payloadType !== KEYLESS_PAYLOAD_TYPE ||
|
|
127
|
+
!Array.isArray(envelope.signatures) ||
|
|
128
|
+
envelope.signatures.length !== 1) {
|
|
129
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
130
|
+
}
|
|
131
|
+
const signature = envelope.signatures[0];
|
|
132
|
+
if (!isRecord(signature) ||
|
|
133
|
+
typeof signature.sig !== "string" ||
|
|
134
|
+
typeof signature.keyid !== "string") {
|
|
135
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
136
|
+
}
|
|
137
|
+
const chain = material.certificateChain;
|
|
138
|
+
if (!Array.isArray(chain) || chain.length === 0) {
|
|
139
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
140
|
+
}
|
|
141
|
+
const pems = [];
|
|
142
|
+
for (const item of chain) {
|
|
143
|
+
if (typeof item !== "string" || !item.includes("BEGIN CERTIFICATE")) {
|
|
144
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
145
|
+
}
|
|
146
|
+
pems.push(item);
|
|
147
|
+
}
|
|
148
|
+
const payload = decodeBase64(envelope.payload);
|
|
149
|
+
const rawSig = decodeBase64(signature.sig);
|
|
150
|
+
if (payload === undefined || rawSig === undefined) {
|
|
151
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
payload,
|
|
155
|
+
payloadType: envelope.payloadType,
|
|
156
|
+
signature: rawSig,
|
|
157
|
+
keyId: signature.keyid,
|
|
158
|
+
chain: pems,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function isRecord(value) {
|
|
162
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
163
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `keyless seal` and `keyless verify`, and `seal --keyless` / `seal --oidc`.
|
|
3
|
+
* Seal is the only path that requests an OIDC token or calls Fulcio.
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2026 MergeSeal
|
|
6
|
+
* MergeSeal <team@mergeseal.dev>
|
|
7
|
+
*/
|
|
8
|
+
import { KeylessUsageError } from "./errors.js";
|
|
9
|
+
export { KeylessUsageError };
|
|
10
|
+
type Flags = Map<string, string[]>;
|
|
11
|
+
export declare function runKeylessCli(command: string, positionals: readonly string[], flags: Flags, json: boolean): Promise<void>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `keyless seal` and `keyless verify`, and `seal --keyless` / `seal --oidc`.
|
|
3
|
+
* Seal is the only path that requests an OIDC token or calls Fulcio.
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2026 MergeSeal
|
|
6
|
+
* MergeSeal <team@mergeseal.dev>
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { EXIT_FAIL, textFailure, withError } from "../cli-contract.js";
|
|
10
|
+
import { fromHex } from "../v1_1/bytes.js";
|
|
11
|
+
import { sealKeyless, verifyKeyless } from "./bundle.js";
|
|
12
|
+
import { KeylessUsageError, KeylessVerifyError } from "./errors.js";
|
|
13
|
+
export { KeylessUsageError };
|
|
14
|
+
import { DEFAULT_FULCIO_URL, GITHUB_ACTIONS_ISSUER, SIGSTORE_AUDIENCE, } from "./oidc.js";
|
|
15
|
+
export async function runKeylessCli(command, positionals, flags, json) {
|
|
16
|
+
if (command === "seal") {
|
|
17
|
+
if (!flags.has("keyless") && !flags.has("oidc")) {
|
|
18
|
+
throw new KeylessUsageError("seal requires --keyless or --oidc");
|
|
19
|
+
}
|
|
20
|
+
await sealCommand(flags, json);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (command !== "keyless") {
|
|
24
|
+
throw new KeylessUsageError(`unknown command ${command}`);
|
|
25
|
+
}
|
|
26
|
+
const action = positionals[0] ?? "";
|
|
27
|
+
switch (action) {
|
|
28
|
+
case "seal":
|
|
29
|
+
await sealCommand(flags, json);
|
|
30
|
+
return;
|
|
31
|
+
case "verify":
|
|
32
|
+
verifyCommand(flags, json);
|
|
33
|
+
return;
|
|
34
|
+
default:
|
|
35
|
+
throw new KeylessUsageError("keyless requires seal or verify");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function sealCommand(flags, json) {
|
|
39
|
+
const payload = readBytes(required(flags, "payload-file"), "payload-file");
|
|
40
|
+
const requestUrl = process.env.ACTIONS_ID_TOKEN_REQUEST_URL;
|
|
41
|
+
const requestToken = process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
|
|
42
|
+
if (requestUrl === undefined ||
|
|
43
|
+
requestUrl.length === 0 ||
|
|
44
|
+
requestToken === undefined ||
|
|
45
|
+
requestToken.length === 0) {
|
|
46
|
+
throw new KeylessUsageError("ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN are required");
|
|
47
|
+
}
|
|
48
|
+
const seed = ephemeralSeed(flags);
|
|
49
|
+
const sealed = await sealKeyless({
|
|
50
|
+
payload,
|
|
51
|
+
fulcioUrl: optional(flags, "fulcio-url") ?? DEFAULT_FULCIO_URL,
|
|
52
|
+
requestUrl,
|
|
53
|
+
requestToken,
|
|
54
|
+
audience: optional(flags, "audience") ?? SIGSTORE_AUDIENCE,
|
|
55
|
+
...(seed === undefined ? {} : { ephemeralSeed: seed }),
|
|
56
|
+
});
|
|
57
|
+
const out = optional(flags, "out");
|
|
58
|
+
if (out !== undefined) {
|
|
59
|
+
writeFileSync(out, `${JSON.stringify(sealed.bundle)}\n`);
|
|
60
|
+
}
|
|
61
|
+
const body = {
|
|
62
|
+
ok: true,
|
|
63
|
+
keyless: true,
|
|
64
|
+
network: true,
|
|
65
|
+
certificateIdentity: sealed.certificateIdentity,
|
|
66
|
+
certificateOidcIssuer: sealed.certificateOidcIssuer,
|
|
67
|
+
bundle: sealed.bundle,
|
|
68
|
+
...(out === undefined ? {} : { out }),
|
|
69
|
+
};
|
|
70
|
+
const text = out === undefined ? `${JSON.stringify(sealed.bundle)}\n` : `wrote ${out}\n`;
|
|
71
|
+
emit(json, body, text);
|
|
72
|
+
}
|
|
73
|
+
function verifyCommand(flags, json) {
|
|
74
|
+
const identity = optional(flags, "certificate-identity");
|
|
75
|
+
const identityPattern = optional(flags, "certificate-identity-regexp");
|
|
76
|
+
if ((identity === undefined) === (identityPattern === undefined)) {
|
|
77
|
+
throw new KeylessUsageError("pass --certificate-identity or --certificate-identity-regexp");
|
|
78
|
+
}
|
|
79
|
+
const bundle = readJson(required(flags, "bundle"));
|
|
80
|
+
const rootPem = readText(required(flags, "fulcio-root"), "fulcio-root");
|
|
81
|
+
let verified;
|
|
82
|
+
try {
|
|
83
|
+
verified = verifyKeyless({
|
|
84
|
+
bundle,
|
|
85
|
+
nowMs: millis(required(flags, "now")),
|
|
86
|
+
rootPem,
|
|
87
|
+
identity,
|
|
88
|
+
identityPattern,
|
|
89
|
+
issuer: optional(flags, "certificate-oidc-issuer") ?? GITHUB_ACTIONS_ISSUER,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (!(error instanceof KeylessVerifyError)) {
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
const body = {
|
|
97
|
+
ok: false,
|
|
98
|
+
network: false,
|
|
99
|
+
reason: error.reason,
|
|
100
|
+
};
|
|
101
|
+
const text = `reject ${error.reason}\n`;
|
|
102
|
+
emit(json, withError(body, error.reason, EXIT_FAIL, verifyNext()), text);
|
|
103
|
+
if (!json) {
|
|
104
|
+
process.stderr.write(textFailure(error.reason, verifyNext()));
|
|
105
|
+
}
|
|
106
|
+
process.exit(EXIT_FAIL);
|
|
107
|
+
}
|
|
108
|
+
emit(json, {
|
|
109
|
+
ok: true,
|
|
110
|
+
network: false,
|
|
111
|
+
certificateIdentity: verified.certificateIdentity,
|
|
112
|
+
certificateOidcIssuer: verified.certificateOidcIssuer,
|
|
113
|
+
}, `ok ${verified.certificateIdentity}\n`);
|
|
114
|
+
}
|
|
115
|
+
function verifyNext() {
|
|
116
|
+
return "npx mergeseal keyless verify --bundle FILE --certificate-identity ID --fulcio-root FILE --now MS --json";
|
|
117
|
+
}
|
|
118
|
+
function ephemeralSeed(flags) {
|
|
119
|
+
const text = optional(flags, "ephemeral-seed");
|
|
120
|
+
if (text === undefined) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
if (!/^[0-9a-fA-F]{64}$/u.test(text)) {
|
|
124
|
+
throw new KeylessUsageError("ephemeral-seed must be 32 bytes of hex");
|
|
125
|
+
}
|
|
126
|
+
return fromHex(text.toLowerCase());
|
|
127
|
+
}
|
|
128
|
+
function millis(text) {
|
|
129
|
+
if (!/^\d+$/u.test(text)) {
|
|
130
|
+
throw new KeylessUsageError("now must be a millisecond timestamp");
|
|
131
|
+
}
|
|
132
|
+
const value = Number(text);
|
|
133
|
+
if (!Number.isSafeInteger(value)) {
|
|
134
|
+
throw new KeylessUsageError("now must be a millisecond timestamp");
|
|
135
|
+
}
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
function readBytes(path, label) {
|
|
139
|
+
try {
|
|
140
|
+
return new Uint8Array(readFileSync(path));
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
const message = error instanceof Error ? error.message : "unreadable";
|
|
144
|
+
throw new KeylessUsageError(`cannot read ${label}: ${message}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function readText(path, label) {
|
|
148
|
+
try {
|
|
149
|
+
return readFileSync(path, "utf8");
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
const message = error instanceof Error ? error.message : "unreadable";
|
|
153
|
+
throw new KeylessUsageError(`cannot read ${label}: ${message}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function readJson(path) {
|
|
157
|
+
try {
|
|
158
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
const message = error instanceof Error ? error.message : "unreadable";
|
|
162
|
+
throw new KeylessUsageError(`cannot read bundle: ${message}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function required(flags, name) {
|
|
166
|
+
const value = optional(flags, name);
|
|
167
|
+
if (value === undefined || value.length === 0) {
|
|
168
|
+
throw new KeylessUsageError(`missing --${name}`);
|
|
169
|
+
}
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
function optional(flags, name) {
|
|
173
|
+
const values = flags.get(name);
|
|
174
|
+
return values === undefined ? undefined : values[values.length - 1];
|
|
175
|
+
}
|
|
176
|
+
function emit(json, value, text) {
|
|
177
|
+
if (json) {
|
|
178
|
+
process.stdout.write(`${JSON.stringify(value)}\n`);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
process.stdout.write(text);
|
|
182
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Failures for opt-in GitHub Actions keyless signing.
|
|
3
|
+
* A usage error is exit 2. A verify error is exit 1 and its message
|
|
4
|
+
* is the reason token.
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2026 MergeSeal
|
|
7
|
+
* MergeSeal <team@mergeseal.dev>
|
|
8
|
+
*/
|
|
9
|
+
export declare const VERIFY_REASONS: readonly ["expired", "invalid_certificate", "identity", "issuer", "bad_signature"];
|
|
10
|
+
export type VerifyReason = (typeof VERIFY_REASONS)[number];
|
|
11
|
+
export declare class KeylessUsageError extends Error {
|
|
12
|
+
constructor(message: string);
|
|
13
|
+
}
|
|
14
|
+
export declare class KeylessVerifyError extends Error {
|
|
15
|
+
readonly reason: VerifyReason;
|
|
16
|
+
constructor(reason: VerifyReason);
|
|
17
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Failures for opt-in GitHub Actions keyless signing.
|
|
3
|
+
* A usage error is exit 2. A verify error is exit 1 and its message
|
|
4
|
+
* is the reason token.
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2026 MergeSeal
|
|
7
|
+
* MergeSeal <team@mergeseal.dev>
|
|
8
|
+
*/
|
|
9
|
+
export const VERIFY_REASONS = [
|
|
10
|
+
"expired",
|
|
11
|
+
"invalid_certificate",
|
|
12
|
+
"identity",
|
|
13
|
+
"issuer",
|
|
14
|
+
"bad_signature",
|
|
15
|
+
];
|
|
16
|
+
export class KeylessUsageError extends Error {
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = "KeylessUsageError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class KeylessVerifyError extends Error {
|
|
23
|
+
reason;
|
|
24
|
+
constructor(reason) {
|
|
25
|
+
super(reason);
|
|
26
|
+
this.name = "KeylessVerifyError";
|
|
27
|
+
this.reason = reason;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sigstore Fulcio v2 signing-certificate request.
|
|
3
|
+
* The proof of possession is an Ed25519 signature over the OIDC `sub`.
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2026 MergeSeal
|
|
6
|
+
* MergeSeal <team@mergeseal.dev>
|
|
7
|
+
*/
|
|
8
|
+
export declare function requestFulcioChain(input: {
|
|
9
|
+
readonly fulcioUrl: string;
|
|
10
|
+
readonly jwt: string;
|
|
11
|
+
readonly publicKeyPem: string;
|
|
12
|
+
readonly proofOfPossession: Uint8Array;
|
|
13
|
+
}): Promise<readonly string[]>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sigstore Fulcio v2 signing-certificate request.
|
|
3
|
+
* The proof of possession is an Ed25519 signature over the OIDC `sub`.
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2026 MergeSeal
|
|
6
|
+
* MergeSeal <team@mergeseal.dev>
|
|
7
|
+
*/
|
|
8
|
+
import { encodeBase64 } from "./asn1.js";
|
|
9
|
+
import { KeylessUsageError, KeylessVerifyError } from "./errors.js";
|
|
10
|
+
import { splitCertificates } from "./x509.js";
|
|
11
|
+
export async function requestFulcioChain(input) {
|
|
12
|
+
let endpoint;
|
|
13
|
+
try {
|
|
14
|
+
endpoint = new URL(input.fulcioUrl);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
throw new KeylessUsageError("fulcio url is not a URL");
|
|
18
|
+
}
|
|
19
|
+
if (endpoint.protocol !== "http:" && endpoint.protocol !== "https:") {
|
|
20
|
+
throw new KeylessUsageError("fulcio url is not http");
|
|
21
|
+
}
|
|
22
|
+
const base = endpoint.toString().replace(/\/$/u, "");
|
|
23
|
+
endpoint.href = `${base}/api/v2/signingCert`;
|
|
24
|
+
let response;
|
|
25
|
+
try {
|
|
26
|
+
response = await fetch(endpoint, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: {
|
|
29
|
+
Accept: "application/json",
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
},
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
credentials: { oidcIdentityToken: input.jwt },
|
|
34
|
+
publicKeyRequest: {
|
|
35
|
+
publicKey: {
|
|
36
|
+
algorithm: "ED25519",
|
|
37
|
+
content: input.publicKeyPem,
|
|
38
|
+
},
|
|
39
|
+
proofOfPossession: encodeBase64(input.proofOfPossession),
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
redirect: "error",
|
|
43
|
+
signal: AbortSignal.timeout(15_000),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
48
|
+
}
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
51
|
+
}
|
|
52
|
+
const type = response.headers.get("content-type") ?? "";
|
|
53
|
+
if (type.includes("pem")) {
|
|
54
|
+
return chainFromPem(await response.text());
|
|
55
|
+
}
|
|
56
|
+
let body;
|
|
57
|
+
try {
|
|
58
|
+
body = await response.json();
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
62
|
+
}
|
|
63
|
+
return chainFromJson(body);
|
|
64
|
+
}
|
|
65
|
+
function chainFromJson(body) {
|
|
66
|
+
if (!isRecord(body)) {
|
|
67
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
68
|
+
}
|
|
69
|
+
const detached = body.signedCertificateDetachedSct;
|
|
70
|
+
const embedded = body.signedCertificateEmbeddedSct;
|
|
71
|
+
const holder = isRecord(detached)
|
|
72
|
+
? detached
|
|
73
|
+
: isRecord(embedded)
|
|
74
|
+
? embedded
|
|
75
|
+
: undefined;
|
|
76
|
+
if (holder === undefined || !isRecord(holder.chain)) {
|
|
77
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
78
|
+
}
|
|
79
|
+
const certificates = holder.chain.certificates;
|
|
80
|
+
if (!Array.isArray(certificates) || certificates.length === 0) {
|
|
81
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
82
|
+
}
|
|
83
|
+
const chain = [];
|
|
84
|
+
for (const item of certificates) {
|
|
85
|
+
if (typeof item !== "string") {
|
|
86
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
87
|
+
}
|
|
88
|
+
chain.push(...splitCertificates(item));
|
|
89
|
+
}
|
|
90
|
+
if (chain.length === 0) {
|
|
91
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
92
|
+
}
|
|
93
|
+
return chain;
|
|
94
|
+
}
|
|
95
|
+
function chainFromPem(text) {
|
|
96
|
+
const chain = splitCertificates(text);
|
|
97
|
+
if (chain.length === 0) {
|
|
98
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
99
|
+
}
|
|
100
|
+
return chain;
|
|
101
|
+
}
|
|
102
|
+
function isRecord(value) {
|
|
103
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
104
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in GitHub Actions keyless signing.
|
|
3
|
+
* Static MERGESEAL_KEY sealing does not import a network call from here.
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2026 MergeSeal
|
|
6
|
+
* MergeSeal <team@mergeseal.dev>
|
|
7
|
+
*/
|
|
8
|
+
export type { KeylessBundle, SealResult } from "./bundle.js";
|
|
9
|
+
export { KEYLESS_MEDIA_TYPE, KEYLESS_PAYLOAD_TYPE, sealKeyless, verifyKeyless, } from "./bundle.js";
|
|
10
|
+
export type { VerifyReason } from "./errors.js";
|
|
11
|
+
export { KeylessUsageError, KeylessVerifyError } from "./errors.js";
|
|
12
|
+
export { requestFulcioChain } from "./fulcio.js";
|
|
13
|
+
export type { GithubActionsToken } from "./oidc.js";
|
|
14
|
+
export { DEFAULT_FULCIO_URL, GITHUB_ACTIONS_ISSUER, readGithubActionsToken, requestOidcJwt, SIGSTORE_AUDIENCE, } from "./oidc.js";
|
|
15
|
+
export type { CertificateAuthority, LeafCertificate } from "./x509.js";
|
|
16
|
+
export { CERTIFICATE_LIFETIME_MS, certificateWindow, chainTrusts, codeSigningSubjectDer, createCertificateAuthority, issueCaCertificate, issueCodeSigningCertificate, issueCodeSigningCertificateSignedBy, linkedChain, publicKeyPem, splitCertificates, } from "./x509.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in GitHub Actions keyless signing.
|
|
3
|
+
* Static MERGESEAL_KEY sealing does not import a network call from here.
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2026 MergeSeal
|
|
6
|
+
* MergeSeal <team@mergeseal.dev>
|
|
7
|
+
*/
|
|
8
|
+
export { KEYLESS_MEDIA_TYPE, KEYLESS_PAYLOAD_TYPE, sealKeyless, verifyKeyless, } from "./bundle.js";
|
|
9
|
+
export { KeylessUsageError, KeylessVerifyError } from "./errors.js";
|
|
10
|
+
export { requestFulcioChain } from "./fulcio.js";
|
|
11
|
+
export { DEFAULT_FULCIO_URL, GITHUB_ACTIONS_ISSUER, readGithubActionsToken, requestOidcJwt, SIGSTORE_AUDIENCE, } from "./oidc.js";
|
|
12
|
+
export { CERTIFICATE_LIFETIME_MS, certificateWindow, chainTrusts, codeSigningSubjectDer, createCertificateAuthority, issueCaCertificate, issueCodeSigningCertificate, issueCodeSigningCertificateSignedBy, linkedChain, publicKeyPem, splitCertificates, } from "./x509.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub Actions OIDC for keyless sealing.
|
|
3
|
+
* The token is requested from ACTIONS_ID_TOKEN_REQUEST_URL.
|
|
4
|
+
* Static MERGESEAL_KEY commands do not call this module.
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2026 MergeSeal
|
|
7
|
+
* MergeSeal <team@mergeseal.dev>
|
|
8
|
+
*/
|
|
9
|
+
export declare const GITHUB_ACTIONS_ISSUER = "https://token.actions.githubusercontent.com";
|
|
10
|
+
export declare const SIGSTORE_AUDIENCE = "sigstore";
|
|
11
|
+
export declare const DEFAULT_FULCIO_URL = "https://fulcio.sigstore.dev";
|
|
12
|
+
export type GithubActionsToken = {
|
|
13
|
+
readonly jwt: string;
|
|
14
|
+
readonly issuer: typeof GITHUB_ACTIONS_ISSUER;
|
|
15
|
+
readonly subject: string;
|
|
16
|
+
readonly certificateIdentity: string;
|
|
17
|
+
readonly issuedAtSeconds: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function requestOidcJwt(input: {
|
|
20
|
+
readonly requestUrl: string;
|
|
21
|
+
readonly requestToken: string;
|
|
22
|
+
readonly audience: string;
|
|
23
|
+
}): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Reads a GitHub Actions token. The signature is Fulcio's job.
|
|
26
|
+
* A token whose issuer is not GitHub Actions is refused here, so
|
|
27
|
+
* this client does not ask Fulcio to bind any other identity.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readGithubActionsToken(jwt: string, audience: string): GithubActionsToken;
|