Skip to content

PSA - Generate root of trust before accessing kvstore #13594

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 2 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "KVStore.h"
#include "kv_config.h"
#include "psa_storage_common_impl.h"
#include "DeviceKey.h"

using namespace utest::v1;
using namespace mbed;
Expand Down Expand Up @@ -219,9 +218,6 @@ utest::v1::status_t case_its_setup_handler(const Case *const source, const size_
status = psa_ps_reset();
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
}
#if DEVICEKEY_ENABLED
DeviceKey::get_instance().generate_root_of_trust();
#endif
return greentea_case_setup_handler(source, index_of_case);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "pits_impl.h"
#include "mbed_error.h"
#include "mbed_toolchain.h"
#include "DeviceKey.h"

using namespace mbed;

Expand Down Expand Up @@ -71,6 +72,10 @@ static void its_init(void)
error("Failed getting kvstore instance\n");
}

#if DEVICEKEY_ENABLED
DeviceKey::get_instance().generate_root_of_trust();
#endif

psa_storage_handle_version(kvstore, ITS_VERSION_KEY, &version, its_version_migrate);
initialized = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "psa_storage_common_impl.h"
#include "mbed_error.h"
#include "mbed_toolchain.h"
#include "DeviceKey.h"

using namespace mbed;

Expand Down Expand Up @@ -69,6 +70,10 @@ static void ps_init(void)
error("Failed getting kvstore instance\n");
}

#if DEVICEKEY_ENABLED
DeviceKey::get_instance().generate_root_of_trust();
#endif

psa_storage_handle_version(kvstore, PS_VERSION_KEY, &version, ps_version_migrate);
initialized = true;
}
Expand Down Expand Up @@ -149,7 +154,7 @@ psa_status_t psa_ps_remove(psa_storage_uid_t uid)

extern "C" psa_status_t psa_ps_reset()
{
// Do not call its_init here to avoid version check before reset
// Do not call ps_init here to avoid version check before reset
int ret = kv_init_storage_config();
if (ret) {
// Can only happen due to system misconfiguration.
Expand All @@ -165,7 +170,12 @@ extern "C" psa_status_t psa_ps_reset()
error("Failed getting kvstore instance\n");
}

return psa_storage_reset_impl(kvstore);
psa_status_t psa_status = psa_storage_reset_impl(kvstore);
if (psa_status == PSA_SUCCESS) {
// force reinitialize to generate ROT and write version
initialized = false;
}
return psa_status;
}

#ifdef __cplusplus
Expand Down