Skip to content

Commit d42f3f1

Browse files
committed
fix(windows): pass the sealing key to nsbundle_pack via the environment
Command lines show up in process lists and audit logs; tools that don't document NS_BUNDLE_KEY_HEX in --help still get --key-hex.
1 parent d265e49 commit d42f3f1

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎lib/services/windows-project-service.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,21 @@ export class WindowsProjectService
562562
"--input", path.join(appProjectDir, "app"),
563563
"--output", path.join(appProjectDir, "app.nsbundle"),
564564
];
565-
// Without a user key, seal with a fresh per-build key the app template embeds.
566-
const keyArgs = keyHex ? ["--key-hex", keyHex] : ["--write-key", keyPath];
567565
this.$logger.info(`Running nsbundle_pack (source protection): ${packExe}`);
568566
try {
569-
const spawnOptions = { cwd: platformData.projectRoot };
567+
const spawnOptions: any = { cwd: platformData.projectRoot };
568+
// Without a user key, seal with a fresh per-build key the app template embeds.
569+
let keyArgs = ["--write-key", keyPath];
570+
if (keyHex) {
571+
// command lines show up in process lists and audit logs; older tools only take --key-hex
572+
const help = await this.$childProcess.spawnFromEvent(packExe, ["--help"], "close", spawnOptions, { throwError: false });
573+
if (/NS_BUNDLE_KEY_HEX/.test(`${help?.stdout}${help?.stderr}`)) {
574+
keyArgs = [];
575+
spawnOptions.env = { ...process.env, NS_BUNDLE_KEY_HEX: keyHex };
576+
} else {
577+
keyArgs = ["--key-hex", keyHex];
578+
}
579+
}
570580
let result = await this.$childProcess.spawnFromEvent(packExe, [...args, ...keyArgs], "close", spawnOptions, { throwError: false });
571581
if (!keyHex && result && result.exitCode !== 0 && /--write-key/.test(result.stderr || "")) {
572582
// A framework from before per-build keys: seal with its shared default key.

0 commit comments

Comments
 (0)