Skip to content

Commit 43af68d

Browse files
Pataterdgreen-arm
authored andcommitted
attestation: Don't create attestation key twice
If psa_attestation_inject_key() is called twice, exit with a non-fatal error status without attempting to create another attestation key. The key already exists and doesn't need to be added again.
1 parent 5c81d19 commit 43af68d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

components/TARGET_PSA/services/attestation/COMPONENT_PSA_SRV_IMPL/psa_inject_attestation_key_impl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ psa_attestation_inject_key_impl(const uint8_t *key_data,
4242

4343
#if defined(MBEDTLS_ECP_C)
4444

45+
status = psa_open_key(key_id, &handle);
46+
if (status == PSA_SUCCESS) {
47+
/* The key already has been injected */
48+
goto exit;
49+
}
50+
4551
psa_set_key_usage_flags(&attributes, usage);
4652
psa_set_key_algorithm(&attributes, PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256));
4753
psa_set_key_type(&attributes, type);

0 commit comments

Comments
 (0)