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 per-session secret (
generate_secret) and operating-system randomness (random_bytes), - the mutual-authentication handshake (
ClientHandshakeandServerHandshake), - the replay-protected envelope every later message travels in
(
SessionandFrameKind), - the size limits and timeout both peers enforce.
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::finishBoth 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§
- Client
Handshake - Client (app) side of the handshake, between the challenge and the server proof
- Server
Handshake - Server (
whisker run) side of the handshake, between the server proof and the client proof - Session
- One authenticated connection’s envelope state
Enums§
Constants§
- ENVELOPE_
OVERHEAD - Bytes an envelope adds around its payload
- HANDSHAKE_
TIMEOUT - Time either peer allows for the complete handshake
- MAX_
CONTROL - Largest
FrameKind::Textpayload 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