Code signing and Defender
Background
Section titled “Background”Microsoft Defender has flagged an unsigned sofcat.exe as
Trojan:Win32/Bearfoos.A!ml on a machine with stale definitions. The !ml
suffix marks a machine-learning verdict, not a signature match. After a
definitions update the same file scanned clean. Defender’s ML models score
unsigned Go binaries poorly when they also carry no publisher or version
metadata.
just winres embeds a VERSIONINFO resource (company, product, version,
original filename) and an asInvoker manifest in all three executables. That makes
a false positive less likely but does not rule one out. SofCat’s releases are
also Authenticode signed, as described under
Release signing in CI. The rest of this page is for
your own builds.
Report a false positive
Section titled “Report a false positive”Submit the flagged file at https://www.microsoft.com/wdsi/filesubmission: choose “Software developer”, “Incorrectly detected as malware/malicious”, and give the detection name and the release tag. Microsoft usually answers within a few days and ships a definitions fix. A submission clears that one file hash, so each build that gets flagged has to be submitted again. Use it to unblock users. It is not a lasting fix.
Authenticode signing
Section titled “Authenticode signing”What signing changes:
- Defender and SmartScreen reputation attach to the signing identity, not the file hash. A new release signed by an identity Defender already knows inherits that identity’s reputation, so ML false positives become much rarer. An unsigned build starts with no reputation every time.
- The UAC and SmartScreen prompts name a publisher instead of “Unknown publisher”. An EV certificate does not skip the SmartScreen warning outright. Every identity builds reputation through download volume.
- A self-signed certificate changes nothing for other people’s machines.
Options. Prices change, so confirm them before buying:
| Option | Cost | Effort | Notes |
|---|---|---|---|
| Azure Trusted Signing | about US$10 a month (Basic) | Medium: Azure subscription, identity validation (organizations, or individuals in the US/Canada), a CI service principal | Microsoft-run CA, keys stay in Azure, short-lived certificates. jsign --storetype TRUSTEDSIGNING signs from Linux. SofCat’s own releases use it. |
| SignPath Foundation (free for OSS) | Free | Medium: apply, the project must meet their OSS rules (Apache-2.0 qualifies), builds must come from GitHub Actions through their connector, with manual approval per release | The publisher shown is “SignPath Foundation”, not you. |
| OV code-signing certificate (Sectigo, DigiCert, SSL.com and others) | about US$200-400 a year | Medium to high: identity validation, and the key must live on an HSM or a cloud key service (a CA/Browser Forum rule), so CI needs the CA’s cloud signing API | Shows your name. |
| EV code-signing certificate | about US$300-600 a year | High: company validation, hardware or cloud key | Does not skip SmartScreen. Worth it only if a customer requires EV. |
Windows signing hook: SIGN_CMD
Section titled “Windows signing hook: SIGN_CMD”The build signs when SIGN_CMD is set and does nothing about signing when it
is not, so a local just build or just setup still produces unsigned
files. SIGN_CMD is a shell command line; the build appends the
file to sign and runs it.
just buildruns it once, after the threego builds, withbuild/<slug>.exe,build/<slug>-ui.exeandbuild/<slug>-useragent.exeappended, and fails if the command fails.just makecatalogsruns it once, after its builds, withbuild/makecatalogs-windows-amd64.exeandbuild/makecatalogs-windows-arm64.exeappended.just setup, which depends onbuild, appends a[sign.windows]section withcommand = "<SIGN_CMD> $f"to theembala.tomlit renders intobuild/setup/, so embala runs the same command on the uninstaller stub it embeds and then on the finishedsetup.exe(embala README, “Signing”).installer/embala.tomlitself carries no sign section.
SIGN_CMD is also a just variable: just SIGN_CMD=... setup is the same as
setting the environment variable, and the command line wins when both are set.
With Azure Trusted Signing, for example:
SIGN_CMD='jsign --storetype TRUSTEDSIGNING --keystore <region>.codesigning.azure.net --storepass "$AZURE_TOKEN" --alias <account>/<profile> --tsaurl http://timestamp.acs.microsoft.com' just setupAlways timestamp, so signatures stay valid after the certificate expires.
Quoting: build runs the value through bash and embala through sh -c, so
write it as you would any shell command line. A tool path with a space goes in
single quotes, and "$AZURE_TOKEN" expands when the command runs, not when
just echoes the line, so the token stays out of the build log. Double quotes
and backslashes are escaped for the TOML string, so they reach embala as
written. embala quotes the $f path itself, and replaces every $f in the
command textually, so do not name another variable $f... in it. Keep the
value on one line: a newline splits the build line and breaks the TOML
string. embala uses sh -c on Linux and macOS hosts, which is where setup
runs in CI; on a Windows host it uses cmd /C, where "$AZURE_TOKEN" would
not expand.
Verify a signed file with osslsigncode verify build/sofcat.exe on Linux or
Get-AuthenticodeSignature .\sofcat.exe on Windows (Status Valid), and the
same for setup.exe.
Release signing in CI
Section titled “Release signing in CI”.github/workflows/build_release.yml signs every release with Azure Trusted
Signing. It downloads a pinned jsign jar, logs the Azure CLI in as a service
principal, takes a token for https://codesigning.azure.net and sets
SIGN_CMD for the build step, so the three executables, the uninstaller stub,
setup.exe and the two Windows makecatalogs are signed and timestamped, with the description SofCat and
the URL https://sofcat.app. Provenance attestation runs afterwards, so it
covers the signed bytes. The repository needs:
| Kind | Name | Value |
|---|---|---|
| Secret | AZURE_TENANT_ID |
The Entra tenant of the service principal. |
| Secret | AZURE_CLIENT_ID |
Its application (client) ID. |
| Secret | AZURE_CLIENT_SECRET |
A client secret for it. |
| Variable | TRUSTED_SIGNING_ENDPOINT |
The account’s regional endpoint host, such as eus.codesigning.azure.net. |
| Variable | TRUSTED_SIGNING_ACCOUNT |
The Trusted Signing account name. |
| Variable | TRUSTED_SIGNING_PROFILE |
The certificate profile name. |
The service principal needs the “Trusted Signing Certificate Profile Signer”
role on the certificate profile. A release is never cut unsigned: the build
step fails when any of the six is missing. The Windows integration job that
follows then checks each released .exe with Get-AuthenticodeSignature and
fails unless every Status is Valid.
The client secret is a long-lived credential that has to be rotated before it
expires. A federated credential (azure/login with OIDC, using the job’s
id-token: write permission) would remove it.
Azure/trusted-signing-action is not used: it needs a Windows runner and
signs finished files, so it cannot sign the uninstaller stub that embala
embeds in setup.exe, nor the executables before they are packed into it.
SignPath would work differently: upload the unsigned artifacts with
signpath/github-action-submit-signing-request and attest and release what
comes back.
macOS signing and notarization
Section titled “macOS signing and notarization”Gatekeeper refuses an app or pkg downloaded from the web unless it is signed
with a Developer ID and notarized by Apple. just build-macos and just pkg
sign and notarize when these variables are set and do nothing about signing
when they are not, so a local just pkg still produces an unsigned pkg. Each is also a just variable, like SIGN_CMD: just CODESIGN_IDENTITY=... pkg is the same as setting the environment variable,
and the command line wins when both are set.
| Variable | Read by | Value |
|---|---|---|
CODESIGN_IDENTITY |
build-macos |
The codesign identity for the CLI and the app: a Developer ID Application certificate’s name or SHA-1, or - for an ad-hoc signature. |
PRODUCTSIGN_IDENTITY |
pkg |
The Developer ID Installer identity for productsign --sign, which embala runs on the built pkg. Needs CODESIGN_IDENTITY. |
NOTARIZE |
pkg |
1 runs just notarize on the pkg once it is built. Needs both identities and the four variables below; any other value is an error. |
NOTARY_AUTH |
notarize |
api-key, the only mode: an App Store Connect API key. |
NOTARY_API_KEY_PATH |
notarize |
The key’s .p8 file. |
NOTARY_API_KEY_ID |
notarize |
The key ID. |
NOTARY_API_ISSUER_ID |
notarize |
The issuer ID. |
just build-macos codesigns build/<slug> right after its go build, with
the identifier <IDENTIFIER>.cli, and build/<Name>.app as a bundle once
its Info.plist and icon are in place, since the signature seals them along
with the main executable. Both get --options runtime (the hardened runtime,
which notarization requires) and --timestamp, except that the ad-hoc
identity gets no timestamp, which codesign refuses for it. --force
replaces the signature of an earlier build. No entitlements: the Wails app
runs under the hardened runtime without any.
just pkg checks the variables before anything is built: a
PRODUCTSIGN_IDENTITY without CODESIGN_IDENTITY, or NOTARIZE=1 without
either identity or one of the notary variables, fails naming the missing
one. It appends a [sign.macos] section to the rendered embala.toml, so
embala runs productsign on the product archive once it is built; the four
component pkgs inside stay unsigned, since the product signature covers
them. With NOTARIZE=1 it
then runs just notarize build/<slug>-<version>.pkg.
just notarize <pkg> runs xcrun notarytool submit <pkg> --key <path> --key-id <id> --issuer <issuer> --wait, then xcrun stapler staple <pkg>
and xcrun stapler validate <pkg>, and stops at the first that fails. It
does not check that the key file exists; notarytool reports that itself.
Apple refuses an ad-hoc signature, so a pkg for notarization needs real
identities for both variables.
Verify each stage:
codesign --verify --strict build/sofcatcodesign --verify --strict --deep build/SofCat.appcodesign -d --verbose=2 build/SofCat.app 2>&1 | grep runtime # flags=0x10000(runtime)pkgutil --check-signature build/sofcat-<version>.pkg # Status: signed by ...xcrun stapler validate build/sofcat-<version>.pkg # The validate action workedspctl --assess --type install -v build/sofcat-<version>.pkg # accepted, source=Notarized Developer IDWith a Developer ID, for example (security find-identity -v lists the
identities in the keychain):
CODESIGN_IDENTITY='Developer ID Application: Name (TEAMID)' PRODUCTSIGN_IDENTITY='Developer ID Installer: Name (TEAMID)' NOTARIZE=1 NOTARY_AUTH=api-key NOTARY_API_KEY_PATH=~/AuthKey_ABC123DEF.p8 NOTARY_API_KEY_ID=ABC123DEF NOTARY_API_ISSUER_ID=<issuer uuid> just pkgjust archive-macos follows pkg and writes
build/<slug>-<version>-darwin-<arch>.tar.gz with the CLI, the helper and
the app. A tar.gz cannot carry a notarization ticket, so with NOTARIZE=1 it
first runs xcrun stapler staple on the app: notarizing the pkg also covers
the code inside it. The two bare executables cannot hold a ticket; Gatekeeper
looks theirs up online.
macOS release signing in CI
Section titled “macOS release signing in CI”The macos job of .github/workflows/build_release.yml runs on a macOS
runner (arm64). It imports the two certificates into a keychain made for the
job, runs just archive-macos with NOTARIZE=1, then checks the result with
codesign --verify, stapler validate and spctl --assess. Nothing is
released if any of that fails. The repository needs:
| Kind | Name | Value |
|---|---|---|
| Secret | APPLE_CODESIGN_P12_BASE64 |
The Developer ID Application certificate and its private key, as a base64 .p12. |
| Secret | APPLE_CODESIGN_P12_PASSWORD |
That file’s password. |
| Secret | APPLE_INSTALLER_P12_BASE64 |
The Developer ID Installer certificate and key, the same way. |
| Secret | APPLE_INSTALLER_P12_PASSWORD |
That file’s password. |
| Secret | NOTARY_API_KEY_P8 |
The App Store Connect API key, the contents of the .p8 file. |
| Secret | NOTARY_API_KEY_ID |
The key ID. |
| Secret | NOTARY_API_ISSUER_ID |
The issuer ID. |
| Variable | CODESIGN_IDENTITY |
Developer ID Application: Name (TEAMID). |
| Variable | PRODUCTSIGN_IDENTITY |
Developer ID Installer: Name (TEAMID). |