From b53b9e0be11c491da8a3698984eecb9e7fe70218 Mon Sep 17 00:00:00 2001 From: mnovak Date: Wed, 25 Nov 2026 11:26:30 +0100 Subject: [PATCH 01/55] [repo] Clean room: allowed and forbidden sources, GPL-provenance rule, source log --- docs/CLEAN_ROOM.md | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 docs/CLEAN_ROOM.md diff --git a/docs/CLEAN_ROOM.md b/docs/CLEAN_ROOM.md new file mode 100644 index 0000000..93ef6f3 --- /dev/null +++ b/docs/CLEAN_ROOM.md @@ -0,0 +1,73 @@ +# Clean room + +DomiStream is a clean-room implementation of the GameStream protocol (the one Moonlight clients and Sunshine hosts +speak). The protocol is written from public protocol notes and our own measurements, never from the code of a +GPL-licensed implementation. This file says what may be read, what may not, and logs every source used. + +## Allowed sources + +| Source | Licence | How we may use it | +| :-- | :-- | :-- | +| [Wolf protocol docs](https://games-on-whales.github.io/wolf/stable/protocols/index.html) and their sub-pages (pairing/HTTP, RTSP, control, RTP video, RTP Opus, input) | Docs site: CC BY-SA 4.0 "except where otherwise noted"; repo: MIT (see [research/open-point-2.md](research/open-point-2.md)) | Read for facts. Restate facts in our own words with a link. Never paste prose or diagrams. The diagram sources (PlantUML, bytefield, wavedrom) are part of the docs pages and may be read the same way. | +| [Moonshine](https://github.com/hgaiser/moonshine) | BSD-2-Clause | May be read. Facts taken are logged below. Code is not copied; if a snippet is ever borrowed, it keeps Moonshine's copyright line and licence text in the file that holds it. | +| RFCs and standards (RTP RFC 3550, RTSP RFC 2326, SDP RFC 4566, Opus RFC 6716 / RFC 7845, AES FIPS 197, GCM/CBC NIST SP 800-38D/38A, PKCS #1 RFC 8017, X.509 RFC 5280) | open standards | Read freely. | +| Crate docs (docs.rs, crates.io, crate READMEs) | per crate | Read freely. | +| Our own measurements | ours | Captures between our client and a host on a **lab machine** (never Mark's PC, never Mark's TV, never 192.168.100.217). Captures stay out of git; only the facts and test vectors derived from them go in, with the date and setup. | +| READMEs and wikis of forbidden projects | n/a | For facts only (licence, release notes, compatibility statements). Never their source files. | + +### Proposed additions (need the build lead's yes before use) + +| Source | Licence | Why | +| :-- | :-- | :-- | +| [Stock ENet](https://github.com/lsalzman/enet) (`protocol.h`, `protocol.c`) | MIT | The ENet 1.3 wire format is not documented anywhere else in prose. The Wolf docs do not describe it. | +| [tokio-enet](https://github.com/hgaiser/tokio-enet) source | BSD-2-Clause | A pure-Rust ENet 1.3 used by Moonshine to talk to Moonlight clients. Its `src/protocol/` files were read for the command list (logged below, S-10). | +| [fec-rs](https://github.com/hgaiser/fec-rs) source | BSD-2-Clause | Its README says its field setup is compatible with Moonlight. Reading its matrix construction would settle UNKNOWN U14 (video FEC). | + +## Forbidden + +Never open, read, paste or port code from: **Sunshine, Moonlight (any client: Qt, Android, iOS, embedded, moonlight-tv), +moonlight-common-c, Moonlight's ENet fork, Apollo, Vibeshine, Rubylight, chiaki** (and forks of them). That also +means their source files on GitHub. Their READMEs and wikis are fine for facts. + +### Second-hand GPL facts + +Moonshine credits Sunshine for "groundwork" on the host side, and a few Moonshine comments cite Sunshine or +moonlight-common-c as the origin of a value. We treat such a value as **GPL-provenance**: it is logged, never +copied into DomiStream, and settled by our own measurement instead. Known cases: + +| Where in Moonshine | What | What we do | +| :-- | :-- | :-- | +| `src/session/stream/audio/encoder.rs` | the fixed 2x4 Reed-Solomon parity matrix for audio FEC; the comment cites a moonlight-common-c file | Not taken. I saw the constant while reading the file; it is not in this repo. U16 in [PROTOCOL.md](PROTOCOL.md) says how to measure it ourselves. | +| `src/session/stream/control/mod.rs` | HDR mode payload "matches Sunshine's" struct | Field layout logged as `[M*]`, confirm by measurement before relying on it | +| `src/rtsp.rs` | `surround-params` digit packing "matching moonlight-common-c" | The Wolf example `surround-params=21101` gives the same packing independently, so we use the Wolf source | + +## How code gets written + +1. Every fact in [PROTOCOL.md](PROTOCOL.md) carries a source tag that points to the log below. +2. A fact without a tag is UNKNOWN until a log entry or a measurement backs it. +3. Code comments cite the PROTOCOL.md section, not the outside source directly. +4. Anything borrowed (more than a fact) is attributed in the file that holds it and listed here. +5. A PR that adds a source adds a row to the log in the same PR. + +## Source log + +All entries by the DomiStream protocol engineer. Pinned commits are the ones read. + +| # | Date | Source | What was taken | +| :-- | :-- | :-- | :-- | +| S-1 | 2026-11-25 | [Wolf: protocols index](https://games-on-whales.github.io/wolf/stable/protocols/index.html) | The six protocols, their default ports, which are encrypted (control AES-GCM 128, audio AES-CBC 128, video plain), that ports other than HTTP/S are dynamic. Licence footer (CC BY-SA 4.0). | +| S-2 | 2026-11-25 | [Wolf: HTTP/S pairing](https://games-on-whales.github.io/wolf/stable/protocols/http-pairing.html) incl. its PlantUML diagram sources | Phases 1-5; AES key from SHA-256(salt + PIN); the hash inputs of phase 2 and phase 4; field names `plaincert`, `challengeresponse`, `serverchallengeresp`, `pairingsecret`, `pairchallenge`, `paired`; phase 5 runs over HTTPS with the client certificate. | +| S-3 | 2026-11-25 | [Wolf: RTSP](https://games-on-whales.github.io/wolf/stable/protocols/rtsp.html) incl. diagram | Method order OPTIONS, DESCRIBE, SETUP (audio, video, control), ANNOUNCE, PLAY; message layout (start line, `CSeq`, options, empty line, payload); example `X-GS-ClientVersion: 14`, `a=fmtp:97 surround-params=21101`. | +| S-4 | 2026-11-25 | [Wolf: control](https://games-on-whales.github.io/wolf/stable/protocols/control-specs.html) incl. bytefield sources | ENet fork with IPv4 + IPv6; encrypted frame `type 0x0001 / len / seq / 16-byte tag / payload`, little-endian, seq used for the IV; message type codes; payloads of rumble, rumble triggers, motion event, RGB LED. | +| S-5 | 2026-11-25 | [Wolf: RTP video](https://games-on-whales.github.io/wolf/stable/protocols/rtp-video.html) incl. diagrams | PING to the negotiated port; packetSize default 1024 + 16-byte RTP header; 16-byte NV video header layout; flags (picture data 1, EOF 2, SOF 4); 8-byte frame prefix `01 37 63 68 61 72 73 73`; FEC example (4 KB, 1024, 50 % = 4 + 2); parity packets have flags 0; IDR requests over control. | +| S-6 | 2026-11-25 | [Wolf: RTP Opus](https://games-on-whales.github.io/wolf/stable/protocols/rtp-opus.html) incl. diagrams | 12-byte RTP header; 12-byte FEC header (shard index, payload type, base seq, base timestamp, SSRC); 4 data + 2 parity; AES-CBC with key and IV from the launch call, same key as control; PING. | +| S-7 | 2026-11-25 | [Wolf: input](https://games-on-whales.github.io/wolf/stable/protocols/input-data.html) incl. bytefield sources | INPUT_DATA layout (size BE, type LE); input type codes; layouts and example bytes for mouse move rel/abs, buttons, keys, scroll, hscroll, controller arrival, controller multi; key code table; button flags; controller types and capability bits. | +| S-8 | 2026-11-25 | GitHub API for [games-on-whales/wolf](https://github.com/games-on-whales/wolf) (`/repos`, `/git/trees/beta`, `LICENSE`, `docs/README.adoc`) | Repo licence MIT; the docs live in `docs/modules/protocols/pages/*.adoc` of the same repo; latest tag `v2026.11`. No source files of Wolf were read. | +| S-9 | 2026-11-25 | [Moonshine](https://github.com/hgaiser/moonshine) at `f184d5e3693e09c3a6ab1025bde6cdb67f36a6bc`: `LICENSE`, `README.md`, `Cargo.toml`, `src/clients.rs`, `src/crypto.rs`, `src/webserver/pairing.rs`, `src/webserver/mod.rs`, `src/rtsp.rs`, `src/session/stream/control/mod.rs`, `src/session/stream/audio/{mod,encoder}.rs`, `src/session/stream/video/{mod,packetizer,shard_batch}.rs` | Facts tagged `[M]` in PROTOCOL.md: pairing query names, AES-128-ECB, key = first 16 bytes of SHA-256(salt + PIN), 16-byte salt/challenge/secret, RSA PKCS#1 v1.5 SHA-256, "certificate signature" = X.509 signatureValue bytes; serverinfo, applist and launch XML and query fields; SDP attribute names, SETUP reply headers, encryption flag bits; control IV layout and direction bytes, START_B starts the streams, INVALIDATE_REF_FRAMES and termination layouts, ENet host settings; audio IV, payload types 97/127, millisecond timestamps; video RTP/NV header byte layout, FEC bit fields and block split, video encryption prefix and IV; `PING` payload. Moonshine depends on `tokio-enet` for the control channel. | +| S-10 | 2026-11-25 | [tokio-enet](https://github.com/hgaiser/tokio-enet) at `364628ed754760c99e0df7bcc88e479ad91475c4`: `README.md`, `CHANGELOG.md`, `src/protocol/{mod,header,commands}.rs` | Claims wire compatibility with C ENet 1.3.x, BSD-2; ENet command numbers 1-12, command sizes, header flags (compressed 1<<14, sent time 1<<15, session bits 12-13), 4-byte command header, big-endian fields. Pending approval as an allowed source (see above). | +| S-11 | 2026-11-25 | crates.io API for `enet`, `enet-rs`, `nsys-enet`, `rusty_enet`, `tokio-enet`, `enet-sys`, `henet`, `enet-cs-sys`, `fec-rs`, `reed-solomon-erasure` and the RustCrypto crates | Licences, versions, repositories (see research/open-point-2.md and the Cargo manifest). | +| S-12 | 2026-11-25 | [docs.rs: rusty_enet](https://docs.rs/rusty_enet/latest/rusty_enet/) | Transpiled from C ENet; caller-supplied `Socket` trait and `HostSettings::time`; optional crc32 checksum; MIT. | +| S-13 | 2026-11-25 | [fec-rs README](https://github.com/hgaiser/fec-rs) | GF(2^8) with polynomial 0x1D (0x11D), "compatible with the Moonlight streaming protocol", reconstruction supported, BSD-2. | +| S-14 | 2026-11-25 | [moonlight-common-c README](https://github.com/moonlight-stream/moonlight-common-c) (README only) | Needs its bundled ENet; other ENet versions are incompatible; GPL-3.0. | +| S-15 | 2026-11-25 | [cgutman/enet](https://github.com/cgutman/enet) repository page (description only) | Forked from lsalzman/enet, has a `moonlight` branch. No files opened. | +| S-16 | 2026-11-25 | Roadmap brief §3.2 ([moonlight-android releases](https://github.com/moonlight-stream/moonlight-android/releases)) | Moonlight Android 12.1 added end-to-end stream encryption with Sunshine. | From 5148abfcc3d39e1267b908207480f726087a3cf8 Mon Sep 17 00:00:00 2001 From: mnovak Date: Wed, 25 Nov 2026 11:26:31 +0100 Subject: [PATCH 02/55] [repo] Open point 2: Wolf docs licence, Rust ENet crates, own sans-I/O ENet recommended --- docs/research/open-point-2.md | 96 +++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 docs/research/open-point-2.md diff --git a/docs/research/open-point-2.md b/docs/research/open-point-2.md new file mode 100644 index 0000000..a1b7732 --- /dev/null +++ b/docs/research/open-point-2.md @@ -0,0 +1,96 @@ +# Open point 2: Wolf docs licence, Rust ENet crates, and a clean ENet + +Roadmap open point 2 asks three things before Day 1 code: the licence of the Wolf protocol docs, the licences of the +Rust ENet crates, and whether Moonlight's ENet changes can be met by a clean Rust implementation. +Checked 2026-11-25. Source numbers (S-n) refer to the log in [../CLEAN_ROOM.md](../CLEAN_ROOM.md). + +## 1. Wolf: docs and repo + +| What | Licence | Evidence | +| :-- | :-- | :-- | +| Docs site `games-on-whales.github.io/wolf` | **CC BY-SA 4.0**, "except where otherwise noted" | Footer of every page: "Copyright © ABeltramo and GOW contributors. Except where otherwise noted, docs are licensed under the Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)." ([index](https://games-on-whales.github.io/wolf/stable/protocols/index.html), S-1) | +| Repo `games-on-whales/wolf` | **MIT** | [`LICENSE`](https://github.com/games-on-whales/wolf/blob/beta/LICENSE), GitHub API reports `MIT` (S-8). The docs sources live in the same repo (`docs/modules/protocols/pages/*.adoc`). | + +The two statements overlap: the `.adoc` files sit in an MIT repo, and the rendered site says CC BY-SA 4.0. We take the +stricter one (CC BY-SA 4.0) for the docs. + +What that means for DomiStream (judgment, not legal advice): +- **Facts are free.** Port numbers, field layouts, message codes and algorithms are facts and methods. We can + implement them under CPAL-1.0. +- **Prose and diagrams are not ours to copy.** CC BY-SA content pasted into our docs would make that part + share-alike, and CC BY-SA 4.0 is not compatible with CPAL-1.0. So PROTOCOL.md restates the facts in our own words + and links each section to its Wolf page (attribution is good practice anyway). +- **Example bytes** (the input packet examples) are short functional data needed to interoperate. QA may rebuild + them from the documented field layout instead of copying the example lines; both give the same bytes. + +## 2. Rust ENet crates + +| Crate | Version (date) | Licence | What it is | Fits DomiStream? | +| :-- | :-- | :-- | :-- | :-- | +| [`rusty_enet`](https://github.com/jabuwu/rusty_enet) | 0.4.1 (2026-11-01) | MIT | Stock C ENet transpiled to Rust; caller supplies the `Socket` and a time function (`HostSettings::time`); optional crc32 checksum ([docs.rs](https://docs.rs/rusty_enet/latest/rusty_enet/), S-12) | Licence fits. Socket and time are pluggable, so it can run in memory. But it is transpiled C (pointer-heavy, `unsafe` inside), stock ENet only, and its API is the C host/peer model rather than bytes in/events out. Good as a **test oracle**, weak as the parser of hostile input. | +| [`tokio-enet`](https://github.com/hgaiser/tokio-enet) | 0.1.1 (2026-06-14) | BSD-2-Clause | Pure-Rust ENet, "wire-compatible with the C ENet v1.3.x protocol" ([README](https://github.com/hgaiser/tokio-enet), S-10). **Moonshine uses it for its control stream with Moonlight clients** (S-9). | Licence fits. Bound to tokio sockets and the clock, so not sans-I/O; cannot run on webOS without tokio. Its existence is the strongest evidence for the compatibility question below. | +| [`enet`](https://github.com/futile/enet-rs) | 0.3.0 (2022-03-30) | MIT OR Apache-2.0 | Bindings to the C library through `enet-sys` | Not pure Rust, not sans-I/O, stock ENet. No. | +| [`enet-sys`](https://github.com/ruabmbua/enet-sys) | 1.0.5 (2026-03-16) | MIT | Raw FFI to C ENet | No (C, FFI, stock). | +| [`enet-rs`](https://github.com/ZTzTopia/enet-rs) | 1.3.171 (2021-08-29) | ISC | Bindings for C ENet 1.3.17 | No (C, unmaintained). | +| [`nsys-enet`](https://github.com/spearman/enet-rs) | 0.2.2 (2026-07-07) | Apache-2.0 | Rust interface to C ENet | No (C). | +| [`enet-cs-sys`](https://github.com/Kalkatral/enet-cs-sys) | 0.1.1 (2023-02-25) | MIT | Bindings to ENet-CSharp, a different, incompatible ENet fork | No. | +| [`henet`](https://github.com/dehorsed/henet) | 0.1.0 (published 2026-11-25) | MIT OR Apache-2.0 | "Idiomatic Rust implementation of ENet" | Too new to judge; first release today. | + +All licences above (MIT, Apache-2.0, BSD-2-Clause, ISC) are permissive and fit a CPAL-1.0 project as dependencies. +None of these crates is GPL. None is a port of Moonlight's ENet fork. + +## 3. Can Moonlight's ENet semantics be met by a clean Rust implementation? + +What is documented: +- Wolf: the control stream "runs over UDP via a custom fork of ENET that supports IPV4 and IPV6" and every message + inside is AES-GCM framed ([control](https://games-on-whales.github.io/wolf/stable/protocols/control-specs.html), S-4). + Wolf documents nothing else about the fork: no wire change, no extra command. +- moonlight-common-c README: the client "requires the specific version of ENet that is bundled" and other versions + are "incompatible", with a crash warning against recent GeForce Experience (S-14). It does not say which bytes differ. +- IPv6 support is a socket-address change in the C library. It does not appear on the ENet wire: ENet datagrams + carry no addresses. + +What is measured by others: +- Moonshine (BSD-2) serves real Moonlight clients with `tokio-enet`, a stock ENet 1.3 wire implementation + (S-9, S-10): one peer, `channel_limit 0x30`, every host message sent reliable on channel 0. So **whatever the fork + changes, a stock-1.3 wire host interoperates with Moonlight clients**. + +What is not known (UNKNOWN U9 in PROTOCOL.md): +- whether Sunshine (which ships the fork on the host side) *sends* anything a stock 1.3 peer would reject: a + checksum, a different `connect`/`verify connect` field, a different MTU, window or timeout default; +- which `connect data` value, channel count and MTU a client must offer. + +Settled by our own measurement: a capture of the control channel between a GameStream client and Sunshine on a +lab machine (not Mark's PC), decoded with our own ENet parser. One session is enough to see the handshake fields. + +**Answer: yes.** Nothing documented points at a wire change, and a stock-wire Rust ENet already talks to +Moonlight clients. The fork's differences that matter to us can be found by measurement; we do not need its code. + +### What we write ourselves + +A sans-I/O ENet 1.3 **client** subset in `domistream::enet`, `#![forbid(unsafe_code)]`: + +| Part | Scope | +| :-- | :-- | +| Datagram codec | protocol header (peer id, session bits, compressed flag rejected, optional sent time), command header, all 12 commands; strict lengths, caps (`MAX_DATAGRAM_BYTES` 4096, 32 commands per datagram) | +| Connection | connect, verify connect, disconnect (incl. disconnect-later), ping, timeout | +| Reliability | reliable sequence numbers per channel, acknowledgements, retransmission with RTT-based timeout, reliable window | +| Delivery | reliable, unreliable sequenced, unsequenced, fragments (send + reassembly, capped) | +| Throttle | parse `throttle configure` and `bandwidth limit`; honour the window; no bandwidth shaping beyond that (the control channel is tiny) | +| Not written | host side, many peers, compression (refused), the crc32 checksum (UNKNOWN whether used; refused until measured) | + +About 1,500-2,500 lines with tests. Tests: our client against `rusty_enet` (MIT) as a **dev-dependency** host over an +in-memory socket (no network, deterministic time), plus fuzzing of the datagram codec, plus the lab capture as a +recorded vector once it exists. + +## Recommendation + +1. **Write the ENet client ourselves** (`domistream::enet`, sans-I/O, no unsafe). Do not depend on an ENet crate at + runtime: the only pure-Rust ones are either tokio-bound (`tokio-enet`) or transpiled C (`rusty_enet`), and this + code parses hostile datagrams. +2. **Use `rusty_enet` (MIT) as a dev-dependency** for in-memory interop tests only. +3. **Approve stock ENet (MIT) and tokio-enet (BSD-2) as reference sources** in CLEAN_ROOM.md, because the ENet wire + format is documented nowhere else. Moonlight's fork stays forbidden. +4. **Book one lab capture** (client to Sunshine on a lab machine) to settle U9 and the other measurement-only + unknowns in PROTOCOL.md in one go. It must not be Mark's PC, his Sunshine install or his TV. +5. **Docs licence:** treat the Wolf docs as CC BY-SA 4.0: facts only, our own words, link every section. From 184f4024c7ce10688f091b4411785f95dc20b0f2 Mon Sep 17 00:00:00 2001 From: mnovak Date: Wed, 25 Nov 2026 11:26:31 +0100 Subject: [PATCH 03/55] [repo] Protocol: GameStream client side from the Wolf docs, with every UNKNOWN listed --- docs/PROTOCOL.md | 565 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 565 insertions(+) create mode 100644 docs/PROTOCOL.md diff --git a/docs/PROTOCOL.md b/docs/PROTOCOL.md new file mode 100644 index 0000000..88dd7c7 --- /dev/null +++ b/docs/PROTOCOL.md @@ -0,0 +1,565 @@ +# GameStream protocol, as DomiStream speaks it (client side) + +The protocol between a GameStream host (Sunshine, later Lumen) and a client (Arena Domi TV). Written from the Wolf +protocol docs in our own words, completed with facts read in Moonshine (BSD-2). Every fact has a tag; every gap is +marked **UNKNOWN Un** with what would settle it. Status: 2026-11-25, Phase A (docs + API, no logic yet). + +**Tags** (details in the source log, [CLEAN_ROOM.md](CLEAN_ROOM.md)): + +| Tag | Source | +| :-- | :-- | +| [W1]-[W7] | Wolf docs: index, pairing, RTSP, control, RTP video, RTP Opus, input (S-1 to S-7) | +| [M] | Moonshine `f184d5e` (S-9). A host implementation: we mirror its behaviour for the client. | +| [M*] | Moonshine, but the value has GPL provenance (Moonshine cites Sunshine or moonlight-common-c). Confirm by measurement before use. | +| [T] | tokio-enet `364628e` (S-10), pending approval as a source | +| [F] | fec-rs README (S-13) | +| [RFC n] | the RFC | + +**Not in DomiStream:** sockets, TLS, the clock, video decoding and **Opus decoding**. DomiStream hands the platform +layer (ArenaTV: webOS NDL, Android MediaCodec, Windows D3D11VA) a complete Annex-B access unit per video frame and one +Opus packet (or a "lost" marker) per audio packet, plus the Opus multistream configuration. Decoding, packet-loss +concealment and output are the platform's job. + +--- + +## 0. Overview + +Six protocols [W1]: + +| Protocol | Default port | Transport | Protection | Purpose | +| :-- | :-- | :-- | :-- | :-- | +| HTTP | TCP 47989 | plain | none | server info, pairing | +| HTTPS | TCP 47984 | TLS, client certificate | TLS | app list, launch/resume/cancel, the last pairing step | +| RTSP | TCP 48010 | plain | none | negotiate the three streams | +| Control | UDP 47999 | ENet | AES-128-GCM per message | input, feedback, host events | +| Video | UDP 47998 | RTP | none by default; optional AES-128-GCM [M] | H.264 / HEVC / AV1 | +| Audio | UDP 48000 | RTP | AES-128-CBC | Opus | + +All ports except HTTP/HTTPS can be changed by the host and reach the client through RTSP [W1]. + +Session order (client view): `serverinfo` (HTTP) → pair once (HTTP + one HTTPS step) → `applist` (HTTPS) → +`launch` (HTTPS, hands over the stream keys) → RTSP OPTIONS, DESCRIBE, SETUP ×3, ANNOUNCE, PLAY → UDP PING to the +video and audio ports + ENet connect to the control port → `START_B` on control → video and audio flow [W1][W3][M]. + +--- + +## 1. HTTP and HTTPS + +Source: [Wolf: HTTP/S pairing](https://games-on-whales.github.io/wolf/stable/protocols/http-pairing.html) [W2], Moonshine `src/webserver/` and `src/clients.rs` [M]. + +### 1.1 Common shape + +- Every call is a `GET` with a query string. Every response body is XML with one root: + `…`; a non-200 `status_code` is an error, possibly with a `status_message` + attribute (UNKNOWN U27: attribute names on errors). [M] +- Every call carries `uniqueid=` [M]. Our client id: 16 random hex characters, stored with the pairing + (UNKNOWN U1: whether the host requires a particular form). +- Binary values travel as hex in both directions [M]. Our parser accepts upper and lower case. +- HTTPS: the host presents its certificate (the same one it sends as `plaincert` while pairing [M]); the client + presents its own certificate. Only a client certificate that completed pairing may call HTTPS APIs [W2]. + The client **pins** the host certificate: the TLS certificate must equal the paired `plaincert` byte for byte. + TLS itself (version, ciphers) belongs to the platform layer (UNKNOWN U24: TLS versions Sunshine offers). + +### 1.2 serverinfo + +`GET /serverinfo?uniqueid=…` over HTTP (unpaired) or HTTPS (paired). `PairStatus` is 1 only over HTTPS with a +paired certificate [M]. Elements under `root` [M]: + +| Element | Meaning | +| :-- | :-- | +| `hostname` | host name to show | +| `appversion` | protocol version string, e.g. `7.1.431.-1`; a negative fourth part marks the Sunshine-era protocol [M] | +| `GfeVersion` | compatibility version string | +| `uniqueid` | host id (stable across restarts) | +| `HttpsPort`, `ExternalPort` | HTTPS and HTTP ports | +| `mac` | MAC address for Wake-on-LAN (may be empty) | +| `LocalIP` | host's address as it sees it | +| `MaxLumaPixelsHEVC` | HEVC capability (0 = none) | +| `ServerCodecModeSupport` | codec bitmask (UNKNOWN U25: bit meanings) | +| `SupportedDisplayMode` | display modes (may be empty) | +| `PairStatus` | 1 = this client is paired | +| `currentgame` | running app id, 0 = none | +| `state` | busy/free string, host-specific suffix (e.g. `…_SERVER_BUSY`, `…_SERVER_FREE`) | + +### 1.3 applist + +`GET /applist?uniqueid=…` over HTTPS. One `` per app with ``, `` (decimal) and +`` (0/1) [M]. Box art: `GET /appasset?appid=…` returns an image [M] (not used: Arena Domi TV +shows Arena's own covers). + +### 1.4 launch, resume, cancel + +`GET /launch?…` over HTTPS. Parameters [M]: + +| Parameter | Value | +| :-- | :-- | +| `appid` | app `ID` from applist | +| `mode` | `xx`, e.g. `1920x1080x60` | +| `rikey` | 16-byte AES key, hex. Used for control, audio and video encryption [W6][M] | +| `rikeyid` | integer key id, decimal. Feeds the audio IV (section 6.3) [M] | +| `hdrMode` | 0/1 | +| `surroundAudioInfo` | `(channel_mask << 16) | channel_count`; stereo default 196610 = `0x30002` [M] | +| others | UNKNOWN U4 (e.g. local audio playback, SOPS, gamepad mask, any version field) | + +Response [M]: `1` and `rtsp://:` +(UNKNOWN U4: what to assume when `sessionUrl0` is missing; we use port 48010 of the same host). + +`GET /resume?rikey=…&rikeyid=…` reattaches to the running app with fresh keys [M]. `GET /cancel` quits the running +app [M]. `GET /unpair` forgets this client [M]. + +**Key rule (ours):** a fresh random `rikey` and `rikeyid` for every launch and resume. Counters behind the GCM +nonces restart with each session (section 7), so a reused key would reuse nonces. + +### 1.5 Pairing + +The host shows nothing to the user in Arena Domi: arena-host submits the PIN to Sunshine locally. On the wire the PIN +handshake is unchanged. + +Inputs: `PIN` (4 ASCII digits [M]), the client's RSA certificate and key, randomness. Notation: `‖` concatenation, +`E_K` / `D_K` AES-128-ECB with key `K` and no padding (inputs are whole blocks) [M], `sig(cert)` the raw +`signatureValue` bytes of an X.509 certificate [M], `Sign`/`Verify` RSASSA-PKCS1-v1_5 with SHA-256 [M][RFC 8017]. + +| Step | Client sends | Host answers | Client then | +| :-- | :-- | :-- | :-- | +| 1 (HTTP) | `/pair?uniqueid&devicename&updateState=1&phrase=getservercert&salt=hex(salt)&clientcert=hex(client cert PEM)`; `salt` 16 random bytes | blocks until the PIN is entered on the host [M], then `paired=1`, `plaincert=hex(host cert PEM)` | derives `K = SHA-256(salt ‖ PIN)[0..16]` [W2][M]; stores the host cert | +| 2 (HTTP) | `clientchallenge=hex(E_K(C))`; `C` 16 random bytes | `challengeresponse=hex(E_K(H_s ‖ S_c))`, 48 bytes: `H_s = SHA-256(C ‖ sig(host cert) ‖ secret_s)`, `S_c` the 16-byte host challenge [W2][M] | decrypts, keeps `H_s` and `S_c`; cannot check `H_s` yet | +| 3 (HTTP) | `serverchallengeresp=hex(E_K(H_c))`, `H_c = SHA-256(S_c ‖ sig(client cert) ‖ secret_c)`, `secret_c` 16 random bytes | `pairingsecret=hex(secret_s ‖ Sign_host(secret_s))` [W2][M] | checks `Verify_host(secret_s, signature)` **and** `SHA-256(C ‖ sig(host cert) ‖ secret_s) == H_s`. Failure = wrong PIN or man in the middle: stop. | +| 4 (HTTP) | `clientpairingsecret=hex(secret_c ‖ Sign_client(secret_c))` | host checks `H_c` and the signature, answers `paired=1` (or `paired=0`) [W2][M] | | +| 5 (HTTPS) | `phrase=pairchallenge`, with the client certificate | `paired=1` [W2] | pairing done; store host cert + host `uniqueid` | + +All step responses are `1…` with the named element inside [M]. +`paired` is `0` when the host refuses. + +- UNKNOWN U1: whether Sunshine requires `devicename` / `updateState`, and the order of steps 4 and 5 (Wolf's diagram: + secret then HTTPS `pairchallenge`; Moonshine's comment lists `pairchallenge` first). We follow Wolf. Settle: lab + capture of a pairing against Sunshine. +- UNKNOWN U2: what Sunshine checks in the client certificate (key size, validity, subject). Our certificate: RSA-2048, + SHA-256, self-signed, long validity, `CN` from the device name. Settle: lab pairing. +- UNKNOWN U28: what a client should do after a failed step (call `/unpair`? just stop?). Settle: lab capture. + +--- + +## 2. RTSP + +Source: [Wolf: RTSP](https://games-on-whales.github.io/wolf/stable/protocols/rtsp.html) [W3], Moonshine `src/rtsp.rs` [M], [RFC 2326]. + +### 2.1 Messages + +Plain text over TCP [W3]. A request is a start line ` RTSP/1.0`, header lines `Name: value`, an +empty line, then an optional payload; lines end in CRLF [W3]. A response starts `RTSP/1.0 ` [W3]. +`CSeq` is always present and counts requests [W3]. Wolf's example carries `X-GS-ClientVersion: 14` [W3] +(UNKNOWN U5: which value Sunshine expects). + +- UNKNOWN U5: framing. Wolf calls the payload "anything after the headers". Our framer uses `Content-Length` when + present and otherwise ends the message when the host closes the connection. Settle: lab capture (does Sunshine + close the TCP connection after each reply, and does it send `Content-Length`?). +- Target: `rtsp://:` from `sessionUrl0` [W3][M]. + +### 2.2 Sequence [W3] + +| # | Request | Answer that matters | +| :-- | :-- | :-- | +| 1 | `OPTIONS` | 200 | +| 2 | `DESCRIBE` | SDP payload with the host's capabilities (2.3) | +| 3 | `SETUP` audio | `Transport: server_port=