forked from CycloneDX/cdxgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcbomutils.js
39 lines (38 loc) · 1.19 KB
/
cbomutils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { readFileSync } from "node:fs";
import { convertOSQueryResults, dirNameStr } from "./utils.js";
import { executeOsQuery } from "./binary.js";
import { join } from "node:path";
const cbomosDbQueries = JSON.parse(
readFileSync(join(dirNameStr, "data", "cbomosdb-queries.json"), "utf-8")
);
/**
* Method to collect crypto and ssl libraries from the OS.
*
* @param {Object} options
* @returns osPkgsList Array of OS crypto packages
*/
export const collectOSCryptoLibs = (options) => {
let osPkgsList = [];
for (const queryCategory of Object.keys(cbomosDbQueries)) {
const queryObj = cbomosDbQueries[queryCategory];
const results = executeOsQuery(queryObj.query);
const dlist = convertOSQueryResults(
queryCategory,
queryObj,
results,
false
);
if (dlist && dlist.length) {
osPkgsList = osPkgsList.concat(dlist);
// Should we downgrade from cryptographic-asset to data for < 1.6 spec
if (options && options.specVersion && options.specVersion < 1.6) {
for (const apkg of osPkgsList) {
if (apkg.type === "cryptographic-asset") {
apkg.type = "data";
}
}
}
}
}
return osPkgsList;
};