Engineering · macOS · Code signing
Self-updating a macOS app without losing its permissions
I shipped a one-click updater for AirCursor, an open-source Mac app that turns AirPods head tracking into a mouse. The first real update installed perfectly, relaunched perfectly, and left the pointer completely dead. This is how the updater works, why macOS quietly revoked its permissions, and the fix.
The setup
AirCursor needs three permissions: Accessibility to post mouse events into other apps, Motion to read the AirPods sensors, and Bluetooth to list and pair headphones. It is distributed outside the Mac App Store as a zip on GitHub Releases, and it can't be sandboxed, because sandboxed apps can't use Accessibility to drive other apps.
Releases are built by GitHub Actions on every merge. There is no paid Developer ID, so CI signed each build ad-hoc (codesign --sign -). Users approved the "unidentified developer" prompt once, granted the three permissions, and everything worked. Until they updated.
Part 1: an updater you can trust
The usual answer here is Sparkle, and it's a good one. AirCursor has a no-dependencies rule, and the whole updater came to roughly 600 lines plus tests, signing script included, so I wrote it directly. The flow:
Why you have to verify it yourself
When a user downloads a zip in Safari, macOS tags it with a quarantine attribute and Gatekeeper inspects it on first launch. A file your app fetches with URLSession gets no such tag, unless you opt in with LSFileQuarantineEnabled. Gatekeeper never looks at it. Your updater is the only gate, so it has to prove the download is yours before it replaces anything.
The proof is an Ed25519 signature. CI signs each release zip with a private key that exists only in a GitHub Actions secret, and attaches the signature as AirCursor-1.0.7.zip.sig. The app ships the public key and checks with CryptoKit, no dependency needed:
import CryptoKit
static func isValid(signatureText: String, for data: Data, publicKeyBase64: String) -> Bool {
guard let keyData = Data(base64Encoded: publicKeyBase64),
let key = try? Curve25519.Signing.PublicKey(rawRepresentation: keyData),
let signature = Data(base64Encoded: signatureText.trimmingCharacters(in: .whitespacesAndNewlines)),
signature.count == 64 else { return false }
return key.isValidSignature(signature, for: data)
}
Two details matter. The app downloads the versioned asset (AirCursor-1.0.7.zip), never the moving latest alias, so a release published mid-download can't swap underneath it. And after unzipping, it checks the bundle ID, the advertised version, and the code signature with SecStaticCodeCheckValidity before the swap.
I tested the refusal path on purpose: a release whose .sig was made over different bytes.
Update install failed: The download’s signature doesn’t match. It wasn’t installed.
installed version: 1.0.3
Replacing a running app
The new bundle is unpacked into an .itemReplacementDirectory created appropriate for the installed app, which guarantees the same volume, so replaceItemAt is a rename rather than a copy. The running process keeps its already-mapped binary. To relaunch, a tiny shell waits for the old process to exit before calling open. The PID and path go in as arguments, never interpolated into the script:
let waiter = Process()
waiter.executableURL = URL(fileURLWithPath: "/bin/sh")
waiter.arguments = ["-c",
#"while /bin/kill -0 "$1" 2>/dev/null; do /bin/sleep 0.2; done; /usr/bin/open "$2""#,
"sh", String(ProcessInfo.processInfo.processIdentifier), appURL.path]
try waiter.run()
NSApp.terminate(nil)
If the app is running from a read-only location, such as straight out of Downloads under App Translocation, it can't replace itself. The updater detects that and falls back to a plain download link.
Local end-to-end test: a fake 1.0.3 build found a signed 1.0.9 served from local files, verified it, swapped, relaunched, and logged Updated to 1.0.9. I published 1.0.5 with the updater, then 1.0.6 to try it for real.
Part 2: the update that killed the pointer
1.0.5 offered 1.0.6. One click, a second of progress, a relaunch, a cheerful "Updated to AirCursor 1.0.6" toast. Then nothing moved. Accessibility in System Settings showed AirCursor switched on. Switching it off and on again changed nothing.
The app's own log said accessibility: false. The interesting part was in the system's privacy daemon, tccd:
log show --last 25m --style compact \
--predicate 'subsystem == "com.apple.TCC" AND eventMessage CONTAINS[c] "AirCursor"'
tccd: Failed to match existing code requirement for subject
io.github.m-afham.AirCursor and service kTCCServiceAccessibility
That line kept repeating, including right after each toggle. The same message showed up for kTCCServiceMotion and kTCCServiceBluetoothAlways. All three permissions were gone.
How TCC remembers an app
When you grant a permission, TCC stores the bundle ID together with a code requirement: a small rule a future process must satisfy to count as the same app. It comes from the app's designated requirement, which you can print:
codesign -d -r- /Applications/AirCursor.app
# ad-hoc signed (AirCursor 1.0.6, one hash per architecture):
designated => cdhash H"001ea6d426ca1fac813381682e7c4df1e5881590"
or cdhash H"346096e3570266cf57cfd9d14ad4d89f67e3bdbd"
# Apple Development signed:
designated => identifier "io.github.m-afham.AirCursor" and anchor apple generic
and certificate leaf[subject.CN] = "Apple Development: Muhammad Afham (…)" …
An ad-hoc build has no certificate, so its requirement is just the hash of its own code. Change one byte, such as the version number in Info.plist, and the hash changes. To TCC, 1.0.6 was a stranger that happened to share 1.0.5's name. Toggling the switch flips the stored grant, but the grant still carries 1.0.5's requirement.
Part 3: a stable identity without a paid Developer ID
The proper fix is a Developer ID certificate plus notarization. That costs a paid Apple Developer membership, and it also removes the "unidentified developer" prompt on first install. Without it, the cheaper option is to put my Apple Development certificate into CI, but that certificate can sign anything as me, for every project I work on. I didn't want it in a GitHub secret.
TCC doesn't require an Apple-issued certificate. It requires a stable requirement. So releases are now signed with a self-signed certificate that exists only for this app:
openssl req -x509 -newkey rsa:3072 -sha256 -days 7300 -nodes \
-keyout key.pem -out cert.pem -subj "/CN=AirCursor Release Signing" \
-addext "basicConstraints=critical,CA:false" \
-addext "keyUsage=critical,digitalSignature" \
-addext "extendedKeyUsage=critical,codeSigning"
openssl pkcs12 -export -inkey key.pem -in cert.pem \
-name "AirCursor Release Signing" -out cert.p12
Builds signed with it get a requirement pinned to the certificate, not to the code:
designated => identifier "io.github.m-afham.AirCursor"
and certificate leaf = H"f449eeafc70243d24866ae40ccb94ae03ae5f04c"
If this certificate ever leaked, someone could sign an app that macOS treats as AirCursor, including the permissions users granted it. That's the same blast radius as a compromised release pipeline, which could already ship a malicious update, and nothing beyond it. Gatekeeper doesn't trust it, so first installs still need "Open Anyway", same as before.
Three gotchas signing with it in CI
codesignsays "no identity found". An untrusted, self-signed identity is only found when its keychain is on the user search list.--keychainalone wasn't enough, and the SHA-1 fingerprint didn't help either. Add the temporary keychain to the list.- Skip the secure timestamp.
--timestampis for Apple-issued certificates. Use--timestamp=nonefor this one. - Set the key partition list after importing, or
codesigncan stall on a keychain access prompt that nobody on a CI runner will ever click.
security create-keychain -p "$KP" "$KC"
security unlock-keychain -p "$KP" "$KC"
security import release.p12 -k "$KC" -P "$P12_PASSWORD" -T /usr/bin/codesign -f pkcs12
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KP" "$KC"
security list-keychains -d user -s "$KC" $(security list-keychains -d user | tr -d '"')
codesign --force --options runtime --timestamp=none \
--entitlements AirCursor.entitlements --sign "AirCursor Release Signing" AirCursor.app
The test that counts
I granted the permissions to a certificate-signed 1.0.7, then let it update itself to a certificate-signed 1.0.8. The relaunched app's first log line:
Update 1.0.8 installed; relaunching
AirCursor starting (accessibility: true, motion: allowed, onboarded: true)
Updated to 1.0.8
No System Settings, no toggling. The published 1.0.7 now carries the same requirement, and every release after it inherits the grants.
Moving existing users across
Anyone coming from an ad-hoc build hits the mismatch one last time, and the advice I had in the app ("switch it off and on") was wrong. What works is to select the app in Privacy & Security › Accessibility, remove it with the − button, then let the app request access again and switch it on. That creates a fresh grant with the new requirement. The update window now says exactly that when it detects it's running an ad-hoc build, and says "your permissions carry over" otherwise.
What each piece protects
| Piece | Protects against | Lives in |
|---|---|---|
| Ed25519 update key | A tampered or fake download being installed | CI secret; public key in the app |
| Versioned asset name | A different release swapping in mid-install | Release workflow |
| Bundle and code checks | A valid archive that contains the wrong app | Installer, before the swap |
| Release certificate | Permissions being dropped on every update | CI secret; identity in every build |
| Developer ID (not used) | The first-install Gatekeeper prompt | Paid Apple membership |
One last design choice: updates never install silently. For someone using their head as the only pointer, a surprise restart mid-task is worse than an extra click. The app announces the update, and the user decides when.
All of it is open source in m-afham/AirCursor: UpdateInstaller.swift, Updates.swift with its tests, scripts/update-signing.swift, and the release workflow.
Shipping a Mac app outside the App Store?
I help iOS and macOS engineers with exactly this kind of problem: signing, updates, permissions, and the parts of Apple's platforms that only fail in production.
Book a free 1:1 Connect on LinkedIn