Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SSLSocketFactory.createSocket connects using http instead of https

 
Anders Nilsson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to make a handshake. I do it with the code below.

I'm running the code in an applet and it works fine when running directly against the server. The problem I have occurs when the same code runs via a proxy.
I'm looking in the java console with trace level 5 activated. Directly after the code line "SSLSocket socket = (SSLSocket) factory.createSocket("www.theserver.com", 443);" is executed
this line appears in the java console "network: Connecting http://www.theserver.com:443 with proxy=DIRECT". After this the applet stops working. I think it is because the
proxy will not allow http traffic on port 443.

Can anyone tell me why it is connecting using http and what I should do to make it connect using https?



import javax.net.ssl.HandshakeCompletedEvent;
import javax.net.ssl.HandshakeCompletedListener;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

public class Handshake
{

class MyHandshakeListener implements HandshakeCompletedListener
{

public void handshakeCompleted(HandshakeCompletedEvent e)
{
System.out.println("Handshake succesful!");
System.out.println("Using cipher suite: " + e.getCipherSuite());
}
}

public void DoHandshake()
{
try
{
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket) factory.createSocket("www.theserver.com", 443);
String[] suites = socket.getSupportedCipherSuites();
socket.setEnabledCipherSuites(suites);
socket.addHandshakeCompletedListener(new MyHandshakeListener());
socket.startHandshake();
}
catch (Exception e)
{
System.out.println(e);
}

}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic