Repository navigation
feat(secure): add the device identity key and the client key registry - #124
Conversation
…racts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiWM4SEVB1xBTaoykRa
The trust anchor of the secure channel (contracts#44, phase 1): - core-interface: the device's X25519 identity, made once from the board's random source and restored at boot, reported with its key ID in SystemState over BLE; the client key registry, filled by EnrollClientKeyCommand from a validated phone over BLE only, dropped with the phone's bond, kept when its validation ends, persisted like the validations. ListPairedPhones reports remote_key_enrolled and the label. - ESP: identity and client keys in the access range of the flash, the identity made once the BLE controller (and so the true RNG) is up. - PC: device_identity_file and client_keys_file under [hardware.pc]. Closes #118 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, mobile-app#133, and the stacked firmware#125 / mobile-app#134. Tests 1–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 #118. Phase 1 of OpenCarControls/contracts#44: the device's identity key and the registry of client keys enrolled over BLE. Nothing uses the keys yet; the secure channel (#119) does. Needs OpenCarControls/contracts#50; the submodule bump is its own commit and points at that PR's branch until it merges (I'll re-pin to
mainthen).Device identity (
core-interface/src/identity.rs)restore_device_identity(stored), which returns the bytes to persist when it made a new one.ClearPairedPhones. I did not add a "factory reset" that rotates it: erasing the flash does, and phones pair again then anyway.SystemState.device_identitywith the access state, BLE only.BleConnector::new, since the RNG is only a true random source while the radio runs. PC:[hardware.pc] device_identity_file.Client key registry (
core-interface/src/client_keys.rs)EnrollClientKeyCommandhandled in the dispatcher: BLE only (MQTT drops system commands), validated phone only (REJECTED_NOT_VALIDATED), answered with the device identity. Hub kind, bad key length, all-zero key, label > 32 bytes, and a key already enrolled by another client are refused (FAILED).ble:ID; re-enrolling replaces it. Dropped with the bond:forget_phone_validation(removal, pairing again),clear_paired_phones, andprune_phone_validationsat boot (bond reset). Kept when the validation ends (another car approved).encode_client_keys/client_keys_to_store/restore_client_keys). ESP: access range key 3, its buffer raised to 768 bytes for 8 phones; a failed write rewrites every item of the range, identity first. PC:client_keys_file.ListPairedPhonesfillsremote_key_enrolledandremote_key_label.client_for_key()is the lookup for the channel.Docs:
docs/ble.md(Device identity, Client keys, Persistence),docs/architecture.md,docs/testing.md,config.toml.example.How it was tested
cargo xtask test: all host suites pass, including the newcore-interface/tests/client_keys.rs(17 tests: identity made once, restored, absent without a random source, kept across clearing phones, key ID vs. the contract vectors; enrollment refused for bonded-not-validated phones and over MQTT, replaced on re-enroll, refusals, removed with the bond / pairing again / clear / prune, kept when the validation ends, store round-trip and malformed input).cargo xtask build --board pcandcargo xtask clippy --board pcpass;cargo test -p board-esppasses.core-interface(withx25519-dalekandblake2) builds forriscv32imc-unknown-none-elf(the C3).+esptoolchain here), soboard-espwithhardware(the store and transport changes) is only checked by CI. Not tested on hardware, and I couldn't measure the flash cost on the C3/S3. A client key surviving a restart on the PC was only checked through the encoding tests, not end to end.Checklist
cargo fmt --all -- --check,cargo xtask clippy(pc) andcargo xtask testpass; ESP clippy/build left to CIconfig.toml, credentials, build artifacts or.binfiles committedSafety
Generated by Claude Code