[probe] gs-probe: desktop GameStream probe client and the live interop run book
tools/gs-probe (own workspace, never published): `probe serverinfo | pair | apps | launch <app-id> | quit | unpair` against one host address, driving DomiStream's pairing, HTTP, RTSP, ENet, control, video and audio state machines over real sockets. Structured JSONL log per run (requests, answers, timings, the U each record bears on, parser errors with their bytes), secrets redacted (rikey, pairing values; PIN never logged; registered key hex scrubbed from every line). Test-only client key and cert in --out. Video: frames, decode-ready frames, FEC recoveries, losses, elementary-stream dump, live U14 parity check; audio: packets, losses, decrypting vs plain receivers (U17), packet dump and offline U16 solver (`solve-audio-fec`). START_A/START_B/PERIODIC_PING/IDR bodies come from the command line (U10). docs/LIVE-INTEROP.md: the sitting's run book (preparation, sequence S0-S5 with the U each step settles, variants, log reading, where each fact lands in PROTOCOL.md and the code, stop-and-report rule, clean-up, Mark's timeline). Built and unit-tested only (41 tests, clippy -D warnings, fmt); never run against a host.
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
//! Hides secrets before anything reaches the log or the terminal: the stream key (`rikey`) and the pairing values
|
||||
//! that, together with the PIN, would let someone redo the pairing proofs. Names stay, values go, so the log still
|
||||
//! shows which parameters were sent and in which order (U1, U4).
|
||||
|
||||
/// Query parameters whose values never reach the log.
|
||||
pub const SECRET_PARAMS: [&str; 6] =
|
||||
["rikey", "salt", "clientchallenge", "serverchallengeresp", "clientpairingsecret", "pin"];
|
||||
/// XML elements whose text never reaches the log.
|
||||
pub const SECRET_ELEMENTS: [&str; 2] = ["challengeresponse", "pairingsecret"];
|
||||
/// What replaces a secret value.
|
||||
pub const MARK: &str = "<redacted>";
|
||||
|
||||
/// `path?k=v&…` with the value of every [`SECRET_PARAMS`] name replaced by [`MARK`] (names compared ignoring case).
|
||||
pub fn query(path_and_query: &str) -> String {
|
||||
let Some((path, q)) = path_and_query.split_once('?') else { return path_and_query.to_owned() };
|
||||
let parts: Vec<String> = q
|
||||
.split('&')
|
||||
.map(|kv| match kv.split_once('=') {
|
||||
Some((k, _)) if SECRET_PARAMS.iter().any(|s| s.eq_ignore_ascii_case(k)) => format!("{k}={MARK}"),
|
||||
_ => kv.to_owned(),
|
||||
})
|
||||
.collect();
|
||||
format!("{path}?{}", parts.join("&"))
|
||||
}
|
||||
|
||||
/// `text` with the content of every `<name>…</…>` of [`SECRET_ELEMENTS`] replaced by [`MARK`] (names compared
|
||||
/// ignoring case; an element left open is redacted to the end).
|
||||
pub fn xml(text: &str) -> String {
|
||||
let lower = text.to_ascii_lowercase();
|
||||
let mut out = String::with_capacity(text.len());
|
||||
let mut i = 0;
|
||||
'scan: while i < text.len() {
|
||||
for name in SECRET_ELEMENTS {
|
||||
let open = format!("<{name}>");
|
||||
if lower.get(i..).is_some_and(|rest| rest.starts_with(&open)) {
|
||||
out.push_str(text.get(i..i + open.len()).unwrap_or(""));
|
||||
out.push_str(MARK);
|
||||
i += open.len();
|
||||
i = lower.get(i..).and_then(|rest| rest.find("</")).map_or(text.len(), |p| i + p);
|
||||
continue 'scan;
|
||||
}
|
||||
}
|
||||
let Some(c) = text.get(i..).and_then(|rest| rest.chars().next()) else { break };
|
||||
out.push(c);
|
||||
i += c.len_utf8();
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use domistream::SessionKeys;
|
||||
use domistream::http::launch::{AudioLayout, LaunchParams, launch_request};
|
||||
|
||||
#[test]
|
||||
fn launch_key_is_hidden_and_the_rest_stays() {
|
||||
assert_eq!(
|
||||
query("/launch?uniqueid=0123&appid=1&rikey=00112233445566778899aabbccddeeff&rikeyid=7"),
|
||||
"/launch?uniqueid=0123&appid=1&rikey=<redacted>&rikeyid=7"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_real_launch_request_never_shows_its_key() {
|
||||
let keys = SessionKeys { rikey: [0xA5; 16], rikeyid: 42 };
|
||||
let params = LaunchParams {
|
||||
app_id: 5,
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
fps: 60,
|
||||
keys,
|
||||
hdr: false,
|
||||
audio: AudioLayout::Stereo,
|
||||
};
|
||||
let req = launch_request(¶ms, "0123456789ABCDEF").unwrap();
|
||||
let shown = query(&req.path_and_query);
|
||||
assert!(!shown.to_ascii_lowercase().contains("a5a5a5a5"), "{shown}");
|
||||
assert!(shown.contains("rikey=<redacted>") && shown.contains("rikeyid=42") && shown.contains("appid=5"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pairing_values_are_hidden_but_names_and_certs_stay() {
|
||||
assert_eq!(
|
||||
query("/pair?uniqueid=1&devicename=x&updateState=1&phrase=getservercert&salt=ABCD&clientcert=2D2D"),
|
||||
"/pair?uniqueid=1&devicename=x&updateState=1&phrase=getservercert&salt=<redacted>&clientcert=2D2D"
|
||||
);
|
||||
assert_eq!(query("/pair?uniqueid=1&ClientChallenge=ff"), "/pair?uniqueid=1&ClientChallenge=<redacted>");
|
||||
assert_eq!(
|
||||
xml("<root status_code=\"200\"><paired>1</paired><pairingsecret>ffee</pairingsecret></root>"),
|
||||
"<root status_code=\"200\"><paired>1</paired><pairingsecret><redacted></pairingsecret></root>"
|
||||
);
|
||||
assert_eq!(
|
||||
xml("<root><challengeresponse>0011</challengeresponse><plaincert>2D2D</plaincert></root>"),
|
||||
"<root><challengeresponse><redacted></challengeresponse><plaincert>2D2D</plaincert></root>"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lookalikes_and_plain_text_are_untouched() {
|
||||
assert_eq!(query("/x?rikeyid=5&nosalt=1&pinned=2"), "/x?rikeyid=5&nosalt=1&pinned=2");
|
||||
assert_eq!(query("/serverinfo"), "/serverinfo");
|
||||
assert_eq!(xml("<root><hostname>PC é</hostname></root>"), "<root><hostname>PC é</hostname></root>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_open_element_is_redacted_to_the_end() {
|
||||
assert_eq!(xml("<challengeresponse>abc"), "<challengeresponse><redacted>");
|
||||
assert_eq!(query("?rikey=abc"), "?rikey=<redacted>");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user