Hello,
I have an application where PKCS11 providers will be loaded dynamically. Therefore I have the following code:
String config = "name=" + libName + "\nlibrary=" + lib + "\nslot=" + slot;
Provider p1 = new sun.security.pkcs11.SunPKCS11(new ByteArrayInputStream(config.getBytes()));
Security.addProvider(p1);
KeyStore ks = KeyStore.getInstance("PKCS11", p1);
The problem is: how do I define the slot variable? I thought not defining the slot parameter would make Java pick the first free slot to associate this provider with, but I've noticed this is not the case. When I don't specify the slot parameter, I get the following exception:
java.security.KeyStoreException: PKCS11 not found
at java.security.KeyStore.getInstance(KeyStore.java:645)
I've noticed that for certain providers, like Belgium eID provider or Mozilla NSS provider, I have to give the slot parameter one specific value for it to work! For Belgium eID slot = 3 and for Mozilla NSS slot = 2, when I reverse those values (2 for eID, 3 for NSS), it won't work! How is this possible?
Is there a way so I can dynamically determine the free slots? Or does anyone know why my providers will only load on one specific slot number, even if the others are still free?
And what is the difference between the "slot" parameter and the "slotListIndex" parameter?
I found the following documentation about slot and slotListIndex, but I still can't see the difference: [http://www.uni-ulm.de/admin/doku/jdk1.5/docs/guide/security/p11guide.html#Config]
Thanks in advance!