From 05f7685a79088f809a018b82ea51ea18d9accaae Mon Sep 17 00:00:00 2001 From: Paul Szczeanek Date: Wed, 3 Jun 2020 17:27:26 +0100 Subject: [PATCH] store local csrk and identity in the security db --- .../FEATURE_BLE/ble/generic/FileSecurityDb.h | 15 +++++++++++++++ features/FEATURE_BLE/ble/generic/SecurityDb.h | 16 ++++++++++++++++ .../source/generic/FileSecurityDb.cpp | 17 +++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/features/FEATURE_BLE/ble/generic/FileSecurityDb.h b/features/FEATURE_BLE/ble/generic/FileSecurityDb.h index 82361a7c4e..2dcdb05843 100644 --- a/features/FEATURE_BLE/ble/generic/FileSecurityDb.h +++ b/features/FEATURE_BLE/ble/generic/FileSecurityDb.h @@ -116,6 +116,21 @@ public: sign_count_t sign_counter ); + /* local csrk and identity */ + + virtual void set_local_csrk( + const csrk_t &csrk + ); + + virtual void set_local_identity( + const irk_t &irk, + const address_t &identity_address, + bool public_address + ); + + /* I am not overriding set_local_sign_counter to avoid constant filesystem writes, + * instead this is synced by sync (which is called on disconnection) */ + /* saving and loading from nvm */ virtual void restore(); diff --git a/features/FEATURE_BLE/ble/generic/SecurityDb.h b/features/FEATURE_BLE/ble/generic/SecurityDb.h index 9228dbd39d..f2243e5f49 100644 --- a/features/FEATURE_BLE/ble/generic/SecurityDb.h +++ b/features/FEATURE_BLE/ble/generic/SecurityDb.h @@ -425,6 +425,22 @@ public: _local_sign_counter = sign_counter; } + /* local identity */ + /** + * Update the local identity. + * + * @param[in] csrk new CSRK value + */ + virtual void set_local_identity( + const irk_t &irk, + const address_t &identity_address, + bool public_address + ) { + _local_identity.irk = irk; + _local_identity.identity_address = identity_address; + _local_identity.identity_address_is_public = public_address; + } + /* list management */ /** diff --git a/features/FEATURE_BLE/source/generic/FileSecurityDb.cpp b/features/FEATURE_BLE/source/generic/FileSecurityDb.cpp index 8e4b226278..abefb7f209 100644 --- a/features/FEATURE_BLE/source/generic/FileSecurityDb.cpp +++ b/features/FEATURE_BLE/source/generic/FileSecurityDb.cpp @@ -265,6 +265,22 @@ void FileSecurityDb::set_entry_peer_sign_counter( } } +void FileSecurityDb::set_local_csrk( + const csrk_t &csrk +) { + this->SecurityDb::set_local_csrk(csrk); + db_write(&_local_csrk, DB_OFFSET_LOCAL_CSRK); +} + +void FileSecurityDb::set_local_identity( + const irk_t &irk, + const address_t &identity_address, + bool public_address +) { + this->SecurityDb::set_local_identity(irk, identity_address, public_address); + db_write(&_local_identity, DB_OFFSET_LOCAL_IDENTITY); +} + /* saving and loading from nvm */ void FileSecurityDb::restore() { @@ -299,6 +315,7 @@ void FileSecurityDb::sync(entry_handle_t db_handle) { db_write(&entry->peer_sign_counter, entry->file_offset + DB_STORE_OFFSET_PEER_SIGNING_COUNT); db_write(&entry->flags, entry->file_offset + DB_STORE_OFFSET_FLAGS); + db_write(&_local_sign_counter, DB_OFFSET_LOCAL_SIGN_COUNT); } void FileSecurityDb::set_restore(bool reload) {