@hardkeel/benthic 0.0.0-stage → 1.0.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/LICENSE +92 -0
  3. package/NOTICE +16 -0
  4. package/README.md +424 -2
  5. package/action.yml +54 -0
  6. package/dist/agility.js +80 -0
  7. package/dist/badge.js +62 -0
  8. package/dist/baseline.js +81 -0
  9. package/dist/cbom-diff.js +273 -0
  10. package/dist/cbom.js +418 -0
  11. package/dist/cli.js +834 -0
  12. package/dist/cloud-aws-services.js +375 -0
  13. package/dist/cloud-aws.js +354 -0
  14. package/dist/cloud-azure-services.js +73 -0
  15. package/dist/cloud-azure.js +144 -0
  16. package/dist/cloud-common.js +242 -0
  17. package/dist/cloud-gcp-services.js +90 -0
  18. package/dist/cloud-gcp.js +150 -0
  19. package/dist/comments.js +138 -0
  20. package/dist/community-rules.js +37 -0
  21. package/dist/community.js +30 -0
  22. package/dist/deps.js +406 -0
  23. package/dist/der.js +571 -0
  24. package/dist/evidence-cli.js +235 -0
  25. package/dist/evidence-live.js +109 -0
  26. package/dist/evidence.js +512 -0
  27. package/dist/ignore.js +90 -0
  28. package/dist/image.js +1224 -0
  29. package/dist/infra.js +635 -0
  30. package/dist/inventory.js +277 -0
  31. package/dist/map-activity.js +24 -0
  32. package/dist/map-areas.js +60 -0
  33. package/dist/map-cloud-keys.js +110 -0
  34. package/dist/map-cloud.js +34 -0
  35. package/dist/map-ct.js +107 -0
  36. package/dist/map-host.js +335 -0
  37. package/dist/map-network.js +520 -0
  38. package/dist/map-people.js +79 -0
  39. package/dist/map-rank.js +70 -0
  40. package/dist/map-report.js +304 -0
  41. package/dist/map-run.js +327 -0
  42. package/dist/map-sarif.js +61 -0
  43. package/dist/map-signin.js +247 -0
  44. package/dist/map-types.js +19 -0
  45. package/dist/map-web.js +666 -0
  46. package/dist/native.js +168 -0
  47. package/dist/policy.js +221 -0
  48. package/dist/pqc.js +46 -0
  49. package/dist/profile.js +65 -0
  50. package/dist/project.js +928 -0
  51. package/dist/prose.js +159 -0
  52. package/dist/protocols.js +207 -0
  53. package/dist/registry.js +326 -0
  54. package/dist/report.js +190 -0
  55. package/dist/rules.js +230 -0
  56. package/dist/sarif-common.js +30 -0
  57. package/dist/sarif.js +114 -0
  58. package/dist/scan.js +601 -0
  59. package/dist/score.js +124 -0
  60. package/dist/secrets.js +192 -0
  61. package/dist/share-config.js +129 -0
  62. package/dist/share-lists.js +19 -0
  63. package/dist/share.js +125 -0
  64. package/dist/sonar.js +83 -0
  65. package/dist/structure.js +218 -0
  66. package/dist/suites.js +402 -0
  67. package/dist/tls-check.js +122 -0
  68. package/dist/types.js +4 -0
  69. package/dist/walk.js +78 -0
  70. package/dist/yaml.js +173 -0
  71. package/package.json +73 -4
package/dist/cbom.js ADDED
@@ -0,0 +1,418 @@
1
+ // SPDX-License-Identifier: PolyForm-Shield-1.0.0
2
+ // Copyright 2026 Hard Keel (https://hardkeel.com)
3
+ // CycloneDX 1.6 Cryptographic Bill of Materials (CBOM) from crypto findings.
4
+ import { randomUUID } from "node:crypto";
5
+ import { pqcReliance } from "./agility.js";
6
+ import { classicalBits, SIGNATURE_OIDS } from "./der.js";
7
+ import { purlOf } from "./deps.js";
8
+ import { suiteByName } from "./suites.js";
9
+ /** What each kind of finding is used for, as CycloneDX names it. */
10
+ const FUNCTIONS = {
11
+ "key-agreement": ["keygen", "keyderive"],
12
+ "public-key-encryption": ["encrypt", "decrypt"],
13
+ signature: ["sign", "verify"],
14
+ hash: ["digest"],
15
+ "block-cipher": ["encrypt", "decrypt"],
16
+ "stream-cipher": ["encrypt", "decrypt"],
17
+ };
18
+ /** Object identifiers for the algorithms named here, where one OID covers the family. */
19
+ const OID = {
20
+ RSA: "1.2.840.113549.1.1.1",
21
+ "RSA signature": "1.2.840.113549.1.1.1",
22
+ "RSA encryption": "1.2.840.113549.1.1.1",
23
+ EC: "1.2.840.10045.2.1",
24
+ DH: "1.2.840.10046.2.1",
25
+ X25519: "1.3.101.110",
26
+ X448: "1.3.101.111",
27
+ Ed25519: "1.3.101.112",
28
+ Ed448: "1.3.101.113",
29
+ DSA: "1.2.840.10040.4.1",
30
+ MD5: "1.2.840.113549.2.5",
31
+ "SHA-1": "1.3.14.3.2.26",
32
+ DES: "1.3.14.3.2.7",
33
+ "3DES": "1.2.840.113549.3.7",
34
+ RC4: "1.2.840.113549.3.4",
35
+ "SHA-256": "2.16.840.1.101.3.4.2.1",
36
+ "SHA-384": "2.16.840.1.101.3.4.2.2",
37
+ "SHA-512": "2.16.840.1.101.3.4.2.3",
38
+ "SHA3-256": "2.16.840.1.101.3.4.2.8",
39
+ "SHA3-384": "2.16.840.1.101.3.4.2.9",
40
+ "SHA3-512": "2.16.840.1.101.3.4.2.10",
41
+ "ML-KEM-512": "2.16.840.1.101.3.4.4.1",
42
+ "ML-KEM-768": "2.16.840.1.101.3.4.4.2",
43
+ "ML-KEM-1024": "2.16.840.1.101.3.4.4.3",
44
+ "ML-DSA-44": "2.16.840.1.101.3.4.3.17",
45
+ "ML-DSA-65": "2.16.840.1.101.3.4.3.18",
46
+ "ML-DSA-87": "2.16.840.1.101.3.4.3.19",
47
+ ECDSA: "1.2.840.10045.2.1",
48
+ ECDH: "1.3.132.1.12",
49
+ ...Object.fromEntries(Object.entries(SIGNATURE_OIDS).map(([o, n]) => [n, o])),
50
+ };
51
+ const oid = (name) => (OID[name] ? { oid: OID[name] } : {});
52
+ /** ECDSA signature OIDs by hash (ANSI X9.62, RFC 5758). */
53
+ const ECDSA_SIG_OID = {
54
+ "SHA-1": "1.2.840.10045.4.1",
55
+ "SHA-224": "1.2.840.10045.4.3.1",
56
+ "SHA-256": "1.2.840.10045.4.3.2",
57
+ "SHA-384": "1.2.840.10045.4.3.3",
58
+ "SHA-512": "1.2.840.10045.4.3.4",
59
+ };
60
+ /**
61
+ * The OID for a group of findings. An ECDSA signature gets its signature OID (ecdsa-with-SHA256)
62
+ * when every place fixes the same hash. Otherwise it keeps the key type (id-ecPublicKey): the hash
63
+ * isn't known, and guessing SHA-256 would be wrong for P-384 and P-521.
64
+ */
65
+ function oidFor(fs) {
66
+ const first = fs[0];
67
+ if (first.algorithm === "ECDSA" && first.hash && ECDSA_SIG_OID[first.hash] && fs.every((f) => f.hash === first.hash))
68
+ return { oid: ECDSA_SIG_OID[first.hash] };
69
+ return oid(first.algorithm);
70
+ }
71
+ /**
72
+ * Which protocol a protocol finding is about. A problem with a certificate or a setting (an expired
73
+ * certificate, an open port) isn't an encryption method, so it returns null and stays out of the inventory.
74
+ */
75
+ function protocolOf(algorithm) {
76
+ if (algorithm === "TLS 1.0/1.1")
77
+ return { type: "tls", version: "1.0/1.1" };
78
+ if (/^(Weak TLS ciphers|Static RSA key exchange|TLS key exchange)$/.test(algorithm))
79
+ return { type: "tls" };
80
+ if (/^SSH\b|SSH key exchange$/.test(algorithm))
81
+ return { type: "ssh" };
82
+ return null;
83
+ }
84
+ const CDX_MODES = new Set(["cbc", "ecb", "ccm", "gcm", "cfb", "ofb", "ctr"]);
85
+ const CDX_PRIMITIVE = {
86
+ "key-agreement": "key-agree",
87
+ "public-key-encryption": "pke",
88
+ signature: "signature",
89
+ hash: "hash",
90
+ "block-cipher": "block-cipher",
91
+ "stream-cipher": "stream-cipher",
92
+ protocol: "other",
93
+ credential: "other",
94
+ setting: "other",
95
+ };
96
+ const slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
97
+ function classical(f) {
98
+ return classicalBits(f.algorithm, f.keySize, f.curve);
99
+ }
100
+ /**
101
+ * Certificates and public keys read from PEM: one certificate asset per certificate, and one
102
+ * related-crypto-material asset per public key, each pointing at its algorithm.
103
+ */
104
+ function materialComponents(findings, algRef, existing) {
105
+ const out = [];
106
+ const taken = new Set(existing.map((c) => c["bom-ref"]));
107
+ const ref = (base) => {
108
+ let r = base;
109
+ for (let n = 2; taken.has(r); n++)
110
+ r = `${base}-${n}`;
111
+ taken.add(r);
112
+ return r;
113
+ };
114
+ const sigAlgRefs = new Map();
115
+ const sigAlgRef = (m) => {
116
+ if (!m.signatureAlgorithm)
117
+ return undefined;
118
+ const name = m.signatureAlgorithm;
119
+ const existingRef = existing.find((c) => c.name === name)?.["bom-ref"];
120
+ if (existingRef)
121
+ return existingRef;
122
+ if (sigAlgRefs.has(name))
123
+ return sigAlgRefs.get(name);
124
+ const r = ref(`crypto:${slug(name)}`);
125
+ sigAlgRefs.set(name, r);
126
+ const pq = /^(ML-DSA|SLH-DSA|HSS|XMSS)/.test(name);
127
+ out.push({
128
+ type: "cryptographic-asset",
129
+ "bom-ref": r,
130
+ name,
131
+ cryptoProperties: {
132
+ assetType: "algorithm",
133
+ algorithmProperties: { primitive: "signature", cryptoFunctions: ["sign", "verify"], ...(pq ? {} : { nistQuantumSecurityLevel: 0 }) },
134
+ ...(m.signatureOid ? { oid: m.signatureOid } : {}),
135
+ },
136
+ properties: [{ name: "hardkeel:risk", value: pq ? "quantum-safe" : /md[25]|sha1/i.test(name) ? "weak-now" : "quantum-vulnerable" }],
137
+ });
138
+ return r;
139
+ };
140
+ const seen = new Set();
141
+ for (const f of findings) {
142
+ const m = f.material;
143
+ if (!m || f.ruleId.endsWith("-weak-signature"))
144
+ continue;
145
+ const key = `${f.file}:${f.line}:${m.subject ?? ""}`;
146
+ if (seen.has(key))
147
+ continue;
148
+ seen.add(key);
149
+ const where = { occurrences: [{ location: f.file, ...(f.line > 0 ? { line: f.line } : {}) }] };
150
+ const keyRef = ref(`key:${slug(`${f.file}-${f.line}`)}`);
151
+ out.push({
152
+ type: "cryptographic-asset",
153
+ "bom-ref": keyRef,
154
+ name: `${m.type === "parameters" ? "Parameters" : "Public key"} ${f.keySize ? `${f.algorithm.split(" ")[0]}-${f.keySize}` : f.curve ? `${f.algorithm} ${f.curve}` : f.algorithm}`,
155
+ cryptoProperties: {
156
+ assetType: "related-crypto-material",
157
+ relatedCryptoMaterialProperties: {
158
+ type: m.type === "parameters" ? "other" : "public-key",
159
+ algorithmRef: algRef(f),
160
+ ...(f.keySize ? { size: f.keySize } : {}),
161
+ format: "PEM",
162
+ },
163
+ ...(m.keyOid ? { oid: m.keyOid } : {}),
164
+ },
165
+ evidence: where,
166
+ });
167
+ if (m.type !== "certificate")
168
+ continue;
169
+ const sig = sigAlgRef(m);
170
+ out.push({
171
+ type: "cryptographic-asset",
172
+ "bom-ref": ref(`cert:${slug(m.subject ?? f.file)}`),
173
+ name: m.subject ?? "Certificate",
174
+ cryptoProperties: {
175
+ assetType: "certificate",
176
+ certificateProperties: {
177
+ ...(m.subject ? { subjectName: m.subject } : {}),
178
+ ...(m.issuer ? { issuerName: m.issuer } : {}),
179
+ ...(m.notBefore ? { notValidBefore: m.notBefore } : {}),
180
+ ...(m.notAfter ? { notValidAfter: m.notAfter } : {}),
181
+ ...(sig ? { signatureAlgorithmRef: sig } : {}),
182
+ subjectPublicKeyRef: keyRef,
183
+ certificateFormat: "X.509",
184
+ certificateExtension: f.file.match(/\.(pem|crt|cer|der)$/i)?.[1].toLowerCase() ?? "pem",
185
+ },
186
+ },
187
+ evidence: where,
188
+ });
189
+ }
190
+ return out;
191
+ }
192
+ /**
193
+ * One protocol component per TLS version in use, with the suites that version can negotiate, and one for
194
+ * SSH. Skipped when a finding already made a component of the same name.
195
+ */
196
+ function protocolComponents(protocols, taken) {
197
+ const out = [];
198
+ const tls = protocols.filter((p) => p.protocol === "tls");
199
+ const versions = [...new Set(tls.filter((p) => p.kind === "tls-version").map((p) => p.name))].sort();
200
+ const suites = new Map();
201
+ for (const p of tls)
202
+ if (p.kind === "tls-suite" && !suites.has(p.name))
203
+ suites.set(p.name, p);
204
+ const occurrences = (ps) => {
205
+ const seen = new Set();
206
+ return ps.flatMap((p) => {
207
+ const k = `${p.file}:${p.line}`;
208
+ if (seen.has(k))
209
+ return [];
210
+ seen.add(k);
211
+ return [{ location: p.file, ...(p.line > 0 ? { line: p.line } : {}) }];
212
+ });
213
+ };
214
+ for (const name of versions) {
215
+ const ref = `protocol:${slug(name)}`;
216
+ if (taken.has(ref))
217
+ continue;
218
+ taken.add(ref);
219
+ const version = name.replace(/^TLS /, "");
220
+ // A suite can be negotiated at the versions that know it: TLS 1.3 has its own five, TLS 1.0 and 1.1 lack the SHA-2 and AEAD ones.
221
+ const fits = [...suites.values()].filter((s) => {
222
+ const min = suiteByName(s.name)?.min;
223
+ return version === "1.3" ? min === "1.3" : version === "1.2" ? min !== "1.3" : min === "1.0";
224
+ });
225
+ const v = tls.find((p) => p.name === name);
226
+ out.push({
227
+ type: "cryptographic-asset",
228
+ "bom-ref": ref,
229
+ name,
230
+ cryptoProperties: {
231
+ assetType: "protocol",
232
+ protocolProperties: {
233
+ type: "tls",
234
+ version,
235
+ ...(fits.length ? { cipherSuites: fits.map((s) => ({ name: s.name, ...(s.code ? { identifiers: [`0x${s.code.slice(2, 4)}`, `0x${s.code.slice(4, 6)}`] } : {}) })) } : {}),
236
+ },
237
+ },
238
+ properties: [
239
+ { name: "hardkeel:strength", value: v.strength },
240
+ { name: "hardkeel:seen", value: [...new Set(tls.filter((p) => p.name === name).map((p) => p.seen))].join(", ") },
241
+ ],
242
+ evidence: { occurrences: occurrences(tls.filter((p) => p.name === name)) },
243
+ });
244
+ }
245
+ const ssh = protocols.filter((p) => p.protocol === "ssh");
246
+ if (ssh.length && !taken.has("protocol:ssh")) {
247
+ taken.add("protocol:ssh");
248
+ const list = (k) => [...new Set(ssh.filter((p) => p.kind === k).map((p) => p.name))].join(", ");
249
+ out.push({
250
+ type: "cryptographic-asset",
251
+ "bom-ref": "protocol:ssh",
252
+ name: "SSH",
253
+ cryptoProperties: { assetType: "protocol", protocolProperties: { type: "ssh" } },
254
+ properties: [
255
+ ...["ssh-kex", "ssh-cipher", "ssh-mac", "ssh-hostkey"].filter((k) => list(k)).map((k) => ({ name: `hardkeel:${k}`, value: list(k) })),
256
+ { name: "hardkeel:weak", value: [...new Set(ssh.filter((p) => p.strength === "weak").map((p) => p.name))].join(", ") || "none" },
257
+ ],
258
+ evidence: { occurrences: occurrences(ssh) },
259
+ });
260
+ }
261
+ return out;
262
+ }
263
+ /**
264
+ * Parameters an algorithm's name already fixes, for entries where the code didn't spell out a key size
265
+ * or curve: Ed25519 is always on edwards25519, SHA-1 always has a 160-bit digest, ML-KEM-768 is its own
266
+ * parameter set. Nothing is guessed: RSA, ECDSA and AES without a size stay without one.
267
+ */
268
+ export function impliedParameters(name) {
269
+ const fixedCurve = { Ed25519: "Ed25519", Ed448: "Ed448", X25519: "X25519", X448: "X448" };
270
+ if (fixedCurve[name])
271
+ return { curve: fixedCurve[name] };
272
+ if (/\bsecp256k1\b/i.test(name))
273
+ return { curve: "secp256k1" };
274
+ const digest = { MD5: "128", "SHA-1": "160", DES: "56", "3DES": "168" };
275
+ if (digest[name])
276
+ return { parameterSetIdentifier: digest[name] };
277
+ const pq = name.match(/^(?:ML-KEM|ML-DSA)-(\d+)$/) ?? name.match(/^SLH-DSA-(.+)$/);
278
+ if (pq)
279
+ return { parameterSetIdentifier: pq[1] };
280
+ const sha = name.match(/^(?:HMAC|HKDF|PBKDF2)-SHA-?(?:2-)?(224|256|384|512)$|^SHA-?(?:2-|3-)?(224|256|384|512)$/i);
281
+ if (sha)
282
+ return { parameterSetIdentifier: sha[1] ?? sha[2] };
283
+ return {};
284
+ }
285
+ /**
286
+ * The CBOM: one component per algorithm (and key size). Findings are the ones to fix; inventory is
287
+ * everything else the code uses (AES, SHA-2, HMAC, key derivation, post-quantum), so the list is complete.
288
+ */
289
+ export function buildCbom(findings, opts, inventory = [], libraries = []) {
290
+ const crypto = findings.filter((f) => f.kind === "crypto" && (f.primitive !== "protocol" || protocolOf(f.algorithm)));
291
+ const byAlg = new Map();
292
+ const nameOf = (f) => (f.keySize ? `${f.algorithm}-${f.keySize}` : f.curve ? `${f.algorithm} ${f.curve}` : f.algorithm);
293
+ for (const f of crypto) {
294
+ const key = nameOf(f);
295
+ byAlg.set(key, [...(byAlg.get(key) ?? []), f]);
296
+ }
297
+ const components = [...byAlg.entries()].map(([name, fs]) => {
298
+ const first = fs[0];
299
+ const isProtocol = first.primitive === "protocol";
300
+ const cryptoProperties = isProtocol
301
+ ? { assetType: "protocol", protocolProperties: protocolOf(first.algorithm) }
302
+ : {
303
+ assetType: "algorithm",
304
+ algorithmProperties: {
305
+ primitive: CDX_PRIMITIVE[first.primitive],
306
+ ...(first.keySize ? { parameterSetIdentifier: String(first.keySize) } : {}),
307
+ ...(first.curve ? { curve: first.curve } : {}),
308
+ ...(!first.keySize && !first.curve ? impliedParameters(first.algorithm) : {}),
309
+ ...(FUNCTIONS[first.primitive] ? { cryptoFunctions: FUNCTIONS[first.primitive] } : {}),
310
+ ...(classical(first) !== undefined ? { classicalSecurityLevel: classical(first) } : {}),
311
+ // 0 = no security against a quantum attacker (NIST category scale).
312
+ nistQuantumSecurityLevel: 0,
313
+ },
314
+ ...oidFor(fs),
315
+ };
316
+ return {
317
+ type: "cryptographic-asset",
318
+ "bom-ref": `crypto:${name.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`,
319
+ name,
320
+ cryptoProperties,
321
+ properties: [
322
+ { name: "hardkeel:risk", value: first.risk },
323
+ { name: "hardkeel:occurrences", value: String(fs.length) },
324
+ ],
325
+ evidence: {
326
+ // CycloneDX lines start at 1; a place with no line (a device, a website) gives its location alone.
327
+ occurrences: fs.map((f) => ({ location: f.file, ...(f.line > 0 ? { line: f.line } : {}) })),
328
+ },
329
+ };
330
+ });
331
+ const taken = new Set(components.map((c) => c["bom-ref"]));
332
+ const byInv = new Map();
333
+ for (const i of inventory)
334
+ byInv.set(i.algorithm, [...(byInv.get(i.algorithm) ?? []), i]);
335
+ for (const [name, items] of byInv) {
336
+ const first = items[0];
337
+ const ref = `crypto:${name.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`;
338
+ if (taken.has(ref))
339
+ continue;
340
+ components.push({
341
+ type: "cryptographic-asset",
342
+ "bom-ref": ref,
343
+ name,
344
+ cryptoProperties: {
345
+ assetType: "algorithm",
346
+ algorithmProperties: {
347
+ primitive: first.primitive,
348
+ ...(first.nistQuantumLevel !== undefined ? { nistQuantumSecurityLevel: first.nistQuantumLevel } : {}),
349
+ ...(first.keySize ? { parameterSetIdentifier: String(first.keySize) } : impliedParameters(name)),
350
+ ...(first.mode ? { mode: CDX_MODES.has(first.mode) ? first.mode : "other" } : {}),
351
+ cryptoFunctions: first.functions,
352
+ ...(first.family === "AES" && first.keySize ? { classicalSecurityLevel: first.keySize } : {}),
353
+ },
354
+ ...oid(name),
355
+ },
356
+ properties: [
357
+ { name: "hardkeel:risk", value: first.risk ?? (first.family.startsWith("ML-") || first.family === "SLH-DSA" ? "quantum-safe" : "ok") },
358
+ { name: "hardkeel:occurrences", value: String(items.length) },
359
+ ...(first.note ? [{ name: "hardkeel:note", value: first.note }] : []),
360
+ ...(first.caution ? [{ name: "hardkeel:caution", value: first.caution }] : []),
361
+ ],
362
+ evidence: { occurrences: items.map((i) => ({ location: i.file, ...(i.line > 0 ? { line: i.line } : {}) })) },
363
+ });
364
+ }
365
+ components.push(...materialComponents(crypto, (f) => `crypto:${slug(nameOf(f))}`, components));
366
+ // Encryption libraries from package manifests: what the code can reach, listed with what each offers.
367
+ const libs = new Map();
368
+ for (const l of libraries) {
369
+ const p = purlOf(l);
370
+ libs.set(p, [...(libs.get(p) ?? []), l]);
371
+ }
372
+ for (const [purl, ls] of libs) {
373
+ const first = ls[0];
374
+ const exact = /@[^/]+$/.test(purl.split("/").pop());
375
+ components.push({
376
+ type: "library",
377
+ "bom-ref": `lib:${purl}`,
378
+ name: first.name,
379
+ ...(exact && first.version ? { version: first.version.replace(/^v/, "") } : {}),
380
+ purl,
381
+ properties: [
382
+ { name: "hardkeel:risk", value: first.risk },
383
+ { name: "hardkeel:provides", value: first.provides },
384
+ ...(first.version && !exact ? [{ name: "hardkeel:versionRange", value: first.version }] : []),
385
+ ],
386
+ evidence: { occurrences: ls.map((l) => ({ location: l.file, ...(l.line > 0 ? { line: l.line } : {}) })) },
387
+ });
388
+ }
389
+ components.push(...protocolComponents(opts.protocols ?? [], taken));
390
+ // How much of the post-quantum encryption rests on lattice math alone, with agility advice. Never a grade.
391
+ const reliance = pqcReliance(opts.pqc ?? [], inventory);
392
+ const relianceProps = reliance.places
393
+ ? [
394
+ { name: "hardkeel:pqcPlaces", value: String(reliance.places) },
395
+ { name: "hardkeel:pqcLatticeOnly", value: String(reliance.latticeOnly) },
396
+ ...reliance.notes.map((value) => ({ name: "hardkeel:agility", value })),
397
+ ]
398
+ : [];
399
+ // A local folder is named by its last part, so the inventory doesn't carry the path on this computer.
400
+ const name = /^([a-zA-Z]:)?[\\/]/.test(opts.repo) ? opts.repo.replace(/[\\/]+$/, "").split(/[\\/]/).pop() || opts.repo : opts.repo;
401
+ return {
402
+ $schema: "http://cyclonedx.org/schema/bom-1.6.schema.json",
403
+ bomFormat: "CycloneDX",
404
+ specVersion: "1.6",
405
+ // A fresh id for each inventory, so tools that track BOMs can tell two runs apart.
406
+ serialNumber: `urn:uuid:${randomUUID()}`,
407
+ version: 1,
408
+ metadata: {
409
+ timestamp: opts.timestamp ?? new Date().toISOString(),
410
+ tools: { components: [{ type: "application", publisher: "Hard Keel", supplier: { name: "Hard Keel", url: ["https://hardkeel.com"] }, name: "Hard Keel Benthic", version: opts.toolVersion }] },
411
+ component: { type: "application", "bom-ref": "subject", name, ...(opts.ref ? { version: opts.ref } : {}) },
412
+ ...(relianceProps.length || opts.dirty !== undefined ? { properties: [...relianceProps, ...(opts.dirty !== undefined ? [{ name: "hardkeel:uncommittedChanges", value: String(opts.dirty) }] : [])] } : {}),
413
+ },
414
+ components,
415
+ // What was checked uses every algorithm listed.
416
+ dependencies: [{ ref: "subject", dependsOn: components.map((c) => c["bom-ref"]) }],
417
+ };
418
+ }