SDK

SDK de cliente

valkyr-client, el SDK de cliente opcional en modo usuario: heartbeats de sesión firmados, atestación de la build y pistas de integridad.

valkyr-client es opcional. Vive dentro del cliente de tu juego, se ejecuta en modo usuario, no necesita permisos de administrador y no instala nada. Le da al servidor tres cosas que el servidor no puede medir por sí mismo:

  1. Una sesión firmada. Claves Ed25519 nuevas por sesión, rotadas según un calendario y que responden a nonces del servidor, así que los heartbeats no se pueden falsificar ni repetir.
  2. Atestación de la build. El hash de la build del juego y un hash raíz sobre los propios archivos del juego, comparados con las builds que permites.
  3. Pistas de integridad. Un depurador conectado, breakpoints de hardware, una biblioteca precargada, saltos del reloj de pared, cambios en memoria de la sección de código del juego.

El servidor nunca confía en él más que en su propia evidencia: las señales del cliente entran como alertas client.*, y un veredicto construido solo con ellas se limita a review.

El handshake

El cliente saluda, el servidor responde con un desafío, el cliente envía un heartbeat firmado, el servidor lo verifica y reporta los problemas. En un juego real, el JSON viaja por tu propio canal de red hasta el servidor de juego, que lo reenvía a valkyr-server (POST /v1/sessions y POST /v1/sessions/{session_id}/heartbeat).

heartbeat.rsRust
fn main() {    let build_hash = Hex32([0x42; 32]);    let manifest_root = Hex32([0x24; 32]);     // Client side: session key and signal collector.    let mut client = ClientSession::new(ClientConfig {        build_hash,        manifest_root,        rotate_every: 2,    })    .expect("os random generator");    let mut collector = SignalCollector::new(SignalConfig::default());    let mut scheduler = Scheduler::new(Duration::from_secs(10), 25);     // 1. Client -> server: hello.    let hello_json = serde_json::to_string(&client.hello()).unwrap();    println!("hello: {hello_json}");     // Server side: accept the hello.    let hello: Hello = serde_json::from_str(&hello_json).unwrap();    let config = VerifierConfig {        allowed_builds: vec![build_hash],        expected_manifest_root: Some(manifest_root),        rotate_after: 2,        ..VerifierConfig::default()    };    let mut server = SessionVerifier::new(&hello, config, wall_ms()).expect("hello accepted");     for round in 1..=3 {        // 2. Server -> client: challenge.        let challenge_json =            serde_json::to_string(&server.issue_challenge(wall_ms()).unwrap()).unwrap();        println!("challenge {round}: {challenge_json}");         // 3. Client -> server: signed heartbeat.        let challenge: Challenge = serde_json::from_str(&challenge_json).unwrap();        client.handle_challenge(&challenge);        collector            .clock_mut()            .observe_server_time(challenge.server_time_ms);        let signals = collector.collect();        let heartbeat = client.heartbeat(signals, code_hash()).unwrap();        let heartbeat_json = serde_json::to_string(&heartbeat).unwrap();        println!("heartbeat {round}: {heartbeat_json}");         // 4. Server verifies.        let heartbeat: Heartbeat = serde_json::from_str(&heartbeat_json).unwrap();        let report: HeartbeatReport = server.verify(&heartbeat, wall_ms());        println!(            "report {round}: {}",            serde_json::to_string(&report).unwrap()        );        for p in &report.problems {            println!("  problem: {p}");        }        println!(            "  next check in {:?} (a real game would wait)",            scheduler.next_delay()        );    }     // A replayed heartbeat is refused.    let challenge = server.issue_challenge(wall_ms()).unwrap();    client.handle_challenge(&challenge);    let hb = client.heartbeat(collector.collect(), None).unwrap();    assert!(server.verify(&hb, wall_ms()).ok);    let replay = server.verify(&hb, wall_ms());    println!("replay: ok={} problems={:?}", replay.ok, replay.problems);}

Ejecútalo con cargo run -p valkyr-client --example heartbeat.

Exactamente lo que se envía

Esta tabla forma parte de la documentación del crate y se incluye aquí tal como está escrita:

valkyr-client/src/lib.rsText
game enables them in [`signals::SignalConfig`]. | Field | Default | What is sent ||---|---|---|| `client_key`, `next_key` | always | random ed25519 public keys, fresh per session, not tied to the machine or the user || `build_hash` | always | SHA-256 of the game build, chosen by the game || `manifest_root` | always | one SHA-256 over the game's own listed files (paths, sizes, hashes stay local) || `code_hash` | when the game passes it | SHA-256 of the game's own in memory code section || `client_time_ms`, `monotonic_ms` | always | wall clock and time since session start || `signals.debugger` | on | one state: a debugger is attached to the game process || `signals.hardware_breakpoints` | on | one state: debug registers set on the collecting thread || `signals.timing_anomaly` | on | one state from timing a fixed workload || `signals.hypervisor` | on | one state from CPUID, a hint only, never treated as cheating || `signals.preload_env` | on | one state: `LD_PRELOAD` / `DYLD_INSERT_LIBRARIES` is set for the game; the value is not sent || `signals.unexpected_modules` | **opt in** | a count and the SHA-256 of each unexpected module *file name*; never paths, never the allowed modules || `signals.overlay_windows` | **opt in** | for each window covering the game: SHA-256 of a per session random salt plus the title (the title itself is never sent and cannot be correlated across sessions), and four flags (topmost, layered, click through, same process) || `signals.clock` | on | one state, a count of wall clock jumps, the largest jump, and the client to server speed ratio || `signals.code_drift` | on | one state: the game's code section changed since startup | Nothing else is collected: no hardware identifiers, no user names, noprocess lists, no file lists outside the manifest, no screenshots.

No se recopila nada más: ni identificadores de hardware, ni nombres de usuario, ni listas de procesos, ni listas de archivos fuera del manifiesto, ni capturas de pantalla. Consulta Privacidad.

Ajustes de sesión

OpciónTipoValor por defectoDescripción
client.allowed_buildsVec<Hex32>[]Allowed build hashes (hex). Empty accepts any build.
client.expected_manifest_rootOption<Hex32>sin definirExpected manifest root (hex).
client.max_gap_msu6430000Maximum time between two heartbeats.
client.rotate_afteru640Required key rotation period in heartbeats (0: none).
client.clock_tolerance_msu642000Allowed wall against monotonic clock drift between heartbeats.
client.speed_window_msu6430000Server time span before the clock speed ratio is judged.
client.speed_tolerance_ppmu64100000Allowed speed ratio deviation, parts per million.
client.max_outstanding_noncesusize4Outstanding nonces per session.
client.nonce_ttl_msu6460000Maximum nonce age.

Generado a partir de crates/valkyr-server/src/config.rs (ClientSection) al compilar el sitio.

Desde otros lenguajes

La ABI de C expone la misma sesión de cliente (valkyr_client_new, valkyr_client_hello_json, valkyr_client_handle_challenge_json, valkyr_client_heartbeat_json) y las funciones del manifiesto. Consulta las páginas de C, C++ y C#.

Editar esta página en GitHub