Skip to content

[nrf noup] bootutil: Locking KMU keys #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions boot/bootutil/src/ed25519_psa.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,34 @@ int exec_revoke(void)
return ret;
}
#endif /* CONFIG_BOOT_KMU_KEYS_REVOCATION */

void nrf_crypto_keys_housekeeping(void)
{
psa_status_t status = psa_crypto_init();

if (status != PSA_SUCCESS) {
BOOT_LOG_ERR("PSA crypto init failed with error %d", status);
return;
}

status = PSA_ERROR_NOT_SUPPORTED;

/* We will continue through all keys, even if we have error while
* processing any of it. Only doing BOOT_LOG_DBG, as we do not
* really want to inform on failures to lock.
*/
for (int i = 0; i < CONFIG_BOOT_SIGNATURE_KMU_SLOTS; ++i) {
psa_key_attributes_t attr;

status = psa_get_key_attributes(kmu_key_ids[i], &attr);
BOOT_LOG_DBG("KMU key 0x%x(%d) attr query status == %d",
kmu_key_ids[i], i, status);

if (status == PSA_SUCCESS) {
status = cracen_kmu_block(&attr);
BOOT_LOG_DBG("KMU key lock status == %d", status);
}
}
}

#endif
11 changes: 11 additions & 0 deletions boot/zephyr/include/nrf_cleanup.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ void nrf_cleanup_peripheral(void);
*/
void nrf_cleanup_ns_ram(void);

/**
* Crypto key storage housekeeping. Intended to cleanup key objects from
* crypto backend and apply key policies that should take effect after
* MCUboot no longer needs access to keys.
*/
#if defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
extern void nrf_crypto_keys_housekeeping(void);
#else
#define nrf_crypto_keys_housekeeping() do {} while (0)
#endif

#endif
7 changes: 7 additions & 0 deletions boot/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,13 @@ int main(void)

mcuboot_status_change(MCUBOOT_STATUS_BOOTABLE_IMAGE_FOUND);

/* From this point MCUboot does not need access to crypto keys.
* Cleanup backend key objects and apply key access policies that
* will take effect from now through entire boot session and application
* run.
*/
nrf_crypto_keys_housekeeping();

#if USE_PARTITION_MANAGER && CONFIG_FPROTECT

#ifdef PM_S1_ADDRESS
Expand Down