Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
direct_bt::SMPKeyBin Class Reference

Storage for SMP keys including required connection parameter per local adapter and remote device. More...

#include <SMPKeyBin.hpp>

Collaboration diagram for direct_bt::SMPKeyBin:

Public Member Functions

 SMPKeyBin ()
 
 SMPKeyBin (BTRole localRole_, BDAddressAndType localAddress_, BDAddressAndType remoteAddress_, const BTSecurityLevel sec_level_, const SMPIOCapability io_cap_)
 
constexpr uint64_t getCreationTime () const noexcept
 Returns the creation timestamp in seconds since Unix epoch. More...
 
constexpr const SMPSignatureResolvingKeygetCSRKInit () const noexcept
 
constexpr const SMPSignatureResolvingKeygetCSRKResp () const noexcept
 
std::string getFileBasename () const noexcept
 Returns the base filename, see SMPKeyBin API doc for naming scheme. More...
 
std::string getFilename (const std::string &path) const noexcept
 
constexpr SMPIOCapability getIOCap () const noexcept
 
constexpr const SMPIdentityResolvingKeygetIRKInit () const noexcept
 
constexpr const SMPIdentityResolvingKeygetIRKResp () const noexcept
 
constexpr const SMPLinkKeygetLKInit () const noexcept
 
constexpr const SMPLinkKeygetLKResp () const noexcept
 
constexpr const BDAddressAndTypegetLocalAddrAndType () const noexcept
 Return the local adapter address. More...
 
constexpr BTRole getLocalRole () const noexcept
 Return the local adapter BTRole. More...
 
constexpr const SMPLongTermKeygetLTKInit () const noexcept
 
constexpr const SMPLongTermKeygetLTKResp () const noexcept
 
constexpr const BDAddressAndTypegetRemoteAddrAndType () const noexcept
 Return the remote device address. More...
 
constexpr BTSecurityLevel getSecLevel () const noexcept
 
constexpr uint16_t getSize () const noexcept
 
constexpr bool getVerbose () const noexcept
 
constexpr uint16_t getVersion () const noexcept
 
constexpr bool hasCSRKInit () const noexcept
 
constexpr bool hasCSRKResp () const noexcept
 
constexpr bool hasIRKInit () const noexcept
 
constexpr bool hasIRKResp () const noexcept
 
constexpr bool hasLKInit () const noexcept
 
constexpr bool hasLKResp () const noexcept
 
constexpr bool hasLTKInit () const noexcept
 
constexpr bool hasLTKResp () const noexcept
 
constexpr bool isSizeValid () const noexcept
 
constexpr bool isValid () const noexcept
 Returns true if. More...
 
constexpr bool isVersionValid () const noexcept
 
bool read (const std::string &fname)
 
bool remove (const std::string &path)
 
void setCSRKInit (const SMPSignatureResolvingKey &v) noexcept
 
void setCSRKResp (const SMPSignatureResolvingKey &v) noexcept
 
void setIRKInit (const SMPIdentityResolvingKey &v) noexcept
 
void setIRKResp (const SMPIdentityResolvingKey &v) noexcept
 
void setLKInit (const SMPLinkKey &v) noexcept
 
void setLKResp (const SMPLinkKey &v) noexcept
 
void setLTKInit (const SMPLongTermKey &v) noexcept
 
void setLTKResp (const SMPLongTermKey &v) noexcept
 
void setVerbose (bool v) noexcept
 
std::string toString () const noexcept
 
constexpr bool uses_SC () const noexcept
 Return whether Secure Connection (SC) is being used via LTK keys. More...
 
bool write (const std::string &path, const bool overwrite) const noexcept
 

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 verbose_)
 Create a new SMPKeyBin instance on the fly based upon given BTDevice's BTSecurityLevel, SMPPairingState, PairingMode and LTK keys. More...
 
static std::string getFileBasename (const BDAddressAndType &localAddress_, const BDAddressAndType &remoteAddress_) noexcept
 Returns the base filename, see SMPKeyBin API doc for naming scheme. More...
 
static std::string getFilename (const std::string &path, const BDAddressAndType &localAddress_, const BDAddressAndType &remoteAddress_) noexcept
 
static std::string getFilename (const std::string &path, const BTDevice &remoteDevice) noexcept
 
static SMPKeyBin read (const std::string &fname, const bool verbose_)
 Create a new SMPKeyBin instance based upon stored file denoted by fname. More...
 
static SMPKeyBin read (const std::string &path, const BTDevice &device, const bool verbose_)
 Create a new SMPKeyBin instance based upon the given BTDevice's matching filename, see SMPKeyBin API doc for filename naming scheme. More...
 
static std::vector< SMPKeyBinreadAll (const std::string &dname, const bool verbose_)
 
static std::vector< SMPKeyBinreadAllForLocalAdapter (const BDAddressAndType &localAddress, const std::string &dname, const bool verbose_)
 
static bool remove (const std::string &path, const BDAddressAndType &localAddress_, const BDAddressAndType &remoteAddress_)
 
static bool remove (const std::string &path, const BTDevice &remoteDevice)
 

Static Public Attributes

static constexpr const uint16_t VERSION = (uint16_t)0b0101010101010101U + (uint16_t)6U
 

Detailed Description

Storage for SMP keys including required connection parameter per local adapter and remote device.

File format version 5.

Storage for a device's BDAddressAndType, its security connection setup BTSecurityLevel + SMPIOCapability and optionally the initiator and responder SMPLongTermKeyInfo (LTK), SMPSignatureResolvingKeyInfo (CSRK) and SMPLinkKeyInfo (LK) within one file.

Since the SMPLongTermKeyInfo (LTK), SMPSignatureResolvingKeyInfo (CSRK) and SMPLinkKeyInfo (LK) are optionally set depending on their availability per initiator and responder, implementation supports mixed mode for certain devices. E.g. LTK responder key only etc.

Data is stored in endian::little format, native to Bluetooth.

Filename as retrieved by SMPKeyBin::getFileBasename() has the following form bd_010203040506_C026DA01DAB11.key:

Definition at line 79 of file SMPKeyBin.hpp.

Constructor & Destructor Documentation

◆ SMPKeyBin() [1/2]

direct_bt::SMPKeyBin::SMPKeyBin ( BTRole  localRole_,
BDAddressAndType  localAddress_,
BDAddressAndType  remoteAddress_,
const BTSecurityLevel  sec_level_,
const SMPIOCapability  io_cap_ 
)
inline

Definition at line 240 of file SMPKeyBin.hpp.

◆ SMPKeyBin() [2/2]

direct_bt::SMPKeyBin::SMPKeyBin ( )
inline

Definition at line 254 of file SMPKeyBin.hpp.

Member Function Documentation

◆ create()

SMPKeyBin SMPKeyBin::create ( const BTDevice device)
static

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.

Parameters
devicethe BTDevice from which all required data is derived
Returns
a valid SMPKeyBin instance if properly connected, otherwise an invalid instance.
See also
BTDevice
isValid()

Definition at line 64 of file SMPKeyBin.cpp.

Here is the caller graph for this function:

◆ createAndWrite()

bool SMPKeyBin::createAndWrite ( const BTDevice device,
const std::string &  path,
const bool  verbose_ 
)
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().

If BTDevice::getPairingMode() is PairingMode::PRE_PAIRED, an existing file will not be overwritten. Otherwise, a new key is assumed and an existing file shall be overwritten.

Method returns false if resulting SMPKeyBin is not SMPKeyBin::isValid(). Otherwise, method returns the SMPKeyBin::write() result.

Parameters
devicethe BTDevice from which all required data is derived
paththe path for the stored SMPKeyBin file.
verbose_set to true to have detailed write processing logged to stderr, otherwise false
Returns
true if file has been successfully written, otherwise false.
See also
BTDevice
Create()
write()
isValid()

Definition at line 111 of file SMPKeyBin.cpp.

◆ read() [1/3]

static SMPKeyBin direct_bt::SMPKeyBin::read ( const std::string &  fname,
const bool  verbose_ 
)
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.

Parameters
fnamefull path of the stored SMPKeyBin file.
verbose_set to true to have detailed read processing logged to stderr, otherwise false
Returns
valid SMPKeyBin instance if file exist and read successfully, otherwise invalid SMPKeyBin instance.
See also
isValid()
read()

Definition at line 209 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ read() [2/3]

static SMPKeyBin direct_bt::SMPKeyBin::read ( const std::string &  path,
const BTDevice device,
const bool  verbose_ 
)
inlinestatic

Create a new SMPKeyBin instance based upon the given BTDevice's matching filename, see SMPKeyBin API doc for filename naming scheme.

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.

Parameters
pathdirectory for the stored SMPKeyBin file.
deviceBTDevice used to derive the filename, see getFilename()
verbose_set to true to have detailed read processing logged to stderr, otherwise false
Returns
valid SMPKeyBin instance if file exist and read successfully, otherwise invalid SMPKeyBin instance.
See also
getFilename()
isValid()
read()

Definition at line 233 of file SMPKeyBin.hpp.

◆ readAll()

std::vector< SMPKeyBin > SMPKeyBin::readAll ( const std::string &  dname,
const bool  verbose_ 
)
static

Definition at line 125 of file SMPKeyBin.cpp.

Here is the caller graph for this function:

◆ readAllForLocalAdapter()

std::vector< SMPKeyBin > SMPKeyBin::readAllForLocalAdapter ( const BDAddressAndType localAddress,
const std::string &  dname,
const bool  verbose_ 
)
static

Definition at line 137 of file SMPKeyBin.cpp.

Here is the caller graph for this function:

◆ isVersionValid()

constexpr bool direct_bt::SMPKeyBin::isVersionValid ( ) const
inlineconstexprnoexcept

Definition at line 266 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ getVersion()

constexpr uint16_t direct_bt::SMPKeyBin::getVersion ( ) const
inlineconstexprnoexcept

Definition at line 267 of file SMPKeyBin.hpp.

◆ isSizeValid()

constexpr bool direct_bt::SMPKeyBin::isSizeValid ( ) const
inlineconstexprnoexcept

Definition at line 269 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ getSize()

constexpr uint16_t direct_bt::SMPKeyBin::getSize ( ) const
inlineconstexprnoexcept

Definition at line 270 of file SMPKeyBin.hpp.

◆ getCreationTime()

constexpr uint64_t direct_bt::SMPKeyBin::getCreationTime ( ) const
inlineconstexprnoexcept

Returns the creation timestamp in seconds since Unix epoch.

Definition at line 273 of file SMPKeyBin.hpp.

◆ getLocalRole()

constexpr BTRole direct_bt::SMPKeyBin::getLocalRole ( ) const
inlineconstexprnoexcept

Return the local adapter BTRole.

Definition at line 276 of file SMPKeyBin.hpp.

◆ getLocalAddrAndType()

constexpr const BDAddressAndType & direct_bt::SMPKeyBin::getLocalAddrAndType ( ) const
inlineconstexprnoexcept

Return the local adapter address.

Definition at line 279 of file SMPKeyBin.hpp.

◆ getRemoteAddrAndType()

constexpr const BDAddressAndType & direct_bt::SMPKeyBin::getRemoteAddrAndType ( ) const
inlineconstexprnoexcept

Return the remote device address.

Definition at line 282 of file SMPKeyBin.hpp.

◆ uses_SC()

constexpr bool direct_bt::SMPKeyBin::uses_SC ( ) const
inlineconstexprnoexcept

Return whether Secure Connection (SC) is being used via LTK keys.

Definition at line 285 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ getSecLevel()

constexpr BTSecurityLevel direct_bt::SMPKeyBin::getSecLevel ( ) const
inlineconstexprnoexcept

Definition at line 290 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ getIOCap()

constexpr SMPIOCapability direct_bt::SMPKeyBin::getIOCap ( ) const
inlineconstexprnoexcept

Definition at line 291 of file SMPKeyBin.hpp.

◆ hasLTKInit()

constexpr bool direct_bt::SMPKeyBin::hasLTKInit ( ) const
inlineconstexprnoexcept

Definition at line 293 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ hasIRKInit()

constexpr bool direct_bt::SMPKeyBin::hasIRKInit ( ) const
inlineconstexprnoexcept

Definition at line 294 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ hasCSRKInit()

constexpr bool direct_bt::SMPKeyBin::hasCSRKInit ( ) const
inlineconstexprnoexcept

Definition at line 295 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ hasLKInit()

constexpr bool direct_bt::SMPKeyBin::hasLKInit ( ) const
inlineconstexprnoexcept

Definition at line 296 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ getLTKInit()

constexpr const SMPLongTermKey & direct_bt::SMPKeyBin::getLTKInit ( ) const
inlineconstexprnoexcept

Definition at line 297 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ getIRKInit()

constexpr const SMPIdentityResolvingKey & direct_bt::SMPKeyBin::getIRKInit ( ) const
inlineconstexprnoexcept

Definition at line 298 of file SMPKeyBin.hpp.

◆ getCSRKInit()

constexpr const SMPSignatureResolvingKey & direct_bt::SMPKeyBin::getCSRKInit ( ) const
inlineconstexprnoexcept

Definition at line 299 of file SMPKeyBin.hpp.

◆ getLKInit()

constexpr const SMPLinkKey & direct_bt::SMPKeyBin::getLKInit ( ) const
inlineconstexprnoexcept

Definition at line 300 of file SMPKeyBin.hpp.

◆ setLTKInit()

void direct_bt::SMPKeyBin::setLTKInit ( const SMPLongTermKey v)
inlinenoexcept

Definition at line 301 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ setIRKInit()

void direct_bt::SMPKeyBin::setIRKInit ( const SMPIdentityResolvingKey v)
inlinenoexcept

Definition at line 306 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ setCSRKInit()

void direct_bt::SMPKeyBin::setCSRKInit ( const SMPSignatureResolvingKey v)
inlinenoexcept

Definition at line 311 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ setLKInit()

void direct_bt::SMPKeyBin::setLKInit ( const SMPLinkKey v)
inlinenoexcept

Definition at line 316 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ hasLTKResp()

constexpr bool direct_bt::SMPKeyBin::hasLTKResp ( ) const
inlineconstexprnoexcept

Definition at line 322 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ hasIRKResp()

constexpr bool direct_bt::SMPKeyBin::hasIRKResp ( ) const
inlineconstexprnoexcept

Definition at line 323 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ hasCSRKResp()

constexpr bool direct_bt::SMPKeyBin::hasCSRKResp ( ) const
inlineconstexprnoexcept

Definition at line 324 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ hasLKResp()

constexpr bool direct_bt::SMPKeyBin::hasLKResp ( ) const
inlineconstexprnoexcept

Definition at line 325 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ getLTKResp()

constexpr const SMPLongTermKey & direct_bt::SMPKeyBin::getLTKResp ( ) const
inlineconstexprnoexcept

Definition at line 326 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ getIRKResp()

constexpr const SMPIdentityResolvingKey & direct_bt::SMPKeyBin::getIRKResp ( ) const
inlineconstexprnoexcept

Definition at line 327 of file SMPKeyBin.hpp.

◆ getCSRKResp()

constexpr const SMPSignatureResolvingKey & direct_bt::SMPKeyBin::getCSRKResp ( ) const
inlineconstexprnoexcept

Definition at line 328 of file SMPKeyBin.hpp.

◆ getLKResp()

constexpr const SMPLinkKey & direct_bt::SMPKeyBin::getLKResp ( ) const
inlineconstexprnoexcept

Definition at line 329 of file SMPKeyBin.hpp.

◆ setLTKResp()

void direct_bt::SMPKeyBin::setLTKResp ( const SMPLongTermKey v)
inlinenoexcept

Definition at line 330 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ setIRKResp()

void direct_bt::SMPKeyBin::setIRKResp ( const SMPIdentityResolvingKey v)
inlinenoexcept

Definition at line 335 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ setCSRKResp()

void direct_bt::SMPKeyBin::setCSRKResp ( const SMPSignatureResolvingKey v)
inlinenoexcept

Definition at line 340 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ setLKResp()

void direct_bt::SMPKeyBin::setLKResp ( const SMPLinkKey v)
inlinenoexcept

Definition at line 345 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ setVerbose()

void direct_bt::SMPKeyBin::setVerbose ( bool  v)
inlinenoexcept

Definition at line 351 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ getVerbose()

constexpr bool direct_bt::SMPKeyBin::getVerbose ( ) const
inlineconstexprnoexcept

Definition at line 353 of file SMPKeyBin.hpp.

◆ isValid()

constexpr bool direct_bt::SMPKeyBin::isValid ( ) const
inlineconstexprnoexcept

Returns true if.

isVersionValid() && isSizeValid() && not BTSecurityLevel::UNSET && not SMPIOCapability::UNSET && has valid LTK, if at all

Definition at line 364 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ toString()

std::string SMPKeyBin::toString ( ) const
noexcept

Definition at line 148 of file SMPKeyBin.cpp.

Here is the caller graph for this function:

◆ getFileBasename() [1/2]

std::string SMPKeyBin::getFileBasename ( ) const
noexcept

Returns the base filename, see SMPKeyBin API doc for naming scheme.

Definition at line 226 of file SMPKeyBin.cpp.

Here is the caller graph for this function:

◆ getFileBasename() [2/2]

std::string SMPKeyBin::getFileBasename ( const BDAddressAndType localAddress_,
const BDAddressAndType remoteAddress_ 
)
staticnoexcept

Returns the base filename, see SMPKeyBin API doc for naming scheme.

Definition at line 232 of file SMPKeyBin.cpp.

◆ getFilename() [1/3]

static std::string direct_bt::SMPKeyBin::getFilename ( const std::string &  path,
const BDAddressAndType localAddress_,
const BDAddressAndType remoteAddress_ 
)
inlinestaticnoexcept

Definition at line 393 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ getFilename() [2/3]

std::string SMPKeyBin::getFilename ( const std::string &  path,
const BTDevice remoteDevice 
)
staticnoexcept

Definition at line 238 of file SMPKeyBin.cpp.

◆ remove() [1/3]

static bool direct_bt::SMPKeyBin::remove ( const std::string &  path,
const BDAddressAndType localAddress_,
const BDAddressAndType remoteAddress_ 
)
inlinestatic

Definition at line 398 of file SMPKeyBin.hpp.

Here is the caller graph for this function:

◆ remove() [2/3]

bool SMPKeyBin::remove ( const std::string &  path,
const BTDevice remoteDevice 
)
static

Definition at line 242 of file SMPKeyBin.cpp.

◆ getFilename() [3/3]

std::string direct_bt::SMPKeyBin::getFilename ( const std::string &  path) const
inlinenoexcept

Definition at line 403 of file SMPKeyBin.hpp.

◆ remove() [3/3]

bool direct_bt::SMPKeyBin::remove ( const std::string &  path)
inline

Definition at line 406 of file SMPKeyBin.hpp.

◆ write()

bool SMPKeyBin::write ( const std::string &  path,
const bool  overwrite 
) const
noexcept

Definition at line 246 of file SMPKeyBin.cpp.

Here is the caller graph for this function:

◆ read() [3/3]

bool SMPKeyBin::read ( const std::string &  fname)

Definition at line 341 of file SMPKeyBin.cpp.

Member Data Documentation

◆ VERSION

constexpr const uint16_t direct_bt::SMPKeyBin::VERSION = (uint16_t)0b0101010101010101U + (uint16_t)6U
staticconstexpr

Definition at line 81 of file SMPKeyBin.hpp.


The documentation for this class was generated from the following files: