I have been assigned an application that is a few years old now, written by people who are no longer at the company. There is little-to-no documentation on processes or code.

It signs firmware for a System to accept, while digging through its source code it appears to sign and verify with the following commands:


openssl cms -engine pkcs11 -keyform engine -sign -inkey 'pkcs11:token=xxxxxxxxxxx;type=private' -signer 'certificate.pem' -md SHA256 -out out_file -in in_file.txt -outform DER -binary


openssl smime -verify -binary -inform der -in in_file.txt -content other.txt -certfile cert.pem -CAfile ca_cert.pem

So, ultimately, this application signs the firmware with the above command. Now that the firmware is signed, it can be uploaded to this other system (that holds the public key/cert) that checks that the uploaded firmware has a valid signature on it.

I am not a security/encryption expert, so I am trying to figure out why they used the smime/cms code.

Why don't they just use the private key to sign a hash of the firmware, and then return the signed hash, and the valid firmware. Which can then be uploaded to the system which holds the public key, that can decrypt/verify the signature, and if it is able to then accept the payload?

What advantages does using the CMS commands offer? Specifically, I am trying to understand what the above sign command is actually doing. It appears to take a certificate, and a weird pkcs11 token inkey sort of thing. I am not familiar with this format, or what it does.

1 Answer 1


... and a weird pkcs11 token inkey sort of thing.

This is using a PKCS11 backend to create the signature, for example some smartcard which has the private key on it. In this case no direct access to the private key is needed, since the signing is done on the PKCS11 backend (inside the smartcard). Since the private key never leaves the PKCS11 backend this is much safer than to have the private key accessible (and thus clonable by an attacker) on the system.

What advantages does using the CMS commands offer?

The decisions which led to the choice are not known, so one can only widely speculate. One possible reason is that CMS is an established standard format for signed/encrypted data, so why not use it.

  • Hey Steffen, Thank you for your reply. I am a newb when it comes to encryption/security. Can you elaborate (or point me to) on what you mean it uses PKCS11 backend to create the signature? It seems like the token=xxxx is important, and in some way representative of a key? Also, the -signer option that takes a certificate, why does it need a certificate and a key? Does it append the certificate onto the signature, but it is technically 'signed' with the PKCS11 key? Commented Jan 3 at 0:48
  • @DylanHolmes: "what you mean it uses PKCS11 backend" - PKCS11 provides a standard interface to external cryptographic backends like smartcards, HSM, ... which can be used for signing, encrypting ... - without the secret keys leaving these backends. The token argument is just an instruction to this backend which key to use. See Wikipedia:PKCS11 for more. Commented Jan 3 at 5:28
  • @DylanHolmes: "Also, the -signer option that takes a certificate, why does it need a certificate and a key?" - The private key is needed for signing, The certificate with the public key is included in the signed message (unless -nocerts is given) so that it is clear who signed the message. Commented Jan 3 at 5:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .