Repository navigation
fix: keep a pending sign key across reconnects until the server accepts it - #52
Merged
Merged
Conversation
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
A station with an unreliable link can't be added. Seen on a v4 station (v3.5.5) behind micro-connector (ids and keys invented):
Every later submit goes the same way whenever the link drops between the submit and the approval.
Cause
#48 treated any mismatch while the key was pending as "the server never accepted it" and dropped the key. But before approval the server always signs with its old key, so a reconnect in that window is enough to throw the key away. The admin then accepts a key that no longer exists on the station.
Fix
A pending key survives reconnects until a handshake proves the server signs with it. The trust decision now lives in a pure function,
src/utils/trust.rs, with host tests.RandomSigned(server has no key for us)trust_serveris cleared explicitly0)NoKey)While a key waits for approval:
Addwith the same pending key; it does not make a new one. fix: let a station without a sign key be added again #45/fix: drop a sign key the server never accepted, so the station can be added again #48 andsim/scenarios/readd-sign-key.jsonshow why: a second key races the firstAdd. The backend dedupes an identical request and keeps only the latest request per device. If the admin rejected the request, it reappears in the panel.add_deviceno longer setstrust_serveron that resend, because this connection's handshake just saw another key.WsError::Recheck). The new handshake is signed with the accepted key, so the station becomes trusted and pending is cleared. The first settings of a connection never trigger this, so it can't loop. Any other device-list change costs a waiting station one reconnect.Power cycles. The pending flag was already in NVS (
SIGN_PENDING) and still is. After a reboot the request in the panel still waits for that same key, and a new key would just repeat the bug. After a reboot the session starts untrusted, and the approval push makes the station re-check, as above.No timeout. A timer that drops the key brings the bug back for any admin slower than the timer. Dropping also doesn't help any case it was meant for:
There is also no trustworthy clock at handshake time after a reboot, because
EpochTimearrives after the handshake. The way out stays Reset settings, which clears both NVS entries, so the next submit makes a fresh key (unchanged).auto_add. It followsadded. A station waiting for approval re-sends its pending key, and on a first connect (no key) it still makes a fresh key with optimistic trust, as before.Security. A station still never trusts a server that signs with a key it doesn't hold. The only optimistic trust left is the one that already existed right after a fresh
Addon the same connection.Testing
host-tests(trust_tests) cover every row of the table, the "not added while waiting" rule, the recheck rule (first settings vs later push), and the reported sequence end to end. All 51 tests pass.cargo fmt --check, clippy-D warningsfor v3, v4, v4+auto_addand the sim feature (SIM_CLIPPY=1 sim/run.sh), and release builds for v3 and v4.RequestToConnectDevicethe moment it arrives, so there is no window in which to reconnect before approval. A scenario would need a hold/approve command in the e2e control socket (micro-connector repo) first. esp-emu also isn't installed on the machine this was built on, so the existing scenarios weren't re-run either.readd-sign-key.jsonand a monkey run are worth running before merging.