Custom Signing Function

NCS v2.7.0 and sysbuild system.

I'm looking for some clarification about Secure Boot and implementing a custom signing command.

What is the difference between secure boot and the signing that happens when you just set BOOT_SIGNATURE_KEY_FILE="/path/to/key.pem"? 

Examining the scripts in `nrf/scripts/bootloaders/` it appears that all of the signing and verification functions are expecting ECDSA keys, which I was unable to find anywhere in the documentation.  Is there a way to get this to work with RSA keys? or is ECDSA my only option?

The documentation (https://github.com/nrfconnect/sdk-nrf/blob/a8ea23813b59e40e5999636063b15d629eea373f/sysbuild/Kconfig.secureboot#L73) says that the output of the signing function should be in DER format.  

When I ran this signing command that output an actual DER formatted signature, the build system threw an error that it was expecting a 64 byte signature, i.e. just the R and S values of the signature.  When I modified the code to write the R and S values it worked as expected.

    signature = private_key.sign(data, ec.ECDSA(hashes.SHA256()))
    
    # This is the der formatted signature. It would be 70 bytes
    # sys.stdout.buffer.write(signature)
    
    # Instead, extract the R and S values and print them to stdout

    r, s = decode_dss_signature(signature)

    r_bytes = r.to_bytes(32, "big")
    s_bytes = s.to_bytes(32, "big")
    sig = bytearray(r_bytes)
    sig.extend(s_bytes)

    sys.stdout.buffer.write(sig)
    sys.stdout.flush()

Parents Reply
  • Roedy said:
    I can get the public key out of the system and store it as a file.  The issue is that when I actually need to do the signature from an HSM it isn't just a file that I can load.  We're using a cloud based HSM, so I need to make an API call to my cloud service to generate the signature. 

    If we were using a local HSM (like a yubi key, for instance) we'd still need to use some sort of library to load the key reference, for example https://python-pkcs11.readthedocs.io/en/latest/index.html

    Right, that makes it harder then.

    Roedy said:
    The way that you guys included the SB_CONFIG_SECURE_BOOT_SIGNING_COMMAND option for the nordic bootloader is wonderful, and is exactly what I was looking for, but I think I'm stuck with mcuboot at the moment so I'll probably just modify the imgtool to do what I need it to do.

    I agree that this seems like the way.
    Thanks for the feedback on this though; I will forward it to our bootloader team.

Children
Related