Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
Storage for SMP keys including the required connection parameter. More...
#include <SMPKeyBin.hpp>
Public Member Functions | |
SMPKeyBin (const BDAddressAndType &addrAndType_, const BTSecurityLevel sec_level_, const SMPIOCapability io_cap_) | |
SMPKeyBin () | |
constexpr bool | isVersionValid () const noexcept |
constexpr uint16_t | getVersion () const noexcept |
constexpr bool | isSizeValid () const noexcept |
constexpr uint16_t | getSize () const noexcept |
constexpr uint64_t | getCreationTime () const noexcept |
Returns the creation timestamp in seconds since Unix epoch. More... | |
constexpr const BDAddressAndType & | getAddrAndType () const noexcept |
constexpr BTSecurityLevel | getSecLevel () const noexcept |
constexpr SMPIOCapability | getIOCap () const noexcept |
constexpr bool | hasLTKInit () const noexcept |
constexpr bool | hasCSRKInit () const noexcept |
constexpr const SMPLongTermKeyInfo & | getLTKInit () const noexcept |
constexpr const SMPSignatureResolvingKeyInfo & | getCSRKInit () const noexcept |
void | setLTKInit (const SMPLongTermKeyInfo &v) noexcept |
void | setCSRKInit (const SMPSignatureResolvingKeyInfo &v) noexcept |
constexpr bool | hasLTKResp () const noexcept |
constexpr bool | hasCSRKResp () const noexcept |
constexpr const SMPLongTermKeyInfo & | getLTKResp () const noexcept |
constexpr const SMPSignatureResolvingKeyInfo & | getCSRKResp () const noexcept |
void | setLTKResp (const SMPLongTermKeyInfo &v) noexcept |
void | setCSRKResp (const SMPSignatureResolvingKeyInfo &v) noexcept |
void | setVerbose (bool v) noexcept |
constexpr bool | isValid () const noexcept |
Returns true if. More... | |
std::string | toString () const noexcept |
std::string | getFileBasename () const noexcept |
Returns the base filename, see SMPKeyBin API doc for naming scheme. More... | |
bool | write (const std::string &fname, const bool overwrite) const noexcept |
bool | read (const std::string &fname) |
HCIStatusCode | apply (BTDevice &device) const noexcept |
If this instance isValid() and initiator or responder LTK available, i.e. More... | |
Static Public Member Functions | |
static SMPKeyBin | create (const BTDevice &device) |
Create a new SMPKeyBin instance based upon given BTDevice's BTSecurityLevel, SMPPairingState, PairingMode and LTK keys. More... | |
static bool | createAndWrite (const BTDevice &device, const std::string &path, const bool overwrite, const bool verbose_) |
Create a new SMPKeyBin instance on the fly based upon given BTDevice's BTSecurityLevel, SMPPairingState, PairingMode and LTK keys. More... | |
static SMPKeyBin | read (const std::string &fname, const bool verbose_) |
Create a new SMPKeyBin instance based upon stored file denoted by fname . More... | |
static HCIStatusCode | readAndApply (const std::string &path, BTDevice &device, const BTSecurityLevel minSecLevel, const bool verbose_) |
Create a new SMPKeyBin instance on the fly based upon stored file denoted by path and BTDevice::getAddressAndType(), i.e. More... | |
static std::string | getFileBasename (const BDAddressAndType &addrAndType_) |
Returns the base filename, see SMPKeyBin API doc for naming scheme. More... | |
static std::string | getFilename (const std::string &path, const BDAddressAndType &addrAndType_) |
static bool | remove (const std::string &path, const BDAddressAndType &addrAndType_) |
Static Public Attributes | |
constexpr static const uint16_t | VERSION = (uint16_t)0b0101010101010101U + (uint16_t)2U |
Storage for SMP keys including the required connection parameter.
Storage for a device's BDAddressAndType, its security connection setup BTSecurityLevel + SMPIOCapability and optionally the initiator and responder SMPLongTermKeyInfo (LTK) and SMPSignatureResolvingKeyInfo (CSRK) within one file.
Since the SMPLongTermKeyInfo (LTK) and SMPSignatureResolvingKeyInfo (CSRK) can be optionally set due to their availability per initiator and responder, implementation supports mixed mode for certain devices. E.g. LTK responder key only etc.
Filename as retrieved by SMPKeyBin::getFileBasename() has the following form bd_C0_26_DA_01_DA_B1_1-smpkey.bin
:
denotes the suffix
Definition at line 62 of file SMPKeyBin.hpp.
|
inline |
Definition at line 199 of file SMPKeyBin.hpp.
|
inline |
Definition at line 209 of file SMPKeyBin.hpp.
|
noexcept |
If this instance isValid() and initiator or responder LTK available, i.e.
hasLTKInit() or hasLTKResp(), the following procedure will be applied to the given BTDevice:
If all three operations succeed, HCIStatusCode::SUCCESS will be returned, otherwise the appropriate status code below.
BTSecurityLevel::ENC_ONLY is set to avoid a new SMP PairingMode negotiation, which is undesired as this instances' stored LTK shall be used for PairingMode::PRE_PAIRED.
Method may fail for any of the following reasons:
Reason | HCIStatusCode |
---|---|
! isValid() | HCIStatusCode::INVALID_PARAMS |
! hasLTKInit() && ! hasLTKResp() | HCIStatusCode::INVALID_PARAMS |
BTDevice::isValid() == false | HCIStatusCode::INVALID_PARAMS |
BTDevice has already being connected | HCIStatusCode::CONNECTION_ALREADY_EXISTS |
BTDevice::connectLE() or BTDevice::connectBREDR() called | HCIStatusCode::CONNECTION_ALREADY_EXISTS |
BTDevice::setLongTermKeyInfo() failed | HCIStatusCode from BT adapter |
On failure and after BTDevice::setConnSecurity() has been performed, the BTSecurityLevel and SMPIOCapability pre-connect values have been written and must be set by the caller again.
device | the BTDevice for which this instances' LTK shall be applied |
Definition at line 364 of file SMPKeyBin.cpp.
Create a new SMPKeyBin instance based upon given BTDevice's BTSecurityLevel, SMPPairingState, PairingMode and LTK keys.
Returned SMPKeyBin shall be tested if valid via SMPKeyBin::isValid(), whether the retrieved data from BTDevice is consistent and hence having BTDevice is a well connected state.
device | the BTDevice from which all required data is derived |
Definition at line 46 of file SMPKeyBin.cpp.
|
static |
Create a new SMPKeyBin instance on the fly based upon given BTDevice's BTSecurityLevel, SMPPairingState, PairingMode and LTK keys.
If valid, instance is stored to a file denoted by path
and BTDevice::getAddressAndType()
.
Method returns false
if resulting SMPKeyBin is not SMPKeyBin::isValid().
Otherwise, method returns the SMPKeyBin::write() result.
device | the BTDevice from which all required data is derived |
path | the path for the stored SMPKeyBin file. |
overwrite | if true and file already exists, delete file first. If false and file exists, return false w/o writing. |
verbose_ | set to true to have detailed write processing logged to stderr, otherwise false |
true
if file has been successfully written, otherwise false
. Definition at line 79 of file SMPKeyBin.cpp.
|
inlineconstexprnoexcept |
Definition at line 227 of file SMPKeyBin.hpp.
|
inlineconstexprnoexcept |
Returns the creation timestamp in seconds since Unix epoch.
Definition at line 225 of file SMPKeyBin.hpp.
|
inlineconstexprnoexcept |
Definition at line 234 of file SMPKeyBin.hpp.
|
inlineconstexprnoexcept |
Definition at line 249 of file SMPKeyBin.hpp.
|
noexcept |
Returns the base filename, see SMPKeyBin API doc for naming scheme.
Definition at line 169 of file SMPKeyBin.cpp.
|
static |
Returns the base filename, see SMPKeyBin API doc for naming scheme.
Definition at line 174 of file SMPKeyBin.cpp.
|
inlinestatic |
Definition at line 292 of file SMPKeyBin.hpp.
|
inlineconstexprnoexcept |
Definition at line 229 of file SMPKeyBin.hpp.
|
inlineconstexprnoexcept |
Definition at line 233 of file SMPKeyBin.hpp.
|
inlineconstexprnoexcept |
Definition at line 248 of file SMPKeyBin.hpp.
|
inlineconstexprnoexcept |
Definition at line 228 of file SMPKeyBin.hpp.
|
inlineconstexprnoexcept |
Definition at line 222 of file SMPKeyBin.hpp.
|
inlineconstexprnoexcept |
Definition at line 219 of file SMPKeyBin.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Returns true
if.
isVersionValid() && isSizeValid() && not BTSecurityLevel::UNSET && not SMPIOCapability::UNSET && has valid LTK, if at all
Definition at line 272 of file SMPKeyBin.hpp.
|
inlineconstexprnoexcept |
bool SMPKeyBin::read | ( | const std::string & | fname | ) |
|
inlinestatic |
Create a new SMPKeyBin instance based upon stored file denoted by fname
.
Returned SMPKeyBin shall be tested if valid via SMPKeyBin::isValid(), whether the read() operation was successful and data is consistent.
If file is invalid, it is removed.
fname | full path of the stored SMPKeyBin file. |
verbose_ | set to true to have detailed read processing logged to stderr, otherwise false |
Definition at line 169 of file SMPKeyBin.hpp.
|
static |
Create a new SMPKeyBin instance on the fly based upon stored file denoted by path
and BTDevice::getAddressAndType(), i.e.
path/
+ getFileBasename().
Method returns HCIStatusCode::INVALID_PARAMS if resulting SMPKeyBin is not SMPKeyBin::isValid().
Otherwise, method returns the HCIStatusCode of SMPKeyBin::apply().
If key file is invalid or key could not be applied, i.e. not returning HCIStatusCode::SUCCESS, it is removed.
path | the path of the stored SMPKeyBin file. |
device | the BTDevice for which address the stored SMPKeyBin file will be read and applied to |
minSecLevel | minimum BTSecurityLevel the read SMPKeyBin::sec_level must be compliant to. If SMPKeyBin::sec_level < minSecLevel method removes the key file and returns HCIStatusCode::ENCRYPTION_MODE_NOT_ACCEPTED. |
verbose_ | set to true to have detailed read processing logged to stderr, otherwise false |
Definition at line 92 of file SMPKeyBin.cpp.
|
inlinestatic |
Definition at line 296 of file SMPKeyBin.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
noexcept |
Definition at line 120 of file SMPKeyBin.cpp.
|
noexcept |
Definition at line 189 of file SMPKeyBin.cpp.
|
staticconstexpr |
Definition at line 64 of file SMPKeyBin.hpp.