Skip to content

Commit

Permalink
Add maximum encryption key size to PairingDelegate
Browse files Browse the repository at this point in the history
So far the maxmium encryption key size has been hardcoded to 16 bytes in
'send_pairing_request_command()' and 'send_pairing_response_comman()'. By
making this configurable via the PairingDelegate, one can test how devices
respond to smaller encryption key sizes. Default remains 16 bytes.
  • Loading branch information
jmdietrich-gcx committed Nov 28, 2024
1 parent 082d55a commit 07f9997
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions bumble/pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,19 @@ class KeyDistribution(enum.IntFlag):
io_capability: IoCapability
local_initiator_key_distribution: KeyDistribution
local_responder_key_distribution: KeyDistribution
maximum_encryption_key_size: int

def __init__(
self,
io_capability: IoCapability = NO_OUTPUT_NO_INPUT,
local_initiator_key_distribution: KeyDistribution = DEFAULT_KEY_DISTRIBUTION,
local_responder_key_distribution: KeyDistribution = DEFAULT_KEY_DISTRIBUTION,
maximum_encryption_key_size: int = 16
) -> None:
self.io_capability = io_capability
self.local_initiator_key_distribution = local_initiator_key_distribution
self.local_responder_key_distribution = local_responder_key_distribution
self.maximum_encryption_key_size = maximum_encryption_key_size

@property
def classic_io_capability(self) -> int:
Expand Down
9 changes: 7 additions & 2 deletions bumble/smp.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ def __init__(
self.ltk_ediv = 0
self.ltk_rand = bytes(8)
self.link_key: Optional[bytes] = None
self.maximum_encryption_key_size: int = 0
self.initiator_key_distribution: int = 0
self.responder_key_distribution: int = 0
self.peer_random_value: Optional[bytes] = None
Expand Down Expand Up @@ -741,6 +742,10 @@ def __init__(
else:
self.pairing_result = None

self.maximum_encryption_key_size = (
pairing_config.delegate.maximum_encryption_key_size
)

# Key Distribution (default values before negotiation)
self.initiator_key_distribution = (
pairing_config.delegate.local_initiator_key_distribution
Expand Down Expand Up @@ -993,7 +998,7 @@ def send_pairing_request_command(self) -> None:
io_capability=self.io_capability,
oob_data_flag=self.oob_data_flag,
auth_req=self.auth_req,
maximum_encryption_key_size=16,
maximum_encryption_key_size=self.maximum_encryption_key_size,
initiator_key_distribution=self.initiator_key_distribution,
responder_key_distribution=self.responder_key_distribution,
)
Expand All @@ -1005,7 +1010,7 @@ def send_pairing_response_command(self) -> None:
io_capability=self.io_capability,
oob_data_flag=self.oob_data_flag,
auth_req=self.auth_req,
maximum_encryption_key_size=16,
maximum_encryption_key_size=self.maximum_encryption_key_size,
initiator_key_distribution=self.initiator_key_distribution,
responder_key_distribution=self.responder_key_distribution,
)
Expand Down

0 comments on commit 07f9997

Please sign in to comment.