Skip to content

Commit c29b277

Browse files
guy-msjanc
authored andcommitted
host: sm: secure connection only pairing might fail with no reason
When BLE_SM_SC_ONLY is on during pairing request, the process might fail even though both SC is supported by the peer and the key size meet the requirements.
1 parent 0f09bcf commit c29b277

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

nimble/host/src/ble_sm.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -1849,18 +1849,18 @@ ble_sm_pair_req_rx(uint16_t conn_handle, struct os_mbuf **om,
18491849
} else if (req->max_enc_key_size > BLE_SM_PAIR_KEY_SZ_MAX) {
18501850
res->sm_err = BLE_SM_ERR_INVAL;
18511851
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_INVAL);
1852-
} else if (MYNEWT_VAL(BLE_SM_SC_ONLY)) {
1853-
/* Fail if Secure Connections Only mode is on and remote does not
1854-
* meet key size requirements - MITM was checked in last step.
1855-
* Fail if SC is not supported by peer or key size is too small
1852+
} else if (MYNEWT_VAL(BLE_SM_SC_ONLY) && !(req->authreq & BLE_SM_PAIR_AUTHREQ_SC)) {
1853+
/* Fail if Secure Connections Only mode is on and SC is not supported by peer
18561854
*/
1857-
if (!(req->authreq & BLE_SM_PAIR_AUTHREQ_SC)) {
1858-
res->sm_err = BLE_SM_ERR_AUTHREQ;
1859-
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_AUTHREQ);
1860-
} else if (req->max_enc_key_size != BLE_SM_PAIR_KEY_SZ_MAX) {
1861-
res->sm_err = BLE_SM_ERR_ENC_KEY_SZ;
1862-
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_ENC_KEY_SZ);
1863-
}
1855+
res->sm_err = BLE_SM_ERR_AUTHREQ;
1856+
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_AUTHREQ);
1857+
res->enc_cb = 1;
1858+
} else if (MYNEWT_VAL(BLE_SM_SC_ONLY) && (req->max_enc_key_size != BLE_SM_PAIR_KEY_SZ_MAX)) {
1859+
/* Fail if Secure Connections Only mode is on and key size is too small
1860+
*/
1861+
res->sm_err = BLE_SM_ERR_ENC_KEY_SZ;
1862+
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_ENC_KEY_SZ);
1863+
res->enc_cb = 1;
18641864
} else if (!ble_sm_verify_auth_requirements(req->authreq)) {
18651865
res->sm_err = BLE_SM_ERR_AUTHREQ;
18661866
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_AUTHREQ);

0 commit comments

Comments
 (0)