I installed Softhsm v 2.2 and Started working with PkCS#11 Java API that on
Operations:
I am getting below exception :
Exception in thread "main" java.security.ProviderException: Initialization failed
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:376)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:103)
at SoftHSM.main(SoftHSM.java:47)
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_TOKEN_NOT_RECOGNIZED
at sun.security.pkcs11.wrapper.PKCS11.C_OpenSession(Native Method)
at sun.security.pkcs11.SessionManager.openSession(SessionManager.java:215)
at sun.security.pkcs11.SessionManager.getOpSession(SessionManager.java:150)
at sun.security.pkcs11.Token.<init>(Token.java:151)
at sun.security.pkcs11.SunPKCS11.initToken(SunPKCS11.java:858)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:367)
... 2 more
My softhsm.cfg
name = SoftHSM
library = Z:\SOFTHSM_INSTALL\lib\softhsm2-x64.dll
slot= 0
attributes(generate, *, *) = {
CKA_TOKEN = true
}
attributes(generate, CKO_CERTIFICATE, *) = {
CKA_PRIVATE = false
}
attributes(generate, CKO_PUBLIC_KEY, *) = {
CKA_PRIVATE = false
}
After I tried another after restart of PC:
C:\SoftHSM2\bin>softhsm2-util.exe --show-slots
Available slots:
Slot 0
Slot info:
Description: SoftHSM slot ID 0x0
Manufacturer ID: SoftHSM project
Hardware version: 2.2
Firmware version: 2.2
Token present: yes
Token info:
Manufacturer ID: SoftHSM project
Model: SoftHSM v2
Hardware version: 2.2
Firmware version: 2.2
Serial number:
Initialized: no
User PIN init.: no
Label:
C:\SoftHSM2\bin> softhsm2-util.exe --init-token --slot 1 --label "A token"
=== SO PIN (4-255 characters) ===
Please enter SO PIN: ******
Please reenter SO PIN: ******
=== User PIN (4-255 characters) ===
Please enter user PIN: ****
Please reenter user PIN: ****
CKR_SLOT_ID_INVALID: Slot 1 does not exist.
C:\SoftHSM2\bin> softhsm2-util.exe --init-token --slot 0 --label "0 token"
=== SO PIN (4-255 characters) ===
Please enter SO PIN: ******
Please reenter SO PIN: ******
=== User PIN (4-255 characters) ===
Please enter user PIN: ****
Please reenter user PIN: ****
The token has been initialized.
C:\SoftHSM2\bin>softhsm2-util.exe --show-slots
Available slots:
Slot 1526831955
Slot info:
Description: SoftHSM slot ID 0x5b019b53
Manufacturer ID: SoftHSM project
Hardware version: 2.2
Firmware version: 2.2
Token present: yes
Token info:
Manufacturer ID: SoftHSM project
Model: SoftHSM v2
Hardware version: 2.2
Firmware version: 2.2
Serial number: cafa9efc5b019b53
Initialized: yes
User PIN init.: yes
Label: 0 token
Slot 1
Slot info:
Description: SoftHSM slot ID 0x1
Manufacturer ID: SoftHSM project
Hardware version: 2.2
Firmware version: 2.2
Token present: yes
Token info:
Manufacturer ID: SoftHSM project
Model: SoftHSM v2
Hardware version: 2.2
Firmware version: 2.2
Serial number:
Initialized: no
User PIN init.: no
Label:
C:\SoftHSM2\bin> softhsm2-util.exe --init-token --slot 0 --label "B token"
=== SO PIN (4-255 characters) ===
Please enter SO PIN: ******
Please reenter SO PIN: ******
=== User PIN (4-255 characters) ===
Please enter user PIN: ****
Please reenter user PIN: ****
CKR_SLOT_ID_INVALID: Slot 0 does not exist.
C:\SoftHSM2\bin> softhsm2-util.exe --init-token --slot 5 --label "s5 token"
=== SO PIN (4-255 characters) ===
Please enter SO PIN: ******
Please reenter SO PIN: ******
=== User PIN (4-255 characters) ===
Please enter user PIN: ****
Please reenter user PIN: ****
CKR_SLOT_ID_INVALID: Slot 5 does not exist.
C:\SoftHSM2\bin> softhsm2-util.exe --init-token --slot 0 --label "1 token"
=== SO PIN (4-255 characters) ===
Please enter SO PIN: ******
Please reenter SO PIN: ******
=== User PIN (4-255 characters) ===
Please enter user PIN: ****
Please reenter user PIN: ****
CKR_SLOT_ID_INVALID: Slot 0 does not exist.
C:\SoftHSM2\bin>
But Now it says its initialized, but still I dont know what slot id i have to provide . I tried with slot=1, slot=1526831955 but I am getting
sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SLOT_ID_INVALID