fix(crypto): recover from undecryptable peer messages after identity resets #22

Merged
jmz merged 1 commit from maximus/fix/utd-recovery into main 2026-11-28 23:26:36 +00:00
Owner

Why

On 2026-11-14 Felinus's messages were undecryptable (UTD) on every Maximus bridge. Her bridge had reset its cross-signing identity; the new Megolm session it created did not include our device, and nothing on either side noticed. The workaround was manual: she deleted her outbound_group_session row so the next message re-shared the key.

Separately, running matrix-bridge-mcp --version to check the binary acquired the single-instance store lock and evicted the live bridge.

What

  • trust.rs: when a previously verified peer identity is replaced (verification violation), withdraw the old verification before pin() (pin alone leaves the violation set and keys keep being withheld). Peer devices are marked locally trusted. apply_trust_policy now returns whether any identity changed (tracked per user's master key, process-wide).
  • client.rs: on a reported change, discard our outbound room keys so the next message is re-shared under the new trust state. UTD events now log sender key, session id and device instead of a bare decryption error.
  • New recovery surface: MCP tool discard_room_key and CLI matrix-bridge discard-room-key <room>.
  • mcp_main.rs: --version / --help exit before touching the store lock.

Testing

  • cargo test --locked -j 1 --all-features on rpi5: all pass (debuginfo off to fit the linker under a memory cap).
  • cargo check --all: clean apart from the existing BridgeError::LoginFailed dead-code warning.
  • The UTD recovery itself is not unit-tested (it needs two homeserver identities); verify after deploy by having one bridge reset its identity and checking the other decrypts the next message without manual steps.

Notes

  • cargo fmt was applied to the six touched files only. The base branch isn't rustfmt-clean under rustfmt 1.9, so some hunks in those files are formatting only. CI doesn't check fmt.
  • Deploy: rebuilding/replacing the running bridge evicts the live session (single-instance lock). Do it when no agent is mid-conversation; all bridges must be redeployed for the both-sides trust policy to apply.

🤖 Generated with Claude Code

## Why On 2026-11-14 Felinus's messages were undecryptable (UTD) on every Maximus bridge. Her bridge had reset its cross-signing identity; the new Megolm session it created did not include our device, and nothing on either side noticed. The workaround was manual: she deleted her `outbound_group_session` row so the next message re-shared the key. Separately, running `matrix-bridge-mcp --version` to check the binary acquired the single-instance store lock and evicted the live bridge. ## What - **trust.rs**: when a previously *verified* peer identity is replaced (verification violation), withdraw the old verification before `pin()` (pin alone leaves the violation set and keys keep being withheld). Peer devices are marked locally trusted. `apply_trust_policy` now returns whether any identity changed (tracked per user's master key, process-wide). - **client.rs**: on a reported change, discard our outbound room keys so the next message is re-shared under the new trust state. UTD events now log sender key, session id and device instead of a bare decryption error. - **New recovery surface**: MCP tool `discard_room_key` and CLI `matrix-bridge discard-room-key <room>`. - **mcp_main.rs**: `--version` / `--help` exit before touching the store lock. ## Testing - `cargo test --locked -j 1 --all-features` on rpi5: all pass (debuginfo off to fit the linker under a memory cap). - `cargo check --all`: clean apart from the existing `BridgeError::LoginFailed` dead-code warning. - The UTD recovery itself is not unit-tested (it needs two homeserver identities); verify after deploy by having one bridge reset its identity and checking the other decrypts the next message without manual steps. ## Notes - `cargo fmt` was applied to the six touched files only. The base branch isn't rustfmt-clean under rustfmt 1.9, so some hunks in those files are formatting only. CI doesn't check fmt. - **Deploy**: rebuilding/replacing the running bridge evicts the live session (single-instance lock). Do it when no agent is mid-conversation; all bridges must be redeployed for the both-sides trust policy to apply. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fix(crypto): recover from undecryptable peer messages after identity resets
All checks were successful
check / check (pull_request) Successful in 6m43s
2f3223dc30
On 2026-11-14 a peer reset its cross-signing identity; its new Megolm
session silently excluded our device, so every message from it was a UTD
until the peer deleted its outbound group session by hand.

- trust: when a previously verified identity was replaced (verification
  violation), withdraw the old verification before pinning; mark peer
  devices locally trusted; report whether any identity changed.
- client: on a reported change, discard our outbound room keys so the next
  message is re-shared under the new trust state; log session diagnostics
  for UTD events (sender key, session id, device) instead of a bare error.
- new `discard_room_key` MCP tool and `matrix-bridge discard-room-key` CLI
  subcommand for manual recovery.
- mcp: `--version` / `--help` exit before acquiring the single-instance
  store lock, so a probe no longer evicts the running bridge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
jmz force-pushed maximus/fix/utd-recovery from 2f3223dc30
All checks were successful
check / check (pull_request) Successful in 6m43s
to d3d40faa11
All checks were successful
check / check (pull_request) Successful in 3m53s
2026-11-28 11:18:56 +00:00
Compare
jmz merged commit d3d40faa11 into main 2026-11-28 23:26:36 +00:00
jmz deleted branch maximus/fix/utd-recovery 2026-11-28 23:26:36 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
public/matrix-bridge!22
No description provided.