mirror of
https://github.com/google/bumble.git
synced 2026-04-16 00:25:31 +00:00
Merge pull request #905 from markusjellitsch/feature/debug-keys
Feature - Add SMP Debug Mode (Core Vol.3, Part H)
This commit is contained in:
@@ -2159,6 +2159,7 @@ class DeviceConfiguration:
|
|||||||
)
|
)
|
||||||
eatt_enabled: bool = False
|
eatt_enabled: bool = False
|
||||||
gatt_services: list[dict[str, Any]] = field(init=False)
|
gatt_services: list[dict[str, Any]] = field(init=False)
|
||||||
|
smp_debug_mode: bool = False
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
self.gatt_services = []
|
self.gatt_services = []
|
||||||
@@ -2571,6 +2572,7 @@ class Device(utils.CompositeEventEmitter):
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
self.smp_manager.debug_mode = self.config.smp_debug_mode
|
||||||
|
|
||||||
self.l2cap_channel_manager.register_fixed_channel(smp.SMP_CID, self.on_smp_pdu)
|
self.l2cap_channel_manager.register_fixed_channel(smp.SMP_CID, self.on_smp_pdu)
|
||||||
|
|
||||||
|
|||||||
@@ -178,6 +178,16 @@ class AuthReq(hci.SpecableFlag):
|
|||||||
SMP_CTKD_H7_LEBR_SALT = bytes.fromhex('000000000000000000000000746D7031')
|
SMP_CTKD_H7_LEBR_SALT = bytes.fromhex('000000000000000000000000746D7031')
|
||||||
SMP_CTKD_H7_BRLE_SALT = bytes.fromhex('000000000000000000000000746D7032')
|
SMP_CTKD_H7_BRLE_SALT = bytes.fromhex('000000000000000000000000746D7032')
|
||||||
|
|
||||||
|
# Diffie-Hellman private / public key pair in Debug Mode (Core - Vol. 3, Part H)
|
||||||
|
SMP_DEBUG_KEY_PRIVATE = bytes.fromhex(
|
||||||
|
'3f49f6d4 a3c55f38 74c9b3e3 d2103f50 4aff607b eb40b799 5899b8a6 cd3c1abd'
|
||||||
|
)
|
||||||
|
SMP_DEBUG_KEY_PUBLIC_X = bytes.fromhex(
|
||||||
|
'20b003d2 f297be2c 5e2c83a7 e9f9a5b9 eff49111 acf4fddb cc030148 0e359de6'
|
||||||
|
)
|
||||||
|
SMP_DEBUG_KEY_PUBLIC_Y= bytes.fromhex(
|
||||||
|
'dc809c49 652aeb6d 63329abf 5a52155c 766345c2 8fed3024 741c8ed0 1589d28b'
|
||||||
|
)
|
||||||
# fmt: on
|
# fmt: on
|
||||||
# pylint: enable=line-too-long
|
# pylint: enable=line-too-long
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
@@ -1919,6 +1929,7 @@ class Manager(utils.EventEmitter):
|
|||||||
self._ecc_key = None
|
self._ecc_key = None
|
||||||
self.pairing_config_factory = pairing_config_factory
|
self.pairing_config_factory = pairing_config_factory
|
||||||
self.session_proxy = Session
|
self.session_proxy = Session
|
||||||
|
self.debug_mode = False
|
||||||
|
|
||||||
def send_command(self, connection: Connection, command: SMP_Command) -> None:
|
def send_command(self, connection: Connection, command: SMP_Command) -> None:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
@@ -1965,6 +1976,13 @@ class Manager(utils.EventEmitter):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def ecc_key(self) -> crypto.EccKey:
|
def ecc_key(self) -> crypto.EccKey:
|
||||||
|
if self.debug_mode:
|
||||||
|
# Core - Vol 3, Part H:
|
||||||
|
# When the Security Manager is placed in a Debug mode it shall use the
|
||||||
|
# following Diffie-Hellman private / public key pair:
|
||||||
|
debug_key = crypto.EccKey.from_private_key_bytes(SMP_DEBUG_KEY_PRIVATE)
|
||||||
|
return debug_key
|
||||||
|
|
||||||
if self._ecc_key is None:
|
if self._ecc_key is None:
|
||||||
self._ecc_key = crypto.EccKey.generate()
|
self._ecc_key = crypto.EccKey.generate()
|
||||||
assert self._ecc_key
|
assert self._ecc_key
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import pytest
|
|||||||
from bumble import crypto, pairing, smp
|
from bumble import crypto, pairing, smp
|
||||||
from bumble.core import AdvertisingData
|
from bumble.core import AdvertisingData
|
||||||
from bumble.crypto import EccKey, aes_cmac, ah, c1, f4, f5, f6, g2, h6, h7, s1
|
from bumble.crypto import EccKey, aes_cmac, ah, c1, f4, f5, f6, g2, h6, h7, s1
|
||||||
from bumble.device import Device
|
from bumble.device import Device, DeviceConfiguration
|
||||||
from bumble.hci import Address
|
from bumble.hci import Address
|
||||||
from bumble.pairing import LeRole, OobData, OobSharedData
|
from bumble.pairing import LeRole, OobData, OobSharedData
|
||||||
|
|
||||||
@@ -312,3 +312,17 @@ async def test_send_identity_address_command(
|
|||||||
actual_command = mock_method.call_args.args[0]
|
actual_command = mock_method.call_args.args[0]
|
||||||
assert actual_command.addr_type == expected_identity_address.address_type
|
assert actual_command.addr_type == expected_identity_address.address_type
|
||||||
assert actual_command.bd_addr == expected_identity_address
|
assert actual_command.bd_addr == expected_identity_address
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_smp_debug_mode():
|
||||||
|
config = DeviceConfiguration(smp_debug_mode=True)
|
||||||
|
device = Device(config=config)
|
||||||
|
|
||||||
|
assert device.smp_manager.ecc_key.x == smp.SMP_DEBUG_KEY_PUBLIC_X
|
||||||
|
assert device.smp_manager.ecc_key.y == smp.SMP_DEBUG_KEY_PUBLIC_Y
|
||||||
|
|
||||||
|
device.smp_manager.debug_mode = False
|
||||||
|
|
||||||
|
assert not device.smp_manager.ecc_key.x == smp.SMP_DEBUG_KEY_PUBLIC_X
|
||||||
|
assert not device.smp_manager.ecc_key.y == smp.SMP_DEBUG_KEY_PUBLIC_Y
|
||||||
|
|||||||
Reference in New Issue
Block a user