powered by Jive Software

Https proxy

Is it possible using the latest smack api to connect through a https proxy? My aim is to connect to google talk through a firewall. It looks like there is support for http, socks4 and socks5 but not https. I was hoping I could do some thing like the following:

ProxyInfo proxy = ProxyInfo.forHttpsProxy(pHost, pPort, pUser, pPass);
ConnectionConfiguration cc = new ConnectionConfiguration(host, port, serviceName, proxy);

I believe I could create an extension of ProxyInfo that returns the SSLSocketFactory defined here : http://www.igniterealtime.org/community/message/131581#131581 but I was hoping there would be an official method of doing this.

Thanks,

Stuart

The following 2 classes seem to do what I want:

public class HTTPSProxySocketFactory extends SSLSocketFactory {

private SSLSocketFactory dfactory;
private SocketFactory httpProxySocketFactory;

public HTTPSProxySocketFactory(ProxyInfo proxy) {
httpProxySocketFactory = ProxyInfo.forHttpProxy(proxy.getProxyAddress(),
proxy.getProxyPort(), proxy.getProxyUsername(),
proxy.getProxyPassword()).getSocketFactory();
dfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
}

@Override
public Socket createSocket(
String host, int port)
throws IOException, UnknownHostException {
return createSocket(null, host, port, true);
}

@Override
public Socket createSocket(
String host, int port, InetAddress localHost, int localPort)
throws IOException, UnknownHostException {
return createSocket(null, host, port, true);
}

@Override
public Socket createSocket(
InetAddress host, int port)
throws IOException {
return createSocket(null, host.getHostName(), port, true);
}

@Override
public Socket createSocket(
InetAddress address, int port, InetAddress localAddress, int localPort)
throws IOException {
return createSocket(null, address.getHostName(), port, true);
}

@Override
public Socket createSocket(
        Socket s, String host, int port, boolean autoClose)
        throws IOException, UnknownHostException {
    // First of all create a connection to the proxy.
    Socket tunnel = httpProxySocketFactory.createSocket(host, port);
    return dfactory.createSocket(tunnel, host, port, autoClose);
}

@Override
public String[] getDefaultCipherSuites() {
return dfactory.getDefaultCipherSuites();
}

@Override
public String[] getSupportedCipherSuites() {
return dfactory.getSupportedCipherSuites();
}
}

public class HTTPSProxyInfo extends ProxyInfo {

public HTTPSProxyInfo(String pHost, int pPort, String pUser, String pPass) {
super(null, pHost, pPort, pUser, pPass);
}

@Override
public SocketFactory getSocketFactory() {
    return new HTTPSProxySocketFactory(this);
}

}

The code now becomes :

ProxyInfo proxy = new HTTPSProxyInfo(pHost, pPort, pUser, pPass);

String host = “talk.google.com”;
int port = 443;
String serviceName = “googlemail.com”;

ConnectionConfiguration cc = new ConnectionConfiguration(host, port, serviceName, proxy);

XMPPConnection connection = new XMPPConnection(cc);
connection.connect();

Is there a better way to do this using the smack libraries?