| 1 | #!/usr/bin/env node |
| 2 | // Enumerates every PE file in a Windows signing payload (the flat Go |
| 3 | // executables plus the Electron app/ tree) into signing-files.txt, the list |
| 4 | // the SignPath contract and the Authenticode verifier consume. |
| 5 | // |
| 6 | // usage: node desktop/packaging/signing-files.mjs <payload-dir> [--check] |
| 7 | import { existsSync, readFileSync, writeFileSync } from "node:fs"; |
| 8 | import { join, resolve } from "node:path"; |
| 9 | import { parseSigningFileList, PRODUCT, signingFileList, walkFiles, WINDOWS_FLAT_PAYLOAD } from "./lib.mjs"; |
| 10 | |
| 11 | const [dirArg, mode] = process.argv.slice(2); |
| 12 | if (!dirArg || (mode && mode !== "--check")) { |
| 13 | console.error("usage: signing-files.mjs <payload-dir> [--check]"); |
| 14 | process.exit(2); |
| 15 | } |
| 16 | const dir = resolve(dirArg); |
| 17 | const listPath = join(dir, "signing-files.txt"); |
| 18 | const files = signingFileList(walkFiles(dir)); |
| 19 | const problems = []; |
| 20 | for (const name of WINDOWS_FLAT_PAYLOAD) if (!files.includes(name)) problems.push(`flat payload executable is missing: ${name}`); |
| 21 | if (!files.includes(`app/${PRODUCT.executable}.exe`)) problems.push(`Electron shell is missing: app/${PRODUCT.executable}.exe`); |
| 22 | if (problems.length > 0) { |
| 23 | for (const problem of problems) console.error(`signing-files: ${problem}`); |
| 24 | process.exit(1); |
| 25 | } |
| 26 | |
| 27 | if (mode === "--check") { |
| 28 | if (!existsSync(listPath)) { |
| 29 | console.error(`signing-files: ${listPath} is missing`); |
| 30 | process.exit(1); |
| 31 | } |
| 32 | const recorded = parseSigningFileList(readFileSync(listPath, "utf8")); |
| 33 | const missing = recorded.filter((name) => !files.includes(name)); |
| 34 | const extra = files.filter((name) => !recorded.includes(name)); |
| 35 | if (missing.length > 0 || extra.length > 0) { |
| 36 | for (const name of missing) console.error(`signing-files: listed but absent: ${name}`); |
| 37 | for (const name of extra) console.error(`signing-files: present but unlisted: ${name}`); |
| 38 | process.exit(1); |
| 39 | } |
| 40 | console.log(`signing-files: ${files.length} PE files match ${listPath}`); |
| 41 | } else { |
| 42 | writeFileSync(listPath, files.join("\n") + "\n"); |
| 43 | console.log(`signing-files: wrote ${files.length} PE files to ${listPath}`); |
| 44 | } |
| 45 |