@cloudhal/release-verify 0.0.0-placeholder.0 → 0.10.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 +81 -2
- package/dist/src/attestation.d.ts +42 -0
- package/dist/src/attestation.js +180 -0
- package/dist/src/crypto.d.ts +15 -0
- package/dist/src/crypto.js +87 -0
- package/dist/src/documents.d.ts +23 -0
- package/dist/src/documents.js +167 -0
- package/dist/src/errors.d.ts +13 -0
- package/dist/src/errors.js +48 -0
- package/dist/src/generated/release-keys.d.ts +67 -0
- package/dist/src/generated/release-keys.js +72 -0
- package/dist/src/generated/release-manifest.d.ts +211 -0
- package/dist/src/generated/release-manifest.js +237 -0
- package/dist/src/generated/release-statement.d.ts +61 -0
- package/dist/src/generated/release-statement.js +66 -0
- package/dist/src/generated/release-yank-list.d.ts +73 -0
- package/dist/src/generated/release-yank-list.js +78 -0
- package/dist/src/generated/validators.d.ts +22 -0
- package/dist/src/generated/validators.js +5656 -0
- package/dist/src/index.d.ts +22 -0
- package/dist/src/index.js +48 -0
- package/dist/src/keys.d.ts +28 -0
- package/dist/src/keys.js +84 -0
- package/dist/src/limits.d.ts +24 -0
- package/dist/src/limits.js +30 -0
- package/dist/src/paths.d.ts +14 -0
- package/dist/src/paths.js +59 -0
- package/dist/src/scopes.d.ts +10 -0
- package/dist/src/scopes.js +22 -0
- package/dist/src/tar.d.ts +31 -0
- package/dist/src/tar.js +398 -0
- package/dist/src/trust.d.ts +67 -0
- package/dist/src/trust.js +248 -0
- package/dist/src/urls.d.ts +8 -0
- package/dist/src/urls.js +37 -0
- package/dist/src/verify.d.ts +68 -0
- package/dist/src/verify.js +171 -0
- package/dist/src/yank-memory.d.ts +22 -0
- package/dist/src/yank-memory.js +106 -0
- package/package.json +50 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,82 @@
|
|
|
1
|
-
# @cloudhal/release-verify
|
|
1
|
+
# @cloudhal/release-verify
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Verifies a [Cloudhal](https://cloudhal.dev) release bundle before you deploy it. It follows [RFC-0046](https://github.com/cloudhal-dev/cloudhal/blob/main/docs/rfcs/0046-release-bundles.md) §2, §7 and §11a: hosts, tools and the `cloudhal` CLI share this one verifier. It runs on Workers, Node 24 and browsers.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { releaseAssetUrls, verifyRelease } from "@cloudhal/release-verify";
|
|
7
|
+
|
|
8
|
+
const release = await verifyRelease({
|
|
9
|
+
request: { version: "0.9.0" }, // what you asked for: a signed older release is refused
|
|
10
|
+
statement, signature, manifest, // the exact downloaded bytes (Uint8Array)
|
|
11
|
+
tarball: () => fetchTarballStream(), // opened twice: digest first, then entries
|
|
12
|
+
planVersion: 1, // the highest plan version your deployer supports
|
|
13
|
+
});
|
|
14
|
+
for await (const entry of release.entries()) {
|
|
15
|
+
// { worker, kind, path, type?, bytes }: verified against the signed manifest
|
|
16
|
+
}
|
|
17
|
+
// Activate the deployment only after the loop has finished without an error.
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## What it checks
|
|
21
|
+
|
|
22
|
+
1. **Sizes.** The statement is at most 4096 bytes, and the signature is exactly 64.
|
|
23
|
+
2. **Signature.** Ed25519 over the exact statement bytes, with a trusted key for `signing.keyId`.
|
|
24
|
+
3. **Request.** The statement is for the requested version and channel.
|
|
25
|
+
4. **Statement.** Its schema, through the precompiled validator, plus RFC-0046 §2 invariants 1 to 3 and 6.
|
|
26
|
+
5. **Manifest.**
|
|
27
|
+
- Its size and SHA-256 equal the statement's.
|
|
28
|
+
- Its schema and invariants 4 and 5.
|
|
29
|
+
- The `release-statement.sig` signature form.
|
|
30
|
+
- `planVersion`.
|
|
31
|
+
- Every listed path, and §7's limits.
|
|
32
|
+
6. **Tarball.** Its size and SHA-256 equal the statement's.
|
|
33
|
+
|
|
34
|
+
Then `entries()` re-reads the tarball. It refuses:
|
|
35
|
+
- an entry the manifest does not list, or one whose size or SHA-256 differs from its listing;
|
|
36
|
+
- a missing entry;
|
|
37
|
+
- anything outside §7's tar format;
|
|
38
|
+
- an unsafe path: `..`, `.`, an empty segment, a backslash, a control character, more than 512 bytes, or two paths that collide after case folding.
|
|
39
|
+
|
|
40
|
+
There is no soft-fail mode. Every refusal is a `ReleaseVerifyError` with a stable `code` (`ERROR_CODES`).
|
|
41
|
+
|
|
42
|
+
## Keys
|
|
43
|
+
|
|
44
|
+
`PINNED_KEYS` holds the keys of [docs/security/release-signing-keys.md](https://github.com/cloudhal-dev/cloudhal/blob/main/docs/security/release-signing-keys.md) as they were when this version was published. It cannot learn about later revocations by itself.
|
|
45
|
+
|
|
46
|
+
You can only reduce trust: pass `revoked: ["<keyId>"]` to withdraw a key. Passing your own `keys` map replaces the table, so treat that as a reviewed change.
|
|
47
|
+
|
|
48
|
+
## Key list and yank list (RFC-0046 §9)
|
|
49
|
+
|
|
50
|
+
`keys.json` (signed by an offline root) and `yanked.json` (signed by a yank key) live at `https://cloudhal.dev/.well-known/cloudhal/`, each with its `.sig`. Fetch all four on every run, verify them, and merge them into the keys you pin. They can only take trust away:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { mergeTrust, PINNED_KEYS, verifyKeys, verifyRelease, verifyYanked } from "@cloudhal/release-verify";
|
|
54
|
+
|
|
55
|
+
const keys = await verifyKeys({ document: keysJson, signature: keysSig }); // pinned root, fresh
|
|
56
|
+
const yanked = await verifyYanked({ document: yankedJson, signature: yankedSig, keys }); // stale → stale-yank-list
|
|
57
|
+
await verifyRelease({ ...input, keys: mergeTrust(PINNED_KEYS, { keys, yanked }), yanked });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- **Expiry.** A statement's `createdAt` must lie within its key's `[notBefore, notAfter]`. After `notAfter`, the key verifies only while a fresh `keys.json` lists it as `retiring`. With pinned keys alone, the release is refused with `key-expired`.
|
|
61
|
+
- **Yanking.** A yanked version is refused (`yanked`), and a key that `yanked.json` revokes is refused (`key-revoked`).
|
|
62
|
+
- **Keep state if you can.** Pass the `memory` you stored to `verifyKeys` and `verifyYanked`, and store `rememberYanks(yanked, keys, memory)` after every accepted pair. Refused:
|
|
63
|
+
- a list that goes back in `serial`, or drops a version or key you have already seen yanked or revoked (`stale-yank-list`);
|
|
64
|
+
- a `keys.json` older than the newest one you have seen (`key-list-invalid`), so a replayed list cannot bring back a revoked yank key;
|
|
65
|
+
- a list signed by a yank key a root list revoked or replaced (`yank-list-invalid`);
|
|
66
|
+
- a list from another yank key, unless a newer `keys.json` replaces the remembered one (`stale-yank-list`).
|
|
67
|
+
|
|
68
|
+
Without memory, a stolen yank key could undo yanks for you until the root rotates it. A `keys.json` lists at most one active yank key.
|
|
69
|
+
- **Not yet published.** `PINNED_ROOTS` is empty until the root is generated. Until then `verifyKeys` refuses every list, unless you pass `roots`.
|
|
70
|
+
|
|
71
|
+
## The second factor
|
|
72
|
+
|
|
73
|
+
The Node-only subpath `@cloudhal/release-verify/attestation` checks the GitHub build-provenance attestation of the tarball, the manifest and the statement. It needs `gh` 2.68.0 or newer, signed in. It returns `verified` or `failed`, or `unavailable` when `gh` is missing, too old, or signed out.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { verifyAttestation } from "@cloudhal/release-verify/attestation";
|
|
77
|
+
const r = await verifyAttestation({ dir, version: "0.9.0", commit: release.statement.commit });
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Scopes
|
|
81
|
+
|
|
82
|
+
`missingScopes(manifest, granted)` compares Cloudflare scope ids exactly, with one exception: `workers-scripts.admin` covers `workers-scripts.edit`, which manifests up to v0.9.0 name (RFC-0046 §3).
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const MIN_GH_VERSION = "2.68.0";
|
|
2
|
+
export declare const SIGNER_WORKFLOW = "cloudhal-dev/cloudhal/.github/workflows/bundle-build.yml";
|
|
3
|
+
/** Every flag the verify call passes; the probe requires each in `gh attestation verify --help`. */
|
|
4
|
+
export declare const ATTESTATION_FLAGS: readonly ["--repo", "--signer-workflow", "--source-ref", "--source-digest", "--deny-self-hosted-runners", "--bundle"];
|
|
5
|
+
export type AttestationResult = {
|
|
6
|
+
readonly status: "verified";
|
|
7
|
+
} | {
|
|
8
|
+
readonly status: "failed";
|
|
9
|
+
readonly file: string;
|
|
10
|
+
readonly reason: string;
|
|
11
|
+
} | {
|
|
12
|
+
readonly status: "unavailable";
|
|
13
|
+
readonly reason: string;
|
|
14
|
+
};
|
|
15
|
+
export interface RunResult {
|
|
16
|
+
readonly code: number | null;
|
|
17
|
+
readonly signal: string | null;
|
|
18
|
+
readonly timedOut: boolean;
|
|
19
|
+
readonly stdout: string;
|
|
20
|
+
readonly stderr: string;
|
|
21
|
+
}
|
|
22
|
+
export type Runner = (cmd: string, args: readonly string[], timeoutMs: number) => Promise<RunResult>;
|
|
23
|
+
export interface AttestationOptions {
|
|
24
|
+
/** The directory holding the downloaded assets. */
|
|
25
|
+
readonly dir: string;
|
|
26
|
+
readonly version: string;
|
|
27
|
+
/** The verified statement's `commit` (40 hex), pinned with `--source-digest`. */
|
|
28
|
+
readonly commit: string;
|
|
29
|
+
readonly timeoutMs?: number;
|
|
30
|
+
/** For tests: how commands run (default: spawn, no shell). */
|
|
31
|
+
readonly run?: Runner;
|
|
32
|
+
}
|
|
33
|
+
/** The argument vector of the verify call for `file` (exact flags of §11a). */
|
|
34
|
+
export declare function attestationArgs(file: string, commit: string, bundle?: string): string[];
|
|
35
|
+
/** `a.b.c` ≥ `min`, comparing the numeric parts. */
|
|
36
|
+
export declare function versionAtLeast(version: string, min: string): boolean;
|
|
37
|
+
/** The version `gh --version` prints first (`gh version 2.102.0 (2026-09-30)`). */
|
|
38
|
+
export declare function ghVersionOf(stdout: string): string | undefined;
|
|
39
|
+
/** Verifies the attestation of the tarball, the manifest and the statement in `o.dir`. */
|
|
40
|
+
export declare function verifyAttestation(o: AttestationOptions): Promise<AttestationResult>;
|
|
41
|
+
/** Runs `cmd` without a shell; never throws for a non-zero exit. */
|
|
42
|
+
export declare const spawnRunner: Runner;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The second factor (RFC-0046 §2, §9, §11a): the GitHub build-provenance attestation of a
|
|
3
|
+
* release's files, checked with `gh attestation verify`. Node only (it runs `gh`).
|
|
4
|
+
*
|
|
5
|
+
* - `unavailable` (nothing verified): `gh` is missing, older than 2.68.0 (the first release with
|
|
6
|
+
* `--source-ref` and `--source-digest`), lacks one of the flags below in its `--help`, or is not
|
|
7
|
+
* signed in. Callers decide what that means; the CLI refuses unless told to rely on one factor.
|
|
8
|
+
* - `failed`: any non-zero exit, a signal, or no exit within the timeout. Always a refusal.
|
|
9
|
+
* - `verified`: all three files (tarball, manifest, statement) verified.
|
|
10
|
+
*/
|
|
11
|
+
import { spawn } from "node:child_process";
|
|
12
|
+
import { existsSync } from "node:fs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import { MANIFEST_FILE, STATEMENT_FILE, sigstoreName, tarballName } from "./limits.js";
|
|
15
|
+
import { RELEASE_REPOSITORY, releaseAssetNames } from "./urls.js";
|
|
16
|
+
|
|
17
|
+
export const MIN_GH_VERSION = "2.68.0";
|
|
18
|
+
export const SIGNER_WORKFLOW = `${RELEASE_REPOSITORY}/.github/workflows/bundle-build.yml`;
|
|
19
|
+
/** Every flag the verify call passes; the probe requires each in `gh attestation verify --help`. */
|
|
20
|
+
export const ATTESTATION_FLAGS = [
|
|
21
|
+
"--repo",
|
|
22
|
+
"--signer-workflow",
|
|
23
|
+
"--source-ref",
|
|
24
|
+
"--source-digest",
|
|
25
|
+
"--deny-self-hosted-runners",
|
|
26
|
+
"--bundle",
|
|
27
|
+
] ;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
/** The argument vector of the verify call for `file` (exact flags of §11a). */
|
|
60
|
+
export function attestationArgs(file , commit , bundle ) {
|
|
61
|
+
return [
|
|
62
|
+
"attestation",
|
|
63
|
+
"verify",
|
|
64
|
+
file,
|
|
65
|
+
"--repo",
|
|
66
|
+
RELEASE_REPOSITORY,
|
|
67
|
+
"--signer-workflow",
|
|
68
|
+
SIGNER_WORKFLOW,
|
|
69
|
+
"--source-ref",
|
|
70
|
+
"refs/heads/main",
|
|
71
|
+
"--source-digest",
|
|
72
|
+
commit,
|
|
73
|
+
"--deny-self-hosted-runners",
|
|
74
|
+
...(bundle ? ["--bundle", bundle] : []),
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** `a.b.c` ≥ `min`, comparing the numeric parts. */
|
|
79
|
+
export function versionAtLeast(version , min ) {
|
|
80
|
+
const a = version.split(".").map((x) => Number.parseInt(x, 10));
|
|
81
|
+
const b = min.split(".").map((x) => Number.parseInt(x, 10));
|
|
82
|
+
for (let i = 0; i < 3; i++) {
|
|
83
|
+
const x = a[i] ?? 0;
|
|
84
|
+
const y = b[i] ?? 0;
|
|
85
|
+
if (Number.isNaN(x)) return false;
|
|
86
|
+
if (x !== y) return x > y;
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The version `gh --version` prints first (`gh version 2.102.0 (2026-09-30)`). */
|
|
92
|
+
export function ghVersionOf(stdout ) {
|
|
93
|
+
const first = stdout.split("\n", 1)[0] ?? "";
|
|
94
|
+
const words = first.trim().split(" ");
|
|
95
|
+
return words[0] === "gh" && words[1] === "version" ? words[2] : undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const ok = (r ) => r.code === 0 && r.signal === null && !r.timedOut;
|
|
99
|
+
|
|
100
|
+
async function probe(run , timeoutMs ) {
|
|
101
|
+
const need = `gh ${MIN_GH_VERSION} or newer, signed in (gh auth login)`;
|
|
102
|
+
const v = await run("gh", ["--version"], timeoutMs).catch(() => undefined);
|
|
103
|
+
if (!v || !ok(v)) return `gh is not installed: install ${need}`;
|
|
104
|
+
const version = ghVersionOf(v.stdout);
|
|
105
|
+
if (!version || !versionAtLeast(version, MIN_GH_VERSION))
|
|
106
|
+
return `gh ${version ?? "(unknown version)"} is too old: install ${need}`;
|
|
107
|
+
const help = await run("gh", ["attestation", "verify", "--help"], timeoutMs).catch(
|
|
108
|
+
() => undefined,
|
|
109
|
+
);
|
|
110
|
+
const text = help ? `${help.stdout}\n${help.stderr}` : "";
|
|
111
|
+
const lacking = ATTESTATION_FLAGS.filter((f) => !text.includes(f));
|
|
112
|
+
if (!help || !ok(help) || lacking.length)
|
|
113
|
+
return `gh ${version} lacks gh attestation verify ${lacking.join(" ")}: install ${need}`;
|
|
114
|
+
const auth = await run("gh", ["auth", "status"], timeoutMs).catch(() => undefined);
|
|
115
|
+
if (!auth || !ok(auth)) return `gh is not signed in: run gh auth login`;
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Verifies the attestation of the tarball, the manifest and the statement in `o.dir`. */
|
|
120
|
+
export async function verifyAttestation(o ) {
|
|
121
|
+
releaseAssetNames(o.version); // refuses a malformed version before anything runs
|
|
122
|
+
if (o.commit.length !== 40 || [...o.commit].some((c) => !"0123456789abcdef".includes(c)))
|
|
123
|
+
throw new TypeError("commit must be 40 lowercase hex characters");
|
|
124
|
+
const run = o.run ?? spawnRunner;
|
|
125
|
+
const timeoutMs = o.timeoutMs ?? 60_000;
|
|
126
|
+
const why = await probe(run, timeoutMs);
|
|
127
|
+
if (why) return { status: "unavailable", reason: why };
|
|
128
|
+
// Absolute paths, so no file name can ever be read by gh as a flag.
|
|
129
|
+
const dir = path.resolve(o.dir);
|
|
130
|
+
const bundle = path.join(dir, sigstoreName(o.version));
|
|
131
|
+
const withBundle = existsSync(bundle) ? bundle : undefined;
|
|
132
|
+
for (const name of [tarballName(o.version), MANIFEST_FILE, STATEMENT_FILE]) {
|
|
133
|
+
const file = path.join(dir, name);
|
|
134
|
+
const r = await run("gh", attestationArgs(file, o.commit, withBundle), timeoutMs).catch(
|
|
135
|
+
(e ) => ({
|
|
136
|
+
code: null,
|
|
137
|
+
signal: null,
|
|
138
|
+
timedOut: false,
|
|
139
|
+
stdout: "",
|
|
140
|
+
stderr: e.message,
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
if (!ok(r)) {
|
|
144
|
+
const reason = r.timedOut
|
|
145
|
+
? `no answer within ${timeoutMs / 1000} s`
|
|
146
|
+
: r.signal
|
|
147
|
+
? `stopped by ${r.signal}`
|
|
148
|
+
: r.stderr.trim().split("\n").pop() || `exit ${r.code}`;
|
|
149
|
+
return { status: "failed", file: name, reason };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return { status: "verified" };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Runs `cmd` without a shell; never throws for a non-zero exit. */
|
|
156
|
+
export const spawnRunner = (cmd, args, timeoutMs) =>
|
|
157
|
+
new Promise((resolve, reject) => {
|
|
158
|
+
const child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
159
|
+
let stdout = "";
|
|
160
|
+
let stderr = "";
|
|
161
|
+
let timedOut = false;
|
|
162
|
+
const timer = setTimeout(() => {
|
|
163
|
+
timedOut = true;
|
|
164
|
+
child.kill("SIGKILL");
|
|
165
|
+
}, timeoutMs);
|
|
166
|
+
child.stdout.on("data", (c ) => {
|
|
167
|
+
stdout += c.toString();
|
|
168
|
+
});
|
|
169
|
+
child.stderr.on("data", (c ) => {
|
|
170
|
+
stderr += c.toString();
|
|
171
|
+
});
|
|
172
|
+
child.once("error", (e) => {
|
|
173
|
+
clearTimeout(timer);
|
|
174
|
+
reject(e);
|
|
175
|
+
});
|
|
176
|
+
child.once("close", (code, signal) => {
|
|
177
|
+
clearTimeout(timer);
|
|
178
|
+
resolve({ code, signal, timedOut, stdout, stderr });
|
|
179
|
+
});
|
|
180
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Pure Ed25519 over the exact `message` bytes. */
|
|
2
|
+
export declare function verifyEd25519(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): Promise<boolean>;
|
|
3
|
+
/** SHA-256 of `bytes`, lowercase hex. */
|
|
4
|
+
export declare function sha256Hex(bytes: Uint8Array): Promise<string>;
|
|
5
|
+
export interface IncrementalSha256 {
|
|
6
|
+
update(chunk: Uint8Array): Promise<void>;
|
|
7
|
+
/** Lowercase hex; call once, after the last `update`. */
|
|
8
|
+
digest(): Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
/** Workers' `crypto.DigestStream` (a WritableStream whose `digest` resolves on close). */
|
|
11
|
+
export type DigestStreamConstructor = new (algorithm: string) => WritableStream<Uint8Array> & {
|
|
12
|
+
readonly digest: Promise<ArrayBuffer>;
|
|
13
|
+
};
|
|
14
|
+
/** An incremental SHA-256: `crypto.DigestStream` when the runtime has one, else @noble/hashes. */
|
|
15
|
+
export declare function incrementalSha256(DigestStream?: DigestStreamConstructor | undefined): IncrementalSha256;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ed25519 and SHA-256 on every runtime (RFC-0046 §11a): WebCrypto for Ed25519 and one-shot
|
|
3
|
+
* digests; for the streamed tarball, Workers' native `crypto.DigestStream` where it exists and
|
|
4
|
+
* otherwise `@noble/hashes` (audited, zero dependencies), because WebCrypto's `digest` cannot
|
|
5
|
+
* stream. test/crypto.test.ts checks both paths against the NIST vectors and `node:crypto`.
|
|
6
|
+
*/
|
|
7
|
+
import { sha256 as nobleSha256 } from "@noble/hashes/sha2.js";
|
|
8
|
+
|
|
9
|
+
const toHex = (bytes ) => {
|
|
10
|
+
let s = "";
|
|
11
|
+
for (const b of bytes) s += b.toString(16).padStart(2, "0");
|
|
12
|
+
return s;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* `bytes` as WebCrypto's `BufferSource` under every consumer's lib settings: the same view when it
|
|
17
|
+
* is backed by an `ArrayBuffer`, else a copy (a `SharedArrayBuffer` is never handed to WebCrypto).
|
|
18
|
+
*/
|
|
19
|
+
function buffer(bytes ) {
|
|
20
|
+
return bytes.buffer instanceof ArrayBuffer
|
|
21
|
+
? (bytes )
|
|
22
|
+
: new Uint8Array(bytes);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Pure Ed25519 over the exact `message` bytes. */
|
|
26
|
+
export async function verifyEd25519(
|
|
27
|
+
publicKey ,
|
|
28
|
+
message ,
|
|
29
|
+
signature ,
|
|
30
|
+
) {
|
|
31
|
+
try {
|
|
32
|
+
const key = await crypto.subtle.importKey(
|
|
33
|
+
"raw",
|
|
34
|
+
buffer(publicKey),
|
|
35
|
+
{ name: "Ed25519" },
|
|
36
|
+
false,
|
|
37
|
+
["verify"],
|
|
38
|
+
);
|
|
39
|
+
return await crypto.subtle.verify({ name: "Ed25519" }, key, buffer(signature), buffer(message));
|
|
40
|
+
} catch {
|
|
41
|
+
// A key that is not a valid Ed25519 point verifies nothing.
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** SHA-256 of `bytes`, lowercase hex. */
|
|
47
|
+
export async function sha256Hex(bytes ) {
|
|
48
|
+
return toHex(new Uint8Array(await crypto.subtle.digest("SHA-256", buffer(bytes))));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
/** Workers' `crypto.DigestStream` (a WritableStream whose `digest` resolves on close). */
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
const nativeDigestStream = () =>
|
|
63
|
+
(globalThis ).crypto?.DigestStream;
|
|
64
|
+
|
|
65
|
+
/** An incremental SHA-256: `crypto.DigestStream` when the runtime has one, else @noble/hashes. */
|
|
66
|
+
export function incrementalSha256(
|
|
67
|
+
DigestStream = nativeDigestStream(),
|
|
68
|
+
) {
|
|
69
|
+
if (DigestStream) {
|
|
70
|
+
const stream = new DigestStream("SHA-256");
|
|
71
|
+
const writer = stream.getWriter();
|
|
72
|
+
return {
|
|
73
|
+
update: (chunk) => writer.write(chunk),
|
|
74
|
+
async digest() {
|
|
75
|
+
await writer.close();
|
|
76
|
+
return toHex(new Uint8Array(await stream.digest));
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const h = nobleSha256.create();
|
|
81
|
+
return {
|
|
82
|
+
update: async (chunk) => {
|
|
83
|
+
h.update(chunk);
|
|
84
|
+
},
|
|
85
|
+
digest: async () => toHex(h.digest()),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ReleaseManifest } from "./generated/release-manifest.js";
|
|
2
|
+
import type { ReleaseStatement } from "./generated/release-statement.js";
|
|
3
|
+
/** The JSON document in `bytes`, or the refusal `code`. */
|
|
4
|
+
export declare function parseJson(bytes: Uint8Array, code: "statement-invalid" | "manifest-invalid"): unknown;
|
|
5
|
+
/** §2 step 4: the schema, then invariants 1, 2, 3 and 6. */
|
|
6
|
+
export declare function checkStatementDoc(doc: unknown, serialisedBytes: number): ReleaseStatement;
|
|
7
|
+
/** §2 step 3 (invariant 7): the statement is for the version and channel that were asked for. */
|
|
8
|
+
export declare function checkRequested(doc: unknown, version: string, channel?: "stable" | "next"): void;
|
|
9
|
+
/** §2 step 5 after the digest: the schema, invariants 4 and 5, the signature form, planVersion. */
|
|
10
|
+
export declare function checkManifestDoc(doc: unknown, statement: ReleaseStatement, planVersion: number): ReleaseManifest;
|
|
11
|
+
export type Worker = "site" | "admin";
|
|
12
|
+
/** One part the manifest lists, by its tar path. */
|
|
13
|
+
export interface ListedPart {
|
|
14
|
+
readonly worker: Worker | null;
|
|
15
|
+
readonly kind: "module" | "asset" | "starter";
|
|
16
|
+
/** The module path, the asset path (`/x`), or the starter's `starter/<file>`. */
|
|
17
|
+
readonly path: string;
|
|
18
|
+
readonly type?: string;
|
|
19
|
+
readonly bytes: number;
|
|
20
|
+
readonly sha256: string;
|
|
21
|
+
}
|
|
22
|
+
/** Every part the manifest lists, keyed by its tar path (`site/modules/x.mjs`, …). */
|
|
23
|
+
export declare function listedParts(m: ReleaseManifest): Map<string, ListedPart>;
|