Skip to content

Commit 49215a0

Browse files
author
Moshe Shahar
committed
PSA - Generate root of trust before accessing kvstore
1 parent 890f056 commit 49215a0

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/services/storage/its/pits_impl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "pits_impl.h"
2424
#include "mbed_error.h"
2525
#include "mbed_toolchain.h"
26+
#include "DeviceKey.h"
2627

2728
using namespace mbed;
2829

@@ -71,6 +72,10 @@ static void its_init(void)
7172
error("Failed getting kvstore instance\n");
7273
}
7374

75+
#if DEVICEKEY_ENABLED
76+
DeviceKey::get_instance().generate_root_of_trust();
77+
#endif
78+
7479
psa_storage_handle_version(kvstore, ITS_VERSION_KEY, &version, its_version_migrate);
7580
initialized = true;
7681
}

features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/services/storage/ps/protected_storage.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "psa_storage_common_impl.h"
2525
#include "mbed_error.h"
2626
#include "mbed_toolchain.h"
27+
#include "DeviceKey.h"
2728

2829
using namespace mbed;
2930

@@ -69,6 +70,10 @@ static void ps_init(void)
6970
error("Failed getting kvstore instance\n");
7071
}
7172

73+
#if DEVICEKEY_ENABLED
74+
DeviceKey::get_instance().generate_root_of_trust();
75+
#endif
76+
7277
psa_storage_handle_version(kvstore, PS_VERSION_KEY, &version, ps_version_migrate);
7378
initialized = true;
7479
}
@@ -149,7 +154,7 @@ psa_status_t psa_ps_remove(psa_storage_uid_t uid)
149154

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

168-
return psa_storage_reset_impl(kvstore);
173+
psa_status_t psa_status = psa_storage_reset_impl(kvstore);
174+
if (psa_status == PSA_SUCCESS) {
175+
// force reinitialize to generate ROT and write version
176+
initialized = false;
177+
}
178+
return psa_status;
169179
}
170180

171181
#ifdef __cplusplus

0 commit comments

Comments
 (0)