Repository navigation
feat: enroll the app's client key once the phone is validated - #133
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
Hardware test: WiCAN (ESP32-C3) + virtual-carTested with contracts#50, firmware#124, and the stacked firmware#125 / mobile-app#134. Tests 2, 3 and 5 cover this PR. 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
Requested by Michaël · project thread
What and why
Closes #128. Phase 1 of OpenCarControls/contracts#44: the app gets its own client key and enrolls it with the device over Bluetooth once the phone is validated, and pins the device's identity per vehicle. Nothing uses the keys for a connection yet; the Dart secure channel session (#129) does. Needs OpenCarControls/contracts#50 (the submodule bump is its own commit and points at that PR's branch until it merges) and the firmware side, OpenCarControls/firmware#124.
lib/secure/client_key.dart): one X25519 key pair per install, made on first use, kept influtter_secure_storage(Android Keystore), never inSharedPreferences. New dependencies:cryptography(pure Dart X25519/BLAKE2s/ChaCha20-Poly1305, also used by Secure channel session in the app #129),flutter_secure_storage, anddevice_info_plusfor the label.lib/secure/device_identity.dart): only a 32-byte key whose key ID matches it is accepted. Pinned inPairedVehicleConfig(devicePublicKey,deviceKeyId), with the client key the device last accepted (enrolledClientKey), so unpairing forgets them.clientKeyEnrollmentProvider): on each Bluetooth connection (and the debug HTTP transport), once the device reports the phone validated, it lists the paired phones and sendsEnrollClientKey(kind phone, label = phone maker and model cut to 32 UTF-8 bytes) when the device doesn't list this phone with a key, no identity is pinned, or the device last accepted another key. It pins the identity from the answer. A failure waits for the next connection.SecureChannelConstantsBuildergenerateslib/secure/secure_channel_constants.g.dartfrom[secure_channel]intransport.toml, so the key ID length and label limit are imported, not copied.code-generation.md,architecture.md(new "Secure channel keys" section and providers),ble.md,ui.md(banner order),ui-screens.md.How it was tested
test/client_key_enrollment_test.dart: key made once and kept, unreadable stored key replaced, identity validation, UTF-8 label cut, enrollment after validation (and pinned identity persisted), nothing while only bonded, no re-enrollment when already enrolled, re-enrollment when the device lost the key, a different device key flagged and then trusted, a different identity in the system state, unpair forgets the identity.dart format,flutter analyze --fatal-infosand the fullflutter testpass.flutter testneededthermion_dart's native download skipped (blocked in my sandbox); 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
It adds one system command sent over Bluetooth (
EnrollClientKey), only after the device reports the phone validated; the device checks validation itself too. Bonding,source_device_idand vehicle commands are unchanged. The private key never leaves the phone.https://claude.ai/code/session_01XkZEiWM4SEVB1xBTaoykRa
Generated by Claude Code