Firma y Notarización en macOS
Developer ID, hardened runtime y notarytool
Guía del flujo completo para distribuir software macOS fuera de la App Store: identidad Developer ID, firma con hardened runtime, empaquetado (.app/.dmg/.pkg), notarización y verificación con Gatekeeper.
🚨 Qué ha cambiado (leer primero)
Sección titulada «🚨 Qué ha cambiado (leer primero)»⚠️ Obsoleto / en desuso (oct. 2026):
altoolestá deprecado y el servicio de notarización de Apple dejó de aceptarlo el 1 de noviembre de 2023. Sustituido pornotarytool, incluido en Xcode 13+. Alternativa recomendada: usarxcrun notarytoolen todo el flujo.
⚠️ Obsoleto / en desuso (oct. 2026):
codesign --deepcomo estrategia de firma: firma en profundidad sin control y en orden impredecible. Firma los binarios anidados uno a uno, y luego el bundle exterior.
⚠️ Fin del soporte Intel. Rosetta 2 mantiene soporte completo hasta macOS 27 (Golden Gate, septiembre 2026). macOS 28 (otoño 2027) no ejecutará apps solo-Intel (salvo juegos antiguos emulados). macOS 26 (Tahoe) fue la última versión compatible con Macs Intel. Consecuencia práctica: compila siempre arm64 o Universal 2.
🔑 Credenciales de notarización
Sección titulada «🔑 Credenciales de notarización»notarytool acepta dos formas de autenticación: API Key (.p8) (recomendada para CI) o Apple ID + app-specific password.
Opción A: API Key (.p8)
Sección titulada «Opción A: API Key (.p8)»- App Store Connect → Users and Access → Integrations → Team Keys.
- Crea la clave, descarga el
.p8(solo se puede descargar una vez) y anota Key ID e Issuer ID.
# Guarda el perfil en el llavero (no repite credenciales en cada comando)xcrun notarytool store-credentials "mi-notary" \ --key /ruta/AuthKey_ABC123DEF.p8 \ --key-id ABC123DEF \ --issuer 01234567-89AB-CDEF-0123-456789ABCDEFOpción B: Apple ID + app-specific password
Sección titulada «Opción B: Apple ID + app-specific password»# Crea la contraseña en https://account.apple.com → Iniciar sesión y seguridadxcrun notarytool store-credentials "mi-notary-asp" \ --password "abcd-efgh-ijkl-mnop" \ --team-id RXXXXXXXXXEl Team ID aparece en Developer Account → Membership.
✍️ Firmar con Developer ID y hardened runtime
Sección titulada «✍️ Firmar con Developer ID y hardened runtime»# Identidades disponibles (busca "Developer ID Application: ...")security find-identity -v -p codesigning
# Firma de un binario/ejecutable con hardened runtime y timestamp segurocodesign --force --options runtime --timestamp \ --sign "Developer ID Application: Tu Nombre (TEAMID)" \ MiApp.app/Contents/MacOS/MiApp
# Firma del bundle completo (los anidados primero, este al final)codesign --force --options runtime --timestamp \ --sign "Developer ID Application: Tu Nombre (TEAMID)" \ MiApp.app--options runtimeactiva el hardened runtime, obligatorio para notarizar.--timestampincrusta un sello de tiempo seguro (la firma sigue válida cuando el certificado caduca).--entitlementssolo si tu app necesita capacidades extra (JIT, cámara, micrófono, Apple Events).
# Firma con entitlements (p. ej. una app Electron con JIT)codesign --force --options runtime --timestamp \ --entitlements MiApp.entitlements \ --sign "Developer ID Application: Tu Nombre (TEAMID)" \ MiApp.appEjemplo mínimo de MiApp.entitlements:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict> <key>com.apple.security.cs.allow-jit</key> <true/> <key>com.apple.security.cs.allow-unsigned-executable-memory</key> <true/></dict></plist>🧬 Binarios Universal 2 (arm64 + x86_64)
Sección titulada «🧬 Binarios Universal 2 (arm64 + x86_64)»# Swift/Clang: compila y enlaza ambos slices en un único binarioswift build -c release --arch arm64 --arch x86_64
clang -arch arm64 -arch x86_64 -o miapp main.c
# Comprueba las arquitecturas de un binario ya construidolipo -info MiApp.app/Contents/MacOS/MiAppfile MiApp.app/Contents/MacOS/MiAppSi tu toolchain no soporta builds universales, distribuye al menos arm64 nativo: es lo único garantizado en macOS 28.
📦 Empaquetar (.zip, .dmg, .pkg)
Sección titulada «📦 Empaquetar (.zip, .dmg, .pkg)»# .zip para notarizar una .app (conserva permisos y estructura)ditto -c -k --keepParent MiApp.app MiApp.zip
# .dmg comprimido (UDZO = zlib, el formato habitual de distribución)hdiutil create -volname "MiApp" -srcfolder MiApp.app -ov -format UDZO MiApp.dmg
# .pkg para instalar en /Applicationspkgbuild --root ./payload \ --identifier com.celerolab.miapp \ --version 1.0.0 \ --install-location /Applications \ MiApp.pkg
# Firmar el paquete con el certificado de instalador (distinto del de aplicación)productsign --sign "Developer ID Installer: Tu Nombre (TEAMID)" MiApp.pkg MiApp-firmado.pkg
# Entitlements/scripts → producto con distribución personalizadaproductbuild --distribution distribution.xml --package-path ./build MiApp.pkg🚀 Notarizar
Sección titulada «🚀 Notarizar»# .zip y .dmg se notarizan como Developer ID Applicationxcrun notarytool submit MiApp.zip --keychain-profile "mi-notary" --waitxcrun notarytool submit MiApp.dmg --keychain-profile "mi-notary" --wait
# .pkg se notariza como Developer ID Installer (usa el pkg ya firmado)xcrun notarytool submit MiApp-firmado.pkg --keychain-profile "mi-notary" --wait
# Historial de envíosxcrun notarytool history --keychain-profile "mi-notary"
# Detalle de un envíoxcrun notarytool info <UUID> --keychain-profile "mi-notary"
# Log JSON (obligatorio para depurar rechazos)xcrun notarytool log <UUID> --keychain-profile "mi-notary"--wait bloquea hasta que Apple responde. Sin él, el comando devuelve un UUID y hay que consultar con info.
📎 Stapling
Sección titulada «📎 Stapling»Fijar el ticket en el artefacto permite a Gatekeeper validarlo sin conexión.
xcrun stapler staple MiApp.dmg # .app, .dmg o .pkgxcrun stapler validate MiApp.dmg # comprueba que el ticket está fijadoSi modificas la app después de notarizar, el ticket queda inválido: vuelve a firmar y notarizar.
✅ Verificación
Sección titulada «✅ Verificación»# Firma de un .app/.dmgcodesign --verify --strict --verbose=2 MiApp.appcodesign -dv --verbose=4 MiApp.app # detalle: identidad, flags, timestamp
# Gatekeeper sobre una .app ejecutablespctl -a -vvv -t execute MiApp.app # debe imprimir "accepted"
# Gatekeeper sobre un instalador .pkgspctl -a -vvv -t install MiApp.pkgpkgutil --check-signature MiApp.pkg # estado de firma del paquete
# Simula lo que ve el usuario: marca la app en cuarentenaxattr -w com.apple.quarantine "0081;00000000;Safari;" MiApp.app🤖 Automatización en CI (GitHub Actions)
Sección titulada «🤖 Automatización en CI (GitHub Actions)»# 1) Crea un llavero temporalsecurity create-keychain -p "$KEYCHAIN_PASS" build.keychainsecurity default-keychain -s build.keychainsecurity unlock-keychain -p "$KEYCHAIN_PASS" build.keychain
# 2) Importa el .p12 del certificado Developer IDsecurity import cert.p12 -k build.keychain -P "$P12_PASS" -T /usr/bin/codesignsecurity set-key-partition-list -S apple-tool:,apple: -k "$KEYCHAIN_PASS" build.keychain
# 3) Guarda credenciales de notarización y firma/notariza como en localxcrun notarytool store-credentials "ci-notary" \ --key AuthKey.p8 --key-id "$KEY_ID" --issuer "$ISSUER_ID"Guarda todos los secretos ($KEYCHAIN_PASS, $P12_PASS, contenido del .p8) en los secrets del repositorio, nunca en el código.
❓ ¿Por qué me rechaza altool?
➡ Está deprecado y el servicio dejó de soportarlo el 1-nov-2023. Migra a notarytool (ver TN3147 de Apple).
❓ “The binary is not signed with a Developer ID certificate” ➡ Usas un certificado de App Store o de desarrollo. Necesitas Developer ID Application (para .app/.dmg) o Developer ID Installer (para .pkg).
❓ La app se firma pero Gatekeeper la bloquea
➡ Falta el staple, falta --options runtime, o algún framework/binario anidado no está firmado. Firma los anidados primero y notariza de nuevo.
❓ ¿--deep no basta para firmar todo?
➡ No. Aunque codesign --deep firma recursivamente, el orden y las opciones no son fiables. Firma explícitamente cada binario con --options runtime --timestamp.
❓ ¿Qué binarios hay que firmar dentro de una app?
➡ Todo ejecutable y biblioteca propia: .dylib, .so, helpers, .framework. Los de sistema no (Apple ya los firma).
❓ ¿Puedo notarizar sin conexión? ➡ No: la notarización es un servicio en línea. El staple es lo que permite validar después sin conexión.
❓ ¿Cómo paso el certificado a un pipeline?
➡ Exporta el certificado como .p12 protegido, impórtalo en un llavero temporal del runner y guarda la contraseña como secreto.
🔗 Enlaces
Sección titulada «🔗 Enlaces»- Notarizing macOS software before distribution: Apple
- Customizing the notarization workflow: Apple
- TN3147: Migrating to the latest notarization tool (Apple)
- Configuring the hardened runtime: Apple
- Resolving common notarization issues: Apple
- TN2206: macOS Code Signing In Depth (Apple)
- App Store Connect: Team API Keys
🧩 Ver también
Sección titulada «🧩 Ver también»Colección creada y mantenida por CeleroLab. Contenido libre bajo licencia MIT.