From fe9b558a2aaa51a28a196bee0a94601ff4958a96 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Fri, 9 Feb 2018 13:29:37 +0000 Subject: [PATCH] init random number on local device for OOB data --- features/FEATURE_BLE/ble/BLETypes.h | 7 ++++++ .../ble/generic/GenericSecurityManager.h | 2 ++ .../source/generic/GenericSecurityManager.cpp | 22 ++++++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/features/FEATURE_BLE/ble/BLETypes.h b/features/FEATURE_BLE/ble/BLETypes.h index a09563f633..9afee36507 100644 --- a/features/FEATURE_BLE/ble/BLETypes.h +++ b/features/FEATURE_BLE/ble/BLETypes.h @@ -315,6 +315,13 @@ struct octet_type_t { return _value; } + /** + * Return the pointer to the buffer holding data. + */ + uint8_t* buffer() const { + return _value; + } + /** * Size in byte of a data. */ diff --git a/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h b/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h index 3b5e72f6a4..3cfcafd92d 100644 --- a/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h +++ b/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h @@ -344,6 +344,7 @@ private: const csrk_t *csrk ); +#if defined(MBEDTLS_CMAC_C) /** * Generate local OOB data to be sent to the application which sends it to the peer. * @@ -352,6 +353,7 @@ private: void generate_secure_connections_oob( connection_handle_t connection ); +#endif /** * Updates the entry for the connection with OOB data presence. diff --git a/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp b/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp index 30a0c20956..e0f1927dcd 100644 --- a/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp +++ b/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp @@ -492,9 +492,11 @@ ble_error_t GenericSecurityManager::setOOBDataUsage( entry->attempt_oob = useOOB; entry->oob_mitm_protection = OOBProvidesMITM; +#if defined(MBEDTLS_CMAC_C) if (_public_keys_generated) { generate_secure_connections_oob(connection); } +#endif return BLE_ERROR_NONE; } @@ -640,28 +642,38 @@ void GenericSecurityManager::return_csrk_cb( ); } +#if defined(MBEDTLS_CMAC_C) void GenericSecurityManager::generate_secure_connections_oob( connection_handle_t connection ) { -#if defined(MBEDTLS_CMAC_C) address_t local_address; - /*TODO: get local address*/ oob_confirm_t confirm; + oob_rand_t random; + random_data_t random_data; + + /*TODO: get local address*/ + + _pal.get_random_data(random_data); + memcpy(random.buffer(), random_data.buffer(), random_data_t.size()); + _pal.get_random_data(random_data); + memcpy(random.buffer() + random_data_t.size(), &random_data.buffer(), random_data_t.size()); crypto_toolbox_f4( _db.get_public_key_x(), _db.get_public_key_y(), - _db.get_local_sc_oob_random(), + random, confirm ); _app_event_handler->oobGenerated( &local_address, - &_db.get_local_sc_oob_random(), + &random, &confirm ); -#endif + + _db.set_local_sc_oob_random(random); } +#endif void GenericSecurityManager::update_oob_presence(connection_handle_t connection) { SecurityEntry_t *entry = _db.get_entry(connection);