Signing and sharing
pocketone desktop build gives you apps that run on the machine that built them. Before you send them to other people,
sign them, so each operating system knows the app comes from you and hasn't been changed since:
| Platform | Unsigned, your users see | To sign, you need |
|---|---|---|
| macOS | "can't be opened", until they approve it in System Settings | An Apple Developer account and a Mac |
| Windows | A SmartScreen "Windows protected your PC" warning | A code-signing certificate |
| Linux | Nothing; Linux doesn't check | Optional: a GPG key, to publish a signature |
Let desktop build sign
Add a sign section to pocketone.yaml, and every pocketone desktop build signs what it built, on your machine,
with your certificates. Name only the platforms you sign for:
desktop:
name: Hello
id: dev.pocketone.hello
sign:
macos:
identity: "Developer ID Application: Your Name (ABCDE12345)"
notary_profile: pocketone-notary # omit to sign without notarizing
windows:
# any command that signs {file} in place
command: signtool sign /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 /a {file}
linux:
gpg_key: [email protected]
- macOS: it signs each
.appwith your Developer ID and the hardened runtime, puts it in a.dmg, signs the DMG, sends it to Apple to notarize, and staples the result to both. You get the raw.appand the.dmg. - Windows: it runs your command on each
.exe, with{file}replaced by its path. Usesigntool,osslsigncodeor your signing service's tool, whichever fits your certificate. - Linux: it writes
<name>.sha256and a detached<name>.ascGPG signature beside each binary.
Before it builds anything, it checks that the tools are installed, that the identity is in your keychain and that the
GPG key exists, so a missing piece fails in a second, not after the build. pocketone desktop build --no-sign skips
the section, for a quick build to try out.
Signing happens on your machine, not in the build image, because that's where your keychain and certificates are. So
macOS builds are signed, notarized and put in a DMG only when you build on a Mac; built elsewhere, they're unsigned
.app bundles. Windows and Linux builds sign anywhere their tools run (signtool only runs on Windows;
osslsigncode runs everywhere).
The sections below are the one-time setup for each platform, and the commands desktop build runs, if you'd rather
sign by hand.
macOS
macOS wants two things for an app downloaded from the internet: a Developer ID signature, and notarization, where Apple scans the app and records that it did. You do both on a Mac, with the tools that come with Xcode.
Once: get a Developer ID certificate
-
Join the Apple Developer Program (paid, yearly).
-
In Xcode, open Settings → Accounts, add your Apple ID, select your team and choose Manage Certificates. Click + and pick Developer ID Application. Xcode creates the certificate and puts it in your keychain.
-
Check that it's there and copy its name:
security find-identity -v -p codesigning # 1) 3F2A… "Developer ID Application: Your Name (ABCDE12345)"ABCDE12345is your team ID. -
Create an app-specific password for your Apple ID (Sign-In and Security → App-Specific Passwords), and save it for the notary tool under a profile name:
xcrun notarytool store-credentials pocketone-notary \ --apple-id [email protected] --team-id ABCDE12345 --password <app-specific password>
By hand: sign, notarize, staple
desktop build does this for you with a sign.macos section. By hand, for each macOS build (dist/darwin-arm64/Hello.app, dist/darwin-amd64/Hello.app):
-
Sign with your Developer ID, the hardened runtime (
--options runtime, which notarization requires) and a secure timestamp.--forcereplaces the ad hoc signature the build added:codesign --force --options runtime --timestamp \ --sign "Developer ID Application: Your Name (ABCDE12345)" dist/darwin-arm64/Hello.app codesign --verify --strict --verbose=2 dist/darwin-arm64/Hello.app -
Notarize: zip the app and send it to Apple. It usually takes a few minutes:
ditto -c -k --keepParent dist/darwin-arm64/Hello.app Hello.zip xcrun notarytool submit Hello.zip --keychain-profile pocketone-notary --waitIf it says
Invalid,xcrun notarytool log <submission id> --keychain-profile pocketone-notaryshows why. -
Staple the result to the app, so it opens even when the user is offline, and check it:
xcrun stapler staple dist/darwin-arm64/Hello.app spctl --assess --type execute --verbose dist/darwin-arm64/Hello.app # dist/darwin-arm64/Hello.app: accepted # source=Notarized Developer ID -
Package the stapled app to share it. A zip:
ditto -c -k --keepParent dist/darwin-arm64/Hello.app Hello-macos-arm64.zipor a disk image, which you sign too:
hdiutil create -volname Hello -srcfolder dist/darwin-arm64/Hello.app -ov -format UDZO Hello.dmg codesign --timestamp --sign "Developer ID Application: Your Name (ABCDE12345)" Hello.dmg
One download for both kinds of Mac: join the two executables with lipo before you sign, and ship one app.
cp -R dist/darwin-arm64/Hello.app Hello.app
lipo -create dist/darwin-arm64/Hello.app/Contents/MacOS/Hello dist/darwin-amd64/Hello.app/Contents/MacOS/Hello \
-output Hello.app/Contents/MacOS/Hello
Without an Apple Developer account
Without a Developer ID, macOS still runs your app, but anyone who downloads it is warned first. What they see depends on how it's signed:
| Your app is | Someone who downloads it sees |
|---|---|
Signed ad hoc (what desktop build does with no sign.macos) |
"Apple could not verify it is free of malware", and the app doesn't open |
| Signed with a self-signed certificate | The same warning |
| Signed with a Developer ID, not notarized | A similar warning |
| Signed with a Developer ID and notarized | Only "downloaded from the internet, open it?" |
The warning only appears for downloaded apps, which macOS marks as quarantined. An app you build and run on your own Mac opens without it.
Opening it anyway. For yourself, testers and people you know, that's fine. They:
- Open the app and dismiss the warning.
- Go to System Settings → Privacy & Security, scroll to Security and click Open Anyway next to the app.
- Confirm, and the app opens from then on.
Or, if they're comfortable with Terminal, they remove the quarantine mark, and the app opens normally:
xattr -dr com.apple.quarantine /Applications/Hello.app
Self-signing. You can make your own code-signing certificate: in Keychain Access, choose Keychain Access →
Certificate Assistant → Create a Certificate, set Certificate Type to Code Signing, and then mark it
Always Trust for code signing (double-click it, open Trust). Its name then goes in sign.macos.identity, without
notary_profile, since Apple only notarizes Developer ID apps.
It doesn't remove the warning: macOS can't trust a certificate it doesn't know, so a self-signed app gets the same warning as an ad hoc one. What it gives you is the same identity from one version to the next, so macOS remembers what your users allowed the app to do (files, camera, keychain items) when they update.
For an app you give to the public, only a Developer ID and notarization open it without warnings.
Windows
Windows checks an Authenticode signature. You need a code-signing certificate from a certificate authority, such as DigiCert, Sectigo or SSL.com. Certificates issued today keep their key on a hardware token or in the CA's cloud signing service rather than in a file, so how you sign depends on which you get.
Once: get a certificate
- Organization validation (OV): the CA checks that your business exists. For an individual, pick a certificate issued to you by name.
- Extended validation (EV): a stricter check, for businesses.
- A cloud signing service, such as Azure Trusted Signing, signs without a token, for organizations it can verify.
Either way, a new certificate starts with no reputation: SmartScreen may still warn for a while, until enough people have installed your signed app.
By hand: sign with signtool
On Windows, with the Windows SDK installed (it includes signtool) and your certificate on its token or in the
certificate store:
signtool sign /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 /a dist\windows-amd64\Hello.exe
signtool verify /pa /v dist\windows-amd64\Hello.exe
/a picks the best certificate it finds; /sha1 <thumbprint> picks one exactly. A cloud signing service gives you
its own signtool plugin or tool; follow its instructions for the same step. Sign windows-arm64 the same way.
From a Mac or Linux
osslsigncode signs Windows executables on macOS and Linux, if your certificate's key is in a file or on a token it can reach:
osslsigncode sign -pkcs12 certificate.pfx -pass "$PFX_PASSWORD" -n "Hello" \
-t http://timestamp.digicert.com -in dist/windows-amd64/Hello.exe -out Hello.exe
Linux
Linux runs the binary you give it; there's no signature check to pass. What you can do is let people check the download is yours and intact:
cd dist/linux-amd64
sha256sum Hello > Hello.sha256 # a checksum to publish next to the download
gpg --armor --detach-sign Hello # Hello.asc: a signature anyone with your public key can check
Users check with sha256sum -c Hello.sha256 and gpg --verify Hello.asc Hello. Packaging the app as a .deb,
Flatpak or AppImage, where the package or repository is signed, also works.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.