From 026cbf947c9813fc0cec9fd148c7db3dcbc7d437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Fri, 8 Oct 2021 12:10:24 +0200 Subject: [PATCH] host/mesh: Reject identical public keys This commit address Erratum E10395 and Errata Correction E16350 to ensure that public keys exchanged between Provisioner and a device aren't identical. This is port of 33fafe1e2f41e5b61b1dc71f9ad0d8cb0930607f --- nimble/host/mesh/src/provisioner.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/nimble/host/mesh/src/provisioner.c b/nimble/host/mesh/src/provisioner.c index 3b4b76598..9e8df8937 100644 --- a/nimble/host/mesh/src/provisioner.c +++ b/nimble/host/mesh/src/provisioner.c @@ -385,8 +385,11 @@ static void prov_dh_key_cb(const uint8_t dhkey[32]) static void prov_dh_key_gen(void) { - uint8_t remote_pk_le[64], *remote_pk; + uint8_t remote_pk_le[64]; + const uint8_t *remote_pk; + const uint8_t *local_pk; + local_pk = &bt_mesh_prov_link.conf_inputs[17]; remote_pk = &bt_mesh_prov_link.conf_inputs[81]; /* Copy remote key in little-endian for bt_dh_key_gen(). @@ -396,6 +399,12 @@ static void prov_dh_key_gen(void) sys_memcpy_swap(remote_pk_le, remote_pk, 32); sys_memcpy_swap(&remote_pk_le[32], &remote_pk[32], 32); + if (!memcmp(local_pk, remote_pk, 64)) { + BT_ERR("Public keys are identical"); + prov_fail(PROV_ERR_NVAL_FMT); + return; + } + if (bt_dh_key_gen(remote_pk_le, prov_dh_key_cb)) { BT_ERR("Failed to generate DHKey"); prov_fail(PROV_ERR_UNEXP_ERR);