@@ -140,7 +140,6 @@ CHIP_ERROR ICDMonitoringEntry::SetKey(ByteSpan keyData)
140
140
Crypto::Symmetric128BitsKeyByteArray keyMaterial;
141
141
memcpy (keyMaterial, keyData.data (), sizeof (Crypto::Symmetric128BitsKeyByteArray));
142
142
143
- // TODO - Add function to set PSA key lifetime
144
143
ReturnErrorOnFailure (symmetricKeystore->CreateKey (keyMaterial, aesKeyHandle));
145
144
CHIP_ERROR error = symmetricKeystore->CreateKey (keyMaterial, hmacKeyHandle);
146
145
@@ -269,16 +268,26 @@ CHIP_ERROR ICDMonitoringTable::Set(uint16_t index, const ICDMonitoringEntry & en
269
268
VerifyOrReturnError (entry.keyHandleValid , CHIP_ERROR_INVALID_ARGUMENT);
270
269
271
270
ICDMonitoringEntry e (this ->mFabric , index );
272
- e.checkInNodeID = entry.checkInNodeID ;
273
- e.monitoredSubject = entry.monitoredSubject ;
274
- e.clientType = entry.clientType ;
275
- e.index = index ;
271
+ e.checkInNodeID = entry.checkInNodeID ;
272
+ e.monitoredSubject = entry.monitoredSubject ;
273
+ e.clientType = entry.clientType ;
274
+ e.index = index ;
275
+ e.symmetricKeystore = entry.symmetricKeystore ;
276
276
277
277
memcpy (e.aesKeyHandle .AsMutable <Crypto::Symmetric128BitsKeyByteArray>(),
278
278
entry.aesKeyHandle .As <Crypto::Symmetric128BitsKeyByteArray>(), sizeof (Crypto::Symmetric128BitsKeyByteArray));
279
279
memcpy (e.hmacKeyHandle .AsMutable <Crypto::Symmetric128BitsKeyByteArray>(),
280
280
entry.hmacKeyHandle .As <Crypto::Symmetric128BitsKeyByteArray>(), sizeof (Crypto::Symmetric128BitsKeyByteArray));
281
281
282
+ ReturnErrorOnFailure (e.symmetricKeystore ->PersistICDKey (e.aesKeyHandle ));
283
+ CHIP_ERROR error = e.symmetricKeystore ->PersistICDKey (e.hmacKeyHandle );
284
+ if (error != CHIP_NO_ERROR)
285
+ {
286
+ // If setting the persistence of the HmacKeyHandle failed, we need to delete the AesKeyHandle to avoid a key leak
287
+ e.symmetricKeystore ->DestroyKey (e.aesKeyHandle );
288
+ return error;
289
+ }
290
+
282
291
return e.Save (this ->mStorage );
283
292
}
284
293
0 commit comments