Signing a Windows app
Code signing is a security technology that you use to certify that an app was created by you.
Last updated
Was this helpful?
Code signing is a security technology that you use to certify that an app was created by you.
Last updated
Was this helpful?
Starting June 1, 2023 at 00:00 UTC, private keys for code signing certificates need to be stored on a hardware storage module compliant with FIPS 140 Level 2, Common Criteria EAL 4+ or equivalent. In practice, this means that software-based OV certificates used in the steps below will no longer be available for purchase. For instructions on how to sign applications with newer token-based certificates, consult your Certificate Authority's documentation.
On Windows, apps are signed using , which is included in Visual Studio. Install Visual Studio to get the signing utility (the free is enough).
You can get a code signing certificate from many vendors. Prices vary, so it may be worth your time to shop around. Popular vendors include:
Amongst others, please shop around to find one that suits your needs! 😄
Keep your certificate password private
Your certificate password should be a secret. Do not share it publicly or commit it to your source code.
On Windows, Electron apps are signed on the installer level at the Make step.
For example, if you are creating a Squirrel.Windows installer:
In your project directory, do the following:
Install the dotenv-cli
package: npm i -D dotenv-cli
Update @electron/windows-sign
to version 1.2.0 or later: npm update @electron/windows-sign
.env.trustedsigning
fileCreate a file .env.trustedsigning
in your project root with the following content:
Fill in the credentials for your Azure App Registration user into the first three variables.
Adjust the other variables to be the absolute paths to the metadata.json
, Azure.CodeSigning.Dlib.dll
and signtool.exe
files that you created or installed as part of the prerequisites.
.gitignore
Add .env.trustedsigning
to your .gitignore
file. You should never commit login credentials to version control.
In addition, add electron-windows-sign.log
to .gitignore
. This file will be created automatically during the signing process.
windowsSign.ts
fileCreate a file windowsSign.ts
in your project root with the following content:
Some notes:
We specify the /v
and /debug
parameters even though they aren't technically required. This ensures that warnings are logged if timestamping fails.
Do not use the debug
parameter on the WindowsSignOptions
. Similarly, do not enable the DEBUG
environment variable for electron-windows-sign
. (If you do either of them, the debug
npm package will log all debug messages to stderr. An executable in @electron/windows-sign
will interpret the existence of messages printed to stderr as a signing failure. Then your build will fail.)
forge.config.ts
In your forge.config.ts
, add the following:
When you call scripts such as electron-forge make
or electron-forge publish
, you will now have to prefix them with dotenv -e .env.trustedsigning --
. This loads the environment variables from the .env.trustedsigning
file.
For example, your npm scripts in your package.json
might then look like this:
Once you have a Personal Information Exchange (.pfx
) file for your certificate, you can sign and installers in Electron Forge with the certificateFile
and certificatePassword
fields in their respective configuration objects.
is Microsoft's modern cloud-based alternative to EV certificates. It is the cheapest option for code signing on Windows, and it gets rid of SmartScreen warnings.
As of November 2024, Azure Trusted Signing is available to organizations with 3+ years of verifiable business history and to individuals. Microsoft is to organizations with a shorter history, too. If you're reading this at a later point, it could make sense to check.
First, create an Azure account and set up Azure Trusted Signing in your account as described .
Then install the dependencies for local code signing as described . Also create the required metadata.json
file in an arbitrary location on your computer.
Ensure that none of the paths have spaces in them. Otherwise, signing will fail. (@electron/windows-sign
issue currently prevents quoting of paths with spaces.)