Repository navigation
Conversation
The device side of the secure channel (contracts#44, phase 1), independent of the transport that carries its frames: - noise.rs: Noise_IK_25519_ChaChaPoly_BLAKE2s (responder, plus a test initiator), written on x25519-dalek, chacha20poly1305 and blake2; passes the contracts' test vectors byte for byte. - secure_channel.rs: frames, the 64-wide replay window, a session table (4 sessions, 2 per client) with idle, lifetime and message-count expiry, sessions ended by a closed link or a removed key, silent drops for unknown keys and replayed handshakes, unknown session replies, seal() for outbound messages and SECURE_TX_CHANNEL for responses. - dispatch: handle_secure_message stamps the client's ID and applies the same checks as BLE to basic and advanced commands; system commands are dropped. Transport::Secure routes responses back through the session. - Constants from [secure_channel] in transport.toml. Closes #119 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiWM4SEVB1xBTaoykRa
6 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Michaël · project thread
What and why
Closes #119. The device side of the secure channel (OpenCarControls/contracts#46, spec in OpenCarControls/contracts#50) in
core-interface, with no transport using it yet: the LAN (#120) and MQTT (#122) issues plug into it. Stacked on #124 (base branchfeat/device-identity-key); merge that first.noise.rs): I looked atclatterand implemented the pattern directly onx25519-dalek,chacha20poly1305andblake2instead. IK alone is short, and doing it directly gives the explicit per-frame nonces and the fixed ephemeral keys the vectors need without clatter's generic layers and RNG traits. It passesdocs/secure-channel-vectors.jsonbyte for byte on both sides (handshake frames, handshake hash, every transport frame), and a wrong prologue, another device key, a refused key or a tampered message fail. Low-order DH results are refused.secure_channel.rs): frame parsing and building, the 64-wide replay window (updated only once a frame decrypts), empty plaintext = keepalive, a static table of 4 sessions (2 per client) keyed by session ID +ChannelLink, expiry on idle / lifetime / message count, ended byclose_linkor by the client's key leaving the registry (checked on every frame and seal), silent drop for unknown keys and recently seen ephemerals, an unknown session frame for transport frames of a session the device doesn't have. Constants are generated from[secure_channel]intransport.toml.process_secure_frame(link, bytes) -> Option<reply>,close_link(link),seal(session, &DeviceToApp) -> (link, frame), andSECURE_TX_CHANNELfor responses (never waited on, so a stalled transport can't stall the dispatcher).handle_secure_messagestamps the client'sble:ID assource_device_id, then basic and advanced commands go through the sameadmit_vehicle_commandas BLE (read-only, validated, controller lease) and get aCommandAuthorization. Responses route back throughTransport::Secure(SessionHandle). System commands are dropped. The plain-MQTTMQTT_COMMANDS_AUTHENTICATEDgate stays until Move the MQTT driver onto the secure channel and allow remote commands #122, as the issue says.ble:source); the comment and docs say so.SESSION_BYTES, in a static).sealbuilds the frame in one buffer encrypted in place, and inbound frames decrypt into one buffer, so the heap cost of a message is about its own size (up to ~4 KB for the largest).Docs:
docs/architecture.md(new "Secure channel" section, channels table, dedupe),docs/ble.md,docs/testing.md.How it was tested
cargo xtask test: all suites pass, includingcore-interface/tests/secure_channel.rs(22 tests: the device handshake against the vectors, unknown key unanswered, replayed init refused, malformed and tampered frames dropped, commands stamped and authorized like BLE, advanced commands allowed, a not-validated phone refused withREJECTED_NOT_VALIDATEDsealed back to its session, read-only refused with the reason, system commands dropped, a command resent over BLE caught as a duplicate, sealing and per-frame counters, the replay window, keepalives, unknown session replies, idle and lifetime expiry, key removal and link close, session limits and replacement) and the vector tests innoise.rs.cargo xtask clippy --board pcandcargo fmt --checkpass;core-interfacebuilds forriscv32imc-unknown-none-elf.+esptoolchain here) and anything on hardware. I couldn't measure the handshake's real stack and heap use or its time on the C3; the 4 X25519 operations of a handshake are the cost to watch there.Checklist
cargo fmt --all -- --check,cargo xtask clippy(pc) andcargo xtask testpass; ESP left to CIconfig.toml, credentials, build artifacts or.binfiles committedSafety
admit_vehicle_commandas BLE: read-only check, validated phone for the identified car, controller lease, thenCommandAuthorization::newfor that phone, exactly as over BLE, soallow_can_txstill checks the validated phone when the frames are sent. No new way to create aCommandAuthorization, andis_can_read_only()gating is unchanged. The phone identity comes from the Noise handshake (a key enrolled over BLE by that validated phone), never from the message.Generated by Claude Code