Skip to content

Commit e73fdcb

Browse files
committed
Allow the keystore parameter to specify a slot number with the OPENSC storetype
1 parent c70736a commit e73fdcb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

jsign-core/src/main/java/net/jsign/OpenSC.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525

2626
import sun.security.pkcs11.wrapper.CK_SLOT_INFO;
27+
import sun.security.pkcs11.wrapper.CK_TOKEN_INFO;
2728
import sun.security.pkcs11.wrapper.PKCS11;
2829
import sun.security.pkcs11.wrapper.PKCS11Exception;
2930

@@ -48,7 +49,7 @@ static Provider getProvider(String name) {
4849
/**
4950
* Returns the SunPKCS11 configuration for OpenSC.
5051
*
51-
* @param name the name of the token
52+
* @param name the name or the slot id of the token
5253
* @throws ProviderException thrown if the PKCS11 modules cannot be found
5354
*/
5455
static String getSunPKCS11Configuration(String name) {
@@ -58,7 +59,12 @@ static String getSunPKCS11Configuration(String name) {
5859
}
5960
String configuration = "--name=opensc\nlibrary = \"" + libpkcs11.getAbsolutePath().replace("\\", "\\\\") + "\"\n";
6061
try {
61-
long slot = getTokenSlot(libpkcs11, name);
62+
long slot;
63+
try {
64+
slot = Integer.parseInt(name);
65+
} catch (Exception e) {
66+
slot = getTokenSlot(libpkcs11, name);
67+
}
6268
if (slot >= 0) {
6369
configuration += "slot=" + slot;
6470
}

0 commit comments

Comments
 (0)