Zero-Knowledge HPKE Push & LiveKit RTC
FynnCloud provides two built-in platform brokers so apps never handle raw Apple APNs .p8 keys, Firebase credentials, or LiveKit master API secrets:
- Zero-Knowledge HPKE Push (
/api/push/devices) — End-to-end encrypted mobile/desktop push delivery for apps withnotifications:send(plus iOS PushKit VoIP when combined withrtc:roomsandpush.voip: true). - LiveKit RTC Broker (
/api/rtc/*) — App-isolated SFU room token minting and moderation for apps withrtc:rooms.
Part 1: Zero-Knowledge HPKE Push Notifications
Section titled “Part 1: Zero-Knowledge HPKE Push Notifications”1. Declare Push Support in manifest.json
Section titled “1. Declare Push Support in manifest.json”{ "permissions": ["notifications:send", "rtc:rooms"], "push": { "gateways": ["https://push.fynncloud.ch/v1/push"], "voip": true }}push.gateways: 1–5 publichttps://PushRelay URLs allowed for your companion clients. (Administrators can override per app withPUSH_GATEWAY_OVERRIDES.)push.voip: Required alongsidenotifications:send+rtc:roomsto permitapns-voipregistrations on iOS.
2. Generate Device X25519 Keypair & Register (/api/push/devices)
Section titled “2. Generate Device X25519 Keypair & Register (/api/push/devices)”On first launch (and whenever the OS rotates the push token), the native companion client generates a Curve25519 keypair (Curve25519.KeyAgreement.PrivateKey), stores the private key in the device Keychain / App Group Keychain (shared with your iOS UNNotificationServiceExtension), and registers the raw 32-byte base64 public key:
PUT /api/push/devicesAuthorization: Bearer <AppAccessToken with notifications:send>Content-Type: application/json
{ "installationId": "iphone-16-pro-abc123", "platform": "ios", "transport": "apns", "environment": "production", "target": "ch.fynncloud.talk", "token": "<64-256 lowercase hex APNs token>", "keyId": "k1-2026", "publicKey": "<base64 of 32-byte raw X25519 public key>", "gatewayUrl": "https://push.fynncloud.ch/v1/push"}Transport & Validation Rules
Section titled “Transport & Validation Rules”| Transport | Platforms | target Format |
Token Format | Keypair Required? | Notes |
|---|---|---|---|---|---|
apns |
ios, macos |
Bundle ID (must not end in .voip or .pushkit.fileprovider) |
64–256 even hex chars | Yes | Standard alert & silent background dismiss |
apns-voip |
ios only |
Must end with .voip |
64–256 even hex chars | Yes | Requires notifications:send + rtc:rooms + push.voip: true |
apns-fileprovider |
ios, macos |
Must end with .pushkit.fileprovider |
64–256 even hex chars | Optional | Official core client only; optional domain (1–256 chars) |
fcm |
android |
Android package ID | 16–512 non-whitespace chars | Yes | Data-only HPKE encrypted push |
unifiedpush |
android (etc.) |
App target string | 1–512 non-whitespace chars | Yes | Requires server PUSH_ALLOW_UNIFIEDPUSH=true & public https:// gatewayUrl |
- Account-switch safety: Re-registering an existing
(transport, target, token)row reassigns ownership to the current user/app so notifications never leak across accounts on a shared device. - Listing & Cleanup:
GET /api/push/devices— List registrations for the current(user, appId).DELETE /api/push/devices/:deviceID— Delete one registration.DELETE /api/push/devices/installation/:installationID— Delete all transports (e.g. bothapnsandapns-voip) for an installation on sign-out.
3. HPKE Encryption Wire Format (PushCrypto)
Section titled “3. HPKE Encryption Wire Format (PushCrypto)”Whenever your backend calls POST /api/apps/notifications (or /dismiss), PushDispatchService automatically seals an EncryptedPushPayload (v: 1) individually for every registered device of each recipient:
- Ciphersuite (RFC 9180 Base Mode):
- KEM:
DHKEM(X25519, HKDF-SHA256) - KDF:
HKDF-SHA256 - AEAD:
AES-256-GCM - Domain info string:
"fynncloud-push-v1"(UTF-8 bytes)
- KEM:
- Wire encoding (
ciphertext):base64(encapsulatedKey[32 bytes] || aeadCiphertextAndTag) - Collapse ID:
hex(SHA256("<appId>:<key>")[0..<16])(32 lowercase hex chars, never exposes plaintextkeyto relays) - Plaintext JSON (
EncryptedPushPayloadv1):
{ "v": 1, "event": "upsert", "appId": "talk", "key": "msg:room-42", "kind": "message", "title": "Alice", "body": "See you in 5 minutes!", "route": "/rooms/room-42", "sound": "chime", "priority": "normal", "metadata": { "roomId": "room-42" }, "expiresAt": 1796225000}For dismiss events (POST /api/apps/notifications/dismiss), event is "dismiss" with { "v": 1, "event": "dismiss", "appId": "...", "key": "..." }, sent as kind: "background" with ttlSeconds: 30.
4. On-Device Decryption (Swift CryptoKit)
Section titled “4. On-Device Decryption (Swift CryptoKit)”import CryptoKitimport Foundation
func decryptFynnCloudPush(ciphertextBase64: String, privateKey: Curve25519.KeyAgreement.PrivateKey) throws -> Data { guard let wire = Data(base64Encoded: ciphertextBase64), wire.count > 32 + 16 else { throw NSError(domain: "PushCrypto", code: 1) } let ciphersuite = HPKE.Ciphersuite( kem: .Curve25519_HKDF_SHA256, kdf: .HKDF_SHA256, aead: .AES_GCM_256 ) let encapsulatedKey = wire.prefix(32) let ciphertext = wire.dropFirst(32) var recipient = try HPKE.Recipient( privateKey: privateKey, ciphersuite: ciphersuite, info: Data("fynncloud-push-v1".utf8), encapsulatedKey: encapsulatedKey ) return try recipient.open(ciphertext)}Routing Behavior for Ringing Calls vs Alerts
Section titled “Routing Behavior for Ringing Calls vs Alerts”- When
descriptor.kind == "call"andeffectiveSound != "none"(not muted by DND):- On iOS, dispatch targets
apns-voipexclusively (kind: "voip",urgency: "call",ttlSeconds: min(remaining ?? 45, 60),collapseId: nil) so CallKit rings immediately. - Non-call pushes never use
apns-voip. - Call pushes do not fall back to
coreapp devices—only the calling app’s native companion devices receive them.
- On iOS, dispatch targets
- Non-call alerts target the app’s registered companion devices if the user has any, otherwise falling back to
core(FynnCloud-Apple) devices. - PushRelay returns HTTP
410(unregistered: true) on dead APNs/FCM tokens, and FynnCloud automatically prunes them frompush_devices.
Part 2: LiveKit RTC Broker (/api/rtc/*)
Section titled “Part 2: LiveKit RTC Broker (/api/rtc/*)”Apps declaring rtc:rooms call /api/rtc/* from their backend using X-FynnCloud-App-ID + X-FynnCloud-App-Secret. Every room name is validated against ^[A-Za-z0-9._\-]{1,128}$ (disallowing ..) and automatically isolated as app_<appId>_<room>.
1. Check LiveKit Availability (GET /api/rtc/status)
Section titled “1. Check LiveKit Availability (GET /api/rtc/status)”// Configured:{ "enabled": true, "url": "wss://cloud.example.com/livekit" }
// Unconfigured (fall back to P2P WebRTC):{ "enabled": false, "url": null }2. Mint a Participant Token (POST /api/rtc/token)
Section titled “2. Mint a Participant Token (POST /api/rtc/token)”Request:
{ "room": "room-42", "identity": "<userUUID>", "name": "Alice", "metadata": "{\"avatar\":\"...\"}", "canPublish": true, "canSubscribe": true, "canPublishData": true, "ttlSeconds": 3600}identity: 1–128 chars.ttlSeconds: clamped to60–86400seconds (default3600).canPublish/canSubscribe/canPublishData: defaulttrue.
Response (200 OK):
{ "enabled": true, "url": "wss://cloud.example.com/livekit", "room": "app_talk_room-42", "token": "<HS256 LiveKit JWT>", "expiresIn": 3600}If LiveKit is not configured on the instance, POST /api/rtc/token still returns 200 OK with { "enabled": false, "url": null, "room": null, "token": null, "expiresIn": null } so your app can seamlessly fall back to P2P WebRTC.
3. Room Moderation (Twirp Proxy)
Section titled “3. Room Moderation (Twirp Proxy)”- Mute/unmute a participant’s audio tracks:
ReturnsPOST /api/rtc/rooms/:room/muteContent-Type: application/json{ "identity": "<userUUID>", "muted": true }
204 No Content. Internally calls LiveKitGetParticipantandMutePublishedTrackfor every publishedAUDIOtrack. - Kick / remove a participant:
ReturnsDELETE /api/rtc/rooms/:room/participants/:identity
204 No Content(treats LiveKit404 not_foundas idempotent success).