[tor-commits] [tor/master] Copy socks5.trunnel from trunnel examples dir

nickm at torproject.org nickm at torproject.org
Sun Jul 15 21:07:27 UTC 2018


commit adbe6a25215b5f2c626a0801a49d596c0e478b5c
Author: rl1987 <rl1987 at sdf.lonestar.org>
Date:   Sun May 13 14:06:43 2018 +0200

    Copy socks5.trunnel from trunnel examples dir
---
 src/trunnel/socks5.trunnel | 115 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 115 insertions(+)

diff --git a/src/trunnel/socks5.trunnel b/src/trunnel/socks5.trunnel
new file mode 100644
index 000000000..ab53a4315
--- /dev/null
+++ b/src/trunnel/socks5.trunnel
@@ -0,0 +1,115 @@
+// Example: here's a quickie implementation of the messages in the
+// socks5 protocol.
+
+struct socks5_client_version {
+   u8 version IN [5];
+   u8 n_methods;
+   u8 methods[n_methods];
+}
+
+struct socks5_server_method {
+   u8 version IN [5];
+   u8 method;
+}
+
+const CMD_CONNECT = 1;
+const CMD_BIND = 2;
+const CMD_UDP_ASSOCIATE = 3;
+// This is a tor extension
+const CMD_RESOLVE_PTR = 0xF1;
+
+const ATYPE_IPV4 = 1;
+const ATYPE_IPV6 = 4;
+const ATYPE_DOMAINNAME = 3;
+
+struct domainname {
+   u8 len;
+   char name[len];
+}
+
+struct socks5_client_request {
+   u8 version IN [5];
+   u8 command IN [CMD_CONNECT, CMD_BIND, CMD_UDP_ASSOCIATE, CMD_RESOLVE_PTR];
+   u8 reserved IN [0];
+   u8 atype;
+   union dest_addr[atype] {
+     ATYPE_IPV4: u32 ipv4;
+     ATYPE_IPV6: u8 ipv6[16];
+     ATYPE_DOMAINNAME: struct domainname domainname;
+     default: fail;
+   };
+   u16 dest_port;
+}
+
+struct socks5_server_reply {
+   u8 version IN [5];
+   u8 reply;
+   u8 reserved IN [0];
+   u8 atype;
+   union bind_addr[atype] {
+     ATYPE_IPV4: u32 ipv4;
+     ATYPE_IPV6: u8 ipv6[16];
+     ATYPE_DOMAINNAME: struct domainname domainname;
+     default: fail;
+   };
+   u16 bind_port;
+}
+
+struct socks5_client_userpass_auth {
+   u8 version IN [1];
+   u8 username_len;
+   char username[username_len];
+   u8 passwd_len;
+   char passwd[passwd_len];
+}
+
+struct socks5_server_userpath_auth {
+   u8 version IN [1];
+   u8 status;
+}
+
+// Oh why not.  Here's socks4 and socks4a.
+
+struct socks4_client_request {
+   u8 version IN [4];
+   u8 command IN [CMD_CONNECT,CMD_BIND,CMD_RESOLVE_PTR];
+   u16 port;
+   u32 addr;
+   nulterm username;
+   union socks4a_addr[addr] {
+      1..255:
+               nulterm hostname;
+      default:
+               ;
+   };
+}
+
+struct socks4_server_reply {
+   u8 version IN [4];
+   u8 status;
+   u16 port;
+   u32 addr;
+}
+
+// And here's the extended stuff from proposal 229
+
+struct tor_socksauth_keyval {
+  u16 keylen;
+  char key[keylen];
+  u16 vallen;
+  char val[vallen];
+}
+
+struct tor_extended_socks_auth_request {
+  u8 version IN [1];
+  u16 npairs;
+  struct tor_socksauth_keyval pairs[npairs];
+}
+
+struct tor_extended_socks_auth_response {
+  u8 version IN [1];
+  u8 status;
+  u16 npairs;
+  struct tor_socksauth_keyval pairs[npairs];
+}
+





More information about the tor-commits mailing list