diff options
author | Sven Gothel <[email protected]> | 2020-12-10 16:18:31 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-12-10 16:18:31 +0100 |
commit | 2c794724c4937b3f019a19a30b1de70c08eb69ae (patch) | |
tree | 510ef2cc384576983924766913bcfdcc826c24c4 /api/direct_bt | |
parent | d3c5a0ea76457bb74c5ce63d5ef07c20dd507f26 (diff) |
Added support for SMPSignatureResolvingKeyInfo and SMPKeyType query
- Added SMPSignatureResolvingKeyInfo (native + Java) key retrieval
- Rename SMPKeyDist -> SMPKeyType: For general use, e.g. new query 'SMPKeyType getAvailableSMPKeys(const bool responder)'
- Added SMPKeyType.java
- Added DBTDevice::getAvailableSMPKeys(const bool responder): Allowing user to act upon specific keys when available (native + java)
Diffstat (limited to 'api/direct_bt')
-rw-r--r-- | api/direct_bt/DBTDevice.hpp | 24 | ||||
-rw-r--r-- | api/direct_bt/SMPTypes.hpp | 62 |
2 files changed, 51 insertions, 35 deletions
diff --git a/api/direct_bt/DBTDevice.hpp b/api/direct_bt/DBTDevice.hpp index 22772080..ae363599 100644 --- a/api/direct_bt/DBTDevice.hpp +++ b/api/direct_bt/DBTDevice.hpp @@ -95,8 +95,8 @@ namespace direct_bt { SMPIOCapability ioCap_init, ioCap_resp; SMPOOBDataFlag oobFlag_init, oobFlag_resp; uint8_t maxEncsz_init, maxEncsz_resp; - SMPKeyDist keys_init_exp, keys_resp_exp; - SMPKeyDist keys_init_has, keys_resp_has; + SMPKeyType keys_init_exp, keys_resp_exp; + SMPKeyType keys_init_has, keys_resp_has; // LTK: Set of Long Term Key data: ltk, ediv + rand SMPLongTermKeyInfo ltk_init, ltk_resp; @@ -107,7 +107,7 @@ namespace direct_bt { bool is_static_random_address; // CSRK - jau::uint128_t csrk_init, csrk_resp; + SMPSignatureResolvingKeyInfo csrk_init, csrk_resp; }; PairingData pairing_data; std::mutex mtx_pairing; @@ -447,7 +447,14 @@ namespace direct_bt { HCIStatusCode disconnect(const HCIStatusCode reason=HCIStatusCode::REMOTE_USER_TERMINATED_CONNECTION ) noexcept; /** - * Returns a copy of the long term ket (LTK) info, valid after connection and SMP pairing has been completed. + * Returns the available ::SMPKeyType mask for the responder (LL slave) or initiator (LL master). + * @param responder if true, queries the responder (LL slave) key, otherwise the initiator (LL master) key. + * @return ::SMPKeyType mask result + */ + SMPKeyType getAvailableSMPKeys(const bool responder) const noexcept; + + /** + * Returns a copy of the Long Term Key (LTK) info, valid after connection and SMP pairing has been completed. * @param responder true will return the responder's LTK info (remote device, LL slave), otherwise the initiator's (the LL master). * @return the resulting key. SMPLongTermKeyInfo::enc_size will be zero if invalid. * @see ::SMPPairingState::COMPLETED @@ -466,6 +473,15 @@ namespace direct_bt { HCIStatusCode setLongTermKeyInfo(const SMPLongTermKeyInfo& ltk) noexcept; /** + * Returns a copy of the Signature Resolving Key (LTK) info, valid after connection and SMP pairing has been completed. + * @param responder true will return the responder's LTK info (remote device, LL slave), otherwise the initiator's (the LL master). + * @return the resulting key + * @see ::SMPPairingState::COMPLETED + * @see AdapterStatusListener::deviceReady() + */ + SMPSignatureResolvingKeyInfo getSignatureResolvingKeyInfo(const bool responder) const noexcept; + + /** * Unpairs this device from the adapter while staying connected. * <p> * All keys will be cleared within the adapter and host implementation.<br> diff --git a/api/direct_bt/SMPTypes.hpp b/api/direct_bt/SMPTypes.hpp index 42d709d8..2b30ffc4 100644 --- a/api/direct_bt/SMPTypes.hpp +++ b/api/direct_bt/SMPTypes.hpp @@ -331,7 +331,7 @@ namespace direct_bt { const SMPIOCapability ioCap_ini, const SMPIOCapability ioCap_res) noexcept; /** - * SMP Key Distribution, indicates keys distributed in the Transport Specific Key Distribution phase. + * SMP Key Type for Distribution, indicates keys distributed in the Transport Specific Key Distribution phase. * <pre> * Field format and usage: Vol 3, Part H, 3.6.1 SMP - LE Security - Key distribution and generation. * See also Vol 3, Part H, 2.4.3 SM - LE Security - Distribution of keys. @@ -342,7 +342,7 @@ namespace direct_bt { * uint8_t EncKey : 1, IdKey : 1, SignKey : 1, LinkKey : 1, RFU : 4; * </pre> */ - enum class SMPKeyDist : uint8_t { + enum class SMPKeyType : uint8_t { NONE = 0, /** * LE legacy pairing: Indicates device shall distribute LTK using the Encryption Information command, @@ -386,41 +386,41 @@ namespace direct_bt { /** Reserved for future use */ RFU_4 = 0b10000000 }; - constexpr SMPKeyDist operator ^(const SMPKeyDist lhs, const SMPKeyDist rhs) noexcept { - return static_cast<SMPKeyDist> ( static_cast<uint8_t>(lhs) ^ static_cast<uint8_t>(rhs) ); + constexpr SMPKeyType operator ^(const SMPKeyType lhs, const SMPKeyType rhs) noexcept { + return static_cast<SMPKeyType> ( static_cast<uint8_t>(lhs) ^ static_cast<uint8_t>(rhs) ); } - constexpr SMPKeyDist& operator ^=(SMPKeyDist& store, const SMPKeyDist& rhs) noexcept { - store = static_cast<SMPKeyDist> ( static_cast<uint8_t>(store) ^ static_cast<uint8_t>(rhs) ); + constexpr SMPKeyType& operator ^=(SMPKeyType& store, const SMPKeyType& rhs) noexcept { + store = static_cast<SMPKeyType> ( static_cast<uint8_t>(store) ^ static_cast<uint8_t>(rhs) ); return store; } - constexpr SMPKeyDist operator |(const SMPKeyDist lhs, const SMPKeyDist rhs) noexcept { - return static_cast<SMPKeyDist> ( static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs) ); + constexpr SMPKeyType operator |(const SMPKeyType lhs, const SMPKeyType rhs) noexcept { + return static_cast<SMPKeyType> ( static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs) ); } - constexpr SMPKeyDist& operator |=(SMPKeyDist& store, const SMPKeyDist& rhs) noexcept { - store = static_cast<SMPKeyDist> ( static_cast<uint8_t>(store) | static_cast<uint8_t>(rhs) ); + constexpr SMPKeyType& operator |=(SMPKeyType& store, const SMPKeyType& rhs) noexcept { + store = static_cast<SMPKeyType> ( static_cast<uint8_t>(store) | static_cast<uint8_t>(rhs) ); return store; } - constexpr SMPKeyDist operator &(const SMPKeyDist lhs, const SMPKeyDist rhs) noexcept { - return static_cast<SMPKeyDist> ( static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs) ); + constexpr SMPKeyType operator &(const SMPKeyType lhs, const SMPKeyType rhs) noexcept { + return static_cast<SMPKeyType> ( static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs) ); } - constexpr SMPKeyDist& operator &=(SMPKeyDist& store, const SMPKeyDist& rhs) noexcept { - store = static_cast<SMPKeyDist> ( static_cast<uint8_t>(store) & static_cast<uint8_t>(rhs) ); + constexpr SMPKeyType& operator &=(SMPKeyType& store, const SMPKeyType& rhs) noexcept { + store = static_cast<SMPKeyType> ( static_cast<uint8_t>(store) & static_cast<uint8_t>(rhs) ); return store; } - constexpr bool operator ==(const SMPKeyDist lhs, const SMPKeyDist rhs) noexcept { + constexpr bool operator ==(const SMPKeyType lhs, const SMPKeyType rhs) noexcept { return static_cast<uint8_t>(lhs) == static_cast<uint8_t>(rhs); } - constexpr bool operator !=(const SMPKeyDist lhs, const SMPKeyDist rhs) noexcept { + constexpr bool operator !=(const SMPKeyType lhs, const SMPKeyType rhs) noexcept { return !( lhs == rhs ); } - constexpr uint8_t number(const SMPKeyDist rhs) noexcept { + constexpr uint8_t number(const SMPKeyType rhs) noexcept { return static_cast<uint8_t>(rhs); } - constexpr bool isKeyDistBitSet(const SMPKeyDist mask, const SMPKeyDist bit) noexcept { - return SMPKeyDist::NONE != ( mask & bit ); + constexpr bool isKeyDistBitSet(const SMPKeyType mask, const SMPKeyType bit) noexcept { + return SMPKeyType::NONE != ( mask & bit ); } - std::string getSMPKeyDistBitString(const SMPKeyDist bit) noexcept; - std::string getSMPKeyDistMaskString(const SMPKeyDist mask) noexcept; + std::string getSMPKeyTypeBitString(const SMPKeyType bit) noexcept; + std::string getSMPKeyTypeMaskString(const SMPKeyType mask) noexcept; /** * SMP Long Term Key Info, used for platform agnostic persistence. @@ -822,16 +822,16 @@ namespace direct_bt { private: const bool request; const SMPAuthReqs authReqMask; - const SMPKeyDist initiator_key_dist; - const SMPKeyDist responder_key_dist; + const SMPKeyType initiator_key_dist; + const SMPKeyType responder_key_dist; public: SMPPairingMsg(const bool request_, const uint8_t* source, const jau::nsize_t length) : SMPPDUMsg(source, length), request(request_), authReqMask(static_cast<SMPAuthReqs>( pdu.get_uint8_nc(3) )), - initiator_key_dist(static_cast<SMPKeyDist>(pdu.get_uint8_nc(5))), - responder_key_dist(static_cast<SMPKeyDist>(pdu.get_uint8_nc(6))) + initiator_key_dist(static_cast<SMPKeyType>(pdu.get_uint8_nc(5))), + responder_key_dist(static_cast<SMPKeyType>(pdu.get_uint8_nc(6))) { checkOpcode(request? Opcode::PAIRING_REQUEST : Opcode::PAIRING_RESPONSE); } @@ -839,8 +839,8 @@ namespace direct_bt { SMPPairingMsg(const bool request_, const SMPIOCapability ioc, const SMPOOBDataFlag odf, const SMPAuthReqs auth_req_mask, const uint8_t maxEncKeySize, - const SMPKeyDist initiator_key_dist_, - const SMPKeyDist responder_key_dist_) + const SMPKeyType initiator_key_dist_, + const SMPKeyType responder_key_dist_) : SMPPDUMsg(request_? Opcode::PAIRING_REQUEST : Opcode::PAIRING_RESPONSE, 1+6), request(request_), authReqMask(auth_req_mask), initiator_key_dist(initiator_key_dist_), responder_key_dist(responder_key_dist_) @@ -911,7 +911,7 @@ namespace direct_bt { * </pre> * @see SMPKeyDistFormat */ - constexpr SMPKeyDist getInitKeyDist() const noexcept { + constexpr SMPKeyType getInitKeyDist() const noexcept { return initiator_key_dist; } /** @@ -924,7 +924,7 @@ namespace direct_bt { * </p> * @see SMPKeyDistFormat */ - constexpr SMPKeyDist getRespKeyDist() const noexcept { + constexpr SMPKeyType getRespKeyDist() const noexcept { return responder_key_dist; } @@ -938,8 +938,8 @@ namespace direct_bt { ", oob "+getSMPOOBDataFlagString(getOOBDataFlag())+ ", auth_req "+getSMPAuthReqMaskString(getAuthReqMask())+ ", max_keysz "+std::to_string(getMaxEncryptionKeySize())+ - ", key_dist[init "+getSMPKeyDistMaskString(getInitKeyDist())+ - ", resp "+getSMPKeyDistMaskString(getRespKeyDist())+ + ", key_dist[init "+getSMPKeyTypeMaskString(getInitKeyDist())+ + ", resp "+getSMPKeyTypeMaskString(getRespKeyDist())+ "]"; } }; |