Skip to content

Commit 2761887

Browse files
Johan Hedbergnashif
authored andcommitted
Bluetooth: SMP: Make public key handling more robust
Update code to handle other users of the public key generation APIs by fetching the current public key at the beginning of each SMP session. This is particularly important if someone creates the (rather odd) combination of Mesh and SMP where Mesh will regenerate a new key pair after provisioning. Signed-off-by: Johan Hedberg <[email protected]>
1 parent de50834 commit 2761887

File tree

1 file changed

+8
-9
lines changed
  • subsys/bluetooth/host

1 file changed

+8
-9
lines changed

subsys/bluetooth/host/smp.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ static struct bt_smp_br bt_smp_br_pool[CONFIG_BT_MAX_CONN];
252252
static struct bt_smp bt_smp_pool[CONFIG_BT_MAX_CONN];
253253
static bool bondable = IS_ENABLED(CONFIG_BT_BONDABLE);
254254
static bool sc_supported;
255-
static bool sc_local_pkey_valid;
256-
static u8_t sc_public_key[64];
255+
static const u8_t *sc_public_key;
257256

258257
static u8_t get_io_capa(void)
259258
{
@@ -2267,6 +2266,8 @@ static int smp_init(struct bt_smp *smp)
22672266

22682267
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_FAIL);
22692268

2269+
sc_public_key = bt_pub_key_get();
2270+
22702271
return 0;
22712272
}
22722273

@@ -2634,7 +2635,7 @@ static u8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
26342635
return 0;
26352636
}
26362637

2637-
if (!sc_local_pkey_valid) {
2638+
if (!sc_public_key) {
26382639
atomic_set_bit(smp->flags, SMP_FLAG_PKEY_SEND);
26392640
return 0;
26402641
}
@@ -3401,7 +3402,7 @@ static u8_t smp_public_key(struct bt_smp *smp, struct net_buf *buf)
34013402
}
34023403

34033404
#if defined(CONFIG_BT_PERIPHERAL)
3404-
if (!sc_local_pkey_valid) {
3405+
if (!sc_public_key) {
34053406
atomic_set_bit(smp->flags, SMP_FLAG_PKEY_SEND);
34063407
return 0;
34073408
}
@@ -3569,15 +3570,13 @@ static void bt_smp_pkey_ready(const u8_t *pkey)
35693570

35703571
BT_DBG("");
35713572

3573+
sc_public_key = pkey;
3574+
35723575
if (!pkey) {
35733576
BT_WARN("Public key not available");
3574-
sc_local_pkey_valid = false;
35753577
return;
35763578
}
35773579

3578-
memcpy(sc_public_key, pkey, 64);
3579-
sc_local_pkey_valid = true;
3580-
35813580
for (i = 0; i < ARRAY_SIZE(bt_smp_pool); i++) {
35823581
struct bt_smp *smp = &bt_smp_pool[i];
35833582
u8_t err;
@@ -4387,7 +4386,7 @@ int bt_smp_auth_pairing_confirm(struct bt_conn *conn)
43874386
return legacy_send_pairing_confirm(smp);
43884387
}
43894388

4390-
if (!sc_local_pkey_valid) {
4389+
if (!sc_public_key) {
43914390
atomic_set_bit(smp->flags, SMP_FLAG_PKEY_SEND);
43924391
return 0;
43934392
}

0 commit comments

Comments
 (0)