Skip to content

Generate DeviceKey Root of Trust if SecureStore is enabled #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
#include <string.h>
#include "KVStore.h"
#include "kvstore_global_api.h"
#include "DeviceKey.h"

using namespace mbed;

#define EXAMPLE_KV_VALUE_LENGTH 64
#define EXAMPLE_KV_KEY_LENGTH 32
#define err_code(res) MBED_GET_ERROR_CODE(res)

#define STR_EXPAND(tok) #tok
#define STR(tok) STR_EXPAND(tok)
Comment on lines +31 to +32
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


void kv_store_global_api_example();

int main()
Expand Down Expand Up @@ -59,6 +63,11 @@ void kv_store_global_api_example()
res = kv_reset("/kv/");
printf("kv_reset -> %d\n", err_code(res));

if (strcmp(STR(MBED_CONF_STORAGE_STORAGE_TYPE), "TDB_EXTERNAL") == 0) {
Copy link
Contributor Author

@LDong-Arm LDong-Arm Nov 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In most projects, we normally do

#if (MBED_CONF_STORAGE_STORAGE_TYPE  == TDB_EXTERNAL)

but kv-config doesn't define TDB_EXTERNAL as a macro, so we need to convert MBED_CONF_STORAGE_STORAGE_TYPE to string for string comparison (like everywhere MBED_CONF_STORAGE_STORAGE_TYPE is checked in Mbed OS)...

The runtime check is probably not optimal in terms of code size (i.e. DeviceKey dependencies get pulled in even if the condition is not true). Unless the compiler compares the strings at compile time for optimisation?

res = DeviceKey::get_instance().generate_root_of_trust();
printf("DeviceKey::get_instance().generate_root_of_trust() -> %d\n", res);
}

/* Set First 'Dummy' Key/Value pair with unprotected clear value data */
printf("kv_set first dummy key\n");
res = kv_set(kv_key_in, kv_value_in, strlen(kv_value_in), 0);
Expand Down