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

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, for the details.

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

def do_rsa_pss_hsm(buf, p_key):

    tmpf_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?

Any further updates for this? I’m trying to get the definitive word on whether firmware can be signed with an HSM protected key. If not, I would like to request that this become a feature request for a future L4T release that would further improve security in the signing process.

Related discussions in Format of mb1_t194_prod.bin OEM signature header - #10 by danwalkes1 and OE4T Meeting Notes 2021 12 09 · OE4T/meta-tegra Wiki · GitHub for anyone tracking this issue.