Skip to content

device_credentials_installer: add nrf_cloud_cred_shell cmd type#87

Open
PavelVPV wants to merge 2 commits into
nRFCloud:mainfrom
PavelVPV:generate_pk_and_csr_on_device_using_psa
Open

device_credentials_installer: add nrf_cloud_cred_shell cmd type#87
PavelVPV wants to merge 2 commits into
nRFCloud:mainfrom
PavelVPV:generate_pk_and_csr_on_device_using_psa

Conversation

@PavelVPV

Copy link
Copy Markdown

Add a new --cmd-type 'nrf_cloud_cred_shell' that uses the NrfCloudCredShellInterface to generate the device private key and CSR on-device via the 'nrf_cloud_cred' shell commands.

The CSR returned by this interface is plain Base64-encoded DER (not the modem's body.cose format), so get_csr() decodes it with load_der_x509_csr(). As with tls_cred_shell, a random device id is used when none is provided. The private key stays in PSA on the device; only CA and device certificates are written via the TLS Credentials Shell.

PavelVPV and others added 2 commits June 19, 2026 14:06
Add a new --cmd-type 'nrf_cloud_cred_shell' that uses the
NrfCloudCredShellInterface to generate the device private key and CSR
on-device via the 'nrf_cloud_cred' shell commands.

The CSR returned by this interface is plain Base64-encoded DER (not the
modem's body.cose format), so get_csr() decodes it with
load_der_x509_csr(). As with tls_cred_shell, a random device id is used
when none is provided. The private key stays in PSA on the device; only
CA and device certificates are written via the TLS Credentials Shell.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
For the nrf_cloud_cred_shell command type, the private key is held in
PSA and cannot be hashed, so verify it by comparing the device public
key against the public key in the installed device certificate.

Also reject --local-cert / --local-cert-file with nrf_cloud_cred_shell,
since the key and CSR are generated on-device and a host-generated key
would be a mistake.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@PavelVPV PavelVPV changed the title [WIP] device_credentials_installer: add nrf_cloud_cred_shell cmd type device_credentials_installer: add nrf_cloud_cred_shell cmd type Jun 23, 2026
@PavelVPV PavelVPV marked this pull request as ready for review June 23, 2026 12:56
csr = x509.load_der_x509_csr(base64.b64decode(csr_blob))
else:
csr_bytes, _, _, _ = modem_credentials_parser.parse_keygen_output(csr_blob)
csr = x509.load_pem_x509_csr(csr_bytes)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

csr = x509.load_pem_x509_csr() is common to both branches, consider moving to after if/else statement

if args.cmd_type == CMD_TYPE_NRF_CLOUD_CRED_SHELL and (args.local_cert or args.local_cert_file):
# The key and CSR are generated on-device; generating a key on the host
# would defeat the purpose and is almost certainly a mistake.
logger.error(f"cmd_type '{CMD_TYPE_NRF_CLOUD_CRED_SHELL}' generates the key on-device; "

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could probably use parser.error() here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants