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

X509KeyManager implementation for NewSunX509 throws unspecified ProviderException

XMLWordPrintable

    • beta
    • generic
    • generic

      According to the specification for getPrivateKey(String alias) and
      getCertificateChain(String alias) should return null if the alias can't be found.

      But implementation for NewSunX509 throws ProviderException in this case.

      To reproduce this bug please use the following example.
      Note the attached keystore should be placed in the current directory in "keystore" file.
      -------------------------Test.java--------------------
      package test;

      import java.io.*;
      import java.net.*;
      import java.security.*;
      import javax.net.ssl.*;

      public class Test {

          public static void main(String[] args) {
              KeyStore ks = null;
              KeyManagerFactory kmf = null;
              String word = "password";
              char [] password = word.toCharArray();

              try {
                  ks = KeyStore.getInstance("JKS");
                  ks.load(new FileInputStream("keystore"), "StorePass".toCharArray());
                  kmf = KeyManagerFactory.getInstance("NewSunX509");
                  kmf.init(ks, "KeyPass".toCharArray());
                  KeyManager[] managers = kmf.getKeyManagers();

                  try {
                      ((X509KeyManager)managers[0]).getPrivateKey("doesnotexist");
                  } catch (ProviderException e) {
                      System.out.println("1. getPrivateKey throws ProviderException.");
                  }

                  try {
                      ((X509KeyManager)managers[0]).getCertificateChain("doesnotexist");
                  } catch (ProviderException e) {
                      System.out.println("2. getCertificateChain throws ProviderException.");
                  }
              } catch (NoSuchAlgorithmException nsae) {
                  nsae.printStackTrace();
                  System.out.println("Failed: Unexpected " + nsae);
                  return;
              } catch (Exception nspe) {
                  nspe.printStackTrace();
                  System.out.println("Failed: Unexpected " + nspe);
                  return;
              }
          }
      }
      5.0

            xuelei Xuelei Fan
            msokolni Maxim Sokolnikov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: