Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6520123

ClassCastException in KeyStoreSpi.engineLoad

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • security-libs

      FULL PRODUCT VERSION :
      java version "1.5.0_10"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
      Java Hotspot(TM) Client VM (build 1.5.0_10-b03, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      Whenever a keystore is creating using the indirection of a builder and no inputstream or file is given, then the method call getKeyStore on the builder object will result in a ClassCastException. The latter stems from a typo in the source file KeyStoreSpi.java (starting from line 365):

      ProtectionParameter protection = param.getProtectionParameter();
      char[] password;
      if (protection instanceof PasswordProtection) {
      password = ((PasswordProtection)param).getPassword();
      } else if (protection instanceof CallbackHandlerProtection) {
      CallbackHandler handler =
      ((CallbackHandlerProtection)param).getCallbackHandler();

      Instead of casting the variable param here it should be the variable protection.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Construct a keystore object using the indirection of a builder only specifying the keystore type and protection parameters using the method

      KeyStore.Builder.newInstance(String, Provider, ProtectionParameter);

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The load operation loads the keystore without throwing an unrelated exception.
      ACTUAL -
      The load operation throws a ClassCastException.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.ClassCastException:
      java.security.KeyStore$SimpleLoadStoreParameter
               at java.security.KeyStoreSpi.engineLoad(KeyStoreSpi.java:368)
               at java.security.KeyStore.load(KeyStore.java:1180)
               at java.security.KeyStore$Builder$2$1.run(KeyStore.java:1598)
               at java.security.AccessController.doPrivileged(Native Method)
               at java.security.KeyStore$Builder$2.getKeyStore(KeyStore.java:1607)
               at Test.main(Test.java:8)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Test {
          public static void main(String[] args) {
              KeyStore.Builder builder = KeyStore.Builder.newInstance(keyStoreType,
                  null, new PasswordDialog());
              KeyStore store = builder.getKeyStore();
          }
      }
      ...
      class PasswordDialog extends KeyStore.PasswordProtection {
          public PasswordDialog() {
              super(null);
          }
          
          public char[] getPassword() {
              return new char[]{'t', 'e', 's', 't'};
          }
      }
      ---------- END SOURCE ----------

            andreas Andreas Sterbenz
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: