Hi. I'm trying to connect to a server using SSL. I can create a socket to the server and complete a handshake fine, but when I try to use the InputStream I get from the socket I get a Timeout error. I overrode the TrustManager to just trust everything, so I know that I've accepted the server's certificate, and because I can complete the handshake it seems to me like it's not an authorization problem. Here's my code:
URL url = new URL(location);
SSLContext sslContext = SSLContext.getInstance("SSL");
TrustManager[] tm = new TrustManager[1];
tm[0] = new LameTrustManager();
sslContext.init(null, tm, null);
SSLSocketFactory factory = sslContext.getSocketFactory();
SSLSocket socket = (SSLSocket) factory.createSocket(url.getHost(), url.getPort());
socket.addHandshakeCompletedListener(new HandshakeCompletedListener() {
public void handshakeCompleted(HandshakeCompletedEvent event) {
System.out.println("Handshake Completed");
}
});
socket.startHandshake();
is = socket.getInputStream();
I get the "Handshake Completed" output, and then it hangs until I get the "Error - Timeout" problem.
Alternatively, if I open an HttpsURLConnection, give it the SSLSocketFactory I created and a lame HostnameVerifier which verifies everything, and then open an input stream from that, I get an http 403 error, "Forbidden request." If I got to the URL with Mozilla, I have no problems (except that it warns me that the certificate from the server is not from a CA it recognizes).
Many thanks for any help you could give me!
Nathan