Repository navigation
fix(remote): pair against the invitation the desktop is showing - #817
Merged
Merged
Conversation
A bridge generation rebuilt after the first invitation was minted (an
unscanned code, a NATS disconnect, suspend/resume) re-ran `establish()` and
minted a fresh invitation — new desktop NKey, new secure identity, new PSK —
for the same `pair_id`. `shared_runtime` reused the cached runtime for that
pair_id, and with it the cached `HandshakeState`, so the bridge kept offering
the *old* identity while the GUI showed the new QR. Every scan then failed
`secure_open` with `remote_secure_channel_invalid`; the phone folds that into
`desktop_handshake_failed` and shows PA005 ("update both apps"), and nothing on
either side logs why. Only stopping the bridge (which drops `bridge_shared`)
cleared it.
Reuse the cached runtime only while it still serves the invitation these
credentials describe, identified by the two public keys the phone
authenticates against (`desktopKey` and `secureKey`). A credential refresh
keeps both, so a rotated JWT still inherits its single-flight reply slots and
pairing confirmation; a re-minted invitation inherits neither, and the cached
identity is replaced rather than reused.
Regression: #554 cached the handshake state per `pair_id`; before it, every
generation built its `HandshakeState` from the credentials it had just
resolved, so the QR and the served identity could not diverge.
… app version Two follow-ups to the identity fix, both about the same gap: a pairing that cannot succeed was invisible and gave the wrong instruction. Desktop side. `secure::Transport::handshake` collapsed every refusal into the opaque `remote_secure_channel_invalid` and the command loop dropped it on the floor, so an expired invitation, an already-consumed one, a peer proving the wrong key, and an undecryptable open all looked identical — and when the phone sent no reply subject, nothing was reported anywhere at all. A refusal now carries its reason (`invitation_expired`, `invitation_already_used`, `peer_mismatch`, `open_undecryptable`, ...) after the unchanged `remote_secure_channel_invalid` prefix, reaches the desktop's stderr through the quota-limited `HANDSHAKE_EPISODE`, and is returned to the phone. The signature-challenge path names the field that disagreed instead of replying a bare `pairing_identity_mismatch`; a QR describing an identity the bridge no longer serves fails exactly there. Mobile side. The phone discarded the desktop's error and its handshake wrapper turned every outcome into `desktop_handshake_failed: ...`, which the screen then matched on the word "handshake". So a desktop that was simply unreachable told the user to update both apps. Timeouts now read as a network problem (NW001) and a refused handshake as "generate a new code on the desktop" (PA002); PA005 is left for what it actually means — the two builds cannot complete the handshake (`pairing_confirmation_mismatch`, a confirmation without `e2ee_v2`). The desktop's reason is appended to the stable `pairing_signature_invalid` token, which the credential classifier and connection presentation both match on, so it stays in the phone's console for support without changing either classification. Docs: the PA002 row now covers a refused handshake, and PA005 is narrowed to the protocol mismatch it is reserved for.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Scanning a valid, unexpired pairing QR from a current desktop failed with PA005 ("update both apps and scan again") — on both sides reporting nothing. Reproduced in a test, then bisected to #554.
establish()mints a fresh invitation (new desktop NKey, new secure identity, new PSK) whenever the pairing was never confirmed — an unscanned code, a NATS disconnect, suspend/resume. #554 madeshared_runtimecache the bridge identity perpair_id, so a rebuilt generation kept serving the old identity while the GUI displayed the new QR. Every scan then failedsecure_openwithremote_secure_channel_invalid; the phone folded that intodesktop_handshake_failed→ PA005, and neither side wrote anything to a log. Before #554 every generation builtHandshakeStatefrom the credentials it had just resolved, so the QR and the served identity could not diverge.Changes
desktopKeyandsecureKey). A credential refresh keeps both, so a rotated JWT still inherits its single-flight reply slots and pairing confirmation; a re-minted invitation inherits neither.Transport::handshakenow carries its reason (invitation_expired,invitation_already_used,peer_mismatch,open_undecryptable, …) after the byte-stableremote_secure_channel_invalidprefix; it reaches the desktop's stderr through the quota-limitedHANDSHAKE_EPISODEand is returned to the phone. The signature-challenge path names the field that disagreed rather than replying a barepairing_identity_mismatch.desktop_handshake_failedwrapper made the screen match on the word "handshake" — so an unreachable desktop told users to update both apps. Timeouts now read as a network problem (NW001), a refused handshake as "generate a new code on the desktop" (PA002), and PA005 is left for a genuine protocol mismatch. The desktop's reason is appended to the stablepairing_signature_invalidtoken so the credential classifier and connection presentation keep matching on it.Verification
cargo test --lib remote::— 173 passed (desktop/src-tauri), including two new end-to-end tests: a reissued code for the samepair_idnow pairs, with a control proving a newpair_idalone was never the trigger.cargo fmt --check,cargo clippy --all-targets -- -D warnings— clean.npx jest125 suites / 1907 tests,tsc --noEmit,eslint— clean. New test asserts the three outcomes produce three different actions.Docs: the PA002 support-code row now covers a refused handshake; PA005 is narrowed to the protocol mismatch it is reserved for.