SOCK5 Mediated connections wiht XEP-0065
From: "Andrew VanUitert" <avanuitert@xxxxxxxxxxxx>
Date: Mon, 9 Aug 2010 21:14:52 +0200 (CEST)
In XEP-0065 there are a number of steps described that describes how to
connect two entities through a proxy for a mediated SOCKS5 connection.
Any idea if gloox 1.0 supports this sequence?  I have been attempting to
establish a mediated SOCKS5 connection using gloox for the purposes of
tunneling socket connections for a proprietary RPC over a NAT firewall.
So far I have been able to get the connection established at the target,
however I have not been able to get a full end to end SOCKS connection
established.

 

For clarification, I have the following entities in my XMPP setup.

Initiator: avan-xp@xxxxxxxxxxxxxx with iP: 192.168.0.100 

Target: controller@xxxxxxxxxxxxxx with IP: 192.168.0.200

XMPP Server / Proxy: manny.xxxx.com with IP 192.168.0.101

Additionally, I have a class that implements several interfaces Called
XmppDispatcher. This derives from LogHandler, PresenseHandler,
ByteStreamHandler, and ByteStreamDataHandler.

 

 

For the target, I accept the socks5 connection in
"handleIncomingBytestreamRequest" via the Socks5Manager with the
following results.

08/09/2010 10:59:00 INFO:
c4::xmpp::XmppDispatcher::handleIncomingBytestreamRequest sid:
uid:4c6033b1:238e1f29 from:
controller@xxxxxxxxxxxxxx/110736323212813731063963

08/09/2010 10:59:00 INFO:
c4::xmpp::XmppDispatcher::handleIncomingBytestream target:
avan-xp@xxxxxxxxxxxxxx/18889880401281373124332756 initiator:
controller@xxxxxxxxxxxxxx/110736323212813731063963

08/09/2010 11:01:24 DEBUG: Connecting to manny.xxxx.com
(192.168.0.101:7777)

08/09/2010 11:01:24 DEBUG: Connected to manny.xxxx.com
(192.168.0.101:7777)

08/09/2010 11:01:24 DEBUG: Attempting to negotiate socks5 proxy
connection

08/09/2010 11:01:24 INFO: ok! s5b connected to streamhost

08/09/2010 11:01:57 DEBUG: Requesting socks5 proxy connection to
31a77abf1a8a67af86decdb2006402c75dfb36f0:0

 

At this point, the socks5 connection for the target to the proxy seems
to have been established, however a call to ByteStream::isOpen() return
false. (Which I suppose should be that case since the initiator has not
opened its half of the connection)  

 

If I run netstat  we see that the output

$ netstat.exe |grep 7777

  TCP    avan-xp:1349     manny.xxxx.com:7777  ESTABLISHED

 

From what I understand about the connection sequence as described in
XEP-0065 the target should now send a S5b acceptance message to the
initiator so that the initiator can establish a SOCKS5 connection as
well. This is where things seem to go wrong.

 

I have tried 2 different approaches to see if I can get the initiator to
establish its half of the socks5 connection.

 

1) Let the Socks5Manager mange the whole negotiation, 2) Send a request
form the target to the initiator.

 

For approach 1, I have not had any success. For approach 2, I have tried
sending a request to the initiator in the "handleIncomingBytestream"
handler:

-------------------- Code snippet ---------------------

socks_5_manager_->addStreamHost(bs->initiator().server(),
"manny.xxxx.com", 7777);

socks_5_manager_->requestSOCKS5Bytestream(bs->initiator(),
SOCKS5BytestreamManager::S5BTCP, bs->sid());

 

And then the initiator receives a  "handleIncomingBytestreamRequest"
callback where is accepts the connection, and it looks like both the
initiator and the target have a socks5 connection, but again the
bytestreams are not open.

 

So this leads to a couple questions.

1)       Should I be sending the request from the target to the
initiator after the bytestream is connected ? Although the SOCKS
connections get established with the same session id, the xml messages
don't seem to follow the steps outline in XEP-00065.

 

2)       If I don't have to send the request from the target to the
initiator, will the SOCKS5Manger handle it automatically ?

 

3)       Should I be using another mechanism for setting up a tunnel ?

 

As you can tell, I have been struggling to get this to work, so any help
would be greatly appreciated.

Thanks,

Andy