Skip to content

Commit 1616225

Browse files
Address PR comments
1 parent 618e522 commit 1616225

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/crypto/PSASessionKeystore.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ CHIP_ERROR PSASessionKeystore::PersistICDKey(Aes128KeyHandle & key)
196196
CHIP_ERROR err;
197197
AesKeyAttributes attrs;
198198
psa_key_id_t previousKeyId = key.As<psa_key_id_t>();
199+
psa_key_attributes_t previousKeyAttrs;
200+
201+
psa_get_key_attributes(previousKeyId, &previousKeyAttrs);
202+
// Exit early if key is already persistent
203+
if (psa_get_key_lifetime(&previousKeyAttrs) == PSA_KEY_LIFETIME_PERSISTENT)
204+
{
205+
ExitNow(err = CHIP_NO_ERROR);
206+
}
199207

200208
SuccessOrExit(err = Crypto::FindFreeKeySlotInRange(key.AsMutable<psa_key_id_t>(),
201209
to_underlying(KeyIdOptional::ICDAesKeyRangeStart), kMaxICDClientKeys));
@@ -221,6 +229,14 @@ CHIP_ERROR PSASessionKeystore::PersistICDKey(Hmac128KeyHandle & key)
221229
CHIP_ERROR err;
222230
HmacKeyAttributes attrs;
223231
psa_key_id_t previousKeyId = key.As<psa_key_id_t>();
232+
psa_key_attributes_t previousKeyAttrs;
233+
234+
psa_get_key_attributes(previousKeyId, &previousKeyAttrs);
235+
// Exit early if key is already persistent
236+
if (psa_get_key_lifetime(&previousKeyAttrs) == PSA_KEY_LIFETIME_PERSISTENT)
237+
{
238+
ExitNow(err = CHIP_NO_ERROR);
239+
}
224240

225241
SuccessOrExit(err = Crypto::FindFreeKeySlotInRange(key.AsMutable<psa_key_id_t>(),
226242
to_underlying(KeyIdOptional::ICDHmacKeyRangeStart), kMaxICDClientKeys));

0 commit comments

Comments
 (0)