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

KeyStore.store can write wrong type of file

    XMLWordPrintable

Details

    • b26
    • generic
    • generic
    • Verified

    Description

      Create a PKCS12 keystore. Initialize as empty then attempt to load from a empty file. The load fails as expected. If you then write the keystore with KeyStore.store(OutputStream, char[]) you end up with a JKS keystore. The reverse also happens - if you start with a JKS keystore you end up with PKCS12 after the store.

      Here's a small test:

      public class ksload {

        public static void main(String ... args) throws Exception {
          
          File file = new File(args[0]);
          char [] pw = {'x'};
          KeyStore ks = KeyStore.getInstance("PKCS12");
          
          ks.load(null, null);
          
          try (InputStream in = new FileInputStream(file)) {
            ks.load(in, pw);
          } catch (Exception e) {
            System.out.println(e);
          }
          
          try (OutputStream out = new FileOutputStream(file)) {
            ks.store(out, pw);
          } catch (Exception e) {
            System.out.println(e);
          }
        }
      }

      Run it with an argument naming an empty file.

      Seems OK in Java 1.8.

      Attachments

        Activity

          People

            weijun Weijun Wang
            revans Richard Evans
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: