fix legacy pairing with oob

This commit is contained in:
Gilles Boccon-Gibod
2025-06-23 07:05:21 +02:00
parent ebaa720e74
commit 1a05eebfdb
2 changed files with 20 additions and 10 deletions

View File

@@ -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

View File

@@ -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