Skip to content

Mach-O Reference

Code signing

Code signing and entitlements

How a Mach-O code signature works: the CodeDirectory that hashes the image, the cdhash that identifies it, the entitlements that grant it privileges, and what ad-hoc versus CMS-signed means.

What a signature contains

The LC_CODE_SIGNATURE command points at a SuperBlob holding several pieces. The three that matter most for understanding a binary are the CodeDirectory, the entitlements and the CMS signature.

The CodeDirectory

The CodeDirectory (magic 0xfade0c02) is the heart of the signature. It hashes the image one page at a time and records enough metadata to identify the signer:

FieldMeaning
identifierThe signing identifier, e.g. com.apple.ls — the stable name of the program.
teamIDThe Apple Developer Team that signed it (absent for ad-hoc and some Apple binaries).
hashTypeThe digest used for the page hashes — almost always SHA-256.
pageSizeBytes per hashed page (typically 4096).
nCodeSlotsNumber of page hashes — one per page of signed code.
nSpecialSlotsNegative-indexed slots hashing the entitlements, requirements, and so on.
flagsadhoc, runtime (hardened runtime), linker-signed, and others.

cdhash

The cdhash is the hash of the entire CodeDirectory blob, taken with the CodeDirectory's own hashType. Because the CodeDirectory hashes every page of the image, the cdhash transitively identifies the whole binary — it is the value codesign -d prints and the identity the system uses to recognise the program.

Entitlements

Entitlements are a property list embedded in the signature (magic 0xfade7171, with a DER copy at 0xfade7172). They are key/value grants — privileges the program claims, such as com.apple.security.app-sandbox or private com.apple.private.* keys. Because they live inside the signed data, they cannot be changed without breaking the signature. Reading them tells you what a binary is allowed to do.

Ad-hoc, signed, unsigned

  • Unsigned — no LC_CODE_SIGNATURE at all.
  • Ad-hoc — a CodeDirectory (and therefore a cdhash) but no CMS signature. The adhoc flag is set; the binary identifies itself but no authority vouches for it. Apple Silicon requires at least an ad-hoc signature to run.
  • Signed — a CMS (PKCS#7) signature blob (0xfade0b01) that chains the cdhash to a signing certificate, so the system can verify who signed it.