Skip to content

Commit d4fd267

Browse files
Johan Hedbergnashif
authored andcommitted
Bluetooth: Mesh: Fix rejecting invalid remote public key
Mesh Profile Spec v1.0.1 | Section 5.4.2.3: "The Provisioner and the device shall check whether the public key provided by the peer device or obtained OOB is valid (see Section 5.4.3.1). When the Provisioner receives an invalid public key, then provisioning fails, and the Provisioner shall act as described in Section 5.4.4. When the device receives an invalid public key, then provisioning fails, and the device shall act as described in Section 5.4.4." This is also in Erratum 10395 which is Mandatory for Mesh v1.0. The code was already rejecting the key, however that rejection happened only after we had already sent our public key as response, which got interpreted as acceptance by the tester (PTS). Fixes MESH/NODE/PROV/BI-13-C. Signed-off-by: Johan Hedberg <[email protected]>
1 parent 9fb22af commit d4fd267

File tree

1 file changed

+16
-12
lines changed
  • subsys/bluetooth/host/mesh

1 file changed

+16
-12
lines changed

subsys/bluetooth/host/mesh/prov.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -909,20 +909,11 @@ static void send_pub_key(void)
909909

910910
BT_DBG("Local Public Key: %s", bt_hex(key, 64));
911911

912-
prov_buf_init(&buf, PROV_PUB_KEY);
913-
914-
/* Swap X and Y halves independently to big-endian */
915-
sys_memcpy_swap(net_buf_simple_add(&buf, 32), key, 32);
916-
sys_memcpy_swap(net_buf_simple_add(&buf, 32), &key[32], 32);
917-
918-
memcpy(&link.conf_inputs[81], &buf.data[1], 64);
919-
920-
prov_send(&buf);
921-
922912
/* Copy remote key in little-endian for bt_dh_key_gen().
923-
* X and Y halves are swapped independently.
913+
* X and Y halves are swapped independently. Use response
914+
* buffer as a temporary storage location. The bt_dh_key_gen()
915+
* will also take care of validating the remote public key.
924916
*/
925-
net_buf_simple_reset(&buf);
926917
sys_memcpy_swap(buf.data, &link.conf_inputs[17], 32);
927918
sys_memcpy_swap(&buf.data[32], &link.conf_inputs[49], 32);
928919

@@ -932,6 +923,19 @@ static void send_pub_key(void)
932923
return;
933924
}
934925

926+
prov_buf_init(&buf, PROV_PUB_KEY);
927+
928+
/* Swap X and Y halves independently to big-endian */
929+
sys_memcpy_swap(net_buf_simple_add(&buf, 32), key, 32);
930+
sys_memcpy_swap(net_buf_simple_add(&buf, 32), &key[32], 32);
931+
932+
memcpy(&link.conf_inputs[81], &buf.data[1], 64);
933+
934+
if (prov_send(&buf)) {
935+
BT_ERR("Failed to send Public Key");
936+
return;
937+
}
938+
935939
link.expect = PROV_CONFIRM;
936940
}
937941

0 commit comments

Comments
 (0)