nRF Cloud on-device key generation
The nRF Cloud on-device key generation feature lets a device generate its own TLS private key and a Certificate Signing Request (CSR) without the key ever leaving the device. It is part of the nRF Cloud library and is intended for the manual provisioning flow on devices that do not have a modem-managed key store.
Overview
The private key is generated using the PSA Crypto API as a persistent, non-exportable ECC P-256 key, stored using the Secure Storage.
The key is referenced for TLS by its PSA key ID through the TLS_CREDENTIAL_PRIVATE_KEY_PSA credential type, so the private key is never exported to the application or written to the TLS credentials store as raw key material.
A typical provisioning flow is as follows:
Generate the device key on the device.
Generate a CSR signed by the device key and transfer it off the device (over the shell, or using the API).
Sign the device certificate on the host with your own CA certificate. nRF Cloud does not issue the device certificate.
Install the device certificate and the nRF Cloud root CA certificates on the device.
Onboard the device to your nRF Cloud account by uploading the device certificate.
For the complete provisioning and onboarding process, see On-device key generation and nRF Cloud Utils: Devices without a modem.
The device key is re-registered with the TLS credentials module from the Secure Storage during nRF Cloud initialization, so a key generated in a previous session is available for the TLS handshake after a reboot.
Configuration
Set the following Kconfig options to enable the feature:
CONFIG_NRF_CLOUD_CREDENTIALS_KEYGEN- Enables on-device key and CSR generation and the associated API.CONFIG_NRF_CLOUD_CREDENTIALS_KEYGEN_VERIFY- Enables exporting the on-device public key so host tooling can verify that the key matches the device certificate.Enabled by default, disable to save code if verification is not needed.
CONFIG_NRF_CLOUD_CREDENTIALS_KEYGEN_SHELL- Enables thenrf_cloud_credshell commands.
The CONFIG_NRF_CLOUD_CREDENTIALS_KEYGEN and CONFIG_NRF_CLOUD_CREDENTIALS_KEYGEN_SHELL options are experimental and depend on the TLS credentials management option (CONFIG_NRF_CLOUD_CREDENTIALS_MGMT_TLS_CRED).
Shell commands
When the CONFIG_NRF_CLOUD_CREDENTIALS_KEYGEN_SHELL Kconfig option is enabled, the following commands are available under nrf_cloud_cred.
If the security tag is omitted, the nRF Cloud security tag (CONFIG_NRF_CLOUD_SEC_TAG) is used.
Command |
Description |
|---|---|
|
Generate the device private key. Fails if a key already exists for the security tag. |
|
Generate and print a Base64-encoded DER CSR signed by the device key. If the subject is omitted, |
|
Delete the device private key. |
|
Export and print the Base64-encoded public key (requires |
To rotate the key, delete it and generate a new one. The previously issued device certificate no longer matches the new key and must be re-provisioned.
API documentation
subsys/net/lib/nrf_cloud/common/src/