Pairing & Cryptography
JetPack protects the local 127.0.0.1:9470 WebSocket channel with Out-of-Band (OOB) human authorization, mutual asymmetric authentication, ephemeral forward secrecy, and encrypted at-rest key storage.
1. Out-of-Band Pairing (jetpack://pair)
Standard browser CORS is insufficient to protect a localhost daemon against DNS rebinding or rogue browser tabs. Every external origin must first pair out-of-band:
- Identity Generation (
WasmClientIdentity):- In the browser,
jetpack-wasmgenerates a randomUUIDv4client_idand two 32-byte seeds (Ed25519signing key + companionX25519static key) usinggetrandom, persisted inwindow.localStorage(jetpack_client_id,jetpack_ed25519_seed,jetpack_x25519_seed).
- In the browser,
- Pairing URI Construction:
- The client formats a deep link:text
jetpack://pair?client_id=<uuid>&pubkey=<urlsafe-base64>&origin=<normalized-origin> crates/jetpack-proto/src/pairing.rsvalidates thatclient_idis an RFC 4122 UUID,pubkeydecodes to 32 bytes (Ed25519) or 64 bytes (Ed25519+X25519), andoriginis a validhttps://origin or loopbackhttp://127.0.0.1/http://localhost. Plainhttp://remote origins are rejected withPairingUriError::InvalidOrigin. (Legacycorenode://pairURIs remain accepted for backwards compatibility.)
- The client formats a deep link:
- Single-Instance IPC Dispatch:
- When the OS launches
jetpack-daemonvia the custom URI handler (CLI arguments on Windows/Linux orAppleEventon macOS), the secondary process pings<root>/config/pairing.ipc(PING <token>). If a primary daemon is running, it forwards the URI over local IPC and exits with status0.
- When the OS launches
- Native OS Confirmation Dialog:
- On the main UI thread,
jetpack-daemondisplays a native OS modal dialog (NSAlerton macOS,TaskDialogon Windows,GTK/Portalon Linux viarfd) showing:- Requesting web
origin client_idUUID- Deterministic
SHA-256public key fingerprint (SHA256:XX:YY:...)
- Requesting web
- Only clicking Yes / Allow persists the client in
paired_clients.db. Dismissing or clicking No aborts without writing to disk.
- On the main UI thread,
2. Encrypted At-Rest Storage (ChaCha20-Poly1305 + OS Secret Vault)
Approved clients, authorized folder mounts (authorized_volumes), and daemon settings live in <root>/config/paired_clients.db, encrypted at rest as a pure-Rust ChaCha20-Poly1305 (AEAD) container over serialized SQLite (rusqlite bundled, zero OpenSSL dependency).
- Master Key & AEAD Envelope: On first run,
OsKeyringStore(crates/jetpack-daemon/src/pairing.rs) generates 32 cryptographically random bytes (256-bitkey). Every write generates a fresh 96-bit CSPRNG nonce (getrandom), authenticates theJPKDB01\0header + nonce as AAD, and atomically replacespaired_clients.db. - OS Vault Storage (
keyring): The master key is never stored in plaintext config files. It is stored exclusively inside the host OS credential vault under serviceio.jetpack.daemon(with automatic migration from legacyio.corenode.daemon):- Windows: Windows Credential Manager / DPAPI
- macOS: macOS Keychain
- Linux: FreeDesktop Secret Service (
gnome-keyring/KWallet)
- Attempting to inspect
paired_clients.dbwith standardsqlite3without the vault key fails immediately withError: file is not a database.
3. Authenticated X25519 + Ed25519 Session Handshake
Every WebSocket connection to ws://127.0.0.1:9470 must pass two layers before any application data is processed:
- HTTP Upgrade & Private Network Access (PNA):
- On
OPTIONSpreflight andGETWebSocket Upgrade,ws_server.rsnormalizes the HTTPOriginheader and verifies it againstpaired_clients.db(or the daemon's own Control Center originhttp://127.0.0.1:<port>). - Unauthorized or missing origins receive
HTTP/1.1 403 Forbidden. - Authorized origins receive
Access-Control-Allow-Origin: <origin>,Access-Control-Allow-Private-Network: true, andVary: Origin.
- On
- Post-Upgrade
ClientHello/ServerHello(crates/jetpack-proto/src/handshake.rs):- Immediately after
101 Switching Protocols, the client has 5 seconds (DEFAULT_HANDSHAKE_TIMEOUT) to send a binaryClientHelloenvelope:text(Wire magic[Magic "CNOD" (4 B)] + [Version u16 LE (2 B)] + [MsgPack ClientHello]"CNOD"and transcript signing domainb"CORENODE-HANDSHAKE-V1"are preserved for protocol compatibility.) ClientHellocontainsclient_id,origin, a fresh ephemeralX25519public key (32 B), a randomclient_nonce(32 B), and a 64-byteEd25519signature over the transcript.ServerHandshakeverifies:client_idexists inpaired_clients.db.ClientHello.originmatches both the storedorigininpaired_clients.dband the HTTP UpgradeOriginheader (preventing cross-client origin spoofing).- The
Ed25519signature is valid under the stored public key.
- The daemon generates its own ephemeral
X25519keypair andserver_nonce, computes the ECDH shared secret, and derives three 256-bit secrets via HKDF-SHA256 bound to the full handshake transcript:client_to_daemon_key(32 B)daemon_to_client_key(32 B)confirm_key(32 B) +session_id
- The daemon responds with
ServerHellocontaining anHMAC-SHA256transcript confirmation tag (confirm_key), and both sides zeroize ephemeral private keys and raw shared secrets in memory (zeroize::Zeroize).
- Immediately after
4. ChaCha20-Poly1305 Streaming Frames & Replay Protection
After ServerHello, all WebSocket messages are authenticated and encrypted with ChaCha20-Poly1305 (RFC 8439) inside SessionCipher (crates/jetpack-proto/src/framing.rs):
+-------------------------------+----------------------------------------+------------------------+
| seq: uint64 LE (8 B, AAD) | Ciphertext of Plaintext HybridFrame | Poly1305 Tag (16 B) |
+-------------------------------+----------------------------------------+------------------------+- Directional 96-bit Nonces:
- Client -> Daemon:
b"C2D\0" || seq.to_le_bytes()(4 B + 8 B = 12 B) - Daemon -> Client:
b"D2C\0" || seq.to_le_bytes()(4 B + 8 B = 12 B)
- Client -> Daemon:
- Associated Data (AAD): The 8-byte little-endian
seqis passed as AAD to AEAD encryption/decryption. - Strict Anti-Replay Enforcement: Both directions maintain independent
u64sequence counters starting at0. Any frame arriving with an out-of-order, duplicated, or skippedseqis rejected withProtoError::InvalidSequenceNumberwithout advancing the counter, and the WebSocket connection is closed immediately. - Strict Binary-Only Policy: Sending any post-handshake WebSocket text/JSON frame (
Message::Text) causesjetpack-daemonto immediately close the connection with1003 Unsupported Data.
