Skip to content

Commit

Permalink
samples: matter: Set custom keystore manager during the init.
Browse files Browse the repository at this point in the history
We need to set a custom keystore manager in Matter server
while using KMU and assign the KMUKeyAllocator.

Signed-off-by: Arkadiusz Balys <[email protected]>
  • Loading branch information
ArekBalysNordic committed Jan 30, 2025
1 parent 74eb329 commit c7c990a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
18 changes: 18 additions & 0 deletions samples/matter/common/src/app/matter_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
#include <ram_pwrdn.h>
#endif

#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
#include <platform/nrfconnect/KMUKeyAllocator.h>
#endif

#include <app/InteractionModelEngine.h>
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/server/OnboardingCodesUtil.h>
Expand All @@ -72,6 +76,10 @@ Clusters::NetworkCommissioning::Instance Nrf::Matter::InitData::sWiFiCommissioni
chip::Crypto::PSAOperationalKeystore Nrf::Matter::InitData::sOperationalKeystoreDefault{};
#endif

#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
chip::DeviceLayer::KMUSessionKeystore Nrf::Matter::InitData::sKMUSessionKeystoreDefault{};
#endif

#ifdef CONFIG_CHIP_FACTORY_DATA
FactoryDataProvider<InternalFlashFactoryData> Nrf::Matter::InitData::sFactoryDataProviderDefault{};
#endif
Expand All @@ -87,6 +95,9 @@ Nrf::Matter::InitData sLocalInitData{ .mNetworkingInstance = nullptr,
#endif
#ifdef CONFIG_CHIP_CRYPTO_PSA
.mOperationalKeyStore = nullptr,
#endif
#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
.mSessionKeystore = nullptr,
#endif
.mPreServerInitClbk = nullptr,
.mPostServerInitClbk = nullptr };
Expand Down Expand Up @@ -277,6 +288,13 @@ void DoInitChipServer(intptr_t /* unused */)
sLocalInitData.mServerInitParams->operationalKeystore = sLocalInitData.mOperationalKeyStore;
#endif

/* Set KMUKeyAllocator for devices that supports KMU */
#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
static KMUKeyAllocator kmuAllocator;
Crypto::SetPSAKeyAllocator(&kmuAllocator);
sLocalInitData.mServerInitParams->sessionKeystore = sLocalInitData.mSessionKeystore;
#endif

VerifyOrReturn(sLocalInitData.mServerInitParams, LOG_ERR("No valid server initialization parameters"));
sInitResult = sLocalInitData.mServerInitParams->InitializeStaticResourcesBeforeServerInit();
VerifyInitResultOrReturn(sInitResult, "InitializeStaticResourcesBeforeServerInit() failed");
Expand Down
11 changes: 11 additions & 0 deletions samples/matter/common/src/app/matter_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <crypto/PSAOperationalKeystore.h>
#endif

#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
#include <platform/nrfconnect/KMUSessionKeystore.h>
#endif

#ifdef CONFIG_CHIP_FACTORY_DATA
#include <platform/nrfconnect/FactoryDataProvider.h>
#else
Expand Down Expand Up @@ -58,6 +62,10 @@ struct InitData {
#ifdef CONFIG_CHIP_CRYPTO_PSA
/** @brief Pointer to the user provided OperationalKeystore implementation. */
chip::Crypto::OperationalKeystore *mOperationalKeyStore{ &sOperationalKeystoreDefault };
#endif
#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
/** @brief Pointer to the user provided SessionKeystore implementation. */
chip::Crypto::SessionKeystore *mSessionKeystore{ &sKMUSessionKeystoreDefault };
#endif
/** @brief Custom code to execute in the Matter main event loop before the server initialization. */
CustomInit mPreServerInitClbk{ nullptr };
Expand All @@ -77,6 +85,9 @@ struct InitData {
#ifdef CONFIG_CHIP_CRYPTO_PSA
static chip::Crypto::PSAOperationalKeystore sOperationalKeystoreDefault;
#endif
#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
static chip::DeviceLayer::KMUSessionKeystore sKMUSessionKeystoreDefault;
#endif
};

/**
Expand Down
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ manifest:
- name: matter
repo-path: sdk-connectedhomeip
path: modules/lib/matter
revision: c63ff3ffd71d97ab36d9231fe8bd1ade1674e49e
revision: pull/539/head
west-commands: scripts/west/west-commands.yml
submodules:
- name: nlio
Expand Down

0 comments on commit c7c990a

Please sign in to comment.