Skip to content

Commit c116004

Browse files
samples: matter: Set custom keystore manager during the init.
We need to set a custom keystore manager in Matter server while using KMU and assign the KMUKeyAllocator. Signed-off-by: Arkadiusz Balys <arkadiusz.balys@nordicsemi.no>
1 parent 5c21704 commit c116004

File tree

5 files changed

+105
-1
lines changed

5 files changed

+105
-1
lines changed

doc/nrf/protocols/matter/end_product/security.rst

+74
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,80 @@ This is a reference configuration that can be modified in the production firmwar
161161
To use the Oberon backend for specific cryptographic operations supported by both drivers, disable those operations in the CRACEN driver, as it takes priority when both are enabled.
162162
See the :ref:`nrf_security_drivers` documentation for more information.
163163
164+
.. _matter_platforms_security_kmu:
165+
166+
nRF54L15 Key Management Unit (KMU)
167+
==================================
168+
169+
nRF54l15 devices contains :ref:`ug_nrf54l_crypto_kmu_cracen_peripherals` that can be used to store cryptographic keys in Matter.
170+
In this solution, the keys are stored within the available slots in the :ref:`ug_nrf54l_crypto_kmu_slots` range that are not reserved for current and future |NCS| use cases.
171+
172+
The default slots range used for Matter is from ``100`` to ``180``, not including the DAC private key.
173+
To see configuration for DAC private key, see the :ref:`matter_platforms_security_dac_priv_key_kmu`.
174+
You can change the slots range by setting the :kconfig:option:`CONFIG_CHIP_KMU_SLOT_RANGE_START` and :kconfig:option:`CONFIG_CHIP_KMU_SLOT_RANGE_END` Kconfig options.
175+
For now, we use the Raw usage scheme defined in the :ref:`ug_nrf54l_crypto_kmu_key_usage_schemes` section.
176+
177+
To use this feature set the :kconfig:option:`CONFIG_CHIP_STORE_KEYS_IN_KMU` Kconfig option to ``y``, and switch to the ``KMUKeyAllocator`` by calling the ``chip::Crypto::SetPSAKeyAllocator`` method in your code during the Matter stack initialization.
178+
179+
For example:
180+
181+
.. code-block:: cpp
182+
183+
#include <platform/nrfconnect/KMUKeyAllocator.h>
184+
185+
static KMUKeyAllocator kmuAllocator;
186+
Crypto::SetPSAKeyAllocator(&kmuAllocator);
187+
188+
See the :file:`samples/matter/common/src/app/matter_init.cpp` to see an usage example.
189+
190+
Due to limited slots available in the KMU, the maximum number of Matter fabric is limited.
191+
The following table shows the current number of slots used by Matter:
192+
193+
.. list-table:: KMU slots used by Matter crypto materials
194+
:widths: auto
195+
:header-rows: 1
196+
197+
* - Crypto material in Matter
198+
- Key type
199+
- Number of slots needed per key
200+
- Multiplication
201+
- Minimal keys amount
202+
* - Node Operational Certificate (NOC) private key
203+
- ECC secp256r1 key pair
204+
- 2
205+
- Per Matter Fabric
206+
- 5 (5 Matter fabrics per device)
207+
* - Intermittently Connected Device (ICD) Token
208+
- HMAC SHA-256 128-bit keys
209+
- 1
210+
- Per ICD user
211+
- 10 (2 ICD users per Matter Fabric)
212+
* - Intermittently Connected Device (ICD) symmetric Key
213+
- AES 128-bit keys
214+
- 1
215+
- Per ICD user
216+
- 10 (2 ICD users per Matter Fabric)
217+
* Device Attestation Certificate (DAC) private key
218+
- ECC secp256r1 key pair
219+
- 2
220+
- Per device
221+
- 1
222+
* - Group key [3]_
223+
- AES 128-bit keys
224+
- 1
225+
- Per group
226+
- 15 (3 groups per Matter Fabric)
227+
228+
.. [3] Group keys are not stored in the KMU yet, but it is planned to be stored in the future.
229+
A key may be shared between multiple groups, so the number of slots needed for group keys may be lower than the number of groups.
230+
We assume 3 grup keys per Matter Fabric.
231+
232+
According to the table you can calculate the maximum number of Matter fabrics that can be stored in the KMU.
233+
The minimal number of slots needed for the crypto materials is 46, including the DAC private key.
234+
A single Matter fabric requires at least 9 KMU slots.
235+
The default values for the KMU slots range allows to store 8 Matter Fabrics.
236+
You can extend the range, but you must ensure that the range does not overlap with the reserved slots.
237+
164238
.. _matter_platforms_security_dac_priv_key:
165239

166240
Storing Device Attestation Certificate private key

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Matter
163163
* A description for the new :ref:`ug_matter_gs_tools_matter_west_commands_append` within the :ref:`ug_matter_gs_tools_matter_west_commands` page.
164164
* New arguments to the :ref:`ug_matter_gs_tools_matter_west_commands_zap_tool_gui` to provide a custom cache directory and add new clusters to Matter Data Model.
165165
* :ref:`ug_matter_debug_snippet`.
166+
* Storing Matter key materials in the :ref:`matter_platforms_security_kmu`.
166167

167168
* Disabled the :ref:`mpsl` before performing factory reset to speed up the process.
168169

samples/matter/common/src/app/matter_init.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
#include <ram_pwrdn.h>
4747
#endif
4848

49+
#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
50+
#include <platform/nrfconnect/KMUKeyAllocator.h>
51+
#endif
52+
4953
#include <app/InteractionModelEngine.h>
5054
#include <app/clusters/network-commissioning/network-commissioning.h>
5155
#include <credentials/examples/DeviceAttestationCredsExample.h>
@@ -72,6 +76,10 @@ Clusters::NetworkCommissioning::Instance Nrf::Matter::InitData::sWiFiCommissioni
7276
chip::Crypto::PSAOperationalKeystore Nrf::Matter::InitData::sOperationalKeystoreDefault{};
7377
#endif
7478

79+
#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
80+
chip::DeviceLayer::KMUSessionKeystore Nrf::Matter::InitData::sKMUSessionKeystoreDefault{};
81+
#endif
82+
7583
#ifdef CONFIG_CHIP_FACTORY_DATA
7684
FactoryDataProvider<InternalFlashFactoryData> Nrf::Matter::InitData::sFactoryDataProviderDefault{};
7785
#endif
@@ -87,6 +95,9 @@ Nrf::Matter::InitData sLocalInitData{ .mNetworkingInstance = nullptr,
8795
#endif
8896
#ifdef CONFIG_CHIP_CRYPTO_PSA
8997
.mOperationalKeyStore = nullptr,
98+
#endif
99+
#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
100+
.mSessionKeystore = nullptr,
90101
#endif
91102
.mPreServerInitClbk = nullptr,
92103
.mPostServerInitClbk = nullptr };
@@ -277,6 +288,13 @@ void DoInitChipServer(intptr_t /* unused */)
277288
sLocalInitData.mServerInitParams->operationalKeystore = sLocalInitData.mOperationalKeyStore;
278289
#endif
279290

291+
/* Set KMUKeyAllocator for devices that supports KMU */
292+
#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
293+
static KMUKeyAllocator kmuAllocator;
294+
Crypto::SetPSAKeyAllocator(&kmuAllocator);
295+
sLocalInitData.mServerInitParams->sessionKeystore = sLocalInitData.mSessionKeystore;
296+
#endif
297+
280298
VerifyOrReturn(sLocalInitData.mServerInitParams, LOG_ERR("No valid server initialization parameters"));
281299
sInitResult = sLocalInitData.mServerInitParams->InitializeStaticResourcesBeforeServerInit();
282300
VerifyInitResultOrReturn(sInitResult, "InitializeStaticResourcesBeforeServerInit() failed");

samples/matter/common/src/app/matter_init.h

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include <crypto/PSAOperationalKeystore.h>
2424
#endif
2525

26+
#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
27+
#include <platform/nrfconnect/KMUSessionKeystore.h>
28+
#endif
29+
2630
#ifdef CONFIG_CHIP_FACTORY_DATA
2731
#include <platform/nrfconnect/FactoryDataProvider.h>
2832
#else
@@ -58,6 +62,10 @@ struct InitData {
5862
#ifdef CONFIG_CHIP_CRYPTO_PSA
5963
/** @brief Pointer to the user provided OperationalKeystore implementation. */
6064
chip::Crypto::OperationalKeystore *mOperationalKeyStore{ &sOperationalKeystoreDefault };
65+
#endif
66+
#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
67+
/** @brief Pointer to the user provided SessionKeystore implementation. */
68+
chip::Crypto::SessionKeystore *mSessionKeystore{ &sKMUSessionKeystoreDefault };
6169
#endif
6270
/** @brief Custom code to execute in the Matter main event loop before the server initialization. */
6371
CustomInit mPreServerInitClbk{ nullptr };
@@ -77,6 +85,9 @@ struct InitData {
7785
#ifdef CONFIG_CHIP_CRYPTO_PSA
7886
static chip::Crypto::PSAOperationalKeystore sOperationalKeystoreDefault;
7987
#endif
88+
#ifdef CONFIG_CHIP_STORE_KEYS_IN_KMU
89+
static chip::DeviceLayer::KMUSessionKeystore sKMUSessionKeystoreDefault;
90+
#endif
8091
};
8192

8293
/**

west.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ manifest:
157157
- name: matter
158158
repo-path: sdk-connectedhomeip
159159
path: modules/lib/matter
160-
revision: cb40b0d0dcc8135c7cf9dc78f2b47d89404047ad
160+
revision: pull/539/head
161161
west-commands: scripts/west/west-commands.yml
162162
submodules:
163163
- name: nlio

0 commit comments

Comments
 (0)