문제

I'm using the following code to access the contents of a PKCS#11 smartcard from an Athena smartcard reader.

Provider pkcs11Provider = new SunPKCS11(new ByteArrayInputStream (config.getBytes()));
if (Security.getProvider(pkcs11Provider.getName()) != null) {
    Security.removeProvider(pkcs11Provider.getName());
}

Security.addProvider(pkcs11Provider);

KeyStore myKeyStore = KeyStore.getInstance ("PKCS11", pkcs11Provider);
myKeyStore.load(null, keystore_password.toCharArray());

return myKeyStore;

The problem is as follows:

  1. I enter wrong password.
  2. Code throws an exception (as expected).
  3. I enter correct password.
  4. Code does not throw an exception (as expected).
  5. I enter wrong password.
  6. Code does not throw an exception (unexpected).

According to http://docs.oracle.com/javase/6/docs/technotes/guides/security/p11guide.html, when the KeyStore.Builder class is used, no password is asked for after the first successful load using the same smartcard. Of course, I'm not using this class in the code above. Does the same thing apply to KeyStore.getInstance(...) method? Is there any way to make the keystore throw exceptions when wrong passwords are entered, regardless of previous load attempts?

도움이 되었습니까?

해결책

try this

((SunPKCS11) pkcs11Provider ).logout();
pkcs11Provider.clear();

if this doesn't help then replace the provider with newly created SunPKCS11 object before each login

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top