81 constexpr static const uint16_t
VERSION = (uint16_t)0b0101010101010101U + (uint16_t)6U;
86 uint64_t ts_creation_sec;
106 constexpr static const int byte_size_max = 205;
107 constexpr static const int byte_size_min = 31;
111 constexpr uint16_t calcSize()
const {
113 s +=
sizeof(version);
115 s +=
sizeof(ts_creation_sec);
116 s +=
sizeof(localRole);
117 s +=
sizeof(localAddress.
address);
118 s +=
sizeof(localAddress.
type);
119 s +=
sizeof(remoteAddress.
address);
120 s +=
sizeof(remoteAddress.
type);
121 s +=
sizeof(sec_level);
124 s +=
sizeof(keys_init);
125 s +=
sizeof(keys_resp);
128 s +=
sizeof(ltk_init);
131 s +=
sizeof(irk_init);
134 s +=
sizeof(csrk_init);
137 s +=
sizeof(lk_init);
141 s +=
sizeof(ltk_resp);
144 s +=
sizeof(irk_resp);
147 s +=
sizeof(csrk_resp);
150 s +=
sizeof(lk_resp);
155 static bool remove_impl(
const std::string& fname);
212 smpKeyBin.
read( fname );
237 static std::vector<SMPKeyBin>
readAll(
const std::string& dname,
const bool verbose_);
245 localRole(localRole_),
246 localAddress(
std::move(localAddress_)), remoteAddress(
std::move(remoteAddress_)),
247 sec_level(sec_level_), io_cap(io_cap_),
249 ltk_init(), irk_init(), csrk_init(), lk_init(),
250 ltk_resp(), irk_resp(), csrk_resp(), lk_resp(),
252 { size = calcSize(); }
258 localAddress(), remoteAddress(),
261 ltk_init(), irk_init(), csrk_init(), lk_init(),
262 ltk_resp(), irk_resp(), csrk_resp(), lk_resp(),
264 { size = calcSize(); }
267 constexpr uint16_t
getVersion() const noexcept {
return version;}
269 constexpr bool isSizeValid() const noexcept {
return calcSize() == size;}
270 constexpr uint16_t
getSize() const noexcept {
return size;}
353 constexpr bool getVerbose() const noexcept {
return verbose; }
367 const BDAddressAndType& responderAddress = local_is_responder ? localAddress : remoteAddress;
368 const BDAddressAndType& initiatorAddress = local_is_responder ? remoteAddress : localAddress;
381 std::string
toString() const noexcept;
396 static std::string
getFilename(
const std::string& path,
const BTDevice& remoteDevice) noexcept ;
399 return remove_impl(
getFilename(path, localAddress_, remoteAddress_) );
401 static bool remove(
const std::string& path,
const BTDevice& remoteDevice);
404 return getFilename(path, localAddress, remoteAddress);
410 bool write(
const std::string& path,
const bool overwrite)
const noexcept;
412 bool read(
const std::string& fname);
Unique Bluetooth EUI48 address and BDAddressType tuple.
BTDevice represents one remote Bluetooth device.
Storage for SMP keys including required connection parameter per local adapter and remote device.
constexpr bool hasLKInit() const noexcept
static std::string getFilename(const std::string &path, const BDAddressAndType &localAddress_, const BDAddressAndType &remoteAddress_) noexcept
constexpr const SMPLinkKey & getLKResp() const noexcept
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,...
constexpr bool getVerbose() const noexcept
void setLTKResp(const SMPLongTermKey &v) noexcept
static std::vector< SMPKeyBin > readAll(const std::string &dname, const bool verbose_)
constexpr bool hasLTKInit() const noexcept
void setLKResp(const SMPLinkKey &v) noexcept
static std::vector< SMPKeyBin > readAllForLocalAdapter(const BDAddressAndType &localAddress, const std::string &dname, const bool verbose_)
std::string toString() const noexcept
constexpr const SMPSignatureResolvingKey & getCSRKInit() const noexcept
constexpr bool hasIRKInit() const noexcept
constexpr uint64_t getCreationTime() const noexcept
Returns the creation timestamp in seconds since Unix epoch.
constexpr bool isValid() const noexcept
Returns true if.
void setVerbose(bool v) noexcept
constexpr const SMPIdentityResolvingKey & getIRKResp() const noexcept
constexpr SMPIOCapability getIOCap() const noexcept
static SMPKeyBin create(const BTDevice &device)
Create a new SMPKeyBin instance based upon given BTDevice's BTSecurityLevel, SMPPairingState,...
void setCSRKInit(const SMPSignatureResolvingKey &v) noexcept
static bool remove(const std::string &path, const BDAddressAndType &localAddress_, const BDAddressAndType &remoteAddress_)
constexpr uint16_t getSize() const noexcept
void setIRKResp(const SMPIdentityResolvingKey &v) noexcept
void setIRKInit(const SMPIdentityResolvingKey &v) noexcept
constexpr bool uses_SC() const noexcept
Return whether Secure Connection (SC) is being used via LTK keys.
constexpr bool hasLKResp() const noexcept
constexpr bool hasLTKResp() const noexcept
void setCSRKResp(const SMPSignatureResolvingKey &v) noexcept
static constexpr const uint16_t VERSION
constexpr bool hasCSRKInit() const noexcept
constexpr bool isSizeValid() const noexcept
bool write(const std::string &path, const bool overwrite) const noexcept
void setLTKInit(const SMPLongTermKey &v) noexcept
SMPKeyBin(BTRole localRole_, BDAddressAndType localAddress_, BDAddressAndType remoteAddress_, const BTSecurityLevel sec_level_, const SMPIOCapability io_cap_)
std::string getFilename(const std::string &path) const noexcept
std::string getFileBasename() const noexcept
Returns the base filename, see SMPKeyBin API doc for naming scheme.
bool remove(const std::string &path)
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,...
constexpr const SMPLongTermKey & getLTKResp() const noexcept
static SMPKeyBin read(const std::string &fname, const bool verbose_)
Create a new SMPKeyBin instance based upon stored file denoted by fname.
constexpr const SMPIdentityResolvingKey & getIRKInit() const noexcept
constexpr const BDAddressAndType & getLocalAddrAndType() const noexcept
Return the local adapter address.
void setLKInit(const SMPLinkKey &v) noexcept
constexpr const SMPLongTermKey & getLTKInit() const noexcept
constexpr const BDAddressAndType & getRemoteAddrAndType() const noexcept
Return the remote device address.
constexpr uint16_t getVersion() const noexcept
constexpr BTRole getLocalRole() const noexcept
Return the local adapter BTRole.
constexpr BTSecurityLevel getSecLevel() const noexcept
constexpr bool isVersionValid() const noexcept
constexpr bool hasIRKResp() const noexcept
constexpr bool hasCSRKResp() const noexcept
constexpr const SMPLinkKey & getLKInit() const noexcept
constexpr const SMPSignatureResolvingKey & getCSRKResp() const noexcept
SMPKeyType
SMP Key Type for Distribution, indicates keys distributed in the Transport Specific Key Distribution ...
SMPIOCapability
Vol 3, Part H, 2.3.2 IO capabilities.
@ LINK_KEY
SMP on the LE transport: Indicate that the device would like to derive the Link Key from the LTK.
@ SIGN_KEY
Indicates that the device shall distribute CSRK using the Signing Information command.
@ ENC_KEY
LE legacy pairing: Indicates device shall distribute LTK using the Encryption Information command,...
@ ID_KEY
Indicates that the device shall distribute IRK using the Identity Information command followed by its...
@ UNSET
Denoting unset value, i.e.
BTRole
Bluetooth roles from the perspective of the link layer (connection initiator).
BTSecurityLevel
Bluetooth Security Level.
constexpr bool is_set(const LE_Features mask, const LE_Features bit) noexcept
@ Slave
Slave or peripheral role, advertising and waiting for connections to accept.
@ UNSET
Security Level not set, value 0.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
uint64_t getWallClockSeconds() noexcept
Returns current wall-clock system time of day in seconds since Unix Epoch 00:00:00 UTC on 1 January 1...
SMP Identity Resolving Key, used for platform agnostic persistence.
EUI48 id_address
Identity Address for the IRK.
Local SMP Link Key, used for platform agnostic persistence, mapping to platform specific MgmtLoadLink...
constexpr bool isValid() const noexcept
SMP Long Term Key, used for platform agnostic persistence.
constexpr bool isValid() const noexcept
@ SC
Secure Connection used.
@ NONE
No specific property.
Property properties
SMPLongTermKey::Property bit mask.
SMP Signature Resolving Key, used for platform agnostic persistence.