title: java keytool with opensc pkcs#11 provider only works with debug option enabled
body: <p>I have the latest opensc 0.12.2 running on ubuntu 11.10 with OpenJDK ( java version "1.6.0_22")</p>
  
  <p>I can read my smartcard (a Feitian ePass PKI) with</p>
  
  <pre><code>pkcs15-tool --dump
  </code></pre>
  
  <p>Now i try to use my smartcard with keytool:</p>
  
  <pre><code>keytool 
     -providerClass sun.security.pkcs11.SunPKCS11 \
     -providerArg /etc/opensc/opensc-java.cfg \
     -keystore NONE -storetype PKCS11 -list 
  </code></pre>
  
  <p>which results in an error:</p>
  
  <pre><code>keytool error: java.security.KeyStoreException: PKCS11 not found
  java.security.KeyStoreException: PKCS11 not found
      at java.security.KeyStore.getInstance(KeyStore.java:603)
      at sun.security.tools.KeyTool.doCommands(KeyTool.java:621)
      at sun.security.tools.KeyTool.run(KeyTool.java:194)
      at sun.security.tools.KeyTool.main(KeyTool.java:188)
  Caused by: java.security.NoSuchAlgorithmException: PKCS11 KeyStore not available
      at sun.security.jca.GetInstance.getInstance(GetInstance.java:159)
      at java.security.Security.getImpl(Security.java:696)
      at java.security.KeyStore.getInstance(KeyStore.java:600)
      ... 3 more
  </code></pre>
  
  <p>When i run the same command with debug options enabled like this:</p>
  
  <pre><code>keytool 
     -providerClass sun.security.pkcs11.SunPKCS11 \
     -providerArg /etc/opensc/opensc-java.cfg \
     -keystore NONE -storetype PKCS11 -list \
     -J-Djava.security.debug=sunpkcs11
  </code></pre>
  
  <p>it suddenly works:</p>
  
  <pre><code>... debug infos ...
  Enter keystore password:  
  sunpkcs11: login succeeded
  
  Keystore type: PKCS11
  Keystore provider: SunPKCS11-OpenSC
  
  Your keystore contains 2 entries
  ...
  Certificate fingerprint (MD5): ...
  ...
  Certificate fingerprint (MD5): ...
  </code></pre>
  
  <p>The same behaviour when i configure it statically:</p>
  
  <pre><code>$ grep opensc /usr/lib/jvm/java-6-openjdk/jre/lib/security/java.security
  security.provider.7=sun.security.pkcs11.SunPKCS11 /etc/opensc/opensc-java.cfg
  </code></pre>
  
  <p>and my config</p>
  
  <pre><code>$ cat /etc/opensc/opensc-java.cfg
  name = OpenSC
  description = SunPKCS11 w/ OpenSC Smart card Framework
  library = /usr/lib/opensc-pkcs11.so
  </code></pre>
  
  <p>My guess it, it has something to do with openjdk or internal package <code>sun.security</code> which might usually not be used because it is an internal package. Activating Debug options might activate this internal package?</p>