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

X509KeyManager implementation for NewSunX509 algorithm returns empty arrays instead of null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 5.0
    • security-libs
    • None
    • beta
    • generic
    • generic

      The X509KeyManager.getServerAliases and getClientAliases implementation reads:
       "Returns:
          the alias name for the desired key, or null if there are no matches."

      But these methods for the implementation of NewSunX509 return empty array if there are
      no matches.

      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.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();
                  String[] list = ((X509KeyManager)managers[0]).getServerAliases("shold not be supported", null);
                  if ((list != null) && (list.length == 0)) {
                      System.out.println("getServerAliases returns an empty array instead of null.");
                  }
                  list = ((X509KeyManager)managers[0]).getClientAliases("shold not be supported", null);
                  if ((list != null) && (list.length == 0)) {
                      System.out.println("getClientAliases returns an empty array instead of null.");
                  }
              } catch (NoSuchAlgorithmException nsae) {
                  nsae.printStackTrace();
                  System.out.println("Failed: Unexpected " + nsae);
                  return;
              } catch (Exception nspe) {
                  nspe.printStackTrace();
                  System.out.println("Failed: Unexpected " + nspe);
                  return;
              }
          }
      }

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: