@@ -258,13 +258,22 @@ CHIP_ERROR DefaultICDClientStorage::Load(FabricIndex fabricIndex, std::vector<IC
258
258
ReturnErrorOnFailure (reader.Next (TLV::ContextTag (ClientInfoTag::kMonitoredSubject )));
259
259
ReturnErrorOnFailure (reader.Get (clientInfo.monitored_subject ));
260
260
261
- // Shared key
262
- ReturnErrorOnFailure (reader.Next (TLV::ContextTag (ClientInfoTag::kSharedKey )));
263
- ByteSpan buf ;
264
- ReturnErrorOnFailure (reader.Get (buf ));
265
- VerifyOrReturnError (buf .size () == sizeof (Crypto::Symmetric128BitsKeyByteArray), CHIP_ERROR_INTERNAL);
266
- memcpy (clientInfo.shared_key .AsMutable <Crypto::Symmetric128BitsKeyByteArray>(), buf .data (),
261
+ // Aes key handle
262
+ ReturnErrorOnFailure (reader.Next (TLV::ContextTag (ClientInfoTag::kAesKeyHandle )));
263
+ ByteSpan aesBuf ;
264
+ ReturnErrorOnFailure (reader.Get (aesBuf ));
265
+ VerifyOrReturnError (aesBuf .size () == sizeof (Crypto::Symmetric128BitsKeyByteArray), CHIP_ERROR_INTERNAL);
266
+ memcpy (clientInfo.aes_key_handle .AsMutable <Crypto::Symmetric128BitsKeyByteArray>(), aesBuf .data (),
267
267
sizeof (Crypto::Symmetric128BitsKeyByteArray));
268
+
269
+ // Hmac key handle
270
+ ReturnErrorOnFailure (reader.Next (TLV::ContextTag (ClientInfoTag::kHmacKeyHandle )));
271
+ ByteSpan hmacBuf;
272
+ ReturnErrorOnFailure (reader.Get (hmacBuf));
273
+ VerifyOrReturnError (hmacBuf.size () == sizeof (Crypto::Symmetric128BitsKeyByteArray), CHIP_ERROR_INTERNAL);
274
+ memcpy (clientInfo.hmac_key_handle .AsMutable <Crypto::Symmetric128BitsKeyByteArray>(), hmacBuf.data (),
275
+ sizeof (Crypto::Symmetric128BitsKeyByteArray));
276
+
268
277
ReturnErrorOnFailure (reader.ExitContainer (ICDClientInfoType));
269
278
clientInfoVector.push_back (clientInfo);
270
279
}
@@ -285,12 +294,20 @@ CHIP_ERROR DefaultICDClientStorage::SetKey(ICDClientInfo & clientInfo, const Byt
285
294
Crypto::Symmetric128BitsKeyByteArray keyMaterial;
286
295
memcpy (keyMaterial, keyData.data (), sizeof (Crypto::Symmetric128BitsKeyByteArray));
287
296
288
- return mpKeyStore->CreateKey (keyMaterial, clientInfo.shared_key );
297
+ // TODO : Update key lifetime once creaKey method supports it.
298
+ ReturnErrorOnFailure (mpKeyStore->CreateKey (keyMaterial, clientInfo.aes_key_handle ));
299
+ CHIP_ERROR err = mpKeyStore->CreateKey (keyMaterial, clientInfo.hmac_key_handle );
300
+ if (err != CHIP_NO_ERROR)
301
+ {
302
+ mpKeyStore->DestroyKey (clientInfo.aes_key_handle );
303
+ }
304
+ return err;
289
305
}
290
306
291
307
void DefaultICDClientStorage::RemoveKey (ICDClientInfo & clientInfo)
292
308
{
293
- mpKeyStore->DestroyKey (clientInfo.shared_key );
309
+ mpKeyStore->DestroyKey (clientInfo.aes_key_handle );
310
+ mpKeyStore->DestroyKey (clientInfo.hmac_key_handle );
294
311
}
295
312
296
313
CHIP_ERROR DefaultICDClientStorage::SerializeToTlv (TLV::TLVWriter & writer, const std::vector<ICDClientInfo> & clientInfoVector)
@@ -306,8 +323,10 @@ CHIP_ERROR DefaultICDClientStorage::SerializeToTlv(TLV::TLVWriter & writer, cons
306
323
ReturnErrorOnFailure (writer.Put (TLV::ContextTag (ClientInfoTag::kStartICDCounter ), clientInfo.start_icd_counter ));
307
324
ReturnErrorOnFailure (writer.Put (TLV::ContextTag (ClientInfoTag::kOffset ), clientInfo.offset ));
308
325
ReturnErrorOnFailure (writer.Put (TLV::ContextTag (ClientInfoTag::kMonitoredSubject ), clientInfo.monitored_subject ));
309
- ByteSpan buf (clientInfo.shared_key .As <Crypto::Symmetric128BitsKeyByteArray>());
310
- ReturnErrorOnFailure (writer.Put (TLV::ContextTag (ClientInfoTag::kSharedKey ), buf));
326
+ ByteSpan aesBuf (clientInfo.aes_key_handle .As <Crypto::Symmetric128BitsKeyByteArray>());
327
+ ReturnErrorOnFailure (writer.Put (TLV::ContextTag (ClientInfoTag::kAesKeyHandle ), aesBuf));
328
+ ByteSpan hmacBuf (clientInfo.hmac_key_handle .As <Crypto::Symmetric128BitsKeyByteArray>());
329
+ ReturnErrorOnFailure (writer.Put (TLV::ContextTag (ClientInfoTag::kHmacKeyHandle ), hmacBuf));
311
330
ReturnErrorOnFailure (writer.EndContainer (ICDClientInfoContainerType));
312
331
}
313
332
return writer.EndContainer (arrayType);
0 commit comments