aboutsummaryrefslogtreecommitdiff
path: root/src/trunnel/socks5.trunnel
blob: b86ec03b9d018163e073a5ecad1656ecbd8136d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// 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 = 0xF0;
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, 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_userpass_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,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;
}