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

MSCAPI doesn't list aliases correctly

    Details

    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 9, 10
    • Fix Version/s: tbd
    • Component/s: security-libs
    • Labels:
      None

      Description

      Test:
      import java.security.KeyStore;
      import java.security.KeyStoreException;
      import java.security.SecureRandom;
      import java.util.Enumeration;

      import sun.security.tools.keytool.CertAndKeyGen;
      import sun.security.x509.X500Name;

      public class WinKeyStoreTest {

          public static void main(String[] args) throws Exception {
              KeyStore keyStore = KeyStore.getInstance("Windows-MY");
              keyStore.load(null, null);
              System.out.println("keystore loaded");
              listAlias(keyStore);

              String alias = "test";
              int number = 2;

              System.out.println("add alias...");
              CertAndKeyGen ckg = new CertAndKeyGen("RSA", "SHA1withRSA");
              ckg.setRandom(new SecureRandom());
              for (int i = 0; i < number; i++) {
                  ckg.generate(1024);
                  keyStore.setCertificateEntry(alias,
                          ckg.getSelfCertificate(new X500Name("CN=TEST"), 1000));
              }
              System.out.println("alias added");
              listAlias(keyStore);

              keyStore.load(null, null);
              System.out.println("keystore reloaded");
              listAlias(keyStore);
          }

          private static void listAlias(KeyStore keyStore) throws KeyStoreException {
              System.out.println("===== alias list =====");
              for (Enumeration<String> e = keyStore.aliases(); e.hasMoreElements();) {
                  String alias = e.nextElement();
                  System.out.println(alias);
              }
              System.out.println("======================");
          }
      }

      Test output:
      keystore loaded
      ===== alias list =====
      ======================
      add alias...
      alias added
      ===== alias list =====
      test
      ======================
      keystore reloaded
      ===== alias list =====
      test
      test (1)
      ======================

      The test adds two entries with the same alias to Windows-MY keystore, before reload the keystore, it lists only one alias.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                weijun Weijun Wang
                Reporter:
                jjiang John Jiang
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: