Sub topic 6
Code signing and Developer ID
This chapter assumes you know the difference between an app, a .dmg and a .pkg. It also assumes you have seen why the install source matters. Running the commands is optional, but they work in Terminal.
What a code signature is
Code signing attaches a cryptographic signature to an app. The developer creates it with a private key. The signature records a fingerprint (a hash) of every file in the app bundle.
The signature tells macOS two things:
- Who signed it. The signing certificate names the developer and the Team ID, a 10-character identifier tied to their Apple Developer account.
- Whether it changed. If anyone edits a file inside the app after signing, the hashes no longer match and the signature is invalid.
A signature does not say the app is safe. It says who made it and that it has not been altered since.
Developer ID certificates
Apple issues different certificates for different distribution routes.
| Certificate | Used for | Who vouches for the app |
|---|---|---|
| Apple Distribution | Mac App Store | Apple, after App Review |
| Developer ID Application | Apps downloaded from the web | The developer, with an identity Apple has issued |
| Developer ID Installer | `.pkg` installers from the web | The developer |
A Developer ID certificate is issued only to enrolled developers, and Apple can revoke it. If a developer distributes malware, Apple can revoke the certificate. Gatekeeper then refuses apps signed with it.
An ad-hoc signature has no developer identity behind it. Apps built locally often have one. It proves integrity only, not origin.
The chain of trust
macOS follows the chain from the app's certificate up to an Apple root certificate built into the system. If any link is broken, expired, or revoked, the check fails.
Inspecting a signature
First, check that the signature is valid and the contents are untouched:
codesign --verify --deep --strict --verbose=2 /Applications/Example.appNo output other than "valid on disk" and "satisfies its Designated Requirement" means success. An error such as "a sealed resource is missing or invalid" means the bundle was modified after signing.
Next, see who signed it:
codesign -dv --verbose=4 /Applications/Example.app 2>&1 | grep -E 'Authority|TeamIdentifier'For a web download you should see Authority=Developer ID Application: Name (TEAMID), then Developer ID Certification Authority, then Apple Root CA. Compare the Team ID with the one the developer publishes.
Common errors
- Assuming signed means safe. Signed apps can still be harmful.
- Ignoring a changed Team ID. If an app you trust is suddenly signed by a different team, find out why before you update.
- Treating "not signed" as a small matter. An unsigned or ad-hoc app from the web has no verified origin. Look closely at where it came from.
Exercise
You run codesign --verify on an app and it reports that a sealed resource is missing or invalid. What does this tell you, and does it prove the app is malware?
Show answer
The app's files no longer match the hashes recorded when it was signed, so something was changed after signing. It does not prove malware, because a bad download or a manual edit can also cause it. You should not trust the copy, though. Delete it and download a fresh one from the developer's official site.