From 619b32d36e495c6b57723e5efee284a0ee20625d Mon Sep 17 00:00:00 2001 From: Gopi Sakshihally Bhuthaiah Date: Thu, 8 Aug 2024 07:53:05 +0000 Subject: [PATCH 1/7] DH Key compute check modification for OOB Pairing --- bumble/smp.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/bumble/smp.py b/bumble/smp.py index 9eba42d..0255350 100644 --- a/bumble/smp.py +++ b/bumble/smp.py @@ -764,7 +764,7 @@ class Session: 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 = 0 if pairing_config.oob.peer_data is None else 1 # Set up addresses self_address = connection.self_resolvable_address or connection.self_address @@ -791,7 +791,7 @@ class Session: raise InvalidArgumentError( "oob pairing config requires a context when sc is True" ) - self.r = pairing_config.oob.our_context.r + self.local_oob_r = pairing_config.oob.our_context.r self.ecc_key = pairing_config.oob.our_context.ecc_key if pairing_config.oob.legacy_context is not None: self.tk = pairing_config.oob.legacy_context.tk @@ -800,12 +800,12 @@ class Session: raise InvalidArgumentError( "oob pairing config requires a legacy context when sc is False" ) - self.r = bytes(16) + self.local_oob_r = bytes(16) self.ecc_key = manager.ecc_key self.tk = pairing_config.oob.legacy_context.tk else: self.peer_oob_data = None - self.r = bytes(16) + self.local_oob_r = bytes(16) self.ecc_key = manager.ecc_key self.tk = bytes(16) @@ -1457,7 +1457,7 @@ class Session: return if command.oob_data_flag == 0: # The peer doesn't have OOB data, use r=0 - self.r = bytes(16) + self.local_oob_r = bytes(16) else: # Decide which pairing method to use from the IO capability self.decide_pairing_method( @@ -1527,7 +1527,7 @@ class Session: return if command.oob_data_flag == 0: # The peer doesn't have OOB data, use r=0 - self.r = bytes(16) + self.local_oob_r = bytes(16) else: # Decide which pairing method to use from the IO capability self.decide_pairing_method( @@ -1727,7 +1727,6 @@ class Session: if self.pairing_method in ( PairingMethod.JUST_WORKS, PairingMethod.NUMERIC_COMPARISON, - PairingMethod.OOB, ): ra = bytes(16) rb = ra @@ -1735,6 +1734,12 @@ class Session: assert self.passkey ra = self.passkey.to_bytes(16, byteorder='little') rb = ra + elif self.pairing_method == PairingMethod.OOB: + if self.peer_oob_data: + ra = self.peer_oob_data.r + else: + ra = bytes(16) + rb = self.local_oob_r else: return From 29e4a843dfb98f6a648a62b93648d85331d2b2d3 Mon Sep 17 00:00:00 2001 From: Gopi Sakshihally Bhuthaiah Date: Thu, 8 Aug 2024 08:45:15 +0000 Subject: [PATCH 2/7] DH Key compute check modification for OOB Pairing --- bumble/smp.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/bumble/smp.py b/bumble/smp.py index 0255350..7b910d1 100644 --- a/bumble/smp.py +++ b/bumble/smp.py @@ -791,7 +791,7 @@ class Session: raise InvalidArgumentError( "oob pairing config requires a context when sc is True" ) - self.local_oob_r = pairing_config.oob.our_context.r + self.r = pairing_config.oob.our_context.r self.ecc_key = pairing_config.oob.our_context.ecc_key if pairing_config.oob.legacy_context is not None: self.tk = pairing_config.oob.legacy_context.tk @@ -800,12 +800,12 @@ class Session: raise InvalidArgumentError( "oob pairing config requires a legacy context when sc is False" ) - self.local_oob_r = bytes(16) + self.r = bytes(16) self.ecc_key = manager.ecc_key self.tk = pairing_config.oob.legacy_context.tk else: self.peer_oob_data = None - self.local_oob_r = bytes(16) + self.r = bytes(16) self.ecc_key = manager.ecc_key self.tk = bytes(16) @@ -1014,8 +1014,10 @@ class Session: 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: @@ -1457,7 +1459,7 @@ class Session: return if command.oob_data_flag == 0: # The peer doesn't have OOB data, use r=0 - self.local_oob_r = bytes(16) + self.r = bytes(16) else: # Decide which pairing method to use from the IO capability self.decide_pairing_method( @@ -1527,7 +1529,7 @@ class Session: return if command.oob_data_flag == 0: # The peer doesn't have OOB data, use r=0 - self.local_oob_r = bytes(16) + self.r = bytes(16) else: # Decide which pairing method to use from the IO capability self.decide_pairing_method( @@ -1739,7 +1741,7 @@ class Session: ra = self.peer_oob_data.r else: ra = bytes(16) - rb = self.local_oob_r + rb = self.r else: return From b164524380ca15735b37bdc81f6c72fbbd275185 Mon Sep 17 00:00:00 2001 From: Gopi Sakshihally Bhuthaiah Date: Thu, 8 Aug 2024 08:45:15 +0000 Subject: [PATCH 3/7] DH Key compute check modification for OOB Pairing --- bumble/smp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bumble/smp.py b/bumble/smp.py index 7b910d1..3580937 100644 --- a/bumble/smp.py +++ b/bumble/smp.py @@ -764,7 +764,11 @@ class Session: self.peer_io_capability = SMP_NO_INPUT_NO_OUTPUT_IO_CAPABILITY # OOB - self.oob_data_flag = 0 if pairing_config.oob.peer_data is None else 1 + self.oob_data_flag = 0 + if pairing_config.oob is not None: + if pairing_config.oob.peer_data is not None: + self.oob_data_flag = 1 + # Set up addresses self_address = connection.self_resolvable_address or connection.self_address From ed00d44ae136257118671a341e2c9439e049ba63 Mon Sep 17 00:00:00 2001 From: Gopi Sakshihally Bhuthaiah Date: Thu, 8 Aug 2024 08:45:15 +0000 Subject: [PATCH 4/7] DH Key compute check modification for OOB Pairing --- bumble/smp.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bumble/smp.py b/bumble/smp.py index 3580937..212489b 100644 --- a/bumble/smp.py +++ b/bumble/smp.py @@ -764,11 +764,7 @@ class Session: self.peer_io_capability = SMP_NO_INPUT_NO_OUTPUT_IO_CAPABILITY # OOB - self.oob_data_flag = 0 - if pairing_config.oob is not None: - if pairing_config.oob.peer_data is not None: - self.oob_data_flag = 1 - + self.oob_data_flag = 1 if pairing.oob and pairing_config.oob.peer_data else 0 # Set up addresses self_address = connection.self_resolvable_address or connection.self_address From 414f2f3efbd4b201b292b5200161d7823d2e6cd6 Mon Sep 17 00:00:00 2001 From: Gopi Sakshihally Bhuthaiah Date: Thu, 8 Aug 2024 08:45:15 +0000 Subject: [PATCH 5/7] DH Key compute check modification for OOB Pairing --- bumble/smp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumble/smp.py b/bumble/smp.py index 212489b..6a8af40 100644 --- a/bumble/smp.py +++ b/bumble/smp.py @@ -764,7 +764,7 @@ class Session: self.peer_io_capability = SMP_NO_INPUT_NO_OUTPUT_IO_CAPABILITY # OOB - self.oob_data_flag = 1 if pairing.oob and pairing_config.oob.peer_data else 0 + 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 From c44c89cc6ecaf4135d49dbd7507af808a0d05998 Mon Sep 17 00:00:00 2001 From: Gopi Sakshihally Bhuthaiah Date: Thu, 8 Aug 2024 08:45:15 +0000 Subject: [PATCH 6/7] DH Key compute check modification for OOB Pairing --- bumble/smp.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bumble/smp.py b/bumble/smp.py index 6a8af40..152f916 100644 --- a/bumble/smp.py +++ b/bumble/smp.py @@ -764,7 +764,9 @@ class Session: self.peer_io_capability = SMP_NO_INPUT_NO_OUTPUT_IO_CAPABILITY # OOB - self.oob_data_flag = 1 if pairing_config.oob and pairing_config.oob.peer_data else 0 + 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 From 0c9fd64434ecdcce6f5beee0adaba0141b61d5ee Mon Sep 17 00:00:00 2001 From: Gopi Sakshihally Bhuthaiah Date: Thu, 8 Aug 2024 08:45:15 +0000 Subject: [PATCH 7/7] DH Key compute check modification for OOB Pairing --- bumble/smp.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/bumble/smp.py b/bumble/smp.py index 152f916..8e92ff6 100644 --- a/bumble/smp.py +++ b/bumble/smp.py @@ -1739,11 +1739,21 @@ class Session: ra = self.passkey.to_bytes(16, byteorder='little') rb = ra elif self.pairing_method == PairingMethod.OOB: - if self.peer_oob_data: - ra = self.peer_oob_data.r + 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: - ra = bytes(16) - rb = self.r + if self.peer_oob_data: + ra = self.peer_oob_data.r + rb = self.r + else: + ra = bytes(16) + rb = self.r + else: return