Skip to content

Commit 3f0daaf

Browse files
Implement setting key persitence for ICD server
1 parent d605569 commit 3f0daaf

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/app/icd/server/ICDMonitoringTable.cpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ CHIP_ERROR ICDMonitoringEntry::SetKey(ByteSpan keyData)
140140
Crypto::Symmetric128BitsKeyByteArray keyMaterial;
141141
memcpy(keyMaterial, keyData.data(), sizeof(Crypto::Symmetric128BitsKeyByteArray));
142142

143-
// TODO - Add function to set PSA key lifetime
144143
ReturnErrorOnFailure(symmetricKeystore->CreateKey(keyMaterial, aesKeyHandle));
145144
CHIP_ERROR error = symmetricKeystore->CreateKey(keyMaterial, hmacKeyHandle);
146145

@@ -269,16 +268,26 @@ CHIP_ERROR ICDMonitoringTable::Set(uint16_t index, const ICDMonitoringEntry & en
269268
VerifyOrReturnError(entry.keyHandleValid, CHIP_ERROR_INVALID_ARGUMENT);
270269

271270
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;
276276

277277
memcpy(e.aesKeyHandle.AsMutable<Crypto::Symmetric128BitsKeyByteArray>(),
278278
entry.aesKeyHandle.As<Crypto::Symmetric128BitsKeyByteArray>(), sizeof(Crypto::Symmetric128BitsKeyByteArray));
279279
memcpy(e.hmacKeyHandle.AsMutable<Crypto::Symmetric128BitsKeyByteArray>(),
280280
entry.hmacKeyHandle.As<Crypto::Symmetric128BitsKeyByteArray>(), sizeof(Crypto::Symmetric128BitsKeyByteArray));
281281

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+
282291
return e.Save(this->mStorage);
283292
}
284293

0 commit comments

Comments
 (0)