So here is what I did with the Smack 3.2 libs, wanted to put this up so that folks can critque and it hopefully helps someone out.
HttpProxyTest.java
package com.httpTunnel.text;
import java.net.SocketException;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.proxy.ProxyInfo;
public class HttpTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
ConnectionConfiguration config = getConfiguration();
config.setReconnectionAllowed(false);
XMPPConnection conn = TrytoConnect(config);
conn.login(“channa”, “1234567”);
} catch (SocketException | XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static XMPPConnection TrytoConnect(ConnectionConfiguration config){
XMPPConnection connection = new XMPPConnection(config);
try {
connection.connect();
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return connection;
}
private static ConnectionConfiguration getConfiguration() throws SocketException {
final ConnectionConfiguration config;
config = new ConnectionConfiguration(“jabclust.dev.xxxxx.local”, 443);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
config.setCompressionEnabled(true);
config.setSocketFactory(new SSLTunnelSocketFactory(“xx.xx.xx.xx”,3128));
config.setSASLAuthenticationEnabled(true);
return config;
}
}
SSLTunnelSocketFactory.java
package com.httpTunnel.text;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.net.ssl.HandshakeCompletedEvent;
import javax.net.ssl.HandshakeCompletedListener;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class SSLTunnelSocketFactory extends SSLSocketFactory
{
private SSLSocketFactory dfactory;
private String tunnelHost;
private int tunnelPort;
public SSLTunnelSocketFactory(String proxyhost, int proxyport){
tunnelHost = proxyhost;
tunnelPort = proxyport;
}
public Socket createSocket(String host, int port)
throws IOException, UnknownHostException
{
return createSocket(null,host,port,true);
}
public Socket createSocket(String host,int port,InetAddress clientHost,
int clientPort)
throws IOException,UnknownHostException
{
return createSocket(null,host,port,true);
}
public Socket createSocket(InetAddress host,int port)
throws IOException
{
return createSocket(null,host.getHostName(),port,true);
}
public Socket createSocket(InetAddress address,int port,
InetAddress clientAddress,int clientPort)
throws IOException
{
return createSocket(null,address.getHostName(),port,true);
}
public Socket createSocket(Socket s, String host, int port,
boolean autoClose)
throws IOException,UnknownHostException
{
Socket tunnel = new Socket(tunnelHost,tunnelPort);
doTunnelHandshake(tunnel,host,port);
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance(“SSL”);
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
} catch (Exception e) {
}
dfactory = sslContext.getSocketFactory();
SSLSocket result = (SSLSocket)dfactory.createSocket(
tunnel,host,port,autoClose);
result.addHandshakeCompletedListener(
new HandshakeCompletedListener() {
public void handshakeCompleted(HandshakeCompletedEvent event) {
System.out.println(“Handshake finished!”);
System.out.println(
“\t CipherSuite:” + event.getCipherSuite());
System.out.println(
"\t SessionId " + event.getSession());
System.out.println(
"\t PeerHost " + event.getSession().getPeerHost());
}
}
);
result.startHandshake();
return result;
}
private void doTunnelHandshake(Socket tunnel, String host, int port)
throws IOException
{
OutputStream out = tunnel.getOutputStream();
String msg = “CONNECT " + host + “:” + port + " HTTP/1.0\n”
-
"User-Agent: "
-
“DesktopAlertingTest”
-
“\r\n\r\n”;
byte b[];
try {
b = msg.getBytes(“ASCII7”);
} catch (UnsupportedEncodingException ignored) {
b = msg.getBytes();
}
out.write(b);
out.flush();
byte reply[] = new byte[200];
int replyLen = 0;
int newlinesSeen = 0;
boolean headerDone = false; /* Done on first newline */
InputStream in = tunnel.getInputStream();
while (newlinesSeen < 2) {
int i = in.read();
if (i < 0) {
throw new IOException(“Unexpected EOF from proxy”);
}
if (i == ‘\n’) {
headerDone = true;
++newlinesSeen;
} else if (i != ‘\r’) {
newlinesSeen = 0;
if (!headerDone && replyLen < reply.length) {
reply[replyLen++] = (byte) i;
}
}
}
String replyStr;
try {
replyStr = new String(reply, 0, replyLen, “ASCII7”);
} catch (UnsupportedEncodingException ignored) {
replyStr = new String(reply, 0, replyLen);
}
if(replyStr.toLowerCase().indexOf(“200 connection established”) == -1){
throw new IOException("Unable to tunnel through "
}
}
public String[] getDefaultCipherSuites(){
return dfactory.getDefaultCipherSuites();
}
public String[] getSupportedCipherSuites(){
return dfactory.getSupportedCipherSuites();
}
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
}
};
}
I’m going to try an actual tunneling lib to replace the “doHandshake” method. Thanks again LG you are a wizard.