Signing firmware with an HSM protected private key

Does such a capability exist with current signing tools (via pkcs11)? The only reference in the documentation for utilization of an HSM is in the exploitation of its random number generator for creating a truly random key.

Generating the RSA Key Pair

But, I don’t see anything online about being to integrate the signing tools to the HSM such that the private key is never exposed. As an example, it would be nice if you could integrate to a service like AWS CloudHSM.

hello chad.mcquillen,

may I know which release you’re working with?
for example, if you’re using the latest release (i.e. JetPack-4.6), it has using the updated flash tools (TegraSign_v3) to support singed binaries using HSM.

here’s also another discussion thread for your reference, Creating fuse blobs and signed/encrypted images using HSM - #3 by JerryChang
thanks

We are currently on the L4T 32.4.3 release with plans to upgrade to latest in the near future. I’ve seen that other discussion thread, but the response seemed to me to imply that the private key (.pem) had to be directly accessible (via -u <rsa_priv.pem>) to the signing tools. That’s not what I’m looking for because I don’t ever want the private key to be publicly exposed.

hello chad.mcquillen,

there’s flash tools to support singed binaries using HSM,
is your request same as Topic 168742?

No, that is a different issue.

“there’s flash tools to support singed binaries using HSM”

Where in the documentation is this stated?

hello chad.mcquillen,

sorry, there’s no documentation related to HSM,
you should check the python file, tegrasign_v3_internal.py for the details.

I didn’t have alot of time to look at this today. But, looking at tegrasign_v3_internal.py I do see some *_hsm() functions. For PKC signing it seems to go here:

def do_rsa_pss_hsm(buf, p_key):

    tmpf_in = 'tmp_rsa_pss.in'
    tmpf_out = 'tmp_rsa_pss.sig'
    tmpf_hash = 'tmp_sha256.hash'
    priv_keyf = p_key.filename

    with open_file(tmpf_in, 'wb') as f:
        write_file(f, buf)

    # rsa_pss_saltlen:-1 means the same length of hash (sha256) here
    # single line execution:
    # runcmd = "openssl dgst -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1 -sign %s -out %s %s" % (priv_keyf, tmpf_out, tmpf_in)

    # two separate line execution with intermediate sha256 output
    runcmd1 = "openssl dgst -sha256 -binary -out %s %s" % (tmpf_hash, tmpf_in)
    runcmd2 = "openssl pkeyutl -sign -pkeyopt rsa_padding_mode:pss -pkeyopt rsa_pss_saltlen:-1 -pkeyopt digest:sha256 -in %s -out %s -inkey %s" % (tmpf_hash, tmpf_out, priv_keyf)

Isn’t privkeyf pointing to the private signing key which is directly exposed on the filesystem?