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

X509KeyManager implementation for NewSunX509 throws unspecified NullPointerException

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      generic
    • OS:
      generic

      Description

      The X509KeyManager methods does not allow NullPointerException. But the NewSunX509 implementation throws NullPointerException in the following cases: Note that SunX509 does not
      throw NullPointerException in these cases:
       1. getServerAliases(String keyType, Principal[] issuers) throws NullPointerException if the
      keyType is null.
       2. getClientAliases(String keyType, Principal[] issuers) throws NullPointerException if the
      keyType is null.
       3. getPrivateKey(String alias) throws NullPointerException if the alias is null
       4. getCertificateChain(String alias) throws NullPointerException if the alias is null
       5. chooseServerAlias(String keyType, Principal[] issuers, Socket socket) throws
      NullPointerException if the keyType is null.
       6. chooseClientAlias(String keyType, Principal[] issuers, Socket socket) throws
      NullPointerException if the keyType is null.

      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]).getServerAliases(null, null);
                  } catch (NullPointerException e) {
                      System.out.println("1. getServerAliases throws NullPointerException.");
                  }
                  try {
                      ((X509KeyManager)managers[0]).getClientAliases(null, null);
                  } catch (NullPointerException e) {
                      System.out.println("2. getClientAliases throws NullPointerException.");
                  }

                  try {
                      ((X509KeyManager)managers[0]).getPrivateKey(null);
                  } catch (NullPointerException e) {
                      System.out.println("3. getPrivateKey throws NullPointerException.");
                  }

                  try {
                      ((X509KeyManager)managers[0]).getCertificateChain(null);
                  } catch (NullPointerException e) {
                      System.out.println("4. getCertificateChain throws NullPointerException.");
                  }
                  try {
                      ((X509KeyManager)managers[0]).chooseServerAlias(null, null, new Socket());
                  } catch (NullPointerException e) {
                      System.out.println("5. chooseServerAlias throws NullPointerException.");
                  }

                  try {
                      ((X509KeyManager)managers[0]).chooseClientAlias(null, null, new Socket());
                  } catch (NullPointerException e) {
                      System.out.println("6. chooseClientAlias throws NullPointerException.");
                  }
              } catch (NoSuchAlgorithmException nsae) {
                  nsae.printStackTrace();
                  System.out.println("Failed: Unexpected " + nsae);
                  return;
              } catch (Exception nspe) {
                  nspe.printStackTrace();
                  System.out.println("Failed: Unexpected " + nspe);
                  return;
              }
          }
      }

        Attachments

          Activity

            People

            • Assignee:
              xuelei Xue-Lei Fan
              Reporter:
              msokolni Maxim Sokolnikov (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: