1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 17:49:38 +02:00

Rework support for Proxy connections

in order to improve support for Tor connections.

This makes it possible to establish a connection to an .onion domain by
manually setting host and port in the ConnectionConfiguration and
configuring a Socks5Proxy pointing to a Tor node.

Fixes SMACK-720.
This commit is contained in:
Florian Schmaus 2016-05-03 09:59:20 +02:00
parent 3251fe89e2
commit 4c63cfafd7
5 changed files with 51 additions and 44 deletions

View file

@ -21,7 +21,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
@ -45,12 +44,12 @@ class HTTPProxySocketConnection implements ProxySocketConnection {
}
@Override
public void connect(Socket socket, InetAddress inetAddress, int port, int timeout)
public void connect(Socket socket, String host, int port, int timeout)
throws IOException {
String proxyhost = proxy.getProxyAddress();
int proxyPort = proxy.getProxyPort();
socket.connect(new InetSocketAddress(proxyhost, proxyPort));
String hostport = "CONNECT " + inetAddress.getCanonicalHostName() + ":" + port;
String hostport = "CONNECT " + host + ":" + port;
String proxyLine;
String username = proxy.getProxyUsername();
if (username == null)

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2015 Florian Schmaus.
* Copyright 2015-2016 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,12 +17,11 @@
package org.jivesoftware.smack.proxy;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
public interface ProxySocketConnection {
public void connect(Socket socket, InetAddress inetAddress, int port, int timeout)
public void connect(Socket socket, String host, int port, int timeout)
throws IOException;
}

View file

@ -37,7 +37,7 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
}
@Override
public void connect(Socket socket, InetAddress inetAddress, int port, int timeout)
public void connect(Socket socket, String host, int port, int timeout)
throws IOException {
InputStream in = null;
OutputStream out = null;
@ -80,6 +80,7 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
buf[index++]=(byte)(port>>>8);
buf[index++]=(byte)(port&0xff);
InetAddress inetAddress = InetAddress.getByName(proxy_host);
byte[] byteAddress = inetAddress.getAddress();
for (int i = 0; i < byteAddress.length; i++)
{

View file

@ -19,7 +19,6 @@ package org.jivesoftware.smack.proxy;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
@ -37,7 +36,7 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
}
@Override
public void connect(Socket socket, InetAddress inetAddress, int port, int timeout)
public void connect(Socket socket, String host, int port, int timeout)
throws IOException {
InputStream in = null;
OutputStream out = null;
@ -211,7 +210,7 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
buf[index++]=1; // CONNECT
buf[index++]=0;
byte[] hostb= inetAddress.getCanonicalHostName().getBytes();
byte[] hostb= host.getBytes();
int len=hostb.length;
buf[index++]=3; // DOMAINNAME
buf[index++]=(byte)(len);