Skip to content

Commit 3664063

Browse files
[nrf toup][nrfconnect] Fail boot if DAC is in ITS with KMU enabled
Add CONFIG_CHIP_CRYPTO_PSA_DAC_PRIV_KEY_FATAL_IF_IN_ITS to detect a DAC private key still stored in PSA ITS when factory data is configured for CRACEN KMU. Signed-off-by: Arkadiusz Balys <arkadiusz.balys@nordicsemi.no>
1 parent b8d422d commit 3664063

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎config/nrfconnect/chip-module/Kconfig‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ if CHIP_CRYPTO_PSA_MIGRATE_DAC_PRIV_KEY
331331

332332
choice CHIP_CRYPTO_PSA_DAC_PRIV_KEY_MIGRATION_DEST
333333
prompt "Destination for DAC private key migration"
334-
default CHIP_CRYPTO_PSA_DAC_PRIV_KEY_KMU if CRACEN_LIB_KMU
334+
default CHIP_CRYPTO_PSA_DAC_PRIV_KEY_KMU if CRACEN_KMU
335335
default CHIP_CRYPTO_PSA_DAC_PRIV_KEY_ITS
336336

337337
config CHIP_CRYPTO_PSA_DAC_PRIV_KEY_ITS
@@ -344,7 +344,7 @@ config CHIP_CRYPTO_PSA_DAC_PRIV_KEY_ITS
344344

345345
config CHIP_CRYPTO_PSA_DAC_PRIV_KEY_KMU
346346
bool "Migrate DAC private key from factory data to CRACEN KMU"
347-
depends on CRACEN_LIB_KMU
347+
depends on CRACEN_KMU
348348
help
349349
Move DAC private key from the factory data set to the CRACEN Key Management Unit (KMU) secure
350350
storage and remove it. After the first boot of the device the DAC private key will be
@@ -371,7 +371,7 @@ endif # CHIP_CRYPTO_PSA_MIGRATE_DAC_PRIV_KEY
371371

372372
config CHIP_STORE_KEYS_IN_KMU
373373
bool "Use KMU to store crypto keys"
374-
depends on CRACEN_LIB_KMU
374+
depends on CRACEN_KMU
375375
select EXPERIMENTAL
376376
help
377377
Stores cryptographic materials like keys in the KMU if available on the device.

‎src/platform/nrfconnect/FactoryDataProvider.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ CHIP_ERROR FactoryDataProvider<FlashFactoryData>::Init()
8585
}
8686

8787
#ifdef CONFIG_CHIP_CRYPTO_PSA
88+
#ifdef CHIP_CRYPTO_PSA_DAC_PRIV_KEY_KMU
89+
VerifyOrDie(FatalIfDACPrivateKeyInITS() == CHIP_NO_ERROR);
90+
#endif
8891
VerifyOrDie(MoveDACPrivateKeyToSecureStorage(factoryData, factoryDataSize) == CHIP_NO_ERROR);
8992
#endif
9093

@@ -220,6 +223,27 @@ CHIP_ERROR FactoryDataProvider<FlashFactoryData>::MoveDACPrivateKeyToSecureStora
220223

221224
return CHIP_NO_ERROR;
222225
}
226+
227+
#ifdef CHIP_CRYPTO_PSA_DAC_PRIV_KEY_KMU
228+
template <class FlashFactoryData>
229+
CHIP_ERROR FactoryDataProvider<FlashFactoryData>::FatalIfDACPrivateKeyInITS()
230+
{
231+
const psa_key_id_t itsDacKeyId = to_underlying(chip::Crypto::KeyIdBase::DACPrivKey);
232+
233+
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
234+
if (psa_get_key_attributes(itsDacKeyId, &attributes) == PSA_SUCCESS)
235+
{
236+
psa_reset_key_attributes(&attributes);
237+
ChipLogError(DeviceLayer,
238+
"DAC private key found in PSA ITS while CRACEN KMU storage is configured. "
239+
"Automatic migration from ITS to KMU is not supported. "
240+
"Re-provision the device.");
241+
return CHIP_ERROR_INTERNAL;
242+
}
243+
244+
return CHIP_NO_ERROR;
245+
}
246+
#endif // CHIP_CRYPTO_PSA_DAC_PRIV_KEY_KMU
223247
#endif // CONFIG_CHIP_CRYPTO_PSA
224248

225249
template <class FlashFactoryData>

‎src/platform/nrfconnect/FactoryDataProvider.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ class FactoryDataProvider : public FactoryDataProviderBase
153153
CHIP_ERROR MoveDACPrivateKeyToSecureStorage(uint8_t * factoryDataPartition, size_t factoryDataSize);
154154
#endif
155155

156+
#ifdef CHIP_CRYPTO_PSA_DAC_PRIV_KEY_KMU
157+
CHIP_ERROR FatalIfDACPrivateKeyInITS();
158+
#endif // CHIP_CRYPTO_PSA_DAC_PRIV_KEY_KMU
159+
156160
// ===== Members functions that implement the DeviceAttestationCredentialsProvider
157161
CHIP_ERROR GetCertificationDeclaration(MutableByteSpan & outBuffer) override;
158162
CHIP_ERROR GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) override;

0 commit comments

Comments
 (0)