aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes SSLSocketFactory.createSocket connects using http instead of https Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "SSLSocketFactory.createSocket connects using http instead of https" Watch "SSLSocketFactory.createSocket connects using http instead of https" New topic
Author

SSLSocketFactory.createSocket connects using http instead of https

Anders Nilsson
Greenhorn

Joined: Mar 22, 2013
Posts: 1
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);
}

}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SSLSocketFactory.createSocket connects using http instead of https