Fix retrieve ltk key with ediv and rand instead of role#890
Open
yannpoupon wants to merge 1 commit intogoogle:mainfrom
Open
Fix retrieve ltk key with ediv and rand instead of role#890yannpoupon wants to merge 1 commit intogoogle:mainfrom
yannpoupon wants to merge 1 commit intogoogle:mainfrom
Conversation
Collaborator
|
You're right, there's a bug here. I'll need to double check how the non-legacy pairing modes may be also affected, and follow up. |
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.
Fix: Incorrect LTK Retrieved on Reconnection Causing MIC Failures
Context
In my test I simulate a peripheral device that use legacy OOB :

And try to do a connection, disconnection and then a reconnection with a Central.
The first connection works without any issue, but the second connection fails with some MIC failure 100% of my test.
Problem
When a previously paired device reconnects and the controller requests the Long Term Key (LTK) via
HCI_LE_Long_Term_Key_Request_Event, Bumble was returning the wrong LTK key, resulting in connection termination with error code0x3D(Connection Terminated Due To MIC Failure).Root Cause
The bug occurred due to a mismatch between storage logic (based on pairing role) and retrieval logic (based on connection role):
Storage (smp.py:1376-1381):
is_initiator)ltk_central = our_ltk,ltk_peripheral = peer_ltkRetrieval (device.py - before fix):
connection.role)ltk_peripheral→ returned peer's LTKThe Issue:
In normal/expected scenarios where the central initiates pairing:
ltk_centralfieldltk_peripheralfieldDocumentation
The Peripheral may store the mapping between EDIV, Rand and LTK in a security database so the correct LTK value is used when the Central requests encryption.
Solution
Match LTKs using their cryptographic identifiers (EDIV + Rand) instead of relying on role-based field names:
I am not sure if the change is only valid for the legacy version or not.