javax.net.ssl.SSLException: Unrecognized SSL message
843811Jan 17 2003 — edited Jun 24 2008Hello:
When I try to use the javax.net.ssl classes to open a URL to my
development server at https://dsl.JAMMConsulting.com, I get this error:
Exception in thread "main" javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.net.ssl.internal.ssl.InputRecord.b(DashoA6275)
at com.sun.net.ssl.internal.ssl.InputRecord.read(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(DashoA6275)
at sun.net.www.protocol.https.HttpsClient.afterConnect(DashoA6275)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(DashoA6275)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(DashoA6275)
at HttpsTest.main(HttpsTest.java:20)
But, when I try to open a connection to https://www.redhat.com,
everything works fine.
I have implemented my own TrustManager so that I can
avoid problems with the self-generated certificate for
the development server. But, I dont think it is working.
Here is my code for HttpsTest:
import java.io.*;
import java.net.*;
import java.security.*;
import javax.net.ssl.*;
class HttpsTest {
public static void main(String[] args) throws Exception {
X509TrustManager tm = new MyTrustManager();
KeyManager []km = null;
TrustManager []tma = {tm};
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(km,tma,new java.security.SecureRandom());
SSLSocketFactory sf1 = sc.getSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(sf1);
URL url = new URL("https://dsl.JAMMConsulting.com/");
//URL url = new URL("https://www.redhat.com");
URLConnection urlc = url.openConnection();
urlc.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
String line = reader.readLine();
while( line != null ) {
System.out.println(line);
line = reader.readLine();
}
reader.close();
}
}
Here is my code for MyTrustManager:
import java.security.cert.*;
import javax.net.ssl.*;
public class MyTrustManager implements X509TrustManager {
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
Any ideas?
Thanks,
Neil
neil@JAMMConsulting.com