code signing tool with hardware security module

Showing results for 
Search instead for 
Did you mean: 

code signing tool with hardware security module

Contributor II


The code-signing-tool requires access to private/public keys for generating the secure boot headers.

However, the need for having private key files in plain text on the file system for using CST is rather bad.

Private/privileged cryptographic material should be generated and accessible only within a secured environment like a hardware-security-module.

Is there (eventually going to be) any support in the CST to hand off RSA operations with private keys to a HSM?

Right now, there is always this loose end at the very beginning of the trusted-boot-chain, which contradicts best practices from a security standpoint.

u-boot/mkimage already has such capabilities: Add support for signing with pkcs11 ->;a=commit;h=f1ca1fdebf1cde1c37c91b3d85f8b7af111112ea

Thank you!

Labels (1)
5 Replies

NXP Employee
NXP Employee

The best approach would be creating an OpenSSL engine which talks to your HSM.

You create the CMS signature using OpenSSL's public accessors. OpenSSL in his turn will offload any cryprohraphic operation involved during signing to the HSM.

You can find a detailed answer here 

Contributor I


we succesfully extended the CST backend code to allow signing code using HSM Module using PKCS11.

we also developed a solution that enable CST to remotely sign the code using Keys/HSM stored on other server over a secure channel.

For more information or inquiries you can contact us at :

Best regards,

0 Kudos

Contributor II

The CST v2.3.2 back end code, included with the tool, can be rewritten to support an HSM.  I ported it for my company to support the Amazon CloudHSM service.  Most of it is trivial, except for when you want to generate the signing information.  The HSM does not support CSM syntax signatures, but you can dig into the OpenSSL code and call the appropriate bits to construct the expected signature.  You will need to link directly to the libcrypto.a file, instead of dynamically loading your system's file.  Working through the OpenSSL code is tedious, but it's necessary.  You'll have to pick a specific OpenSSL version, and then stick with it.

Contributor II

If it's not asked to much, would it be possible to get a diff-patch of your modifications, as a starting point?

0 Kudos

Contributor II

Unfortunately, the patch would be massive.  I've removed all unused functions, and rewritten a good chunk of what remained.  And then it would take weeks for the code to be cleared to be let out of the company.

Since the hard part is creating the final CMS signature, here's the sequence of OpenSSL functions you'll need to call:
cms_DigestAlgorithm_set() /* for mechanism */
cms_DigestAlgorithm_set() /* for message digest algorithm */
CMS_signed_add1_attr_by_NID() /* for message digest */
CMS_signed_add1_attr_by_NID() /* for X509_gmtime_adj() */
CMS_signed_add1_attr_by_NID() /* for content type */
ASN1_item_i2d() /* for signed attributes */
/* finalize HSM digest */
ASN1_STRING_set0() /* add signature data */
ASN1_item_i2d() /* for CMS content info */

All of this is based on the OpenSSL code.  Look in cms_smime.c CMS_sign(), cms_sd.c CMS_add1_signer() and CMS_SignerInfo_sign().  First get familiar with the HSM sample code and functions, and then write a signature function.  Then you'll be able to plug it into the CST code without much difficulty.