Skip to content

Commit 05f7685

Browse files
store local csrk and identity in the security db
1 parent 94a6cac commit 05f7685

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

features/FEATURE_BLE/ble/generic/FileSecurityDb.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ class FileSecurityDb : public SecurityDb {
116116
sign_count_t sign_counter
117117
);
118118

119+
/* local csrk and identity */
120+
121+
virtual void set_local_csrk(
122+
const csrk_t &csrk
123+
);
124+
125+
virtual void set_local_identity(
126+
const irk_t &irk,
127+
const address_t &identity_address,
128+
bool public_address
129+
);
130+
131+
/* I am not overriding set_local_sign_counter to avoid constant filesystem writes,
132+
* instead this is synced by sync (which is called on disconnection) */
133+
119134
/* saving and loading from nvm */
120135

121136
virtual void restore();

features/FEATURE_BLE/ble/generic/SecurityDb.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,22 @@ class SecurityDb {
425425
_local_sign_counter = sign_counter;
426426
}
427427

428+
/* local identity */
429+
/**
430+
* Update the local identity.
431+
*
432+
* @param[in] csrk new CSRK value
433+
*/
434+
virtual void set_local_identity(
435+
const irk_t &irk,
436+
const address_t &identity_address,
437+
bool public_address
438+
) {
439+
_local_identity.irk = irk;
440+
_local_identity.identity_address = identity_address;
441+
_local_identity.identity_address_is_public = public_address;
442+
}
443+
428444
/* list management */
429445

430446
/**

features/FEATURE_BLE/source/generic/FileSecurityDb.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,22 @@ void FileSecurityDb::set_entry_peer_sign_counter(
265265
}
266266
}
267267

268+
void FileSecurityDb::set_local_csrk(
269+
const csrk_t &csrk
270+
) {
271+
this->SecurityDb::set_local_csrk(csrk);
272+
db_write(&_local_csrk, DB_OFFSET_LOCAL_CSRK);
273+
}
274+
275+
void FileSecurityDb::set_local_identity(
276+
const irk_t &irk,
277+
const address_t &identity_address,
278+
bool public_address
279+
) {
280+
this->SecurityDb::set_local_identity(irk, identity_address, public_address);
281+
db_write(&_local_identity, DB_OFFSET_LOCAL_IDENTITY);
282+
}
283+
268284
/* saving and loading from nvm */
269285

270286
void FileSecurityDb::restore() {
@@ -299,6 +315,7 @@ void FileSecurityDb::sync(entry_handle_t db_handle) {
299315

300316
db_write(&entry->peer_sign_counter, entry->file_offset + DB_STORE_OFFSET_PEER_SIGNING_COUNT);
301317
db_write(&entry->flags, entry->file_offset + DB_STORE_OFFSET_FLAGS);
318+
db_write(&_local_sign_counter, DB_OFFSET_LOCAL_SIGN_COUNT);
302319
}
303320

304321
void FileSecurityDb::set_restore(bool reload) {

0 commit comments

Comments
 (0)