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

Keystore can not read RSA keys

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.2
    • security-libs

      Name: gm110360 Date: 08/04/2003


      FULL PRODUCT VERSION :
      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

      FULL OS VERSION :
      Linux kolli.hds.se 2.4.21-0.13mdk #1 Fri Mar 14 15:08:06 EST 2003 i686 unknown unknown GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      An RSA private key created with keytool can not be read from a java program.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the command: "keytool -genkey -alias rsatest -keyalg RSA -keysize 1024 -keypass abc123 -keystore testkeystore -storepass abc123 -storetype JCEKS"

      Run the provided test case with the arguments "read testkeystore"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The test case should print the following information:

      Found alias: rsatest
      rsatest key algorithm: RSA
      rsatest key format: PKCS8
      ACTUAL -
      The test case could find the key but threw an exception on "getKey".

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.NullPointerException
              at com.sun.crypto.provider.SunJCE_z.a(DashoA6275)
              at com.sun.crypto.provider.JceKeyStore.engineGetKey(DashoA6275)
              at java.security.KeyStore.getKey(KeyStore.java:289)
              at Test.main(Test.java:29)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import java.security.*;
      import java.security.cert.Certificate;
      import java.util.Enumeration;

      public class Test {
         static char[] password = "abc123".toCharArray();

         public static void main(String[] args) throws Exception {
            if ("read".equalsIgnoreCase(args[0])) {
               InputStream fIn = new FileInputStream(args[1]);
               KeyStore keyStore = KeyStore.getInstance("JCEKS");
               keyStore.load(fIn, password);

               Enumeration enum = keyStore.aliases();
               while (enum.hasMoreElements()) {
                  String alias = (String) enum.nextElement();
                  System.out.println("Found alias: " + alias);
                  if (keyStore.isKeyEntry(alias)) {
                     Key key = keyStore.getKey(alias, password);
                     System.out.println(alias + " key algorithm: " + key.getAlgorithm());
                     System.out.println(alias + " key format: " + key.getFormat());
                  }
                  if (keyStore.isCertificateEntry(alias)) {
                     Certificate cert = keyStore.getCertificate(alias);
                     System.out.println(alias + " cert type: " + cert.getType());
                  }
               }

            } else if ("write".equalsIgnoreCase(args[0])) {
               KeyStore keyStore = KeyStore.getInstance("JCEKS");
               keyStore.load(null, password);

               FileOutputStream output = new FileOutputStream(args[1]);
               keyStore.store(output, password);
            }
         }
      }
      ---------- END SOURCE ----------
      (Incident Review ID: 189725)
      ======================================================================

            valeriep Valerie Peng
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: