Hi all!
I'm trying to reach a smartcard through the PKCS#11 Bridge. The smartcard itselfs has middleware software which has to prompt me with a logon popup. But when I try to run the following code, i get a Exception which tells me the PIN is incorrect. This is reasonalbe because i didn't yet insert the pin. Did someone had the same problem?
I hope someone can tell me why i'm not getting the popup? I dont want to store the pin in my code, because it has to be dynamically.
Java code:
import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.Security;
import java.security.UnrecoverableKeyException;
public class ReadUZI {
/**
* @param args
*/
public static void main(String[] args) {
String configName = "Pkcs11eToken.properties";
Provider provider = new sun.security.pkcs11.SunPKCS11(configName);
Security.addProvider(provider);
KeyStore.ProtectionParameter pp = new KeyStore.PasswordProtection(new char[]{});
KeyStore.Builder keyStoreBuilder = KeyStore.Builder.newInstance("PKCS11",provider,pp);
try {
KeyStore ks = keyStoreBuilder.getKeyStore();
Key key = ks.getKey("alias", null);
} catch (KeyStoreException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnrecoverableKeyException e) {
e.printStackTrace();
}
}
}
The Exception:
java.security.KeyStoreException: KeyStore instantiation failed
at java.security.KeyStore$Builder$2.getKeyStore(Unknown Source)
at nl.atosorigin.et.hl7.ReadUZI.main(ReadUZI.java:27)
Caused by: java.io.IOException: load failed
at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:830)
at java.security.KeyStore.load(Unknown Source)
at java.security.KeyStore$Builder$2$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 2 more
Caused by: javax.security.auth.login.FailedLoginException
at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:900)
at sun.security.pkcs11.P11KeyStore.login(P11KeyStore.java:846)
at sun.security.pkcs11.P11KeyStore.engineLoad(P11KeyStore.java:821)
... 5 more
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_PIN_INCORRECT
at sun.security.pkcs11.wrapper.PKCS11.C_Login(Native Method)
at sun.security.pkcs11.SunPKCS11.login(SunPKCS11.java:888)
... 7 more
the configuration file:
name = uzipas
library = C:\WINDOWS\system32\aetpkss1.dll
I hope to hear from you all soon! :)
My regards,
Jan-Martijn