Skip to content

0176: Notices also reach your Apple devices as pushes, end-to-end encrypted, through a Heinzel relay

  • Implementation partial

Context and Problem Statement

A notice pops up only where hz runs: in an open web app, or through the daemon's native notifier (0043). The iPhone and iPad apps show a notice only while they are open ("keep Heinzel active to receive new notices"). Apple delivers to a closed app only through the Apple Push Notification service (APNs), and APNs takes a request only from a holder of the app's APNs auth key. Each hz install can't hold that key: it is one secret per app, and every install would carry it. How does a notice reach a closed app without the key on every install, and without anyone but the person reading it?

Decision Drivers

  • The owner's decisions: a small Heinzel relay holds the APNs key; full text, end-to-end encrypted, the relay and Apple see only ciphertext and a device token; every kind of notice is also pushed, each switchable, on by default, shown once across devices; approve, reject and inline reply from the notification, sent back over the existing authenticated app connection, never through the relay.
  • Nothing is sent home (0027): the relay is an opt-in extra place, like chat (0160), and learns nothing it could sell or leak.
  • Merge dark (0115) until the relay is deployed and the APNs key exists.

Considered Options

  • A Heinzel push relay with per-device HPKE encryption; actions through the app (chosen)
  • The APNs key in every install: one leaked install leaks the key for every person's devices.
  • Web Push (VAPID): rejected in 0043; and iOS shows Web Push only for a home-screen web app, not the native app.
  • A third-party push service: a vendor that sees device tokens and timing of every person, with its own account.
  • Actions through the relay: the relay would become a path into hz; the owner ruled it out.
  • Actions from the background with a new per-device action credential: a second credential next to the paired device token (0046), stored by the app outside the page; not now.

Decision Outcome

Chosen option: a Heinzel push relay with per-device HPKE encryption; actions through the app, because only the relay holds the APNs key, only the person's devices can read a notice, and nothing new can act on hz.

Threat model. Adversaries: the relay's operator or a breach of it, Apple, the network, another hz install, and a lost locked device. The relay and Apple see the device token, the install id, the ciphertext's size and the time; never a title, body, kind, route or notice id.

Another install can't push to a device it didn't register (routes belong to the install that made them). A forged relay request fails its signature; a replayed one fails its time window or, inside it, the relay's memory of signatures already seen (every hz request carries a fresh nonce); a stale or replayed notice is dropped by the device by the time sealed inside it.

A lost locked device shows notices on its lock screen as iOS's own settings allow, but can't approve, reject or reply without unlock (Face ID / passcode). Accepted risk: another install that learns a device's APNs token can register it under its own route and push to it; the device can't open such a push and shows only the placeholder.

The relay does not refuse a token another install holds, since that would let an attacker who registers a victim's token first block the device's own install. iOS shows that placeholder: an extension can't suppress an alert without the notification-filtering entitlement, which the app doesn't have. Out of scope: a compromised hz install or unlocked device (it can read everything anyway), and traffic analysis by timing.

Key exchange. The app generates a random device id and an X25519 key pair per workspace (hz install) in the Keychain (shared with its notification service extension only, never synced), so a notice opens only with the key of the install that sent it and its actions go back to that workspace only. Over the paired connection (the page's device token, the registration in the JSON body), it registers with that install: device id, name, platform, APNs token, APNs environment, bundle id and the public key.

Each push names the key that opens it by an opaque digest of the public key. HPKE base mode does not authenticate the sender: anyone holding a device's public key could seal a notice it shows. Only the registering install holds it (the relay never sees it), which is accepted; auth mode with a per-install key is the way to close it if that changes.

hz keeps the devices in state_dir/notify/push/ (0700/0600) and never shows a token or key in a listing. hz encrypts each push per device with HPKE (RFC 9180) base mode, DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20-Poly1305, info = heinzel-push-v1 and the device id. Python uses cryptography's HPKE, the apps CryptoKit's HPKE (Curve25519_SHA256_ChachaPoly); a fixture made by one is opened by the other in tests.

The payload, before encryption, is JSON, at most 2,600 bytes (sealed and in base64url it stays under APNs' 4 KB): v, type (notice or clear), at (Unix seconds; the device drops a payload older than 12 hours or more than five minutes ahead), and for a notice its id, title, body (cut to fit), the Heinzel's name, route, kind and the actions offered; for clear the ids seen.

Relay API (https://push.heinzel.team/v1, in relay/push/: one implementation. The supported deployment is a small container with Node's HTTP/2 client, which keeps counters and seen signatures in one process, so limits and the replay check are exact. The Cloudflare Worker variant is not supported: APNs takes HTTP/2 only and Cloudflare documents Worker subrequests over HTTP/1.1, and its KV is eventually consistent, so its limits and replay check are only approximate: two edges can each accept the same signature once.) Every request but enrolment is signed by the install: Ed25519 over method, path, timestamp and the body's SHA-256, within five minutes, in canonical base64url only (the last character's unused bits must be zero, so a signature has one spelling), each signature accepted once (remembered for ten minutes; a replay answers 409), at most 120 signed requests a minute per install before anything is remembered for them, its key registered once (POST /v1/installs with the public key, signed by it; the install id is a digest of the key). The relay never throws: anything unexpected, an APNs transport error included, answers 500 or 502 without detail.

  • PUT /v1/routes/{route} {token, environment, topic}: registers or rotates a device's token. The route id is random, made by hz; the relay keeps only route → install, token, environment and topic. At most 20 routes per install (409 beyond), 60 route writes an hour per install; a route expires after 60 days and an install key after 90 unless registered again (the apps register on every launch).
  • Release signing. A Developer ID (release) Mac build must be signed and authorized for the production push environment, and only an Apple Development-signed local build for development; the Mac release checks refuse anything else, as the iOS archive check requires production.
  • Production only, one topic. The APNs key is Production-only and topic-specific to the app's bundle id (team.heinzel.apple, the Worker's APNS_TOPIC): the relay refuses a sandbox route or another topic, and hz already refuses a sandbox registration with that reason. TestFlight and App Store builds receive pushes; Debug and development builds use the APNs sandbox and can't, until a separate sandbox key is added.
  • DELETE /v1/routes/{route}: unregisters it.
  • POST /v1/push {route, ciphertext, collapse, hint, kind}: alert sends mutable-content with a fixed placeholder ("New notice") that the extension replaces; background wakes the app (a Mac's notice, or a clear on any device). collapse is a keyed digest of the notice id, the same for every device, so a later push replaces an earlier one.
  • Rate limits: 20 enrolments an hour per address (behind a trusted proxy, the right-most forwarded address), 300 pushes an hour and 3,000 a day per install, 60 an hour per route; answers 429 with Retry-After. Bodies over 4 KB are refused. The container keeps counters and seen signatures in memory, routing in one 0600 file.
  • APNs 410 Unregistered or BadDeviceToken deletes the route and answers 410: hz then drops the device.
  • The relay stores no payload, keeps no request logs (observability off, no console in its sources) and holds the APNs key, its key id and team id as Worker secrets; none of them is in the repository.

Token rotation and unregister. While a workspace is on, its page registers this device again on every load and whenever the app reports a new APNs token; the same device id updates its route. "Stop pushing to this device" (or removing this device's row) forgets the workspace's key in the app and unregisters the device at hz, which deletes its route at the relay; a 410 drops it too. After a reinstall (the Keychain outlives the app, its storage does not) the app forgets every key and makes new ones.

Which notices, when, shown once. Everything that pops up today is also pushed under the same policy (kinds, quiet mode, working hours, rate limit); [system.notify] push switches pushing on (off by default while dark) and push_<kind> each kind (on by default). A notice is pushed when it is due, unless a head watches (the open web app shows it) or it was already shown. When the web app shows or acknowledges it, hz sends clear to every device it went to, which removes it from Notification Center. The Mac app takes the same pushes and posts them itself; it is the app, not the daemon's notifier, so a person with both sees the daemon's pop-up only when push is off.

Actions. A notice in a Heinzel chat offers Reply (inline text); a notice that offers a decision offers Approve and Reject. Each action requires unlock (authenticationRequired) and opens the app (foreground), which hands it to the page: Reply sends the text into that chat at once, as compose does (0170); Approve and Reject open the notice's review, where the existing approval path decides. Nothing acts through the relay or from a locked device.

Dark. Behind the feature push_notices: off, hz registers no device, sends nothing, and Settings shows nothing.

Consequences

  • Good: notices reach a closed iPhone, iPad or Mac app, readable only there.
  • Good: the relay is small, stateless but for routing, and holds the only APNs key.
  • Bad: a new service the project must run, pay for and keep up; until then the feature stays dark.
  • Bad: a new direct dependency (cryptography, already installed through mcp); the relay learns when notices happen.
  • Bad: Debug and development builds can't receive pushes while the only APNs key is Production-only.
  • Bad: Approve and Reject open the review rather than deciding from the banner: the review's exact terms are the trusted boundary (0068, 0120), and a decision without them would bypass it.
  • Bad: iOS throttles background pushes, so clear is best effort.

Confirmation

Unit tests of the sender fail when a payload leaves hz unencrypted, a switched-off kind or a watched notice is pushed, a shown notice sends no clear, or a 410 keeps the device; a Python-made fixture must open in the Swift decryption test. The relay's Node test suite fails when an unsigned, stale or foreign request, a sandbox route or another topic is accepted, a limit is not enforced, or a body is logged or stored.

More Information

Built in 0.9.59, dark behind push_notices: this record, the relay (tested, not deployed, as a container and a Worker), hz's devices, sender, settings and per-kind switches, the web settings, the iOS notification service extension embedded in the app, the push entitlements and the remote-notification background mode (the release check requires them), the Mac app's own handling and its push entitlement on the profile-signed path (both Mac verifiers require it), the categories and the hand-over of actions, and scripts/apple_push_profiles.py, which registers the extension's App ID, enables Push and makes the App Store profiles. A device belongs to the workspace that registered it last. The Production APNs key exists outside the repository.

Still to do by the owner: run scripts/apple_push_profiles.py and then scripts/apple_devid_profiles.py, store the new secret HEINZEL_IOS_NOTIFICATIONS_PROFILE_B64 (and the refreshed app profiles) next to those of ADR 0172, deploy the relay with its secrets, and switch push_notices on. The app declares no non-exempt encryption today; whether HPKE through CryptoKit changes that answer is the owner's export-compliance call.