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:

  1. Generate the device key on the device.

  2. Generate a CSR signed by the device key and transfer it off the device (over the shell, or using the API).

  3. Sign the device certificate on the host with your own CA certificate. nRF Cloud does not issue the device certificate.

  4. Install the device certificate and the nRF Cloud root CA certificates on the device.

  5. 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:

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

nrf_cloud_cred keygen [<sec_tag>]

Generate the device private key. Fails if a key already exists for the security tag.

nrf_cloud_cred csr [<sec_tag>] [<subject>]

Generate and print a Base64-encoded DER CSR signed by the device key. If the subject is omitted, CN=<device id> is used.

nrf_cloud_cred delete [<sec_tag>]

Delete the device private key.

nrf_cloud_cred pubkey [<sec_tag>]

Export and print the Base64-encoded public key (requires CONFIG_NRF_CLOUD_CREDENTIALS_KEYGEN_VERIFY).

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

Source files: subsys/net/lib/nrf_cloud/common/src/
nRF Cloud on-device key generation