Skip to content

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

Merged
transfix merged 1 commit into
feat/h1-room-tokenfrom
feat/h1-device-keys
Oct 25, 2026
Merged

transfix merged 1 commit into
feat/h1-room-tokenfrom
feat/h1-device-keys

Conversation

@transfix

@transfix transfix commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #809 (feat/h1-room-token). Roadmap §5f, next step: the device id named a device; now a device proves it with a key it keeps, and the relay pins that key on first use.

Keys

  • Module: state_device_key.h, Ed25519 on OpenSSL's libcrypto. cvcpkg has an openssl bundle for every platform we ship, wasm included.

    • Without OpenSSL nothing is derived or verified, and no device gets a tag.
    • CMake logs cvc::state: device keys ENABLED (OpenSSL x.y.z) when it finds OpenSSL.
  • The seed: each device keeps one 32-byte seed. Natively it lives at:

    • Windows: %LOCALAPPDATA%\cvc\device-key (local, not roaming);
    • elsewhere: $XDG_CONFIG_HOME/cvc/device-key, falling back to ~/.config/cvc/device-key.

    It is made on first use, owner-only on POSIX. It is written in full to a temporary file and then published in one step that fails if the file already exists (link() / MoveFileExW). So two first launches agree on one seed, and neither reads a half-written file.

  • Overrides: CVC_DEVICE_KEY_FILE names another seed file. CVC_DEVICE_KEY (64 hex digits) gives the seed itself; that's how the browser page passes the seed it keeps in localStorage (cvc.device_key).

  • Per relay: each device derives its own Ed25519 key for each relay, as HMAC-SHA256 of the seed and the relay URL. Two relays see unrelated public keys, just as they see unrelated device ids.

The proof

  • Challenge: a relay with a pin store puts a fresh 32-byte nonce in its Hello (Hello.nonce, field 4) to each connection it accepts.
  • Answer: the client replies with a DeviceProof (Frame field 12): its public key and a signature over the nonce, both node ids and its device id. Each field is length-prefixed.
    • One proof per challenge.
    • A proof that reaches the relay before the client's own Hello is held and checked when the Hello arrives. A client's reader can answer before its Hello is written.
  • Pinning: the relay verifies the proof 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).
    • A proof under another key, or with a bad signature, is refused and counted (total_device_proofs_refused).
    • A refused device stays in the room, without a tag.
  • Compatibility: old peers ignore the nonce field and the unknown frame type.

The room

  • Tags need a proof: participants.<pid>.device is now written only for a verified link that holds the pid. When the pid's holder has proved no key, its tag is cleared, so a takeover never keeps the last device's tag.
  • arisrv: keeps one pin store for both transports, in memory or in a file with --device-pins PATH (one <device id> <key> line each), so pins outlive a restart.
    • An unwritable pin file stops it with status 2.
    • It logs at startup whether keys are checked, and logs device keys: refused N proof(s).
  • arigl and the page: arigl loads the seed and signs for its relay. The page keeps the seed beside its device id, or for one page load where storage is blocked.

Review

An independent review found no way to get verified without the key. These findings are fixed here:

  • Stale tag after takeover (the most serious): a verified tag outlived its device when another link took over the pid after the holder fell silent.
  • Proof before Hello: a proof could arrive before the client's Hello and be refused, leaving the device unverified for the session. Now it's held, and a raw-frame test forces that order.
  • Ambiguous proof message: the fields were NUL-separated, but the nonce is binary. They're now length-prefixed.
  • Seed creation: races on both platforms, and roaming %APPDATA%.
  • Smaller:
    • the nonce had its own lock taken under write_mu; it now has a dedicated mutex;
    • a failed pin-file append is now logged;
    • a test temp directory could collide with a concurrent run.

Testing

  • New tests:
    • state_device_key_test: key derivation per relay; a proof verifies only as signed; the message separates its parts, a NUL in the nonce included; the seed comes from the environment or a kept file, with no temporary file left behind; pins keep the first key across a restart; a full store refuses new devices.
    • WS: DeviceProofsPinOnFirstUse and AProofBeforeTheHelloIsCheckedWhenItComes. The latter uses a raw client that sends the proof first, replays it, and signs for another device id.
    • gRPC: DeviceProofsPinOnFirstUse.
    • Loopback: RoomRelayLoopbackTest.OnlyAProvenDeviceGetsItsTag, on each transport. An impostor showing the same id under another key, cross-transport, is refused and gets no tag. A device with an id but no key gets none. The real device, as a fresh process, matches its pin.
    • RoomNet.LinkDevicesTagOnlyVerifiedHolders, including a takeover clearing a tag that was already set.
  • Changed test: RoomTokenAdmitsOnlyItsHolders gives its clients keys.
  • Mutation checks: each of these breaks the named tests:
    • tagging unverified links;
    • never clearing a tag;
    • accepting a mismatched key;
    • dropping the early-proof hold.
  • Windows, static WS tree: WS 38/38, gRPC 45/45, room relay 14/14, room intrinsics 9/9, identity 6/6, device keys 6/6. The one skip is the no-OpenSSL case.
  • Windows, shared build: 189/189 of the transport, room, holon, identity and device-key suites. cvc.dll has 65,485 exports, under the 65,535 limit. That's tight until this stack takes master's build(windows): cvc.dll stops exporting std:: symbols (63,073 -> 18,661 names) #793.
  • Formatting: clang-format 18.1.8 on the changed lines.
  • cyprty built for wasm on Windows from cvcpkg: the 22 wasm bundles from Room token and default device identity (§5f), before usernames #809 plus cvcpkg's openssl 3.4.1 wasm bundle. CMake logs device keys ENABLED (OpenSSL 3.4.1), and cyprty.wasm grows from 49.8 to 52.7 MB.
  • Browser smoke against a local arisrv with --device-pins:
    • A fresh page is pinned. The pin file gets one line, keyed by the relay-scoped id; the page's raw id never reaches the relay.
    • A reload with the same key matches its pin: still one line, nothing refused.
    • The same device id with a different cvc.device_key is refused (ws device of impostor_… was not pinned … unverified), and the pin is unchanged.

Known limits

  • The pin store can fill: every connection that proves a key adds a pin, joined or not, and a full store refuses every new device (fail closed).
    • A client holding the room token can fill it, and so can anyone in an open room. Ordinary use fills it slowly, since each private-window load is a new device.
    • The remedy today is the operator's: delete lines from the pin file, or run with pins in memory.
    • Expiring unused pins, or deriving the device id from the key so that no pin is needed, would remove the limit.
  • A lost seed locks out a native device: a native device that loses its seed keeps its id (it comes from the machine), so its new key is refused until the operator deletes its line from the pin file. Running it once with another CVC_DEVICE_KEY has the same effect.
  • No channel binding: over plain ws:// or insecure gRPC an active man-in-the-middle can relay the challenge. Deploy behind wss://, as for the token.
  • Deployment: the browser build needs the openssl wasm bundle in its prefix. Without it, the page runs as before and simply has no tag.

…t 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.
@transfix
transfix merged commit 0fd9144 into feat/h1-room-token Oct 25, 2026
7 checks passed
transfix added a commit that referenced this pull request Oct 25, 2026
* Bound writes: a relay client writes only its own participant, as itself

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.

* Room token and default device identity (§5f), before usernames

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.

* ws: declare steady_ns before the accept loop uses it

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).

* Device keys: a device proves its id with a key the relay pins on first 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.

* Conference: a volume slider that holds still, a mover's avatar that doesn'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 added a commit that referenced this pull request Oct 25, 2026
)

* Bound writes: a relay client writes only its own participant, as itself

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.

* Room token and default device identity (§5f), before usernames

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.

* ws: declare steady_ns before the accept loop uses it

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).

* 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.

* Device keys: a device proves its id with a key the relay pins on first 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.

* 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.

* Per-viewer video rungs: the relay re-encodes each camera for each viewer's link

The user asked for per-viewer control of resolution and bitrate, adapted when a viewer's link
degrades, and asked whether senders must send several sizes. They need not: MJPEG frames stand
alone, so the relay makes the smaller sizes itself.

Rungs (cvc::media_rung_shaper, media_rungs.h):
- full (as sent), half and quarter (decoded at 1/2 or 1/4 size by libjpeg-turbo's DCT scaling and
  re-encoded), thumb (quarter at 2 fps) and off (no video; audio still flows).
- A variant is made once per frame and rung and shared by every viewer on it, across transports.
  Publishers upload one stream; old clients need no change.
- media_endpoint gains set_media_shaper, asked per receiver after the gate (the frame as sent, a
  variant, or nothing); the WS and gRPC fans encode each variant once per frame.
- cvc links libjpeg-turbo when the prefix has it (CVC_HAVE_TURBOJPEG); without it the smaller
  rungs send frames as is.

Adaptation (room_rung_controller, room_rungs.h), once a second over the link reports:
- per viewer, queueing (round trip above its minimum), the share of media frames dropped for it
  (new per-link media_sent / media_dropped counters) and what it was sent;
- down one rung after two bad seconds (queueing > 150 ms, > 5% dropped, or over budget), up one
  after ten good ones; a step up that fails early doubles the next wait (to 60 s).
- arisrv: --adapt on|off, --video-max RUNG, --video-floor RUNG, --viewer-kbps-max N; it logs each
  change and writes the rung to participants.<pid>.net.relay.video (relay-owned).

Camera off is a flag, not frames: a client whose camera is off sends no frames and publishes
participants.<pid>.video.off; viewers show "camera off" instead of the last frame they got.

The roster shows each person's rung as a dot before their name (green full, red reduced, black
none; hover for which) and "video in: ..." in My Camera. The dot is a new status_dot widget drawn
with ImGui's draw list, as the web build's font has no circle glyph.

Tests: MediaRungs.* (downscale sizes, shared variants, thumb pacing, audio untouched), RoomRungs.*
(down on queueing and drops, slow and wary up, the server's bounds), the WS shaper per receiver,
and RoomRelayLoopbackTest.AViewersVideoRungShapesWhatItGets on each transport.

* build(windows): cvc.dll stops exporting std:: symbols (63,073 -> 18,661 names) (#793)

cvc.dll's export table came from WINDOWS_EXPORT_ALL_SYMBOLS, which exports every external
symbol in cvc's objects, and a PE export table holds at most 65,535 names. The gRPC build
of master exported 63,073 and S7 (#789) 65,122; that limit is why the WebSocket transport
stays off on Windows. 44,412 of master's names were in namespace std: the members of
std::vector<cvc::...>, std::_Tree<...> and std::function's _Func_impl for cvc's lambdas,
the STL's inline functions, std RTTI. No consumer imports them. Each is an implicit
instantiation or an inline function that the consumer compiles from the same header, and
the linker resolves it from the consumer's own objects: of the 2,194 names S7's 286
binaries import from cvc.dll, none is in std.

Under MSVC, cvc_msvc_export_def (CMake/CvcMsvcExportDef.cmake) now builds the table as a
pre-link step. `cmake -E __create_def` over $<TARGET_OBJECTS:cvc> writes the same file
WINDOWS_EXPORT_ALL_SYMBOLS did, byte for byte. cvc_def_filter, a small host tool on
dbghelp's UnDecorateSymbolName, then leaves out every symbol whose undecorated name is in
namespace std, and cvc.dll links with /DEF: on the result. cvc_igl and cvc_physics_jolt
are still private static archives that are not scanned. Cross-compiles, CMake older than
3.18 and MinGW keep WINDOWS_EXPORT_ALL_SYMBOLS.

The gRPC RelWithDebInfo build of master now exports 18,661 names, and cvc.dll shrinks from
56.7 MB to 42.0 MB. S7's export list through the same filter is 18,946, and a CVC_ENABLE_WS=ON +
libigl build, which could not link before (66,726 names), exports 21,861. The cvc_igl_packaging
test also checks that the generated table names no igl:: or Eigen:: symbol.

(cherry picked from commit 1d0c87f)

* Video rungs: review fixes (bad JPEGs, variant cache, thumb pacing)

- jpeg_downscale refuses a JPEG over 4096 x 4096 before allocating for it:
  a frame's header names its own size, and one claiming 65535 x 65535 from
  any client would have the relay allocate gigabytes on a reader thread.
- A TurboJPEG handle a call failed on is replaced. A decompressor stopped
  partway through a bad header refuses every image after it ("two SOI
  markers"), so one malformed frame ended downscaling on that reader thread
  for good. The thread-local handles are now also destroyed at thread exit.
- write_media holds each variant's shared_ptr for the whole fan (WS and
  gRPC). Matched by address, a variant freed mid-fan could hand its address
  to another and a later receiver would get the wrong encoding.
- An unidentified receiver is shaped too, as "" (no rung: full).
- The thumb rung admits a frame a quarter of its interval early: the AOI
  tier may already pace that camera at the same 2 fps on its own schedule,
  and those frames arrive with a frame period of jitter, so a strict gap
  halved them.
- arisrv's room-debug report adds the shaper's totals.

Tests: the downscale test sends an oversized header and then a good frame
(which failed before the handle fix); the thumb test covers the early
frame; OnlyAViewersHoldingLinkCounts now checks a returning viewer starts
over at the best rung (it checked nothing); the WS shaper test claims only
what it checks, and asserts a shaped-out frame is not a link drop (the
controller would read its own off rung as congestion).

* Opus mics: 32 kbit/s instead of 1.5 Mbit/s

A mic sent as raw f32 at 48 kHz is 1.5 Mbit/s, the largest stream after
video. cvc::opus_encoder / opus_decoder (media_opus.h, over libopus) carry it
as Opus at 32 kbit/s: the sender re-chunks the mic's 1024-frame chunks into
20 ms (960-frame) packets, one media_frame each (codec "opus", a seq per
packet so a gap is a lost packet), and a new talk spurt resets the encoder.

A receiver decodes each peer with its own decoder (Opus is stateful),
conceals up to two lost packets, and cuts the result into mixer-sized
chunks: the mixer sums one chunk per peer, and a 960-frame packet in a
1024-frame mix would drift and click. A gap of over 0.4 s ends a peer's
talk spurt; a shorter delivery hitch keeps its samples.

The relay forwards a mic as sent, whatever its codec, and needs no libopus.
A client without libopus sends f32, which every client plays; it cannot
decode a peer's Opus, logs that once, and hears that peer as silence.
Older clients are not provided for.

libopus is optional. cvcpkg's autotools-built bundles ship no CMake config,
so it is found by header and library and linked through a synthesised
CvcOpus::opus, which cvcConfig.cmake recreates for a static consumer (as
PkgConfig::ZSTD). Under MSVC the search takes only the import library
(opus.lib, from cy-pca/cvcpkg#467, or libopus.dll.a): CMake would otherwise
take MinGW's libopus.a for `opus`, and its ___chkstk_ms calls do not link.
The libcvc recipe gains libopus on linux, macos and windows; wasm follows
once #467 publishes its bundle.

* conference_roster: ASCII status text (the browser's font draws a bullet or an em dash as ?)

The browser build's ImGui font is ASCII-only, so My Camera read "camera: ? on"
and a taken name "... is taken ? pick another". Plain "on" and a semicolon.

* recipe(libcvc): libopus for wasm too (cvcpkg libopus cvc.8)

cy-pca/cvcpkg#467 published a static wasm libopus, so the single-threaded
wasm libcvc gets Opus mics like the native ones. wasm-mt has no libopus
bundle, and Emscripten will not link a non-pthread archive into a -pthread
build, so it goes without (its mics stay f32).

* arigl: clang-format the video_off_ member comment

The Opus members inserted above it ended the aligned comment block, so
master's changed-lines check wants the single space back.
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-device-keys 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