Skip to content

Room token and default device identity (§5f), before usernames - #809

Merged
transfix merged 6 commits into
feat/h1-admissionfrom
feat/h1-room-token
Oct 25, 2026
Merged

transfix merged 6 commits into
feat/h1-admissionfrom
feat/h1-room-token

Conversation

@transfix

@transfix transfix commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #807 (feat/h1-bound-writes). Roadmap §5f, v1: two credentials a client can carry before there are usernames.

Room token (who may join)

  • arisrv config: arisrv --room-token-file PATH, or CVC_ARISRV_ROOM_TOKEN.
    • The token is never read from the command line, which other users of the host can see.
    • Asking for a token and not getting a valid one stops arisrv instead of opening the room. That covers a flag with no path, an unreadable or blank file, and a set but empty variable.
    • Tokens are 16–256 characters of [A-Za-z0-9._~-].
    • With no token configured, the room is open as before.
  • gRPC: sends it as authorization: Bearer, which already existed. The comparison is now constant-time, and refusals are counted in total_auth_rejected().
  • WebSocket: new auth_config.
    • A browser can't set an Authorization header, so the client offers cvc.v1,cvc-token.<token> in Sec-WebSocket-Protocol.
    • The server reads the upgrade request itself and answers HTTP 401 unless the token is offered. It replies with cvc.v1, because a browser requires the reply to name a subprotocol it offered.
    • A client with no token offers no subprotocol, so it still works with older relays.
  • Before admission: both checks run before the connection is admitted, so a client without the token is sent nothing: no bootstrap, broadcast or media.
  • Clients: arigl reads CVC_ARIADNE_ROOM_TOKEN. The browser page takes it from the invite link's URL fragment (#token=…), which never reaches a server or its logs. Checked in the browser pane: the page picked the token up, and the static server's log shows the request without it.
  • WebSocket handshakes run on their own threads: each accepted connection now does its handshake, and so its token check, on its own thread, with a 10 s deadline and at most 64 at once. Before, one client that connected and sent nothing held up every join and hung stop().

Device id (which device is this)

  • On the wire: Hello.device_id (proto field 3), set with state_transport::set_device_id().

  • The default id: default_device_id() is a salted SHA-256 of the OS machine id, the host name and the user:

    • Linux: /etc/machine-id, or /var/lib/dbus/machine-id or /etc/hostid;
    • Windows: MachineGuid;
    • macOS: the host UUID.

    The raw values never leave the process.

  • In the browser: the page makes a random id once and keeps it in localStorage, or keeps it for one page load where storage is blocked. Under Emscripten the id is empty unless the page sets CVC_DEVICE_ID, since the constant browser environment would otherwise give every browser the same id.

  • Per relay: a client sends scoped_device_id(base, relay URL), so two relays (two operators) can't match one device.

  • Relay side:

    • A relay ignores a device id that isn't 1–64 characters of [A-Za-z0-9._-].
    • Link reports carry remote_device_id, plus holds_id (whether that link holds its pid under bound writes).
    • arisrv publishes participants.<pid>.device, a room-scoped 16-hex tag, written only from the link holding the pid (room_net write_link_devices, which the loopback test also calls). Every peer sees the same tag for one device in one room across sessions. The tag is relay-owned, and room_write_gate refuses a client's write to it.
  • Not a credential: anyone who knows or observes the inputs can compute the id. Giving it authority (roles, bans) needs a key the device keeps and the relay pins on first use.

Review

An independent review found no way past the token. These findings are fixed here:

  • Open room by mistake: a blank or missing token config could silently open the room.
  • Unbounded device id: the relay's main loop could be made to hash megabytes every second.
  • Shared browser id: wasm gave every storage-blocked browser the same id.
  • Idle handshakes: one silent connection could block every WebSocket join (this predates the change).
  • Missing tests:
    • the cvc.v1 reply;
    • a token sent to an open relay;
    • a wrong gRPC token;
    • holds_id == false;
    • the integration test copying arisrv's device loop instead of calling shared code.
  • Smaller fixes:
    • Refused gRPC streams: a refused stream now logs a hint, since connect_to_peer reports success before the server refuses.
    • Per-relay ids: the scoped device id.
    • 32-bit Windows: MachineGuid is now read with KEY_WOW64_64KEY.

Testing

  • New tests:
    • WebSocket: RoomTokenIsCheckedAtTheHandshake (no token, a wrong token, the right token with its device id, and a raw handshake asserting the cvc.v1 reply), ARoomTokenOfferedToAnOpenRelayIsHarmless, AnIdleHandshakeDoesNotBlockOtherJoins and LinkReportsShowTheHolderAndAValidDeviceId.
    • gRPC: BearerTokenRejectsAWrongToken and HelloCarriesTheDeviceId; BearerTokenRejectsMissingMetadata now also checks the refusal count.
    • Loopback: RoomRelayLoopbackTest.RoomTokenAdmitsOnlyItsHolders. Clients holding the token see each other's device tags; on each transport, a client without it is refused and never sees the room.
    • Unit tests: state_identity_test (the token rule, the device id, the scoped id) and RoomNet.ADeviceTagIsPerRoom.
  • Before the review fixes:
    • Windows, static WS tree: WS 33/33, gRPC 43/43, room relay 13/13, room intrinsics 8/8, identity 4/4.
    • Windows, shared build: 4,865/4,865 (-E Convergence), with cvc.dll at 65,228 exports.
    • state_identity.cpp compiles under em++.
  • After the review fixes:
    • Windows, static WS tree: WS 36/36, gRPC 44/44, room relay 13/13, room intrinsics 8/8, identity 6/6.
    • arisrv exits with status 2 for --room-token-file with no path, a blank token file, or a too-short CVC_ARISRV_ROOM_TOKEN.
  • cyprty built for wasm on Windows from cvcpkg: 22 wasm bundles from the catalog, plus protobuf 28.3 built for wasm by recipe(protobuf, wasm): build libprotobuf for wasm cy-pca/cvcpkg#452. It links, with cyprty.wasm at 49.8 MB. The final link needed ImageMagick's codec libraries passed explicitly, which is the open wasm: build the gallery and pycvc-gl with ImageMagick ON, and make it work #801 fix and not part of this PR.
  • Browser smoke against a local arisrv with --room-token-file:
    • Without #token=: the WebSocket handshake fails in the page, and the relay logs room token: refused 1 connection(s) with 0 links and 0 present.
    • With it: the client joins, the roster shows it at a 37 ms ping, and its admission hold is released by its filter (admissions held 1 (timed out 0)). Its media is routed, and the refusal count stays at 1.
  • Formatting: clang-format 18.1.8 reports no changes.

Known limits

  • One shared token: one token per room, so revoking one person means rotating it for everyone. Per-person tokens and roles come later.
  • Media plane not gated: the separate gRPC media plane (stream_relay) doesn't check the token yet.
  • No TLS: over ws:// or insecure gRPC the token travels in cleartext. Deploy behind wss://.
  • Old relays: a browser offering a token to a relay that predates this answers no subprotocol, so the browser drops the connection.

The relay applied and forwarded whatever a client sent: another
participant's intent, the server holon's poses, the scene, mutations or
media naming another origin, even a snapshot pushed at it.

state_inbound_gate (cvc/state), installed with
state_transport::set_inbound_gate on gRPC and WS, governs what a
transport takes from the connections it accepts. Dialed connections,
the bridge and the relay's own writes are not gated.

- Identity: a connection speaks only as the node id of its first Hello.
  One live connection holds a node id at a time. The first claim wins
  until it closes, or until it has been silent for 6 s (three missed
  link probes), when the next claim takes it over: a dropped network
  leaves the old stream open. The relay's own ids (its transport's and
  its shards') are never a client's.
- Origin: mutations, messages and media must name that id, and gRPC
  heartbeats must name it as their node. A client's SnapshotResponse is
  never applied, and a snapshot request is answered only for a
  connection speaking as itself.
- Departure: a close is that peer leaving only when the connection
  still held its id.
- Refused frames are not applied, forwarded or bridged; they are counted
  in total_inbound_rejected().

room_write_gate is the room's rule:
- a participant writes only inside conf.rooms.<room>.participants.<pid>,
  with value, touch or data ops;
- never the relay's keys there: pose, net.relay, and streams.<kind>.ready;
- only on canonical paths of at most 16 segments and 512 bytes (no empty
  or padded segment, which the tree would trim onto another key);
- and only for a pid that is one identifier.

Every client write today fits this rule.

arisrv --bind-writes on|off (default on; not an S7 switch) installs one
gate on both transports, and logs refusals as their count grows. The
bench mirrors it. The gate's holder map is file-local, so cvc.dll grows
only 71 names (65,198 of 65,535).

Tests:
- InboundGate{TakesOnlyWhatAPeerMayWriteAsItself, BindsANodeIdTo*,
  RefusesTheRelaysOwnId, HandsASilentHoldersIdOver} for gRPC and WS, and
  InboundGateSpansBothTransports;
- RoomWriteGate.* (the rule, binding, takeover);
- RoomRelayLoopbackTest.ClientWritesOnlyItsOwnParticipant: what the
  relay applies from a client that writes A's intent and pose, its own
  pose by normalising paths, the scene and the AOI, and A's intent as A.
  Mutants without the relay-id or canonical-path checks fail these.
- NoIntentOrUiDocsLeak now expects the echo refused by the write gate,
  and ControlPlaneEgressDrops's pre-S7 baseline turns bound writes off.
Two credentials a peer can carry before there are accounts.

Room token -- who may join:
- arisrv takes it from --room-token-file PATH or CVC_ARISRV_ROOM_TOKEN,
  never from the command line. A token asked for must be a valid one: a
  flag with no path, an unreadable or blank file, or a set but empty
  variable is an error, not an open room.
- gRPC carries it as authorization: Bearer, now compared in constant
  time and counted in total_auth_rejected().
- WebSocket gains auth_config. A browser cannot set an Authorization
  header, so the client offers "cvc.v1,cvc-token.<token>" in
  Sec-WebSocket-Protocol. The server reads the upgrade request itself,
  refuses it with HTTP 401 unless the token is offered, and answers
  cvc.v1 (a browser requires the reply to name an offered subprotocol).
- Both checks run before admission, so a client without the token is
  sent nothing.
- arigl reads CVC_ARIADNE_ROOM_TOKEN. The browser page takes it from the
  invite link's URL fragment (#token=...), which never reaches a server
  or its logs.
- With no token configured the room is open, as before.

Each accepted WebSocket connection now does its handshake on its own
thread (10 s deadline, at most 64 at once). One client that connected
and sent nothing used to hold up every join, and stop().

Device id -- which device is this:
- Hello gains device_id (field 3), set with
  state_transport::set_device_id().
- default_device_id() is a salted SHA-256 of the OS machine id, the host
  name and the user. Under Emscripten it is "" unless CVC_DEVICE_ID is
  set; the page keeps a random id in localStorage, per page load where
  storage is blocked.
- A client sends scoped_device_id(base, relay URL), so two relays cannot
  match one device. A relay ignores an id that is not valid_device_id
  (1-64 of [A-Za-z0-9._-]).
- Link reports carry remote_device_id and holds_id.
- arisrv publishes participants.<pid>.device, a room-scoped 16-hex tag,
  from the link holding the pid (room_net write_link_devices).
  room_write_gate refuses a client's write to it.
- It is an identifier, not a credential: giving it authority needs a
  key the device keeps and the relay pins.
The per-connection handshake stamps handshake_started_ns in accept_loop,
above steady_ns's definition: native builds with WebSocket failed to
compile (the wasm build skips accept_loop).
Bound writes (#807) is now squashed into feat/h1-admission; merged with its head as the base, so only this branch's own changes apply. The tree is unchanged.
@transfix
transfix changed the base branch from feat/h1-bound-writes to feat/h1-admission October 25, 2026 07:40
…t use (§5f) (#816)

The device id names a device; this gives it authority.

Keys (state_device_key.h, on OpenSSL's libcrypto):
- A device keeps one 32-byte seed: %LOCALAPPDATA%\cvc\device-key, or
  $XDG_CONFIG_HOME/cvc/device-key (~/.config/cvc/device-key), made on
  first use, owner-only on POSIX, and published in one step so two
  first launches agree on one seed. CVC_DEVICE_KEY_FILE names another
  file; CVC_DEVICE_KEY (64 hex) gives the seed itself, which is how the
  browser page passes the one it keeps in localStorage.
- For each relay it derives an Ed25519 key, HMAC-SHA256 of the seed and
  the relay URL, so two relays see unrelated keys.

The proof:
- A relay with a pin store puts a fresh 32-byte nonce in its Hello to
  each connection it accepts (Hello.nonce, field 4).
- The client answers with a DeviceProof (Frame field 12): its public
  key and a signature over the nonce, both node ids and its device id,
  each length-prefixed. One proof per challenge. A proof that arrives
  before the client's own Hello is held and checked when it comes.
- The relay verifies it and pins the key to the device id on first use
  (state_device_pins). A later proof under the pinned key verifies the
  link (state_link_report::device_verified); another key, or a bad
  signature, is refused and counted. A refused device stays in the
  room, without a tag. A store holds at most 65,536 pins.

The room:
- participants.<pid>.device is written only for a verified link that
  holds the pid, and cleared when the pid's holder proved no key, so a
  takeover does not keep the last device's tag.
- arisrv keeps one pin store for both transports, in memory or in a
  file with --device-pins PATH, and logs refused proofs.
- arigl loads the seed and signs for its relay; the page keeps the seed
  in localStorage (cvc.device_key) beside its device id.

Without OpenSSL nothing is derived or verified, and no device has a tag.
…oesn't jump, and ~1/8 of the video bandwidth (#819)

* Device keys: a device proves its id with a key the relay pins on first use (§5f)

The device id names a device; this gives it authority.

Keys (state_device_key.h, on OpenSSL's libcrypto):
- A device keeps one 32-byte seed: %LOCALAPPDATA%\cvc\device-key, or
  $XDG_CONFIG_HOME/cvc/device-key (~/.config/cvc/device-key), made on
  first use, owner-only on POSIX, and published in one step so two
  first launches agree on one seed. CVC_DEVICE_KEY_FILE names another
  file; CVC_DEVICE_KEY (64 hex) gives the seed itself, which is how the
  browser page passes the one it keeps in localStorage.
- For each relay it derives an Ed25519 key, HMAC-SHA256 of the seed and
  the relay URL, so two relays see unrelated keys.

The proof:
- A relay with a pin store puts a fresh 32-byte nonce in its Hello to
  each connection it accepts (Hello.nonce, field 4).
- The client answers with a DeviceProof (Frame field 12): its public
  key and a signature over the nonce, both node ids and its device id,
  each length-prefixed. One proof per challenge. A proof that arrives
  before the client's own Hello is held and checked when it comes.
- The relay verifies it and pins the key to the device id on first use
  (state_device_pins). A later proof under the pinned key verifies the
  link (state_link_report::device_verified); another key, or a bad
  signature, is refused and counted. A refused device stays in the
  room, without a tag. A store holds at most 65,536 pins.

The room:
- participants.<pid>.device is written only for a verified link that
  holds the pid, and cleared when the pid's holder proved no key, so a
  takeover does not keep the last device's tag.
- arisrv keeps one pin store for both transports, in memory or in a
  file with --device-pins PATH, and logs refused proofs.
- arigl loads the seed and signs for its relay; the page keeps the seed
  in localStorage (cvc.device_key) beside its device id.

Without OpenSSL nothing is derived or verified, and no device has a tag.

* Conference roster: a volume slider that holds still, and per-peer controls that follow the person

The Users window's volume slider sat in an auto-width table column. ImGui re-fits such a column to
its content every frame, and a slider in a cell took ~65% of it (ImGui's default item width), so
the column shrank by a third each frame until reserve_label_width's 48 px floor snapped it back: the
bar never held a width long enough to be dragged. The six fixed columns also already filled the
420 px window, which clipped the slider to a sliver.

- ImGuiBackend: a slider or int widget in a table cell now fills its cell, so an auto-width column
  settles at once (cvcgl_imgui_grid_slider: without this the column ends at 13 px, oscillating).
- conference_roster.ari: every roster column has a fixed width (vol 72 px), the window is 470 px,
  and the peer camera tiles move right with it. Each row's two name texts (plain and talking-green)
  are one group, so the cell exists on a frame where neither visibility check runs and the row no
  longer shifts left.
- Per-peer cam, mic and volume were keyed by roster ROW, and rows are sorted by pid, so a join or
  leave moved your settings onto someone else. on_tick now parks each row's controls under its pid
  (ctl.<pid>.*) before the rebuild and gives each row its own pid's back.

* Conference movement: the mover's own avatar stops jumping

Other people's view of a walking avatar was smooth, but the walker's own view jumped. arigl
predicts its avatar locally and replays its inputs on each server pose, so it was the only viewer
that saw the reconcile path, and three things fed that prediction the wrong history:

- The relay's ~1 Hz WebSocket re-broadcast sent a client its OWN intent back. The relay forgets a
  path when the client writes it, so the broadcast carried whatever the relay held; with the
  client's next write still in flight, that was the previous intent. The client applied it and
  predicted on it until the next key change or broadcast, while the server integrated the real one,
  so every 20 Hz pose snapped it back and the replay pushed it on again.
  - state_inbound_gate::sources (default false): whether a path is a peer's own. room_write_gate
    answers with its write rule, and broadcast_snapshot never sends such a path to its source.
  - arigl takes a tree intent only when it is not older than its last proposal
    (holon_sync read_current_intent; propose_intent now returns its stamp). A stamp of 0, the
    document's room-set-intent, is always taken.
- A clock realign wiped the input log. arigl moves its lead with the measured round trip, and any
  rise of ~50 ms seeked the clock and dropped the logged inputs, so the next pose snapped the
  avatar back by a round trip of walking. Within max_skew_ticks the client now slews its clock
  (holon_config::lead_slew, 5%) toward the target instead; the first alignment, joining, still
  seeks.
- The local avatar was drawn at its last whole 120 Hz quantum, so frames between quanta stood still
  and the rigidly following camera passed that judder to the whole view. display_pose now
  interpolates it between its last two quanta by the frame's alpha, as peers already are, and a
  reconcile shifts that interpolation with its correction.

Tests: RoomRelayLoopbackTest.ABroadcastNeverEchoesAClientsOwnIntent (the echo, end to end over WS;
fails without the broadcast skip), HolonTest.ALongerLeadIsSlewedIntoWithoutACorrection (a lead step
mid-walk: no correction slewing, one seeking), ClientSlewsTowardANewLead,
TheLocalAvatarIsShownBetweenQuanta, HolonSyncTest.ReadCurrentIntentRefusesAnEchoOfAnEarlierProposal
and RoomWriteGate.AParticipantSourcesWhatItWrites. Each fails with its fix removed.

* cvcgl_room_view: the local avatar's turn shows a quantum after it is taken

holon::display_pose now shows the local avatar between its last two quanta by the frame's alpha, so a turn taken on one quantum is drawn on the next. The visor check advances two quanta instead of one.

* Conference media: a fraction of the bandwidth, and an uplink that sheds instead of queueing

What each participant cost (the user's question; a 4-person room, every pair in view):
- Camera: 640x480 MJPEG at q70 and 30 fps, about 4-5 Mbit/s per receiver (17-22 KB a frame for a
  detailed scene with webcam-like noise), shown in ~300 px tiles.
- Mic: raw 32-bit float PCM at 48 kHz, 1.5 Mbit/s, sent even when muted or silent.
- So about 7.6 Mbit/s up and 23 Mbit/s down per client, and the link probe queued behind it.

Changes:
- The camera is captured at 320x240, 15 fps and q60: about 0.6 Mbit/s per receiver, ~8x less, for
  the same tiles. stream-capture-camera gains a `quality` option (1-100, default 70); it was always
  q70.
- arigl sends no mic chunk below -48 dBFS RMS more than 0.8 s after a louder one, so a silent or
  muted mic costs nothing (receivers already mix silence for a peer with no chunks, and its video
  runs free). A muted camera sends one frame a second instead of 15.
- A browser's send backlog is now WebSocket.bufferedAmount (it was always 0 there), so its uplink
  drops media at the 32 KB threshold instead of queueing it without bound behind every other frame,
  the link probe included.
- On every WebSocket link audio gets four times video's backlog allowance: a congested link sheds
  video first.

The roadmap records the new defaults (and the re-broadcast's no-echo rule from the movement fix).
Opus audio and per-receiver rungs are next.
@transfix
transfix merged commit 8d247ab into feat/h1-admission Oct 25, 2026
5 of 6 checks passed
transfix added a commit that referenced this pull request Oct 25, 2026
With #809 (room token, device keys) and #819 (conference fixes) collapsed into
feat/h1-admission, #796 into master runs the changed-lines clang-format check
over them for the first time (stack PRs into feature branches skip it).
Alignment only: holon.h, arisrv/main.cpp, cvcgl_media_capture.cpp.
transfix added a commit that referenced this pull request Oct 25, 2026
#819 (feat/h1-conf-fixes) was squash-merged into feat/h1-room-token and that,
as #809, into feat/h1-admission, which now also carries master. Merge base
555f326, the conf-fixes head this branch was built on (its tree is exactly
#819's squash). The cherry-picked #793 export filter (5ec3f19) now matches
master's own copy, so it merges away.
transfix added a commit that referenced this pull request Oct 26, 2026
… field fixes, per-viewer video rungs and Opus mics (#796)

The conference stack after #783, squashed through feat/h1-admission:

- #796 admission hold: a late joiner's admit snapshot goes through its AOI
  filter (no other participant's intent, the outer peer by push).
- #807 bound writes: a relay client writes only its own participant subtree,
  as itself.
- #809 room token and a default device identity (section 5f); #816 device keys,
  TOFU-pinned by the relay.
- #819 field fixes: a volume slider that holds still, a mover's own avatar
  that no longer jumps (the WS re-broadcast echoed its intent; the clock slews
  instead of seeking), and about 1/8 of the video bandwidth.
- #821 per-viewer video rungs (the relay re-encodes each camera for each
  viewer's link: full / half / quarter / thumb / off, adapted from queueing,
  drops and budget), Opus mics (32 kbit/s instead of 1.5 Mbit/s), a camera-off
  flag, status dots, and libopus for the libcvc recipe (cvcpkg libopus cvc.8).
- 05d0d60: the clock slews after any first sample, not only after a first
  seek (HolonTest.AClientInStepFromItsFirstSampleStillSlews), and two relay
  loopback tests bound wall-clock rates loosely enough for a Debug gRPC runner.
@transfix
transfix deleted the feat/h1-room-token branch October 29, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant