@cdxgen/cdxgen 13.3.0 → 13.4.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 (255) hide show
  1. package/README.md +9 -6
  2. package/bin/cdxgen.js +90 -26
  3. package/bin/evinse.js +18 -1
  4. package/bin/repl.js +86 -0
  5. package/bin/sign.js +45 -15
  6. package/bin/tracebom.js +5 -1
  7. package/bin/validate.js +84 -18
  8. package/bin/verify.js +155 -86
  9. package/data/helpers/init.gradle +46 -21
  10. package/data/remediations.json +61 -0
  11. package/data/rules/dependency-sources.yaml +67 -0
  12. package/data/rules/scala-evidence.yaml +115 -0
  13. package/lib/audit/index.js +38 -6
  14. package/lib/cli/index.js +113 -54
  15. package/lib/cli/jsBom.js +50 -29
  16. package/lib/cli/jvmBom.js +665 -138
  17. package/lib/cli/managedBom.js +320 -200
  18. package/lib/cli/nativeBom.js +139 -30
  19. package/lib/core/activity.js +12 -0
  20. package/lib/core/env.js +17 -9
  21. package/lib/core/fs.js +3 -2
  22. package/lib/core/httpClient.js +159 -24
  23. package/lib/core/pluginRun.js +184 -0
  24. package/lib/core/processTree.js +100 -0
  25. package/lib/core/runState.js +39 -0
  26. package/lib/core/toml.js +72 -0
  27. package/lib/ecosystems/asarutils.js +4 -2
  28. package/lib/ecosystems/bunutils.js +5 -7
  29. package/lib/ecosystems/cargoCache.js +231 -8
  30. package/lib/ecosystems/cmakeResolver.js +10 -21
  31. package/lib/ecosystems/cppBuildContext.js +631 -0
  32. package/lib/ecosystems/cppEvidence.js +337 -22
  33. package/lib/ecosystems/cppIncludeResolver.js +294 -0
  34. package/lib/ecosystems/denoutils.js +93 -66
  35. package/lib/ecosystems/ecosystems.js +1967 -788
  36. package/lib/ecosystems/golem.js +28 -12
  37. package/lib/ecosystems/gradleutils.js +314 -30
  38. package/lib/ecosystems/jsEvidence.js +85 -24
  39. package/lib/ecosystems/kosi.js +21 -4
  40. package/lib/ecosystems/npmutils.js +64 -0
  41. package/lib/ecosystems/parsers-dotnet.js +567 -151
  42. package/lib/ecosystems/parsers-elm.js +46 -28
  43. package/lib/ecosystems/parsers-gleam.js +3 -4
  44. package/lib/ecosystems/parsers-go.js +324 -61
  45. package/lib/ecosystems/parsers-js.js +92 -26
  46. package/lib/ecosystems/parsers-julia.js +2 -3
  47. package/lib/ecosystems/parsers-jvm.js +204 -12
  48. package/lib/ecosystems/parsers-misc.js +182 -55
  49. package/lib/ecosystems/parsers-python.js +141 -10
  50. package/lib/ecosystems/parsers-rust.js +4 -4
  51. package/lib/ecosystems/parsers-terraform.js +1573 -19
  52. package/lib/ecosystems/pythonutils.js +102 -6
  53. package/lib/ecosystems/remote/huggingface.js +3 -0
  54. package/lib/ecosystems/rubyutils.js +67 -17
  55. package/lib/ecosystems/rusi.js +22 -9
  56. package/lib/ecosystems/sbtutils.js +243 -187
  57. package/lib/ecosystems/scalacliutils.js +342 -0
  58. package/lib/ecosystems/scalasem.js +2618 -0
  59. package/lib/ecosystems/terraformRegistry.js +288 -0
  60. package/lib/ecosystems/utils.js +2 -0
  61. package/lib/ecosystems/vendoredCode.js +156 -0
  62. package/lib/evinser/evinser.js +578 -69
  63. package/lib/helpers/agenticToolutils.js +2 -2
  64. package/lib/helpers/bomSigner.js +576 -128
  65. package/lib/inventory/aiCollector.js +4 -1
  66. package/lib/inventory/analyzer.js +110 -127
  67. package/lib/inventory/atomUtils.js +171 -48
  68. package/lib/inventory/auditCategories.js +7 -0
  69. package/lib/inventory/buildToolRateLimit.js +144 -0
  70. package/lib/inventory/cacheCommands.js +2 -1
  71. package/lib/inventory/cmakeBuildDirs.js +254 -0
  72. package/lib/inventory/deps.js +501 -124
  73. package/lib/inventory/dosai.js +248 -44
  74. package/lib/inventory/dosaiParsers.js +310 -15
  75. package/lib/inventory/dynamic.js +52 -6
  76. package/lib/inventory/evidenceUtils.js +154 -109
  77. package/lib/inventory/fetchBatch.js +574 -38
  78. package/lib/inventory/fetchDiskCache.js +597 -0
  79. package/lib/inventory/forgeEnricher.js +14 -5
  80. package/lib/inventory/jvmLocalRepos.js +917 -0
  81. package/lib/inventory/mcpConfigParser.js +2 -3
  82. package/lib/inventory/parentSelection.js +146 -0
  83. package/lib/inventory/rustFormulationParser.js +3 -4
  84. package/lib/inventory/scalaCoords.js +153 -0
  85. package/lib/inventory/source.js +8 -8
  86. package/lib/inventory/spdx.js +101 -0
  87. package/lib/inventory/traceRunner.js +88 -7
  88. package/lib/inventory/tracedCrypto.js +294 -0
  89. package/lib/managers/docker.js +33 -32
  90. package/lib/managers/oci.js +24 -2
  91. package/lib/parsers/cmakeCache.js +69 -0
  92. package/lib/parsers/cmakeLists.js +16 -2
  93. package/lib/parsers/cmakePresets.js +400 -0
  94. package/lib/parsers/compileCommands.js +557 -0
  95. package/lib/parsers/strictJson.js +322 -0
  96. package/lib/parsers/terraformConfig.js +1073 -0
  97. package/lib/parsers/terraformSource.js +652 -0
  98. package/lib/server/server.js +23 -0
  99. package/lib/stages/postgen/introspection/markers.js +1 -1
  100. package/lib/stages/postgen/postgen.js +15 -1
  101. package/lib/stages/postgen/specVersionCompat.js +32 -0
  102. package/lib/validator/index.js +25 -10
  103. package/lib/validator/reporters/json.js +1 -0
  104. package/package.json +21 -21
  105. package/types/lib/audit/index.d.ts.map +1 -1
  106. package/types/lib/cli/index.d.ts.map +1 -1
  107. package/types/lib/cli/jsBom.d.ts.map +1 -1
  108. package/types/lib/cli/jvmBom.d.ts +24 -1
  109. package/types/lib/cli/jvmBom.d.ts.map +1 -1
  110. package/types/lib/cli/managedBom.d.ts +7 -4
  111. package/types/lib/cli/managedBom.d.ts.map +1 -1
  112. package/types/lib/cli/nativeBom.d.ts +3 -1
  113. package/types/lib/cli/nativeBom.d.ts.map +1 -1
  114. package/types/lib/core/activity.d.ts.map +1 -1
  115. package/types/lib/core/env.d.ts +9 -0
  116. package/types/lib/core/env.d.ts.map +1 -1
  117. package/types/lib/core/fs.d.ts.map +1 -1
  118. package/types/lib/core/httpClient.d.ts +13 -8
  119. package/types/lib/core/httpClient.d.ts.map +1 -1
  120. package/types/lib/core/pluginRun.d.ts +97 -0
  121. package/types/lib/core/pluginRun.d.ts.map +1 -0
  122. package/types/lib/core/processTree.d.ts +36 -0
  123. package/types/lib/core/processTree.d.ts.map +1 -0
  124. package/types/lib/core/runState.d.ts +29 -0
  125. package/types/lib/core/runState.d.ts.map +1 -0
  126. package/types/lib/core/toml.d.ts +20 -0
  127. package/types/lib/core/toml.d.ts.map +1 -0
  128. package/types/lib/ecosystems/asarutils.d.ts.map +1 -1
  129. package/types/lib/ecosystems/bunutils.d.ts.map +1 -1
  130. package/types/lib/ecosystems/cargoCache.d.ts +12 -0
  131. package/types/lib/ecosystems/cargoCache.d.ts.map +1 -1
  132. package/types/lib/ecosystems/cmakeResolver.d.ts +5 -3
  133. package/types/lib/ecosystems/cmakeResolver.d.ts.map +1 -1
  134. package/types/lib/ecosystems/cppBuildContext.d.ts +55 -0
  135. package/types/lib/ecosystems/cppBuildContext.d.ts.map +1 -0
  136. package/types/lib/ecosystems/cppEvidence.d.ts +18 -2
  137. package/types/lib/ecosystems/cppEvidence.d.ts.map +1 -1
  138. package/types/lib/ecosystems/cppIncludeResolver.d.ts +92 -0
  139. package/types/lib/ecosystems/cppIncludeResolver.d.ts.map +1 -0
  140. package/types/lib/ecosystems/denoutils.d.ts +9 -3
  141. package/types/lib/ecosystems/denoutils.d.ts.map +1 -1
  142. package/types/lib/ecosystems/ecosystems.d.ts +62 -13
  143. package/types/lib/ecosystems/ecosystems.d.ts.map +1 -1
  144. package/types/lib/ecosystems/golem.d.ts.map +1 -1
  145. package/types/lib/ecosystems/gradleutils.d.ts +50 -0
  146. package/types/lib/ecosystems/gradleutils.d.ts.map +1 -1
  147. package/types/lib/ecosystems/jsEvidence.d.ts.map +1 -1
  148. package/types/lib/ecosystems/kosi.d.ts.map +1 -1
  149. package/types/lib/ecosystems/npmutils.d.ts +15 -0
  150. package/types/lib/ecosystems/npmutils.d.ts.map +1 -1
  151. package/types/lib/ecosystems/parsers-dotnet.d.ts +118 -4
  152. package/types/lib/ecosystems/parsers-dotnet.d.ts.map +1 -1
  153. package/types/lib/ecosystems/parsers-elm.d.ts.map +1 -1
  154. package/types/lib/ecosystems/parsers-gleam.d.ts.map +1 -1
  155. package/types/lib/ecosystems/parsers-go.d.ts +44 -2
  156. package/types/lib/ecosystems/parsers-go.d.ts.map +1 -1
  157. package/types/lib/ecosystems/parsers-js.d.ts +6 -1
  158. package/types/lib/ecosystems/parsers-js.d.ts.map +1 -1
  159. package/types/lib/ecosystems/parsers-julia.d.ts.map +1 -1
  160. package/types/lib/ecosystems/parsers-jvm.d.ts +46 -1
  161. package/types/lib/ecosystems/parsers-jvm.d.ts.map +1 -1
  162. package/types/lib/ecosystems/parsers-misc.d.ts +3 -1
  163. package/types/lib/ecosystems/parsers-misc.d.ts.map +1 -1
  164. package/types/lib/ecosystems/parsers-python.d.ts +53 -3
  165. package/types/lib/ecosystems/parsers-python.d.ts.map +1 -1
  166. package/types/lib/ecosystems/parsers-terraform.d.ts +38 -21
  167. package/types/lib/ecosystems/parsers-terraform.d.ts.map +1 -1
  168. package/types/lib/ecosystems/pythonutils.d.ts +27 -2
  169. package/types/lib/ecosystems/pythonutils.d.ts.map +1 -1
  170. package/types/lib/ecosystems/remote/huggingface.d.ts.map +1 -1
  171. package/types/lib/ecosystems/rubyutils.d.ts +21 -1
  172. package/types/lib/ecosystems/rubyutils.d.ts.map +1 -1
  173. package/types/lib/ecosystems/rusi.d.ts.map +1 -1
  174. package/types/lib/ecosystems/sbtutils.d.ts +88 -2
  175. package/types/lib/ecosystems/sbtutils.d.ts.map +1 -1
  176. package/types/lib/ecosystems/scalacliutils.d.ts +56 -0
  177. package/types/lib/ecosystems/scalacliutils.d.ts.map +1 -0
  178. package/types/lib/ecosystems/scalasem.d.ts +311 -0
  179. package/types/lib/ecosystems/scalasem.d.ts.map +1 -0
  180. package/types/lib/ecosystems/terraformRegistry.d.ts +9 -0
  181. package/types/lib/ecosystems/terraformRegistry.d.ts.map +1 -0
  182. package/types/lib/ecosystems/utils.d.ts +2 -2
  183. package/types/lib/ecosystems/utils.d.ts.map +1 -1
  184. package/types/lib/ecosystems/vendoredCode.d.ts +32 -0
  185. package/types/lib/ecosystems/vendoredCode.d.ts.map +1 -0
  186. package/types/lib/evinser/evinser.d.ts +75 -8
  187. package/types/lib/evinser/evinser.d.ts.map +1 -1
  188. package/types/lib/helpers/bomSigner.d.ts +80 -4
  189. package/types/lib/helpers/bomSigner.d.ts.map +1 -1
  190. package/types/lib/inventory/aiCollector.d.ts.map +1 -1
  191. package/types/lib/inventory/analyzer.d.ts.map +1 -1
  192. package/types/lib/inventory/atomUtils.d.ts +82 -10
  193. package/types/lib/inventory/atomUtils.d.ts.map +1 -1
  194. package/types/lib/inventory/auditCategories.d.ts +3 -0
  195. package/types/lib/inventory/auditCategories.d.ts.map +1 -1
  196. package/types/lib/inventory/buildToolRateLimit.d.ts +38 -0
  197. package/types/lib/inventory/buildToolRateLimit.d.ts.map +1 -0
  198. package/types/lib/inventory/cacheCommands.d.ts +2 -1
  199. package/types/lib/inventory/cacheCommands.d.ts.map +1 -1
  200. package/types/lib/inventory/cmakeBuildDirs.d.ts +58 -0
  201. package/types/lib/inventory/cmakeBuildDirs.d.ts.map +1 -0
  202. package/types/lib/inventory/deps.d.ts +59 -1
  203. package/types/lib/inventory/deps.d.ts.map +1 -1
  204. package/types/lib/inventory/dosai.d.ts +57 -8
  205. package/types/lib/inventory/dosai.d.ts.map +1 -1
  206. package/types/lib/inventory/dosaiParsers.d.ts +53 -7
  207. package/types/lib/inventory/dosaiParsers.d.ts.map +1 -1
  208. package/types/lib/inventory/dynamic.d.ts +10 -0
  209. package/types/lib/inventory/dynamic.d.ts.map +1 -1
  210. package/types/lib/inventory/evidenceUtils.d.ts +19 -4
  211. package/types/lib/inventory/evidenceUtils.d.ts.map +1 -1
  212. package/types/lib/inventory/fetchBatch.d.ts +83 -14
  213. package/types/lib/inventory/fetchBatch.d.ts.map +1 -1
  214. package/types/lib/inventory/fetchDiskCache.d.ts +169 -0
  215. package/types/lib/inventory/fetchDiskCache.d.ts.map +1 -0
  216. package/types/lib/inventory/forgeEnricher.d.ts.map +1 -1
  217. package/types/lib/inventory/jvmLocalRepos.d.ts +178 -0
  218. package/types/lib/inventory/jvmLocalRepos.d.ts.map +1 -0
  219. package/types/lib/inventory/mcpConfigParser.d.ts.map +1 -1
  220. package/types/lib/inventory/parentSelection.d.ts +34 -0
  221. package/types/lib/inventory/parentSelection.d.ts.map +1 -0
  222. package/types/lib/inventory/rustFormulationParser.d.ts.map +1 -1
  223. package/types/lib/inventory/scalaCoords.d.ts +80 -0
  224. package/types/lib/inventory/scalaCoords.d.ts.map +1 -0
  225. package/types/lib/inventory/source.d.ts.map +1 -1
  226. package/types/lib/inventory/spdx.d.ts +9 -0
  227. package/types/lib/inventory/spdx.d.ts.map +1 -1
  228. package/types/lib/inventory/traceRunner.d.ts +12 -0
  229. package/types/lib/inventory/traceRunner.d.ts.map +1 -1
  230. package/types/lib/inventory/tracedCrypto.d.ts +42 -0
  231. package/types/lib/inventory/tracedCrypto.d.ts.map +1 -0
  232. package/types/lib/managers/docker.d.ts.map +1 -1
  233. package/types/lib/managers/oci.d.ts +3 -1
  234. package/types/lib/managers/oci.d.ts.map +1 -1
  235. package/types/lib/parsers/cmakeCache.d.ts +16 -0
  236. package/types/lib/parsers/cmakeCache.d.ts.map +1 -1
  237. package/types/lib/parsers/cmakeLists.d.ts +2 -1
  238. package/types/lib/parsers/cmakeLists.d.ts.map +1 -1
  239. package/types/lib/parsers/cmakePresets.d.ts +78 -0
  240. package/types/lib/parsers/cmakePresets.d.ts.map +1 -0
  241. package/types/lib/parsers/compileCommands.d.ts +115 -0
  242. package/types/lib/parsers/compileCommands.d.ts.map +1 -0
  243. package/types/lib/parsers/strictJson.d.ts +46 -0
  244. package/types/lib/parsers/strictJson.d.ts.map +1 -0
  245. package/types/lib/parsers/terraformConfig.d.ts +70 -0
  246. package/types/lib/parsers/terraformConfig.d.ts.map +1 -0
  247. package/types/lib/parsers/terraformSource.d.ts +66 -0
  248. package/types/lib/parsers/terraformSource.d.ts.map +1 -0
  249. package/types/lib/server/server.d.ts.map +1 -1
  250. package/types/lib/stages/postgen/postgen.d.ts.map +1 -1
  251. package/types/lib/stages/postgen/specVersionCompat.d.ts.map +1 -1
  252. package/types/lib/validator/index.d.ts +8 -0
  253. package/types/lib/validator/index.d.ts.map +1 -1
  254. package/types/lib/validator/reporters/json.d.ts.map +1 -1
  255. package/lib/third-party/arborist/snapshots/calc-dep-flags.test.cjs +0 -462
package/bin/validate.js CHANGED
@@ -26,6 +26,7 @@ import {
26
26
  safeMkdirSync,
27
27
  safeWriteSync,
28
28
  } from "../lib/ecosystems/utils.js";
29
+ import { displayValue } from "../lib/helpers/bomSigner.js";
29
30
  import {
30
31
  getNonCycloneDxErrorMessage,
31
32
  isCycloneDxBom,
@@ -35,6 +36,7 @@ import {
35
36
  isProtoBomPath,
36
37
  } from "../lib/inventory/protobomLoader.js";
37
38
  import { getBomWithOras } from "../lib/managers/oci.js";
39
+ import { parseStrictJson } from "../lib/parsers/strictJson.js";
38
40
  import { shouldFail, validateBomAdvanced } from "../lib/validator/index.js";
39
41
  import { render as renderReport } from "../lib/validator/reporters/index.js";
40
42
 
@@ -126,9 +128,8 @@ const args = _yargs
126
128
  })
127
129
  .option("require-signature", {
128
130
  type: "boolean",
129
- default: false,
130
131
  description:
131
- "Exit non-zero (4) when --public-key or --secret-key is provided but signature verification fails.",
132
+ "Exit non-zero (4) when signature verification fails. On by default when --public-key or --secret-key is given; pass --no-require-signature to only report the result.",
132
133
  })
133
134
  .option("strict", {
134
135
  type: "boolean",
@@ -143,7 +144,11 @@ const args = _yargs
143
144
  .help()
144
145
  .wrap(Math.min(120, yargs().terminalWidth())).argv;
145
146
 
146
- async function loadBom(input, platform) {
147
+ /**
148
+ * Loads the BOM. When signatures are verified, the text must also pass
149
+ * parseStrictJson(), and `strictError` explains why it did not.
150
+ */
151
+ async function loadBom(input, platform, strict, requireSignature) {
147
152
  if (safeExistsSync(input)) {
148
153
  try {
149
154
  if (isProtoBomPath(input)) {
@@ -151,9 +156,18 @@ async function loadBom(input, platform) {
151
156
  "cdx-validate",
152
157
  "protobuf BOM input",
153
158
  );
154
- return readBinary(input, true);
159
+ return { bomJson: readBinary(input, true) };
155
160
  }
156
- return JSON.parse(fs.readFileSync(input, "utf8"));
161
+ const bytes = fs.readFileSync(input);
162
+ const bomJson = JSON.parse(bytes.toString("utf8"));
163
+ if (strict) {
164
+ try {
165
+ parseStrictJson(bytes);
166
+ } catch (err) {
167
+ return { bomJson, strictError: err.message };
168
+ }
169
+ }
170
+ return { bomJson };
157
171
  } catch (err) {
158
172
  console.error(`Failed to parse ${input}: ${err.message}`);
159
173
  process.exit(1);
@@ -164,8 +178,27 @@ async function loadBom(input, platform) {
164
178
  input.includes("docker") ||
165
179
  input.includes("ghcr")
166
180
  ) {
167
- const bom = await getBomWithOras(input, platform);
168
- if (bom) return bom;
181
+ let strictError;
182
+ try {
183
+ const bom = await getBomWithOras(
184
+ input,
185
+ platform,
186
+ strict ? { checkBytes: parseStrictJson } : {},
187
+ );
188
+ if (bom) return { bomJson: bom };
189
+ } catch (err) {
190
+ if (requireSignature) {
191
+ console.error(
192
+ `cdx-validate: signature verification failed — the attached BOM cannot be verified: ${err.message}`,
193
+ );
194
+ process.exit(4);
195
+ }
196
+ strictError = err.message;
197
+ }
198
+ if (strictError) {
199
+ const bom = await getBomWithOras(input, platform);
200
+ if (bom) return { bomJson: bom, strictError };
201
+ }
169
202
  }
170
203
  console.error(`Input '${input}' is not a readable SBOM.`);
171
204
  process.exit(1);
@@ -173,12 +206,21 @@ async function loadBom(input, platform) {
173
206
  }
174
207
 
175
208
  function loadKeyFile(path, label, encoding) {
176
- if (!path) return null;
209
+ if (path === undefined) return null;
210
+ if (typeof path !== "string" || !path.trim()) {
211
+ console.error(`cdx-validate: ${label} needs exactly one file path.`);
212
+ process.exit(1);
213
+ }
177
214
  if (!safeExistsSync(path)) {
178
215
  console.error(`${label} '${path}' not found.`);
179
216
  process.exit(1);
180
217
  }
181
- return fs.readFileSync(path, encoding);
218
+ const content = fs.readFileSync(path, encoding);
219
+ if (!content.toString().trim()) {
220
+ console.error(`${label} '${path}' is empty.`);
221
+ process.exit(1);
222
+ }
223
+ return content;
182
224
  }
183
225
 
184
226
  function splitCsv(value) {
@@ -208,14 +250,21 @@ function isLocalProtoBomInput(input) {
208
250
  return isProtoBomPath(input);
209
251
  }
210
252
 
211
- const bomJson = await loadBom(args.input, args.platform);
212
- if (args.publicKey && args.secretKey) {
253
+ const keyGiven = args.publicKey !== undefined || args.secretKey !== undefined;
254
+ const requireSignature = args.requireSignature ?? keyGiven;
255
+ const { bomJson, strictError } = await loadBom(
256
+ args.input,
257
+ args.platform,
258
+ keyGiven,
259
+ requireSignature,
260
+ );
261
+ if (args.publicKey !== undefined && args.secretKey !== undefined) {
213
262
  console.error("cdx-validate: use either --public-key or --secret-key.");
214
263
  process.exit(1);
215
264
  }
216
265
  const publicKeyStr = loadKeyFile(args.publicKey, "Public key", "utf8");
217
266
  const secretKey = loadKeyFile(args.secretKey, "Shared secret");
218
- const verificationRequested = Boolean(publicKeyStr || secretKey);
267
+ const verificationRequested = keyGiven;
219
268
  const inputIsLocalProtoBom = isLocalProtoBomInput(args.input);
220
269
  if (!isCycloneDxBom(bomJson)) {
221
270
  console.error(getNonCycloneDxErrorMessage(bomJson, "cdx-validate"));
@@ -226,7 +275,7 @@ if (inputIsLocalProtoBom && verificationRequested) {
226
275
  console.error(
227
276
  "cdx-validate: protobuf BOM input does not currently preserve JSF signature blocks. Verify signatures against the source JSON BOM instead.",
228
277
  );
229
- process.exit(args.requireSignature ? 4 : 1);
278
+ process.exit(requireSignature ? 4 : 1);
230
279
  }
231
280
 
232
281
  const report = await validateBomAdvanced(bomJson, {
@@ -237,10 +286,17 @@ const report = await validateBomAdvanced(bomJson, {
237
286
  minSeverity: args.minSeverity,
238
287
  includeManual: args.includeManual,
239
288
  includePass: args.includePass,
240
- publicKey: publicKeyStr || undefined,
241
- secretKey: secretKey || undefined,
289
+ publicKey: publicKeyStr ?? undefined,
290
+ secretKey: secretKey ?? undefined,
242
291
  nestedSignatures: args.nestedSignatures,
243
292
  });
293
+ if (strictError && verificationRequested) {
294
+ report.signatureVerified = false;
295
+ report.signatureEntries = null;
296
+ report.signatureDetails = {
297
+ error: `the BOM cannot be verified: ${strictError}`,
298
+ };
299
+ }
244
300
 
245
301
  let output;
246
302
  try {
@@ -267,14 +323,24 @@ for (const e of report.validationErrors || []) {
267
323
  const { shouldFail: fail, reason } = shouldFail(report, {
268
324
  failSeverity: args.failSeverity,
269
325
  strict: args.strict,
270
- requireSignature: Boolean(args.requireSignature && verificationRequested),
326
+ requireSignature: Boolean(requireSignature && verificationRequested),
271
327
  });
272
328
 
273
- if (report.signatureVerified === false && args.requireSignature) {
329
+ if (report.signatureVerified === false && verificationRequested) {
274
330
  console.error(
275
331
  `cdx-validate: signature verification failed — ${report.signatureDetails?.error || "no matching key"}.`,
276
332
  );
277
- process.exit(4);
333
+ if (requireSignature) {
334
+ process.exit(4);
335
+ }
336
+ }
337
+ const unverifiedEntries = (report.signatureEntries || []).filter(
338
+ (entry) => !entry.verified,
339
+ );
340
+ if (report.signatureVerified && unverifiedEntries.length) {
341
+ console.error(
342
+ `cdx-validate: warning — ${unverifiedEntries.length} of ${report.signatureEntries.length} signature entries did not verify with the given key: ${unverifiedEntries.map((entry) => `entry ${entry.index}${entry.keyId === undefined ? "" : ` (keyId '${displayValue(entry.keyId)}')`}`).join(", ")}.`,
343
+ );
278
344
  }
279
345
 
280
346
  if (args.strict && report.schemaValid === false) {
package/bin/verify.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  displayValue,
18
18
  loadSharedSecret,
19
19
  loadVerificationKey,
20
- verifyNode,
20
+ verifyBomSignatures,
21
21
  } from "../lib/helpers/bomSigner.js";
22
22
  import {
23
23
  getNonCycloneDxErrorMessage,
@@ -25,6 +25,7 @@ import {
25
25
  } from "../lib/inventory/bomUtils.js";
26
26
  import { isProtoBomPath } from "../lib/inventory/protobomLoader.js";
27
27
  import { getBomWithOras } from "../lib/managers/oci.js";
28
+ import { parseStrictJson } from "../lib/parsers/strictJson.js";
28
29
 
29
30
  const dirName = dirNameStr;
30
31
 
@@ -41,10 +42,13 @@ const args = _yargs
41
42
  description: "The platform to validate. No default",
42
43
  })
43
44
  .option("public-key", {
45
+ type: "array",
46
+ string: true,
44
47
  description:
45
- "Public key in PEM format. Default public.key unless --secret-key is used",
48
+ "Trusted public key in PEM format. Repeat to trust several keys; a signature entry verifies when one of them verifies it.",
46
49
  })
47
50
  .option("secret-key", {
51
+ type: "string",
48
52
  description:
49
53
  "File holding the shared secret for HMAC (HS256, HS384, HS512) signatures. HMAC signatures are only accepted with this option.",
50
54
  })
@@ -52,7 +56,19 @@ const args = _yargs
52
56
  type: "boolean",
53
57
  default: true,
54
58
  description:
55
- "Strictly verify all nested component, service, and annotation signatures against the provided public key. Pass --no-deep to verify only the root signature.",
59
+ "Strictly verify all nested component, service, and annotation signatures against the provided keys. Pass --no-deep to verify only the root signature.",
60
+ })
61
+ .option("require-all", {
62
+ type: "boolean",
63
+ default: false,
64
+ description:
65
+ "Require every entry of a signers or chain signature to verify with one of the keys, instead of at least one.",
66
+ })
67
+ .option("allow-nested-only", {
68
+ type: "boolean",
69
+ default: false,
70
+ description:
71
+ "Accept a BOM without a root signature when every component, service, and annotation carries a signature that verifies. No signature then covers the other members of the BOM.",
56
72
  })
57
73
  .completion("completion", "Generate bash/zsh completion")
58
74
  .epilogue("for documentation, visit https://cdxgen.github.io/cdxgen")
@@ -96,7 +112,7 @@ async function getBom(args) {
96
112
  process.exit(1);
97
113
  }
98
114
  try {
99
- return JSON.parse(fs.readFileSync(args.input, "utf8"));
115
+ return parseStrictJson(fs.readFileSync(args.input));
100
116
  } catch (error) {
101
117
  console.log(`Failed to parse '${args.input}': ${error.message}`);
102
118
  process.exit(1);
@@ -107,11 +123,32 @@ async function getBom(args) {
107
123
  args.input.includes("docker") ||
108
124
  args.input.includes("ghcr")
109
125
  ) {
110
- return await getBomWithOras(args.input, args.platform);
126
+ try {
127
+ return await getBomWithOras(args.input, args.platform, {
128
+ checkBytes: parseStrictJson,
129
+ });
130
+ } catch (error) {
131
+ console.log(
132
+ `Failed to parse the BOM attached to '${args.input}': ${error.message}`,
133
+ );
134
+ process.exit(1);
135
+ }
111
136
  }
112
137
  return undefined;
113
138
  }
114
139
 
140
+ const publicKeyFiles = args.publicKey || [];
141
+ if (publicKeyFiles.length && args.secretKey) {
142
+ console.log("Use either --public-key or --secret-key, not both.");
143
+ process.exit(1);
144
+ }
145
+ if (!publicKeyFiles.length && !args.secretKey) {
146
+ console.log(
147
+ "Name the trusted key with --public-key <file>, or --secret-key <file> for HMAC signatures.",
148
+ );
149
+ process.exit(1);
150
+ }
151
+
115
152
  const bomJson = await getBom(args);
116
153
 
117
154
  if (!bomJson) {
@@ -123,107 +160,139 @@ if (!isCycloneDxBom(bomJson)) {
123
160
  process.exit(1);
124
161
  }
125
162
 
126
- if (args.publicKey && args.secretKey) {
127
- console.log("Use either --public-key or --secret-key, not both.");
128
- process.exit(1);
129
- }
130
- const keyFile = args.secretKey || args.publicKey || "public.key";
131
- if (!args.secretKey && !args.publicKey) {
132
- console.log(
133
- `No --public-key given; using '${keyFile}' from the current directory. Pass --public-key to name the trusted key explicitly.`,
134
- );
135
- }
136
- if (!safeExistsSync(keyFile)) {
137
- console.log(
138
- args.secretKey
139
- ? "Shared secret for signature verification is missing!"
140
- : "Public key for signature verification is missing!",
141
- );
142
- process.exit(1);
143
- }
144
-
145
- let verificationKey;
146
- try {
147
- verificationKey = args.secretKey
148
- ? loadSharedSecret(fs.readFileSync(keyFile))
149
- : loadVerificationKey(fs.readFileSync(keyFile, "utf8"));
150
- } catch (error) {
151
- console.log(`Unable to use '${keyFile}': ${error.message}`);
152
- process.exit(1);
163
+ const verificationKeys = [];
164
+ for (const keyFile of args.secretKey ? [args.secretKey] : publicKeyFiles) {
165
+ if (!safeExistsSync(keyFile)) {
166
+ console.log(
167
+ args.secretKey
168
+ ? `Shared secret '${keyFile}' for signature verification is missing!`
169
+ : `Public key '${keyFile}' for signature verification is missing!`,
170
+ );
171
+ process.exit(1);
172
+ }
173
+ try {
174
+ verificationKeys.push(
175
+ args.secretKey
176
+ ? loadSharedSecret(fs.readFileSync(keyFile))
177
+ : loadVerificationKey(fs.readFileSync(keyFile, "utf8")),
178
+ );
179
+ } catch (error) {
180
+ console.log(`Unable to use '${keyFile}': ${error.message}`);
181
+ process.exit(1);
182
+ }
153
183
  }
154
184
 
155
- function verify(node) {
156
- const reasons = [];
157
- const match = verifyNode(node, verificationKey, { reasons });
158
- return { match, reasons };
185
+ function describeEntry(node, entry) {
186
+ const parts = [displayValue(entry.algorithm)];
187
+ if (entry.keyId !== undefined) {
188
+ parts.push(`keyId '${displayValue(entry.keyId)}'`);
189
+ }
190
+ const position =
191
+ node.form === "single" ? "" : `${node.form}[${entry.index}] `;
192
+ return `${position}(${parts.join(", ")})`;
159
193
  }
160
194
 
161
- function printReasons(reasons) {
162
- for (const reason of new Set(reasons)) {
195
+ function printRejections(node) {
196
+ for (const reason of node.reasons) {
163
197
  console.log(` - ${reason}`);
164
198
  }
165
- }
166
-
167
- let rootResult = null;
168
- if (bomJson.signature) {
169
- rootResult = verify(bomJson);
170
- }
171
-
172
- const verifyNested = args.deep || !bomJson.signature;
173
- let hasInvalidNested = false;
174
- let checkedNested = 0;
175
-
176
- if (verifyNested) {
177
- const nestedTargets = [
178
- ["components", "Component", (c) => c["bom-ref"] || c.name],
179
- ["services", "Service", (s) => s["bom-ref"] || s.name],
180
- ["annotations", "Annotation", (a) => a["bom-ref"] || a.subject],
181
- ];
182
- for (const [field, label, nameOf] of nestedTargets) {
183
- for (const node of bomJson[field] || []) {
184
- if (node?.signature) {
185
- checkedNested++;
186
- const result = verify(node);
187
- if (!result.match) {
188
- console.log(
189
- `${label} '${displayValue(nameOf(node))}' signature is invalid!`,
190
- );
191
- printReasons(result.reasons);
192
- hasInvalidNested = true;
193
- }
194
- }
199
+ for (const entry of node.entries) {
200
+ for (const reason of entry.reasons) {
201
+ console.log(
202
+ ` - ${node.form === "single" ? "" : `${node.form}[${entry.index}]: `}${reason}`,
203
+ );
195
204
  }
196
205
  }
197
206
  }
198
207
 
199
- if (hasInvalidNested) {
208
+ const report = verifyBomSignatures(bomJson, verificationKeys, {
209
+ deep: args.deep,
210
+ allowNestedOnly: args.allowNestedOnly,
211
+ requireAll: args.requireAll,
212
+ });
213
+
214
+ for (const error of report.errors) {
215
+ console.log(error);
216
+ }
217
+ const keyFiles = args.secretKey ? [args.secretKey] : publicKeyFiles;
218
+ if (args.requireAll && report.root?.form) {
219
+ report.root.keysMatched.forEach((matched, index) => {
220
+ if (!matched) {
221
+ console.log(` - key #${index + 1}: ${keyFiles[index]}`);
222
+ }
223
+ });
224
+ }
225
+ const invalidNested = report.nested.filter((item) => !item.verified);
226
+ for (const item of invalidNested) {
227
+ console.log(`${item.label} signature is invalid!`);
228
+ printRejections(item);
229
+ }
230
+ if (invalidNested.length) {
200
231
  console.log("One or more nested signatures are invalid!");
201
- if (rootResult?.match) {
232
+ if (report.root?.verified) {
202
233
  console.log(
203
234
  "The root signature verifies with this key. Nested signatures belong to the party that created them, so pass --no-deep to verify only the root signature with this key.",
204
235
  );
205
236
  }
237
+ }
238
+ if (report.root && !report.root.verified) {
239
+ console.log("BOM signature is invalid!");
240
+ printRejections(report.root);
241
+ if (!report.root.reasons.length && !report.root.match) {
242
+ console.log(
243
+ "If this BOM was signed with cdxgen 13.2.0 or earlier, re-sign it with this version of cdx-sign.",
244
+ );
245
+ }
246
+ }
247
+ if (!report.root && !bomJson.signature && !args.allowNestedOnly) {
248
+ console.log(
249
+ "Pass --allow-nested-only to accept a BOM whose components, services, and annotations are all signed.",
250
+ );
251
+ }
252
+ for (const notice of report.notices) {
253
+ console.log(`Note: ${notice}`);
254
+ }
255
+ if (!report.verified) {
206
256
  process.exit(1);
207
257
  }
208
258
 
209
- if (bomJson.signature) {
210
- const rootMatch = rootResult?.match;
211
- if (rootMatch) {
212
- const identifier = rootMatch.keyId
213
- ? `KeyId: '${displayValue(rootMatch.keyId)}'`
214
- : `Algorithm: '${rootMatch.algorithm}'`;
215
- console.log(`✓ Signature is valid! (Matched ${identifier})`);
216
- } else {
217
- console.log("BOM signature is invalid!");
218
- printReasons(rootResult?.reasons || []);
259
+ if (report.root) {
260
+ const rootMatch = report.root.match;
261
+ const identifier = rootMatch.keyId
262
+ ? `KeyId: '${displayValue(rootMatch.keyId)}'`
263
+ : `Algorithm: '${rootMatch.algorithm}'`;
264
+ console.log(`✓ Signature is valid! (Matched ${identifier})`);
265
+ const unverified = report.root.entries.filter((entry) => !entry.verified);
266
+ if (unverified.length) {
219
267
  console.log(
220
- "If this BOM was signed with cdxgen 13.2.0 or earlier, re-sign it with this version of cdx-sign.",
268
+ `Warning: ${unverified.length} of ${report.root.entries.length} ${report.root.form} entries did not verify with the given key(s). Pass --require-all to fail in that case.`,
221
269
  );
222
- process.exit(1);
270
+ for (const entry of unverified) {
271
+ console.log(
272
+ ` - ${describeEntry(report.root, entry)}: ${entry.reasons[0] || "not verified"}`,
273
+ );
274
+ }
223
275
  }
224
- } else if (checkedNested > 0 && !hasInvalidNested) {
225
- console.log(`✓ ${checkedNested} nested signature(s) are valid!`);
226
276
  } else {
227
- console.log("No valid signatures found to verify!");
228
- process.exit(1);
277
+ console.log(`✓ ${report.nested.length} nested signature(s) are valid!`);
278
+ }
279
+ const MAX_LISTED_ENTRIES = 10;
280
+ const unverifiedNested = report.nested.flatMap((item) =>
281
+ item.entries
282
+ .filter((entry) => !entry.verified)
283
+ .map(
284
+ (entry) =>
285
+ `${item.label} ${describeEntry(item, entry)}: ${entry.reasons[0] || "not verified"}`,
286
+ ),
287
+ );
288
+ if (unverifiedNested.length) {
289
+ console.log(
290
+ `Warning: ${unverifiedNested.length} nested signature entries did not verify with the given key(s). Pass --require-all to fail in that case.`,
291
+ );
292
+ for (const line of unverifiedNested.slice(0, MAX_LISTED_ENTRIES)) {
293
+ console.log(` - ${line}`);
294
+ }
295
+ if (unverifiedNested.length > MAX_LISTED_ENTRIES) {
296
+ console.log(` - and ${unverifiedNested.length - MAX_LISTED_ENTRIES} more`);
297
+ }
229
298
  }
@@ -17,14 +17,51 @@ allprojects {
17
17
  // attached to the matching component instead of guessing the first repository.
18
18
  if (project.hasProperty('cdxgenResolveDistribution') &&
19
19
  project.property('cdxgenResolveDistribution').toString() == 'true') {
20
- def resolvedKeys = [] as Set
20
+ // Shared by every project in the build, so a dependency declared in
21
+ // many subprojects is probed once, and a repository host that
22
+ // answers 429 is left alone for the rest of the build.
23
+ if (!gradle.ext.has('cdxgenResolvedKeys')) {
24
+ gradle.ext.cdxgenResolvedKeys = java.util.concurrent.ConcurrentHashMap.newKeySet()
25
+ gradle.ext.cdxgenPausedHosts = java.util.concurrent.ConcurrentHashMap.newKeySet()
26
+ }
27
+ def resolvedKeys = gradle.ext.cdxgenResolvedKeys
28
+ def pausedHosts = gradle.ext.cdxgenPausedHosts
29
+ // A HEAD request answers whether the repository serves the file
30
+ // without downloading it. Other URL schemes, such as file:, are
31
+ // opened and closed.
32
+ def artifactExists = { String artifactUrl ->
33
+ try {
34
+ def url = new URL(artifactUrl)
35
+ if (url.protocol == 'http' || url.protocol == 'https') {
36
+ if (pausedHosts.contains(url.host)) {
37
+ return false
38
+ }
39
+ def connection = (HttpURLConnection) url.openConnection()
40
+ connection.requestMethod = 'HEAD'
41
+ connection.instanceFollowRedirects = true
42
+ connection.connectTimeout = 10000
43
+ connection.readTimeout = 10000
44
+ def code = connection.responseCode
45
+ connection.disconnect()
46
+ if (code == 429) {
47
+ pausedHosts.add(url.host)
48
+ }
49
+ return code >= 200 && code < 300
50
+ }
51
+ def stream = url.openStream()
52
+ stream.close()
53
+ return true
54
+ } catch (Exception ignored) {
55
+ return false
56
+ }
57
+ }
21
58
  project.configurations.each { configuration ->
22
59
  configuration.dependencies.each { dependency ->
23
60
  if (dependency.group == null || dependency.version == null) {
24
61
  return
25
62
  }
26
63
  def depKey = String.format("%s:%s:%s", dependency.group, dependency.name, dependency.version)
27
- if (resolvedKeys.contains(depKey)) {
64
+ if (!resolvedKeys.add(depKey)) {
28
65
  return
29
66
  }
30
67
  def groupPath = dependency.group.replace('.', '/')
@@ -40,28 +77,16 @@ allprojects {
40
77
  def jarUrl = String.format("%s%s/%s/%s/%s-%s.jar", urlString,
41
78
  groupPath, dependency.name, dependency.version,
42
79
  dependency.name, dependency.version)
80
+ if (artifactExists(jarUrl)) {
81
+ println "<CDXGEN:distribution>:" + depKey + " -> " + jarUrl
82
+ break
83
+ }
43
84
  def aarUrl = String.format("%s%s/%s/%s/%s-%s.aar", urlString,
44
85
  groupPath, dependency.name, dependency.version,
45
86
  dependency.name, dependency.version)
46
- try {
47
- def inStreamJar = new URL(jarUrl).openStream()
48
- if (inStreamJar != null) {
49
- inStreamJar.close()
50
- println "<CDXGEN:distribution>:" + depKey + " -> " + jarUrl
51
- resolvedKeys.add(depKey)
52
- break
53
- }
54
- } catch (Exception ignored) {
55
- }
56
- try {
57
- def inStreamAar = new URL(aarUrl).openStream()
58
- if (inStreamAar != null) {
59
- inStreamAar.close()
60
- println "<CDXGEN:distribution>:" + depKey + " -> " + aarUrl
61
- resolvedKeys.add(depKey)
62
- break
63
- }
64
- } catch (Exception ignored) {
87
+ if (artifactExists(aarUrl)) {
88
+ println "<CDXGEN:distribution>:" + depKey + " -> " + aarUrl
89
+ break
65
90
  }
66
91
  }
67
92
  }
@@ -263,6 +263,46 @@
263
263
  },
264
264
  "docs": "https://cyclonedx.github.io/cdxgen/#/PROJECT_TYPES?id=java"
265
265
  },
266
+ "build.rate-limited": {
267
+ "ecosystem": "generic",
268
+ "kind": "evidence.degraded",
269
+ "impact": "transitive-deps",
270
+ "title": "A build tool's repository rate limited the machine, so its dependency tree did not resolve",
271
+ "targetTier": null,
272
+ "actions": [
273
+ {
274
+ "kind": "config",
275
+ "command": "Maven: declare a <mirror> in the Maven settings.xml, or set MVNW_REPOURL for the Maven wrapper"
276
+ },
277
+ {
278
+ "kind": "config",
279
+ "command": "Gradle: declare the mirror repository in a Gradle init script"
280
+ },
281
+ {
282
+ "kind": "config",
283
+ "command": "sbt: list the mirror in ~/.sbt/repositories and pass -Dsbt.override.build.repos=true in SBT_OPTS or .sbtopts"
284
+ },
285
+ {
286
+ "kind": "config",
287
+ "command": "Mill and scala-cli: set central.from and central.to in Coursier's mirror.properties, separating several central.from URLs with semicolons"
288
+ },
289
+ {
290
+ "kind": "env",
291
+ "command": "Point MAVEN_CENTRAL_URL at a mirror for cdxgen's own lookups"
292
+ },
293
+ {
294
+ "kind": "rerun"
295
+ }
296
+ ],
297
+ "verify": {
298
+ "rules": [],
299
+ "expectTier": null,
300
+ "eventsCleared": [
301
+ "build.rate-limited"
302
+ ]
303
+ },
304
+ "docs": "https://cyclonedx.github.io/cdxgen/#/ADVANCED"
305
+ },
266
306
  "js.no-lockfile": {
267
307
  "ecosystem": "npm",
268
308
  "kind": "evidence.degraded",
@@ -1187,5 +1227,26 @@
1187
1227
  ]
1188
1228
  },
1189
1229
  "docs": "https://cyclonedx.github.io/cdxgen/#/ENV"
1230
+ },
1231
+ "policy.rate-limited": {
1232
+ "ecosystem": "generic",
1233
+ "kind": "evidence.degraded",
1234
+ "impact": "licenses",
1235
+ "title": "A registry rate limited this run, so its metadata came from local caches only",
1236
+ "targetTier": null,
1237
+ "actions": [
1238
+ {
1239
+ "kind": "env",
1240
+ "command": "Point MAVEN_CENTRAL_URL at a mirror or repository manager, or wait for the block to expire, then re-run"
1241
+ }
1242
+ ],
1243
+ "verify": {
1244
+ "rules": [],
1245
+ "expectTier": null,
1246
+ "eventsCleared": [
1247
+ "policy.rate-limited"
1248
+ ]
1249
+ },
1250
+ "docs": "https://cyclonedx.github.io/cdxgen/#/ENV"
1190
1251
  }
1191
1252
  }