diff --git a/subsys/bluetooth/mesh/crypto_psa.c b/subsys/bluetooth/mesh/crypto_psa.c index 8d95ed912ec..dcefb18565c 100644 --- a/subsys/bluetooth/mesh/crypto_psa.c +++ b/subsys/bluetooth/mesh/crypto_psa.c @@ -452,9 +452,14 @@ int bt_mesh_key_import(enum bt_mesh_key_type type, const uint8_t in[16], struct psa_set_key_bits(&key_attributes, 128); status = psa_import_key(&key_attributes, in, 16, &out->key); - err = status == PSA_SUCCESS ? 0 : - status == PSA_ERROR_ALREADY_EXISTS ? -EALREADY : -EIO; + if (status == PSA_ERROR_ALREADY_EXISTS) { + LOG_WRN("Key with ID 0x%4x already exists (desync between mesh and PSA ITS)", + key_id); + (void)psa_destroy_key(key_id); + status = psa_import_key(&key_attributes, in, 16, &out->key); + } + err = status == PSA_SUCCESS ? 0 : -EIO; if (err && key_id != PSA_KEY_ID_NULL) { keyid_free(key_id); }