From f68533d3b6fc4c01dcafba34d9fc954efbd44e37 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 3 Dec 2020 07:28:52 +0100 Subject: SMPTypes.hpp: Complete Phase 3 SMPPDUMsg types (Fix arg names + API doc + string representation) --- api/direct_bt/SMPTypes.hpp | 114 +++++++++++++++++++++++++++++++-------------- 1 file changed, 80 insertions(+), 34 deletions(-) (limited to 'api') diff --git a/api/direct_bt/SMPTypes.hpp b/api/direct_bt/SMPTypes.hpp index 174b66be..6901ccfd 100644 --- a/api/direct_bt/SMPTypes.hpp +++ b/api/direct_bt/SMPTypes.hpp @@ -633,7 +633,6 @@ namespace direct_bt { */ class SMPPairingMsg : public SMPPDUMsg { - private: const bool request; const SMPAuthReqs authReqMask; @@ -820,15 +819,16 @@ namespace direct_bt { * See Vol 3, Part H, 2.3.5.6 SM - Pairing algo - LE Secure Connections pairing phase 2. *

*/ - jau::uint128_t getConfirmValuePtr() const noexcept { return pdu.get_uint128_nc(1); } + jau::uint128_t getConfirmValue() const noexcept { return pdu.get_uint128_nc(1); } std::string getName() const noexcept override { return "SMPPairConfirm"; } protected: - std::string valueString() const noexcept override { - return "size "+std::to_string(getDataSize())+", data anon"; // FIXME: Shareable? + std::string valueString() const noexcept override { // hex-fmt aligned with btmon + return "size "+std::to_string(getDataSize())+", value "+ + jau::bytesHexString(pdu.get_ptr_nc(1), 0, getDataSize(), true /* lsbFirst */, false /* leading0X */); } }; @@ -909,15 +909,16 @@ namespace direct_bt { * the initiating device sends Na and the responding device sends Nb. *

*/ - jau::uint128_t getRandomValuePtr() const noexcept { return pdu.get_uint128_nc(1); } + jau::uint128_t getRand() const noexcept { return pdu.get_uint128_nc(1); } std::string getName() const noexcept override { return "SMPPairRand"; } protected: - std::string valueString() const noexcept override { - return "size "+std::to_string(getDataSize())+", data anon"; + std::string valueString() const noexcept override { // hex-fmt aligned with btmon + return "size "+std::to_string(getDataSize())+", rand "+ + jau::bytesHexString(pdu.get_ptr_nc(1), 0, getDataSize(), true /* lsbFirst */, false /* leading0X */); } }; @@ -992,7 +993,7 @@ namespace direct_bt { /** * Vol 3, Part H: 3.5.6 Pairing Public Key message. *
-     * Vol 3 (Host), Part H (SM): 3 (SMP), 3.5 Pairing Methods
+     * Vol 3 (Host), Part H (SM): 3 (SMP), 3.5.6 Pairing Public Key
      * 
* * Opcode::PAIRING_PUBLIC_KEY @@ -1030,16 +1031,24 @@ namespace direct_bt { /** * Returns the 256-bit Public Key X value (32 octets) */ - jau::uint256_t getPublicKeyXValuePtr() const noexcept { return pdu.get_uint256_nc(1); } + jau::uint256_t getPubKeyX() const noexcept { return pdu.get_uint256_nc(1); } /** * Returns the 256-bit Public Key Y value (32 octets) */ - jau::uint256_t getPublicKeyYValuePtr() const noexcept { return pdu.get_uint256_nc(1+32); } + jau::uint256_t getPubKeyY() const noexcept { return pdu.get_uint256_nc(1+32); } std::string getName() const noexcept override { return "SMPPairPubKey"; } + + protected: + std::string valueString() const noexcept override { + return "size "+std::to_string(getDataSize())+", pk_x "+ + jau::bytesHexString(pdu.get_ptr_nc(1), 0, 32, true /* lsbFirst */, false /* leading0X */)+ + ", pk_y "+ + jau::bytesHexString(pdu.get_ptr_nc(1+32), 0, 32, true /* lsbFirst */, false /* leading0X */); + } }; /** @@ -1081,7 +1090,7 @@ namespace direct_bt { /** * Returns the 128-bit DHKey Check value (16 octets) */ - jau::uint128_t getDHKeyCheckValuePtr() const noexcept { return pdu.get_uint128_nc(1); } + jau::uint128_t getDHKeyCheck() const noexcept { return pdu.get_uint128_nc(1); } std::string getName() const noexcept override { return "SMPPairDHKeyCheck"; @@ -1089,7 +1098,8 @@ namespace direct_bt { protected: std::string valueString() const noexcept override { - return "size "+std::to_string(getDataSize())+", data anon"; // FIXME: Shareable? + return "size "+std::to_string(getDataSize())+", dhkey_chk "+ + jau::bytesHexString(pdu.get_ptr_nc(1), 0, getDataSize(), true /* lsbFirst */, false /* leading0X */); } }; @@ -1157,6 +1167,8 @@ namespace direct_bt { * Vol 3, Part H: 3.6.2 Encryption Information message. *
      * Vol 3 (Host), Part H (SM): 3 (SMP), 3.6 SECURITY IN BLUETOOTH LOW ENERGY
+     * Vol 3 (Host), Part H (SM): 3 (SMP), 3.6.1 Key distribution and generation
+     * Vol 3 (Host), Part H (SM): 2 (SM), 2.4.1 Definition of keys and values
      * 
* * Opcode::ENCRYPTION_INFORMATION @@ -1167,9 +1179,12 @@ namespace direct_bt { * * * Message is used in the LE legacy pairing Transport Specific Key Distribution - * to distribute LTK that is used when encrypting future connections. + * to distribute Long Term Key (LTK) that is used when encrypting future connections. + *

+ * The message shall only be sent when the link has been encrypted or re-encrypted using the generated LTK. + *

*

- * The message shall only be sent when the link has been encrypted or re-encrypted using the generated STK. + * Legacy: #1 in distribution, first value. *

*/ class SMPEncInfoMsg : public SMPPDUMsg @@ -1195,18 +1210,19 @@ namespace direct_bt { * Returns the 128-bit Long Term Key (16 octets) *

* The generated LTK value being distributed, - * see Vol 3, Part H, 2.4.2.3 SM - Generation of CSRK - LE legacy pairing - generation of LTK, EDIV and Rand. + * see Vol 3, Part H, 2.4.2.3 SM - LE legacy pairing - generation of LTK, EDIV and Rand. *

*/ - jau::uint128_t getLongTermKeyPtr() const noexcept { return pdu.get_uint128_nc(1); } + jau::uint128_t getLTK() const noexcept { return pdu.get_uint128_nc(1); } std::string getName() const noexcept override { return "SMPEncInfo"; } protected: - std::string valueString() const noexcept override { - return "size "+std::to_string(getDataSize())+", data anon"; + std::string valueString() const noexcept override { // hex-fmt aligned with btmon + return "size "+std::to_string(getDataSize())+", ltk "+ + jau::bytesHexString(pdu.get_ptr_nc(1), 0, getDataSize(), true /* lsbFirst */, false /* leading0X */); } }; @@ -1214,6 +1230,8 @@ namespace direct_bt { * Vol 3, Part H: 3.6.3 Master Identification message. *
      * Vol 3 (Host), Part H (SM): 3 (SMP), 3.6 SECURITY IN BLUETOOTH LOW ENERGY
+     * Vol 3 (Host), Part H (SM): 3 (SMP), 3.6.1 Key distribution and generation
+     * Vol 3 (Host), Part H (SM): 2 (SM), 2.4.1 Definition of keys and values
      * 
* * Opcode::MASTER_IDENTIFICATION @@ -1225,10 +1243,13 @@ namespace direct_bt { * * * Message is used in the LE legacy pairing Transport Specific Key Distribution phase - * to distribute EDIV and Rand which are used when encrypting future connections. + * to distribute Encrypted Diversifier (EDIV) and Random Number (Rand) which are used when encrypting future connections. * *

- * The message shall only be sent when the link has been encrypted or re-encrypted using the generated STK. + * The message shall only be sent when the link has been encrypted or re-encrypted using the generated LTK. + *

+ *

+ * Legacy: #2 in distribution *

*/ class SMPMasterIdentMsg : public SMPPDUMsg @@ -1272,8 +1293,11 @@ namespace direct_bt { } protected: - std::string valueString() const noexcept override { - return "size "+std::to_string(getDataSize())+", data anon"; + std::string valueString() const noexcept override { // hex-fmt aligned with btmon + return "size "+std::to_string(getDataSize())+", ediv "+ + jau::bytesHexString(pdu.get_ptr_nc(1), 0, 2, false /* lsbFirst */, true /* leading0X */)+ + ", rand "+ + jau::bytesHexString(pdu.get_ptr_nc(1+2), 0, 8, false /* lsbFirst */, true /* leading0X */); } }; @@ -1281,6 +1305,9 @@ namespace direct_bt { * Vol 3, Part H: 3.6.4 Identify Information message. *
      * Vol 3 (Host), Part H (SM): 3 (SMP), 3.6 SECURITY IN BLUETOOTH LOW ENERGY
+     * Vol 3 (Host), Part H (SM): 3 (SMP), 3.6.1 Key distribution and generation
+     * Vol 3 (Host), Part H (SM): 2 (SM), 2.4.1 Definition of keys and values
+     * Vol 3 (Host), Part H (SM): 2 (SM), 2.4.2.1 Generation of IRK
      * 
* * Opcode::IDENTITY_INFORMATION @@ -1290,9 +1317,13 @@ namespace direct_bt { * jau::uint128_t identity_resolving_key * * - * Message is used in the Transport Specific Key Distribution phase to distribute IRK. + * Message is used in the Transport Specific Key Distribution phase to distribute Identity Resolving Key (IRK). + *

+ * The message shall only be sent when the link has been encrypted or re-encrypted using the generated key. + *

*

- * The message shall only shall only be sent when the link has been encrypted or re-encrypted using the generated key. + * Legacy: #3 in distribution
+ * Secure Connection: #1 in distribution, first value. *

*/ class SMPIdentInfoMsg : public SMPPDUMsg @@ -1321,7 +1352,7 @@ namespace direct_bt { * see Vol 3, Part H, 2.4.2.1 SM - Definition of keys and values - Generation of IRK. *

*/ - jau::uint128_t getIRKPtr() const noexcept { return pdu.get_uint128_nc(1); } + jau::uint128_t getIRK() const noexcept { return pdu.get_uint128_nc(1); } std::string getName() const noexcept override { return "SMPIdentInfo"; @@ -1329,7 +1360,8 @@ namespace direct_bt { protected: std::string valueString() const noexcept override { - return "size "+std::to_string(getDataSize())+", data anon"; + return "size "+std::to_string(getDataSize())+", irk "+ + jau::bytesHexString(pdu.get_ptr_nc(1), 0, getDataSize(), true /* lsbFirst */, false /* leading0X */); } }; @@ -1338,6 +1370,7 @@ namespace direct_bt { * Vol 3, Part H: 3.6.5 Identity Address Information message. *
      * Vol 3 (Host), Part H (SM): 3 (SMP), 3.6 SECURITY IN BLUETOOTH LOW ENERGY
+     * Vol 3 (Host), Part H (SM): 3 (SMP), 3.6.1 Key distribution and generation
      * 
* * Opcode::IDENTITY_ADDRESS_INFORMATION @@ -1353,6 +1386,10 @@ namespace direct_bt { *

* The message shall only be sent when the link has been encrypted or re-encrypted using the generated key. *

+ *

+ * Legacy: #4 in distribution
+ * Secure Connection: #2 in distribution + *

*/ class SMPIdentAddrInfoMsg : public SMPPDUMsg { @@ -1399,6 +1436,9 @@ namespace direct_bt { * Vol 3, Part H: 3.6.6 Signing Information message. *
      * Vol 3 (Host), Part H (SM): 3 (SMP), 3.6 SECURITY IN BLUETOOTH LOW ENERGY
+     * Vol 3 (Host), Part H (SM): 3 (SMP), 3.6.1 Key distribution and generation
+     * Vol 3 (Host), Part H (SM): 2 (SM), 2.4.1 Definition of keys and values
+     * Vol 3 (Host), Part H (SM): 2 (SM), 2.4.2.2 Generation of CSRK
      * 
* * Opcode::SIGNING_INFORMATION @@ -1408,9 +1448,14 @@ namespace direct_bt { * jau::uint128_t signature_key * * - * Message is used in the Transport Specific Key Distribution to distribute the CSRK which a device uses to sign data. + * Message is used in the Transport Specific Key Distribution + * to distribute the Connection Signature Resolving Key (CSRK), which a device uses to sign data. *

- * The message shall only shall only be sent when the link has been encrypted or re-encrypted using the generated key. + * The message shall only be sent when the link has been encrypted or re-encrypted using the generated key. + *

+ *

+ * Legacy: #5 in distribution, last value.
+ * Secure Connection: #3 in distribution, last value. *

*/ class SMPSignInfoMsg : public SMPPDUMsg @@ -1433,21 +1478,22 @@ namespace direct_bt { } /** - * Returns the 128-bit Identity Resolving Key (IRK, 16 octets) + * Returns the 128-bit Connection Signature Resolving Key (CSRK, 16 octets) *

- * The 128-bit IRK value being distributed, - * see Vol 3, Part H, 2.4.2.1 SM - Definition of keys and values - Generation of IRK. + * The 128-bit CSRK value being distributed, + * see Vol 3, Part H, 2.4.2.2 SM - Definition of keys and values - Generation of CSRK. *

*/ - jau::uint128_t getIRKPtr() const noexcept { return pdu.get_uint128_nc(1); } + jau::uint128_t getCSRK() const noexcept { return pdu.get_uint128_nc(1); } std::string getName() const noexcept override { return "SMPSignInfo"; } protected: - std::string valueString() const noexcept override { - return "size "+std::to_string(getDataSize())+", data anon"; + std::string valueString() const noexcept override { // hex-fmt aligned with btmon + return "size "+std::to_string(getDataSize())+", csrk "+ + jau::bytesHexString(pdu.get_ptr_nc(1), 0, getDataSize(), true /* lsbFirst */, false /* leading0X */); } }; -- cgit v1.2.3