aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-11 21:13:09 +0200
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-11 21:13:09 +0200
commitc0e0a7086902a9d5cfbe88c4aa220abdf2ee3dde (patch)
tree0dc00906f723d0e2ad2894a711992af03ea12f21 /src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java
parent51100ab48b94c55f8cce981c422e50a607f261ad (diff)
socks5 initialisation works. doesn't get activate though
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java')
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java b/src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java
new file mode 100644
index 00000000..5c36d66f
--- /dev/null
+++ b/src/eu/siacs/conversations/xmpp/jingle/SocksConnection.java
@@ -0,0 +1,70 @@
+package eu.siacs.conversations.xmpp.jingle;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+
+import eu.siacs.conversations.utils.CryptoHelper;
+
+import android.util.Log;
+
+public class SocksConnection {
+
+ private JingleConnection jingleConnection;
+ private Socket socket;
+ private String host;
+ private int port;
+ private String destination;
+
+ public SocksConnection(JingleConnection jingleConnection, String host, int port) {
+ this.jingleConnection = jingleConnection;
+ this.host = host;
+ this.port = port;
+ try {
+ MessageDigest mDigest = MessageDigest.getInstance("SHA-1");
+ StringBuilder destBuilder = new StringBuilder();
+ destBuilder.append(jingleConnection.getSessionId());
+ destBuilder.append(jingleConnection.getInitiator());
+ destBuilder.append(jingleConnection.getResponder());
+ mDigest.reset();
+ Log.d("xmppService","plain destination: "+destBuilder.toString());
+ this.destination = CryptoHelper.bytesToHex(mDigest.digest(destBuilder.toString().getBytes()));
+ Log.d("xmppService","host="+host+", port="+port+", destination: "+destination);
+ } catch (NoSuchAlgorithmException e) {
+
+ }
+ }
+
+ public boolean connect() {
+ try {
+ this.socket = new Socket(this.host, this.port);
+ InputStream is = socket.getInputStream();
+ OutputStream os = socket.getOutputStream();
+ byte[] login = {0x05, 0x01, 0x00};
+ byte[] expectedReply = {0x05,0x00};
+ byte[] reply = new byte[2];
+ os.write(login);
+ is.read(reply);
+ if (Arrays.equals(reply, expectedReply)) {
+ String connect = ""+'\u0005'+'\u0001'+'\u0000'+'\u0003'+'\u0028'+this.destination+'\u0000'+'\u0000';
+ os.write(connect.getBytes());
+ byte[] result = new byte[2];
+ is.read(result);
+ int status = result[0];
+ return (status==0);
+ } else {
+ socket.close();
+ return false;
+ }
+ } catch (UnknownHostException e) {
+ return false;
+ } catch (IOException e) {
+ return false;
+ }
+ }
+}