2022-06-22 04:17:48 -04:00
---
title: 'Code Signing'
description: 'Code signing is a security technology that you use to certify that an app was created by you.'
slug: code-signing
hide_title: false
---
2018-05-01 17:56:44 -07:00
2018-06-16 03:43:03 +03:00
Code signing is a security technology that you use to certify that an app was
2022-06-22 04:17:48 -04:00
created by you. You should sign your application so it does not trigger any
operating system security checks.
2018-05-02 11:52:52 +10:00
2022-06-22 04:17:48 -04:00
On macOS, the system can detect any change to the app, whether the change is
2018-05-02 11:52:52 +10:00
introduced accidentally or by malicious code.
2020-04-16 10:30:33 -07:00
On Windows, the system assigns a trust level to your code signing certificate
which if you don't have, or if your trust level is low, will cause security
2022-06-22 04:17:48 -04:00
dialogs to appear when users start using your application. Trust level builds
2020-04-16 10:30:33 -07:00
over time so it's better to start code signing as early as possible.
2018-05-01 17:56:44 -07:00
2019-12-13 11:16:20 -05:00
While it is possible to distribute unsigned apps, it is not recommended. Both
2020-04-16 10:30:33 -07:00
Windows and macOS will, by default, prevent either the download or the execution
of unsigned applications. Starting with macOS Catalina (version 10.15), users
have to go through multiple manual steps to open unsigned applications.
2018-05-01 17:56:44 -07:00
2022-06-22 04:17:48 -04:00

2018-05-01 17:56:44 -07:00
2019-12-13 11:16:20 -05:00
As you can see, users get two options: Move the app straight to the trash or
cancel running it. You don't want your users to see that dialog.
2018-05-01 17:56:44 -07:00
2018-06-16 03:43:03 +03:00
If you are building an Electron app that you intend to package and distribute,
2022-06-22 04:17:48 -04:00
it should be code signed.
2018-05-01 17:56:44 -07:00
2022-06-22 04:17:48 -04:00
## Signing & notarizing macOS builds
2018-05-01 17:56:44 -07:00
2022-06-22 04:17:48 -04:00
Properly preparing macOS applications for release requires two steps. First, the
app needs to be code signed. Then, the app needs to be uploaded to Apple for a
process called **notarization** , where automated systems will further verify that
2020-04-16 10:30:33 -07:00
your app isn't doing anything to endanger its users.
To start the process, ensure that you fulfill the requirements for signing and
notarizing your app:
2018-05-01 17:56:44 -07:00
2023-01-16 01:22:49 -08:00
1. Enroll in the [Apple Developer Program][] (requires an annual fee)
2. Download and install [Xcode][] - this requires a computer running macOS
3. Generate, download, and install [signing certificates][]
2018-05-01 17:56:44 -07:00
2020-04-16 10:30:33 -07:00
Electron's ecosystem favors configuration and freedom, so there are multiple
ways to get your application signed and notarized.
2022-06-22 04:17:48 -04:00
### Using Electron Forge
2020-04-16 10:30:33 -07:00
If you're using Electron's favorite build tool, getting your application signed
and notarized requires a few additions to your configuration. [Forge ](https://electronforge.io ) is a
2023-01-16 01:22:49 -08:00
collection of the official Electron tools, using [`electron-packager` ][],
[`@electron/osx-sign` ][], and [`@electron/notarize` ][] under the hood.
2020-04-16 10:30:33 -07:00
2022-11-11 11:42:27 -08:00
Detailed instructions on how to configure your application can be found in the
[Signing macOS Apps ](https://www.electronforge.io/guides/code-signing/code-signing-macos ) guide in
the Electron Forge docs.
2020-04-16 10:30:33 -07:00
2022-06-22 04:17:48 -04:00
### Using Electron Packager
2020-04-16 10:30:33 -07:00
2022-09-21 13:49:22 -07:00
If you're not using an integrated build pipeline like Forge, you
2023-01-16 01:22:49 -08:00
are likely using [`electron-packager` ][], which includes [`@electron/osx-sign` ][] and
[`@electron/notarize` ][].
2020-04-16 10:30:33 -07:00
If you're using Packager's API, you can pass [in configuration that both signs
2022-06-22 04:17:48 -04:00
and notarizes your application](https://electron.github.io/electron-packager/main/interfaces/electronpackager.options.html).
2020-04-16 10:30:33 -07:00
```js
const packager = require('electron-packager')
packager({
dir: '/path/to/my/app',
2022-11-11 11:42:27 -08:00
osxSign: {},
2020-04-16 10:30:33 -07:00
osxNotarize: {
appleId: 'felix@felix .fun',
appleIdPassword: 'my-apple-id-password'
}
})
```
2022-06-22 04:17:48 -04:00
### Signing Mac App Store applications
2019-12-13 11:16:20 -05:00
2023-01-16 01:22:49 -08:00
See the [Mac App Store Guide][].
2018-05-01 17:56:44 -07:00
2022-06-22 04:17:48 -04:00
## Signing Windows builds
2018-05-01 17:56:44 -07:00
2018-05-02 11:12:15 +10:00
Before signing Windows builds, you must do the following:
2019-04-18 21:20:14 +05:30
1. Get a Windows Authenticode code signing certificate (requires an annual fee)
2020-04-16 10:30:33 -07:00
2. Install Visual Studio to get the signing utility (the free [Community
Edition](https://visualstudio.microsoft.com/vs/community/) is enough)
2018-05-02 11:12:15 +10:00
2020-04-16 10:30:33 -07:00
You can get a code signing certificate from a lot of resellers. Prices vary, so
it may be worth your time to shop around. Popular resellers include:
2018-05-02 11:12:15 +10:00
2022-06-22 04:17:48 -04:00
- [digicert ](https://www.digicert.com/code-signing/microsoft-authenticode.htm )
- [Sectigo ](https://sectigo.com/ssl-certificates-tls/code-signing )
- Amongst others, please shop around to find one that suits your needs! 😄
:::caution Keep your certificate password private
Your certificate password should be a **secret** . Do not share it publicly or
commit it to your source code.
:::
### Using Electron Forge
2022-09-21 13:49:22 -07:00
Electron Forge is the recommended way to sign your `Squirrel.Windows` and `WiX MSI` installers. Detailed instructions on how to configure your application can be found in the [Electron Forge Code Signing Tutorial ](https://www.electronforge.io/guides/code-signing/code-signing-macos ).
2018-05-02 11:12:15 +10:00
2022-06-22 04:17:48 -04:00
### Using electron-winstaller (Squirrel.Windows)
2023-01-16 01:22:49 -08:00
[`electron-winstaller` ][] is a package that can generate Squirrel.Windows installers for your
2022-06-22 04:17:48 -04:00
Electron app. This is the tool used under the hood by Electron Forge's
[Squirrel.Windows Maker][maker-squirrel]. If you're not using Electron Forge and want to use
`electron-winstaller` directly, use the `certificateFile` and `certificatePassword` configuration
options when creating your installer.
```js {10-11}
const electronInstaller = require('electron-winstaller')
// NB: Use this syntax within an async function, Node does not have support for
// top-level await as of Node 12.
try {
await electronInstaller.createWindowsInstaller({
appDirectory: '/tmp/build/my-app-64',
outputDirectory: '/tmp/build/installer64',
authors: 'My App Inc.',
exe: 'myapp.exe',
certificateFile: './cert.pfx',
certificatePassword: 'this-is-a-secret',
})
console.log('It worked!')
} catch (e) {
console.log(`No dice: ${e.message}` )
}
```
2023-01-16 01:22:49 -08:00
For full configuration options, check out the [`electron-winstaller` ][] repository!
2022-06-22 04:17:48 -04:00
### Using electron-wix-msi (WiX MSI)
2023-01-16 01:22:49 -08:00
[`electron-wix-msi` ][] is a package that can generate MSI installers for your
2022-06-22 04:17:48 -04:00
Electron app. This is the tool used under the hood by Electron Forge's [MSI Maker][maker-msi].
If you're not using Electron Forge and want to use `electron-wix-msi` directly, use the
`certificateFile` and `certificatePassword` configuration options
2023-01-16 01:22:49 -08:00
or pass in parameters directly to [SignTool.exe][] with the `signWithParams` option.
2022-06-22 04:17:48 -04:00
```js {12-13}
import { MSICreator } from 'electron-wix-msi'
// Step 1: Instantiate the MSICreator
const msiCreator = new MSICreator({
appDirectory: '/path/to/built/app',
description: 'My amazing Kitten simulator',
exe: 'kittens',
name: 'Kittens',
manufacturer: 'Kitten Technologies',
version: '1.1.2',
outputDirectory: '/path/to/output/folder',
certificateFile: './cert.pfx',
certificatePassword: 'this-is-a-secret',
})
// Step 2: Create a .wxs template file
const supportBinaries = await msiCreator.create()
// 🆕 Step 2a: optionally sign support binaries if you
// sign you binaries as part of of your packaging script
supportBinaries.forEach(async (binary) => {
// Binaries are the new stub executable and optionally
// the Squirrel auto updater.
await signFile(binary)
})
// Step 3: Compile the template to a .msi file
await msiCreator.compile()
```
2023-01-16 01:22:49 -08:00
For full configuration options, check out the [`electron-wix-msi` ][] repository!
2022-06-22 04:17:48 -04:00
### Using Electron Builder
Electron Builder comes with a custom solution for signing your application. You
can find [its documentation here ](https://www.electron.build/code-signing ).
2018-05-02 11:12:15 +10:00
2022-06-22 04:17:48 -04:00
### Signing Windows Store applications
2018-05-02 11:12:15 +10:00
2023-01-16 01:22:49 -08:00
See the [Windows Store Guide][].
2018-05-01 17:56:44 -07:00
2022-06-22 04:17:48 -04:00
[apple developer program]: https://developer.apple.com/programs/
2022-11-11 11:42:27 -08:00
[`@electron/osx-sign` ]: https://github.com/electron/osx-sign
2019-07-19 18:52:11 -07:00
[`electron-packager` ]: https://github.com/electron/electron-packager
2022-11-11 11:42:27 -08:00
[`@electron/notarize` ]: https://github.com/electron/notarize
2018-05-02 11:12:15 +10:00
[`electron-winstaller` ]: https://github.com/electron/windows-installer
2022-11-11 11:42:27 -08:00
[`electron-wix-msi` ]: https://github.com/electron-userland/electron-wix-msi
2022-06-22 04:17:48 -04:00
[xcode]: https://developer.apple.com/xcode
2022-11-11 11:42:27 -08:00
[signing certificates]: https://developer.apple.com/support/certificates/
2022-06-22 04:17:48 -04:00
[mac app store guide]: ./mac-app-store-submission-guide.md
[windows store guide]: ./windows-store-guide.md
[maker-squirrel]: https://www.electronforge.io/config/makers/squirrel.windows
[maker-msi]: https://www.electronforge.io/config/makers/wix-msi
[signtool.exe]: https://docs.microsoft.com/en-us/dotnet/framework/tools/signtool-exe