Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
SMPKeyBin.cpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2021 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#include <cstring>
26#include <limits>
27#include <string>
28#include <memory>
29#include <cstdint>
30#include <cstdio>
31#include <fstream>
32#include <iostream>
33
34#include <jau/file_util.hpp>
35
36#include "SMPKeyBin.hpp"
37
38#include "BTDevice.hpp"
39#include "BTAdapter.hpp"
40
41using namespace direct_bt;
42
43static std::vector<std::string> get_file_list(const std::string& dname) {
44 std::vector<std::string> res;
46 ( void(*)(std::vector<std::string>*, const jau::fs::dir_item&) ) /* help template type deduction of function-ptr */
47 ( [](std::vector<std::string>* receiver, const jau::fs::dir_item& item) -> void {
48 if( 0 == item.basename().find("bd_") ) { // prefix checl
49 const jau::nsize_t suffix_pos = item.basename().size() - 4;
50 if( suffix_pos == item.basename().find(".key", suffix_pos) ) { // suffix check
51 receiver->push_back( item.path() ); // full path
52 }
53 }
54 } )
55 );
56 jau::fs::get_dir_content(dname, cs);
57 return res;
58}
59
60bool SMPKeyBin::remove_impl(const std::string& fname) {
61 return 0 == std::remove( fname.c_str() );
62}
63
65 const BTSecurityLevel sec_lvl = device.getConnSecurityLevel();
66 const SMPPairingState pstate = device.getPairingState();
67 const PairingMode pmode = device.getPairingMode(); // Skip PairingMode::PRE_PAIRED (write again)
68
69 SMPKeyBin smpKeyBin(device.getAdapter().getRole(), device.getAdapter().getAddressAndType(), device.getAddressAndType(),
70 device.getConnSecurityLevel(), device.getConnIOCapability());
71
72 if( ( BTSecurityLevel::NONE < sec_lvl && SMPPairingState::COMPLETED == pstate && PairingMode::NEGOTIATING < pmode ) ||
73 ( BTSecurityLevel::NONE == sec_lvl && SMPPairingState::NONE == pstate && PairingMode::NONE == pmode ) )
74 {
75 const SMPKeyType keys_resp = device.getAvailableSMPKeys(true /* responder */);
76 const SMPKeyType keys_init = device.getAvailableSMPKeys(false /* responder */);
77
78 if( is_set(keys_init, SMPKeyType::ENC_KEY) ) {
79 smpKeyBin.setLTKInit( device.getLongTermKey(false /* responder */) );
80 }
81 if( is_set(keys_resp, SMPKeyType::ENC_KEY) ) {
82 smpKeyBin.setLTKResp( device.getLongTermKey(true /* responder */) );
83 }
84
85 if( is_set(keys_init, SMPKeyType::ID_KEY) ) {
86 smpKeyBin.setIRKInit( device.getIdentityResolvingKey(false /* responder */) );
87 }
88 if( is_set(keys_resp, SMPKeyType::ID_KEY) ) {
89 smpKeyBin.setIRKResp( device.getIdentityResolvingKey(true /* responder */) );
90 }
91
92 if( is_set(keys_init, SMPKeyType::SIGN_KEY) ) {
93 smpKeyBin.setCSRKInit( device.getSignatureResolvingKey(false /* responder */) );
94 }
95 if( is_set(keys_resp, SMPKeyType::SIGN_KEY) ) {
96 smpKeyBin.setCSRKResp( device.getSignatureResolvingKey(true /* responder */) );
97 }
98
99 if( is_set(keys_init, SMPKeyType::LINK_KEY) ) {
100 smpKeyBin.setLKInit( device.getLinkKey(false /* responder */) );
101 }
102 if( is_set(keys_resp, SMPKeyType::LINK_KEY) ) {
103 smpKeyBin.setLKResp( device.getLinkKey(true /* responder */) );
104 }
105 } else {
106 smpKeyBin.size = 0; // explicitly mark invalid
107 }
108 return smpKeyBin;
109}
110
111bool SMPKeyBin::createAndWrite(const BTDevice& device, const std::string& path, const bool verbose_) {
112 SMPKeyBin smpKeyBin = SMPKeyBin::create(device);
113 if( smpKeyBin.isValid() ) {
114 smpKeyBin.setVerbose( verbose_ );
115 const bool overwrite = PairingMode::PRE_PAIRED != device.getPairingMode();
116 return smpKeyBin.write( path, overwrite );
117 } else {
118 if( verbose_ ) {
119 jau::fprintf_td(stderr, "Create SMPKeyBin: Invalid %s, %s\n", smpKeyBin.toString().c_str(), device.toString().c_str());
120 }
121 return false;
122 }
123}
124
125std::vector<SMPKeyBin> SMPKeyBin::readAll(const std::string& dname, const bool verbose_) {
126 std::vector<SMPKeyBin> res;
127 std::vector<std::string> fnames = get_file_list(dname);
128 for(const std::string& fname : fnames) {
129 SMPKeyBin f = read(fname, verbose_);
130 if( f.isValid() ) {
131 res.push_back(f);
132 }
133 }
134 return res;
135}
136
137std::vector<SMPKeyBin> SMPKeyBin::readAllForLocalAdapter(const BDAddressAndType& localAddress, const std::string& dname, const bool verbose_) {
138 std::vector<SMPKeyBin> res;
139 std::vector<SMPKeyBin> all = readAll(dname, verbose_);
140 for(const SMPKeyBin& f : all) {
141 if( localAddress == f.getLocalAddrAndType() ) {
142 res.push_back(f);
143 }
144 }
145 return res;
146}
147
148std::string SMPKeyBin::toString() const noexcept {
149 std::string res = "SMPKeyBin[local["+to_string(localRole)+", "+localAddress.toString()+"], remote "+remoteAddress.toString()+
150 ", SC "+std::to_string(uses_SC())+", sec "+to_string(sec_level)+", io "+to_string(io_cap)+
151 ", ";
152 if( isVersionValid() ) {
153 bool comma = false;
154 res += "Init[";
155 if( hasLTKInit() ) {
156 res += ltk_init.toString();
157 comma = true;
158 }
159 if( hasIRKInit() ) {
160 if( comma ) {
161 res += ", ";
162 }
163 res += irk_init.toString();
164 comma = true;
165 }
166 if( hasCSRKInit() ) {
167 if( comma ) {
168 res += ", ";
169 }
170 res += csrk_init.toString();
171 comma = true;
172 }
173 // NOLINTBEGIN(clang-analyzer-deadcode.DeadStores)
174 if( hasLKInit() ) {
175 if( comma ) {
176 res += ", ";
177 }
178 res += lk_init.toString();
179 comma = true;
180 }
181 comma = false;
182 res += "], Resp[";
183 if( hasLTKResp() ) {
184 res += ltk_resp.toString();
185 comma = true;
186 }
187 if( hasIRKResp() ) {
188 if( comma ) {
189 res += ", ";
190 }
191 res += irk_resp.toString();
192 comma = true;
193 }
194 if( hasCSRKResp() ) {
195 if( comma ) {
196 res += ", ";
197 }
198 res += csrk_resp.toString();
199 comma = true;
200 }
201 if( hasLKResp() ) {
202 if( comma ) {
203 res += ", ";
204 }
205 res += lk_resp.toString();
206 comma = true;
207 }
208 res += "], ";
209 // NOLINTEND(clang-analyzer-deadcode.DeadStores)
210 }
211 res += "ver["+jau::to_hexstring(version)+", ok "+std::to_string( isVersionValid() )+
212 "], size["+std::to_string(size);
213 if( verbose ) {
214 res += ", calc "+std::to_string( calcSize() );
215 }
216 res += ", valid "+std::to_string( isSizeValid() )+
217 "], ";
218 {
219 jau::fraction_timespec t0( (int64_t) std::min<uint64_t>(ts_creation_sec, std::numeric_limits<int64_t>::max()), 0 );
220 res += t0.to_iso8601_string();
221 }
222 res += ", valid "+std::to_string( isValid() )+"]";
223 return res;
224}
225
226std::string SMPKeyBin::getFileBasename() const noexcept {
227 std::string r("bd_"+localAddress.address.toString()+"_"+remoteAddress.address.toString()+std::to_string(number(remoteAddress.type))+".key");
228 auto it = std::remove( r.begin(), r.end(), ':');
229 r.erase(it, r.end());
230 return r;
231}
232std::string SMPKeyBin::getFileBasename(const BDAddressAndType& localAddress_, const BDAddressAndType& remoteAddress_) noexcept {
233 std::string r("bd_"+localAddress_.address.toString()+"_"+remoteAddress_.address.toString()+std::to_string(number(remoteAddress_.type))+".key");
234 auto it = std::remove( r.begin(), r.end(), ':');
235 r.erase(it, r.end());
236 return r;
237}
238std::string SMPKeyBin::getFilename(const std::string& path, const BTDevice& remoteDevice) noexcept {
239 return getFilename(path, remoteDevice.getAdapter().getAddressAndType(), remoteDevice.getAddressAndType());
240}
241
242bool SMPKeyBin::remove(const std::string& path, const BTDevice& remoteDevice) {
243 return remove(path, remoteDevice.getAdapter().getAddressAndType(), remoteDevice.getAddressAndType());
244}
245
246bool SMPKeyBin::write(const std::string& path, const bool overwrite) const noexcept {
247 if( !isValid() ) {
248 if( verbose ) {
249 jau::fprintf_td(stderr, "Write SMPKeyBin: Invalid (skipped) %s\n", toString().c_str());
250 }
251 return false;
252 }
253 const std::string fname = getFilename(path);
254 const jau::fs::file_stats fname_stat(fname);
255 if( fname_stat.exists() ) {
256 if( fname_stat.is_file() && overwrite ) {
257 if( !remove_impl(fname) ) {
258 jau::fprintf_td(stderr, "Write SMPKeyBin: Failed deletion of existing file %s, %s\n", fname_stat.to_string().c_str(), toString().c_str());
259 return false;
260 }
261 } else {
262 if( verbose ) {
263 jau::fprintf_td(stderr, "Write SMPKeyBin: Not overwriting existing %s, %s\n", fname_stat.to_string().c_str(), toString().c_str());
264 }
265 return false;
266 }
267 }
268 std::ofstream file(fname, std::ios::out | std::ios::binary);
269
270 if ( !file.good() || !file.is_open() ) {
271 jau::fprintf_td(stderr, "Write SMPKeyBin: Failed: File not open %s: %s\n", fname_stat.to_string().c_str(), toString().c_str());
272 file.close();
273 return false;
274 }
275 uint8_t buffer[8];
276
278 file.write((char*)buffer, sizeof(version));
279
281 file.write((char*)buffer, sizeof(size));
282
283 jau::put_uint64(buffer, ts_creation_sec, jau::lb_endian_t::little);
284 file.write((char*)buffer, sizeof(ts_creation_sec));
285
286 file.write((char*)&localRole, sizeof(localRole));
287 {
288 localAddress.address.put(buffer, jau::lb_endian_t::little);
289 file.write((char*)buffer, sizeof(localAddress.address.b));
290 }
291 file.write((char*)&localAddress.type, sizeof(localAddress.type));
292 {
293 remoteAddress.address.put(buffer, jau::lb_endian_t::little);
294 file.write((char*)buffer, sizeof(remoteAddress.address.b));
295 }
296 file.write((char*)&remoteAddress.type, sizeof(remoteAddress.type));
297 file.write((char*)&sec_level, sizeof(sec_level));
298 file.write((char*)&io_cap, sizeof(io_cap));
299
300 file.write((char*)&keys_init, sizeof(keys_init));
301 file.write((char*)&keys_resp, sizeof(keys_resp));
302
303 if( hasLTKInit() ) {
304 file.write((char*)&ltk_init, sizeof(ltk_init));
305 }
306 if( hasIRKInit() ) {
307 file.write((char*)&irk_init, sizeof(irk_init));
308 }
309 if( hasCSRKInit() ) {
310 file.write((char*)&csrk_init, sizeof(csrk_init));
311 }
312 if( hasLKInit() ) {
313 file.write((char*)&lk_init, sizeof(lk_init));
314 }
315
316 if( hasLTKResp() ) {
317 file.write((char*)&ltk_resp, sizeof(ltk_resp));
318 }
319 if( hasIRKResp() ) {
320 file.write((char*)&irk_resp, sizeof(irk_resp));
321 }
322 if( hasCSRKResp() ) {
323 file.write((char*)&csrk_resp, sizeof(csrk_resp));
324 }
325 if( hasLKResp() ) {
326 file.write((char*)&lk_resp, sizeof(lk_resp));
327 }
328
329 const bool res = file.good() && file.is_open();
330 if( res ) {
331 if( verbose ) {
332 jau::fprintf_td(stderr, "Write SMPKeyBin: Success: %s: %s\n", fname.c_str(), toString().c_str());
333 }
334 } else {
335 jau::fprintf_td(stderr, "Write SMPKeyBin: Failed: %s: %s\n", fname.c_str(), toString().c_str());
336 }
337 file.close();
338 return res;
339}
340
341bool SMPKeyBin::read(const std::string& fname) {
342 std::ifstream file(fname, std::ios::binary);
343 if ( !file.is_open() ) {
344 if( verbose ) {
345 jau::fprintf_td(stderr, "Read SMPKeyBin failed: %s\n", fname.c_str());
346 }
347 size = 0; // explicitly mark invalid
348 return false;
349 }
350 bool err = false;
351 uint8_t buffer[8];
352
353 file.read((char*)buffer, sizeof(version));
354 version = jau::get_uint16(buffer, jau::lb_endian_t::little);
355 err = file.fail();
356
357 if( !err ) {
358 file.read((char*)buffer, sizeof(size));
360 err = file.fail();
361 }
362 uint16_t remaining = size - sizeof(version) - sizeof(size);
363
364 if( !err && 8 <= remaining ) {
365 file.read((char*)buffer, sizeof(ts_creation_sec));
366 ts_creation_sec = jau::get_uint64(buffer, jau::lb_endian_t::little);
367 remaining -= 8;
368 err = file.fail();
369 } else {
370 err = true;
371 }
372 if( !err && 7+7+4 <= remaining ) {
373 file.read((char*)&localRole, sizeof(localRole));
374 {
375 file.read((char*)buffer, sizeof(localAddress.address.b));
376 localAddress.address = jau::EUI48(buffer, jau::lb_endian_t::little);
377 }
378 file.read((char*)&localAddress.type, sizeof(localAddress.type));
379 {
380 file.read((char*)buffer, sizeof(remoteAddress.address.b));
381 remoteAddress.address = jau::EUI48(buffer, jau::lb_endian_t::little);
382 }
383 file.read((char*)&remoteAddress.type, sizeof(remoteAddress.type));
384 file.read((char*)&sec_level, sizeof(sec_level));
385 file.read((char*)&io_cap, sizeof(io_cap));
386
387 file.read((char*)&keys_init, sizeof(keys_init));
388 file.read((char*)&keys_resp, sizeof(keys_resp));
389 remaining -= 7+7+4;
390 err = file.fail();
391 } else {
392 err = true;
393 }
394 remoteAddress.clearHash();
395
396 if( !err && hasLTKInit() ) {
397 if( sizeof(ltk_init) <= remaining ) {
398 file.read((char*)&ltk_init, sizeof(ltk_init));
399 remaining -= sizeof(ltk_init);
400 err = file.fail();
401 } else {
402 err = true;
403 }
404 }
405 if( !err && hasIRKInit() ) {
406 if( sizeof(irk_init) <= remaining ) {
407 file.read((char*)&irk_init, sizeof(irk_init));
408 remaining -= sizeof(irk_init);
409 err = file.fail();
410 } else {
411 err = true;
412 }
413 }
414 if( !err && hasCSRKInit() ) {
415 if( sizeof(csrk_init) <= remaining ) {
416 file.read((char*)&csrk_init, sizeof(csrk_init));
417 remaining -= sizeof(csrk_init);
418 err = file.fail();
419 } else {
420 err = true;
421 }
422 }
423 if( !err && hasLKInit() ) {
424 if( sizeof(lk_init) <= remaining ) {
425 file.read((char*)&lk_init, sizeof(lk_init));
426 remaining -= sizeof(lk_init);
427 err = file.fail();
428 } else {
429 err = true;
430 }
431 }
432
433 if( !err && hasLTKResp() ) {
434 if( sizeof(ltk_resp) <= remaining ) {
435 file.read((char*)&ltk_resp, sizeof(ltk_resp));
436 remaining -= sizeof(ltk_resp);
437 err = file.fail();
438 } else {
439 err = true;
440 }
441 }
442 if( !err && hasIRKResp() ) {
443 if( sizeof(irk_resp) <= remaining ) {
444 file.read((char*)&irk_resp, sizeof(irk_resp));
445 remaining -= sizeof(irk_resp);
446 err = file.fail();
447 } else {
448 err = true;
449 }
450 }
451 if( !err && hasCSRKResp() ) {
452 if( sizeof(csrk_resp) <= remaining ) {
453 file.read((char*)&csrk_resp, sizeof(csrk_resp));
454 remaining -= sizeof(csrk_resp);
455 err = file.fail();
456 } else {
457 err = true;
458 }
459 }
460 if( !err && hasLKResp() ) {
461 if( sizeof(lk_resp) <= remaining ) {
462 file.read((char*)&lk_resp, sizeof(lk_resp));
463 remaining -= sizeof(lk_resp);
464 err = file.fail();
465 } else {
466 err = true;
467 }
468 }
469
470 if( !err ) {
471 err = !isValid();
472 }
473
474 file.close();
475 if( err ) {
476 remove_impl( fname );
477 if( verbose ) {
478 jau::fprintf_td(stderr, "Read SMPKeyBin: Failed %s (removed): %s, remaining %u\n",
479 fname.c_str(), toString().c_str(), remaining);
480 }
481 size = 0; // explicitly mark invalid
482 } else {
483 if( verbose ) {
484 jau::fprintf_td(stderr, "Read SMPKeyBin: OK %s: %s, remaining %u\n",
485 fname.c_str(), toString().c_str(), remaining);
486 }
487 }
488 return err;
489}
490
static std::vector< std::string > get_file_list(const std::string &dname)
Definition: SMPKeyBin.cpp:43
Unique Bluetooth EUI48 address and BDAddressType tuple.
Definition: BTAddress.hpp:175
void clearHash()
Method clears the cached hash value.
Definition: BTAddress.hpp:334
std::string toString() const noexcept
Definition: BTTypes0.cpp:186
BTRole getRole() const noexcept
Return the current BTRole of this adapter.
Definition: BTAdapter.hpp:676
BDAddressAndType const & getAddressAndType() const noexcept
Returns the adapter's public BDAddressAndType, i.e.
Definition: BTAdapter.hpp:691
BTDevice represents one remote Bluetooth device.
Definition: BTDevice.hpp:81
SMPLongTermKey getLongTermKey(const bool responder) const noexcept
Returns a copy of the Long Term Key (LTK), valid after connection and SMP pairing has been completed.
Definition: BTDevice.cpp:1726
SMPSignatureResolvingKey getSignatureResolvingKey(const bool responder) const noexcept
Returns a copy of the Signature Resolving Key (CSRK), valid after connection and SMP pairing has been...
Definition: BTDevice.cpp:1775
constexpr BDAddressAndType const & getAddressAndType() const noexcept
Returns the devices' unique EUI48 address and type tuple, might be its initially reported (resolvable...
Definition: BTDevice.hpp:388
SMPPairingState getPairingState() const noexcept
Returns the current SMPPairingState.
Definition: BTDevice.cpp:2078
SMPIdentityResolvingKey getIdentityResolvingKey(const bool responder) const noexcept
Returns a copy of the Identity Resolving Key (IRK), valid after connection and SMP pairing has been c...
Definition: BTDevice.cpp:1744
PairingMode getPairingMode() const noexcept
Returns the current PairingMode used by the device.
Definition: BTDevice.cpp:2073
BTSecurityLevel getConnSecurityLevel() const noexcept
Return the BTSecurityLevel, determined when the connection is established.
Definition: BTDevice.cpp:1811
SMPKeyType getAvailableSMPKeys(const bool responder) const noexcept
Returns the available SMPKeyType mask for the responder (LL slave) or initiator (LL master).
Definition: BTDevice.cpp:1547
BTAdapter & getAdapter() const
Returns the managing adapter.
Definition: BTDevice.hpp:332
SMPIOCapability getConnIOCapability() const noexcept
Return the set SMPIOCapability value, determined when the connection is established.
Definition: BTDevice.cpp:1816
SMPLinkKey getLinkKey(const bool responder) const noexcept
Returns a copy of the Link Key (LK), valid after connection and SMP pairing has been completed.
Definition: BTDevice.cpp:1793
std::string toString() const noexcept override
Definition: BTDevice.hpp:470
Storage for SMP keys including required connection parameter per local adapter and remote device.
Definition: SMPKeyBin.hpp:79
constexpr bool hasLKInit() const noexcept
Definition: SMPKeyBin.hpp:296
static std::string getFilename(const std::string &path, const BDAddressAndType &localAddress_, const BDAddressAndType &remoteAddress_) noexcept
Definition: SMPKeyBin.hpp:393
void setLTKResp(const SMPLongTermKey &v) noexcept
Definition: SMPKeyBin.hpp:330
static std::vector< SMPKeyBin > readAll(const std::string &dname, const bool verbose_)
Definition: SMPKeyBin.cpp:125
constexpr bool hasLTKInit() const noexcept
Definition: SMPKeyBin.hpp:293
void setLKResp(const SMPLinkKey &v) noexcept
Definition: SMPKeyBin.hpp:345
static std::vector< SMPKeyBin > readAllForLocalAdapter(const BDAddressAndType &localAddress, const std::string &dname, const bool verbose_)
Definition: SMPKeyBin.cpp:137
std::string toString() const noexcept
Definition: SMPKeyBin.cpp:148
constexpr bool hasIRKInit() const noexcept
Definition: SMPKeyBin.hpp:294
constexpr bool isValid() const noexcept
Returns true if.
Definition: SMPKeyBin.hpp:364
void setVerbose(bool v) noexcept
Definition: SMPKeyBin.hpp:351
static SMPKeyBin create(const BTDevice &device)
Create a new SMPKeyBin instance based upon given BTDevice's BTSecurityLevel, SMPPairingState,...
Definition: SMPKeyBin.cpp:64
void setCSRKInit(const SMPSignatureResolvingKey &v) noexcept
Definition: SMPKeyBin.hpp:311
static bool remove(const std::string &path, const BDAddressAndType &localAddress_, const BDAddressAndType &remoteAddress_)
Definition: SMPKeyBin.hpp:398
void setIRKResp(const SMPIdentityResolvingKey &v) noexcept
Definition: SMPKeyBin.hpp:335
void setIRKInit(const SMPIdentityResolvingKey &v) noexcept
Definition: SMPKeyBin.hpp:306
constexpr bool uses_SC() const noexcept
Return whether Secure Connection (SC) is being used via LTK keys.
Definition: SMPKeyBin.hpp:285
constexpr bool hasLKResp() const noexcept
Definition: SMPKeyBin.hpp:325
constexpr bool hasLTKResp() const noexcept
Definition: SMPKeyBin.hpp:322
void setCSRKResp(const SMPSignatureResolvingKey &v) noexcept
Definition: SMPKeyBin.hpp:340
constexpr bool hasCSRKInit() const noexcept
Definition: SMPKeyBin.hpp:295
constexpr bool isSizeValid() const noexcept
Definition: SMPKeyBin.hpp:269
bool write(const std::string &path, const bool overwrite) const noexcept
Definition: SMPKeyBin.cpp:246
void setLTKInit(const SMPLongTermKey &v) noexcept
Definition: SMPKeyBin.hpp:301
std::string getFileBasename() const noexcept
Returns the base filename, see SMPKeyBin API doc for naming scheme.
Definition: SMPKeyBin.cpp:226
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,...
Definition: SMPKeyBin.cpp:111
static SMPKeyBin read(const std::string &fname, const bool verbose_)
Create a new SMPKeyBin instance based upon stored file denoted by fname.
Definition: SMPKeyBin.hpp:209
void setLKInit(const SMPLinkKey &v) noexcept
Definition: SMPKeyBin.hpp:316
constexpr bool isVersionValid() const noexcept
Definition: SMPKeyBin.hpp:266
constexpr bool hasIRKResp() const noexcept
Definition: SMPKeyBin.hpp:323
constexpr bool hasCSRKResp() const noexcept
Definition: SMPKeyBin.hpp:324
Representing a directory item split into dirname() and basename().
Definition: file_util.hpp:90
const std::string & basename() const noexcept
Return the basename, shall not be empty nor contain a dirname.
Definition: file_util.hpp:199
Platform agnostic representation of POSIX ::lstat() and ::stat() for a given pathname.
Definition: file_util.hpp:406
constexpr bool exists() const noexcept
Returns true if entity does not exist, exclusive bit.
Definition: file_util.hpp:648
constexpr bool is_file() const noexcept
Returns true if entity is a file, might be in combination with is_link().
Definition: file_util.hpp:639
std::string to_string() const noexcept
Returns a comprehensive string representation of this element.
Definition: file_util.cpp:859
Class template jau::function is a general-purpose static-polymorphic function wrapper.
constexpr uint16_t get_uint16(uint8_t const *buffer) noexcept
Returns a uint16_t value from the given byte address using packed_t to resolve a potential memory ali...
Definition: byte_util.hpp:661
constexpr void put_uint64(uint8_t *buffer, const uint64_t &v) noexcept
See put_uint16() for reference.
Definition: byte_util.hpp:716
constexpr void put_uint16(uint8_t *buffer, const uint16_t v) noexcept
Put the given uint16_t value into the given byte address using packed_t to resolve a potential memory...
Definition: byte_util.hpp:638
constexpr uint64_t get_uint64(uint8_t const *buffer) noexcept
See get_uint16() for reference.
Definition: byte_util.hpp:732
@ little
Identifier for little endian, equivalent to endian::little.
std::string to_string(const alphabet &v) noexcept
Definition: base_codec.hpp:97
SMPPairingState
SMP Pairing Process state definition.
Definition: SMPTypes.hpp:107
SMPKeyType
SMP Key Type for Distribution, indicates keys distributed in the Transport Specific Key Distribution ...
Definition: SMPTypes.hpp:415
@ COMPLETED
Phase 3: Key & value distribution completed by responding (slave) device sending SMPIdentInfoMsg (#1)...
@ NONE
No pairing in process.
@ 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...
std::string to_string(const DiscoveryPolicy v) noexcept
Definition: BTAdapter.cpp:58
BTSecurityLevel
Bluetooth Security Level.
Definition: BTTypes0.hpp:267
PairingMode
Bluetooth secure pairing mode.
Definition: BTTypes0.hpp:317
constexpr bool is_set(const LE_Features mask, const LE_Features bit) noexcept
Definition: BTTypes0.hpp:219
constexpr uint8_t number(const DiscoveryPolicy rhs) noexcept
Definition: BTAdapter.hpp:100
@ NONE
No encryption and no authentication.
@ PRE_PAIRED
Reusing encryption keys from previous pairing.
@ NEGOTIATING
Pairing mode in negotiating, i.e.
@ NONE
No pairing mode, implying no secure connections, no encryption and no MITM protection.
bool get_dir_content(const std::string &path, const consume_dir_item &digest) noexcept
Returns a list of directory elements excluding .
Definition: file_util.cpp:966
bool remove(const std::string &path, const traverse_options topts=traverse_options::none) noexcept
Remove the given path.
Definition: file_util.cpp:1173
jau::function< R(A...)> bind_capref(I *data_ptr, R(*func)(I *, A...)) noexcept
Bind given data by passing the captured reference (pointer) to the value and non-void function to an ...
constexpr T max(const T x, const T y) noexcept
Returns the maximum of two integrals (w/ branching) in O(1)
Definition: base_math.hpp:191
std::string to_hexstring(value_type const &v) noexcept
Produce a lower-case hexadecimal string representation of the given pointer.
int fprintf_td(const uint64_t elapsed_ms, FILE *stream, const char *format,...) noexcept
Convenient fprintf() invocation, prepending the given elapsed_ms timestamp.
Definition: debug.cpp:270
std::string toString() const noexcept
Definition: SMPTypes.hpp:636
std::string toString() const noexcept
Definition: SMPTypes.hpp:824
std::string toString() const noexcept
Definition: SMPTypes.hpp:552
std::string toString() const noexcept
Definition: SMPTypes.hpp:712
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
Definition: eui48.hpp:324
uint8_t b[6]
Definition: eui48.hpp:324
std::string toString() const noexcept
Definition: eui48.cpp:167
Timespec structure using int64_t for its components in analogy to struct timespec_t on 64-bit platfor...
std::string to_iso8601_string() const noexcept
Convenience string conversion interpreted since Unix Epoch in UTC to ISO 8601 YYYY-mm-ddTHH:MM:SS....
Definition: basic_types.cpp:81