AN12812 - How to use CST with HSM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AN12812 - How to use CST with HSM

Jump to solution
1,372 Views
eduardo3
Contributor III

Hello,

I am trying to follow AN12812 to use CST 3.3.2 with softhsm2. Everything completes successfully with the exception of calling CST to do the actual signing, so I am a bit lost at the moment.

I have rebuilt CST and followed the steps in the application note. There is the content of the HSM, imx-boot.csf and the CST output.

I appreciate if additional debug info is needed (please let me know how to get it).

$ pkcs11-tool --module $PKCS11_MODULE -l --pin $USR_PIN --list-objects
Using slot 0 with a present token (0x10)
Certificate Object; type = X.509 cert
label: IMG1_1_sha256_2048_usr
subject: DN: CN=IMG1_1_sha256_2048_usr
ID: 1003
Private Key Object; RSA
label: CA1_sha256_2048_ca
ID: 1000
Usage: decrypt, sign, unwrap
Access: sensitive, always sensitive, never extractable, local
Public Key Object; RSA 2048 bits
label: CSF1_1_sha256_2048_usr
ID: 1002
Usage: encrypt, verify, wrap
Access: local
Public Key Object; RSA 2048 bits
label: CA1_sha256_2048_ca
ID: 1000
Usage: encrypt, verify, wrap
Access: local
Public Key Object; RSA 2048 bits
label: IMG1_1_sha256_2048_usr
ID: 1003
Usage: encrypt, verify, wrap
Access: local
Certificate Object; type = X.509 cert
label: SRK1_sha256_2048_ca
subject: DN: CN=SRK1_sha256_2048_ca
ID: 1001
Private Key Object; RSA
label: SRK1_sha256_2048_ca
ID: 1001
Usage: decrypt, sign, unwrap
Access: sensitive, always sensitive, never extractable, local
Private Key Object; RSA
label: CSF1_1_sha256_2048_usr
ID: 1002
Usage: decrypt, sign, unwrap
Access: sensitive, always sensitive, never extractable, local
Certificate Object; type = X.509 cert
label: CSF1_1_sha256_2048_usr
subject: DN: CN=CSF1_1_sha256_2048_usr
ID: 1002
Public Key Object; RSA 2048 bits
label: SRK1_sha256_2048_ca
ID: 1001
Usage: encrypt, verify, wrap
Access: local
Private Key Object; RSA
label: IMG1_1_sha256_2048_usr
ID: 1003
Usage: decrypt, sign, unwrap
Access: sensitive, always sensitive, never extractable, local

 

$ cat imx-boot.csf 
[Header]
        Version = 4.3
        Hash Algorithm = sha256
        Engine = CAAM
        Engine Configuration = 0
        Certificate Format = X509
        Signature Format = CMS

[Install SRK]
        File = "./SRK_1_table.bin"
        Source index = 0

[Install CSFK]
        File = "pkcs11:token=CST-HSM-DEMO;object=CSF1_1_sha256_2048_usr;type=cert;pin-value=12345678"

[Authenticate CSF]

[Unlock]
        Engine = CAAM
        Features = MID

[Unlock]
        Engine = CAAM
        Features = MFG

[Install Key]
        Verification index = 0
        Target index = 2
        File = "pkcs11:token=CST-HSM-DEMO;object=IMG1_1_sha256_2048_usr;type=cert;pin-value=12345678"

[Authenticate Data]
        Verification index = 2
        Blocks = 0x7e0fc0 0x0 0x2bc00 "flash.bin"

 

$ cst -i imx-boot.csf -o imx-boot.csf.bin
Public key certificate is invalid in file pkcs11:token=CST-HSM-DEMO;object=CSF1_1_sha256_2048_usr;type=cert;pin-value=12345678

 

Environment variables are defined like in the AN. I am running an up to date Ubuntu 20.04.

PKCS11_MODULE=/usr/lib/x86_64-linux-gnu/p11-kit-proxy.so 

SO_PIN=7635005489180126 

USR_PIN=12345678

SRK1_KEY=SRK1_sha256_2048_ca

CSF1_KEY=CSF1_1_sha256_2048_usr

IMG1_KEY=IMG1_1_sha256_2048_usr

Before running the openssl commands, I am using 

openssl engine dynamic -pre SO_PATH:/usr/lib/x86_64-linux-gnu/engines-1.1/pkcs11.so -pre ID:pkcs11 -pre LIST_ADD:1 -pre LOAD -pre MODULE_PATH:$PKCS11_MODULE

 

Any help is appreciated. 

 

Another thing is AN12812 only mentions HABv4, but I am using i.MX8X, which is AHAB.

 

 

 

 

 

Tags (2)
0 Kudos
1 Solution
1,268 Views
eduardo3
Contributor III

Adding "-b pkcs11" results in "CSF Processed successfully and signed data available in imx-boot.csf.bin" using the same CSF file I posted here. Thanks for that.

 

Could you expand a bit on the "Code-Signing Rev. 3.3.2 for AHAB" part? Is it a document/section of a document/etc? It is not obvious what you are referring there.

Also, could you point the information (link, doc, etc) where that info is located?

 

View solution in original post

0 Kudos
11 Replies
692 Views
jbhaijy
Contributor III

Hi,@Irene @eduardo3

I have similar requirement & want to sign the i.MX6/8 images with CST tool with third party HSM which is not in our organization network. 

The questions here is instead of SoftHSM, can we use external third party HSM to sign the images with CST tool without changing the default CST backend? I know we need HSM vendor PKCS#11 Module & configure at client side where we execute the CST tool. 

   
 @eduardo3 Are you able to sign the images with SoftHSM by following the steps mentioned in the above document i.e. AN12812?

 

Appreciate you help & support. Thanks.

0 Kudos
663 Views
eduardo3
Contributor III

The main thing that is not in this post is the CSF file that I had to figure out. We are not signing in production, just investigating. It's been a while I looked into this.

$ cat > ahab-imx-boot.csf<<EOF
[Header]
Target = AHAB
Version = 1.0

[Install SRK]
File = "./SRK_1_table.bin"
Source = "pkcs11:token=CST-HSM-DEMO;object=SRK1_sha384_4096_65537_usr;type=cert;pin-value=12345678"
Source index = 0
Source set = OEM
Revocations = 0x0

[Authenticate Data]
File = "./flash.bin"
Offsets = 0x400 0x590

EOF

flash.bin is from a previous yocto build. "Authentication Data", the offsets come from the imx-mkimage tool output. The guide does not provide AHAB + HSM examples.

0 Kudos
1,231 Views
eduardo3
Contributor III

I accepted the solution but NXP must update AN12812 or/and add HSM examples to the main CST user guide.

0 Kudos
1,248 Views
Irene
NXP Pro Support
NXP Pro Support

Hello Eduardo,
The latest Code Signing Toolsi is version 3.3.2, which you can find on the nxp.com website. In that installation folder, you should see the Code-Signing Tool User’s Guide, Rev. 3.3.2, which has an example of using AHAB. We need to work on updating the Application Note.

0 Kudos
1,269 Views
eduardo3
Contributor III

Adding "-b pkcs11" results in "CSF Processed successfully and signed data available in imx-boot.csf.bin" using the same CSF file I posted here. Thanks for that.

 

Could you expand a bit on the "Code-Signing Rev. 3.3.2 for AHAB" part? Is it a document/section of a document/etc? It is not obvious what you are referring there.

Also, could you point the information (link, doc, etc) where that info is located?

 

0 Kudos
1,304 Views
Irene
NXP Pro Support
NXP Pro Support

According to Code-Signing Tool User’s Guide, Rev. 3.3.2, you can use the PKCS backend via the command line without recompiling the CST.  

 

In the Release Notes for Code-Signing Rev. 3.3.2, NXP has added backend support to support the pkcs11 interface. You can select the backend support by using the ‘-b pkcs11’ parameter on the command line when invoking CST. CST will use the standard backend by default.

 

Please take a look at Code-Signing Rev. 3.3.2 for AHAB.  

 

 

 

0 Kudos
467 Views
kauschked
Contributor II

Hello Irene,

I also would like to use the cst tool with PKCS11 backend without recompiling cst-tool.

Unfortunately I dont find the latest Code-Signing Tool User’s Guide, Rev. 3.3.2 and the cst-tool on the website nxp.com

Could you please give us the complete URLs to download the guide and the cst-tool with version 3.3.2?

 

Thank you!

 

Best regards

David

0 Kudos
408 Views
kauschked
Contributor II

Any information to the questions above from you@Irene ? Would be very helpful.

0 Kudos
395 Views
jbhaijy
Contributor III

Hi @kauschked ,

  • I believe CST-3.3.2 onwards the NXP has added pkcs11 supports in the CST tool with option -b pkcs11. Its default feature & hence no need to compile the CST again. You can follow the steps mentioned in AN12812 to setup the SoftHSM to test the CST pkcs11 feature. 
  • The latest CST release version which I see is CST-3.4.0 & its document explain how to execute the CST with -b pkcs11 option.
  • You will find & download the latest CST tool from https://www.nxp.com/search?keyword=IMX_CST_TOOL&start=0&category=software

 

0 Kudos
393 Views
kauschked
Contributor II

@jbhaijyThank you very much for your help. /closed

0 Kudos
1,369 Views
Irene
NXP Pro Support
NXP Pro Support

let me look into this.

0 Kudos