From d79ba4d77693dd6a459f545dc5f900f5ab57825b Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Tue, 14 Sep 2021 09:28:59 +0530 Subject: [PATCH] Nimble/host: Compare only x component of public key before pairing Update fix of MITM vulnerability during public key exchange in secure connection --- nimble/host/src/ble_sm_sc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nimble/host/src/ble_sm_sc.c b/nimble/host/src/ble_sm_sc.c index 562f33b51..ace49e34a 100644 --- a/nimble/host/src/ble_sm_sc.c +++ b/nimble/host/src/ble_sm_sc.c @@ -612,6 +612,14 @@ ble_sm_sc_public_key_rx(uint16_t conn_handle, struct os_mbuf **om, cmd = (struct ble_sm_public_key *)(*om)->om_data; + /* Check if the X component of peer public key is same as X component of our generated public key. + * Return fail if they match. */ + if (memcmp(cmd, ble_sm_sc_pub_key, 32) == 0) { + res->enc_cb = 1; + res->sm_err = BLE_SM_ERR_AUTHREQ; + return; + } + ble_hs_lock(); proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_PUBLIC_KEY, -1, NULL);