Skip to content

Commit ad973f2

Browse files
authored
Merge pull request ARMmbed#13594 from moshe-shahar/psa-gen-rot
PSA - Generate root of trust before accessing kvstore
2 parents 2691b4e + eaf9601 commit ad973f2

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/TESTS/its_ps/main.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "KVStore.h"
3737
#include "kv_config.h"
3838
#include "psa_storage_common_impl.h"
39-
#include "DeviceKey.h"
4039

4140
using namespace utest::v1;
4241
using namespace mbed;
@@ -219,9 +218,6 @@ utest::v1::status_t case_its_setup_handler(const Case *const source, const size_
219218
status = psa_ps_reset();
220219
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
221220
}
222-
#if DEVICEKEY_ENABLED
223-
DeviceKey::get_instance().generate_root_of_trust();
224-
#endif
225221
return greentea_case_setup_handler(source, index_of_case);
226222
}
227223

platform/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
}

platform/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)