Skip to content

feat(system): add the device identity, client key enrollment and the secure channel spec - #50

Open
Tichael wants to merge 1 commit into
mainfrom
feat/secure-channel-keys
Open

Tichael wants to merge 1 commit into
mainfrom
feat/secure-channel-keys

Conversation

@Tichael

@Tichael Tichael commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Requested by Michaël · project thread

What and why

Phase 1 of the epic #44 (keys and secure channel), contracts side. Closes #45 and #46 in one PR, since the firmware and the app need both to implement and test the channel.

#45, keys over BLE (system.proto, append-only):

  • DeviceIdentity { public_key, key_id }, reported in SystemState.device_identity (field 10, BLE only) and in SystemCommandResult.device_identity (field 5).
  • EnrollClientKeyCommand { public_key, kind, label } (SystemCommand field 14) and ClientKind (PHONE; HUB reserved and refused for now). BLE only, validated phone only, re-enrolling replaces the key; revocation is documented in the comments.
  • PairedPhone.remote_key_enrolled (4) and remote_key_label (5, so the phone list can show the label the issue mentions).
  • mqtt_client_id is not deprecated here, as the issue says (that comes with the relay).

#46, the channel spec: docs/secure-channel.md, a [secure_channel] section in transport.toml with its constants, docs/secure-channel-vectors.json, and the generator tools/secure_channel_vectors.py (Python noiseprotocol 0.3.1, run with python -I, deterministic output). README links the doc.

Choices the issue left open (please check)

  • Handshake payloads are empty in both messages. A message in message 1 would get neither forward secrecy nor replay protection, so messages only travel in transport frames. Cost: one round trip before the first command.
  • Unknown session: explicit frame type 5 (type + session ID, nothing else) answered to a transport frame for a session the device doesn't have. It is unauthenticated, so the client treats it as a hint and keeps its old session until a new handshake completes. It reveals nothing (session IDs are random) and is smaller than what triggered it.
  • Session limits: 4 sessions, 2 per client (LAN + relay), idle 300 s, lifetime 3600 s or 1,000,000 frames per direction, then the client re-handshakes (no in-session rekey). When full, the session idle the longest is replaced (the same client's first).
  • Replayed handshake inits: refused when their ephemeral key was seen recently for that client, so a replay can't take a slot.
  • Handshake timeout 10 s (LTE relay), label at most 32 UTF-8 bytes, empty plaintext = keepalive.
  • Prologue: opencar/secure/1 + 0x00 + the key ID in ASCII. Transport messages use empty associated data (the counter is the nonce, and each session has its own keys).

Checklist

  • PR title uses conventional-commit style
  • buf format, buf lint and buf breaking --against '.git#branch=main' pass
  • Append-only rules followed: new fields and messages appended, nothing renumbered or removed
  • BLE message size limit still respected (the identity adds 56 bytes to a system state update sent on its own)
  • Matching firmware and mobile-app changes exist or are linked: they follow (firmware#118/#119, mobile-app#128/#129) and will be linked here

Source of the data

The vectors come from the noiseprotocol reference implementation, with fixed static and ephemeral keys.


Generated by Claude Code

…secure channel spec

Adds the trust anchor and the contract of the end-to-end encrypted channel
(epic #44, phase 1):

- DeviceIdentity (X25519 public key and key ID) in SystemState and in the
  answer to the new EnrollClientKeyCommand, with ClientKind (HUB reserved).
- PairedPhone.remote_key_enrolled and remote_key_label.
- docs/secure-channel.md: Noise_IK_25519_ChaChaPoly_BLAKE2s, prologue, frame
  format, replay window, session rules, identity and authorization.
- [secure_channel] constants in transport.toml.
- docs/secure-channel-vectors.json and the script that generates them with
  the noiseprotocol reference implementation.

Closes #45
Closes #46

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
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Proto Check / check (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedDec 1, 2026, 1:21 AM

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.

Add the device identity key and client key enrollment over BLE

2 participants