title: PKCS#11 keystore does not validate password after successful attempt to enter it
body: <p>I'm using the following code to access the contents of a PKCS#11 smartcard from an Athena smartcard reader.</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>The problem is as follows:</p>
  
  <ol>
  <li>I enter wrong password.</li>
  <li>Code throws an exception (as expected).</li>
  <li>I enter correct password.</li>
  <li>Code does not throw an exception (as expected).</li>
  <li>I enter wrong password.</li>
  <li>Code does <em>not</em> throw an exception (unexpected).</li>
  </ol>
  
  <p>According to <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/p11guide.html" rel="nofollow">http://docs.oracle.com/javase/6/docs/technotes/guides/security/p11guide.html</a>, when the <code>KeyStore.Builder</code> 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  <code>KeyStore.getInstance(...)</code> method? Is there any way to make the keystore throw exceptions when wrong passwords are entered, regardless of previous load attempts?</p>