Stuck when generating a RSA key #115
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I am using a ESP32-S3 board to flash the Pico HSM firmware. The OS is Windows 11 Pro.
I followed the steps in the doc/usage.md. The initialization is good. The init cmd is as below:
python pico-hsm-tool.py initialize --pin 275809 --so-pin E11DEBA1706B3903And then I modify the VID/PID using Pico Commissioner web tool. This step is also good. (I saw the success sign.)
When I started generating RSA key following the instruction in usage.md, it went wrong. This process took over 20 min.
The keypair gen cmd is
pkcs11-tool -l --pin 275809 --keypairgen --key-type rsa:1024 --id 1 --label "k1". To speed up the process, I used the rsa:1024, but it didn't work.I had no idea what happened, so I tried the keypair generation process several times. If I unplug the USB key within a couple of minutes, the cmd.exe prompts like this:
C:\Users\michaelren\Repositories\pico-hsm\tools>pkcs11-tool -l --pin 275809 --keypairgen --key-type rsa:1024 --id 1 --label "k1"
Using slot 0 with a present token (0x0)
error: PKCS11 function C_GenerateKeyPair failed: rv = CKR_DEVICE_REMOVED (0x32)
Aborting.
However, once I waited too long to know how much time the generation process took, and finally I removed the USB, this time the output info changed to:
C:\Users\michaelren\Repositories\pico-hsm\tools>pkcs11-tool -l --pin 275809 --keypairgen --key-type rsa:1024 --id 1 --label "k1"
Using slot 0 with a present token (0x0)
error: PKCS11 function C_GenerateKeyPair failed: rv = CKR_GENERAL_ERROR (0x5)
Aborting.
P.S. Tried different ESP32-S3 boards, the results were same.
Yes, ESP32 is really painful doing RSA. Use it for ECC instead or generate it offline and import.
So the ESP32 is totally out for RSA, right?
I guess RP2350 is better option for Pico HSM.
SmartCard-HSM Version 6.0 on JCOP Free memory 1048576 byte
Issuer Certificate : CVC id-AT DV (official domestic) CAR=ESPICOHSMCA00002 CHR=ESPICOHSMDV00002 CED=April 6, 2025 CXD=April 6, 2026
Device Certificate : CVC id-AT Terminal CAR=ESPICOHSMDV00002 CHR=ESPICOHSMTR692WX CED=December 7, 2025 CXD=December 7, 2026
Default Key Domain : 57C6E455BB768A1E76FFF38BD036A0085798613918731A4D5150EAA36C4E0C8E
Creating outline...
org.mozilla.javascript.EcmaError: ReferenceError: "OutlineNode" is not defined. (D:\Program Files\scsh_with_JRE\keymanager\keymanager.js#1653)
at D:\Program Files\scsh_with_JRE\keymanager\keymanager.js#1653
at D:\Program Files\scsh_with_JRE\keymanager\keymanager.js#304
at D:\Program Files\scsh_with_JRE\keymanager\keymanager.js#41
at D:\Program Files\scsh_with_JRE\keymanager\keymanager.js#3348
@polhenarejos I got this when I tried to import RSA key. I double checked the code and am sure everything goes as scs3.md. Is scsh with JRE not the compatible scsh for this?
@polhenarejos Btw, I tried the "Generate certificate and sign it" section and ran
opensslinstalled bywinget. I know thisopensslis not connected with pkcs11-tool that connects with Pico HSM key, so how can I fix that?Thx for your help.
In case someone has same issue, I post what I've done to fix the issue I had. Hopefully, this post will help someone.
When I installed openssl using
winget, I triedopenssl req -engine pkcs11 -new -key 0:1 -keyform engine -out cert.pem -text -x509 -days 365to sign the certificate. But it output as below:To fix this, download pre-compiled pkcs11.dll from OpenSC libq11 release page. For OpenSSL 3.x use the latest libp11 version. Unzip the downloaded archive, copy pkcs11.dll to somewhere under C drive. I put it in the subdir of openssl.
Then, set the environment variable OPENSSL_CNF
set OPENSSL_CNF=C:\Program Files\OpenSSL-Win64\bin\cnf\openssl.cnf. Note that no need to add quotes even if the path has a space char. I also set PKCS11_MODULE_PATH toC:\Program Files\OpenSC Project\pkcs11\opensc-pkcs11.dll.Next, edit the file openssl.cnf that is located at
C:\Program Files\OpenSSL-Win64\bin\cnf(C:\Program Files\OpenSSL-Win64is where I installed openssl). Make sureopenssl_conf = openssl_initis in the file, and then add following lines at the end of the file:Next, run
openssl engine dynamic -pre ID:pkcs11 -pre SO_PATH:/path/to/openssl/lib/engines/pkcs11.dll -pre LIST_ADD:1 -pre LOAD -pre MODULE_PATH:/path/to/OpenSC/pkcs11/opensc-pkcs11.dllto load the engine and point it to module. Some-preoptions can be taken down.Now, run
openssl engine pkcs11 -tto check if the engine is set right. If you see:the engine setting should be passed.