@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/dist/map-run.js CHANGED
@@ -1,205 +1,271 @@
1
- // quantum-scan map: asks before each area, runs only what was approved, and writes the encryption map.
2
- // Unattended runs use a scope file, which records what was approved. Nothing outside it is touched.
3
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
- import { join, resolve } from "node:path";
5
- import { createInterface } from "node:readline/promises";
6
- import { applyIgnore, applyIgnoreTargets, IGNORE_FILE, parseIgnore } from "./ignore.js";
7
- import { buildCbom } from "./cbom.js";
8
- import { ActivityLog } from "./map-activity.js";
9
- import { CARDS, cardText } from "./map-areas.js";
10
- import { runHost } from "./map-host.js";
11
- import { fromCodeFinding, rank, toFinding } from "./map-rank.js";
12
- import { buildMapReport, mapHtml, mapText } from "./map-report.js";
13
- import { emptyResult } from "./map-types.js";
14
- import { proofRecord, runWeb } from "./map-web.js";
15
- import { scanFiles } from "./scan.js";
16
- import { INDUSTRIES, SIZES } from "./share-config.js";
17
- import { walkFolder } from "./walk.js";
18
- export const SCOPE_FILE = "quantum-scan.scope.json";
19
- export function parseScope(text) {
20
- let v;
21
- try {
22
- v = JSON.parse(text);
23
- }
24
- catch {
25
- return { error: "the scope file isn't valid JSON" };
26
- }
27
- if (!v || v.version !== 1 || typeof v.areas !== "object")
28
- return { error: "the scope file needs version 1 and an areas object" };
29
- const s = { version: 1, created: String(v.created ?? ""), areas: {} };
30
- if (typeof v.ownershipToken === "string" && /^[a-f0-9]{24}$/.test(v.ownershipToken))
31
- s.ownershipToken = v.ownershipToken;
32
- const strings = (x) => (Array.isArray(x) ? x.filter((y) => typeof y === "string" && y.length > 0 && y.length < 300) : []);
33
- if (v.areas.code)
34
- s.areas.code = { folders: strings(v.areas.code.folders) };
35
- if (v.areas.web)
36
- s.areas.web = { targets: strings(v.areas.web.targets) };
37
- if (v.areas.host)
38
- s.areas.host = {};
39
- const known = new Set(["code", "web", "host"]);
40
- const unknown = Object.keys(v.areas).filter((k) => !known.has(k));
41
- if (unknown.length)
42
- return { error: `this version can't check: ${unknown.join(", ")}` };
43
- return s;
44
- }
45
- export function terminalPrompter() {
46
- const rl = createInterface({ input: process.stdin, output: process.stderr });
47
- return { ask: (q) => rl.question(q), close: () => rl.close() };
48
- }
49
- const yes = (a) => /^\s*y(es)?\s*$/i.test(a);
50
- /** Walks through each area with its card. The answer is no unless the person types yes. */
51
- export async function askScope(p, cwd, write) {
52
- const scope = { version: 1, created: new Date().toISOString().slice(0, 10), areas: {} };
53
- write("\nI'll go through each area, say what it does, and ask first. Press Enter to skip any of them.\n\n");
54
- write(cardText(CARDS.code, [cwd]) + "\n");
55
- if (yes(await p.ask("Scan the code and config in this folder? (y/N) ")))
56
- scope.areas.code = { folders: ["."] };
57
- write("\n");
58
- const raw = await p.ask("Websites and public services: list addresses to check, separated by spaces (e.g. example.com api.example.com:8443 ssh://git.example.com), or press Enter to skip:\n> ");
59
- const targets = raw.split(/[\s,]+/).filter(Boolean);
60
- if (targets.length) {
61
- write("\n" + cardText(CARDS.web, targets) + "\n");
62
- if (yes(await p.ask("Check these addresses? (y/N) ")))
63
- scope.areas.web = { targets };
64
- }
65
- write("\n" + cardText(CARDS.host, []) + "\n");
66
- if (yes(await p.ask("Check this machine? (y/N) ")))
67
- scope.areas.host = {};
68
- return scope;
69
- }
70
- /** Optional, asked once: lets the anonymized counts be grouped by industry and size. */
71
- export async function askProfile(p, s, write) {
72
- write(`\nOptional: your industry and company size help us understand encryption trends. Press Enter to skip.\n Industries: ${INDUSTRIES.join(", ")}\n`);
73
- const ind = (await p.ask("Industry: ")).trim().toLowerCase();
74
- if (INDUSTRIES.includes(ind))
75
- s.industry = ind;
76
- const size = (await p.ask(`Company size (${SIZES.join(", ")}): `)).trim();
77
- if (SIZES.includes(size))
78
- s.size = size;
79
- s.profileAsked = true;
80
- }
81
- export async function runMap(o) {
82
- const write = o.write ?? ((t) => process.stderr.write(t));
83
- let scope;
84
- if (o.scopePath) {
85
- if (!existsSync(o.scopePath)) {
86
- write(`No scope file at ${o.scopePath}.\n`);
87
- return { code: 2 };
88
- }
89
- const parsed = parseScope(readFileSync(o.scopePath, "utf8"));
90
- if ("error" in parsed) {
91
- write(`Can't use ${o.scopePath}: ${parsed.error}.\n`);
92
- return { code: 2 };
93
- }
94
- scope = parsed;
95
- }
96
- else if (o.interactive) {
97
- const p = (o.prompter ?? terminalPrompter)();
98
- try {
99
- scope = await askScope(p, o.cwd, write);
100
- if (o.sharingOn && !o.settings.profileAsked)
101
- await askProfile(p, o.settings, write);
102
- if (Object.keys(scope.areas).length && yes(await p.ask(`\nSave these answers to ${SCOPE_FILE} so the next run (or a pipeline) can reuse them? (y/N) `))) {
103
- scope.ownershipToken = o.settings.ownershipToken;
104
- writeFileSync(join(o.cwd, SCOPE_FILE), JSON.stringify(scope, null, 2) + "\n");
105
- write(`Saved ${SCOPE_FILE}.\n`);
106
- }
107
- }
108
- finally {
109
- p.close();
110
- }
111
- }
112
- else {
113
- write(`quantum-scan map asks before each area. Run it in a terminal, or pass --scope ${SCOPE_FILE} for unattended runs.\n`);
114
- return { code: 2 };
115
- }
116
- const areas = Object.keys(scope.areas);
117
- if (!areas.length) {
118
- write("Nothing approved, so nothing was checked.\n");
119
- return { code: 0 };
120
- }
121
- mkdirSync(o.outDir, { recursive: true });
122
- const logPath = join(o.outDir, "activity.log");
123
- writeFileSync(logPath, "");
124
- const log = new ActivityLog(logPath);
125
- const results = [];
126
- const ignored = {};
127
- const pqcCounts = {};
128
- if (scope.areas.code) {
129
- const res = emptyResult("code");
130
- for (const folder of scope.areas.code.folders.length ? scope.areas.code.folders : ["."]) {
131
- const dir = resolve(o.cwd, folder);
132
- log.record("code", dir, "read source and config files");
133
- try {
134
- const walked = walkFolder(dir);
135
- for (const u of walked.unreadable)
136
- res.errors.push({ area: "code", target: `${folder}/${u.path}`.replace(/^\.\//, ""), kind: u.reason === "permission denied" ? "permission" : "read", message: `couldn't read (${u.reason})` });
137
- const { findings, pqc, filesScanned } = scanFiles(walked.files);
138
- const ign = join(dir, IGNORE_FILE);
139
- const { kept, ignored: ig } = applyIgnore(findings, existsSync(ign) ? parseIgnore(readFileSync(ign, "utf8")) : []);
140
- for (const [k, n] of Object.entries(ig))
141
- ignored[k] = (ignored[k] ?? 0) + n;
142
- res.findings.push(...kept.map(fromCodeFinding));
143
- for (const s of pqc)
144
- pqcCounts[s.algorithm] = (pqcCounts[s.algorithm] ?? 0) + 1;
145
- res.checked.push(`${folder} (${filesScanned} files)`);
146
- }
147
- catch (e) {
148
- res.errors.push({ area: "code", target: folder, kind: "read", message: e instanceof Error ? e.message : String(e) });
149
- }
150
- }
151
- results.push(res);
152
- }
153
- if (scope.areas.web) {
154
- const token = scope.ownershipToken ?? o.settings.ownershipToken;
155
- const res = await runWeb(scope.areas.web.targets, log, { ...o.web, token });
156
- results.push(res);
157
- if (res.unproved.length) {
158
- write("\nSome addresses were skipped because their domain isn't proved yet. To prove one, add this DNS record, then run again:\n");
159
- for (const d of res.unproved) {
160
- const r = proofRecord(d, token);
161
- write(` ${r.name} TXT "${r.value}"\n`);
162
- }
163
- write("One record covers the domain and everything under it.\n");
164
- }
165
- if (res.dnsFailed.length) {
166
- write(`\nCouldn't look up the ownership record for ${res.dnsFailed.join(", ")} because DNS didn't answer, so ${res.dnsFailed.length === 1 ? "it was" : "they were"} skipped. Check this machine's DNS settings, then run again.\n`);
167
- }
168
- }
169
- if (scope.areas.host)
170
- results.push(runHost(log, o.hostIO));
171
- // Known leftovers the person accepted in .quantum-scan-ignore (websites and this machine; code was handled per folder).
172
- const ignorePath = join(o.cwd, IGNORE_FILE);
173
- const entries = existsSync(ignorePath) ? parseIgnore(readFileSync(ignorePath, "utf8")) : [];
174
- const accepted = [];
175
- for (const r of results) {
176
- if (r.area === "code" || !entries.length)
177
- continue;
178
- const a = applyIgnoreTargets(r.findings, entries);
179
- r.findings = a.kept;
180
- accepted.push(...a.accepted);
181
- for (const f of a.accepted)
182
- ignored[f.ruleId] = (ignored[f.ruleId] ?? 0) + 1;
183
- }
184
- const ranked = rank(results.flatMap((r) => r.findings));
185
- const report = buildMapReport(results, ranked, o.version, new Date(), accepted);
186
- writeFileSync(join(o.outDir, "map.json"), JSON.stringify(report, null, 2) + "\n");
187
- writeFileSync(join(o.outDir, "map.html"), mapHtml(report, log.entries));
188
- writeFileSync(join(o.outDir, "map.cbom.json"), JSON.stringify(buildCbom(ranked.map(toFinding), { repo: "encryption map", toolVersion: o.version }), null, 2) + "\n");
189
- process.stdout.write(mapText(report) + `\n\nWrote ${join(o.outDir, "map.html")}, map.json, map.cbom.json and activity.log. They stay on this machine.\n`);
190
- // Counts for the anonymized summary. Targets never leave this function.
191
- const rules = {};
192
- const algorithms = {};
193
- for (const f of ranked) {
194
- rules[f.ruleId] = (rules[f.ruleId] ?? 0) + 1;
195
- const a = (algorithms[f.algorithm] ??= { count: 0, quantumVulnerable: 0 });
196
- a.count++;
197
- if (f.risk === "quantum-vulnerable")
198
- a.quantumVulnerable++;
199
- }
200
- for (const s of report.strengths)
201
- pqcCounts[s.algorithm] = (pqcCounts[s.algorithm] ?? 0) + 1;
202
- const errors = [...new Set(results.flatMap((r) => r.errors.map((e) => e.kind)))];
203
- const facts = { command: "map", areas, rules, algorithms, quantumSafe: pqcCounts, fixed: {}, ignored, replacements: {}, errors };
204
- return { code: 0, report, facts, stateKey: `map:${resolve(o.cwd)}`, state: { rules, pqc: pqcCounts } };
205
- }
1
+ // quantum-scan map: asks before each area, runs only what was approved, and writes the encryption map.
2
+ // Unattended runs use a scope file, which records what was approved. Nothing outside it is touched.
3
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { join, resolve } from "node:path";
5
+ import { createInterface } from "node:readline/promises";
6
+ import { applyIgnore, applyIgnoreTargets, IGNORE_FILE, parseIgnore } from "./ignore.js";
7
+ import { buildCbom } from "./cbom.js";
8
+ import { ActivityLog } from "./map-activity.js";
9
+ import { CARDS, cardText } from "./map-areas.js";
10
+ import { runHost } from "./map-host.js";
11
+ import { fromCodeFinding, rank, toFinding } from "./map-rank.js";
12
+ import { buildMapReport, mapHtml, mapText } from "./map-report.js";
13
+ import { emptyResult } from "./map-types.js";
14
+ import { cloudKeyAdvice } from "./map-cloud-keys.js";
15
+ import { isPrivateRange, machineRanges, parseRange, realNetIO, runNetwork, suggestedRanges } from "./map-network.js";
16
+ import { askPeople, parseAnswers, QUESTIONS, scorePeople } from "./map-people.js";
17
+ import { proofRecord, runWeb } from "./map-web.js";
18
+ import { scanFiles } from "./scan.js";
19
+ import { INDUSTRIES, SIZES } from "./share-config.js";
20
+ import { walkFolder } from "./walk.js";
21
+ export const SCOPE_FILE = "quantum-scan.scope.json";
22
+ export function parseScope(text) {
23
+ let v;
24
+ try {
25
+ v = JSON.parse(text);
26
+ }
27
+ catch {
28
+ return { error: "the scope file isn't valid JSON" };
29
+ }
30
+ if (!v || v.version !== 1 || typeof v.areas !== "object")
31
+ return { error: "the scope file needs version 1 and an areas object" };
32
+ const s = { version: 1, created: String(v.created ?? ""), areas: {} };
33
+ if (typeof v.ownershipToken === "string" && /^[a-f0-9]{24}$/.test(v.ownershipToken))
34
+ s.ownershipToken = v.ownershipToken;
35
+ const strings = (x) => (Array.isArray(x) ? x.filter((y) => typeof y === "string" && y.length > 0 && y.length < 300) : []);
36
+ if (v.areas.code)
37
+ s.areas.code = { folders: strings(v.areas.code.folders) };
38
+ if (v.areas.web)
39
+ s.areas.web = { targets: strings(v.areas.web.targets) };
40
+ if (v.areas.host)
41
+ s.areas.host = {};
42
+ if (v.areas.network) {
43
+ const n = v.areas.network;
44
+ s.areas.network = { ranges: strings(n.ranges).slice(0, 16), routed: strings(n.routed).slice(0, 16), exclude: strings(n.exclude).slice(0, 256) };
45
+ }
46
+ if (v.people?.answers)
47
+ s.people = { answers: parseAnswers(v.people.answers) };
48
+ const known = new Set(["code", "web", "host", "network"]);
49
+ const unknown = Object.keys(v.areas).filter((k) => !known.has(k));
50
+ if (unknown.length)
51
+ return { error: `this version can't check: ${unknown.join(", ")}` };
52
+ return s;
53
+ }
54
+ export function terminalPrompter() {
55
+ const rl = createInterface({ input: process.stdin, output: process.stderr });
56
+ return { ask: (q) => rl.question(q), close: () => rl.close() };
57
+ }
58
+ const yes = (a) => /^\s*y(es)?\s*$/i.test(a);
59
+ /** Walks through each area with its card. The answer is no unless the person types yes. */
60
+ export async function askScope(p, cwd, write, netIO = realNetIO) {
61
+ const scope = { version: 1, created: new Date().toISOString().slice(0, 10), areas: {} };
62
+ write("\nI'll go through each area, say what it does, and ask first. Press Enter to skip any of them.\n\n");
63
+ write(cardText(CARDS.code, [cwd]) + "\n");
64
+ if (yes(await p.ask("Scan the code and config in this folder? (y/N) ")))
65
+ scope.areas.code = { folders: ["."] };
66
+ write("\n");
67
+ const raw = await p.ask("Websites and public services: list addresses to check, separated by spaces (e.g. example.com api.example.com:8443 ssh://git.example.com), or press Enter to skip:\n> ");
68
+ const targets = raw.split(/[\s,]+/).filter(Boolean);
69
+ if (targets.length) {
70
+ write("\n" + cardText(CARDS.web, targets) + "\n");
71
+ if (yes(await p.ask("Check these addresses? (y/N) ")))
72
+ scope.areas.web = { targets };
73
+ }
74
+ write("\n");
75
+ const sugg = suggestedRanges(netIO);
76
+ const rawNet = await p.ask(`Network and connected equipment: list your private address ranges${sugg.length ? ` (this computer is on ${sugg.join(", ")})` : " (e.g. 192.168.1.0/24)"}, or press Enter to skip:\n> `);
77
+ const asked = rawNet.split(/[\s,]+/).filter(Boolean);
78
+ if (asked.length) {
79
+ const mine = machineRanges(netIO);
80
+ const ranges = [];
81
+ const routed = [];
82
+ for (const raw of asked) {
83
+ const r = parseRange(raw);
84
+ if ("error" in r || !isPrivateRange(r)) {
85
+ write(` Skipping ${raw}: ${"error" in r ? r.error : "only private address ranges can be checked"}.\n`);
86
+ continue;
87
+ }
88
+ if (mine.some((m) => r.start >= m.start && r.end <= m.end))
89
+ ranges.push(raw);
90
+ else if (yes(await p.ask(` This computer isn't on ${raw}. Is it another part of your own network, reached through your router? (y/N) `)))
91
+ routed.push(raw);
92
+ }
93
+ const all = [...ranges, ...routed];
94
+ if (all.length) {
95
+ write("\n" + cardText(CARDS.network, all) + "\n");
96
+ if (yes(await p.ask("Check these networks? (y/N) ")))
97
+ scope.areas.network = { ranges, routed, exclude: [] };
98
+ }
99
+ }
100
+ write("\n" + cardText(CARDS.host, []) + "\n");
101
+ if (yes(await p.ask("Check this machine? (y/N) ")))
102
+ scope.areas.host = {};
103
+ return scope;
104
+ }
105
+ /** Optional, asked once: lets the anonymized counts be grouped by industry and size. */
106
+ export async function askProfile(p, s, write) {
107
+ write(`\nOptional: your industry and company size help us understand encryption trends. Press Enter to skip.\n Industries: ${INDUSTRIES.join(", ")}\n`);
108
+ const ind = (await p.ask("Industry: ")).trim().toLowerCase();
109
+ if (INDUSTRIES.includes(ind))
110
+ s.industry = ind;
111
+ const size = (await p.ask(`Company size (${SIZES.join(", ")}): `)).trim();
112
+ if (SIZES.includes(size))
113
+ s.size = size;
114
+ s.profileAsked = true;
115
+ }
116
+ export const PEOPLE_FILE = "people.json";
117
+ function loadPeople(outDir) {
118
+ try {
119
+ const v = JSON.parse(readFileSync(join(outDir, PEOPLE_FILE), "utf8"));
120
+ const answers = parseAnswers(v?.answers);
121
+ return Object.keys(answers).length ? { answeredAt: String(v.answeredAt ?? "").slice(0, 10), answers } : null;
122
+ }
123
+ catch {
124
+ return null;
125
+ }
126
+ }
127
+ export async function runMap(o) {
128
+ const write = o.write ?? ((t) => process.stderr.write(t));
129
+ let scope;
130
+ if (o.scopePath) {
131
+ if (!existsSync(o.scopePath)) {
132
+ write(`No scope file at ${o.scopePath}.\n`);
133
+ return { code: 2 };
134
+ }
135
+ const parsed = parseScope(readFileSync(o.scopePath, "utf8"));
136
+ if ("error" in parsed) {
137
+ write(`Can't use ${o.scopePath}: ${parsed.error}.\n`);
138
+ return { code: 2 };
139
+ }
140
+ scope = parsed;
141
+ }
142
+ else if (o.interactive) {
143
+ const p = (o.prompter ?? terminalPrompter)();
144
+ try {
145
+ scope = await askScope(p, o.cwd, write, o.network?.io);
146
+ const before = loadPeople(o.outDir);
147
+ write(`\nPeople and process: ${QUESTIONS.length} short yes/no questions about what no scan can see, like phishing training, backups and who to call in a breach. About 3 minutes. Answers stay on this machine and are never shared.\n`);
148
+ if (yes(await p.ask(`Answer them now?${before ? ` Enter keeps your answers from ${before.answeredAt}.` : ""} (y/N) `))) {
149
+ const answers = await askPeople((q) => p.ask(q), write);
150
+ if (Object.keys(answers).length)
151
+ scope.people = { answers };
152
+ }
153
+ if (o.sharingOn && !o.settings.profileAsked)
154
+ await askProfile(p, o.settings, write);
155
+ if (Object.keys(scope.areas).length && yes(await p.ask(`\nSave these answers to ${SCOPE_FILE} so the next run (or a pipeline) can reuse them? (y/N) `))) {
156
+ scope.ownershipToken = o.settings.ownershipToken;
157
+ // People and process answers stay out of the scope file, which often ends up in a repository.
158
+ writeFileSync(join(o.cwd, SCOPE_FILE), JSON.stringify({ ...scope, people: undefined }, null, 2) + "\n");
159
+ write(`Saved ${SCOPE_FILE}.\n`);
160
+ }
161
+ }
162
+ finally {
163
+ p.close();
164
+ }
165
+ }
166
+ else {
167
+ write(`quantum-scan map asks before each area. Run it in a terminal, or pass --scope ${SCOPE_FILE} for unattended runs.\n`);
168
+ return { code: 2 };
169
+ }
170
+ const areas = Object.keys(scope.areas);
171
+ if (!areas.length && !scope.people) {
172
+ write("Nothing approved, so nothing was checked.\n");
173
+ return { code: 0 };
174
+ }
175
+ mkdirSync(o.outDir, { recursive: true });
176
+ const people = scope.people?.answers && Object.keys(scope.people.answers).length ? { answeredAt: new Date().toISOString().slice(0, 10), answers: scope.people.answers } : loadPeople(o.outDir);
177
+ if (scope.people?.answers && Object.keys(scope.people.answers).length)
178
+ writeFileSync(join(o.outDir, PEOPLE_FILE), JSON.stringify(people, null, 2) + "\n");
179
+ const logPath = join(o.outDir, "activity.log");
180
+ writeFileSync(logPath, "");
181
+ const log = new ActivityLog(logPath);
182
+ const results = [];
183
+ const ignored = {};
184
+ const pqcCounts = {};
185
+ const cloudKeys = [];
186
+ if (scope.areas.code) {
187
+ const res = emptyResult("code");
188
+ for (const folder of scope.areas.code.folders.length ? scope.areas.code.folders : ["."]) {
189
+ const dir = resolve(o.cwd, folder);
190
+ log.record("code", dir, "read source and config files");
191
+ try {
192
+ const walked = walkFolder(dir);
193
+ for (const u of walked.unreadable)
194
+ res.errors.push({ area: "code", target: `${folder}/${u.path}`.replace(/^\.\//, ""), kind: u.reason === "permission denied" ? "permission" : "read", message: `couldn't read (${u.reason})` });
195
+ const { findings, pqc, filesScanned } = scanFiles(walked.files);
196
+ for (const f of walked.files)
197
+ for (const a of cloudKeyAdvice(f.path, f.content))
198
+ cloudKeys.push({ ...a, target: `${folder}/${a.target}`.replace(/^\.\//, "") });
199
+ const ign = join(dir, IGNORE_FILE);
200
+ const { kept, ignored: ig } = applyIgnore(findings, existsSync(ign) ? parseIgnore(readFileSync(ign, "utf8")) : []);
201
+ for (const [k, n] of Object.entries(ig))
202
+ ignored[k] = (ignored[k] ?? 0) + n;
203
+ res.findings.push(...kept.map(fromCodeFinding));
204
+ for (const s of pqc)
205
+ pqcCounts[s.algorithm] = (pqcCounts[s.algorithm] ?? 0) + 1;
206
+ res.checked.push(`${folder} (${filesScanned} files)`);
207
+ }
208
+ catch (e) {
209
+ res.errors.push({ area: "code", target: folder, kind: "read", message: e instanceof Error ? e.message : String(e) });
210
+ }
211
+ }
212
+ results.push(res);
213
+ }
214
+ if (scope.areas.web) {
215
+ const token = scope.ownershipToken ?? o.settings.ownershipToken;
216
+ const res = await runWeb(scope.areas.web.targets, log, { ...o.web, token });
217
+ results.push(res);
218
+ if (res.unproved.length) {
219
+ write("\nSome addresses were skipped because their domain isn't proved yet. To prove one, add this DNS record, then run again:\n");
220
+ for (const d of res.unproved) {
221
+ const r = proofRecord(d, token);
222
+ write(` ${r.name} TXT "${r.value}"\n`);
223
+ }
224
+ write("One record covers the domain and everything under it.\n");
225
+ }
226
+ if (res.dnsFailed.length) {
227
+ write(`\nCouldn't look up the ownership record for ${res.dnsFailed.join(", ")} because DNS didn't answer, so ${res.dnsFailed.length === 1 ? "it was" : "they were"} skipped. Check this machine's DNS settings, then run again.\n`);
228
+ }
229
+ }
230
+ if (scope.areas.network)
231
+ results.push(await runNetwork(scope.areas.network, log, o.network));
232
+ if (scope.areas.host)
233
+ results.push(runHost(log, o.hostIO));
234
+ // Known leftovers the person accepted in .quantum-scan-ignore (websites and this machine; code was handled per folder).
235
+ const ignorePath = join(o.cwd, IGNORE_FILE);
236
+ const entries = existsSync(ignorePath) ? parseIgnore(readFileSync(ignorePath, "utf8")) : [];
237
+ const accepted = [];
238
+ for (const r of results) {
239
+ if (r.area === "code" || !entries.length)
240
+ continue;
241
+ const a = applyIgnoreTargets(r.findings, entries);
242
+ r.findings = a.kept;
243
+ accepted.push(...a.accepted);
244
+ for (const f of a.accepted)
245
+ ignored[f.ruleId] = (ignored[f.ruleId] ?? 0) + 1;
246
+ }
247
+ const ranked = rank(results.flatMap((r) => r.findings));
248
+ const report = buildMapReport(results, ranked, o.version, new Date(), accepted, { cloudKeys, people: people ? { answeredAt: people.answeredAt, ...scorePeople(people.answers) } : null });
249
+ writeFileSync(join(o.outDir, "map.json"), JSON.stringify(report, null, 2) + "\n");
250
+ writeFileSync(join(o.outDir, "map.html"), mapHtml(report, log.entries));
251
+ writeFileSync(join(o.outDir, "map.cbom.json"), JSON.stringify(buildCbom(ranked.map(toFinding), { repo: "encryption map", toolVersion: o.version }), null, 2) + "\n");
252
+ process.stdout.write(mapText(report) + `\n\nWrote ${join(o.outDir, "map.html")}, map.json, map.cbom.json and activity.log. They stay on this machine.\n`);
253
+ // Counts for the anonymized summary. Targets never leave this function.
254
+ const rules = {};
255
+ const algorithms = {};
256
+ for (const f of ranked) {
257
+ rules[f.ruleId] = (rules[f.ruleId] ?? 0) + 1;
258
+ const a = (algorithms[f.algorithm] ??= { count: 0, quantumVulnerable: 0 });
259
+ a.count++;
260
+ if (f.risk === "quantum-vulnerable")
261
+ a.quantumVulnerable++;
262
+ }
263
+ for (const s of report.strengths)
264
+ pqcCounts[s.algorithm] = (pqcCounts[s.algorithm] ?? 0) + 1;
265
+ // Cloud key custody counts by rule only. People and process answers are never part of the summary.
266
+ for (const a of cloudKeys)
267
+ rules[a.ruleId] = (rules[a.ruleId] ?? 0) + 1;
268
+ const errors = [...new Set(results.flatMap((r) => r.errors.map((e) => e.kind)))];
269
+ const facts = { command: "map", areas, rules, algorithms, quantumSafe: pqcCounts, fixed: {}, ignored, replacements: {}, errors };
270
+ return { code: 0, report, facts, stateKey: `map:${resolve(o.cwd)}`, state: { rules, pqc: pqcCounts } };
271
+ }
package/dist/map-types.js CHANGED
@@ -1,16 +1,16 @@
1
- // Types for the encryption map: one picture of encryption across code, websites and machines.
2
- export const TIER_TITLES = {
3
- 1: "Broken now",
4
- 2: "Recorded now, read later",
5
- 3: "Long-lived signatures",
6
- 4: "Everything else",
7
- };
8
- export const TIER_NOTES = {
9
- 1: "Weak today, without any quantum computer. Fix these first.",
10
- 2: "Internet-facing key exchange with no quantum-safe option. Traffic recorded today can be decrypted once quantum computers arrive.",
11
- 3: "Signatures that must stay trusted for years. NIST deprecates these methods after 2030.",
12
- 4: "Uses RSA or elliptic-curve encryption. NIST disallows these after 2035.",
13
- };
14
- export function emptyResult(area) {
15
- return { area, findings: [], strengths: [], errors: [], checked: [], skipped: [] };
16
- }
1
+ // Types for the encryption map: one picture of encryption across code, websites and machines.
2
+ export const TIER_TITLES = {
3
+ 1: "Broken now",
4
+ 2: "Recorded now, read later",
5
+ 3: "Long-lived signatures",
6
+ 4: "Everything else",
7
+ };
8
+ export const TIER_NOTES = {
9
+ 1: "Weak today, without any quantum computer. Fix these first.",
10
+ 2: "Internet-facing key exchange with no quantum-safe option. Traffic recorded today can be decrypted once quantum computers arrive.",
11
+ 3: "Signatures that must stay trusted for years. NIST deprecates these methods after 2030.",
12
+ 4: "Uses RSA or elliptic-curve encryption. NIST disallows these after 2035.",
13
+ };
14
+ export function emptyResult(area) {
15
+ return { area, findings: [], strengths: [], errors: [], checked: [], skipped: [] };
16
+ }