-
Bug
-
Resolution: Duplicate
-
P4
-
5.0
-
generic
-
generic
Name: aiR10266 Date: 06/24/2004
The description of methods
getServerSocketFactory()
getSocketFactory()
of the SSLContext class doesn't state that methods throws any exceptions and
the description of methods
createSSLEngine()
createSSLEngine(String host, int port)
of the same class states that only UnsupportedOperationException may be
thrown if the underlying provider does not implement the operation. But the
implementation of SSLContext throws NullPointerException if methods
engineCreateSSLEngine()
engineCreateSSLEngine(String host, int port)
engineGetServerSocketFactory()
engineGetSocketFactory()
of SSLContextSpi(using which SSLContext was created) returns null, which is
not forbidden by the description of SSLContextSpi methods.
Example:
import java.security.KeyManagementException;
import java.security.Provider;
import java.security.SecureRandom;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLContextSpi;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSessionContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
public class Test {
public static void main(String argv[]) {
Test test = new Test();
test.run();
}
public void run() {
SSLContextSpi contextSpi = new MySSLContextSpi();
Provider provider = new MyProvider("name", 0.0, "info");
String protocol = "protocol";
SSLContext cnt = new MySSLContext(contextSpi, provider, protocol);
try {
cnt.init(null, null, null);
} catch (KeyManagementException e) {
System.out.println("KeyManagementException has been caught.");
}
try {
System.out.println("\nGetting SocketFactory...");
cnt.getSocketFactory();
} catch (Throwable t) {
System.out.println("Unexpected exception:");
t.printStackTrace(System.out);
}
try {
System.out.println("\nGetting ServerSocketFactory...");
cnt.getServerSocketFactory();
} catch (Throwable t) {
System.out.println("Unexpected exception:");
t.printStackTrace(System.out);
}
try {
System.out.println("\nCreating SSLEngine...");
cnt.createSSLEngine();
} catch (Throwable t) {
System.out.println("Unexpected exception:");
t.printStackTrace(System.out);
}
try {
System.out.println("\nCreating SSLEngine using " +
"advisory peer information...");
cnt.createSSLEngine("localhost", 8080);
} catch (Throwable t) {
System.out.println("Unexpected exception:");
t.printStackTrace(System.out);
}
}
}
class MyProvider extends Provider {
public MyProvider(String name, double version, String info) {
super(name, version, info);
}
}
class MySSLContextSpi extends SSLContextSpi {
public SSLSessionContext engineGetClientSessionContext() {
return null;
}
public SSLSessionContext engineGetServerSessionContext() {
return null;
}
public SSLServerSocketFactory engineGetServerSocketFactory() {
return null;
}
public SSLSocketFactory engineGetSocketFactory() {
return null;
}
public void engineInit(KeyManager[] km,
TrustManager[] tm,
SecureRandom sr)
throws KeyManagementException {
}
public SSLEngine engineCreateSSLEngine() {
return null;
}
public SSLEngine engineCreateSSLEngine(String host, int port) {
return null;
}
}
class MySSLContext extends SSLContext {
public MySSLContext(SSLContextSpi contextSpi,
Provider provider,
String protocol) {
super(contextSpi, provider, protocol);
}
}
======================================================================
The description of methods
getServerSocketFactory()
getSocketFactory()
of the SSLContext class doesn't state that methods throws any exceptions and
the description of methods
createSSLEngine()
createSSLEngine(String host, int port)
of the same class states that only UnsupportedOperationException may be
thrown if the underlying provider does not implement the operation. But the
implementation of SSLContext throws NullPointerException if methods
engineCreateSSLEngine()
engineCreateSSLEngine(String host, int port)
engineGetServerSocketFactory()
engineGetSocketFactory()
of SSLContextSpi(using which SSLContext was created) returns null, which is
not forbidden by the description of SSLContextSpi methods.
Example:
import java.security.KeyManagementException;
import java.security.Provider;
import java.security.SecureRandom;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLContextSpi;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSessionContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
public class Test {
public static void main(String argv[]) {
Test test = new Test();
test.run();
}
public void run() {
SSLContextSpi contextSpi = new MySSLContextSpi();
Provider provider = new MyProvider("name", 0.0, "info");
String protocol = "protocol";
SSLContext cnt = new MySSLContext(contextSpi, provider, protocol);
try {
cnt.init(null, null, null);
} catch (KeyManagementException e) {
System.out.println("KeyManagementException has been caught.");
}
try {
System.out.println("\nGetting SocketFactory...");
cnt.getSocketFactory();
} catch (Throwable t) {
System.out.println("Unexpected exception:");
t.printStackTrace(System.out);
}
try {
System.out.println("\nGetting ServerSocketFactory...");
cnt.getServerSocketFactory();
} catch (Throwable t) {
System.out.println("Unexpected exception:");
t.printStackTrace(System.out);
}
try {
System.out.println("\nCreating SSLEngine...");
cnt.createSSLEngine();
} catch (Throwable t) {
System.out.println("Unexpected exception:");
t.printStackTrace(System.out);
}
try {
System.out.println("\nCreating SSLEngine using " +
"advisory peer information...");
cnt.createSSLEngine("localhost", 8080);
} catch (Throwable t) {
System.out.println("Unexpected exception:");
t.printStackTrace(System.out);
}
}
}
class MyProvider extends Provider {
public MyProvider(String name, double version, String info) {
super(name, version, info);
}
}
class MySSLContextSpi extends SSLContextSpi {
public SSLSessionContext engineGetClientSessionContext() {
return null;
}
public SSLSessionContext engineGetServerSessionContext() {
return null;
}
public SSLServerSocketFactory engineGetServerSocketFactory() {
return null;
}
public SSLSocketFactory engineGetSocketFactory() {
return null;
}
public void engineInit(KeyManager[] km,
TrustManager[] tm,
SecureRandom sr)
throws KeyManagementException {
}
public SSLEngine engineCreateSSLEngine() {
return null;
}
public SSLEngine engineCreateSSLEngine(String host, int port) {
return null;
}
}
class MySSLContext extends SSLContext {
public MySSLContext(SSLContextSpi contextSpi,
Provider provider,
String protocol) {
super(contextSpi, provider, protocol);
}
}
======================================================================