Loading system/bta/csis/csis_client.cc +8 −9 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ #include "stack/btm/btm_sec.h" #include "stack/crypto_toolbox/crypto_toolbox.h" #include "stack/gatt/gatt_int.h" #include "stack/include/btm_ble_sec_api.h" using base::Closure; using bluetooth::Uuid; Loading Loading @@ -1212,17 +1213,16 @@ class CsisClientImpl : public CsisClient { */ bool sdf(const RawAddress& address, const Octet16& encrypted_sirk, Octet16& sirk) { tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(address); if (!p_dev_rec) { auto pltk = BTM_BleGetPeerLTK(address); if (!pltk.has_value()) { LOG_ERROR("No security for %s", ADDRESS_TO_LOGGABLE_CSTR(address)); return false; } #ifdef CSIS_DEBUG LOG_INFO("LTK %s", (base::HexEncode(p_dev_rec->ble.keys.pltk.data(), 16)).c_str()); LOG_INFO("IRK %s", base::HexEncode(p_dev_rec->ble.keys.irk.data(), 16).c_str()); auto irk = BTM_BleGetPeerIRK(address); LOG_INFO("LTK %s", (base::HexEncode(*pltk.data(), 16)).c_str()); LOG_INFO("IRK %s", base::HexEncode(*irk.data(), 16).c_str()); #endif /* Calculate salt CSIS d1.0r05 4.3 */ Loading @@ -1238,11 +1238,10 @@ class CsisClientImpl : public CsisClient { #ifdef CSIS_DEBUG LOG_INFO("s1 (le) %s", base::HexEncode(s1.data(), 16).c_str()); /* Create K = LTK */ LOG_INFO("K (le) %s", base::HexEncode(p_dev_rec->ble.keys.pltk.data(), 16).c_str()); LOG_INFO("K (le) %s", base::HexEncode(*pltk.data(), 16).c_str()); #endif Octet16 T = crypto_toolbox::aes_cmac(s1, p_dev_rec->ble_keys.pltk); Octet16 T = crypto_toolbox::aes_cmac(s1, *pltk); #ifdef CSIS_DEBUG LOG_INFO("T (le) %s", base::HexEncode(T.data(), 16).c_str()); Loading system/bta/test/common/btm_api_mock.cc +15 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,10 @@ #include "btm_api_mock.h" #include <optional> #include "bt_octets.h" #include "stack/include/btm_ble_sec_api.h" #include "types/raw_address.h" static bluetooth::manager::MockBtmInterface* btm_interface = nullptr; Loading Loading @@ -103,3 +107,13 @@ tBTM_INQ_INFO* BTM_InqDbNext(tBTM_INQ_INFO* p_cur) { LOG_ASSERT(btm_interface) << "Mock btm interface not set!"; return btm_interface->BTM_InqDbNext(p_cur); } std::optional<Octet16> BTM_BleGetPeerLTK(const RawAddress address) { LOG_ASSERT(btm_interface) << "Mock btm interface not set!"; return btm_interface->BTM_BleGetPeerLTK(address); } std::optional<Octet16> BTM_BleGetPeerIRK(const RawAddress address) { LOG_ASSERT(btm_interface) << "Mock btm interface not set!"; return btm_interface->BTM_BleGetPeerIRK(address); } system/bta/test/common/btm_api_mock.h +12 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ #include <gmock/gmock.h> #include <optional> #include "bt_octets.h" #include "btm_api.h" #include "stack/btm/security_device_record.h" #include "types/raw_address.h" Loading Loading @@ -54,6 +57,11 @@ class BtmInterface { virtual void AclDisconnectFromHandle(uint16_t handle, tHCI_STATUS reason) = 0; virtual tBTM_INQ_INFO* BTM_InqDbFirst() = 0; virtual tBTM_INQ_INFO* BTM_InqDbNext(tBTM_INQ_INFO* p_cur) = 0; virtual std::optional<Octet16> BTM_BleGetPeerLTK( const RawAddress address) = 0; virtual std::optional<Octet16> BTM_BleGetPeerIRK( const RawAddress address) = 0; virtual ~BtmInterface() = default; }; Loading Loading @@ -95,6 +103,10 @@ class MockBtmInterface : public BtmInterface { MOCK_METHOD((tBTM_INQ_INFO*), BTM_InqDbFirst, (), (override)); MOCK_METHOD((tBTM_INQ_INFO*), BTM_InqDbNext, (tBTM_INQ_INFO * p_cur), (override)); MOCK_METHOD((std::optional<Octet16>), BTM_BleGetPeerLTK, (const RawAddress address), (override)); MOCK_METHOD((std::optional<Octet16>), BTM_BleGetPeerIRK, (const RawAddress address), (override)); }; /** Loading system/stack/btm/btm_ble_sec.cc +20 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ * */ #include <cstddef> #include <optional> #define LOG_TAG "ble_sec" #include <base/strings/stringprintf.h> Loading Loading @@ -1941,3 +1943,21 @@ bool btm_ble_get_acl_remote_addr(uint16_t hci_handle, RawAddress& conn_addr, } return st; } std::optional<Octet16> BTM_BleGetPeerLTK(const RawAddress address) { tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(address); if (p_dev_rec == nullptr) { return std::nullopt; } return p_dev_rec->ble_keys.pltk; } std::optional<Octet16> BTM_BleGetPeerIRK(const RawAddress address) { tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(address); if (p_dev_rec == nullptr) { return std::nullopt; } return p_dev_rec->ble_keys.irk; } system/stack/include/btm_ble_sec_api.h +33 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <hardware/bt_common_types.h> #include <cstdint> #include <optional> #include "btm_ble_api_types.h" #include "btm_ble_sec_api_types.h" Loading Loading @@ -202,3 +203,35 @@ bool BTM_BleVerifySignature(const RawAddress& bd_addr, uint8_t* p_orig, * ******************************************************************************/ void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS* p_key); /******************************************************************************* * * Function BTM_BleGetPeerLTK * * Description This function is used to get the long term key of * a bonded peer (LE) device. * * Parameters: address: address of the peer device * * Returns the ltk contained in std::optional if the remote device * is present in security database * std::nullopt if the device is not present * ******************************************************************************/ std::optional<Octet16> BTM_BleGetPeerLTK(const RawAddress address); /******************************************************************************* * * Function BTM_BleGetPeerIRK * * Description This function is used to get the IRK of a bonded * peer (LE) device. * * Parameters: address: address of the peer device * * Returns the ltk contained in std::optional if the remote device * is present in security database * std::nullopt if the device is not present * ******************************************************************************/ std::optional<Octet16> BTM_BleGetPeerIRK(const RawAddress address); Loading
system/bta/csis/csis_client.cc +8 −9 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ #include "stack/btm/btm_sec.h" #include "stack/crypto_toolbox/crypto_toolbox.h" #include "stack/gatt/gatt_int.h" #include "stack/include/btm_ble_sec_api.h" using base::Closure; using bluetooth::Uuid; Loading Loading @@ -1212,17 +1213,16 @@ class CsisClientImpl : public CsisClient { */ bool sdf(const RawAddress& address, const Octet16& encrypted_sirk, Octet16& sirk) { tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(address); if (!p_dev_rec) { auto pltk = BTM_BleGetPeerLTK(address); if (!pltk.has_value()) { LOG_ERROR("No security for %s", ADDRESS_TO_LOGGABLE_CSTR(address)); return false; } #ifdef CSIS_DEBUG LOG_INFO("LTK %s", (base::HexEncode(p_dev_rec->ble.keys.pltk.data(), 16)).c_str()); LOG_INFO("IRK %s", base::HexEncode(p_dev_rec->ble.keys.irk.data(), 16).c_str()); auto irk = BTM_BleGetPeerIRK(address); LOG_INFO("LTK %s", (base::HexEncode(*pltk.data(), 16)).c_str()); LOG_INFO("IRK %s", base::HexEncode(*irk.data(), 16).c_str()); #endif /* Calculate salt CSIS d1.0r05 4.3 */ Loading @@ -1238,11 +1238,10 @@ class CsisClientImpl : public CsisClient { #ifdef CSIS_DEBUG LOG_INFO("s1 (le) %s", base::HexEncode(s1.data(), 16).c_str()); /* Create K = LTK */ LOG_INFO("K (le) %s", base::HexEncode(p_dev_rec->ble.keys.pltk.data(), 16).c_str()); LOG_INFO("K (le) %s", base::HexEncode(*pltk.data(), 16).c_str()); #endif Octet16 T = crypto_toolbox::aes_cmac(s1, p_dev_rec->ble_keys.pltk); Octet16 T = crypto_toolbox::aes_cmac(s1, *pltk); #ifdef CSIS_DEBUG LOG_INFO("T (le) %s", base::HexEncode(T.data(), 16).c_str()); Loading
system/bta/test/common/btm_api_mock.cc +15 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,10 @@ #include "btm_api_mock.h" #include <optional> #include "bt_octets.h" #include "stack/include/btm_ble_sec_api.h" #include "types/raw_address.h" static bluetooth::manager::MockBtmInterface* btm_interface = nullptr; Loading Loading @@ -103,3 +107,13 @@ tBTM_INQ_INFO* BTM_InqDbNext(tBTM_INQ_INFO* p_cur) { LOG_ASSERT(btm_interface) << "Mock btm interface not set!"; return btm_interface->BTM_InqDbNext(p_cur); } std::optional<Octet16> BTM_BleGetPeerLTK(const RawAddress address) { LOG_ASSERT(btm_interface) << "Mock btm interface not set!"; return btm_interface->BTM_BleGetPeerLTK(address); } std::optional<Octet16> BTM_BleGetPeerIRK(const RawAddress address) { LOG_ASSERT(btm_interface) << "Mock btm interface not set!"; return btm_interface->BTM_BleGetPeerIRK(address); }
system/bta/test/common/btm_api_mock.h +12 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ #include <gmock/gmock.h> #include <optional> #include "bt_octets.h" #include "btm_api.h" #include "stack/btm/security_device_record.h" #include "types/raw_address.h" Loading Loading @@ -54,6 +57,11 @@ class BtmInterface { virtual void AclDisconnectFromHandle(uint16_t handle, tHCI_STATUS reason) = 0; virtual tBTM_INQ_INFO* BTM_InqDbFirst() = 0; virtual tBTM_INQ_INFO* BTM_InqDbNext(tBTM_INQ_INFO* p_cur) = 0; virtual std::optional<Octet16> BTM_BleGetPeerLTK( const RawAddress address) = 0; virtual std::optional<Octet16> BTM_BleGetPeerIRK( const RawAddress address) = 0; virtual ~BtmInterface() = default; }; Loading Loading @@ -95,6 +103,10 @@ class MockBtmInterface : public BtmInterface { MOCK_METHOD((tBTM_INQ_INFO*), BTM_InqDbFirst, (), (override)); MOCK_METHOD((tBTM_INQ_INFO*), BTM_InqDbNext, (tBTM_INQ_INFO * p_cur), (override)); MOCK_METHOD((std::optional<Octet16>), BTM_BleGetPeerLTK, (const RawAddress address), (override)); MOCK_METHOD((std::optional<Octet16>), BTM_BleGetPeerIRK, (const RawAddress address), (override)); }; /** Loading
system/stack/btm/btm_ble_sec.cc +20 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ * */ #include <cstddef> #include <optional> #define LOG_TAG "ble_sec" #include <base/strings/stringprintf.h> Loading Loading @@ -1941,3 +1943,21 @@ bool btm_ble_get_acl_remote_addr(uint16_t hci_handle, RawAddress& conn_addr, } return st; } std::optional<Octet16> BTM_BleGetPeerLTK(const RawAddress address) { tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(address); if (p_dev_rec == nullptr) { return std::nullopt; } return p_dev_rec->ble_keys.pltk; } std::optional<Octet16> BTM_BleGetPeerIRK(const RawAddress address) { tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(address); if (p_dev_rec == nullptr) { return std::nullopt; } return p_dev_rec->ble_keys.irk; }
system/stack/include/btm_ble_sec_api.h +33 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <hardware/bt_common_types.h> #include <cstdint> #include <optional> #include "btm_ble_api_types.h" #include "btm_ble_sec_api_types.h" Loading Loading @@ -202,3 +203,35 @@ bool BTM_BleVerifySignature(const RawAddress& bd_addr, uint8_t* p_orig, * ******************************************************************************/ void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS* p_key); /******************************************************************************* * * Function BTM_BleGetPeerLTK * * Description This function is used to get the long term key of * a bonded peer (LE) device. * * Parameters: address: address of the peer device * * Returns the ltk contained in std::optional if the remote device * is present in security database * std::nullopt if the device is not present * ******************************************************************************/ std::optional<Octet16> BTM_BleGetPeerLTK(const RawAddress address); /******************************************************************************* * * Function BTM_BleGetPeerIRK * * Description This function is used to get the IRK of a bonded * peer (LE) device. * * Parameters: address: address of the peer device * * Returns the ltk contained in std::optional if the remote device * is present in security database * std::nullopt if the device is not present * ******************************************************************************/ std::optional<Octet16> BTM_BleGetPeerIRK(const RawAddress address);