Skip to content

Commit

Permalink
Followup for icd storage pr (#30732)
Browse files Browse the repository at this point in the history
-- Add icd key descriptions
-- Rename sharedKey to shared_key
  • Loading branch information
yunhanw-google authored and pull[bot] committed Jan 19, 2024
1 parent 72095d0 commit 3294696
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/app/icd/client/DefaultICDClientStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ CHIP_ERROR DefaultICDClientStorage::Load(FabricIndex fabricIndex, std::vector<IC
ByteSpan buf;
ReturnErrorOnFailure(reader.Get(buf));
VerifyOrReturnError(buf.size() == sizeof(Crypto::Aes128KeyByteArray), CHIP_ERROR_INTERNAL);
memcpy(clientInfo.sharedKey.AsMutable<Crypto::Aes128KeyByteArray>(), buf.data(), sizeof(Crypto::Aes128KeyByteArray));
memcpy(clientInfo.shared_key.AsMutable<Crypto::Aes128KeyByteArray>(), buf.data(), sizeof(Crypto::Aes128KeyByteArray));
ReturnErrorOnFailure(reader.ExitContainer(ICDClientInfoType));
clientInfoVector.push_back(clientInfo);
}
Expand All @@ -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<ICDClientInfo> & clientInfoVector)
Expand All @@ -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<Crypto::Aes128KeyByteArray>());
ByteSpan buf(clientInfo.shared_key.As<Crypto::Aes128KeyByteArray>());
ReturnErrorOnFailure(writer.Put(TLV::ContextTag(ClientInfoTag::kSharedKey), buf));
ReturnErrorOnFailure(writer.EndContainer(ICDClientInfoContainerType));
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()));
Expand Down
12 changes: 6 additions & 6 deletions src/app/icd/client/ICDClientInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(0);
Crypto::Aes128KeyHandle sharedKey = Crypto::Aes128KeyHandle();
uint32_t start_icd_counter = 0;
uint32_t offset = 0;
uint64_t monitored_subject = static_cast<uint64_t>(0);
Crypto::Aes128KeyHandle shared_key = Crypto::Aes128KeyHandle();

ICDClientInfo() {}
ICDClientInfo(const ICDClientInfo & other) { *this = other; }
Expand All @@ -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<Crypto::Aes128KeyByteArray>());
memcpy(sharedKey.AsMutable<Crypto::Aes128KeyByteArray>(), buf.data(), sizeof(Crypto::Aes128KeyByteArray));
ByteSpan buf(other.shared_key.As<Crypto::Aes128KeyByteArray>());
memcpy(shared_key.AsMutable<Crypto::Aes128KeyByteArray>(), buf.data(), sizeof(Crypto::Aes128KeyByteArray));
return *this;
}
};
Expand Down
4 changes: 4 additions & 0 deletions src/lib/support/DefaultStorageKeyAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3294696

Please sign in to comment.