AUDIO
Listen to this page
Chapters
Remote access through a hub
The holai core only manages sensors/devices inside the home LAN, so it lives behind a NAT/router. But the user wants to control the house from the road — from anywhere with internet. This is delivered by a small, optional hub service.
Background: two roles, no port forwarding
Remote access needs the two classic server roles: a rendezvous (both peers announce themselves there) and a relay (carries traffic when the peers cannot reach each other directly). Both ends only ever make outbound connections to the rendezvous, so the home network needs no port forwarding. The holai hub keeps exactly those two roles, adapted to HTTP/WS APIs (direct hole punching buys nothing for request/response calls):
- home session — the core always opens an outbound WebSocket to the hub and stays attached under its home id
- tunnel — the hub bridges a client WebSocket with the home's; API frames flow end-to-end
- pairing key — the home attaches with a secret; a client may only tunnel to that home when the QR key matches
The home instance keeps its localhost life (sensors, devices); the hub knows nothing about the home contents — the home "phones" the VPS, and every tunneled request still carries the real user JWT.
The hub (deployed on a VPS)
hub/ — one small Node container carrying both roles (rendezvous + relay)
in a single process
(hub/server.js, run it as a plain container on a VPS; no docker socket,
no user data).
| Endpoint | Who | Purpose |
|---|---|---|
GET /health |
anyone | {ok, app:"holai-hub", homes} — also the hub signature for client discovery |
GET /admin/pubkey |
anyone | the hub's ed25519 public key (id pinning) |
POST /admin/homes |
hub-signed admin token | register a home / set-rotate its pair key (only the hash is stored) |
DELETE /admin/homes/:id |
hub-signed admin token | revoke a home's remote access |
WS /home-session?home=<id>&key=<pairKey> |
the home core (outbound from the LAN) | register + presence (heartbeat); id must be admin-registered |
WS /tunnel?home=<id>&key=<pairKey> |
a client from the internet | validates key + presence, then bridges to the home session |
Hub security & anti-spam (no passwords on the wire)
- ed25519 keypair auto-generated once, kept in
hub.jsonon the VPS; the admin token (printed on first boot) is hub-signed and verified both by the home (against the pasted public key) and the hub itself. - Homes attach only with a registered id + pair key; unknown ids / wrong keys are refused pre-upgrade (HTTP 401) — no socket is ever created.
- Per-IP rate limits on upgrades (30/min) and admin calls (10/min), bounded token maps, 8 MB frame cap.
- Users can never mint keys themselves; every admin op is a hub-signed token.
- The hub persists only the keypair + registered homes in
hub.json(survives restarts; the home re-attaches automatically); no users, no payloads — a dropped home session tears down its client tunnels. wss://(TLS) belongs to the VPS reverse proxy.
Frame protocol (text JSON messages, both directions)
{"c":"hReq","id":1,"method":"POST","path":"/chat","headers":{...},"body":"..."}
{"c":"hRes","id":1,"status":200,"headers":{...},"body":"..."}
Push (home → phone): notifications, chat messages, media
Remote profiles must also receive server-initiated data, exactly like
LAN clients (who listen to ws /api/v1/events). The tunnel socket is
reserved 1:1 for hReq/hRes — so pushes use their own listen-mode tunnel:
- the client opens a second WS
GET /tunnel?home=<id>&key=<key>&listen=1(same pre-upgrade firewall) and answer{"c":"listenOk"}; this socket carries home → client only. MaxHUB_MAX_LISTENERS(8) per home. - the home core subscribes to its local event bus and frames every event as
{"c":"push","event":{type, ts, …}}over its main session; the hub forwards it to every live listener (frame cap 64 KB per event). - the home session dropping tears down its listeners (close 4502); the client reconnects the listen socket automatically.
Event types delivered this way (identical shape on LAN and remote):
| type | payload | client reaction |
|---|---|---|
chat |
transcript, tool, reply, audioId, media | chat bubble + voice: fetch & play GET /api/v1/audio/:id (respecting the "play always/mute" setting) |
media |
id, kind, name, url | attachment thumbnail via GET /api/v1/media/:id (through the tunnel) |
notify |
title, body, audioId? | in-app notification (published by plugins via ctx.publish('notify', …)) |
Push payloads are small pointers, never blobs: audio/video travels on demand via the normal hReq tunnel endpoints with the user's JWT, so the hub still sees no payloads and nothing bypasses authorization.
End-to-end encryption — the hub works with ws:// or wss://
The hub runs fine on a bare http://<vps-ip>:8091 (TLS is optional; plain
ws:// home id + pair keys are still firewall-checked pre-upgrade).
Because a VPS IP cannot get a certificate for free, and because a malicious
hub operator must not read anything, all payload traffic is additionally
encrypted end-to-end between the home core and any remote client
(Flutter phone, web client, smart speaker — anything speaking the frame
protocol):
ek(encryption key): a second 256-bit random, generated together with the pair key at pairing/rotation. It lives only in the QR/connection string (holai://connect?hub=…&home=…&key=<pairKey>&ek=<ek>) and on the phone — it is never sent to the hub, so the hub stays hub-blind. Rotating keys rotatesekat the same time (new QR to scan).- Frames (hReq, hRes, push events) are wrapped as
{"c":"enc","v":1,"n":<12B nonce b64url>,"ct":<ciphertext‖GCM-tag b64url>}with AES-256-GCM, key =ekdirectly (32 bytes). Every frame gets a fresh random nonce; decryption failures drop the frame. - Compatibility: a client without
ek(old QR, LAN-only tool) may connect and open plaintext frames — the home detects support by the client saying{"c":"helo","enc":1}right after the tunnel opens and only then replies encrypted on that dial. Push listeners always receive AES frames whenekis configured. LAN access is unaffected (no frames at all). - What the hub can still see: home id presence, frame sizes, timing — no
URLs, no bodies, no JWT, no notification text. Combine with
wss://when available to hide metadata too.
Threat model: interruption vs man-in-the-middle
- MITM read/modify: no. TLS on
wss://plus the hub-blind AES-256-GCM frames above: an attacker on the wire (or a fully hostile hub operator) records only ciphertext and metadata; every tampered frame fails the GCM tag and is dropped, and an E2E-flagged dial refuses readable payloads (no downgrade). The home identity-pins the hub's ed25519 key at pairing and refuses to re-pair when it changes — a swapped or typosquatted hub is rejected; the pair key is stored at the hub as a sha256 hash only. - Interruption (DoS): yes — and it stays availability-only. The hub is a single public endpoint; taking it down (or dropping frames) loses remote access temporarily. It does not escalate: LAN control is unaffected, the home session auto-reconnects, no state lives at the hub, and interrupted requests fail honestly on the client.
- Root of trust is the QR/connection code. It carries the pair key +
ek— treat it like a password: anyone holding it can tunnel in. Rotating in the dashboard mints a fresh pair key + ek and invalidates every old QR. - Residual: a hostile root CA on a device breaks TLS verification (the
E2E layer still holds); a plain
ws://hub still keeps E2E encryption but leaks metadata — prefer TLS domains.
Home side + client side
- Home core (
server/src/services/hubSession.js): persistent outbound WS with reconnect backoff; frames arriving through the tunnel are replayed againsthttp://127.0.0.1:<port>/api/v1/…, so JWT/roles/scopes/audit are enforced locally exactly like on the LAN. Configured in the Admin → Remote access screen: hub URL, hub public key + admin token (pasted once per hub from the VPS console), then one-click Register / get pair key (the hub verifies the token before anything is sent). The home id is allocated at first pairing; "Rotate pair key" re-fires the signed call at any time. - Admin dashboard: Remote access page — status, the connection QR code, hub credentials, register/rotate, copy string.
- Flutter client (client): settings screen gains a
Scan QR code option (
mobile_scanner, mobile platforms) plus a manualholai://...paste field as the web fallback. A hub-connected profile behaves exactly like a LAN profile: every API call transparently rides the tunnel transport.
Testing
hub/tests/e2e.js proves the whole cycle: pairing → attach → tunnel → hub
restart + persistence → key rotation + revocation + push frames.
Last updated: November 2026