From 1a05eebfdb8bab8bfe6a742107214054abd586be Mon Sep 17 00:00:00 2001 From: Gilles Boccon-Gibod Date: Mon, 23 Jun 2025 07:05:21 +0200 Subject: [PATCH] fix legacy pairing with oob --- apps/pair.py | 26 +++++++++++++++++--------- bumble/smp.py | 4 +++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/pair.py b/apps/pair.py index 13dc06d..9567e19 100644 --- a/apps/pair.py +++ b/apps/pair.py @@ -402,14 +402,19 @@ async def pair( # Create an OOB context if needed if oob: our_oob_context = OobContext() - shared_data = ( - None - if oob == '-' - else OobData.from_ad( + if oob == '-': + shared_data = None + legacy_context = OobLegacyContext() + else: + oob_data = OobData.from_ad( AdvertisingData.from_bytes(bytes.fromhex(oob)) - ).shared_data - ) - legacy_context = OobLegacyContext() + ) + shared_data = oob_data.shared_data + legacy_context = oob_data.legacy_context + if legacy_context is None and not sc: + print(color('OOB pairing in legacy mode requires TK', 'red')) + return + oob_contexts = PairingConfig.OobConfig( our_context=our_oob_context, peer_data=shared_data, @@ -419,7 +424,9 @@ async def pair( print(color('@@@ OOB Data:', 'yellow')) if shared_data is None: oob_data = OobData( - address=device.random_address, shared_data=our_oob_context.share() + address=device.random_address, + shared_data=our_oob_context.share(), + legacy_context=(None if sc else legacy_context), ) print( color( @@ -427,7 +434,8 @@ async def pair( 'yellow', ) ) - print(color(f'@@@ TK={legacy_context.tk.hex()}', 'yellow')) + if legacy_context: + print(color(f'@@@ TK={legacy_context.tk.hex()}', 'yellow')) print(color('@@@-----------------------------------', 'yellow')) else: oob_contexts = None diff --git a/bumble/smp.py b/bumble/smp.py index 4a2f710..bf4b257 100644 --- a/bumble/smp.py +++ b/bumble/smp.py @@ -762,7 +762,9 @@ class Session: # OOB self.oob_data_flag = ( - 1 if pairing_config.oob and pairing_config.oob.peer_data else 0 + 1 + if pairing_config.oob and (not self.sc or pairing_config.oob.peer_data) + else 0 ) # Set up addresses