pkcs11-tool and openssl directly, or the hsm_sign_verify.sh script that wraps the RSA pipeline.
- RSA-PKCS
- ECDSA
RSA-PKCS pipeline
The RSA-PKCS pipeline hashes the file separately and passes the raw hash topkcs11-tool.Using hsm_sign_verify.sh
Thehsm_sign_verify.sh script wraps the sign → export pubkey → verify steps for a single input file. It passes the input directly to pkcs11-tool --mechanism RSA-PKCS, so the input should be a pre-computed binary SHA-256 digest.
Configuration variables
Edit the top of the script to match your environment:Running the script
Hash your file first, then pass the hash to the script:| File | Description |
|---|---|
firmware.sha256.sig | Raw RSA-PKCS signature |
pubkey.pem | PEM-encoded RSA public key |
Common errors
Private key not found
Private key not found
--id value does not match any private key object in the slot. Verify with:Private Key Object exists with the expected ID.Slot mismatch
Slot mismatch
--slot does not match the initialized token. Run softhsm2-util --show-slots to get the correct slot ID and update SLOT in the script or your command.Wrong hash format for RSA-PKCS
Wrong hash format for RSA-PKCS
RSA-PKCS expects raw binary hash input. If you produced the hash with
openssl dgst -sha256 (without -binary), the input contains a hex digest line rather than raw bytes, and the signature will be invalid or the tool will error.Always use -binary when preparing input for --mechanism RSA-PKCS:EC key exported with wrong openssl subcommand
EC key exported with wrong openssl subcommand
Attempting to convert an EC public key with Use
openssl rsa produces:openssl ec for EC keys: