Skip to content

Commit 538b29d

Browse files
[nrf toup][nrfconnect] Fix DAC migration
- Fixed wrong dependency in Kconfigs - Fixed wrong bracket placement that causes overwriting DAC private key. Signed-off-by: Arkadiusz Balys <arkadiusz.balys@nordicsemi.no>
1 parent 700233b commit 538b29d

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

config/nrfconnect/chip-module/Kconfig

+6-3
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,7 @@ endif # CHIP_FACTORY_DATA_BUILD
330330

331331
# See config/zephyr/Kconfig for full definition
332332
config CHIP_FACTORY_RESET_ERASE_SETTINGS
333-
default y
334-
depends on NVS || ZMS
335-
depends on !CHIP_CRYPTO_PSA_MIGRATE_DAC_PRIV_KEY
333+
default y if !CHIP_CRYPTO_PSA_DAC_PRIV_KEY_ITS || BUILD_WITH_TFM
336334

337335
config CHIP_LOG_SIZE_OPTIMIZATION
338336
bool "Disable some detailed logs to decrease flash usage"
@@ -369,9 +367,12 @@ config CHIP_ENABLE_READ_CLIENT
369367

370368
config CHIP_CRYPTO_PSA_MIGRATE_DAC_PRIV_KEY
371369
bool "Migrate DAC private key from factory data to a secure storage"
370+
default y
372371
depends on CHIP_CRYPTO_PSA
373372
depends on CHIP_FACTORY_DATA
374373

374+
if CHIP_CRYPTO_PSA_MIGRATE_DAC_PRIV_KEY
375+
375376
choice CHIP_CRYPTO_PSA_DAC_PRIV_KEY_MIGRATION_DEST
376377
prompt "Destination for DAC private key migration"
377378
default CHIP_CRYPTO_PSA_DAC_PRIV_KEY_ITS
@@ -409,6 +410,8 @@ config CHIP_CRYPTO_PSA_DAC_PRIV_KEY_KMU_ENCRYPTED
409410
help
410411
Encrypt the DAC private key in the CRACEN KMU secure storage.
411412

413+
endif # CHIP_CRYPTO_PSA_MIGRATE_DAC_PRIV_KEY
414+
412415
config CHIP_PERSISTENT_SUBSCRIPTIONS
413416
default n
414417
# selecting experimental for this feature since there is an issue with multiple controllers.

config/nrfconnect/chip-module/Kconfig.defaults

-3
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,6 @@ config MBEDTLS_SSL_COOKIE_C
433433
config MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
434434
default y
435435

436-
config CHIP_CRYPTO_PSA_MIGRATE_DAC_PRIV_KEY
437-
default y if !CHIP_WIFI
438-
439436
# ==============================================================================
440437
# Logging configuration
441438
# ==============================================================================

src/platform/nrfconnect/FactoryDataProvider.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,16 @@ CHIP_ERROR FactoryDataProvider<FlashFactoryData>::MoveDACPrivateKeyToSecureStora
174174
#else
175175
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_VOLATILE);
176176
#endif // CONFIG_CHIP_CRYPTO_PSA_MIGRATE_DAC_PRIV_KEY
177+
VerifyOrReturnError(psa_import_key(&attributes, reinterpret_cast<uint8_t *>(mFactoryData.dac_priv_key.data),
178+
mFactoryData.dac_priv_key.len, &mDACPrivKeyId) == PSA_SUCCESS,
179+
CHIP_ERROR_INTERNAL);
177180
}
178-
VerifyOrReturnError(psa_import_key(&attributes, reinterpret_cast<uint8_t *>(mFactoryData.dac_priv_key.data),
179-
mFactoryData.dac_priv_key.len, &mDACPrivKeyId) == PSA_SUCCESS,
180-
CHIP_ERROR_INTERNAL);
181181

182182
#ifdef CONFIG_CHIP_CRYPTO_PSA_MIGRATE_DAC_PRIV_KEY
183-
#ifdef CONFIG_CHIP_FACTORY_RESET_ERASE_SETTINGS
183+
#if defined(CONFIG_CHIP_FACTORY_RESET_ERASE_SETTINGS) && defined(CONFIG_CHIP_CRYPTO_PSA_DAC_PRIV_KEY_ITS) && \
184+
!defined(CONFIG_BUILD_WITH_TFM)
184185
#error "Do not use both CONFIG_CHIP_FACTORY_RESET_ERASE_SETTINGS and CONFIG_CHIP_CRYPTO_PSA_MIGRATE_DAC_PRIV_KEY kconfig options " \
185-
"because you will permanently lose the DAC private key from the device."
186+
"while saving the DAC private key to ITS because you will permanently lose the DAC private key from the device."
186187
#endif
187188
// Check once again if the saved key has attributes set before removing it from the factory data set.
188189
VerifyOrReturnError(psa_get_key_attributes(mDACPrivKeyId, &attributes) == PSA_SUCCESS, CHIP_ERROR_INTERNAL);

0 commit comments

Comments
 (0)