-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
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;
}
}
}
"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;
}
}
}