diff --git a/src/app/icd/client/DefaultICDClientStorage.cpp b/src/app/icd/client/DefaultICDClientStorage.cpp index 3c6453ded8bbac..ce503706846434 100644 --- a/src/app/icd/client/DefaultICDClientStorage.cpp +++ b/src/app/icd/client/DefaultICDClientStorage.cpp @@ -261,7 +261,7 @@ CHIP_ERROR DefaultICDClientStorage::Load(FabricIndex fabricIndex, std::vector(), buf.data(), sizeof(Crypto::Aes128KeyByteArray)); + memcpy(clientInfo.shared_key.AsMutable(), buf.data(), sizeof(Crypto::Aes128KeyByteArray)); ReturnErrorOnFailure(reader.ExitContainer(ICDClientInfoType)); clientInfoVector.push_back(clientInfo); } @@ -281,7 +281,7 @@ CHIP_ERROR DefaultICDClientStorage::SetKey(ICDClientInfo & clientInfo, const Byt Crypto::Aes128KeyByteArray keyMaterial; memcpy(keyMaterial, keyData.data(), sizeof(Crypto::Aes128KeyByteArray)); - return mpKeyStore->CreateKey(keyMaterial, clientInfo.sharedKey); + return mpKeyStore->CreateKey(keyMaterial, clientInfo.shared_key); } CHIP_ERROR DefaultICDClientStorage::SerializeToTlv(TLV::TLVWriter & writer, const std::vector & clientInfoVector) @@ -297,7 +297,7 @@ CHIP_ERROR DefaultICDClientStorage::SerializeToTlv(TLV::TLVWriter & writer, cons ReturnErrorOnFailure(writer.Put(TLV::ContextTag(ClientInfoTag::kStartICDCounter), clientInfo.start_icd_counter)); ReturnErrorOnFailure(writer.Put(TLV::ContextTag(ClientInfoTag::kOffset), clientInfo.offset)); ReturnErrorOnFailure(writer.Put(TLV::ContextTag(ClientInfoTag::kMonitoredSubject), clientInfo.monitored_subject)); - ByteSpan buf(clientInfo.sharedKey.As()); + ByteSpan buf(clientInfo.shared_key.As()); ReturnErrorOnFailure(writer.Put(TLV::ContextTag(ClientInfoTag::kSharedKey), buf)); ReturnErrorOnFailure(writer.EndContainer(ICDClientInfoContainerType)); } @@ -392,7 +392,7 @@ CHIP_ERROR DefaultICDClientStorage::DeleteEntry(const ScopedNodeId & peerNode) { if (peerNode.GetNodeId() == it->peer_node.GetNodeId()) { - mpKeyStore->DestroyKey(it->sharedKey); + mpKeyStore->DestroyKey(it->shared_key); it = clientInfoVector.erase(it); break; } @@ -427,7 +427,7 @@ CHIP_ERROR DefaultICDClientStorage::DeleteAllEntries(FabricIndex fabricIndex) IgnoreUnusedVariable(clientInfoSize); for (auto & clientInfo : clientInfoVector) { - mpKeyStore->DestroyKey(clientInfo.sharedKey); + mpKeyStore->DestroyKey(clientInfo.shared_key); } ReturnErrorOnFailure( mpClientInfoStore->SyncDeleteKeyValue(DefaultStorageKeyAllocator::ICDClientInfoKey(fabricIndex).KeyName())); diff --git a/src/app/icd/client/ICDClientInfo.h b/src/app/icd/client/ICDClientInfo.h index 109d71d81373f4..4ab2aeec6dc8e5 100644 --- a/src/app/icd/client/ICDClientInfo.h +++ b/src/app/icd/client/ICDClientInfo.h @@ -30,10 +30,10 @@ namespace app { struct ICDClientInfo { ScopedNodeId peer_node; - uint32_t start_icd_counter = 0; - uint32_t offset = 0; - uint64_t monitored_subject = static_cast(0); - Crypto::Aes128KeyHandle sharedKey = Crypto::Aes128KeyHandle(); + uint32_t start_icd_counter = 0; + uint32_t offset = 0; + uint64_t monitored_subject = static_cast(0); + Crypto::Aes128KeyHandle shared_key = Crypto::Aes128KeyHandle(); ICDClientInfo() {} ICDClientInfo(const ICDClientInfo & other) { *this = other; } @@ -44,8 +44,8 @@ struct ICDClientInfo start_icd_counter = other.start_icd_counter; offset = other.offset; monitored_subject = other.monitored_subject; - ByteSpan buf(other.sharedKey.As()); - memcpy(sharedKey.AsMutable(), buf.data(), sizeof(Crypto::Aes128KeyByteArray)); + ByteSpan buf(other.shared_key.As()); + memcpy(shared_key.AsMutable(), buf.data(), sizeof(Crypto::Aes128KeyByteArray)); return *this; } }; diff --git a/src/lib/support/DefaultStorageKeyAllocator.h b/src/lib/support/DefaultStorageKeyAllocator.h index 21c0948a98493c..f5947015a59b66 100644 --- a/src/lib/support/DefaultStorageKeyAllocator.h +++ b/src/lib/support/DefaultStorageKeyAllocator.h @@ -233,8 +233,12 @@ class DefaultStorageKeyAllocator static StorageKeyName TSTimeZone() { return StorageKeyName::FromConst("g/ts/tz"); } static StorageKeyName TSDSTOffset() { return StorageKeyName::FromConst("g/ts/dsto"); } + // FabricICDClientInfoCounter is only used by DefaultICDClientStorage + // Records the number of ClientInfos for a particular fabric static StorageKeyName FabricICDClientInfoCounter(FabricIndex fabric) { return StorageKeyName::Formatted("f/%x/icdc", fabric); } + // ICDClientInfoKey is only used by DefaultICDClientStorage + // Stores/Loads all ICD clientInfos for a particular fabric static StorageKeyName ICDClientInfoKey(FabricIndex fabric) { return StorageKeyName::Formatted("f/%x/icdk", fabric); } // ICDFabricList is only used by DefaultICDClientStorage