@hardkeel/quantum-scan 0.2.0 → 0.3.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.
- package/CHANGELOG.md +18 -0
- package/LICENSE +202 -202
- package/README.md +162 -151
- package/action.yml +44 -44
- package/dist/badge.js +60 -60
- package/dist/cbom.js +59 -59
- package/dist/cli.js +305 -305
- package/dist/community-rules.js +30 -30
- package/dist/community.js +28 -28
- package/dist/ignore.js +75 -75
- package/dist/infra.js +557 -557
- package/dist/map-activity.js +22 -22
- package/dist/map-areas.js +50 -41
- package/dist/map-cloud-keys.js +108 -0
- package/dist/map-host.js +333 -333
- package/dist/map-network.js +518 -0
- package/dist/map-people.js +77 -0
- package/dist/map-rank.js +48 -48
- package/dist/map-report.js +178 -138
- package/dist/map-run.js +271 -205
- package/dist/map-types.js +16 -16
- package/dist/map-web.js +640 -640
- package/dist/pqc.js +32 -32
- package/dist/report.js +179 -179
- package/dist/rules.js +135 -133
- package/dist/sarif.js +43 -43
- package/dist/scan.js +220 -214
- package/dist/score.js +122 -122
- package/dist/secrets.js +108 -97
- package/dist/share-config.js +111 -111
- package/dist/share.js +114 -112
- package/dist/types.js +2 -2
- package/dist/walk.js +63 -63
- package/package.json +53 -52
package/dist/share-config.js
CHANGED
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
// Local settings for the command-line version: the random install ID, whether anonymized sharing is on,
|
|
2
|
-
// offline mode, the optional industry and size, and what the last run would have sent.
|
|
3
|
-
// Kept in one JSON file in the user's settings folder. Nothing here leaves the machine except
|
|
4
|
-
// through share.ts, and only the fields that file builds.
|
|
5
|
-
import { createHash, randomBytes } from "node:crypto";
|
|
6
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
7
|
-
import { homedir } from "node:os";
|
|
8
|
-
import { dirname, join, resolve } from "node:path";
|
|
9
|
-
export const INDUSTRIES = [
|
|
10
|
-
"finance",
|
|
11
|
-
"healthcare",
|
|
12
|
-
"government",
|
|
13
|
-
"defense",
|
|
14
|
-
"technology",
|
|
15
|
-
"telecom",
|
|
16
|
-
"energy-utilities",
|
|
17
|
-
"manufacturing",
|
|
18
|
-
"retail",
|
|
19
|
-
"education",
|
|
20
|
-
"professional-services",
|
|
21
|
-
"other",
|
|
22
|
-
];
|
|
23
|
-
export const SIZES = ["1-50", "51-250", "251-1000", "1000+"];
|
|
24
|
-
export function settingsPath(env = process.env, platform = process.platform) {
|
|
25
|
-
if (env.QUANTUM_SCAN_CONFIG)
|
|
26
|
-
return resolve(env.QUANTUM_SCAN_CONFIG);
|
|
27
|
-
if (platform === "win32" && env.APPDATA)
|
|
28
|
-
return join(env.APPDATA, "Hard Keel", "quantum-scan.json");
|
|
29
|
-
if (platform === "darwin")
|
|
30
|
-
return join(homedir(), "Library", "Application Support", "Hard Keel", "quantum-scan.json");
|
|
31
|
-
return join(env.XDG_CONFIG_HOME || join(homedir(), ".config"), "hardkeel", "quantum-scan.json");
|
|
32
|
-
}
|
|
33
|
-
function fresh() {
|
|
34
|
-
return {
|
|
35
|
-
id: randomBytes(16).toString("hex"),
|
|
36
|
-
sharing: "on",
|
|
37
|
-
offline: false,
|
|
38
|
-
noticeShown: false,
|
|
39
|
-
ownershipToken: randomBytes(12).toString("hex"),
|
|
40
|
-
state: {},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
export function loadSettings(path = settingsPath()) {
|
|
44
|
-
const base = fresh();
|
|
45
|
-
if (!existsSync(path))
|
|
46
|
-
return base;
|
|
47
|
-
try {
|
|
48
|
-
const raw = JSON.parse(readFileSync(path, "utf8"));
|
|
49
|
-
return {
|
|
50
|
-
...base,
|
|
51
|
-
...raw,
|
|
52
|
-
id: typeof raw.id === "string" && /^[a-f0-9]{32}$/.test(raw.id) ? raw.id : base.id,
|
|
53
|
-
ownershipToken: typeof raw.ownershipToken === "string" && /^[a-f0-9]{24}$/.test(raw.ownershipToken) ? raw.ownershipToken : base.ownershipToken,
|
|
54
|
-
industry: INDUSTRIES.includes(raw.industry) ? raw.industry : undefined,
|
|
55
|
-
size: SIZES.includes(raw.size) ? raw.size : undefined,
|
|
56
|
-
state: raw.state && typeof raw.state === "object" ? raw.state : {},
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
return base;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/** Saves settings. Never throws: a read-only home folder must not break a scan. */
|
|
64
|
-
export function saveSettings(s, path = settingsPath()) {
|
|
65
|
-
try {
|
|
66
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
67
|
-
const tmp = `${path}.${process.pid}.tmp`;
|
|
68
|
-
writeFileSync(tmp, JSON.stringify(s, null, 2) + "\n", { mode: 0o600 });
|
|
69
|
-
renameSync(tmp, path);
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
// ignore
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
export function folderKey(folder) {
|
|
76
|
-
return createHash("sha256").update(resolve(folder)).digest("hex").slice(0, 16);
|
|
77
|
-
}
|
|
78
|
-
/** Whether this run may send its summary, and why not. */
|
|
79
|
-
export function sharingState(s, opts, env = process.env) {
|
|
80
|
-
if (opts.offline || s.offline || /^(1|true|yes|on)$/i.test(env.QUANTUM_SCAN_OFFLINE ?? ""))
|
|
81
|
-
return "offline";
|
|
82
|
-
if (/^(0|false|no|off)$/i.test(env.QUANTUM_SCAN_SHARING ?? ""))
|
|
83
|
-
return "env-off";
|
|
84
|
-
if (env.DO_NOT_TRACK && env.DO_NOT_TRACK !== "0")
|
|
85
|
-
return "do-not-track";
|
|
86
|
-
return s.sharing === "off" ? "off" : "on";
|
|
87
|
-
}
|
|
88
|
-
export const NOTICE = `Hard Keel Quantum Scan collects anonymized, aggregated information about how its
|
|
89
|
-
checks perform and what kinds of encryption they find. It never includes your code,
|
|
90
|
-
keys, server names, IP addresses or company name. We use it to improve and build our
|
|
91
|
-
products and to understand encryption trends across the industry.
|
|
92
|
-
|
|
93
|
-
See what's sent: quantum-scan config show-shared
|
|
94
|
-
Turn it off: quantum-scan config sharing off (or QUANTUM_SCAN_SHARING=off)
|
|
95
|
-
Send nothing at all: --offline (or QUANTUM_SCAN_OFFLINE=1)
|
|
96
|
-
Details: https://hardkeel.com/privacy/
|
|
97
|
-
`;
|
|
98
|
-
/**
|
|
99
|
-
* Prints the notice the first time, before anything is sent. In automated pipelines,
|
|
100
|
-
* where settings may not survive between runs, it prints every run, at the top of the log.
|
|
101
|
-
*/
|
|
102
|
-
export function showNoticeIfNeeded(s, state, env = process.env, write = (t) => process.stderr.write(t)) {
|
|
103
|
-
if (state !== "on")
|
|
104
|
-
return false;
|
|
105
|
-
const ci = Boolean(env.CI || env.GITHUB_ACTIONS);
|
|
106
|
-
if (s.noticeShown && !ci)
|
|
107
|
-
return false;
|
|
108
|
-
write(`\n${NOTICE}\n`);
|
|
109
|
-
s.noticeShown = true;
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
1
|
+
// Local settings for the command-line version: the random install ID, whether anonymized sharing is on,
|
|
2
|
+
// offline mode, the optional industry and size, and what the last run would have sent.
|
|
3
|
+
// Kept in one JSON file in the user's settings folder. Nothing here leaves the machine except
|
|
4
|
+
// through share.ts, and only the fields that file builds.
|
|
5
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import { dirname, join, resolve } from "node:path";
|
|
9
|
+
export const INDUSTRIES = [
|
|
10
|
+
"finance",
|
|
11
|
+
"healthcare",
|
|
12
|
+
"government",
|
|
13
|
+
"defense",
|
|
14
|
+
"technology",
|
|
15
|
+
"telecom",
|
|
16
|
+
"energy-utilities",
|
|
17
|
+
"manufacturing",
|
|
18
|
+
"retail",
|
|
19
|
+
"education",
|
|
20
|
+
"professional-services",
|
|
21
|
+
"other",
|
|
22
|
+
];
|
|
23
|
+
export const SIZES = ["1-50", "51-250", "251-1000", "1000+"];
|
|
24
|
+
export function settingsPath(env = process.env, platform = process.platform) {
|
|
25
|
+
if (env.QUANTUM_SCAN_CONFIG)
|
|
26
|
+
return resolve(env.QUANTUM_SCAN_CONFIG);
|
|
27
|
+
if (platform === "win32" && env.APPDATA)
|
|
28
|
+
return join(env.APPDATA, "Hard Keel", "quantum-scan.json");
|
|
29
|
+
if (platform === "darwin")
|
|
30
|
+
return join(homedir(), "Library", "Application Support", "Hard Keel", "quantum-scan.json");
|
|
31
|
+
return join(env.XDG_CONFIG_HOME || join(homedir(), ".config"), "hardkeel", "quantum-scan.json");
|
|
32
|
+
}
|
|
33
|
+
function fresh() {
|
|
34
|
+
return {
|
|
35
|
+
id: randomBytes(16).toString("hex"),
|
|
36
|
+
sharing: "on",
|
|
37
|
+
offline: false,
|
|
38
|
+
noticeShown: false,
|
|
39
|
+
ownershipToken: randomBytes(12).toString("hex"),
|
|
40
|
+
state: {},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function loadSettings(path = settingsPath()) {
|
|
44
|
+
const base = fresh();
|
|
45
|
+
if (!existsSync(path))
|
|
46
|
+
return base;
|
|
47
|
+
try {
|
|
48
|
+
const raw = JSON.parse(readFileSync(path, "utf8"));
|
|
49
|
+
return {
|
|
50
|
+
...base,
|
|
51
|
+
...raw,
|
|
52
|
+
id: typeof raw.id === "string" && /^[a-f0-9]{32}$/.test(raw.id) ? raw.id : base.id,
|
|
53
|
+
ownershipToken: typeof raw.ownershipToken === "string" && /^[a-f0-9]{24}$/.test(raw.ownershipToken) ? raw.ownershipToken : base.ownershipToken,
|
|
54
|
+
industry: INDUSTRIES.includes(raw.industry) ? raw.industry : undefined,
|
|
55
|
+
size: SIZES.includes(raw.size) ? raw.size : undefined,
|
|
56
|
+
state: raw.state && typeof raw.state === "object" ? raw.state : {},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return base;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Saves settings. Never throws: a read-only home folder must not break a scan. */
|
|
64
|
+
export function saveSettings(s, path = settingsPath()) {
|
|
65
|
+
try {
|
|
66
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
67
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
68
|
+
writeFileSync(tmp, JSON.stringify(s, null, 2) + "\n", { mode: 0o600 });
|
|
69
|
+
renameSync(tmp, path);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// ignore
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function folderKey(folder) {
|
|
76
|
+
return createHash("sha256").update(resolve(folder)).digest("hex").slice(0, 16);
|
|
77
|
+
}
|
|
78
|
+
/** Whether this run may send its summary, and why not. */
|
|
79
|
+
export function sharingState(s, opts, env = process.env) {
|
|
80
|
+
if (opts.offline || s.offline || /^(1|true|yes|on)$/i.test(env.QUANTUM_SCAN_OFFLINE ?? ""))
|
|
81
|
+
return "offline";
|
|
82
|
+
if (/^(0|false|no|off)$/i.test(env.QUANTUM_SCAN_SHARING ?? ""))
|
|
83
|
+
return "env-off";
|
|
84
|
+
if (env.DO_NOT_TRACK && env.DO_NOT_TRACK !== "0")
|
|
85
|
+
return "do-not-track";
|
|
86
|
+
return s.sharing === "off" ? "off" : "on";
|
|
87
|
+
}
|
|
88
|
+
export const NOTICE = `Hard Keel Quantum Scan collects anonymized, aggregated information about how its
|
|
89
|
+
checks perform and what kinds of encryption they find. It never includes your code,
|
|
90
|
+
keys, server names, IP addresses or company name. We use it to improve and build our
|
|
91
|
+
products and to understand encryption trends across the industry.
|
|
92
|
+
|
|
93
|
+
See what's sent: quantum-scan config show-shared
|
|
94
|
+
Turn it off: quantum-scan config sharing off (or QUANTUM_SCAN_SHARING=off)
|
|
95
|
+
Send nothing at all: --offline (or QUANTUM_SCAN_OFFLINE=1)
|
|
96
|
+
Details: https://hardkeel.com/privacy/
|
|
97
|
+
`;
|
|
98
|
+
/**
|
|
99
|
+
* Prints the notice the first time, before anything is sent. In automated pipelines,
|
|
100
|
+
* where settings may not survive between runs, it prints every run, at the top of the log.
|
|
101
|
+
*/
|
|
102
|
+
export function showNoticeIfNeeded(s, state, env = process.env, write = (t) => process.stderr.write(t)) {
|
|
103
|
+
if (state !== "on")
|
|
104
|
+
return false;
|
|
105
|
+
const ci = Boolean(env.CI || env.GITHUB_ACTIONS);
|
|
106
|
+
if (s.noticeShown && !ci)
|
|
107
|
+
return false;
|
|
108
|
+
write(`\n${NOTICE}\n`);
|
|
109
|
+
s.noticeShown = true;
|
|
110
|
+
return true;
|
|
111
|
+
}
|
package/dist/share.js
CHANGED
|
@@ -1,112 +1,114 @@
|
|
|
1
|
-
// Builds and sends the anonymized summary of a run. Counts are rounded into bands and every name is
|
|
2
|
-
// checked against a fixed list, so nothing taken from the scanned code or systems can reach us.
|
|
3
|
-
// What is sent is exactly what buildPayload returns; `quantum-scan config show-shared` prints it.
|
|
4
|
-
import { ALGORITHMS } from "./rules.js";
|
|
5
|
-
export const SHARE_URL = "https://scan.hardkeel.com/v1/share";
|
|
6
|
-
export const PAYLOAD_VERSION = 1;
|
|
7
|
-
export const BANDS = ["1", "2-5", "6-20", "21-100", "100+"];
|
|
8
|
-
export function band(n) {
|
|
9
|
-
if (!Number.isFinite(n) || n < 1)
|
|
10
|
-
return null;
|
|
11
|
-
if (n === 1)
|
|
12
|
-
return "1";
|
|
13
|
-
if (n <= 5)
|
|
14
|
-
return "2-5";
|
|
15
|
-
if (n <= 20)
|
|
16
|
-
return "6-20";
|
|
17
|
-
if (n <= 100)
|
|
18
|
-
return "21-100";
|
|
19
|
-
return "100+";
|
|
20
|
-
}
|
|
21
|
-
export const AREAS = ["code", "web", "host", "network", "vpn", "cloud"];
|
|
22
|
-
/** Error kinds a run may report. Messages are never sent, only these labels. */
|
|
23
|
-
export const ERROR_KINDS = ["timeout", "refused", "dns", "tls", "ssh", "read", "parse", "permission", "other"];
|
|
24
|
-
/** Post-quantum algorithms we credit. Anything else is dropped. */
|
|
25
|
-
export const PQC_NAMES = ["ML-KEM", "Hybrid ML-KEM key exchange", "ML-DSA", "SLH-DSA", "FN-DSA", "Hybrid SSH key exchange"];
|
|
26
|
-
/** Extra algorithm names the encryption map uses beyond the code rules. */
|
|
27
|
-
export const MAP_ALGORITHMS = ["TLS key exchange", "SSH key exchange", "SSH host key", "TLS certificate", "Static RSA key exchange", "SSH weak settings", "Expired certificate", "Certificate name mismatch", "Untrusted certificate", "Self-signed certificate"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (s.
|
|
77
|
-
payload.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
1
|
+
// Builds and sends the anonymized summary of a run. Counts are rounded into bands and every name is
|
|
2
|
+
// checked against a fixed list, so nothing taken from the scanned code or systems can reach us.
|
|
3
|
+
// What is sent is exactly what buildPayload returns; `quantum-scan config show-shared` prints it.
|
|
4
|
+
import { ALGORITHMS } from "./rules.js";
|
|
5
|
+
export const SHARE_URL = "https://scan.hardkeel.com/v1/share";
|
|
6
|
+
export const PAYLOAD_VERSION = 1;
|
|
7
|
+
export const BANDS = ["1", "2-5", "6-20", "21-100", "100+"];
|
|
8
|
+
export function band(n) {
|
|
9
|
+
if (!Number.isFinite(n) || n < 1)
|
|
10
|
+
return null;
|
|
11
|
+
if (n === 1)
|
|
12
|
+
return "1";
|
|
13
|
+
if (n <= 5)
|
|
14
|
+
return "2-5";
|
|
15
|
+
if (n <= 20)
|
|
16
|
+
return "6-20";
|
|
17
|
+
if (n <= 100)
|
|
18
|
+
return "21-100";
|
|
19
|
+
return "100+";
|
|
20
|
+
}
|
|
21
|
+
export const AREAS = ["code", "web", "host", "network", "vpn", "cloud"];
|
|
22
|
+
/** Error kinds a run may report. Messages are never sent, only these labels. */
|
|
23
|
+
export const ERROR_KINDS = ["timeout", "refused", "dns", "tls", "ssh", "read", "parse", "permission", "other"];
|
|
24
|
+
/** Post-quantum algorithms we credit. Anything else is dropped. */
|
|
25
|
+
export const PQC_NAMES = ["ML-KEM", "Hybrid ML-KEM key exchange", "ML-DSA", "SLH-DSA", "FN-DSA", "Hybrid SSH key exchange"];
|
|
26
|
+
/** Extra algorithm names the encryption map uses beyond the code rules. */
|
|
27
|
+
export const MAP_ALGORITHMS = ["TLS key exchange", "SSH key exchange", "SSH host key", "TLS certificate", "Static RSA key exchange", "SSH weak settings", "Expired certificate", "Certificate name mismatch", "Untrusted certificate", "Self-signed certificate",
|
|
28
|
+
// Network and connected equipment (map-network.ts NET_RULES; listed here so the Worker needn't load network code).
|
|
29
|
+
"Telnet", "Plain FTP", "Remote Desktop open", "VNC open", "Remote support tool", "Setup page open", "Admin page over plain HTTP", "Vendor default certificate", "Open print port", "LPD printing", "Camera stream port", "DVR service port", "MQTT without encryption", "Docker API open", "Docker API port open", "Database open on the network", "UPnP on the router", "Router forward from the internet"];
|
|
30
|
+
const KNOWN_ALGORITHMS = new Set([...Object.keys(ALGORITHMS), ...MAP_ALGORITHMS, ...PQC_NAMES]);
|
|
31
|
+
const RULE_ID = /^[a-z0-9][a-z0-9-]{0,59}$/;
|
|
32
|
+
function bandMap(src, keyOk) {
|
|
33
|
+
const out = {};
|
|
34
|
+
for (const [k, n] of Object.entries(src)) {
|
|
35
|
+
const b = band(n);
|
|
36
|
+
if (b && keyOk(k))
|
|
37
|
+
out[k] = b;
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
export function buildPayload(facts, s, toolVersion, env = process.env, platform = process.platform) {
|
|
42
|
+
const ruleOk = (k) => RULE_ID.test(k);
|
|
43
|
+
const algorithms = {};
|
|
44
|
+
const other = { count: 0, quantumVulnerable: 0 };
|
|
45
|
+
for (const [name, v] of Object.entries(facts.algorithms)) {
|
|
46
|
+
const target = KNOWN_ALGORITHMS.has(name) ? name : null;
|
|
47
|
+
if (!target) {
|
|
48
|
+
other.count += v.count;
|
|
49
|
+
other.quantumVulnerable += v.quantumVulnerable;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const n = band(v.count);
|
|
53
|
+
if (n)
|
|
54
|
+
algorithms[target] = { n, qv: band(v.quantumVulnerable) ?? "0" };
|
|
55
|
+
}
|
|
56
|
+
const on = band(other.count);
|
|
57
|
+
if (on)
|
|
58
|
+
algorithms.other = { n: on, qv: band(other.quantumVulnerable) ?? "0" };
|
|
59
|
+
const pqcOk = (k) => PQC_NAMES.includes(k);
|
|
60
|
+
const payload = {
|
|
61
|
+
v: PAYLOAD_VERSION,
|
|
62
|
+
id: s.id,
|
|
63
|
+
tool: /^\d+\.\d+\.\d+$/.test(toolVersion) ? toolVersion : "0.0.0",
|
|
64
|
+
os: platform === "linux" || platform === "darwin" || platform === "win32" ? platform : "other",
|
|
65
|
+
ci: Boolean(env.CI || env.GITHUB_ACTIONS),
|
|
66
|
+
command: facts.command,
|
|
67
|
+
areas: AREAS.filter((a) => facts.areas.includes(a)),
|
|
68
|
+
rules: bandMap(facts.rules, ruleOk),
|
|
69
|
+
fixed: bandMap(facts.fixed, ruleOk),
|
|
70
|
+
ignored: bandMap(facts.ignored, ruleOk),
|
|
71
|
+
algorithms,
|
|
72
|
+
quantumSafe: bandMap(facts.quantumSafe, pqcOk),
|
|
73
|
+
replacements: bandMap(facts.replacements, pqcOk),
|
|
74
|
+
errors: ERROR_KINDS.filter((e) => facts.errors.includes(e)),
|
|
75
|
+
};
|
|
76
|
+
if (s.industry)
|
|
77
|
+
payload.industry = s.industry;
|
|
78
|
+
if (s.size)
|
|
79
|
+
payload.size = s.size;
|
|
80
|
+
return payload;
|
|
81
|
+
}
|
|
82
|
+
/** Sends the summary. Never throws and never waits more than a few seconds. */
|
|
83
|
+
export async function sendPayload(p, url = SHARE_URL, timeoutMs = 3000) {
|
|
84
|
+
try {
|
|
85
|
+
const res = await fetch(url, {
|
|
86
|
+
method: "POST",
|
|
87
|
+
headers: { "content-type": "application/json", "user-agent": `hardkeel-quantum-scan/${p.tool}` },
|
|
88
|
+
body: JSON.stringify(p),
|
|
89
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
90
|
+
});
|
|
91
|
+
return res.ok;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Compares this run with the last one in the same folder: what went away, and what post-quantum use is new. */
|
|
98
|
+
export function diffRuns(prev, now) {
|
|
99
|
+
const fixed = {};
|
|
100
|
+
const replacements = {};
|
|
101
|
+
if (!prev)
|
|
102
|
+
return { fixed, replacements };
|
|
103
|
+
for (const [rule, n] of Object.entries(prev.rules)) {
|
|
104
|
+
const gone = n - (now.rules[rule] ?? 0);
|
|
105
|
+
if (gone > 0)
|
|
106
|
+
fixed[rule] = gone;
|
|
107
|
+
}
|
|
108
|
+
for (const [alg, n] of Object.entries(now.pqc)) {
|
|
109
|
+
const added = n - (prev.pqc[alg] ?? 0);
|
|
110
|
+
if (added > 0)
|
|
111
|
+
replacements[alg] = added;
|
|
112
|
+
}
|
|
113
|
+
return { fixed, replacements };
|
|
114
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Shared types for the Hard Keel quantum-readiness scanner.
|
|
2
|
-
export {};
|
|
1
|
+
// Shared types for the Hard Keel quantum-readiness scanner.
|
|
2
|
+
export {};
|
package/dist/walk.js
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
// Reads the files in a folder that the scanner looks at.
|
|
2
|
-
// A folder or file that can't be read (no permission, removed mid-scan) is noted and skipped,
|
|
3
|
-
// so one locked folder can't stop the whole scan.
|
|
4
|
-
import { existsSync, lstatSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
5
|
-
import { join, relative } from "node:path";
|
|
6
|
-
import { shouldScan } from "./scan.js";
|
|
7
|
-
function reasonOf(e) {
|
|
8
|
-
const code = String(e?.code ?? "");
|
|
9
|
-
if (code === "EACCES" || code === "EPERM")
|
|
10
|
-
return "permission denied";
|
|
11
|
-
if (code === "ENOENT")
|
|
12
|
-
return "removed during the scan";
|
|
13
|
-
return code || (e instanceof Error ? e.message : String(e));
|
|
14
|
-
}
|
|
15
|
-
/** Throws a plain-English error when the folder itself is missing or isn't a folder. */
|
|
16
|
-
export function walkFolder(root) {
|
|
17
|
-
if (!existsSync(root))
|
|
18
|
-
throw new Error(`Can't scan ${root}: that folder doesn't exist.`);
|
|
19
|
-
if (!statSync(root).isDirectory())
|
|
20
|
-
throw new Error(`Can't scan ${root}: that's a file, not a folder.`);
|
|
21
|
-
const res = { files: [], unreadable: [] };
|
|
22
|
-
const visit = (dir) => {
|
|
23
|
-
let names;
|
|
24
|
-
try {
|
|
25
|
-
names = readdirSync(dir);
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
if (dir === root)
|
|
29
|
-
throw new Error(`Can't scan ${root}: ${reasonOf(e)}.`);
|
|
30
|
-
res.unreadable.push({ path: relative(root, dir).split("\\").join("/") + "/", reason: reasonOf(e) });
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
for (const name of names) {
|
|
34
|
-
const full = join(dir, name);
|
|
35
|
-
const rel = relative(root, full).split("\\").join("/");
|
|
36
|
-
// lstat: symbolic links are skipped, so a broken or looping link can't stop the scan.
|
|
37
|
-
let st;
|
|
38
|
-
try {
|
|
39
|
-
st = lstatSync(full);
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
if (st.isDirectory()) {
|
|
45
|
-
if (name !== ".git" && shouldScan(`${rel}/x`))
|
|
46
|
-
visit(full);
|
|
47
|
-
}
|
|
48
|
-
else if (st.isFile() && st.size <= 1_000_000 && shouldScan(rel)) {
|
|
49
|
-
try {
|
|
50
|
-
res.files.push({ path: rel, content: readFileSync(full, "utf8") });
|
|
51
|
-
}
|
|
52
|
-
catch (e) {
|
|
53
|
-
res.unreadable.push({ path: rel, reason: reasonOf(e) });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
visit(root);
|
|
59
|
-
return res;
|
|
60
|
-
}
|
|
61
|
-
export function walk(root) {
|
|
62
|
-
return walkFolder(root).files;
|
|
63
|
-
}
|
|
1
|
+
// Reads the files in a folder that the scanner looks at.
|
|
2
|
+
// A folder or file that can't be read (no permission, removed mid-scan) is noted and skipped,
|
|
3
|
+
// so one locked folder can't stop the whole scan.
|
|
4
|
+
import { existsSync, lstatSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
5
|
+
import { join, relative } from "node:path";
|
|
6
|
+
import { shouldScan } from "./scan.js";
|
|
7
|
+
function reasonOf(e) {
|
|
8
|
+
const code = String(e?.code ?? "");
|
|
9
|
+
if (code === "EACCES" || code === "EPERM")
|
|
10
|
+
return "permission denied";
|
|
11
|
+
if (code === "ENOENT")
|
|
12
|
+
return "removed during the scan";
|
|
13
|
+
return code || (e instanceof Error ? e.message : String(e));
|
|
14
|
+
}
|
|
15
|
+
/** Throws a plain-English error when the folder itself is missing or isn't a folder. */
|
|
16
|
+
export function walkFolder(root) {
|
|
17
|
+
if (!existsSync(root))
|
|
18
|
+
throw new Error(`Can't scan ${root}: that folder doesn't exist.`);
|
|
19
|
+
if (!statSync(root).isDirectory())
|
|
20
|
+
throw new Error(`Can't scan ${root}: that's a file, not a folder.`);
|
|
21
|
+
const res = { files: [], unreadable: [] };
|
|
22
|
+
const visit = (dir) => {
|
|
23
|
+
let names;
|
|
24
|
+
try {
|
|
25
|
+
names = readdirSync(dir);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
if (dir === root)
|
|
29
|
+
throw new Error(`Can't scan ${root}: ${reasonOf(e)}.`);
|
|
30
|
+
res.unreadable.push({ path: relative(root, dir).split("\\").join("/") + "/", reason: reasonOf(e) });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
for (const name of names) {
|
|
34
|
+
const full = join(dir, name);
|
|
35
|
+
const rel = relative(root, full).split("\\").join("/");
|
|
36
|
+
// lstat: symbolic links are skipped, so a broken or looping link can't stop the scan.
|
|
37
|
+
let st;
|
|
38
|
+
try {
|
|
39
|
+
st = lstatSync(full);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (st.isDirectory()) {
|
|
45
|
+
if (name !== ".git" && shouldScan(`${rel}/x`))
|
|
46
|
+
visit(full);
|
|
47
|
+
}
|
|
48
|
+
else if (st.isFile() && st.size <= 1_000_000 && shouldScan(rel)) {
|
|
49
|
+
try {
|
|
50
|
+
res.files.push({ path: rel, content: readFileSync(full, "utf8") });
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
res.unreadable.push({ path: rel, reason: reasonOf(e) });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
visit(root);
|
|
59
|
+
return res;
|
|
60
|
+
}
|
|
61
|
+
export function walk(root) {
|
|
62
|
+
return walkFolder(root).files;
|
|
63
|
+
}
|