@tinfoilsh/verifier 1.3.0 → 2.0.0-rc.1

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.
Files changed (224) hide show
  1. package/README.md +29 -17
  2. package/dist/document/collateral/collateral.d.ts +76 -0
  3. package/dist/document/collateral/collateral.d.ts.map +1 -0
  4. package/dist/document/collateral/collateral.js +175 -0
  5. package/dist/document/collateral/collateral.js.map +1 -0
  6. package/dist/document/collateral/config.d.ts +24 -0
  7. package/dist/document/collateral/config.d.ts.map +1 -0
  8. package/dist/document/collateral/config.js +46 -0
  9. package/dist/document/collateral/config.js.map +1 -0
  10. package/dist/document/collateral/runtime.d.ts +20 -0
  11. package/dist/document/collateral/runtime.d.ts.map +1 -0
  12. package/dist/document/collateral/runtime.js +37 -0
  13. package/dist/document/collateral/runtime.js.map +1 -0
  14. package/dist/document/collateral/sev.d.ts +13 -0
  15. package/dist/document/collateral/sev.d.ts.map +1 -0
  16. package/dist/document/collateral/sev.js +26 -0
  17. package/dist/document/collateral/sev.js.map +1 -0
  18. package/dist/document/collateral/sigstore.d.ts +19 -0
  19. package/dist/document/collateral/sigstore.d.ts.map +1 -0
  20. package/dist/document/collateral/sigstore.js +31 -0
  21. package/dist/document/collateral/sigstore.js.map +1 -0
  22. package/dist/document/collateral/tdx.d.ts +14 -0
  23. package/dist/document/collateral/tdx.d.ts.map +1 -0
  24. package/dist/document/collateral/tdx.js +44 -0
  25. package/dist/document/collateral/tdx.js.map +1 -0
  26. package/dist/document/document.d.ts +112 -0
  27. package/dist/document/document.d.ts.map +1 -0
  28. package/dist/document/document.js +387 -0
  29. package/dist/document/document.js.map +1 -0
  30. package/dist/errors.d.ts +44 -76
  31. package/dist/errors.d.ts.map +1 -1
  32. package/dist/errors.js +52 -81
  33. package/dist/errors.js.map +1 -1
  34. package/dist/index.d.ts +31 -10
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +70 -10
  37. package/dist/index.js.map +1 -1
  38. package/dist/internal/bytes.d.ts +13 -0
  39. package/dist/internal/bytes.d.ts.map +1 -0
  40. package/dist/internal/bytes.js +37 -0
  41. package/dist/internal/bytes.js.map +1 -0
  42. package/dist/internal/canonical.js +89 -0
  43. package/dist/internal/canonical.js.map +1 -0
  44. package/dist/internal/endorsement/approval.js +467 -0
  45. package/dist/internal/endorsement/approval.js.map +1 -0
  46. package/dist/internal/endorsement/freshness.js +122 -0
  47. package/dist/internal/endorsement/freshness.js.map +1 -0
  48. package/dist/internal/endorsement/provenance.js +256 -0
  49. package/dist/internal/endorsement/provenance.js.map +1 -0
  50. package/dist/internal/endorsement/reference.d.ts +32 -0
  51. package/dist/internal/endorsement/reference.d.ts.map +1 -0
  52. package/dist/internal/endorsement/reference.js +37 -0
  53. package/dist/internal/endorsement/reference.js.map +1 -0
  54. package/dist/internal/endorsement/registry-certificate.js +147 -0
  55. package/dist/internal/endorsement/registry-certificate.js.map +1 -0
  56. package/dist/internal/endorsement/runtime.js +52 -0
  57. package/dist/internal/endorsement/runtime.js.map +1 -0
  58. package/dist/internal/endorsement/time.js +26 -0
  59. package/dist/internal/endorsement/time.js.map +1 -0
  60. package/dist/internal/json/decode.js +151 -0
  61. package/dist/internal/json/decode.js.map +1 -0
  62. package/dist/internal/json/index.d.ts +68 -0
  63. package/dist/internal/json/index.d.ts.map +1 -0
  64. package/dist/internal/json/index.js +486 -0
  65. package/dist/internal/json/index.js.map +1 -0
  66. package/dist/internal/policy/artifact.js +191 -0
  67. package/dist/internal/policy/artifact.js.map +1 -0
  68. package/dist/internal/policy/sev.js +157 -0
  69. package/dist/internal/policy/sev.js.map +1 -0
  70. package/dist/internal/policy/shape.js +31 -0
  71. package/dist/internal/policy/shape.js.map +1 -0
  72. package/dist/internal/policy/tdx.js +55 -0
  73. package/dist/internal/policy/tdx.js.map +1 -0
  74. package/dist/internal/quote/config.js +53 -0
  75. package/dist/internal/quote/config.js.map +1 -0
  76. package/dist/internal/quote/legacy.js +67 -0
  77. package/dist/internal/quote/legacy.js.map +1 -0
  78. package/dist/internal/quote/quote.js +139 -0
  79. package/dist/internal/quote/quote.js.map +1 -0
  80. package/dist/internal/quote/resolve.js +88 -0
  81. package/dist/internal/quote/resolve.js.map +1 -0
  82. package/dist/internal/quote/sev/authenticate.js +125 -0
  83. package/dist/internal/quote/sev/authenticate.js.map +1 -0
  84. package/dist/internal/quote/sev/expectations.js +288 -0
  85. package/dist/internal/quote/sev/expectations.js.map +1 -0
  86. package/dist/internal/quote/sev/identity.js +13 -0
  87. package/dist/internal/quote/sev/identity.js.map +1 -0
  88. package/dist/internal/quote/sev/report.js +224 -0
  89. package/dist/internal/quote/sev/report.js.map +1 -0
  90. package/dist/internal/quote/sev/tcb.js +110 -0
  91. package/dist/internal/quote/sev/tcb.js.map +1 -0
  92. package/dist/internal/quote/sev/vcek.js +299 -0
  93. package/dist/internal/quote/sev/vcek.js.map +1 -0
  94. package/dist/internal/quote/tdx/abi.js +161 -0
  95. package/dist/internal/quote/tdx/abi.js.map +1 -0
  96. package/dist/internal/quote/tdx/authenticate.js +343 -0
  97. package/dist/internal/quote/tdx/authenticate.js.map +1 -0
  98. package/dist/internal/quote/tdx/identity.js +11 -0
  99. package/dist/internal/quote/tdx/identity.js.map +1 -0
  100. package/dist/internal/quote/tdx/pck.js +133 -0
  101. package/dist/internal/quote/tdx/pck.js.map +1 -0
  102. package/dist/internal/quote/tdx/pcs.js +482 -0
  103. package/dist/internal/quote/tdx/pcs.js.map +1 -0
  104. package/dist/internal/rfc3339.js +24 -0
  105. package/dist/internal/rfc3339.js.map +1 -0
  106. package/dist/internal/runtime/config.js +61 -0
  107. package/dist/internal/runtime/config.js.map +1 -0
  108. package/dist/internal/runtime/manifest.js +82 -0
  109. package/dist/internal/runtime/manifest.js.map +1 -0
  110. package/dist/internal/semver.js +124 -0
  111. package/dist/internal/semver.js.map +1 -0
  112. package/dist/internal/sigstore/bundle.js +205 -0
  113. package/dist/internal/sigstore/bundle.js.map +1 -0
  114. package/dist/internal/sigstore/certificate.js +220 -0
  115. package/dist/internal/sigstore/certificate.js.map +1 -0
  116. package/dist/internal/sigstore/certified.js +56 -0
  117. package/dist/internal/sigstore/certified.js.map +1 -0
  118. package/dist/internal/sigstore/keyed.js +556 -0
  119. package/dist/internal/sigstore/keyed.js.map +1 -0
  120. package/dist/internal/sigstore/timestamp.js +421 -0
  121. package/dist/internal/sigstore/timestamp.js.map +1 -0
  122. package/dist/internal/sigstore/trusted-root.js +144 -0
  123. package/dist/internal/sigstore/trusted-root.js.map +1 -0
  124. package/dist/internal/x509/certificate.js +521 -0
  125. package/dist/internal/x509/certificate.js.map +1 -0
  126. package/dist/internal/x509/crl.js +116 -0
  127. package/dist/internal/x509/crl.js.map +1 -0
  128. package/dist/internal/x509/der.js +409 -0
  129. package/dist/internal/x509/der.js.map +1 -0
  130. package/dist/measurement.d.ts +47 -0
  131. package/dist/measurement.d.ts.map +1 -0
  132. package/dist/measurement.js +92 -0
  133. package/dist/measurement.js.map +1 -0
  134. package/dist/trust/amd-genoa-chain.js +4 -0
  135. package/dist/trust/amd-genoa-chain.js.map +1 -0
  136. package/dist/trust/amd-turin-chain.js +4 -0
  137. package/dist/trust/amd-turin-chain.js.map +1 -0
  138. package/dist/trust/intel-sgx-root.js +4 -0
  139. package/dist/trust/intel-sgx-root.js.map +1 -0
  140. package/dist/trust/signing-keys.js +7 -0
  141. package/dist/trust/signing-keys.js.map +1 -0
  142. package/dist/trust/sigstore-trusted-root.js +4 -0
  143. package/dist/trust/sigstore-trusted-root.js.map +1 -0
  144. package/dist/verification.d.ts +134 -0
  145. package/dist/verification.d.ts.map +1 -0
  146. package/dist/verification.js +129 -0
  147. package/dist/verification.js.map +1 -0
  148. package/dist/verifier.d.ts +115 -0
  149. package/dist/verifier.d.ts.map +1 -0
  150. package/dist/verifier.js +565 -0
  151. package/dist/verifier.js.map +1 -0
  152. package/dist/version.js +2 -3
  153. package/dist/version.js.map +1 -1
  154. package/package.json +20 -12
  155. package/dist/attestation.d.ts +0 -14
  156. package/dist/attestation.d.ts.map +0 -1
  157. package/dist/attestation.js +0 -117
  158. package/dist/attestation.js.map +0 -1
  159. package/dist/bundle.d.ts +0 -15
  160. package/dist/bundle.d.ts.map +0 -1
  161. package/dist/bundle.js +0 -134
  162. package/dist/bundle.js.map +0 -1
  163. package/dist/cert-verify.d.ts +0 -30
  164. package/dist/cert-verify.d.ts.map +0 -1
  165. package/dist/cert-verify.js +0 -132
  166. package/dist/cert-verify.js.map +0 -1
  167. package/dist/client.d.ts +0 -17
  168. package/dist/client.d.ts.map +0 -1
  169. package/dist/client.js +0 -135
  170. package/dist/client.js.map +0 -1
  171. package/dist/dcode.d.ts +0 -7
  172. package/dist/dcode.d.ts.map +0 -1
  173. package/dist/dcode.js +0 -35
  174. package/dist/dcode.js.map +0 -1
  175. package/dist/json.d.ts +0 -3
  176. package/dist/json.d.ts.map +0 -1
  177. package/dist/json.js +0 -4
  178. package/dist/json.js.map +0 -1
  179. package/dist/sev/cert-chain.d.ts +0 -22
  180. package/dist/sev/cert-chain.d.ts.map +0 -1
  181. package/dist/sev/cert-chain.js +0 -253
  182. package/dist/sev/cert-chain.js.map +0 -1
  183. package/dist/sev/certs.d.ts +0 -3
  184. package/dist/sev/certs.d.ts.map +0 -1
  185. package/dist/sev/certs.js +0 -77
  186. package/dist/sev/certs.js.map +0 -1
  187. package/dist/sev/constants.d.ts +0 -20
  188. package/dist/sev/constants.d.ts.map +0 -1
  189. package/dist/sev/constants.js +0 -22
  190. package/dist/sev/constants.js.map +0 -1
  191. package/dist/sev/report.d.ts +0 -52
  192. package/dist/sev/report.d.ts.map +0 -1
  193. package/dist/sev/report.js +0 -228
  194. package/dist/sev/report.js.map +0 -1
  195. package/dist/sev/types.d.ts +0 -35
  196. package/dist/sev/types.d.ts.map +0 -1
  197. package/dist/sev/types.js +0 -2
  198. package/dist/sev/types.js.map +0 -1
  199. package/dist/sev/utils.d.ts +0 -7
  200. package/dist/sev/utils.d.ts.map +0 -1
  201. package/dist/sev/utils.js +0 -59
  202. package/dist/sev/utils.js.map +0 -1
  203. package/dist/sev/validation.d.ts +0 -39
  204. package/dist/sev/validation.d.ts.map +0 -1
  205. package/dist/sev/validation.js +0 -324
  206. package/dist/sev/validation.js.map +0 -1
  207. package/dist/sev/verify.d.ts +0 -11
  208. package/dist/sev/verify.d.ts.map +0 -1
  209. package/dist/sev/verify.js +0 -141
  210. package/dist/sev/verify.js.map +0 -1
  211. package/dist/sigstore-trusted-root.d.ts +0 -94
  212. package/dist/sigstore-trusted-root.d.ts.map +0 -1
  213. package/dist/sigstore-trusted-root.js +0 -127
  214. package/dist/sigstore-trusted-root.js.map +0 -1
  215. package/dist/sigstore.d.ts +0 -18
  216. package/dist/sigstore.d.ts.map +0 -1
  217. package/dist/sigstore.js +0 -115
  218. package/dist/sigstore.js.map +0 -1
  219. package/dist/types.d.ts +0 -94
  220. package/dist/types.d.ts.map +0 -1
  221. package/dist/types.js +0 -73
  222. package/dist/types.js.map +0 -1
  223. package/dist/version.d.ts +0 -4
  224. package/dist/version.d.ts.map +0 -1
@@ -0,0 +1,556 @@
1
+ /**
2
+ * Key-signed bundle verification for approvals signed with a pinned key:
3
+ * no certificate, a public-key hint, between one and eight hashedrekord
4
+ * 0.0.2 log entries each with an inclusion proof and no promise, no
5
+ * integration times, and no RFC 3161 timestamps inside the bundle.
6
+ *
7
+ * Each log entry's body must be the canonical hashedrekord record the log
8
+ * would have built from this envelope and key: the digest of the signed
9
+ * message, the DSSE signature, and the pinned key's DER form. Its inclusion
10
+ * proof must reach the root of a checkpoint (a signed note) that the entry's
11
+ * log signed for its own origin. Nothing in a key-signed bundle states a
12
+ * time, so log keys are not checked against their validity windows here; the
13
+ * approval's own signed timestamp establishes when it was made.
14
+ */
15
+ import { concat, sha256, toHex, utf8 } from "../bytes.js";
16
+ import { decodeBase64 } from "../canonical.js";
17
+ import { arr, object, str, struct } from "../json/decode.js";
18
+ import { canonicalize, JsonNumber, strictParse } from "../json/index.js";
19
+ import { bytesEqual, expectSequence, isUniversal } from "../x509/certificate.js";
20
+ import { bitString, decode, DerError, ecdsaSignatureToRaw, oid, pemBlocks, TAG } from "../x509/der.js";
21
+ import { IN_TOTO_PAYLOAD_TYPE } from "./bundle.js";
22
+ import { MAX_TIMESTAMP_SIZE, preAuthEncoding } from "./timestamp.js";
23
+ export const MAX_LOG_RECEIPTS = 8;
24
+ /** The log entry kind and version a key-signed approval must carry. */
25
+ export const HASHEDREKORD_KIND = "hashedrekord";
26
+ export const HASHEDREKORD_VERSION = "0.0.2";
27
+ const OID_EC_PUBLIC_KEY = "1.2.840.10045.2.1";
28
+ const OID_P256 = "1.2.840.10045.3.1.7";
29
+ const P256 = { name: "ECDSA", namedCurve: "P-256" };
30
+ export async function keyHint(key) {
31
+ const imported = key instanceof Uint8Array ? await importP256(key) : key;
32
+ return toBase64(await sha256(await exportP256(imported)));
33
+ }
34
+ /** Imports PEM-encoded P-256 public keys as pinned keys; a key that repeats rejects. */
35
+ export async function pinnedKeys(pems) {
36
+ const out = [];
37
+ const seen = new Set();
38
+ for (const pem of pems) {
39
+ let blocks;
40
+ try {
41
+ blocks = pemBlocks(pem, "PUBLIC KEY");
42
+ }
43
+ catch (err) {
44
+ throw new Error(`parsing signing key: ${message(err)}`);
45
+ }
46
+ if (blocks.length === 0)
47
+ throw new Error("signing key PEM has no PUBLIC KEY block");
48
+ for (const spki of blocks) {
49
+ const key = await importP256(spki);
50
+ const hint = await keyHint(key);
51
+ if (seen.has(hint))
52
+ throw new Error(`duplicate signing key ${hint}`);
53
+ seen.add(hint);
54
+ out.push({ hint, key });
55
+ }
56
+ }
57
+ if (out.length === 0)
58
+ throw new Error("at least one signing key is required");
59
+ return out;
60
+ }
61
+ /**
62
+ * Verifies a key-signed DSSE bundle: the layout above, the key hint naming
63
+ * one of `keys` with an empty DSSE key id, every log entry's
64
+ * body consistent with the envelope and its inclusion proof and checkpoint
65
+ * valid for a log in `root`, and the DSSE signature over the payload. Returns
66
+ * the hint of the key that verified.
67
+ *
68
+ * `digest` is the SHA-256 of the artifact the approval is for; the signed
69
+ * in-toto statement must name it in a subject.
70
+ */
71
+ export async function verifyKeyedBundle(root, bundle, keys, digest) {
72
+ if (bundle.certificate !== undefined)
73
+ throw new Error("approval bundle must carry a key hint, not a certificate");
74
+ const hint = bundle.publicKeyHint;
75
+ if (hint === undefined || hint === "")
76
+ throw new Error("approval bundle has no public key hint");
77
+ if (bundle.dsse.payloadType !== IN_TOTO_PAYLOAD_TYPE) {
78
+ throw new Error(`unsupported DSSE payload type ${JSON.stringify(bundle.dsse.payloadType)}`);
79
+ }
80
+ // The hint identifies the key; a DSSE key id, even one equal to the hint,
81
+ // never verifies.
82
+ if (bundle.dsse.keyId !== "")
83
+ throw new Error("DSSE key id must be empty for a key-signed bundle");
84
+ const pinned = keys.find((k) => k.hint === hint);
85
+ if (pinned === undefined)
86
+ throw new Error("untrusted approval signing key");
87
+ if (digest.length !== 32)
88
+ throw new Error("expected artifact digest is not SHA-256");
89
+ checkLayout(bundle, "none");
90
+ const spki = await exportP256(pinned.key);
91
+ const signed = preAuthEncoding(bundle.dsse.payloadType, bundle.dsse.payload);
92
+ if (!(await verifyP256(pinned.key, bundle.dsse.signature, signed))) {
93
+ throw new Error("DSSE signature does not verify under the pinned key");
94
+ }
95
+ await verifyLogEntries(root, bundle, { digest: toBase64(await sha256(signed)), signature: toBase64(bundle.dsse.signature), verifier: { publicKey: toBase64(spki) } });
96
+ if (!statementNamesDigest(bundle.dsse.payload, toHex(digest))) {
97
+ throw new Error("the statement's subjects do not name the artifact digest");
98
+ }
99
+ return hint;
100
+ }
101
+ /**
102
+ * The entry rules above: a bounded count of hashedrekord 0.0.2 entries with
103
+ * proofs only and no duplicates. `timestamps` says whether the bundle must
104
+ * carry no RFC 3161 timestamp (a key-signed approval, whose time is inside
105
+ * the statement) or exactly one bounded timestamp (a certificate-signed
106
+ * approval, whose signing time that timestamp establishes).
107
+ */
108
+ export function checkLayout(bundle, timestamps) {
109
+ const entries = bundle.tlogEntries;
110
+ if (entries.length === 0 || entries.length > MAX_LOG_RECEIPTS) {
111
+ throw new Error(`approval requires between 1 and ${MAX_LOG_RECEIPTS} transparency log entries, got ${entries.length}`);
112
+ }
113
+ const seen = new Set();
114
+ entries.forEach((entry, i) => {
115
+ if (entry.kind !== HASHEDREKORD_KIND || entry.version !== HASHEDREKORD_VERSION) {
116
+ throw new Error(`transparency log entry ${i} is ${entry.kind} ${entry.version}, not ${HASHEDREKORD_KIND} ${HASHEDREKORD_VERSION}`);
117
+ }
118
+ if (entry.integratedTime !== undefined)
119
+ throw new Error(`transparency log entry ${i} carries an integration time`);
120
+ if (entry.inclusionPromise !== undefined)
121
+ throw new Error(`transparency log entry ${i} carries an inclusion promise`);
122
+ if (entry.inclusionProof === undefined)
123
+ throw new Error(`transparency log entry ${i} has no inclusion proof`);
124
+ const id = `${entry.logId}/${entry.inclusionProof.logIndex}`;
125
+ if (seen.has(id))
126
+ throw new Error(`transparency log entry ${i} duplicates an earlier entry`);
127
+ seen.add(id);
128
+ });
129
+ if (timestamps === "none" && bundle.rfc3161Timestamps.length !== 0)
130
+ throw new Error("approval bundle must carry no RFC 3161 timestamps");
131
+ if (timestamps === "one")
132
+ signatureTimestamp(bundle);
133
+ }
134
+ /**
135
+ * The one RFC 3161 timestamp a certificate-signed bundle carries over its
136
+ * DSSE signature. Any other count, or an oversized timestamp, rejects.
137
+ */
138
+ export function signatureTimestamp(bundle) {
139
+ const timestamps = bundle.rfc3161Timestamps;
140
+ if (timestamps.length !== 1 || timestamps[0].length === 0 || timestamps[0].length > MAX_TIMESTAMP_SIZE) {
141
+ throw new Error("certified registry endorsement requires one bounded signature timestamp");
142
+ }
143
+ return timestamps[0];
144
+ }
145
+ /** Verifies every log entry of `bundle` against the record it must carry. */
146
+ export async function verifyLogEntries(root, bundle, expected) {
147
+ for (let i = 0; i < bundle.tlogEntries.length; i++) {
148
+ try {
149
+ await verifyEntry(root, bundle.tlogEntries[i], expected);
150
+ }
151
+ catch (err) {
152
+ throw new Error(`transparency log entry ${i}: ${message(err)}`);
153
+ }
154
+ }
155
+ }
156
+ const BODY_MEMBERS = ["apiVersion", "kind", "spec"];
157
+ const SPEC_MEMBERS = ["hashedRekordV002"];
158
+ const RECORD_MEMBERS = ["data", "signature"];
159
+ const DATA_MEMBERS = ["algorithm", "digest"];
160
+ const SIGNATURE_MEMBERS = ["content", "verifier"];
161
+ const VERIFIER_MEMBERS = ["publicKey", "x509Certificate", "keyDetails"];
162
+ const RAW_BYTES_MEMBERS = ["rawBytes"];
163
+ const HASH_ALGORITHM = "SHA2_256";
164
+ const KEY_DETAILS = "PKIX_ECDSA_P256_SHA_256";
165
+ async function verifyEntry(root, entry, expected) {
166
+ checkBody(entry.canonicalizedBody, expected);
167
+ const proof = entry.inclusionProof;
168
+ if (proof === undefined)
169
+ throw new Error("no inclusion proof");
170
+ const log = root.transparencyLogs.find((l) => l.logId === entry.logId);
171
+ if (log === undefined)
172
+ throw new Error("names a transparency log the trusted root does not list");
173
+ const origin = await logOrigin(root, log);
174
+ const checkpoint = await verifyCheckpoint(proof.checkpoint, log, origin);
175
+ if (checkpoint.size !== proof.treeSize || !bytesEqual(checkpoint.rootHash, proof.rootHash)) {
176
+ throw new Error("inclusion proof does not state the checkpoint's tree size and root hash");
177
+ }
178
+ const leafHash = await sha256(concat(new Uint8Array([0x00]), entry.canonicalizedBody));
179
+ await verifyMerkleInclusion(leafHash, proof.logIndex, checkpoint.size, proof.hashes, checkpoint.rootHash);
180
+ }
181
+ /**
182
+ * The body must be the canonical hashedrekord 0.0.2 record for this
183
+ * envelope and signer: SHA2_256 of the signed message, the DSSE signature,
184
+ * and the DER public key or signing certificate with its key details.
185
+ */
186
+ function checkBody(body, expected) {
187
+ let value;
188
+ try {
189
+ value = strictParse(body);
190
+ }
191
+ catch (err) {
192
+ throw new Error(`parsing body: ${message(err)}`);
193
+ }
194
+ if (value === null)
195
+ throw new Error("body is null");
196
+ const record = object(value, "body", BODY_MEMBERS);
197
+ const kind = str(record, "kind");
198
+ const version = str(record, "apiVersion");
199
+ if (kind !== HASHEDREKORD_KIND || version !== HASHEDREKORD_VERSION) {
200
+ throw new Error(`body is ${kind} ${version}, not ${HASHEDREKORD_KIND} ${HASHEDREKORD_VERSION}`);
201
+ }
202
+ const spec = struct(struct(record, "spec", SPEC_MEMBERS), "hashedRekordV002", RECORD_MEMBERS);
203
+ const data = struct(spec, "data", DATA_MEMBERS);
204
+ if (str(data, "algorithm") !== HASH_ALGORITHM)
205
+ throw new Error("body digest algorithm is not SHA2_256");
206
+ if (str(data, "digest") !== expected.digest)
207
+ throw new Error("body digest is not the digest of the signed message");
208
+ const signature = struct(spec, "signature", SIGNATURE_MEMBERS);
209
+ if (str(signature, "content") !== expected.signature)
210
+ throw new Error("body signature is not the DSSE signature");
211
+ const verifier = struct(signature, "verifier", VERIFIER_MEMBERS);
212
+ if (str(verifier, "keyDetails") !== KEY_DETAILS)
213
+ throw new Error("body key details are not ECDSA P-256 with SHA-256");
214
+ if ("publicKey" in expected.verifier) {
215
+ if (verifier.has("x509Certificate"))
216
+ throw new Error("body names a certificate, not the pinned key");
217
+ if (str(struct(verifier, "publicKey", RAW_BYTES_MEMBERS), "rawBytes") !== expected.verifier.publicKey) {
218
+ throw new Error("body public key is not the pinned key");
219
+ }
220
+ }
221
+ else {
222
+ if (verifier.has("publicKey"))
223
+ throw new Error("body names a public key, not the signing certificate");
224
+ if (str(struct(verifier, "x509Certificate", RAW_BYTES_MEMBERS), "rawBytes") !== expected.verifier.x509Certificate) {
225
+ throw new Error("body certificate is not the signing certificate");
226
+ }
227
+ }
228
+ if (!bytesEqual(canonicalize(value), body))
229
+ throw new Error("body is not in canonical form");
230
+ }
231
+ /** The sentinel that opens a signature line of a signed note. */
232
+ const SIGNATURE_PREFIX = "— ";
233
+ const MAX_NOTE_SIGNATURES = 100;
234
+ const MAX_UINT64 = (1n << 64n) - 1n;
235
+ /**
236
+ * Verifies a checkpoint envelope (a signed note) under `log`, whose
237
+ * signature line is named `origin` and keyed by the log key's note hint, and
238
+ * returns the tree state it states; the checkpoint's origin must be `origin`.
239
+ * Signature lines of other signers are ignored.
240
+ */
241
+ export async function verifyCheckpoint(envelope, log, origin) {
242
+ for (const ch of envelope) {
243
+ const c = ch.codePointAt(0);
244
+ if (c < 0x20 && c !== 0x0a)
245
+ throw new Error("checkpoint contains a control character");
246
+ }
247
+ const split = envelope.lastIndexOf("\n\n");
248
+ if (split < 0)
249
+ throw new Error("checkpoint has no signature section");
250
+ const text = envelope.slice(0, split + 1);
251
+ const section = envelope.slice(split + 2);
252
+ if (section.length === 0 || !section.endsWith("\n"))
253
+ throw new Error("checkpoint signature section is malformed");
254
+ const lines = section.slice(0, -1).split("\n");
255
+ if (lines.length > MAX_NOTE_SIGNATURES)
256
+ throw new Error("checkpoint has too many signatures");
257
+ const hint = await noteKeyHint(log, origin);
258
+ let verified = false;
259
+ for (const line of lines) {
260
+ if (!line.startsWith(SIGNATURE_PREFIX))
261
+ throw new Error("checkpoint signature line is malformed");
262
+ const rest = line.slice(SIGNATURE_PREFIX.length);
263
+ const space = rest.indexOf(" ");
264
+ const name = space < 0 ? rest : rest.slice(0, space);
265
+ const encoded = space < 0 ? "" : rest.slice(space + 1);
266
+ if (!validNoteName(name) || encoded === "")
267
+ throw new Error("checkpoint signature line is malformed");
268
+ let signature;
269
+ try {
270
+ signature = decodeBase64("checkpoint signature", encoded);
271
+ }
272
+ catch {
273
+ throw new Error("checkpoint signature line is malformed");
274
+ }
275
+ if (signature.length < 5)
276
+ throw new Error("checkpoint signature line is malformed");
277
+ if (name !== origin || !bytesEqual(signature.subarray(0, 4), hint) || verified)
278
+ continue;
279
+ if (!(await verifyLogSignature(log.publicKey, utf8(text), signature.subarray(4)))) {
280
+ throw new Error("checkpoint signature does not verify under the log key");
281
+ }
282
+ verified = true;
283
+ }
284
+ if (!verified)
285
+ throw new Error("checkpoint is not signed by the log");
286
+ const parts = text.split("\n");
287
+ if (parts.length < 4)
288
+ throw new Error("checkpoint has too few lines");
289
+ const [stated, sizeText, hashText] = parts;
290
+ if (stated === "")
291
+ throw new Error("checkpoint has an empty origin");
292
+ if (stated !== origin)
293
+ throw new Error(`checkpoint origin ${JSON.stringify(stated)} is not the log's ${JSON.stringify(origin)}`);
294
+ if (!/^[0-9]+$/.test(sizeText) || BigInt(sizeText) > MAX_UINT64)
295
+ throw new Error("checkpoint tree size is not a 64-bit integer");
296
+ let rootHash;
297
+ try {
298
+ rootHash = decodeBase64("checkpoint root hash", hashText);
299
+ }
300
+ catch (err) {
301
+ throw new Error(`checkpoint root hash: ${message(err)}`);
302
+ }
303
+ if (rootHash.length !== 32)
304
+ throw new Error("checkpoint root hash is not 32 bytes");
305
+ return { origin: stated, size: BigInt(sizeText), rootHash };
306
+ }
307
+ /** A note signer name: non-empty, no whitespace, no '+'. */
308
+ function validNoteName(name) {
309
+ return name !== "" && !/[\s+]/.test(name);
310
+ }
311
+ /**
312
+ * The 4-byte key hint a log's signature line carries: for an ECDSA key the
313
+ * leading bytes of SHA-256 over its DER form; for an Ed25519 key the leading
314
+ * bytes of SHA-256 over the origin, a newline, the byte 0x01 and the raw key.
315
+ */
316
+ async function noteKeyHint(log, origin) {
317
+ const spki = new Uint8Array(await crypto.subtle.exportKey("spki", log.publicKey));
318
+ switch (log.publicKey.algorithm.name) {
319
+ case "ECDSA":
320
+ return (await sha256(spki)).subarray(0, 4);
321
+ case "Ed25519":
322
+ return (await sha256(concat(utf8(origin), new Uint8Array([0x0a, 0x01]), rawKey(spki)))).subarray(0, 4);
323
+ default:
324
+ throw new Error(`unsupported transparency log key type ${log.publicKey.algorithm.name}`);
325
+ }
326
+ }
327
+ /** The subjectPublicKey bits of a SubjectPublicKeyInfo. */
328
+ function rawKey(spki) {
329
+ const parts = expectSequence(decode(spki), "SubjectPublicKeyInfo");
330
+ if (parts.length !== 2)
331
+ throw new Error("SubjectPublicKeyInfo must hold an algorithm and a key");
332
+ return bitString(parts[1]);
333
+ }
334
+ /** Verifies a signature under a transparency log's key: DER ECDSA over the curve's hash, or a raw Ed25519 signature. */
335
+ export async function verifyLogSignature(key, data, signature) {
336
+ try {
337
+ if (key.algorithm.name === "Ed25519") {
338
+ return await crypto.subtle.verify({ name: "Ed25519" }, key, asBuffer(signature), asBuffer(data));
339
+ }
340
+ const curve = key.algorithm.namedCurve;
341
+ const size = curve === "P-256" ? 32 : curve === "P-384" ? 48 : curve === "P-521" ? 66 : undefined;
342
+ if (size === undefined)
343
+ return false;
344
+ const hash = curve === "P-256" ? "SHA-256" : curve === "P-384" ? "SHA-384" : "SHA-512";
345
+ const raw = ecdsaSignatureToRaw(signature, size);
346
+ return await crypto.subtle.verify({ name: "ECDSA", hash }, key, asBuffer(raw), asBuffer(data));
347
+ }
348
+ catch {
349
+ return false;
350
+ }
351
+ }
352
+ /**
353
+ * The first log entry's integration time, proven by the log's inclusion
354
+ * promise: a signature under the key of the log the entry names, listed in
355
+ * `root` and valid at that time, over the canonical record of the entry's
356
+ * body, integration time, index and log id. Undefined when the first entry
357
+ * states no time or carries no promise; a log the root does not list, a time
358
+ * outside the key's validity, or a promise that does not verify rejects.
359
+ */
360
+ export async function promisedLogTime(root, entries) {
361
+ const first = entries[0];
362
+ if (first === undefined || first.integratedTime === undefined || first.inclusionPromise === undefined)
363
+ return undefined;
364
+ const log = root.transparencyLogs.find((l) => l.logId === first.logId);
365
+ if (log === undefined)
366
+ throw new Error("first log entry names a transparency log the trusted root does not list");
367
+ const at = new Date(Number(first.integratedTime) * 1000);
368
+ // A time outside the representable range reads as an invalid date, which no window comparison rejects.
369
+ if (!Number.isFinite(at.getTime()))
370
+ throw new Error("first log entry's integration time is not a representable time");
371
+ if (at.getTime() < log.validFrom.getTime() || (log.validTo !== undefined && at.getTime() > log.validTo.getTime())) {
372
+ throw new Error("first log entry's integration time is outside the log key's validity");
373
+ }
374
+ const record = new Map([
375
+ ["body", toBase64(first.canonicalizedBody)],
376
+ ["integratedTime", new JsonNumber(first.integratedTime.toString())],
377
+ ["logID", first.logId],
378
+ ["logIndex", new JsonNumber(first.logIndex.toString())],
379
+ ]);
380
+ if (!(await verifyLogSignature(log.publicKey, canonicalize(record), first.inclusionPromise))) {
381
+ throw new Error("first log entry's inclusion promise does not verify under the log key");
382
+ }
383
+ return at;
384
+ }
385
+ /** The host name of the log's base URL in the trusted root: the origin its checkpoints must state. */
386
+ async function logOrigin(root, log) {
387
+ const spki = new Uint8Array(await crypto.subtle.exportKey("spki", log.publicKey));
388
+ const tlogs = arr(object(root.json, "trusted root"), "tlogs") ?? [];
389
+ for (const entry of tlogs) {
390
+ if (entry === null)
391
+ continue;
392
+ const record = object(entry, "tlog");
393
+ const rawBytes = str(struct(record, "publicKey", ["rawBytes", "keyDetails", "validFor"]), "rawBytes");
394
+ if (rawBytes === "" || !bytesEqual(decodeBase64("publicKey rawBytes", rawBytes), spki))
395
+ continue;
396
+ const baseUrl = str(record, "baseUrl");
397
+ let hostname;
398
+ try {
399
+ hostname = new URL(baseUrl).hostname;
400
+ }
401
+ catch {
402
+ throw new Error(`transparency log base URL ${JSON.stringify(baseUrl)} is not a URL`);
403
+ }
404
+ if (hostname === "")
405
+ throw new Error(`transparency log base URL ${JSON.stringify(baseUrl)} has no host`);
406
+ return hostname;
407
+ }
408
+ throw new Error("transparency log has no base URL in the trusted root");
409
+ }
410
+ // ---------------------------------------------------------------- Merkle inclusion
411
+ /**
412
+ * Verifies an RFC 6962 inclusion proof: `hashes` carries the sibling hashes
413
+ * from the leaf at `index` up to the root of a tree of `size` leaves, inner
414
+ * nodes first and then the nodes along the tree's right border.
415
+ */
416
+ export async function verifyMerkleInclusion(leafHash, index, size, hashes, rootHash) {
417
+ if (index < 0n || index >= size)
418
+ throw new Error(`inclusion proof index ${index} is outside a tree of ${size} leaves`);
419
+ if (leafHash.length !== 32)
420
+ throw new Error("inclusion proof leaf hash is not 32 bytes");
421
+ const inner = bitLength(index ^ (size - 1n));
422
+ const border = onesCount(index >> BigInt(inner));
423
+ if (hashes.length !== inner + border) {
424
+ throw new Error(`inclusion proof has ${hashes.length} hashes, expected ${inner + border}`);
425
+ }
426
+ for (const h of hashes)
427
+ if (h.length !== 32)
428
+ throw new Error("inclusion proof hash is not 32 bytes");
429
+ let node = leafHash;
430
+ for (let i = 0; i < inner; i++) {
431
+ const sibling = hashes[i];
432
+ node = (index >> BigInt(i)) & 1n ? await hashChildren(sibling, node) : await hashChildren(node, sibling);
433
+ }
434
+ for (let i = inner; i < hashes.length; i++)
435
+ node = await hashChildren(hashes[i], node);
436
+ if (!bytesEqual(node, rootHash))
437
+ throw new Error("inclusion proof does not reach the root hash");
438
+ }
439
+ function hashChildren(left, right) {
440
+ return sha256(concat(new Uint8Array([0x01]), left, right));
441
+ }
442
+ function bitLength(n) {
443
+ return n === 0n ? 0 : n.toString(2).length;
444
+ }
445
+ function onesCount(n) {
446
+ return n.toString(2).split("1").length - 1;
447
+ }
448
+ // ---------------------------------------------------------------- statements
449
+ /**
450
+ * Whether a subject of the in-toto statement carries `digestHex` as its
451
+ * sha256 digest. Every digest value must be hex.
452
+ */
453
+ export function statementNamesDigest(payload, digestHex) {
454
+ let value;
455
+ try {
456
+ value = strictParse(payload);
457
+ }
458
+ catch (err) {
459
+ throw new Error(`parsing in-toto statement: ${message(err)}`);
460
+ }
461
+ if (!(value instanceof Map))
462
+ throw new Error("in-toto statement is not an object");
463
+ const subjects = arr(value, "subject") ?? [];
464
+ let found = false;
465
+ subjects.forEach((s, i) => {
466
+ if (s === null)
467
+ throw new Error(`in-toto statement subject ${i} is null`);
468
+ const subject = object(s, `subject[${i}]`);
469
+ const digests = subject.get("digest");
470
+ if (digests === undefined || digests === null)
471
+ return;
472
+ for (const [algorithm, v] of object(digests, `subject[${i}] digest`)) {
473
+ if (typeof v !== "string" || !/^[0-9a-fA-F]*$/.test(v) || v.length % 2 !== 0) {
474
+ throw new Error(`in-toto statement subject ${i} digest ${JSON.stringify(algorithm)} is not hex`);
475
+ }
476
+ if (algorithm === "sha256" && v.toLowerCase() === digestHex)
477
+ found = true;
478
+ }
479
+ });
480
+ return found;
481
+ }
482
+ // ---------------------------------------------------------------- keys
483
+ /** Imports a DER SubjectPublicKeyInfo as an extractable ECDSA P-256 verification key. */
484
+ export async function importP256(spki) {
485
+ if (!isP256(spki))
486
+ throw new Error("approval requires an ECDSA P-256 key");
487
+ try {
488
+ return await crypto.subtle.importKey("spki", asBuffer(spki), P256, true, ["verify"]);
489
+ }
490
+ catch (err) {
491
+ throw new Error(`importing signing key: ${message(err)}`);
492
+ }
493
+ }
494
+ /** Whether the SubjectPublicKeyInfo names the ecPublicKey algorithm on the P-256 curve. */
495
+ function isP256(spki) {
496
+ try {
497
+ const parts = expectSequence(decode(spki), "SubjectPublicKeyInfo");
498
+ if (parts.length !== 2 || !isUniversal(parts[1], TAG.BIT_STRING))
499
+ return false;
500
+ const alg = expectSequence(parts[0], "key AlgorithmIdentifier");
501
+ return alg.length === 2 && oid(alg[0]) === OID_EC_PUBLIC_KEY && oid(alg[1]) === OID_P256;
502
+ }
503
+ catch {
504
+ return false;
505
+ }
506
+ }
507
+ /** The DER form of a P-256 verification key; any other key rejects. */
508
+ async function exportP256(key) {
509
+ const algorithm = key.algorithm;
510
+ if (key.type !== "public" || algorithm.name !== "ECDSA" || algorithm.namedCurve !== "P-256") {
511
+ throw new Error("approval requires an ECDSA P-256 key");
512
+ }
513
+ try {
514
+ return new Uint8Array(await crypto.subtle.exportKey("spki", key));
515
+ }
516
+ catch (err) {
517
+ throw new Error(`exporting signing key: ${message(err)}`);
518
+ }
519
+ }
520
+ /** Verifies a DER ECDSA signature over SHA-256 of `data`; false for a malformed or bad signature. */
521
+ export async function verifyP256(key, signature, data) {
522
+ let raw;
523
+ try {
524
+ raw = ecdsaSignatureToRaw(signature, 32);
525
+ }
526
+ catch (err) {
527
+ if (err instanceof DerError)
528
+ return false;
529
+ throw err;
530
+ }
531
+ return crypto.subtle.verify({ name: "ECDSA", hash: "SHA-256" }, key, asBuffer(raw), asBuffer(data));
532
+ }
533
+ // ---------------------------------------------------------------- helpers
534
+ const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
535
+ /** Standard base64 with padding. */
536
+ export function toBase64(b) {
537
+ let s = "";
538
+ let i = 0;
539
+ for (; i + 2 < b.length; i += 3) {
540
+ const n = (b[i] << 16) | (b[i + 1] << 8) | b[i + 2];
541
+ s += BASE64[n >> 18] + BASE64[(n >> 12) & 63] + BASE64[(n >> 6) & 63] + BASE64[n & 63];
542
+ }
543
+ if (i < b.length) {
544
+ const second = i + 1 < b.length;
545
+ const n = (b[i] << 16) | ((second ? b[i + 1] : 0) << 8);
546
+ s += BASE64[n >> 18] + BASE64[(n >> 12) & 63] + (second ? BASE64[(n >> 6) & 63] : "=") + "=";
547
+ }
548
+ return s;
549
+ }
550
+ function asBuffer(b) {
551
+ return b;
552
+ }
553
+ function message(err) {
554
+ return err instanceof Error ? err.message : String(err);
555
+ }
556
+ //# sourceMappingURL=keyed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyed.js","sourceRoot":"","sources":["../../../src/internal/sigstore/keyed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAkB,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAA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