aboutsummaryrefslogtreecommitdiff
path: root/src/trunnel
diff options
context:
space:
mode:
authorrl1987 <rl1987@sdf.lonestar.org>2018-05-13 14:06:43 +0200
committerrl1987 <rl1987@sdf.lonestar.org>2018-06-26 12:37:33 +0300
commitadbe6a25215b5f2c626a0801a49d596c0e478b5c (patch)
treec1aec5fb2d5f99886aa5bdf10738264efd907453 /src/trunnel
parentb556894ef2fc41947bcae998c8caa51e256f2a6e (diff)
downloadtor-adbe6a25215b5f2c626a0801a49d596c0e478b5c.tar.gz
tor-adbe6a25215b5f2c626a0801a49d596c0e478b5c.zip
Copy socks5.trunnel from trunnel examples dir
Diffstat (limited to 'src/trunnel')
-rw-r--r--src/trunnel/socks5.trunnel115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/trunnel/socks5.trunnel b/src/trunnel/socks5.trunnel
new file mode 100644
index 0000000000..ab53a4315f
--- /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];
+}
+