sm: check for invalid public key detected by Controller

This commit is contained in:
Matthias Ringwald 2023-09-06 09:46:13 +02:00
parent 9edc39914e
commit 1c34405f17

View File

@ -486,6 +486,18 @@ static bool sm_is_null_key(uint8_t * key){
return btstack_is_null(key, 16);
}
#ifdef ENABLE_LE_SECURE_CONNECTIONS
static bool sm_is_ff(const uint8_t * buffer, uint16_t size){
uint16_t i;
for (i=0; i < size ; i++){
if (buffer[i] != 0xff) {
return false;
}
}
return true;
}
#endif
// sm_trigger_run allows to schedule callback from main run loop // reduces stack depth
static void sm_run_timer_handler(btstack_timer_source_t * ts){
UNUSED(ts);
@ -1948,6 +1960,13 @@ static void sm_sc_dhkey_calculated(void * arg){
sm_connection_t * sm_conn = sm_get_connection_for_handle(con_handle);
if (sm_conn == NULL) return;
// check for invalid public key detected by Controller
if (sm_is_ff(setup->sm_dhkey, 32)){
log_info("sm: peer public key invalid");
sm_pairing_error(sm_conn, SM_REASON_DHKEY_CHECK_FAILED);
return;
}
log_info("dhkey");
log_info_hexdump(&setup->sm_dhkey[0], 32);
setup->sm_state_vars |= SM_STATE_VAR_DHKEY_CALCULATED;