Files
DomiStream/docs/LAB_CAPTURE.md

272 lines
20 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Lab capture: one GameStream session on Mark's PC
Status: **Not run.** Mark, 2026-11-25: "COntinue roadmap without the check". The relay and scripts are kept for byte
logs during Day 1's live interop work; the scripts install nothing unless Mark approves a new step. The blocking
UNKNOWNs are settled live on Day 1 against the Sunshine that arena-host installs (Arena ROADMAP-REMOTE.md open
point 14).
Goal: settle the UNKNOWNs U1-U29 in [PROTOCOL.md](PROTOCOL.md) section 8 by watching **one** desktop stream between
the official Moonlight PC client and the pinned Sunshine, both on this PC, through **our own** logging relay.
Moonlight and Sunshine are black-box peers: we run them and watch their traffic, their `--help`, their own logs and
the files they write. We never open their source, never disassemble them ([CLEAN_ROOM.md](CLEAN_ROOM.md)).
Hard limits:
- One stream of the **Desktop** app, no game. Nothing touches the TV or 192.168.100.217.
- Every listening socket is on loopback: Sunshine on `127.0.0.2`, the relay on `127.0.0.1`.
- Lab keys and credentials live only under `E:\build\play-remotely\lab\`, are never printed, never on a command line that
survives, never in git, and are deleted at the end.
- Recordings stay under `E:\build\play-remotely\lab\captures\`, out of git. Only derived facts and test vectors go into
the docs.
- One UAC prompt in total.
## 0. Layout
```
E:\build\play-remotely\lab\
downloads\ Sunshine MSI and the Moonlight portable zip, as downloaded (untrusted until the sha256 matches)
moonlight\ the extracted Moonlight portable folder
keys\ lab-only TLS material (ACL: Mark's account + SYSTEM): Sunshine lab cert/key, Moonlight lab cert/key
secrets\ Sunshine API credentials, DPAPI-protected for Mark's account (ConvertFrom-SecureString)
captures\ relay recordings (*.dslr), Sunshine's log copy, the msiexec log, our notes
```
Our scripts and the relay come from this repo (`tools/lab-relay/`) and run from it, never from `downloads\`.
Built and checked on 2026-11-25 (Windows MSVC, stable 1.99, `-j 2`): `cargo test` 28 passed, `cargo clippy
--all-targets -- -D warnings` and `cargo fmt --check` clean. The relay has **not been run** yet. The two scripts
(`tools/lab-relay/scripts/lab-install.ps1`, `lab-api.ps1`) have been parse-checked only, never run; the build lead
reads them before anything goes to Mark.
The lab root is on E: (approved for Play remotely). The relay is built in `E:uild\play-remotely\DomiStream-wt-lab`
with `TEMP`/`TMP` set to `E:uild\play-remotely mp`, `-j 2`, and only while CPU, RAM, D: and E: are all below
90 % (DomiStream CLAUDE.md).
## 1. Step (a): the old Sunshine is gone (read-only)
Mark has uninstalled it himself. We only check, changing nothing:
| Check | Command (read-only) | Expected |
| :-- | :-- | :-- |
| Service | `Get-Service *sunshine* -ErrorAction SilentlyContinue` | nothing |
| Processes | `Get-Process sunshine*, sunshinesvc -ErrorAction SilentlyContinue` | nothing |
| Folder | `Test-Path 'C:\Program Files\Sunshine'` | `False` (or a folder without `sunshine.exe`; then we stop and ask, we do not delete it) |
| Uninstall entry | `Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* \| ? DisplayName -like '*Sunshine*'` | nothing |
| TCP ports | `Get-NetTCPConnection -State Listen \| ? LocalPort -in 47984,47989,47990,48010` | nothing |
| UDP ports | `Get-NetUDPEndpoint \| ? LocalPort -in 47998,47999,48000,48002` | nothing |
| Firewall leftovers | `Get-NetFirewallRule -DisplayName '*Sunshine*' -ErrorAction SilentlyContinue` | nothing (only noted if present) |
| Load | the CPU/RAM check from the build rule | both ≤ 90 %, else wait |
Anything unexpected: stop and report; no clean-up on our side.
## 2. Step (b): pinned Sunshine, one UAC prompt
**Pin** (release API, S-19): `v2026.914.233613`, `Sunshine-Windows-AMD64-installer.msi`, 33,710,080 bytes,
sha256 `1d7fed8beecd5889dc7ff14cf9f42d6d38f37c3066c13c6c2a5f4e91847e0ccf`,
`https://github.com/SunshineStream/Sunshine/releases/download/v2026.914.233613/Sunshine-Windows-AMD64-installer.msi`.
The same digest is checked twice: against this pin and against the release API's `digest` field fetched at download
time. A mismatch on either = delete the file and stop.
Download (not elevated): `Invoke-WebRequest -Uri <url> -OutFile E:\build\play-remotely\lab\downloads\Sunshine-Windows-AMD64-installer.msi`,
then `Get-FileHash -Algorithm SHA256`. Nothing is run from `downloads\` before the hash matches.
**Why one elevated script, not a bare `msiexec`:** Sunshine's first start must already be bound to loopback, and
`--creds` needs write access under `C:\Program Files\Sunshine\config`. A plain `msiexec /i` would start the service
on all interfaces with no credentials. So we start **one** elevated PowerShell (`Start-Process powershell -Verb RunAs`
with our script `tools/lab-relay/scripts/lab-install.ps1`). That is the one UAC prompt ("Windows PowerShell",
publisher Microsoft Windows). Inside it, without further prompts:
1. `msiexec /i <msi> /qn /norestart /l*v E:\build\play-remotely\lab\captures\msiexec.log` (quiet; elevated already).
2. `Stop-Service SunshineService` as soon as the MSI returns (the MSI starts it; until our config is in, it has no
credentials, so nobody can pair or call its API).
3. Write `C:\Program Files\Sunshine\config\sunshine.conf` with only these lines:
```
bind_address = 127.0.0.2
address_family = ipv4
origin_web_ui_allowed = pc
upnp = disabled
external_ip = 127.0.0.2
sunshine_name = DomiStream-lab
lan_encryption_mode = 1
wan_encryption_mode = 1
min_log_level = debug
pkey = E:/build/play-remotely/lab/keys/sunshine-lab-key.pem
cert = E:/build/play-remotely/lab/keys/sunshine-lab-cert.pem
```
Forward slashes in paths: how the config parser treats backslashes is not documented. Encryption mode 1 ("if the client supports it") rather than 2: if Moonlight PC lacks one kind of encryption, a
mandatory setting would refuse the only session we get. `pkey`/`cert` point at `keys\` so the lab key never has to
be copied out of Program Files (inferred: Sunshine creates the pair at the configured path when missing; if it does
not, the script removes the two lines, restarts, and copies the default pair from `config\credentials\` into
`keys\` instead, still inside the same elevation).
4. **First-run credentials, never on a surviving command line:** the script draws a throwaway username and password
(32 random bytes each, base64url), runs `sunshine.exe --creds <u> <p>` once (the documented non-interactive way,
sunshine-api.md §4; the arguments live only for that process's lifetime), and saves the throwaway pair to
`secrets\sunshine-throwaway.cred` with `ConvertFrom-SecureString` (DPAPI, Mark's account). It is rotated in step 5.
This needs Mark's account to be the one that elevates (consent prompt, not a password prompt); if UAC asks for a
different admin account, we stop.
5. `Start-Service SunshineService`; wait until `Get-NetTCPConnection` shows 127.0.0.2:47989/47984/47990/48010 and
nothing on 0.0.0.0; `icacls` `keys\` and `secrets\` down to Mark's account + SYSTEM. Exit.
After the elevated script, not elevated (`lab-api.ps1`, PowerShell, Basic auth built in memory, TLS pinned to
`keys\sunshine-lab-cert.pem` by thumbprint): `POST https://127.0.0.2:47990/api/password` from the throwaway pair to a
fresh random lab pair stored in `secrets\sunshine-lab.cred` (DPAPI); delete the throwaway file. Arena's Day 1
takeover rotates once more into Custos.
Firewall: if the MSI added inbound rules, we only note them (`Get-NetFirewallRule`); Sunshine listens on 127.0.0.2,
so they expose nothing. Changing them needs admin and is left to Arena Day 1.
## 3. Step (c): Moonlight PC portable, no install
**Pin** (release API, S-19): `v6.2.0` (2026-10-04), `MoonlightPortable-x64-6.2.0.zip`, 37,242,232 bytes,
sha256 `6f91d268b41ed5ca8066d9d7578dc403b8db190991ff48f00b1700465f8f7ebf`,
`https://github.com/moonlight-stream/moonlight-qt/releases/download/v6.2.0/MoonlightPortable-x64-6.2.0.zip`.
Download to `downloads\`, check the hash (pin and API digest), extract to `E:\build\play-remotely\lab\moonlight\`.
No installer, no admin.
Before its first start we snapshot (names only) the `moonlight\` folder tree and the key names under
`HKCU:\Software` so that afterwards we can see what Moonlight wrote (its settings and its client identity; where it
keeps them is not documented and we do not read its source to find out). We run `Moonlight.exe --help` first
(black-box) to see whether it can pair from the command line with a PIN we choose.
**Moonlight's lab client key:** the relay needs it to talk TLS to Sunshine on Moonlight's behalf (section 4). After
Moonlight's first start (or at the latest right after pairing step 1, which carries its certificate), a small script
finds the new value by name and length only, writes the key as PEM to `keys\moonlight-lab-key.pem` and the certificate
to `keys\moonlight-lab-cert.pem`, and prints neither. If the key is not readable (for example protected with DPAPI by
Moonlight), the relay passes HTTPS through untouched and we fall back to Sunshine's debug log for what HTTPS carries
(section 6 lists what that loses).
## 4. Step (d): the relay
### Addresses
```
Moonlight ──▶ 127.0.0.1:{47984,47989,48010}/tcp, {47998,47999,48000,48002}/udp (lab-relay, logs everything)
└──▶ 127.0.0.2: same ports (Sunshine, bind_address)
```
Moonlight is told the host is `127.0.0.1`. Because Sunshine sits on another loopback address with its **default**
ports, the relay copies the port numbers unchanged: no port rewriting in serverinfo, RTSP or SDP, which matters
because RTSP may be encrypted (U5) and could not be rewritten.
Address rewriting: Sunshine may write its own address (`127.0.0.2`) into answers, for example `sessionUrl0` in the
launch answer, which would send Moonlight around the relay. The relay replaces the 9 bytes `127.0.0.2` with
`127.0.0.1` in **host-to-client plaintext only** (HTTP, decrypted HTTPS, plain RTSP), logs the original and a note
per replacement. Same length, so `Content-Length` stays right.
Fallback if Sunshine refuses `bind_address = 127.0.0.2`: Sunshine on `127.0.0.1` with `port = 48989` (all ports
+1000), the relay on the default ports, and port rewriting of `HttpsPort`/`ExternalPort` (serverinfo), `sessionUrl0`
(launch) and `server_port=` (RTSP SETUP). That only works while RTSP is plaintext, so the fallback also sets the
encryption modes to 0 and gives up U17/U19 for this capture.
UDP: video, audio and control go to the address the client's first datagram (the PING, or the ENet connect) came
from (W5, W6). The relay keeps one upstream socket per client address and port, so Sunshine sees the relay's socket
and answers it; the relay sends the answers back to Moonlight's socket. ENet carries no addresses.
### What is encrypted, and how we see plaintext
| Traffic | Protection | How the relay sees it |
| :-- | :-- | :-- |
| HTTP 47989 (serverinfo, pairing steps 1-4) | none | plaintext |
| HTTPS 47984 (pairing step 5, applist, launch with `rikey`, cancel) | TLS, both sides pin certificates | **terminated in the relay**: towards Moonlight it presents Sunshine's own lab certificate (the one Moonlight pinned in pairing, so the pin holds); towards Sunshine it presents Moonlight's own lab client certificate and pins Sunshine's lab certificate |
| RTSP 48010 | plaintext, or encrypted when negotiated (U5) | as is; if encrypted, decrypted offline with `rikey` from the launch request |
| Control 47999 | AES-128-GCM with `rikey` (client-chosen) | ENet headers plaintext; message bodies decrypted offline with `rikey` |
| Audio 48000 | AES-128-CBC with `rikey`, if negotiated | decrypted offline |
| Video 47998 | AES-128-GCM with `rikey`, only if negotiated | headers plaintext unless encrypted; decrypted offline |
Why TLS termination and not just Sunshine's log: `rikey` and the launch parameters (U4) travel only inside HTTPS.
Without them, control, audio and possibly video stay opaque and U10, U11, U16, U17, U19, U20, U22 stay open. The debug
log's contents are not documented, and asking it to print keys is not something we can count on. Termination uses
only lab material that exists for this capture and is deleted after it; nothing outside this PC's loopback is
touched. Sunshine's debug log (`GET /api/logs`) is still copied into `captures\` as a cross-check.
The relay never changes a byte except the documented address rewrite, and never sends anything on its own.
### Which part of the capture settles which UNKNOWN
| U | Settled by |
| :-- | :-- |
| U1 | HTTP 47989 pairing requests (query names, order), then the first HTTPS request (`pairchallenge`) and its place in the order |
| U2 | partly: the certificate Moonlight sends in pairing step 1 shows one certificate Sunshine accepts (key size, validity, subject); our own certificate is tested on Day 1 |
| U4 | the decrypted HTTPS `/launch` request and answer |
| U5 | the RTSP TCP stream: framing, `Content-Length`, `X-GS-ClientVersion`, SETUP targets, `Transport`, `Session`, PLAY |
| U6 | the ANNOUNCE payload Sunshine accepted |
| U7 | headers of the three SETUP answers |
| U8 | the first client-to-host datagrams on 47998 and 48000, and their timing |
| U9 | control datagrams decoded with our ENet parser: connect/verify connect fields, flags, anything stock 1.3 lacks |
| U10 | decrypted control messages: START_A/B, PERIODIC_PING, LOSS/FRAME_STATS, IDR request, termination at the end, and their timing |
| U11 | control frame sequence numbers in both directions |
| U13 | the first 8 bytes of each reassembled video frame |
| U14 | confirmation: our Cauchy encoder must reproduce every captured video parity packet (offset 32 on) |
| U15 | the multi-FEC flags byte across all video packets |
| U16 | captured audio blocks: solve the 2 × 4 parity matrix over GF(2^8) from data and parity bytes |
| U17 | ANNOUNCE `encryptionEnabled` plus whether audio payloads decrypt |
| U19 | the video packet layout when video encryption was negotiated (if Moonlight PC does not negotiate it, U19 stays open) |
| U20 | keys typed during the stream into a scratch Notepad window |
| U22 | gamepad packets, only if Mark has a controller plugged in (optional) |
| U24 | the TLS handshakes on 47984 (versions, cipher suites), logged by the relay |
| U25 | `ServerCodecModeSupport` in serverinfo from a host whose GPU we know (RTX 3090) |
| U26 | the `surround-params` lines in DESCRIBE (all of them, if Sunshine lists every Opus configuration as Moonshine does) |
| U27 | only if a call is refused during the session; not provoked |
| U29 | video RTP timestamps against the 60 fps frame rate |
| U21, U23, U28 | **not** settled: no touch/pen device, no game to rumble, no wrong PIN in a one-session capture |
## 5. Step (e): what is recorded, analysis, clean-up
**Recorded** (`captures\`):
- `session-<UTC>.dslr`: the relay's record file. Each record: kind (open, data, close, note), protocol (HTTP,
HTTPS plaintext, RTSP, video, control, audio, mic, meta), direction, connection id, microseconds since the start,
and the bytes. Format and tests: `tools/lab-relay/src/record.rs`.
- `sunshine.log` (copied with `GET /api/logs`), `msiexec.log`.
- `notes.md`: what we did and when (times from the relay's clock).
**Privacy:** the video frames are Mark's desktop. Before the stream, Mark closes anything private; during it, only a
scratch Notepad and the desktop are on screen. After analysis the video payload bytes are deleted from the recording
(`lab-relay strip-video`), keeping only packet headers and parity checks.
**Analysis** (offline, no network): `lab-relay dump` lists records with secrets redacted (`rikey=`, `Authorization:`,
pairing values); per-protocol extraction feeds DomiStream's own parsers (Phase B) and small Python checks run with
`python -I` from the repo, never from `captures\`. Every fact that comes out goes into PROTOCOL.md with the tag
`[L1]` (lab capture 1, date, versions) and, where useful, into test vectors that contain **no** lab key (vectors are
re-encrypted with test keys generated in the test).
**Clean-up** (right after the stream, not elevated):
1. Quit Moonlight; stop the relay.
2. `POST /api/clients/unpair-all` (removes the Moonlight lab client from Sunshine).
3. `POST /api/config` without the `pkey`/`cert` lines and `POST /api/restart`, so Sunshine makes a fresh pair at its
default path (inferred; if it does not, the lab pair stays referenced and Arena's Day 1 takeover, which runs
elevated anyway, regenerates it). Then delete `keys\sunshine-lab-*.pem`.
4. Delete `keys\moonlight-lab-*.pem`, the whole `moonlight\` folder and the registry key Moonlight created (found by
the snapshot diff in step (c)).
5. Keep `secrets\sunshine-lab.cred` until Arena's Day 1 takeover rotates the credentials into Custos, then delete it.
6. Delete `downloads\Moonlight*.zip`. Keep the Sunshine MSI (Arena Day 1 pins the same version).
7. Sunshine **stays installed**, bound to 127.0.0.2, ready for Arena's Day 1 takeover.
8. The recordings stay on E: until the facts are in PROTOCOL.md and QA has its vectors; then they are deleted on the
build lead's word.
## 6. If something fails
| Failure | What we do |
| :-- | :-- |
| sha256 mismatch | delete the file, stop, report |
| Sunshine will not bind 127.0.0.2 | fallback of section 4 (port +1000, encryption off for this capture) |
| Moonlight refuses `127.0.0.1` as a host | relay on `127.0.0.3` instead (any loopback address works) |
| The relay's TLS handshake with Moonlight or Sunshine fails (for example a cipher suite rustls does not offer) | restart the relay with `--https-passthrough`: HTTPS is then recorded as raw TLS, with the same losses as the next row |
| Moonlight's key not readable | HTTPS passes through untouched; we lose U4 and `rikey`, so U10, U11, U16, U17, U19, U20, U22 stay open unless Sunshine's debug log shows them |
| Pairing needs a `pairing_id` we cannot find (sunshine-api.md gap) | we watch the network calls of Sunshine's own local PIN page in our browser pane (black-box) and submit the PIN there ourselves |
| CPU or RAM above 90 % | wait (the relay build and the stream are both heavy) |
## 7. Step (f): timeline for Mark
About 20 minutes; Mark's part is **one click**, plus closing private windows before the stream.
| When | What happens | Mark |
| :-- | :-- | :-- |
| 0:00 | We check that the old Sunshine is gone and that the PC is not busy. | nothing |
| 0:02 | We download the pinned Sunshine and Moonlight and check their fingerprints (about 70 MB). | nothing |
| 0:05 | **A UAC prompt appears: "Windows PowerShell – Do you want to allow this app to make changes to your device?" (publisher: Microsoft Windows).** | **click Yes** (the only click) |
| 0:05-0:08 | Sunshine installs quietly and starts, reachable only from this PC. | nothing |
| 0:08 | Moonlight opens in a window (portable, nothing installed). It may show a PIN; we enter it into Sunshine ourselves. If Windows Firewall asks about Moonlight, click **Cancel**: everything runs on this PC. | close private windows; Cancel on a firewall prompt if one appears |
| 0:10 | A one-minute desktop stream: Moonlight shows his own desktop in a window. We move the mouse and type a few letters into a scratch Notepad. If he has a gamepad plugged in, we may ask him to press a few buttons. | hands off the mouse and keyboard for that minute (optional: press gamepad buttons when asked) |
| 0:12 | We close the stream, unpair Moonlight, delete Moonlight and the lab keys. Sunshine stays installed for Arena's Day 1. | nothing |
| later | We analyse the recording offline and delete the desktop video from it. | nothing |