we use Nitrokey HSMs to generate and store multiple key pairs (EC, 30+ objects per HSM) for message signing/encryption and noticed that the first time a HSM is accessed by any application, e.g. OpenSC’s pkcs11-tool or by our application using OpenSC’s pkcs11 engine implemention in OpenSSL it takes a long time (almost 3 minutes with two HSM connected) until that request is answered. After that, all further requests only take a fraction of a second.
I did some debugging and it looks like every object is read once during the first access and the APDU requests to read a key’s information takes around 2 seconds each to read ~500 bytes of data.
I am aware, this might be more of a OpenSC related issue, but I wanted to at least know first, if these access times are indeed unusual.
Also, any hints on how to speed up access would be appreciated. I already tried to enable file caching in opensc.conf as a workaround, but it looks like it isn’t even used in this case.
Kind regards,
Marc
Additional info:
Nitrokey HSM hardware version 24.13, firmware version 4.0
OpenSC 0.25.0, OpenSSL 1.1.1,
Can be reproduced on both Linux (Ubuntu 20.04) + Windows 11
I tested with sc-hsm-embedded and it reduced initialization time by around 30% in my test environment. As you suspected, this mitgates the issue, but I’m not sure it really makes a difference in our case. It’s also not quite a drop-in replacement for OpenSC, since it’s a bit picky about how to address objects on the HSM and it would require a least some workarounds in our application.
I had somehow assumed we already got the newer HSM revision, since they were purchased very recently. I will see if I can get one for further testing.
I conducted some speed test with the latest firmware 4.1 and OpenSC-0.25.0 on the same PC using dual boot Windows 10 Home / Ubuntu 20.04.6 LTS. Speed is x5 faster with Windows compare to Linux!
~$ time /opt/opensc-25/bin/pkcs15-tool -D -s >/dev/null
Using reader with a card: Nitrokey Nitrokey HSM (DENK02008890000 ) 00 00
real 0m30,356s
user 0m0,025s
sys 0m0,007s
$ time /opt/opensc-25/bin/pkcs11-tool -O >/dev/null
Using slot 0 with a present token (0x0)
real 0m57,055s
user 0m0,024s
sys 0m0,023s