Repository navigation
feat: add the secure channel session in pure Dart - #134
Conversation
…racts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiWM4SEVB1xBTaoykRa
Each install makes an X25519 client key, kept in flutter_secure_storage. Over Bluetooth, once the device reports the phone validated, the app enrolls the key with EnrollClientKey and pins the device identity per vehicle. A different identity is never pinned silently: the dashboard shows a banner to trust it or unpair. The paired phones screen shows which phones have remote access set up. Closes #128 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiWM4SEVB1xBTaoykRa
Adds a builder for [secure_channel] in transport.toml, so the key ID length and the client label limit are imported instead of copied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiWM4SEVB1xBTaoykRa
A Noise IK initiator on the cryptography package's Dart code, the channel's frames, replay window and stream framing, and SecureChannel, which keeps a session up over any frame pipe: it handshakes on first use, after expiry, on an unknown session hint and ahead of the limits, and reports a clear error when the device doesn't answer. Tested against the contract's vectors and a fake device. Closes #129 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiWM4SEVB1xBTaoykRa
Hardware test: WiCAN (ESP32-C3) + virtual-carTested with contracts#50, firmware#124, firmware#125 and mobile-app#133 (its base). Test 6 and the host checks cover this PR. Nothing calls this code yet, so it wasn't installed on the phone. Setup
Tests1. [Analysis] The identity is made on the ESP: passAfter the erase, the board created an identity. On boot it logged 2. [PR] Pairing, validation and key enrollment: passFresh pairing of the Virtual car, then validation with the cluster code. After that, Paired phones showed "Remote access set up (…)". No identity banner.
3. [PR]/[Analysis] Reset with the bond kept: passThe board was reset with
4. [Analysis] firmware#125 flashed over #124 without erasing: pass
5. [Analysis] New device identity: passI erased only the access flash range (
6. [Analysis] Live interop: the Dart
|
| Case | Result |
|---|---|
| Owner: handshake, 51 commands (each echoed back on the same session), a keepalive | 1 handshake. Every command reached BASIC_CMD_CHANNEL as Transport::Secure with the owner's ble: ID and an authorization. The keepalive was dropped silently |
| Device restart (sessions forgotten) while the client keeps its session | The next frame got the unknown-session reply (type 5). The client handshook again, and the next command went through. The command sent during the restart is lost, as designed |
| Second phone, enrolled but not validated | RejectedNotValidated from the dispatcher, sealed back on its session and decrypted by the client |
| Unknown client key / wrong pinned device key | No answer. The client failed with SecureHandshakeTimeoutException |
Host checks for the stacked PRs (CI only ran the title check, since their base isn't main)
- firmware#125:
cargo xtask test,cargo fmt --check, andcargo xtask clippyfor pc and esp × virtual-car and egmp all pass. The only warning is arustlsdeprecation inboard-pc, which also appears onmain. - mobile-app#134:
build_runner,dart format(non-generated files),flutter analyze --fatal-infosandflutter test(557 tests) all pass.
Not tested
- E-GMP in the car.
- iOS.
- A second phone: a stranger trying to enroll, or a key already enrolled by another phone.
- Xtensa/S3 flash cost.
- The channel over a real transport (LAN firmware#120, MQTT firmware#122) and its handshake time and memory on the C3.
- Re-enrolling after a lost key on the device. The unit tests cover it, but it can't be triggered on this board without also changing the identity.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiWM4SEVB1xBTaoykRa
…into feat/secure-channel-session # Conflicts: # docs/architecture.md
Requested by Michaël · project thread
What and why
Closes #129. Phase 1 of OpenCarControls/contracts#44: the app side of the secure channel (OpenCarControls/contracts#46), a transport-independent session the LAN (#130) and MQTT (#131) transports will plug into. Stacked on #133 (base
feat/client-key-enrollment); retarget tomainonce that merges.All in
lib/secure/, pure Dart with no Flutter imports (ready for the background isolate in #132):noise_ik.dart:Noise_IK_25519_ChaChaPoly_BLAKE2sinitiator, synchronous on thecryptographypackage's Dart implementations, with HMAC/HKDF from the Noise spec. Refuses a low-order device key, as the firmware does.secure_frames.dart: frame build/parse (malformed → dropped), the 64-counter replay window (updated only after a frame decrypts), and the 2-byte length framing for streams as a separate helper.secure_session.dart:SecureHandshake→SecureSession:seal(AppToDevice),sealKeepalive(),open(frame)→ message, keepalive, or drop with a reason. Tracks idle time, lifetime and message counts.SecureChannelover anySecureFramePipe: handshakes on first use, after expiry, on an unknown-session hint (keeping the old session meanwhile) and at 90 % of the lifetime or message limit (keeping the old session until the new one is up, still reading late frames on it). If the device doesn't answer withinhandshake_timeout_ms, it fails withSecureHandshakeTimeoutException, whose text tells the user to connect over Bluetooth.[secure_channel]constants are generated (SecureChannelConstantsBuilder, added in feat: enroll the app's client key once the phone is validated #133), not copied.docs/architecture.md.One choice to flag: the 90 % re-handshake threshold (
kSecureRehandshakeAt) is an app constant, not in the contract, since the device doesn't need it.How it was tested
test/secure_channel_test.dart, againstcontracts/docs/secure-channel-vectors.json: init frame byte for byte, response, handshake hash, transport frames both ways (including the out-of-order counter and the keepalive), unknown-session frame, response under another device key.SecureChannelagainst a fake device (test/support/fake_secure_device.dart, a small IK responder): messages both ways, a duplicated or replayed frame, a forged tag, timeouts (no answer, client key removed, wrong pinned device key), re-handshake after idle, before the lifetime (old session still read), after a device restart (unknown session), and after dispose.dart format,flutter analyze --fatal-infosand the fullflutter testpass.flutter testneededthermion_dart's native download skipped; that workaround is not committed.Checklist
feat:,fix:,docs:,chore:); CI validates itdart format,flutter analyze --fatal-infosandflutter testpassdocs/or README) updated if behaviour changedconfig.tomlor credentials committed; generated files not hand-editedSafety
Nothing calls the new code yet.
Generated by Claude Code