Skip to content

Code Signing

Carlos Hernandez edited this page Jul 14, 2026 · 2 revisions

Code Signing

embala never implements a signature format. It only shells out to a command you supply, once per built artifact, with $f replaced by that artifact's absolute path. You bring the tool (osslsigncode, signtool, jsign, rcodesign) and the certificate; embala runs it at the right moment in the build.

This means the honest part up front: signing removes the unknown-publisher dialog only for certificates the target machine already trusts. A self-signed cert changes neither SmartScreen nor Gatekeeper for outside users. What actually clears those prompts is reputation (SignPath's OSS program, an EV cert, or download-count reputation earned over time on Windows) and an Apple Developer ID

The [sign] section

Optional. Add to embala.toml:

[sign.windows]
command = "osslsigncode sign -pkcs12 cert.pfx -readpass pw.txt -in $f -out $f.signed && mv $f.signed $f"
signed-stub = "signed-stub.exe"   # optional, path relative to the config file

[sign.macos]
command = "rcodesign sign --p12-file devid.p12 $f"

Fields:

Field Platform Required Meaning
command both yes One shell command line. Must contain $f.
signed-stub windows no Path (relative to the config file) to a pre-signed bare uninstall stub. When set, embala embeds it instead of signing the embedded stub itself.

Rules:

  • $f is substituted with the artifact's shell-quoted absolute path. The command runs via the host shell (sh -c on Unix, cmd /C on Windows) with inherited stdio, so the tool's own output is visible.
  • One command per platform. The same command signs every Windows artifact (and every macOS artifact) in the build, so use a tool that handles all the formats you produce — see tool compatibility.
  • Validation: the command must be non-empty and contain $f, or the build fails at config-parse time (sign.windows: command must be non-empty and contain $f). Unknown fields are rejected.
  • No secrets in the template. command is a build-config value; keep the passphrase in a file (-readpass pw.txt, --storepass, -p @env:...) or a key store, not inline in embala.toml.
  • A nonzero exit from the command fails the build.
  • No [sign] section → no external process runs and the build is byte-reproducible.

What gets signed, and in what order

Platform Artifacts signed
windows the uninstall stub (embedded so the installer writes a signed uninstall.exe), then the finished setup.exe, then the finished .msi
macos the finished .app directory, then the finished .pkg

The .nupkg is never signed (Chocolatey packages aren't Authenticode-signed).

The Windows uninstaller detail is the reason [sign] exists rather than "just run signtool after the build": the uninstall stub is embedded inside setup.exe before setup.exe is assembled, so it has to be signed first. When [sign.windows] is set, embala signs the branded stub — patched with your [setup].icon and the automatic VERSIONINFO exactly as build would (see Setup-Exe § Branding) — (or embeds your signed-stub file) before building setup.exe, so the installer lays down an already-signed, branded uninstall.exe. Branding is applied before the overlay and the outer signature, so it does not change how the finished setup.exe is signed or how its trailer is located. Then it signs the finished setup.exe and .msi normally. Everything else — signing setup.exe and .msi after the build — you can also do by hand with any signtool-equivalent, with no embala involvement: setup.exe survives Authenticode signing structurally (the trailer is located via the PE security directory and 8-byte-aligned so the cert table lands at the unsigned length).

Worked examples

Windows — osslsigncode + PFX (cross-platform)

osslsigncode runs on Linux/macOS, so this is the usual CI path. It refuses in == out, so sign to a sidecar and move it back:

[sign.windows]
command = "osslsigncode sign -pkcs12 cert.pfx -readpass pw.txt -in $f -out $f.signed && mv $f.signed $f"

Caveat: osslsigncode signs PE files (setup.exe, the stub) fine but cannot parse embala's .msi — see tool compatibility. If you build the msi format, use jsign or signtool for Windows instead.

Windows — signtool (on a Windows host)

Native, handles PE and MSI (structured storage) uniformly:

[sign.windows]
command = "signtool sign /fd SHA256 /f cert.pfx /p pass /tr http://timestamp.digicert.com /td SHA256 $f"

Windows — jsign + PFX (one command for everything)

jsign (JVM-based, cross-platform) signs PE and MSI uniformly, so a single command covers the stub, setup.exe, and .msi:

[sign.windows]
command = "jsign --keystore cert.pfx --storepass pass --storetype PKCS12 --tsaurl http://timestamp.digicert.com $f"

This is the recommended Windows command when you build the msi format.

macOS — rcodesign + P12

[sign.macos]
command = "rcodesign sign --p12-file devid.p12 $f"

Requirements and tips:

  • The .app's CFBundleExecutable must be a real Mach-O binary — rcodesign refuses to sign a script-backed bundle. (--pem-file works in place of --p12-file.)
  • The P12 must be PBE-SHA1-3DES with a non-empty password. Export with: openssl pkcs12 -export -legacy -out devid.p12 ...
  • For future notarization, sign with the hardened runtime so the bundle is notarizable as-is:
    command = "rcodesign sign --code-signature-flags runtime --p12-file devid.p12 $f"
    rcodesign timestamps against Apple's TSA by default.

Tool compatibility

embala's .msi is a CFB v4 file (4096-byte sectors, via the msi crate).

Tool PE (setup.exe, stub) embala .msi
osslsigncode ✅ ❌ — fails to parse ("Corrupted Root Directory Entry's Creation Time" / mini-FAT errors)
jsign ✅ ✅ — Windows reports Valid
signtool (Windows) ✅ ✅ — native structured storage

Bottom line for Windows: if you build the msi format, use jsign or signtool (jsign covers stub + setup.exe + msi with one command). Reach for osslsigncode only when you're producing PE artifacts and no msi.

Timestamping

A code signature carries a validity window. Without a countersignature from a timestamp authority (TSA), the signature stops verifying the moment the signing certificate expires — even for artifacts you shipped years earlier. With a timestamp, the signature keeps verifying after cert expiry, because the TSA attests that the signature existed while the cert was valid.

Timestamping is the signing tool's job, not embala's — add the flag to your command:

Tool Flag
osslsigncode -ts http://timestamp.digicert.com
signtool /tr http://timestamp.digicert.com /td SHA256
jsign --tsaurl http://timestamp.digicert.com
rcodesign on by default (Apple's TSA)

For enterprise-internal distribution where you control cert rollout, an alternative is a long-validity self-signed cert (e.g. a 10-year CA) so the signature simply outlives the deployment window; timestamping still doesn't hurt.

SignPath (out-of-band signing service)

SignPath (and similar services) sign artifacts on their infrastructure; you never hold the key. Two cases:

.msi and setup.exe: need nothing from embala. Build unsigned, hand the finished artifact to SignPath, ship what it returns. Both survive post-build Authenticode signing.

The signed uninstaller needs a two-round-trip because the uninstall stub is embedded inside setup.exe before setup.exe exists:

  1. embala dump-stub --config embala.toml --out stub.exe — export the uninstall stub branded exactly as build would patch it (icon + VERSIONINFO from your [setup]/[package]; arch taken from [setup].arch, override with --arch). Use --config — without it (--arch alone) you get the bare stub with the generic icon and no version info, and the uninstall.exe the installer lays down would carry that generic icon even though setup.exe itself looks branded. See Setup-Exe § Branding.
  2. SignPath signs stub.exe.
  3. Point the config at it: signed-stub = "stub.exe" under [sign.windows] (embala still needs a valid command in that section for the finished artifacts — or run those through SignPath too).
  4. embala build — embala embeds the signed, branded stub, so the installer writes a signed uninstall.exe.
  5. SignPath signs the finished setup.exe (and .msi).

Enterprise cert deployment (GPO / MDM)

If you run the fleet, you can distribute your own cert instead of buying reputation. Pushing it to the machine's certificate stores via Group Policy or MDM:

  • Trusted Root Certification Authorities → the OS trusts the cert chain, so a signed MSI/EXE no longer shows the "unknown publisher" dialog.
  • Trusted Publishers → signed MSIs can install silently (no elevation prompt for the publisher) under the matching policy.

What it does not do: it gives you nothing outside your managed fleet. SmartScreen reputation is a Microsoft cloud signal, not a trust-store setting — machines that don't have your cert deployed still see the unknown-publisher experience. Same idea on macOS: an enterprise-deployed cert is not an Apple Developer ID and does not satisfy Gatekeeper for unmanaged Macs.

What signing actually changes

Cert type Windows SmartScreen / dialog macOS Gatekeeper
None (unsigned) "Windows protected your PC" on browser-downloaded MSI/EXE; More info → Run anyway proceeds. Other channels (share, scp, CI) don't prompt. Browser-downloaded .app/.pkg blocked ("cannot be opened"); right-click → Open once, or strip com.apple.quarantine. scp/rsync copies run normally.
Self-signed No change for outside users — still unknown publisher / SmartScreen. Only trusted on machines where you deployed the cert (see GPO/MDM). Not a Developer ID — Gatekeeper still blocks.
SignPath OSS / earned reputation Signed, publisher named; SmartScreen clears once the signing identity accrues reputation (immediate with an EV cert, over download volume otherwise). n/a (Windows program).
EV code-signing Immediate SmartScreen reputation; no unknown-publisher dialog. n/a.
Apple Developer ID + notarization n/a. Gatekeeper allows the app; no override needed. Requires hardened runtime — sign with --code-signature-flags runtime.

The takeaway: [sign] gives you the mechanism. Whether a prompt disappears for your users depends on the certificate's trust, which embala can't manufacture.

Clone this wiki locally