From a378498fdc6e99c28525afe2152676a3a5f216f1 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Mon, 12 Aug 2019 16:02:19 +0200 Subject: [PATCH] Bluetooth: SMP: Add option to treat debug keys normally during debugging Allow SMP debug keys to behave in the same way as normal keys, in order to debug with encryption and Bluetooth sniffer the exact way it behaves when not using debug keys. Signed-off-by: Joakim Andersson --- subsys/bluetooth/host/Kconfig | 7 +++++++ subsys/bluetooth/host/smp.c | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index 89c95634b8f..15b32b44f77 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -305,6 +305,13 @@ config BT_BONDABLE Bonding flag in AuthReq of SMP Pairing Request/Response will be set indicating the support for this mode. +config BT_STORE_DEBUG_KEYS + bool "Store Debug Mode bonds" + help + This option enables support for storing bonds where either of devices + has the Security Manager in Debug mode. This option should + only be enabled for debugging and should never be used in production. + config BT_SMP_ENFORCE_MITM bool "Enforce MITM protection" default y diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index f2e08160c7d..b5da4a404da 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -1540,7 +1540,8 @@ static void smp_pairing_complete(struct bt_smp *smp, u8_t status) * TODO should we allow this if BR/EDR is already connected? */ if (atomic_test_bit(smp->flags, SMP_FLAG_DERIVE_LK) && - !atomic_test_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY)) { + (!atomic_test_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY) || + IS_ENABLED(CONFIG_BT_STORE_DEBUG_KEYS))) { sc_derive_link_key(smp); } #endif /* CONFIG_BT_BREDR */ @@ -3795,7 +3796,8 @@ static void bt_smp_disconnected(struct bt_l2cap_chan *chan) * If debug keys were used for pairing remove them. * No keys indicate no bonding so free keys storage. */ - if (!keys->keys || (keys->flags & BT_KEYS_DEBUG)) { + if (!keys->keys || (!IS_ENABLED(CONFIG_BT_STORE_DEBUG_KEYS) && + (keys->flags & BT_KEYS_DEBUG))) { bt_keys_clear(keys); } }