From bf22fa697b5c5f0aa8ad9600f4930ec19ed14191 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Wed, 26 Mar 2025 14:14:33 +0100 Subject: [PATCH] Bluetooth: Mesh: remove device key candidate Commit removes device key candidate if provisionee failed during device key refresh procedure or mesh reset has been called in between. Otherwise, device key candidate gets stuck in the internal trusted storage of crypto library. Signed-off-by: Aleksandr Khromykh --- subsys/bluetooth/mesh/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subsys/bluetooth/mesh/main.c b/subsys/bluetooth/mesh/main.c index e29fd87adc5..16e66532058 100644 --- a/subsys/bluetooth/mesh/main.c +++ b/subsys/bluetooth/mesh/main.c @@ -237,6 +237,8 @@ void bt_mesh_dev_key_cand_remove(void) } LOG_DBG(""); + bt_mesh_key_destroy(&bt_mesh.dev_key_cand); + memset(&bt_mesh.dev_key_cand, 0, sizeof(struct bt_mesh_key)); if (IS_ENABLED(CONFIG_BT_SETTINGS)) { bt_mesh_net_dev_key_cand_store(); @@ -398,6 +400,10 @@ void bt_mesh_reset(void) bt_mesh_key_destroy(&bt_mesh.dev_key); memset(&bt_mesh.dev_key, 0, sizeof(bt_mesh.dev_key)); + if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV)) { + bt_mesh_dev_key_cand_remove(); + } + bt_mesh_beacon_disable(); bt_mesh_comp_unprovision();