Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DH Key compute check modification for OOB Pairing #526

Merged
merged 7 commits into from
Aug 29, 2024
27 changes: 23 additions & 4 deletions bumble/smp.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,9 @@ def __init__(
self.peer_io_capability = SMP_NO_INPUT_NO_OUTPUT_IO_CAPABILITY

# OOB
self.oob_data_flag = 0 if pairing_config.oob is None else 1
self.oob_data_flag = (
1 if pairing_config.oob and pairing_config.oob.peer_data else 0
)

# Set up addresses
self_address = connection.self_resolvable_address or connection.self_address
Expand Down Expand Up @@ -1014,8 +1016,10 @@ def send_pairing_response_command(self) -> None:
self.send_command(response)

def send_pairing_confirm_command(self) -> None:
self.r = crypto.r()
logger.debug(f'generated random: {self.r.hex()}')

if self.pairing_method != PairingMethod.OOB:
self.r = crypto.r()
logger.debug(f'generated random: {self.r.hex()}')

if self.sc:

Expand Down Expand Up @@ -1727,14 +1731,29 @@ def on_smp_pairing_random_command_secure_connections(
if self.pairing_method in (
PairingMethod.JUST_WORKS,
PairingMethod.NUMERIC_COMPARISON,
PairingMethod.OOB,
):
ra = bytes(16)
rb = ra
elif self.pairing_method == PairingMethod.PASSKEY:
assert self.passkey
ra = self.passkey.to_bytes(16, byteorder='little')
rb = ra
elif self.pairing_method == PairingMethod.OOB:
if self.is_initiator:
if self.peer_oob_data:
rb = self.peer_oob_data.r
ra = self.r
else:
rb = bytes(16)
ra = self.r
else:
if self.peer_oob_data:
ra = self.peer_oob_data.r
rb = self.r
else:
ra = bytes(16)
rb = self.r

else:
return

Expand Down
Loading