Sub topic 12
Verifying signatures with codesign, spctl and pkgutil
This chapter assumes you can open Terminal and run commands, and that you know what an app bundle, a disk image (.dmg) and an installer package (.pkg) are. You should also know roughly what code signing, notarization and Gatekeeper do. Earlier chapters covered those. Here you run the checks yourself.
Three tools do the work:
codesigninspects and verifies code signatures.spctlasks Gatekeeper's policy engine for a verdict.pkgutilinspects installer packages.
A fourth tool, xcrun stapler, checks for an attached notarization ticket.
What each tool answers
Each tool answers a different question. Mixing them up is a common source of wrong conclusions.
| Tool | Question it answers | What it does not tell you |
|---|---|---|
| `codesign --verify` | Is the signature intact, and is the bundle unmodified since signing? | Whether the signer is someone you trust |
| `codesign -dv` | Who signed it, and what is the Team ID? | Whether the signature is valid |
| `spctl --assess` | Would Gatekeeper allow this to run, and on what basis? | Whether the app is safe |
| `xcrun stapler validate` | Is a notarization ticket attached to the app? | Whether the ticket is genuine for this exact build |
| `pkgutil --check-signature` | Is the installer package signed, and by which certificate? | What the installer's scripts will do |
Step 1: Verify the signature is intact
Copy the app to /Applications first, or point the commands at the app wherever it sits. Then run:
codesign --verify --deep --strict --verbose=2 /Applications/Example.appIf everything is fine, the command prints lines like these and exits with status 0:
/Applications/Example.app: valid on disk
/Applications/Example.app: satisfies its Designated RequirementThe flags matter:
--verifychecks the signature instead of displaying it.--deepalso checks nested code, such as helper tools, frameworks and plug-ins inside the bundle.--strictapplies stricter validation rules, so it catches more malformed bundles.--verbose=2prints the result lines above. Without it, success is silent.
Common failures:
code object is not signed at all: the app has no signature. Treat this as a strong warning for software you downloaded from the web.a sealed resource is missing or invalidorfile modified: something inside the bundle changed after signing. This can come from tampering or from a broken download. Delete the app, download it again and re-check.resource fork, Finder information, or similar detritus not allowed: extra metadata is attached to files inside the bundle. This usually means the bundle was copied or archived in an unusual way.
You can read the exit status with echo $?. A script can use this: 0 means the check passed, and any other value means it failed.
Step 2: Identify who signed it
A valid signature only proves that someone signed the code and that it has not changed since. A criminal can sign malware with their own certificate. So you also need to know who signed it:
codesign -dv --verbose=4 /Applications/Example.app 2>&1 | grep -E 'Authority|TeamIdentifier'codesign -dv writes its output to standard error. The 2>&1 redirects it to standard output so grep can filter it. A typical result for software distributed outside the App Store looks like this:
Authority=Developer ID Application: Example Software Ltd (ABCDE12345)
Authority=Developer ID Certification Authority
Authority=Apple Root CA
TeamIdentifier=ABCDE12345Read it from the top. The first Authority line is the signing certificate and names the developer. The following lines are the certificate chain, which should end at Apple Root CA. The TeamIdentifier is a ten-character ID tied to the developer's Apple Developer account.
What to compare:
- The developer name should match the company or person who publishes the software.
- The Team ID should match any value the developer publishes, for example on a security or download page.
- For Mac App Store apps, the first authority is
Apple Mac OS Application Signingor similar, not a Developer ID.
The Team ID is more reliable than the name. Names are free text chosen when the account is created, while the Team ID is assigned by Apple. Once you have confirmed a Team ID for a developer, a later update that shows a different Team ID deserves suspicion.
Step 3: Ask Gatekeeper for its verdict
spctl --assess --type execute --verbose=4 /Applications/Example.appspctl evaluates the app against the system's current policy. It prints a verdict and the source of approval:
/Applications/Example.app: accepted
source=Notarized Developer ID
origin=Developer ID Application: Example Software Ltd (ABCDE12345)Common sources you will see:
Mac App Store: the app came through App Store review.Notarized Developer ID: signed with a Developer ID and notarized by Apple.Developer ID: signed with a Developer ID but not notarized. Recent macOS versions normally reject such apps for downloaded software, so you will see this mainly on older apps.
A rejected app prints rejected with a reason, for example source=no usable signature or source=Unnotarized Developer ID. Rejection fits the earlier chapter on blocked apps. Do not work around a rejection until you understand why it happened.
Two behaviours surprise people:
spctlassesses the app's policy status. Quarantine is a separate matter. An app with no quarantine attribute can still be assessed as accepted or rejected, but Gatekeeper's first-launch check only runs on quarantined files.- A notarization check may need network access. An app without an attached ticket can be accepted when the system can look it up online, and may fail offline.
Step 4: Check for a stapled ticket
xcrun stapler validate /Applications/Example.appSuccess prints The validate action worked!. A failure with does not have a ticket stapled to it does not mean the app is bad. Developers can notarize without stapling, and macOS then looks up the ticket online. A stapled ticket helps when the Mac is offline during first launch. Use this check to understand why an app behaves differently offline, not as a safety verdict by itself.
xcrun finds developer tools. If it asks to install the Command Line Tools, you need to accept that install before stapler runs.
Step 5: Check an installer package
Packages are signed differently from app bundles. Use pkgutil before you run the installer:
pkgutil --check-signature ~/Downloads/Example.pkgSample output for a properly signed and notarized package:
Package "Example.pkg":
Status: signed by a developer certificate issued by Apple for distribution
Notarization: trusted by the Apple notary service
Signed with a trusted timestamp on: 2026-10-14 09:21:07 +0000
Certificate Chain:
1. Developer ID Installer: Example Software Ltd (ABCDE12345)
2. Developer ID Certification Authority
3. Apple Root CAThe package signing certificate is a Developer ID Installer certificate. This differs from the Developer ID Application certificate used for apps. The Team ID in the parentheses should match the developer's.
If the output says Status: no signature, the package is unsigned. For software from the web, stop and ask why. Also note what the check does not cover: a signature says who produced the package and that it was not altered. It says nothing about the pre-install and post-install scripts. Those run with administrator rights after you authenticate, so the trust decision about the signer matters more for packages than for apps.
To see what a package would install before running it, list its payload:
pkgutil --payload-files ~/Downloads/Example.pkg | head -n 20Putting the checks together
Combine the checks into a small script. It stops at the first failure, so you do not skim past an error message.
#!/bin/bash
set -euo pipefail
APP="${1:?Usage: verify-app.sh /path/to/App.app}"
echo "== Signature integrity =="
codesign --verify --deep --strict --verbose=2 "$APP"
echo "== Signer =="
codesign -dv --verbose=4 "$APP" 2>&1 | grep -E 'Authority|TeamIdentifier'
echo "== Gatekeeper assessment =="
spctl --assess --type execute --verbose=4 "$APP"
echo "== Notarization ticket =="
xcrun stapler validate "$APP" || echo "No stapled ticket (may still be notarized online)."
echo "All hard checks passed. Compare the Team ID above with the developer's site."Save it as verify-app.sh, run chmod +x verify-app.sh, then run ./verify-app.sh /Applications/Example.app. The set -e option makes the script exit when a command fails. The || echo after stapler keeps a missing ticket from ending the script, since that is not a failure by itself.
Limits of these checks
Keep these points in mind:
- The signer and the Team ID are only useful if you have a trusted value to compare with. Get that value from the developer's official site, reached by a link you typed or bookmarked yourself, and not from the page that offered the download.
- A revoked certificate can still look valid offline. Apple can revoke a Developer ID, and the system learns this through its online checks and updates.
- Ad hoc signatures (
Signature=adhocin thecodesign -dvoutput) have no certificate. Some open-source builds use them. They prove integrity but not identity, and Gatekeeper treats them like unsigned code for downloaded apps.
Exercise
You run codesign --verify --deep --strict --verbose=2 on a downloaded app and it reports "valid on disk". spctl --assess then reports "rejected, source=Unnotarized Developer ID". What does each result tell you, and should you open the app?
Show answer
The codesign result means the signature is intact and the bundle has not been changed since it was signed. The spctl result means Gatekeeper's policy rejects the app because it was signed with a Developer ID but not notarized. The app is authentically from its signer, but it fails the current system policy. Do not override the block just because the signature is valid. First check with the developer for a notarized build, confirm the Team ID and the download source, and only consider an override if you trust the developer and understand the risk.
Exercise
Why compare the Team ID instead of only the developer name shown in the Authority line, and where should you get the value to compare with?
Show answer
The name is free text chosen when the developer account is created, so it is easier to imitate. The Team ID is a ten-character identifier assigned by Apple. You should get the expected value from the developer's official site, reached through a bookmark or a link you typed yourself, and not from the page that hosted the download.