Calls: four MLS kinds and the call key in the client; coturn in the NixOS module; v0.3.0 #28

Closed
mnovak wants to merge 0 commits from feature/call-kinds into main
Owner

Calls, the client's part (Amicitia F36; .agents/features/call-kinds.md), and coturn for the relay's host.

  • Four MLS kinds (docs/PROTOCOL.md §4): call {id, video, sdp, key, at}, callAnswer {id, sdp}, callIce {id, candidates}, callEnd {id, seq, reason, seconds}. Only callEnd has a seq, so an older client shows it as update the app and drops the rest.
  • Client API: offer_call, answer_call, call_candidates, end_call; events CallOffered, CallAnswered, CallCandidates, CallEnded; ClientError::BadCall. Live calls are kept in memory only, at most 8.
  • The frame key travels in the MLS-sealed offer instead of coming from the MLS exporter as F36 first said; see the review, finding 1.
  • Protocol crate: CallId and CallKey. CallKey's Debug prints nothing.
  • NixOS module: turn.coturn.{enable, realm, minPort, maxPort, externalIp, allowedPeerIps} runs coturn with the relay's secret (a systemd credential, never in the store). It has no log, TLS and DTLS off, and private and reserved peers denied, and it opens 3478 and 49152–49999. Caddy's global logFormat is now lib.mkDefault, so .217's "level ERROR" no longer needs mkForce.
  • VM test: coturn relays packets to a peer with a pair from the relay, refuses a wrong password, and leaves the client's address nowhere on the server.
  • Version 0.3.0. A separate commit runs rustfmt over v0.2.0's relay code (no change in behaviour).

Nix checks on the hub: run r1grtnrqrb580. The self-review is posted below.

Calls, the client's part (Amicitia F36; `.agents/features/call-kinds.md`), and coturn for the relay's host. - **Four MLS kinds** (`docs/PROTOCOL.md` §4): `call` {id, video, sdp, key, at}, `callAnswer` {id, sdp}, `callIce` {id, candidates}, `callEnd` {id, seq, reason, seconds}. Only `callEnd` has a `seq`, so an older client shows it as *update the app* and drops the rest. - **Client API:** `offer_call`, `answer_call`, `call_candidates`, `end_call`; events `CallOffered`, `CallAnswered`, `CallCandidates`, `CallEnded`; `ClientError::BadCall`. Live calls are kept in memory only, at most 8. - **The frame key travels in the MLS-sealed offer** instead of coming from the MLS exporter as F36 first said; see the review, finding 1. - **Protocol crate:** `CallId` and `CallKey`. `CallKey`'s `Debug` prints nothing. - **NixOS module:** `turn.coturn.{enable, realm, minPort, maxPort, externalIp, allowedPeerIps}` runs coturn with the relay's secret (a systemd credential, never in the store). It has no log, TLS and DTLS off, and private and reserved peers denied, and it opens 3478 and 49152–49999. Caddy's global `logFormat` is now `lib.mkDefault`, so .217's `"level ERROR"` no longer needs `mkForce`. - **VM test:** coturn relays packets to a peer with a pair from the relay, refuses a wrong password, and leaves the client's address nowhere on the server. - Version 0.3.0. A separate commit runs rustfmt over v0.2.0's relay code (no change in behaviour). Nix checks on the hub: run r1grtnrqrb580. The self-review is posted below.
mnovak added 5 commits 2026-12-03 10:05:36 +01:00
mnovak reviewed 2026-12-03 10:05:37 +01:00
mnovak left a comment
Author
Owner

Self-review (CLAUDE.md §3, adversarial).

Evidence

  • cargo test --workspace: client 87 (76 before: 8 in tests/calls.rs, 3 unit), protocol 21 (+1), relay 57 (unchanged). cargo clippy --workspace --all-targets -D warnings is clean, and cargo fmt too.
  • Planted bugs, 4/4 caught:
    1. An answer to an offer that isn't ours is accepted: the unit test a_second_offer_under_a_live_id_… fails.
    2. A second offer under a live id rings again: the same test fails.
    3. A blocked contact's call rings: a_blocked_contacts_call_does_not_ring fails.
    4. Candidates for any id are accepted: malformed_call_kinds_are_dropped_… fails.
  • real_relay.rs: the call's SDP, a candidate's address, the id and the key are in no byte of the real relay's database.
  • Nix (hub, run r1grtnrqrb580): the package and relay-keeps-no-address with coturn, both exit 0. coturn relayed uclient's packets to a peer with a pair from the relay, and refused a wrong password. The client's address is in no journal line and no file under /var/log, /run/coturn, /run/turnserver or /tmp.
  • Two earlier VM runs failed on my test, not on coturn:
    • r2e1ecss547wn: the test read uclient's first progress count, 0, before the final total.
    • r1w7p2ns3v8a9: uclient words a refused password as Cannot complete Allocation, not error 401.
      The test now reads the last count and takes either wording, and it prints uclient's output into a failing assertion, because Nix keeps only 25 lines.

Findings

  1. Design change: the frame key is 32 random bytes in the call offer, not export_secret("amicitia call v1", id). Both are equally secret, since only the two members open MLS messages, and both are post-quantum exactly when MLS is. The exporter, though, gives different keys whenever one side has processed a commit the other hasn't. Today there is one epoch, but a key update, the move to X-Wing or a second device would make frames silently fail to open. The F36 doc in Amicitia must say so (I'll update it there).
  2. The app's job, not done here:
    • An Outgoing kept in Amicitia's outbox and delivered again after a crash can deliver a stale call late, so the callee's app must ring only when at is recent.
    • at is the caller's clock, unchecked by the client.
  3. Live calls are in memory. Amicitia keeps the client loaded between commands and unloads it only after a failed save, an erase or a new identity. Any of those mid-call makes the call fail; the app then ends it as failed.
  4. Event's Debug shows the SDP and candidates, as it shows a text's words. An app must not log events. Not changed here.
  5. Not verified by the VM test:
    • that a denied peer is refused. The test allows its own private range, and the IPv6 ranges' syntax is unexercised.
    • NAT (externalIp) on .217.
    • a real WebRTC call through coturn. That comes with Amicitia's calls.
  6. Scope: the rustfmt commit touches v0.2.0's relay files: line breaks and trailing commas only, checked by comparing them with whitespace removed.

Privacy: nothing new reaches the relay (four more kinds of sealed blob). coturn sees both devices' addresses during a call, keeps no log, and the VM test greps the journal, /var/log, /run/coturn, /run/turnserver and /tmp for the client's address.

Self-review (CLAUDE.md §3, adversarial). **Evidence** - `cargo test --workspace`: client **87** (76 before: 8 in `tests/calls.rs`, 3 unit), protocol **21** (+1), relay **57** (unchanged). `cargo clippy --workspace --all-targets -D warnings` is clean, and `cargo fmt` too. - **Planted bugs, 4/4 caught:** 1. An answer to an offer that isn't ours is accepted: the unit test `a_second_offer_under_a_live_id_…` fails. 2. A second offer under a live id rings again: the same test fails. 3. A blocked contact's call rings: `a_blocked_contacts_call_does_not_ring` fails. 4. Candidates for any id are accepted: `malformed_call_kinds_are_dropped_…` fails. - `real_relay.rs`: the call's SDP, a candidate's address, the id and the key are in no byte of the real relay's database. - Nix (hub, run r1grtnrqrb580): the package and `relay-keeps-no-address` with coturn, both exit 0. coturn relayed uclient's packets to a peer with a pair from the relay, and refused a wrong password. The client's address is in no journal line and no file under /var/log, /run/coturn, /run/turnserver or /tmp. - Two earlier VM runs failed on my test, not on coturn: - r2e1ecss547wn: the test read uclient's first progress count, 0, before the final total. - r1w7p2ns3v8a9: uclient words a refused password as `Cannot complete Allocation`, not `error 401`. The test now reads the last count and takes either wording, and it prints uclient's output into a failing assertion, because Nix keeps only 25 lines. **Findings** 1. **Design change:** the frame key is 32 random bytes in the `call` offer, not `export_secret("amicitia call v1", id)`. Both are equally secret, since only the two members open MLS messages, and both are post-quantum exactly when MLS is. The exporter, though, gives different keys whenever one side has processed a commit the other hasn't. Today there is one epoch, but a key update, the move to X-Wing or a second device would make frames silently fail to open. The F36 doc in Amicitia must say so (I'll update it there). 2. **The app's job, not done here:** - An `Outgoing` kept in Amicitia's outbox and delivered again after a crash can deliver a stale `call` late, so the callee's app must ring only when `at` is recent. - `at` is the caller's clock, unchecked by the client. 3. **Live calls are in memory.** Amicitia keeps the client loaded between commands and unloads it only after a failed save, an erase or a new identity. Any of those mid-call makes the call fail; the app then ends it as `failed`. 4. **`Event`'s `Debug` shows the SDP and candidates**, as it shows a text's words. An app must not log events. Not changed here. 5. **Not verified by the VM test:** - that a *denied* peer is refused. The test allows its own private range, and the IPv6 ranges' syntax is unexercised. - NAT (`externalIp`) on .217. - a real WebRTC call through coturn. That comes with Amicitia's calls. 6. **Scope:** the rustfmt commit touches v0.2.0's relay files: line breaks and trailing commas only, checked by comparing them with whitespace removed. **Privacy:** nothing new reaches the relay (four more kinds of sealed blob). coturn sees both devices' addresses during a call, keeps no log, and the VM test greps the journal, /var/log, /run/coturn, /run/turnserver and /tmp for the client's address.
@@ -204,0 +227,4 @@
video: bool,
sdp: String,
key: CallKey,
at: i64,
Author
Owner

Finding 2: the caller's clock, unchecked. The app rings only when it is recent; a stale offer redelivered from an outbox must show as missed.

Finding 2: the caller's clock, unchecked. The app rings only when it is recent; a stale offer redelivered from an outbox must show as missed.
@@ -428,2 +528,4 @@
/// Send receipts and report the other side's (reciprocal). On by default.
receipts: bool,
/// Calls in progress: in memory only, never in a snapshot.
calls: Vec<LiveCall>,
Author
Owner

Finding 3: in memory only. An unload in Amicitia (a failed save, an erase, a new identity) mid-call drops it.

Finding 3: in memory only. An unload in Amicitia (a failed save, an erase, a new identity) mid-call drops it.
@@ -683,0 +818,4 @@
}
let index = self.index_of(contact)?;
let id = CallId::from_bytes(self.random()?);
let key = CallKey::from_bytes(self.random()?);
Author
Owner

Finding 1: the key is made here and sent inside the MLS-sealed offer, not derived from the exporter, so a commit on one side only can't make the two keys differ.

Finding 1: the key is made here and sent inside the MLS-sealed offer, not derived from the exporter, so a commit on one side only can't make the two keys differ.
@@ -18,0 +19,4 @@
# coturn with the same secret. The test network is private, so the client's range is let through here;
# every other private range stays denied.
turn.coturn.enable = true;
turn.coturn.allowedPeerIps = [ "192.168.1.0-192.168.1.255" ];
Author
Owner

Finding 5: the test allows its own range, so the denied list itself is not exercised here.

Finding 5: the test allows its own range, so the denied list itself is not exercised here.
Author
Owner

Merged into main as 2215e8d (--no-ff; the remote hash was checked) and tagged v0.3.0. Its tree is the one Nix run r1grtnrqrb580 tested (1b15845).

Merged into main as 2215e8d (`--no-ff`; the remote hash was checked) and tagged **v0.3.0**. Its tree is the one Nix run r1grtnrqrb580 tested (1b15845).
mnovak closed this pull request 2026-12-03 10:05:51 +01:00
Some checks are pending
ci / check (pull_request) Failing after 52s

Pull request closed

Sign in to join this conversation.