Skip to main content

Crate whisker_dev_protocol

Crate whisker_dev_protocol 

Source
Expand description

Authenticated wire protocol for the whisker run development channel

whisker run (through whisker-dev-server) and the app it launches (through whisker-dev-runtime) talk over a WebSocket that can deliver native libraries the app then loads. This crate holds everything both sides must agree on so that only the app launched by the current session accepts those libraries, and only the current session’s server can send them:

The crate performs no I/O. The dev server and the dev runtime own their sockets, feed received handshake text into these state machines, and send whatever text or bytes the state machines return.

§Handshake

app (client)                               whisker run (server)
  ClientHandshake::start ── challenge ──▶   ServerHandshake::respond
  ClientHandshake::finish ◀── server proof ──
                           ── client proof ─▶ ServerHandshake::finish

Both nonces are fresh 256-bit random values. Each proof is an HMAC-SHA256 over both nonces under a role-specific domain, so neither proof can be reflected back as the other. The secret itself never crosses the wire. The client verifies the server before it sends anything that identifies the process, which keeps a substituted server from learning the app’s ASLR reference, logs, or trace data. There is no version negotiation: a peer built against a different protocol version fails the handshake with an Error that names the mismatch.

§Envelope

After the handshake every message is a binary envelope:

[version: u8][kind: u8][sequence: u64 BE][payload][HMAC-SHA256: 32 bytes]

The tag covers the direction, both nonces, and every envelope byte before it. Each direction must use the next sequence number, so modified, replayed, reordered, reflected, and cross-session envelopes fail Session::open before the payload reaches a parser.

§Example

use whisker_dev_protocol::{ClientHandshake, FrameKind, ServerHandshake};

let secret = whisker_dev_protocol::generate_secret()?;

let (client, challenge) = ClientHandshake::start(&secret)?;
let (server, server_proof) = ServerHandshake::respond(&secret, &challenge)?;
let (mut app, client_proof) = client.finish(&server_proof)?;
let mut host = server.finish(&client_proof)?;

let envelope = host.seal(FrameKind::Text, br#"{"kind":"reload"}"#)?;
assert_eq!(
    app.open(&envelope)?,
    (FrameKind::Text, br#"{"kind":"reload"}"#.as_slice())
);
// The same envelope is rejected the second time.
assert!(app.open(&envelope).is_err());

§Trust boundary

HMAC authenticates the channel but does not encrypt it. The operating system’s debug transport (environment variables, adb) that delivers the secret to the app is trusted.

Structs§

ClientHandshake
Client (app) side of the handshake, between the challenge and the server proof
ServerHandshake
Server (whisker run) side of the handshake, between the server proof and the client proof
Session
One authenticated connection’s envelope state

Enums§

Error
Why a handshake or envelope was rejected
FrameKind
What an envelope’s payload contains

Constants§

ENVELOPE_OVERHEAD
Bytes an envelope adds around its payload
HANDSHAKE_TIMEOUT
Time either peer allows for the complete handshake
MAX_CONTROL
Largest FrameKind::Text payload and patch metadata header, in bytes
MAX_HANDSHAKE
Largest handshake message, in bytes
MAX_MESSAGE
Largest complete envelope, header and tag included, in bytes
MAX_PAYLOAD
Largest payload a single envelope carries, in bytes
PROTOCOL_VERSION
Version byte carried by the challenge and every envelope

Functions§

generate_secret
Generate a fresh per-session secret
random_bytes
Fill an N-byte array from the operating system’s CSPRNG