Skip to content

macOS Code Signatures: What You Can Verify Offline

How a Mach-O is code-signed, which codesign --verify checks work offline, and what ad-hoc, linker-signed and Developer ID signatures really mean.

Published on 6 min read

TL;DR. A macOS code signature is stored at the end of each Mach-O slice. Its core is the CodeDirectory, which holds a hash of every page of the file plus hashes of the entitlements, requirements and Info.plist. For a real identity, a CMS signature made with an Apple-issued certificate signs the CodeDirectory. From the file alone you can re-hash every page, re-check every special slot and verify the CMS signature, just as codesign --verify does. Trust in the certificate chain, revocation and notarization are not in the file, so they need a Mac or the network. A valid signature proves integrity and, at best, provenance. It does not prove innocence.

Where the signature lives

LC_CODE_SIGNATURE points at a blob at the very end of __LINKEDIT. That blob is a SuperBlob (magic 0xFADE0CC0): an index of smaller blobs, each in a numbered slot.

SlotBlobMagic
0CodeDirectory0xFADE0C02
2Requirements0xFADE0C01
5Entitlements (XML plist)0xFADE7171
7Entitlements (DER)0xFADE7172
0x1000+Alternate CodeDirectories (e.g. SHA-1 and SHA-256 side by side)0xFADE0C02
0x10000CMS signature0xFADE0B01

In a universal binary every slice carries its own signature, and the universal header is signed by none of them. See LC_CODE_SIGNATURE and code signing for the byte layout.

The CodeDirectory: one hash per page

The CodeDirectory records the signing identifier, the Team ID, the hash algorithm, the page size, the flags and two lists of hashes:

  • code slots: one hash per page of the file, from offset zero up to the signature (the codeLimit). Pages are 4 KB, or 16 KB in some arm64 signatures. Unlike Authenticode on Windows, the hash has no holes: the header and the load commands are covered too.
  • special slots, numbered backwards: -1 the Info.plist, -2 the requirements, -3 the bundle's resource seal (_CodeSignature/CodeResources), -5 the XML entitlements and -7 the DER entitlements.

The hash of the CodeDirectory itself is the cdhash, the identity macOS uses for signed code. For SHA-256 it is usually shown truncated to 20 bytes, as codesign -dvvv prints it. The flags record how the code should run:

  • adhoc: the signature has no identity;
  • runtime: the hardened runtime;
  • library-validation, kill and restrict: protections the kernel enforces;
  • linker-signed: the signature was added by the linker.

The CMS signature

For a Developer ID, App Store or Apple signature, slot 0x10000 holds a detached CMS SignedData whose content is the CodeDirectory. Its signed attributes carry:

  • the messageDigest, the hash of the CodeDirectory;
  • the signing time;
  • Apple's own attributes listing the hash of every CodeDirectory, so the alternates are covered too.

The embedded certificates form the chain. For Google Chrome, for example, the chain is "Developer ID Application: Google LLC (EQHXZ8M8AV)", then "Developer ID Certification Authority", then "Apple Root CA". An unsigned attribute may hold an RFC 3161 timestamp from Apple's timestamp authority. That secure timestamp is mandatory for notarization.

The offline checks

Mach-O Parser runs these on every slice, the same checks codesign --verify makes:

CheckQuestionFailure means
Page hashesIs every page of code unchanged since signing?Patched, infected or truncated after signing
Special slotsAre the entitlements, requirements and Info.plist the ones that were signed?Entitlements or metadata swapped
CMS messageDigest and cdhash listDoes the signature really cover this CodeDirectory?A signature transplanted from another file
RSA signatureDoes the signer's key validate the signed attributes?Forged or damaged signature

The harmless SyncTool sample behind the Try a sample button shows the first failure. It was signed, then one string was edited in place ("SyncTool 1.0" became "SyncTool 1.1"). Its first page no longer matches its hash, and the tool reports it as modified after signing, at the high level. The signature is still there and still parses; it just no longer describes this file.

Kinds of signature, and what each means

KindSigned byIn triage
Apple platformApple's "Software Signing"The operating system's own binaries
App Store"Apple Mac OS Application Signing"Re-signed by Apple after review; code also FairPlay-encrypted
Developer ID"Developer ID Application: Name (TEAMID)"Distributed outside the App Store; Apple can revoke the certificate and the notarization
Development"Apple Development: …"A developer's test build; not meant to be distributed
Ad hocNobody (codesign -s -)Integrity only. The identifier is free text: one of the samples calls itself com.apple.softwareupdate.agent
Linker-signedNobody (added by ld)Apple Silicon refuses to run unsigned arm64 code, so the linker signs every arm64 output ad hoc
Unsigned—Possible for Intel code only; common in older and open-source command-line tools

A certificate that does not chain to Apple's roots is not a valid macOS signature, whatever its subject says. The tool reports it separately.

The designated requirement

The requirements blob holds the designated requirement, a small expression in Apple's code-requirement language. It says which future signatures count as "the same program", and the tool decompiles it to text. Chrome's, shortened, requires that:

  • the identifier is com.google.Chrome (or one of its beta and canary variants);
  • the chain leads to Apple (anchor apple generic);
  • the certificates carry the Developer ID markers;
  • the leaf certificate's subject.OU is EQHXZ8M8AV.

Keychain access control lists and TCC privacy permissions store this requirement. That is how an updated build keeps the permissions of the previous one, and why a re-signed copy does not get them.

What stays out of reach offline

  • Chain trust. The tool shows the chain, but validating it against the trust store is a property of a Mac, not of the file.
  • Revocation. Apple revokes Developer ID certificates used for malware. That status lives online (OCSP), and Gatekeeper checks it.
  • Notarization. The ticket is stapled to a bundle, disk image or installer package, or fetched online by cdhash. A bare Mach-O file cannot carry one.
  • The bundle's resources. Slot -3 only stores the hash of _CodeSignature/CodeResources. Checking the bundle's resources against it needs the whole .app.
  • Policy and enforcement. Gatekeeper, MDM rules, Santa and the kernel's code-signing enforcement (AMFI) decide what actually runs.

Reading the result in an investigation

  • Unsigned: possible for Intel code only. Common for older command-line tools, so it means little alone, but an app distributed unsigned today is unusual.
  • Ad hoc or linker-signed: integrity without identity. Read the identifier as a claim, not a fact.
  • Modified after signing: high priority. Something changed the code after the developer signed it: a patcher, an infector, or someone repackaging a known app.
  • Developer ID, intact: note the Team ID, then check whether that developer makes such a tool, whether the certificate was revoked, and when it was signed. See dating a Mach-O file.
  • Developer ID without the hardened runtime: it cannot have been notarized since early 2020, when notarization started to require the hardened runtime.

Who signed a file is only half the question. What the signature allows the code to do is the other half: see entitlements and the hardened runtime.

Frequently asked questions

Does a valid code signature mean a Mac app is safe?

No. It means the code has not changed since it was signed, and, for a Developer ID signature, that Apple issued the certificate to a known developer account. Developer ID certificates have signed malware before being revoked, and an ad-hoc signature identifies nobody at all.

What is the difference between an ad-hoc and a linker-signed signature?

Both have no identity and no CMS signature. An ad-hoc signature (codesign -s -) is a full signature that can carry an identifier, requirements and entitlements. A linker-signed one is the minimal ad-hoc signature that ld adds to arm64 code automatically: page hashes only, flagged linker-signed, and replaced as soon as the file is signed properly.

Can I check notarization from the Mach-O file?

No. A notarization ticket is not stored in the Mach-O. It is either stapled to the .app, .dmg or .pkg that carries the file, or fetched online by Gatekeeper using the file's cdhash. A bare command-line tool cannot have a stapled ticket at all.

Related articles

The Mach-O format for incident responders: header and flags, universal binaries, load commands, segments, imports, __LINKEDIT and what matters in triage.
A walkthrough of Mach-O Parser on five harmless samples: triage, signatures, entitlements, a dropper's payload, compare, YARA and exports. Nothing uploaded.
Where Mac malware keeps its binaries, how to copy them without running them and without losing the quarantine attribute, and how to package an .app, a .dmg or a .pkg for analysis on another machine.