Signing with hooks in Squirrel maker results in wrong sign tool being used
Pre-flight checklist
- [X] I have read the contribution documentation for this project.
- [X] I agree to follow the code of conduct that this project uses.
- [X] I have searched the issue tracker for a bug that matches the one I want to file, without success.
Electron Forge version
7.4.0
Electron version
29.1.0
Operating system
Ubuntu 22.04.4 LTS (WSL)
Last known working Electron Forge version
No response
Expected behavior
When providing custom hook module to the Squirrel maker under winSign config, it should use the custom logic and not the signtool.exe.
Actual behavior
When providing custom hook module to the Squirrel maker under winSign config, it attempts to use signtool.exe.
Steps to reproduce
- Setup basic ElectronJS app with all defaults (skeleton app will do fine).
- Add Squirrel maker configuration such as that provided below.
- Add custom code signing logic (see below for js files but could just be as simple as console.log).
- Attempt to publish package.
As you can see in the build log, the packager configuration for this works well and picks up the hook:
2024-08-30T20:18:02.600Z electron-packager Running @electron/windows-sign with the options {"debug":true,"hookModulePath":"/__w/opa/opa/packages/file-signing/dist/index.js","appDirectory":"/__w/opa/opa/apps/.tmp/electron-packager/tmp-UEJqzL"}
2024-08-30T20:18:02.601Z electron-windows-sign Called with options {
options: {
debug: true,
hookModulePath: '/__w/opa/opa/packages/file-signing/dist/index.js',
appDirectory: '/__w/opa/opa/apps/.tmp/electron-packager/tmp-UEJqzL'
}
}
2024-08-30T20:18:02.604Z electron-windows-sign Signing with hook
This results in signed executables, ddls etc being generated for the application. However, when trying to sign the installer with the Squirrel maker, it does not use that hook:
❯ Making a squirrel distributable for win32/x64
2024-08-30T20:19:07.363Z electron-windows-sign Calling /usr/local/bin/node with options: [ '--experimental-sea-config', 'sea-config.json' ]
2024-08-30T20:19:07.370Z electron-windows-sign Spawning /usr/local/bin/node with --experimental-sea-config,sea-config.json
2024-08-30T20:19:07.377Z electron-windows-sign Spawn /usr/local/bin/node stderr: Wrote single executable preparation blob to sea.blob
2024-08-30T20:19:07.380Z electron-windows-sign Spawn /usr/local/bin/node: Child process exited with code 0
2024-08-30T20:19:07.380Z electron-windows-sign stdout:
2024-08-30T20:19:07.380Z electron-windows-sign stderr: Wrote single executable preparation blob to sea.blob
2024-08-30T20:19:07.380Z electron-windows-sign Creating signtool.exe in /__w/opa/opa/node_modules/electron-winstaller/vendor
2024-08-30T20:19:07.519Z electron-windows-sign Spawning /__w/opa/opa/node_modules/@electron/windows-sign/vendor/signtool.exe with remove,/s,/__w/opa/opa/node_modules/electron-winstaller/vendor/signtool.exe
An unhandled exception has occurred inside Forge:
spawn /__w/opa/opa/node_modules/@electron/windows-sign/vendor/signtool.exe EACCES
Error: spawn /__w/opa/opa/node_modules/@electron/windows-sign/vendor/signtool.exe EACCES
at Process.ChildProcess._handle.onexit (node:internal/child_process:286:19)
at onErrorNT (node:internal/child_process:484:16)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "publish" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
I'm struggling to debug this but it looks like the wrong options are being passed from the Squirrel maker to the windows signing.
I also looked for hooks so I could do something there but that didn't work either. The goal here is to sign the installer before uploading through the S3 publisher.
Additional information
Custom Signing Logic: dist.zip Build Log: buildlog.txt
forge.config.ts
import path from "path";
import type { ForgeConfig } from "@electron-forge/shared-types";
import { MakerSquirrel } from "@electron-forge/maker-squirrel";
import { AutoUnpackNativesPlugin } from "@electron-forge/plugin-auto-unpack-natives";
import { WebpackPlugin } from "@electron-forge/plugin-webpack";
import { FusesPlugin } from "@electron-forge/plugin-fuses";
import { FuseV1Options, FuseVersion } from "@electron/fuses";
import { mainConfig } from "./webpack.main.config";
import { rendererConfig } from "./webpack.renderer.config";
import { AUTO_UPDATER_FEED_URL, AUTO_UPDATER_BUCKET_NAME, ICO_URL } from "./src/_constants";
const basePath = (fileName: string) => path.join(process.cwd(), "resources", fileName);
const srcPath = (fileName: string) => path.join(process.cwd(), "src", fileName);
const config: ForgeConfig = {
packagerConfig: {
asar: true,
icon: basePath("appicon.ico"),
extraResource: [basePath("appicon.ico")],
tmpdir: path.join(__dirname, "..", ".tmp"),
overwrite: true,
windowsSign: {
debug: true,
hookModulePath: path.join(__dirname, "../../packages/file-signing/dist/index.js"),
}
},
rebuildConfig: {},
makers: [
new MakerSquirrel({
name: "ApplicationName",
...(process.env.NO_REMOTE_RELEASES ? {} : { remoteReleases: AUTO_UPDATER_FEED_URL }),
iconUrl: ICO_URL,
loadingGif: basePath("appsplash.gif"),
setupIcon: basePath("appicon.ico"),
windowsSign: {
debug: true,
hookModulePath: path.join(__dirname, "../../packages/file-signing/dist/index.js"),
}
}),
],
publishers: [
{
name: "@electron-forge/publisher-s3",
config: {
bucket: AUTO_UPDATER_BUCKET_NAME,
},
},
],
plugins: [
new AutoUnpackNativesPlugin({}),
new WebpackPlugin({
mainConfig,
renderer: {
config: rendererConfig,
entryPoints: [
{
html: srcPath("index.html"),
js: srcPath("renderer.ts"),
name: "main_window",
preload: {
js: srcPath("preload.ts"),
},
},
],
},
}),
// Fuses are used to enable/disable various Electron functionality
// at package time, before code signing the application
new FusesPlugin({
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: false,
[FuseV1Options.EnableCookieEncryption]: true,
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
[FuseV1Options.EnableNodeCliInspectArguments]: false,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
[FuseV1Options.OnlyLoadAppFromAsar]: true,
}),
],
};
export default config;
Worth noting that I have also tried setting the maker config as the below which did not work either:
{
name: "@electron-forge/maker-squirrel",
config: {
name: "GlobalAccessPaxtonNet2",
...(process.env.NO_REMOTE_RELEASES ? {} : { remoteReleases: AUTO_UPDATER_FEED_URL }),
iconUrl: ICO_URL,
loadingGif: basePath("appicon.gif"),
setupIcon: basePath("appicon.ico"),
windowsSign: {
debug: true,
hookModulePath: path.join(__dirname, "../../packages/file-signing/dist/index.js"),
}
},
},
Here too
Update: spawn /__w/opa/opa/node_modules/@electron/windows-sign/vendor/signtool.exe EACCES Error: spawn /__w/opa/opa/node_modules/@electron/windows-sign/vendor/signtool.exe EACCES
I couldn't find documentation for this, but I believe you cannot run this on non-windows OS
I face the same issue. I have windowsSign with hookFunction parameter, however it does not trigger it at all.
Having the same issue - also wondering if anyone has found a workaround for this in the meantime?
Related: https://github.com/electron/windows-installer/issues/548
I am hitting a similar issue, I am attempting to provide the signToolPath, but no matter what it is still using the build-in
windowsSign: {
signToolPath: path.resolve('C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.26100.0\\x64\\signtool.exe'),
signWithParams: [
'/csp "DigiCert Signing Manager KSP"',
'/kc key1',
`/f ${windowsSigningCertPath}`,
'/tr http://timestamp.digicert.com',
'/td SHA256',
'/fd SHA256',
].join(' '),
},
No matter what I do it always uses the bundled sign tool.
System.AggregateException: One or more errors occurred. ---> System.Exception: Failed to sign, command invoked was:
'C:\Users\x\dev\x\dist\desktop-build\node_modules\electron-winstaller\vendor\signtool.exe sign windows-sign
I moved this configuration to the root as suggested in another thread, but that didn't help.
Not 100% sure if my issue is the same, but it might be since no matter what it continues to default to the packaged sign tool.
Having the same issue - also wondering if anyone has found a workaround for this in the meantime?
Related: electron/windows-installer#548
One workaround that worked for me was to use the postMake hook in the forge config file to get the file path for each published artifact, then invoke the sign tool "manually".
Example:
// forge config
hooks: {
postMake: async (forgeConfig, options) => {
const artifactPaths = options.flatMap((o) => o.artifacts);
for (const filePath of artifactPaths) {
invokeCustomSignTool(filePath);
}
},
}
// Manually invoke sign tool
function invokeCustomSignTool(filePath: string) {
// Only sign .exe, not the nupkg, otherwise you get errors
if (![".exe"].some((ext) => filePath.endsWith(ext))) {
console.log("Skipping signing file:", filePath);
return;
}
console.log("Signing file:", filePath);
// args: https://learn.microsoft.com/en-us/dotnet/framework/tools/signtool-exe
const signCommand = `"${process.env.AZURE_SIGN_TOOL_PATH}" sign /v /debug /fd SHA256 /tr "http://timestamp.acs.microsoft.com" /td SHA256 /dlib "${process.env.AZURE_CODE_SIGNING_DLIB}" /dmdf "${process.env.AZURE_METADATA_JSON}" "${filePath}"`;
console.log("Sign command:", signCommand);
try {
// inherit stdout, will log
execSync(signCommand, { stdio: "inherit" });
} catch (error) {
console.error("Error signing file:", filePath, error);
throw error;
}
}