Docs

Push notifications

How notifications reach phones and browsers, what the push relay is and how to set it up.

While the app is open, messages arrive over its own connection to the federation without any setup. Push is for notifications that arrive while the app is closed or in the background. On Windows push is not used: the app shows notifications itself while it runs or sits in the tray.

How it works

federation server ──signed request──▶ push relay ──▶ APNs (Apple) / FCM (Google) / Web Push
      │                                                     │
      └── text encrypted to the device's key ───────────────┴──▶ the device decrypts it
  • The push relay (backend/comon_push_relay) is a separate service that holds Apple and Google tokens and browser subscriptions and passes notifications to them.
  • The federation stores only opaque relay identifiers, never device tokens.
  • The notification text is encrypted to the key of the particular device (JWE, A256GCM). The relay, Apple and Google see an encrypted blob, the time and the size. From outside the notification looks like "New message".
  • A federation can trust several relays at once: each device binding remembers the relay it was made through.

Which relay you need

The relay's address is built into the app, and the Apple and Google keys belong to whoever publishes the app. That gives two cases.

The official Comon apps send push through the project's relay. For them to get notifications from your federation, that relay's operator must trust your federation's sender key (federation_sender_keys and admission_senders in its settings), and your federation must know that relay in federation-push.json. Without that the apps work, but notifications arrive only while they are open.

Your own relay makes sense:

  • with your own app build: your own bundle ID and APNs key, your own Firebase project (developers);
  • for your own web client: Web Push needs no Apple or Google keys, only your own VAPID key pair (web client).

Turning it on in the ready-made stack

The command sets up one provider: APNs for iPhone and Mac, or FCM for Android. It needs openssl on the machine.

# APNs
python3 tools/mvp-stack.py enable-push \
  --apns-key /path/AuthKey_KEYID.p8 --apns-key-id KEYID --apple-team-id TEAMID \
  --push-topic <bundle id> --push-environment production
# or FCM
python3 tools/mvp-stack.py enable-push \
  --fcm-credentials /path/firebase-service-account.json --fcm-project <project id> \
  --push-topic <application id>

python3 tools/mvp-stack.py up

A second provider and Web Push are added to relay.json by hand (fields below), keeping the keys already created.

The command creates the relay's and the federation's keys, writes relay.json and federation-push.json, adds the /push/* route to Caddy and the push-relay service. Running enable-push again refuses, so it never replaces keys. The relay shares the server's network namespace: the server reaches it at http://127.0.0.1:8090, the apps at https://<domain>/push. The .p8 key is mounted read-only and never copied into build contexts.

--push-environment sandbox is for builds from Xcode, production for TestFlight and the App Store.

Admitting installations

The relay accepts only known installations of the app. There are two ways:

  • Through the federation (the usual one): the app signs in to the federation, gets a signed ticket from it and registers with the relay using it. The federation's ID must be in admission_senders.
  • By hand: the app writes the installation's public data to comon-push/admission.json; the operator checks that the file came from the right device and admits it:
python3 tools/mvp-stack.py admit-installation --admission-file /path/admission.json
python3 tools/mvp-stack.py up

On registration the relay also checks that the device owns the token: it sends a one-time code through APNs, FCM or Web Push itself.

Relay settings (relay.json)

Only the owner may read the file (0600), or the relay will not start.

FieldMeaning
host, portWhere to listen. 127.0.0.1:8090 by default. Any non-local address requires behind_tls_proxy: true and a TLS proxy in front of the relay.
database_pathAbsolute path to the relay's SQLite database.
audienceThe relay's name in signatures, tickets and receipts. comon-push-relay by default.
storage_key32 random bytes (base64url) that encrypt tokens in the database. Lose it and everyone registers again.
receipt_seed32 random bytes (base64url): the Ed25519 key the relay signs receipts with.
allowed_topicsAPNs topics: <bundle id>@sandbox or @production. For calls on iPhone add <bundle id>.voip@….
apnskey_path (absolute path to the .p8), key_id, team_id.
fcmcredentials_path (Firebase service account), project_id, allowed_topics such as <application id>@production.
webpushorigins: for each web client address, vapid_private_key_file and subject (mailto: or https:); allowed_push_hosts: a closed list of browser push services.
federation_sender_keysFederation ID → its public sender key.
admission_sendersFederations allowed to admit new installations.
installation_keysInstallations admitted by hand.
max_queueThe job queue, 10,000 by default; one federation may use a quarter.

The relay needs Node and curl with HTTP/2 for APNs; the ready-made stack's image has both.

The allowed_push_hosts list for Web Push is usually:

["fcm.googleapis.com", "updates.push.services.mozilla.com", "web.push.apple.com", "*.notify.windows.com"]

backend/comon_push_relay/bin/vapid_keygen.dart creates a VAPID key pair. Never change the VAPID key: browsers tie every subscription to it, and with a new key every subscription stops working until people subscribe again.

Federation settings (federation-push.json)

The server reads the file through --push-config:

{
  "sender_seed": "<32 bytes, base64url>",
  "storage_key": "<32 bytes, base64url>",
  "relays": [
    {
      "origin": "http://127.0.0.1:8090",
      "audience": "comon-push-relay",
      "public_key": "<the relay's receipt key, base64url>",
      "allow_loopback_http": true
    }
  ]
}
  • sender_seed is the key the federation signs relay requests with. Its public half goes into federation_sender_keys of every relay.
  • relays are the relays the federation trusts. When adding a new one, keep the old one first: it owns the bindings made before bindings started remembering their relay.
  • Remove a relay from the list and its bindings stop working; the apps bind again.
  • The former top-level fields relay_origin, relay_audience, relay_public_key and allow_loopback_http are refused and the server does not start: move them into one entry of relays.

Delivery

  • A notification lives up to five minutes and is retried up to eight times. On Apple or Google errors the retry is postponed by 15 minutes, so old notifications never arrive in a batch.
  • The relay tries to remove a notification read on another device, but Apple and Google do not guarantee it.
  • GET /push/healthz shows that the process is alive, not that notifications get through.

Relay backup

The relay's database is part of the stack's backup; the .p8 key is not, so keep it separately. After a restore push turns itself off: old revocations and preview keys need reconciling, and devices register again. Do not turn an old relay copy back on blindly.

On this page