Skip to content

feat: enroll the app's client key once the phone is validated - #133

Open
Tichael wants to merge 3 commits into
mainfrom
feat/client-key-enrollment
Open

Tichael wants to merge 3 commits into
mainfrom
feat/client-key-enrollment

Conversation

@Tichael

@Tichael Tichael commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

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.

  • Client key (lib/secure/client_key.dart): one X25519 key pair per install, made on first use, kept in flutter_secure_storage (Android Keystore), never in SharedPreferences. New dependencies: cryptography (pure Dart X25519/BLAKE2s/ChaCha20-Poly1305, also used by Secure channel session in the app #129), flutter_secure_storage, and device_info_plus for the label.
  • Device identity (lib/secure/device_identity.dart): only a 32-byte key whose key ID matches it is accepted. Pinned in PairedVehicleConfig (devicePublicKey, deviceKeyId), with the client key the device last accepted (enrolledClientKey), so unpairing forgets them.
  • Enrollment (clientKeyEnrollmentProvider): on each Bluetooth connection (and the debug HTTP transport), once the device reports the phone validated, it lists the paired phones and sends EnrollClientKey (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.
  • Identity change: a reported identity other than the pinned one is never pinned silently. The dashboard shows "The device has a new identity" with Unpair or Trust new identity (which pins it and enrolls again).
  • Paired phones: a phone with a key shows "Remote access set up (label)".
  • Generated constants: a new SecureChannelConstantsBuilder generates lib/secure/secure_channel_constants.g.dart from [secure_channel] in transport.toml, so the key ID length and label limit are imported, not copied.
  • Docs: 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

  • New 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-infos and the full flutter test pass.
  • Not run: a device build, or anything against a real controller. Locally, flutter test needed thermion_dart's native download skipped (blocked in my sandbox); that workaround is not committed.

Checklist

  • PR title uses conventional-commit style (feat:, fix:, docs:, chore:); CI validates it
  • dart format, flutter analyze --fatal-infos and flutter test pass
  • Docs (docs/ or README) updated if behaviour changed
  • No config.toml or credentials committed; generated files not hand-edited
  • If the wire format changed: the contracts PR is linked and the submodule bump is its own commit

Safety

  • This change does not touch BLE pairing/bonding or how commands are sent to the vehicle
  • It does (explain below)

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_id and vehicle commands are unchanged. The private key never leaves the phone.

https://claude.ai/code/session_01XkZEiWM4SEVB1xBTaoykRa


Generated by Claude Code

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
@Tichael Tichael self-assigned this Dec 1, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create the app's client key and enroll it after validation

2 participants