[Telepathy-commits] [telepathy-gabble/master] Set the domain name when sending a SOCKS5 connect message
Marco Barisione
marco at barisione.org
Tue Jan 6 08:41:23 PST 2009
---
src/bytestream-socks5.c | 19 +++++++++++++++++--
tests/twisted/tubes/test-si-socks5-tubes.py | 15 +++++++++------
2 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/src/bytestream-socks5.c b/src/bytestream-socks5.c
index fadf675..680eddb 100644
--- a/src/bytestream-socks5.c
+++ b/src/bytestream-socks5.c
@@ -442,6 +442,10 @@ socks5_handle_received_data (GabbleBytestreamSocks5 *self,
{
GabbleBytestreamSocks5Private *priv = GABBLE_BYTESTREAM_SOCKS5_GET_PRIVATE (self);
gchar msg[47] = {'\0'};
+ const gchar *from;
+ const gchar *to;
+ gchar *unhashed_domain;
+ gchar *domain;
LmMessage *iq_result;
switch (priv->socks5_state)
@@ -454,17 +458,28 @@ socks5_handle_received_data (GabbleBytestreamSocks5 *self,
g_assert (string->str[0] == SOCKS5_VERSION &&
string->str[1] == SOCKS5_STATUS_OK);
+ from = lm_message_node_get_attribute (
+ priv->msg_for_acknowledge_connection->node, "from");
+ to = lm_message_node_get_attribute (
+ priv->msg_for_acknowledge_connection->node, "to"),
+ unhashed_domain = g_strconcat (priv->stream_id, from, to, NULL);
+ domain = sha1_hex (unhashed_domain, -1);
+
msg[0] = SOCKS5_VERSION;
msg[1] = SOCKS5_CMD_CONNECT;
msg[2] = SOCKS5_RESERVED;
msg[3] = SOCKS5_ATYP_DOMAIN;
- /* Lenght of a hex SHA1 */
+ /* Length of a hex SHA1 */
msg[4] = 40;
- /* FIXME: send the domainname */
+ /* Domain name: SHA-1(sid + initiator + target) */
+ memcpy (&msg[5], domain, 40);
/* Port: 0 */
msg[45] = 0x00;
msg[46] = 0x00;
+ g_free (domain);
+ g_free (unhashed_domain);
+
socks5_schedule_write (self, msg, 47);
priv->socks5_state = SOCKS5_STATE_CONNECT_REQUESTED;
diff --git a/tests/twisted/tubes/test-si-socks5-tubes.py b/tests/twisted/tubes/test-si-socks5-tubes.py
index 571f42f..66e5d1a 100644
--- a/tests/twisted/tubes/test-si-socks5-tubes.py
+++ b/tests/twisted/tubes/test-si-socks5-tubes.py
@@ -3,6 +3,7 @@
import base64
import errno
import os
+import sha
import dbus
from dbus.connection import Connection
@@ -299,12 +300,14 @@ def test(q, bus, conn, stream):
transport = event.properties['transport']
transport.write('\x05\x00') # version 5, no auth
event = q.expect('s5b-data-received')
- # ver + cmd + rsv + atyp + len + SHA1 (40) + dst.port (2) = 47
- assert len(event.properties['data']) == 47
- # version 5, connect, reserved, domain type, len(SHA-1)
- assert event.properties['data'].startswith('\x05\x01\x00\x03' + chr(40))
- # port
- assert event.properties['data'].endswith('\x00\x00')
+ # version 5, connect, reserved, domain type
+ expected_connect = '\x05\x01\x00\x03'
+ expected_connect += chr(40) # len (SHA-1)
+ # sha-1(sid + initiator + target)
+ unhashed_domain = query['sid'] + iq['from'] + iq['to']
+ expected_connect += sha.new(unhashed_domain).hexdigest()
+ expected_connect += '\x00\x00' # port
+ assert event.properties['data'] == expected_connect
transport.write('\x05\x00') #version 5, ok
--
1.5.6.5
More information about the Telepathy-commits
mailing list