Skip to content
Permalink
Browse files

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 <johan.hedberg@intel.com>
  • Loading branch information...
jhedberg committed Jun 25, 2019
1 parent 8d9a65c commit 60f47c2d7ee61c444f6becbaa88f56a0981491aa
Showing with 9 additions and 9 deletions.
  1. +9 −9 subsys/bluetooth/host/smp.c
@@ -261,8 +261,7 @@ static struct bt_smp bt_smp_pool[CONFIG_BT_MAX_CONN];
static bool bondable = IS_ENABLED(CONFIG_BT_BONDABLE);
static bool oobd_present;
static bool sc_supported;
static bool sc_local_pkey_valid;
static u8_t sc_public_key[64];
static const u8_t *sc_public_key;
static K_SEM_DEFINE(sc_local_pkey_ready, 0, 1);

static u8_t get_io_capa(void)
@@ -2292,6 +2291,8 @@ static int smp_init(struct bt_smp *smp)

atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_FAIL);

sc_public_key = bt_pub_key_get();

return 0;
}

@@ -2666,7 +2667,7 @@ static u8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
return 0;
}

if (!sc_local_pkey_valid) {
if (!sc_public_key) {
atomic_set_bit(smp->flags, SMP_FLAG_PKEY_SEND);
return 0;
}
@@ -3510,7 +3511,7 @@ static u8_t smp_public_key(struct bt_smp *smp, struct net_buf *buf)
}

#if defined(CONFIG_BT_PERIPHERAL)
if (!sc_local_pkey_valid) {
if (!sc_public_key) {
atomic_set_bit(smp->flags, SMP_FLAG_PKEY_SEND);
return 0;
}
@@ -3678,14 +3679,13 @@ static void bt_smp_pkey_ready(const u8_t *pkey)

BT_DBG("");

sc_public_key = pkey;

if (!pkey) {
BT_WARN("Public key not available");
sc_local_pkey_valid = false;
return;
}

memcpy(sc_public_key, pkey, 64);
sc_local_pkey_valid = true;
k_sem_give(&sc_local_pkey_ready);

for (i = 0; i < ARRAY_SIZE(bt_smp_pool); i++) {
@@ -4453,7 +4453,7 @@ int bt_smp_le_oob_generate_sc_data(struct bt_le_oob_sc_data *le_sc_oob)
{
int err;

if (!sc_local_pkey_valid) {
if (!sc_public_key) {
err = k_sem_take(&sc_local_pkey_ready, K_FOREVER);
if (err) {
return err;
@@ -4631,7 +4631,7 @@ int bt_smp_auth_pairing_confirm(struct bt_conn *conn)
return legacy_send_pairing_confirm(smp);
}

if (!sc_local_pkey_valid) {
if (!sc_public_key) {
atomic_set_bit(smp->flags, SMP_FLAG_PKEY_SEND);
return 0;
}

0 comments on commit 60f47c2

Please sign in to comment.
You can’t perform that action at this time.