From b3481956b77097737052637120964655884a6683 Mon Sep 17 00:00:00 2001 From: Yann poupon Date: Fri, 13 Feb 2026 10:23:16 +0100 Subject: [PATCH 1/2] fix: retrieve ltk key with ediv and rand instead of role --- bumble/device.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bumble/device.py b/bumble/device.py index dbaeb52e..0b08a675 100644 --- a/bumble/device.py +++ b/bumble/device.py @@ -4836,11 +4836,13 @@ async def get_long_term_key( if keys.ltk: return keys.ltk.value - if connection.role == hci.Role.CENTRAL and keys.ltk_central: - return keys.ltk_central.value + # Check both ltk_central and ltk_peripheral by matching EDIV+Rand + if keys.ltk_central and keys.ltk_central.ediv == ediv and keys.ltk_central.rand == rand: + return keys.ltk_central.value + + if keys.ltk_peripheral and keys.ltk_peripheral.ediv == ediv and keys.ltk_peripheral.rand == rand: + return keys.ltk_peripheral.value - if connection.role == hci.Role.PERIPHERAL and keys.ltk_peripheral: - return keys.ltk_peripheral.value return None async def get_link_key(self, address: hci.Address) -> bytes | None: From 38da62cc88f7af66168b70d7261ccafbb71b872d Mon Sep 17 00:00:00 2001 From: Yann poupon Date: Tue, 17 Feb 2026 08:46:58 +0100 Subject: [PATCH 2/2] chore: apply black on file --- bumble/device.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bumble/device.py b/bumble/device.py index 0b08a675..2184378a 100644 --- a/bumble/device.py +++ b/bumble/device.py @@ -4837,10 +4837,18 @@ async def get_long_term_key( return keys.ltk.value # Check both ltk_central and ltk_peripheral by matching EDIV+Rand - if keys.ltk_central and keys.ltk_central.ediv == ediv and keys.ltk_central.rand == rand: + if ( + keys.ltk_central + and keys.ltk_central.ediv == ediv + and keys.ltk_central.rand == rand + ): return keys.ltk_central.value - if keys.ltk_peripheral and keys.ltk_peripheral.ediv == ediv and keys.ltk_peripheral.rand == rand: + if ( + keys.ltk_peripheral + and keys.ltk_peripheral.ediv == ediv + and keys.ltk_peripheral.rand == rand + ): return keys.ltk_peripheral.value return None