Hello,
This is how I do it with swupdate + Nitrokey HSM 2.
1. First we need to extract the public key from the Nitrokey to include it in the rootfs (this is used by swupdate to check the signature of .swu (or more specifically: sw-description))
export PKCS11_MODULE_PATH="/usr/local/lib/libsc-hsm-pkcs11.so"
pkcs11-tool --module "${PKCS11_MODULE_PATH}" --read-object --type pubkey --label "OTA" > /tmp/swu_public.der
# Convert DER → PEM
openssl rsa -pubin -inform DER -in /tmp/swu_public.der -outform PEM -out /tmp/swu_public.pem
Note: In our HSM, the key label is "OTA"
2. Generate the sw-description.sig file:
export SWUPDATE_PKCS11_SIGN_KEY="pkcs11:token=SmartCard-HSM;object=OTA;type=private"
openssl dgst -sha256 -engine pkcs11 -keyform engine -sign "${SWUPDATE_PKCS11_SIGN_KEY}" -out "sw-description.sig" "sw-description"
the pkcs11: URI is to identify the correct key to use:
- You can adapt depending on your HSM configuration (name of the key, token ..)
- Make sure it is not ambiguous (if you have multiple keys with same label or ..) : So add more parameters if needed