Hi, i want to sign a CSR on an embedded device with am62x-SOM using a private key on the nitrokey HSM. I already have certificates and keys stored on the HSM.
I have to use command line for an automated script. Also I’m fixed to openssl3, so the tutorial commands does not work. Is there a tutorial for openssl3?
Thx a lot! I have installed pkcs11-provider additionally and now i got a step further. But now it can not find the private key on the HSM. Am I using the correct key id?
openssl ca -keyfile pkcs11:id=3367dd2bf0d91233a8c4c7694fc985453d358305 -policy signing_policy -extensions signing_req -out new.pem -infiles nginx.csr
Using configuration from /usr/lib/ssl-3/openssl.cnf
Enter pass phrase for PKCS#11 Token (Slot 0 - Nitrokey Nitrokey HSM (ID) 00 00):
Could not find CA private key from pkcs11:id=3367dd2bf0d91233a8c4c7694fc985453d358305
pkcs15-tool --list-keys
Using reader with a card: Nitrokey Nitrokey HSM (ID) 00 00
Private EC Key [HansWerner]
Object Flags : [0x01], private
Usage : [0x104], sign, derive
Access Flags : [0x1D], sensitive, alwaysSensitive, neverExtract, local
Algo_refs : 0
FieldLength : 256
Key ref : 1 (0x01)
Native : yes
Auth ID : 01
ID : 3367dd2bf0d91233a8c4c7694fc985453d358305
MD:guid : 74c2f304-1064-f187-7d6b-13db27dcee6c
I don’t have a NitroHSM. But you’ll most likely only see your “protected” keys (such as for signing) after logging in, i.e., when running pkcs11-tool --login --list-objects. Also, the PKCS#11 URIs that I know are much more complicated than “pkcs11:id=3367dd2bf0d91233a8c4c7694fc985453d358305”. Newer OpenSC versions will show you the correct URI, as will p11tool from GnuTLS.
PS: I haven’t checked how this OpenSSL 3 PKCS#11 provider parses PKCS#11 URIs, but most likely at the very least you would have to “percent-encode” the ID. Here’s an example from the PKCS#11 URI RFC:
RFC 7512 The PKCS #11 URI Scheme April 2015
pkcs11:token=The%20Software%20PKCS%2311%20Softtoken;
manufacturer=Snake%20Oil,%20Inc.;
model=1.0;
object=my-certificate;
type=cert;
id=%69%95%3E%5C%F4%BD%EC%91;
I can set the key by label and I was missing the “-cert” param, which is in my case the same as “-keyfile” openssl ca -policy policy_anything -out new.pem -keyfile “pkcs11:object=testCA;type=private” -cert “pkcs11:object=testCA;type=cert” -in nginx.csr
Also I found a bug inside of XCA program: If you choose a template for an intermediate key, it will make it self-signed but displays it as signed by rootCA. Chain verification will then fail.
It was no bug, but my fault. If you want to verify the whole chain with openssl3 you have to set the flag “untrusted” on top, otherwise only the last certificate will be checked: openssl verify -CAfile <path> -untrusted <csr>.pem <csr>.pem