Repository navigation
"no slot found" when running in LXC with nitrokey HSM2 #13
Copy link
Copy link
Closed
Description
Any help would be highly appreciated as this is my first time using these HSMs.
i am getting the following log:
Dec 06 22:37:56 ca-master nixpkcs.sh[16939]: [nixpkcs.sh/I] (step-ca) <exec> pkcs11-tool --token-label SmartCard-HSM --id 01 --label step-ca --login --login-type user --pin //REDACTED// --keypairgen --key-type EC:secp256r1 --usage-sign --usage-derive
Dec 06 22:37:56 ca-master nixpkcs.sh[16939]: No slot with token named "SmartCard-HSM" found
this seems to be a problem with the systemd service, it also outputs a different result here:
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: [nixpkcs.sh/I] (step-ca) <exec> pkcs11-tool --token-label SmartCard-HSM --id 01 --label step-ca --list-slots
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: Available slots:
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: Slot 0 (0x1): NSS Internal Cryptographic Services
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: token label : NSS Generic Crypto Services
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: token manufacturer : Mozilla Foundation
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: token model : NSS 3
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: token flags : rng, token initialized, readonly, other flags=0x200
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: hardware version : 4.0
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: firmware version : 0.0
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: serial num : 0000000000000000
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: pin min/max : 0/0
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: uri : pkcs11:model=NSS%203;manufacturer=Mozilla%20Foundation;serial=0000000000000000;token=NSS%20Generic%20Crypto%20Services
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: Slot 1 (0x2): NSS User Private Key and Certificate Services
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: token label : NSS Certificate DB
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: token manufacturer : Mozilla Foundation
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: token model : NSS 3
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: token flags : login required, rng, token initialized, PIN initialized, other flags=0x200
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: hardware version : 0.0
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: firmware version : 0.0
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: serial num : 0000000000000000
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: pin min/max : 0/500
Dec 06 22:37:56 ca-master nixpkcs.sh[16935]: uri : pkcs11:model=NSS%203;manufacturer=Mozilla%20Foundation;serial=0000000000000000;token=NSS%20Certificate%20DB
but if i run it (as root):
root@ca-master ~# pkcs11-tool --token-label SmartCard-HSM --id 01 --label step-ca --list-slots
Available slots:
Slot 0 (0x0): Nitrokey Nitrokey HSM (DENK03012600000 ) 00 00
token label : SmartCard-HSM
token manufacturer : www.CardContact.de
token model : PKCS#15 emulated
token flags : login required, rng, token initialized, PIN initialized
hardware version : 24.13
firmware version : 4.0
serial num : DENK0301260
pin min/max : 6/15
uri : pkcs11:model=PKCS%2315%20emulated;manufacturer=www.CardContact.de;serial=DENK0301260;token=SmartCard-HSM
Metadata
Metadata
Assignees
Labels
No labels
Activity
numinit commentedon Dec 7, 2024
Can you paste your key definition in your config?
numinit commentedon Dec 7, 2024
The short answer is that it looks like nixpkcs is using NSS (which is more suited for testing). Do you know which PKCS#11 module your key likes to use? We can fairly easily add support for it.
Arbel-arad commentedon Dec 7, 2024
from what i can tell it is supposed to work with
opensc-pkcs11(normal use) andsc-hsm-embedded(read only mode)numinit commentedon Dec 7, 2024
It's probably just a matter of pointing it at the correct PKCS#11 module. I'll take a look at the right config snippet to add.
numinit commentedon Dec 8, 2024
@Arbel-arad Try using the master branch; this commit may fix it:
be572d4
Instead of saying
pkcs11Module = pkgs.nss_latest.pkcs11Module;in your key definition, useinherit (pkgs.opensc) pkcs11Module;Arbel-arad commentedon Dec 8, 2024
ok it passes the key generation stage now, but fails when trying to create a certificate (technically i don't need the cert)
i also had to put the user pin in the SO pin file because
loginAsUserdidn't use the user pin file for key generation.Dec 08 06:25:13 ca-master nixpkcs.sh[25231]: Could not find private key from pkcs11:id=%0A;object=step-ca;slot-id=2;token=SmartCard-HSM;type=private?module-path=%2Fnix%2Fstore%2F7bl2k36rcrdlp681km9pa0abwm0kngid-opensc-0.26.0%2Flib%2Fopensc-pkcs11.so&pin-source=file%3A%2Fetc%2Fuser.pincan i just disable certificate signing?
it will be signed by an external root anyway.
numinit commentedon Dec 8, 2024
The certificate is how it determines whether the key should be re-generated based on the renewal period in the key definition (and yes, you can definitely replace it with your own, but it basically uses the certificate as a record that the key was generated at a certain point in time). For your issue though, try getting rid of the
slot = 2in the config, you shouldn't need that. There is only one slot for your token.This is expected. You can also point them to the same file.
Arbel-arad commentedon Dec 8, 2024
it worked after removing the
slot = 2;. thank you!numinit commentedon Dec 8, 2024
Excellent, good confirmation that it works on the Nitrokey too. The next release will include the passthru exposing the OpenSC PKCS#11 module.
numinit commentedon Dec 22, 2024
v1.1.9 releases this change.