Bluedroid BLE local and Peer Long Term Key LTK

akshaay24
Posts: 13
Joined: Wed Jul 14, 2021 5:21 am

Bluedroid BLE local and Peer Long Term Key LTK

Postby akshaay24 » Sat Nov 09, 2024 12:08 pm

Hi,

I want to read and print Local and peer Long Term Key (LTK).
On searching, got to know Local LTK structure is esp_ble_lenc_keys_t and Peer LTK structure is esp_ble_penc_keys_t.
But when i try to print Local LTK in ESP_GAP_BLE_AUTH_CMPL_EVT event.

Code: Select all

esp_log_buffer_hex(GATTS_TABLE_TAG, (void *)param->ble_security.ble_key.p_key_value.lenc_key.ltk, sizeof(esp_bt_octet16_t));
The output is all 00.
Similarly for Peer LTK,

Code: Select all

param->ble_security.auth_cmpl.key
Please suggest correct procedure to get Long term Key. Below are my security configurations.
  1. esp_ble_auth_req_t auth_req = ESP_LE_AUTH_REQ_SC_MITM_BOND;     //bonding with peer device after authentication
  2.     esp_ble_io_cap_t iocap = ESP_IO_CAP_OUT;           //set the IO capability to No output No input
  3.     uint8_t key_size = 16;      //the key size should be 7~16 bytes
  4.     uint8_t init_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
  5.     uint8_t rsp_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
  6.     //set static passkey
  7.     uint32_t passkey = 123456;
  8.     uint8_t auth_option = ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_ENABLE;
  9.     uint8_t oob_support = ESP_BLE_OOB_DISABLE;
  10.     esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t));
  11.     esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &auth_req, sizeof(uint8_t));
  12.     esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
  13.     esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &key_size, sizeof(uint8_t));
  14.     esp_ble_gap_set_security_param(ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH, &auth_option, sizeof(uint8_t));
  15.     esp_ble_gap_set_security_param(ESP_BLE_SM_OOB_SUPPORT, &oob_support, sizeof(uint8_t));
  16.     /* If your BLE device acts as a Slave, the init_key means you hope which types of key of the master should distribute to you,
  17.     and the response key means which key you can distribute to the master;
  18.     If your BLE device acts as a master, the response key means you hope which types of key of the slave should distribute to you,
  19.     and the init key means which key you can distribute to the slave. */
  20.     esp_ble_gap_set_security_param(ESP_BLE_SM_SET_INIT_KEY, &init_key, sizeof(uint8_t));
  21.     esp_ble_gap_set_security_param(ESP_BLE_SM_SET_RSP_KEY, &rsp_key, sizeof(uint8_t));
Thank you.

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 104 guests