Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Getting an InputStream from an SSLSocket

843811Jul 17 2003 — edited Jul 29 2004
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 26 2004
Added on Jul 17 2003
14 comments
586 views