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,130 @@
|
|
|
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
|
+
import { base64UrlDecodeStrict } from "../v1_1/b64.js";
|
|
10
|
+
import { KeylessUsageError, KeylessVerifyError } from "./errors.js";
|
|
11
|
+
export const GITHUB_ACTIONS_ISSUER = "https://token.actions.githubusercontent.com";
|
|
12
|
+
export const SIGSTORE_AUDIENCE = "sigstore";
|
|
13
|
+
export const DEFAULT_FULCIO_URL = "https://fulcio.sigstore.dev";
|
|
14
|
+
const WORKFLOW_REF = /^[\w.-]+\/[\w.-]+\/\.github\/workflows\/[\w.-]+@.+$/u;
|
|
15
|
+
export async function requestOidcJwt(input) {
|
|
16
|
+
let url;
|
|
17
|
+
try {
|
|
18
|
+
url = new URL(input.requestUrl);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
throw new KeylessUsageError("ACTIONS_ID_TOKEN_REQUEST_URL is not a URL");
|
|
22
|
+
}
|
|
23
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
24
|
+
throw new KeylessUsageError("ACTIONS_ID_TOKEN_REQUEST_URL is not http");
|
|
25
|
+
}
|
|
26
|
+
url.searchParams.set("audience", input.audience);
|
|
27
|
+
let response;
|
|
28
|
+
try {
|
|
29
|
+
response = await fetch(url, {
|
|
30
|
+
method: "GET",
|
|
31
|
+
headers: {
|
|
32
|
+
Accept: "application/json",
|
|
33
|
+
Authorization: `bearer ${input.requestToken}`,
|
|
34
|
+
},
|
|
35
|
+
redirect: "error",
|
|
36
|
+
signal: AbortSignal.timeout(15_000),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
41
|
+
}
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
44
|
+
}
|
|
45
|
+
let body;
|
|
46
|
+
try {
|
|
47
|
+
body = await response.json();
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
51
|
+
}
|
|
52
|
+
if (!isRecord(body) ||
|
|
53
|
+
typeof body.value !== "string" ||
|
|
54
|
+
body.value.length < 1) {
|
|
55
|
+
throw new KeylessVerifyError("invalid_certificate");
|
|
56
|
+
}
|
|
57
|
+
return body.value;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Reads a GitHub Actions token. The signature is Fulcio's job.
|
|
61
|
+
* A token whose issuer is not GitHub Actions is refused here, so
|
|
62
|
+
* this client does not ask Fulcio to bind any other identity.
|
|
63
|
+
*/
|
|
64
|
+
export function readGithubActionsToken(jwt, audience) {
|
|
65
|
+
const payload = jwtPayload(jwt);
|
|
66
|
+
if (payload.iss !== GITHUB_ACTIONS_ISSUER) {
|
|
67
|
+
throw new KeylessVerifyError("issuer");
|
|
68
|
+
}
|
|
69
|
+
if (!audienceIncludes(payload.aud, audience)) {
|
|
70
|
+
throw new KeylessVerifyError("identity");
|
|
71
|
+
}
|
|
72
|
+
if (typeof payload.sub !== "string" || payload.sub.length < 1) {
|
|
73
|
+
throw new KeylessVerifyError("identity");
|
|
74
|
+
}
|
|
75
|
+
if (typeof payload.job_workflow_ref !== "string" ||
|
|
76
|
+
!WORKFLOW_REF.test(payload.job_workflow_ref)) {
|
|
77
|
+
throw new KeylessVerifyError("identity");
|
|
78
|
+
}
|
|
79
|
+
if (typeof payload.iat !== "number" ||
|
|
80
|
+
!Number.isSafeInteger(payload.iat) ||
|
|
81
|
+
payload.iat < 0) {
|
|
82
|
+
throw new KeylessUsageError("oidc iat is not a time");
|
|
83
|
+
}
|
|
84
|
+
if (typeof payload.exp !== "number" ||
|
|
85
|
+
!Number.isSafeInteger(payload.exp) ||
|
|
86
|
+
payload.exp <= payload.iat) {
|
|
87
|
+
throw new KeylessUsageError("oidc exp is not a time");
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
jwt,
|
|
91
|
+
issuer: GITHUB_ACTIONS_ISSUER,
|
|
92
|
+
subject: payload.sub,
|
|
93
|
+
certificateIdentity: `https://github.com/${payload.job_workflow_ref}`,
|
|
94
|
+
issuedAtSeconds: payload.iat,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function jwtPayload(jwt) {
|
|
98
|
+
const parts = jwt.split(".");
|
|
99
|
+
if (parts.length !== 3) {
|
|
100
|
+
throw new KeylessUsageError("oidc token is malformed");
|
|
101
|
+
}
|
|
102
|
+
const encoded = parts[1];
|
|
103
|
+
if (encoded === undefined) {
|
|
104
|
+
throw new KeylessUsageError("oidc token is malformed");
|
|
105
|
+
}
|
|
106
|
+
const raw = base64UrlDecodeStrict(encoded);
|
|
107
|
+
if (raw === undefined) {
|
|
108
|
+
throw new KeylessUsageError("oidc token is malformed");
|
|
109
|
+
}
|
|
110
|
+
let parsed;
|
|
111
|
+
try {
|
|
112
|
+
parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(raw));
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
throw new KeylessUsageError("oidc token is malformed");
|
|
116
|
+
}
|
|
117
|
+
if (!isRecord(parsed)) {
|
|
118
|
+
throw new KeylessUsageError("oidc token is malformed");
|
|
119
|
+
}
|
|
120
|
+
return parsed;
|
|
121
|
+
}
|
|
122
|
+
function audienceIncludes(aud, expected) {
|
|
123
|
+
if (typeof aud === "string") {
|
|
124
|
+
return aud === expected;
|
|
125
|
+
}
|
|
126
|
+
return Array.isArray(aud) && aud.some((item) => item === expected);
|
|
127
|
+
}
|
|
128
|
+
function isRecord(value) {
|
|
129
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
130
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ed25519 code-signing certificates for a Fulcio-shaped keyless seal.
|
|
3
|
+
* The leaf SAN is the GitHub Actions workflow URI. The OIDC issuer is
|
|
4
|
+
* extension 1.3.6.1.4.1.57264.1.8, a DER UTF8String.
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2026 MergeSeal
|
|
7
|
+
* MergeSeal <team@mergeseal.dev>
|
|
8
|
+
*/
|
|
9
|
+
export declare const CERTIFICATE_LIFETIME_MS: number;
|
|
10
|
+
export type CertificateAuthority = {
|
|
11
|
+
readonly commonName: string;
|
|
12
|
+
readonly privateKey: string;
|
|
13
|
+
readonly certificateDer: Uint8Array;
|
|
14
|
+
readonly certificatePem: string;
|
|
15
|
+
readonly subjectDer: Uint8Array;
|
|
16
|
+
};
|
|
17
|
+
export type LeafCertificate = {
|
|
18
|
+
readonly der: Uint8Array;
|
|
19
|
+
readonly pem: string;
|
|
20
|
+
readonly notBeforeMs: number;
|
|
21
|
+
readonly notAfterMs: number;
|
|
22
|
+
};
|
|
23
|
+
export type LeafIdentity = {
|
|
24
|
+
readonly names: readonly string[];
|
|
25
|
+
readonly issuer: string;
|
|
26
|
+
readonly notBeforeMs: number;
|
|
27
|
+
readonly notAfterMs: number;
|
|
28
|
+
readonly publicKey: Uint8Array;
|
|
29
|
+
};
|
|
30
|
+
export declare function certificateWindow(issuedAtSeconds: number): {
|
|
31
|
+
readonly notBeforeMs: number;
|
|
32
|
+
readonly notAfterMs: number;
|
|
33
|
+
};
|
|
34
|
+
export declare function createCertificateAuthority(input: {
|
|
35
|
+
readonly commonName: string;
|
|
36
|
+
readonly privateKey: string;
|
|
37
|
+
readonly publicKey: Uint8Array;
|
|
38
|
+
readonly notBeforeMs: number;
|
|
39
|
+
readonly notAfterMs: number;
|
|
40
|
+
readonly pathLenConstraint?: number;
|
|
41
|
+
}): CertificateAuthority;
|
|
42
|
+
export declare function issueCodeSigningCertificate(input: {
|
|
43
|
+
readonly issuer: CertificateAuthority;
|
|
44
|
+
readonly publicKey: Uint8Array;
|
|
45
|
+
readonly certificateIdentity: string;
|
|
46
|
+
readonly oidcIssuer: string;
|
|
47
|
+
readonly tokenSubject: string;
|
|
48
|
+
readonly notBeforeMs: number;
|
|
49
|
+
readonly notAfterMs: number;
|
|
50
|
+
}): LeafCertificate;
|
|
51
|
+
/**
|
|
52
|
+
* Subject name of a code-signing leaf. A forged child uses this as its
|
|
53
|
+
* issuer name when the signer is that leaf.
|
|
54
|
+
*/
|
|
55
|
+
export declare function codeSigningSubjectDer(): Uint8Array;
|
|
56
|
+
/**
|
|
57
|
+
* Signs a code-signing certificate. This does not decide that the issuer
|
|
58
|
+
* is a CA. Verification does.
|
|
59
|
+
*/
|
|
60
|
+
export declare function issueCodeSigningCertificateSignedBy(input: {
|
|
61
|
+
readonly issuerPrivateKey: string;
|
|
62
|
+
readonly issuerName: Uint8Array;
|
|
63
|
+
readonly issuerCertificatePem: string;
|
|
64
|
+
readonly publicKey: Uint8Array;
|
|
65
|
+
readonly certificateIdentity: string;
|
|
66
|
+
readonly oidcIssuer: string;
|
|
67
|
+
readonly tokenSubject: string;
|
|
68
|
+
readonly notBeforeMs: number;
|
|
69
|
+
readonly notAfterMs: number;
|
|
70
|
+
readonly keyCertSign?: boolean;
|
|
71
|
+
}): LeafCertificate;
|
|
72
|
+
/** A CA certificate signed by another CA. The new key is `privateKey`. */
|
|
73
|
+
export declare function issueCaCertificate(input: {
|
|
74
|
+
readonly issuer: CertificateAuthority;
|
|
75
|
+
readonly commonName: string;
|
|
76
|
+
readonly privateKey: string;
|
|
77
|
+
readonly publicKey: Uint8Array;
|
|
78
|
+
readonly notBeforeMs: number;
|
|
79
|
+
readonly notAfterMs: number;
|
|
80
|
+
readonly pathLenConstraint?: number;
|
|
81
|
+
}): CertificateAuthority;
|
|
82
|
+
export declare function publicKeyPem(publicKey: Uint8Array): string;
|
|
83
|
+
export declare function splitCertificates(pem: string): string[];
|
|
84
|
+
/** The chain links, and the leaf was signed by the trusted root. */
|
|
85
|
+
export declare function chainTrusts(chain: readonly string[], rootPem: string, nowMs: number): LeafIdentity;
|
|
86
|
+
/**
|
|
87
|
+
* Leaf and parents form one chain. No external root. Time is checked
|
|
88
|
+
* only when `nowMs` is set, so a seal can attach a certificate whose
|
|
89
|
+
* window is fixed by the test token rather than the wall clock.
|
|
90
|
+
*/
|
|
91
|
+
export declare function linkedChain(chain: readonly string[], nowMs: number | undefined): LeafIdentity;
|