forked from shadowsocks/shadowsocks-libev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprotocol
66 lines (57 loc) · 2.7 KB
/
protocol
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
SSS - Scrambled Shadowsocks
Stream Format
client --> Server
--------------------------------------------------------------------------
| Pad-1 | session header(encrypted) | Pad-tail | TLV-1 | TLV-2 ...
--------------------------------------------------------------------------
Server --> Client
--------------------------------------------------------------------------
| Pad-2 | Shadowsocks data ...
--------------------------------------------------------------------------
Pad-1
This is a piece of random data added at the beginning of each TCP
connection. The length of this piece is defined as scramble-x.
scramble-x
A shared constant between a server and its clients. Different servers can
choose different value.
Session header
Session header is encrypted by the RSA public key of the server. It is
defined as below:
typedef struct __attribute__((__packed__)) session_head {
uint64_t client_id; /*
* Not used at this moment, same as
* device_id.
*/
uint64_t device_id; /*
* This is to differentiate the multiple
* devices used by one client.
*/
uint64_t epoch; /*
* EPOCH time at this device.
* A server is always expecting a new
* connection from the same source with
* a greater epoch value.
*/
uint8_t data_type; /*
* Data-type value used in the following
* TLVs in this connection.
*/
uint8_t pad_type; /*
* Pad-type value used in the following
* TLVs in this connection.
*/
uint8_t pad2_len; /* Length of Pad-2. */
uint8_t pad_tail_len; /* Length of Pad-tail. */
uint32_t reserve; /* Not used. */
} session_head_t;
TLVs (Type-Length-Value)
There are two types: data and pad. The type values are specified in
session-header. These values are different in different connections.
A client can choose to send out TLVs in random order with random length
of data or pad.
The data here refers to the original shadowsocks data.
A typical config in scrambled shadowsocks includes:
- scramble-X
- client-id (only at client side, not used at this moment)
- server public key or private key
- shadowsocks config