@cyclonedx/cdxgen 12.1.5 → 12.2.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.
- package/README.md +51 -40
- package/bin/cdxgen.js +194 -97
- package/bin/evinse.js +4 -4
- package/bin/repl.js +1 -1
- package/bin/sign.js +102 -0
- package/bin/validate.js +233 -0
- package/bin/verify.js +69 -28
- package/data/queries.json +1 -1
- package/data/rules/ci-permissions.yaml +186 -0
- package/data/rules/dependency-sources.yaml +123 -0
- package/data/rules/package-integrity.yaml +135 -0
- package/data/rules/vscode-extensions.yaml +228 -0
- package/lib/cli/index.js +449 -429
- package/lib/cli/index.poku.js +117 -0
- package/lib/evinser/db.js +137 -0
- package/lib/{helpers → evinser}/db.poku.js +2 -6
- package/lib/evinser/evinser.js +2 -14
- package/lib/helpers/analyzer.js +606 -3
- package/lib/helpers/analyzer.poku.js +230 -0
- package/lib/helpers/bomSigner.js +312 -0
- package/lib/helpers/bomSigner.poku.js +156 -0
- package/lib/helpers/ciParsers/azurePipelines.js +295 -0
- package/lib/helpers/ciParsers/azurePipelines.poku.js +253 -0
- package/lib/helpers/ciParsers/circleCi.js +286 -0
- package/lib/helpers/ciParsers/circleCi.poku.js +230 -0
- package/lib/helpers/ciParsers/common.js +24 -0
- package/lib/helpers/ciParsers/githubActions.js +636 -0
- package/lib/helpers/ciParsers/githubActions.poku.js +802 -0
- package/lib/helpers/ciParsers/gitlabCi.js +213 -0
- package/lib/helpers/ciParsers/gitlabCi.poku.js +247 -0
- package/lib/helpers/ciParsers/jenkins.js +181 -0
- package/lib/helpers/ciParsers/jenkins.poku.js +197 -0
- package/lib/helpers/depsUtils.js +219 -0
- package/lib/helpers/depsUtils.poku.js +207 -0
- package/lib/helpers/display.js +426 -5
- package/lib/helpers/envcontext.js +18 -3
- package/lib/helpers/formulationParsers.js +351 -0
- package/lib/helpers/logger.js +14 -0
- package/lib/helpers/protobom.js +9 -9
- package/lib/helpers/pythonutils.js +9 -0
- package/lib/helpers/remote/dependency-track.js +84 -0
- package/lib/helpers/remote/dependency-track.poku.js +119 -0
- package/lib/helpers/table.js +384 -0
- package/lib/helpers/table.poku.js +186 -0
- package/lib/helpers/utils.js +865 -416
- package/lib/helpers/utils.poku.js +172 -265
- package/lib/helpers/versutils.js +202 -0
- package/lib/helpers/versutils.poku.js +315 -0
- package/lib/helpers/vsixutils.js +1061 -0
- package/lib/helpers/vsixutils.poku.js +2247 -0
- package/lib/managers/binary.js +19 -19
- package/lib/managers/docker.js +108 -1
- package/lib/managers/oci.js +10 -0
- package/lib/managers/piptree.js +3 -9
- package/lib/parsers/npmrc.js +17 -13
- package/lib/parsers/npmrc.poku.js +41 -5
- package/lib/server/openapi.yaml +34 -1
- package/lib/server/server.js +50 -13
- package/lib/server/server.poku.js +332 -144
- package/lib/stages/postgen/annotator.js +1 -1
- package/lib/stages/postgen/auditBom.js +196 -0
- package/lib/stages/postgen/auditBom.poku.js +378 -0
- package/lib/stages/postgen/postgen.js +54 -1
- package/lib/stages/postgen/postgen.poku.js +90 -1
- package/lib/stages/postgen/ruleEngine.js +369 -0
- package/lib/stages/pregen/envAudit.js +299 -0
- package/lib/stages/pregen/envAudit.poku.js +572 -0
- package/lib/stages/pregen/pregen.js +12 -8
- package/lib/{helpers/validator.js → validator/bomValidator.js} +107 -47
- package/lib/validator/complianceEngine.js +241 -0
- package/lib/validator/complianceEngine.poku.js +168 -0
- package/lib/validator/complianceRules.js +1610 -0
- package/lib/validator/complianceRules.poku.js +328 -0
- package/lib/validator/index.js +222 -0
- package/lib/validator/index.poku.js +144 -0
- package/lib/validator/reporters/annotations.js +121 -0
- package/lib/validator/reporters/console.js +149 -0
- package/lib/validator/reporters/index.js +41 -0
- package/lib/validator/reporters/json.js +37 -0
- package/lib/validator/reporters/sarif.js +184 -0
- package/lib/validator/reporters.poku.js +150 -0
- package/package.json +8 -9
- package/types/bin/sign.d.ts +3 -0
- package/types/bin/sign.d.ts.map +1 -0
- package/types/bin/validate.d.ts +3 -0
- package/types/bin/validate.d.ts.map +1 -0
- package/types/helpers/utils.d.ts +0 -1
- package/types/lib/cli/index.d.ts +49 -52
- package/types/lib/cli/index.d.ts.map +1 -1
- package/types/lib/evinser/db.d.ts +34 -0
- package/types/lib/evinser/db.d.ts.map +1 -0
- package/types/lib/evinser/evinser.d.ts +63 -16
- package/types/lib/evinser/evinser.d.ts.map +1 -1
- package/types/lib/helpers/analyzer.d.ts.map +1 -1
- package/types/lib/helpers/bomSigner.d.ts +27 -0
- package/types/lib/helpers/bomSigner.d.ts.map +1 -0
- package/types/lib/helpers/ciParsers/azurePipelines.d.ts +17 -0
- package/types/lib/helpers/ciParsers/azurePipelines.d.ts.map +1 -0
- package/types/lib/helpers/ciParsers/circleCi.d.ts +17 -0
- package/types/lib/helpers/ciParsers/circleCi.d.ts.map +1 -0
- package/types/lib/helpers/ciParsers/common.d.ts +11 -0
- package/types/lib/helpers/ciParsers/common.d.ts.map +1 -0
- package/types/lib/helpers/ciParsers/githubActions.d.ts +34 -0
- package/types/lib/helpers/ciParsers/githubActions.d.ts.map +1 -0
- package/types/lib/helpers/ciParsers/gitlabCi.d.ts +17 -0
- package/types/lib/helpers/ciParsers/gitlabCi.d.ts.map +1 -0
- package/types/lib/helpers/ciParsers/jenkins.d.ts +17 -0
- package/types/lib/helpers/ciParsers/jenkins.d.ts.map +1 -0
- package/types/lib/helpers/depsUtils.d.ts +21 -0
- package/types/lib/helpers/depsUtils.d.ts.map +1 -0
- package/types/lib/helpers/display.d.ts +111 -11
- package/types/lib/helpers/display.d.ts.map +1 -1
- package/types/lib/helpers/envcontext.d.ts +19 -7
- package/types/lib/helpers/envcontext.d.ts.map +1 -1
- package/types/lib/helpers/formulationParsers.d.ts +50 -0
- package/types/lib/helpers/formulationParsers.d.ts.map +1 -0
- package/types/lib/helpers/logger.d.ts +15 -1
- package/types/lib/helpers/logger.d.ts.map +1 -1
- package/types/lib/helpers/protobom.d.ts +2 -2
- package/types/lib/helpers/pythonutils.d.ts +10 -1
- package/types/lib/helpers/pythonutils.d.ts.map +1 -1
- package/types/lib/helpers/remote/dependency-track.d.ts +16 -0
- package/types/lib/helpers/remote/dependency-track.d.ts.map +1 -0
- package/types/lib/helpers/table.d.ts +6 -0
- package/types/lib/helpers/table.d.ts.map +1 -0
- package/types/lib/helpers/utils.d.ts +533 -128
- package/types/lib/helpers/utils.d.ts.map +1 -1
- package/types/lib/helpers/versutils.d.ts +8 -0
- package/types/lib/helpers/versutils.d.ts.map +1 -0
- package/types/lib/helpers/vsixutils.d.ts +130 -0
- package/types/lib/helpers/vsixutils.d.ts.map +1 -0
- package/types/lib/managers/docker.d.ts +12 -31
- package/types/lib/managers/docker.d.ts.map +1 -1
- package/types/lib/managers/oci.d.ts +11 -1
- package/types/lib/managers/oci.d.ts.map +1 -1
- package/types/lib/managers/piptree.d.ts.map +1 -1
- package/types/lib/parsers/npmrc.d.ts +4 -1
- package/types/lib/parsers/npmrc.d.ts.map +1 -1
- package/types/lib/server/server.d.ts +22 -2
- package/types/lib/server/server.d.ts.map +1 -1
- package/types/lib/stages/postgen/auditBom.d.ts +20 -0
- package/types/lib/stages/postgen/auditBom.d.ts.map +1 -0
- package/types/lib/stages/postgen/postgen.d.ts +8 -1
- package/types/lib/stages/postgen/postgen.d.ts.map +1 -1
- package/types/lib/stages/postgen/ruleEngine.d.ts +18 -0
- package/types/lib/stages/postgen/ruleEngine.d.ts.map +1 -0
- package/types/lib/stages/pregen/envAudit.d.ts +8 -0
- package/types/lib/stages/pregen/envAudit.d.ts.map +1 -0
- package/types/lib/stages/pregen/pregen.d.ts.map +1 -1
- package/types/lib/{helpers/validator.d.ts → validator/bomValidator.d.ts} +1 -1
- package/types/lib/validator/bomValidator.d.ts.map +1 -0
- package/types/lib/validator/complianceEngine.d.ts +66 -0
- package/types/lib/validator/complianceEngine.d.ts.map +1 -0
- package/types/lib/validator/complianceRules.d.ts +70 -0
- package/types/lib/validator/complianceRules.d.ts.map +1 -0
- package/types/lib/validator/index.d.ts +70 -0
- package/types/lib/validator/index.d.ts.map +1 -0
- package/types/lib/validator/reporters/annotations.d.ts +31 -0
- package/types/lib/validator/reporters/annotations.d.ts.map +1 -0
- package/types/lib/validator/reporters/console.d.ts +30 -0
- package/types/lib/validator/reporters/console.d.ts.map +1 -0
- package/types/lib/validator/reporters/index.d.ts +21 -0
- package/types/lib/validator/reporters/index.d.ts.map +1 -0
- package/types/lib/validator/reporters/json.d.ts +11 -0
- package/types/lib/validator/reporters/json.d.ts.map +1 -0
- package/types/lib/validator/reporters/sarif.d.ts +16 -0
- package/types/lib/validator/reporters/sarif.d.ts.map +1 -0
- package/lib/helpers/db.js +0 -162
- package/lib/stages/pregen/env-audit.js +0 -34
- package/lib/stages/pregen/env-audit.poku.js +0 -290
- package/types/helpers/db.d.ts +0 -35
- package/types/helpers/db.d.ts.map +0 -1
- package/types/lib/helpers/db.d.ts +0 -35
- package/types/lib/helpers/db.d.ts.map +0 -1
- package/types/lib/helpers/validator.d.ts.map +0 -1
- package/types/lib/stages/pregen/env-audit.d.ts +0 -2
- package/types/lib/stages/pregen/env-audit.d.ts.map +0 -1
- package/types/managers/binary.d.ts +0 -37
- package/types/managers/binary.d.ts.map +0 -1
- package/types/managers/docker.d.ts +0 -56
- package/types/managers/docker.d.ts.map +0 -1
- package/types/managers/oci.d.ts +0 -2
- package/types/managers/oci.d.ts.map +0 -1
- package/types/managers/piptree.d.ts +0 -2
- package/types/managers/piptree.d.ts.map +0 -1
- package/types/server/server.d.ts +0 -34
- package/types/server/server.d.ts.map +0 -1
- package/types/stages/postgen/annotator.d.ts +0 -27
- package/types/stages/postgen/annotator.d.ts.map +0 -1
- package/types/stages/postgen/postgen.d.ts +0 -51
- package/types/stages/postgen/postgen.d.ts.map +0 -1
- package/types/stages/pregen/pregen.d.ts +0 -59
- package/types/stages/pregen/pregen.d.ts.map +0 -1
package/bin/evinse.js
CHANGED
|
@@ -17,8 +17,7 @@ import {
|
|
|
17
17
|
printReachables,
|
|
18
18
|
printServices,
|
|
19
19
|
} from "../lib/helpers/display.js";
|
|
20
|
-
import {
|
|
21
|
-
import { validateBom } from "../lib/helpers/validator.js";
|
|
20
|
+
import { validateBom } from "../lib/validator/bomValidator.js";
|
|
22
21
|
|
|
23
22
|
const args = yargs(hideBin(process.argv))
|
|
24
23
|
.env("EVINSE")
|
|
@@ -56,8 +55,9 @@ const args = yargs(hideBin(process.argv))
|
|
|
56
55
|
],
|
|
57
56
|
})
|
|
58
57
|
.option("db-path", {
|
|
59
|
-
description:
|
|
60
|
-
default:
|
|
58
|
+
description: "Atom slices DB path. Unused",
|
|
59
|
+
default: undefined,
|
|
60
|
+
hidden: true,
|
|
61
61
|
})
|
|
62
62
|
.option("force", {
|
|
63
63
|
description: "Force creation of the database",
|
package/bin/repl.js
CHANGED
|
@@ -22,8 +22,8 @@ import {
|
|
|
22
22
|
} from "../lib/helpers/display.js";
|
|
23
23
|
import { readBinary } from "../lib/helpers/protobom.js";
|
|
24
24
|
import { getTmpDir } from "../lib/helpers/utils.js";
|
|
25
|
-
import { validateBom } from "../lib/helpers/validator.js";
|
|
26
25
|
import { getBomWithOras } from "../lib/managers/oci.js";
|
|
26
|
+
import { validateBom } from "../lib/validator/bomValidator.js";
|
|
27
27
|
|
|
28
28
|
const options = {
|
|
29
29
|
useColors: true,
|
package/bin/sign.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
|
|
6
|
+
import yargs from "yargs";
|
|
7
|
+
import { hideBin } from "yargs/helpers";
|
|
8
|
+
|
|
9
|
+
import { signBom } from "../lib/helpers/bomSigner.js";
|
|
10
|
+
import { retrieveCdxgenVersion, safeExistsSync } from "../lib/helpers/utils.js";
|
|
11
|
+
|
|
12
|
+
const _yargs = yargs(hideBin(process.argv));
|
|
13
|
+
|
|
14
|
+
const args = _yargs
|
|
15
|
+
.option("input", {
|
|
16
|
+
alias: "i",
|
|
17
|
+
default: "bom.json",
|
|
18
|
+
description: "Input SBOM json to sign.",
|
|
19
|
+
})
|
|
20
|
+
.option("output", {
|
|
21
|
+
alias: "o",
|
|
22
|
+
description: "Output signed SBOM json. Defaults to overwriting input.",
|
|
23
|
+
})
|
|
24
|
+
.option("private-key", {
|
|
25
|
+
alias: "k",
|
|
26
|
+
demandOption: true,
|
|
27
|
+
description: "Private key in PEM format.",
|
|
28
|
+
})
|
|
29
|
+
.option("algorithm", {
|
|
30
|
+
alias: "a",
|
|
31
|
+
default: "RS512",
|
|
32
|
+
description: "JSF Signature Algorithm (e.g., RS512, ES256, Ed25519).",
|
|
33
|
+
})
|
|
34
|
+
.option("mode", {
|
|
35
|
+
alias: "m",
|
|
36
|
+
default: "replace",
|
|
37
|
+
choices: ["replace", "signers", "chain"],
|
|
38
|
+
description:
|
|
39
|
+
"Signature mode. Use 'signers' for multi-signing, 'chain' for sequential chaining.",
|
|
40
|
+
})
|
|
41
|
+
.option("key-id", {
|
|
42
|
+
description:
|
|
43
|
+
"Optional identifier for the key (keyId) to embed in the signature block.",
|
|
44
|
+
})
|
|
45
|
+
.option("sign-components", {
|
|
46
|
+
type: "boolean",
|
|
47
|
+
default: true,
|
|
48
|
+
description:
|
|
49
|
+
"Sign granular components. Disable (--no-sign-components) when appending multi-signatures.",
|
|
50
|
+
})
|
|
51
|
+
.option("sign-services", {
|
|
52
|
+
type: "boolean",
|
|
53
|
+
default: true,
|
|
54
|
+
description:
|
|
55
|
+
"Sign granular services. Disable (--no-sign-services) when appending multi-signatures.",
|
|
56
|
+
})
|
|
57
|
+
.option("sign-annotations", {
|
|
58
|
+
type: "boolean",
|
|
59
|
+
default: true,
|
|
60
|
+
description:
|
|
61
|
+
"Sign granular annotations. Disable (--no-sign-annotations) when appending multi-signatures.",
|
|
62
|
+
})
|
|
63
|
+
.scriptName("cdx-sign")
|
|
64
|
+
.version(retrieveCdxgenVersion())
|
|
65
|
+
.help()
|
|
66
|
+
.wrap(Math.min(120, yargs().terminalWidth())).argv;
|
|
67
|
+
|
|
68
|
+
if (!safeExistsSync(args.input)) {
|
|
69
|
+
console.error(`Input file '${args.input}' not found.`);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!safeExistsSync(args.privateKey)) {
|
|
74
|
+
console.error(`Private key file '${args.privateKey}' not found.`);
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const bomJson = JSON.parse(fs.readFileSync(args.input, "utf8"));
|
|
80
|
+
const privateKey = fs.readFileSync(args.privateKey, "utf8");
|
|
81
|
+
|
|
82
|
+
const signedBom = signBom(bomJson, {
|
|
83
|
+
privateKey,
|
|
84
|
+
algorithm: args.algorithm,
|
|
85
|
+
keyId: args.keyId,
|
|
86
|
+
mode: args.mode,
|
|
87
|
+
signComponents: args.signComponents,
|
|
88
|
+
signServices: args.signServices,
|
|
89
|
+
signAnnotations: args.signAnnotations,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const outputPath = args.output || args.input;
|
|
93
|
+
fs.writeFileSync(outputPath, JSON.stringify(signedBom, null, null));
|
|
94
|
+
|
|
95
|
+
console.log(`Successfully signed BOM and saved to '${outputPath}'`);
|
|
96
|
+
console.log(
|
|
97
|
+
`Mode: ${args.mode} | Algorithm: ${args.algorithm}${args.keyId ? ` | KeyId: ${args.keyId}` : ""}`,
|
|
98
|
+
);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error("SBOM signing failed:", error.message);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
package/bin/validate.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* cdx-validate CLI — structural, deep, and compliance validation for
|
|
5
|
+
* CycloneDX SBOMs.
|
|
6
|
+
*
|
|
7
|
+
* Exit codes:
|
|
8
|
+
* 0 — all checks pass (or no findings >= --fail-severity).
|
|
9
|
+
* 1 — configuration error (bad input, missing file, unknown reporter).
|
|
10
|
+
* 2 — schema validation failed (in --strict mode).
|
|
11
|
+
* 3 — compliance findings at or above --fail-severity.
|
|
12
|
+
* 4 — signature verification was requested and failed.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import fs from "node:fs";
|
|
16
|
+
import { dirname, join } from "node:path";
|
|
17
|
+
import process from "node:process";
|
|
18
|
+
|
|
19
|
+
import yargs from "yargs";
|
|
20
|
+
import { hideBin } from "yargs/helpers";
|
|
21
|
+
|
|
22
|
+
import {
|
|
23
|
+
dirNameStr,
|
|
24
|
+
retrieveCdxgenVersion,
|
|
25
|
+
safeExistsSync,
|
|
26
|
+
safeMkdirSync,
|
|
27
|
+
} from "../lib/helpers/utils.js";
|
|
28
|
+
import { getBomWithOras } from "../lib/managers/oci.js";
|
|
29
|
+
import { shouldFail, validateBomAdvanced } from "../lib/validator/index.js";
|
|
30
|
+
import { render as renderReport } from "../lib/validator/reporters/index.js";
|
|
31
|
+
|
|
32
|
+
const _yargs = yargs(hideBin(process.argv));
|
|
33
|
+
|
|
34
|
+
const args = _yargs
|
|
35
|
+
.option("input", {
|
|
36
|
+
alias: "i",
|
|
37
|
+
default: "bom.json",
|
|
38
|
+
description: "Input SBOM JSON file or OCI reference.",
|
|
39
|
+
})
|
|
40
|
+
.option("platform", {
|
|
41
|
+
description:
|
|
42
|
+
"Platform to use when resolving an OCI reference (passed to oras).",
|
|
43
|
+
})
|
|
44
|
+
.option("report", {
|
|
45
|
+
alias: "r",
|
|
46
|
+
default: "console",
|
|
47
|
+
choices: ["console", "json", "sarif", "annotations"],
|
|
48
|
+
description: "Output format.",
|
|
49
|
+
})
|
|
50
|
+
.option("report-file", {
|
|
51
|
+
alias: "o",
|
|
52
|
+
description:
|
|
53
|
+
"Write the report to this file. Defaults to stdout. Required for the 'annotations' reporter when you want to save the annotated BOM.",
|
|
54
|
+
})
|
|
55
|
+
.option("schema", {
|
|
56
|
+
type: "boolean",
|
|
57
|
+
default: true,
|
|
58
|
+
description:
|
|
59
|
+
"Run the CycloneDX JSON-schema validation. Pass --no-schema to skip.",
|
|
60
|
+
})
|
|
61
|
+
.option("deep", {
|
|
62
|
+
type: "boolean",
|
|
63
|
+
default: true,
|
|
64
|
+
description:
|
|
65
|
+
"Run the deep purl/ref/metadata checks from lib/helpers/bomValidator.js. Pass --no-deep to skip.",
|
|
66
|
+
})
|
|
67
|
+
.option("benchmark", {
|
|
68
|
+
alias: "b",
|
|
69
|
+
type: "string",
|
|
70
|
+
description:
|
|
71
|
+
"Comma-separated list of compliance benchmark aliases to include in the scorecards (scvs, scvs-l1, scvs-l2, scvs-l3, cra). Defaults to all.",
|
|
72
|
+
})
|
|
73
|
+
.option("categories", {
|
|
74
|
+
type: "string",
|
|
75
|
+
description:
|
|
76
|
+
"Comma-separated list of compliance rule categories to evaluate (compliance-scvs, compliance-cra). Defaults to all.",
|
|
77
|
+
})
|
|
78
|
+
.option("min-severity", {
|
|
79
|
+
type: "string",
|
|
80
|
+
default: "info",
|
|
81
|
+
choices: ["info", "low", "medium", "high", "critical"],
|
|
82
|
+
description:
|
|
83
|
+
"Drop findings below this severity from the output (benchmark scoring is unaffected).",
|
|
84
|
+
})
|
|
85
|
+
.option("fail-severity", {
|
|
86
|
+
type: "string",
|
|
87
|
+
default: "high",
|
|
88
|
+
choices: ["info", "low", "medium", "high", "critical"],
|
|
89
|
+
description:
|
|
90
|
+
"Exit with code 3 when any failing finding is at or above this severity.",
|
|
91
|
+
})
|
|
92
|
+
.option("include-manual", {
|
|
93
|
+
type: "boolean",
|
|
94
|
+
default: true,
|
|
95
|
+
description:
|
|
96
|
+
"Include non-automatable manual-review findings in the output. Pass --no-include-manual to hide them.",
|
|
97
|
+
})
|
|
98
|
+
.option("include-pass", {
|
|
99
|
+
type: "boolean",
|
|
100
|
+
default: false,
|
|
101
|
+
description:
|
|
102
|
+
"Include passing findings in the output (useful for audits). Defaults to false.",
|
|
103
|
+
})
|
|
104
|
+
.option("public-key", {
|
|
105
|
+
description:
|
|
106
|
+
"Path to a PEM public key. When set, cdx-validate also verifies the BOM signature.",
|
|
107
|
+
})
|
|
108
|
+
.option("require-signature", {
|
|
109
|
+
type: "boolean",
|
|
110
|
+
default: false,
|
|
111
|
+
description:
|
|
112
|
+
"Exit non-zero (4) when --public-key is provided but signature verification fails.",
|
|
113
|
+
})
|
|
114
|
+
.option("strict", {
|
|
115
|
+
type: "boolean",
|
|
116
|
+
default: false,
|
|
117
|
+
description:
|
|
118
|
+
"Treat a failing schema or deep validation as a non-zero exit (code 2).",
|
|
119
|
+
})
|
|
120
|
+
.completion("completion", "Generate bash/zsh completion")
|
|
121
|
+
.epilogue("for documentation, visit https://cdxgen.github.io/cdxgen")
|
|
122
|
+
.scriptName("cdx-validate")
|
|
123
|
+
.version(retrieveCdxgenVersion())
|
|
124
|
+
.help()
|
|
125
|
+
.wrap(Math.min(120, yargs().terminalWidth())).argv;
|
|
126
|
+
|
|
127
|
+
function loadBom(input, platform) {
|
|
128
|
+
if (safeExistsSync(input)) {
|
|
129
|
+
try {
|
|
130
|
+
return JSON.parse(fs.readFileSync(input, "utf8"));
|
|
131
|
+
} catch (err) {
|
|
132
|
+
console.error(`Failed to parse ${input}: ${err.message}`);
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (
|
|
137
|
+
input.includes(":") ||
|
|
138
|
+
input.includes("docker") ||
|
|
139
|
+
input.includes("ghcr")
|
|
140
|
+
) {
|
|
141
|
+
const bom = getBomWithOras(input, platform);
|
|
142
|
+
if (bom) return bom;
|
|
143
|
+
}
|
|
144
|
+
console.error(`Input '${input}' is not a readable SBOM.`);
|
|
145
|
+
process.exit(1);
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function loadPublicKey(path) {
|
|
150
|
+
if (!path) return null;
|
|
151
|
+
if (!safeExistsSync(path)) {
|
|
152
|
+
console.error(`Public key '${path}' not found.`);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
return fs.readFileSync(path, "utf8");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function splitCsv(value) {
|
|
159
|
+
if (!value) return undefined;
|
|
160
|
+
return value
|
|
161
|
+
.split(",")
|
|
162
|
+
.map((v) => v.trim())
|
|
163
|
+
.filter(Boolean);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function writeOrPrint(content, outputPath) {
|
|
167
|
+
if (!outputPath) {
|
|
168
|
+
process.stdout.write(`${content}\n`);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const parent = dirname(outputPath);
|
|
172
|
+
if (parent && !safeExistsSync(parent)) {
|
|
173
|
+
safeMkdirSync(parent, { recursive: true });
|
|
174
|
+
}
|
|
175
|
+
fs.writeFileSync(outputPath, content);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const bomJson = loadBom(args.input, args.platform);
|
|
179
|
+
const publicKeyStr = loadPublicKey(args.publicKey);
|
|
180
|
+
|
|
181
|
+
const report = validateBomAdvanced(bomJson, {
|
|
182
|
+
schema: args.schema,
|
|
183
|
+
deep: args.deep,
|
|
184
|
+
benchmarks: splitCsv(args.benchmark),
|
|
185
|
+
categories: splitCsv(args.categories),
|
|
186
|
+
minSeverity: args.minSeverity,
|
|
187
|
+
includeManual: args.includeManual,
|
|
188
|
+
includePass: args.includePass,
|
|
189
|
+
publicKey: publicKeyStr || undefined,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
let output;
|
|
193
|
+
try {
|
|
194
|
+
const { version: pkgVersion } = JSON.parse(
|
|
195
|
+
fs.readFileSync(join(dirNameStr, "package.json"), "utf8"),
|
|
196
|
+
);
|
|
197
|
+
output = renderReport(args.report, report, {
|
|
198
|
+
bomJson,
|
|
199
|
+
toolName: "cdx-validate",
|
|
200
|
+
toolVersion: pkgVersion,
|
|
201
|
+
pretty: true,
|
|
202
|
+
});
|
|
203
|
+
} catch (err) {
|
|
204
|
+
console.error(err.message);
|
|
205
|
+
process.exit(1);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
writeOrPrint(output, args.reportFile);
|
|
209
|
+
|
|
210
|
+
const { shouldFail: fail, reason } = shouldFail(report, {
|
|
211
|
+
failSeverity: args.failSeverity,
|
|
212
|
+
strict: args.strict,
|
|
213
|
+
requireSignature: Boolean(args.requireSignature && publicKeyStr),
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
if (report.signatureVerified === false && args.requireSignature) {
|
|
217
|
+
console.error(
|
|
218
|
+
`cdx-validate: signature verification failed — ${report.signatureDetails?.error || "no matching key"}.`,
|
|
219
|
+
);
|
|
220
|
+
process.exit(4);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (args.strict && report.schemaValid === false) {
|
|
224
|
+
console.error("cdx-validate: schema validation failed.");
|
|
225
|
+
process.exit(2);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (fail) {
|
|
229
|
+
console.error(`cdx-validate: ${reason}`);
|
|
230
|
+
process.exit(3);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
process.exit(0);
|
package/bin/verify.js
CHANGED
|
@@ -4,10 +4,10 @@ import fs from "node:fs";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
|
|
7
|
-
import jws from "jws";
|
|
8
7
|
import yargs from "yargs";
|
|
9
8
|
import { hideBin } from "yargs/helpers";
|
|
10
9
|
|
|
10
|
+
import { verifyNode } from "../lib/helpers/bomSigner.js";
|
|
11
11
|
import {
|
|
12
12
|
dirNameStr,
|
|
13
13
|
retrieveCdxgenVersion,
|
|
@@ -32,6 +32,12 @@ const args = _yargs
|
|
|
32
32
|
default: "public.key",
|
|
33
33
|
description: "Public key in PEM format. Default public.key",
|
|
34
34
|
})
|
|
35
|
+
.option("deep", {
|
|
36
|
+
type: "boolean",
|
|
37
|
+
default: true,
|
|
38
|
+
description:
|
|
39
|
+
"Strictly verify all nested component, service, and annotation signatures against the provided public key. Pass --no-deep to verify only the root signature.",
|
|
40
|
+
})
|
|
35
41
|
.completion("completion", "Generate bash/zsh completion")
|
|
36
42
|
.epilogue("for documentation, visit https://cdxgen.github.io/cdxgen")
|
|
37
43
|
.scriptName("cdx-verify")
|
|
@@ -78,49 +84,84 @@ function getBom(args) {
|
|
|
78
84
|
}
|
|
79
85
|
return undefined;
|
|
80
86
|
}
|
|
87
|
+
|
|
81
88
|
const bomJson = getBom(args);
|
|
89
|
+
|
|
82
90
|
if (!bomJson) {
|
|
83
91
|
console.log(`${args.input} is invalid!`);
|
|
84
92
|
process.exit(1);
|
|
85
93
|
}
|
|
94
|
+
|
|
86
95
|
if (bomJson && !safeExistsSync(args.publicKey)) {
|
|
87
96
|
console.log("Public key for signature verification is missing!");
|
|
88
97
|
process.exit(1);
|
|
89
98
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
|
|
100
|
+
const publicKeyStr = fs.readFileSync(args.publicKey, "utf8");
|
|
101
|
+
|
|
102
|
+
let rootMatch = null;
|
|
103
|
+
if (bomJson.signature) {
|
|
104
|
+
rootMatch = verifyNode(bomJson, publicKeyStr);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const verifyNested = args.deep || !bomJson.signature;
|
|
108
|
+
let hasInvalidNested = false;
|
|
109
|
+
let checkedNested = 0;
|
|
110
|
+
|
|
111
|
+
if (verifyNested) {
|
|
112
|
+
for (const comp of bomJson.components || []) {
|
|
113
|
+
if (comp.signature) {
|
|
114
|
+
checkedNested++;
|
|
115
|
+
if (!verifyNode(comp, publicKeyStr)) {
|
|
116
|
+
console.log(
|
|
117
|
+
`Component '${comp["bom-ref"] || comp.name}' signature is invalid!`,
|
|
118
|
+
);
|
|
119
|
+
hasInvalidNested = true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
for (const svc of bomJson.services || []) {
|
|
124
|
+
if (svc.signature) {
|
|
125
|
+
checkedNested++;
|
|
126
|
+
if (!verifyNode(svc, publicKeyStr)) {
|
|
127
|
+
console.log(
|
|
128
|
+
`Service '${svc["bom-ref"] || svc.name}' signature is invalid!`,
|
|
129
|
+
);
|
|
130
|
+
hasInvalidNested = true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (const ann of bomJson.annotations || []) {
|
|
135
|
+
if (ann.signature) {
|
|
136
|
+
checkedNested++;
|
|
137
|
+
if (!verifyNode(ann, publicKeyStr)) {
|
|
138
|
+
console.log(
|
|
139
|
+
`Annotation '${ann["bom-ref"] || ann.subject}' signature is invalid!`,
|
|
140
|
+
);
|
|
141
|
+
hasInvalidNested = true;
|
|
142
|
+
}
|
|
103
143
|
}
|
|
104
144
|
}
|
|
105
145
|
}
|
|
106
|
-
|
|
146
|
+
|
|
147
|
+
if (hasInvalidNested) {
|
|
148
|
+
console.log("One or more nested signatures are invalid!");
|
|
107
149
|
process.exit(1);
|
|
108
150
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
bomSignature,
|
|
117
|
-
bomJson.signature.algorithm,
|
|
118
|
-
fs.readFileSync(args.publicKey, "utf8"),
|
|
119
|
-
);
|
|
120
|
-
if (validationResult) {
|
|
121
|
-
console.log("Signature is valid!");
|
|
151
|
+
|
|
152
|
+
if (bomJson.signature) {
|
|
153
|
+
if (rootMatch) {
|
|
154
|
+
const identifier = rootMatch.keyId
|
|
155
|
+
? `KeyId: '${rootMatch.keyId}'`
|
|
156
|
+
: `Algorithm: '${rootMatch.algorithm}'`;
|
|
157
|
+
console.log(`✓ Signature is valid! (Matched ${identifier})`);
|
|
122
158
|
} else {
|
|
123
159
|
console.log("BOM signature is invalid!");
|
|
124
160
|
process.exit(1);
|
|
125
161
|
}
|
|
162
|
+
} else if (checkedNested > 0 && !hasInvalidNested) {
|
|
163
|
+
console.log(`✓ ${checkedNested} nested signature(s) are valid!`);
|
|
164
|
+
} else {
|
|
165
|
+
console.log("No valid signatures found to verify!");
|
|
166
|
+
process.exit(1);
|
|
126
167
|
}
|
package/data/queries.json
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"vscode_extensions": {
|
|
28
28
|
"query": "select vscode_extensions.* from users join vscode_extensions using (uid);",
|
|
29
29
|
"description": "Lists all vscode extensions.",
|
|
30
|
-
"purlType": "
|
|
30
|
+
"purlType": "vscode-extension",
|
|
31
31
|
"componentType": "application"
|
|
32
32
|
},
|
|
33
33
|
"deb_packages": {
|