fix: verify the device's mutual-auth server proof (M8)#103
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
eaa328b to
f66e009
Compare
Firmware computes CMAC(session_key, server_nonce||client_nonce||device_id) precisely so the client can authenticate the device, but authenticate() discarded the 16-byte proof returned by parse_authenticate_success(). A device (or MITM) that returned status OK without knowing the master key was accepted, deferring detection to the first encrypted exchange. Recompute the proof from the derived session key and constant-time-compare it (hmac.compare_digest), raising AuthenticationFailedError on mismatch before storing the session. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRrm95f1qNZzDM9r2SB6KW
f66e009 to
ba89249
Compare
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.
Summary
M8 — server proof never verified; mutual auth was one-way (🟠)
The firmware computes
CMAC(session_key, server_nonce ‖ client_nonce ‖ device_id)precisely so the client can authenticate the device. Butauthenticate()calledparse_authenticate_success()(which returns the 16-byte proof) and discarded the return value. A device — or a MITM — that returned status0x00without knowing the master key was accepted, deferring detection to the first encrypted exchange.Fix
Add
compute_server_proof(session_key, server_nonce, client_nonce, device_id)and, inauthenticate(), recompute the proof from the derived session key and constant-time-compare it (hmac.compare_digest), raisingAuthenticationFailedErroron mismatch before storing the session state.Test plan
uv run pytest -q→ 445 passed (2 new end-to-end tests: valid proof accepted, bogus proof rejected with no session stored)ruff,mypyclean🤖 Generated with Claude Code