]>
Commit | Line | Data |
---|---|---|
71ba9a7a | 1 | ## WebSockets Utilities: wswrapper and wsproxy |
e5d60a8b JM |
2 | |
3 | ||
71ba9a7a JM |
4 | ### wswrapper |
5 | ||
6 | wswrapper is an LD_PRELOAD library that converts a TCP listen socket | |
7 | of an existing program to a be a WebSockets socket. The `wswrap` | |
8 | script can be used to easily launch a program using wswrapper. Here is | |
9 | an example of using wswrapper with vncserver. wswrapper will convert | |
10 | the socket listening on port 5901 to be a WebSockets port: | |
11 | ||
12 | `cd noVNC/utils` | |
13 | ||
14 | `./wswrap 5901 vncserver -geometry 640x480 :1` | |
15 | ||
16 | ||
17 | ### wsproxy | |
e5d60a8b JM |
18 | |
19 | At the most basic level, wsproxy just translates WebSockets traffic | |
20 | to normal socket traffic. wsproxy accepts the WebSockets handshake, | |
21 | parses it, and then begins forwarding traffic between the client and | |
22 | the target in both directions. WebSockets payload data is UTF-8 | |
23 | encoded so in order to transport binary data it must use an encoding | |
24 | that can be encapsulated within UTF-8. wsproxy uses base64 to encode | |
25 | all traffic to and from the client. Also, WebSockets traffic starts | |
26 | with '\0' (0) and ends with '\xff' (255). Some buffering is done in | |
27 | case the data from the client is not a full WebSockets frame (i.e. | |
28 | does not end in 255). | |
29 | ||
30 | ||
71ba9a7a | 31 | #### Additional wsproxy features |
e5d60a8b JM |
32 | |
33 | These are not necessary for the basic operation. | |
34 | ||
35 | * Daemonizing: When the `-f` option is not specified, wsproxy runs | |
36 | in the background as a daemon process. | |
37 | ||
38 | * SSL (the wss:// WebSockets URI): This is detected automatically by | |
39 | wsproxy by sniffing the first byte sent from the client and then | |
40 | wrapping the socket if the data starts with '\x16' or '\x80' | |
41 | (indicating SSL). | |
42 | ||
43 | * Flash security policy: wsproxy detects flash security policy | |
44 | requests (again by sniffing the first packet) and answers with an | |
45 | appropriate flash security policy response (and then closes the | |
46 | port). This means no separate flash security policy server is needed | |
47 | for supporting the flash WebSockets fallback emulator. | |
48 | ||
49 | * Session recording: This feature that allows recording of the traffic | |
50 | sent and received from the client to a file using the `--record` | |
51 | option. | |
52 | ||
53 | ||
71ba9a7a | 54 | #### Implementations of wsproxy |
e5d60a8b | 55 | |
2574936f JM |
56 | There are three implementations of wsproxy: python, C, and Node |
57 | (node.js). wswrapper is only implemented in C. | |
e5d60a8b | 58 | |
2574936f JM |
59 | Here is the feature support matrix for the the wsproxy implementations |
60 | and wswrapper: | |
e5d60a8b | 61 | |
e5d60a8b JM |
62 | <table> |
63 | <tr> | |
6ace64d3 | 64 | <th>Program</th> |
2574936f | 65 | <th>Language</th> |
6ace64d3 JM |
66 | <th>Proxy or Interposer</th> |
67 | <th>Multiprocess</th> | |
68 | <th>Daemonize</th> | |
69 | <th>SSL/wss</th> | |
70 | <th>Flash Policy Server</th> | |
71 | <th>Session Record</th> | |
72 | <th>Web Server</th> | |
73 | </tr> <tr> | |
74 | <td>wsproxy.py</td> | |
e5d60a8b | 75 | <td>python</td> |
2574936f | 76 | <td>proxy</td> |
e5d60a8b | 77 | <td>yes</td> |
fd758dd3 | 78 | <td>yes</td> |
6ace64d3 | 79 | <td>yes 1</td> |
e5d60a8b JM |
80 | <td>yes</td> |
81 | <td>yes</td> | |
e5d60a8b | 82 | <td>yes</td> |
6ace64d3 JM |
83 | </tr> <tr> |
84 | <td>wsproxy</td> | |
85 | <td>C</td> | |
86 | <td>proxy</td> | |
87 | <td>yes</td> | |
e5d60a8b JM |
88 | <td>yes</td> |
89 | <td>yes</td> | |
fd758dd3 JM |
90 | <td>yes</td> |
91 | <td>no</td> | |
90966d62 | 92 | <td>no</td> |
fd758dd3 | 93 | </tr> |
6ace64d3 JM |
94 | </tr> <tr> |
95 | <td>wsproxy.js</td> | |
96 | <td>Node (node.js)</td> | |
97 | <td>proxy</td> | |
fd758dd3 | 98 | <td>yes</td> |
fd758dd3 JM |
99 | <td>no</td> |
100 | <td>no</td> | |
101 | <td>no</td> | |
6ace64d3 JM |
102 | <td>no</td> |
103 | <td>no</td> | |
e5d60a8b | 104 | </tr> |
6ace64d3 JM |
105 | </tr> <tr> |
106 | <td>wswrap/wswrapper.so</td> | |
107 | <td>shell/C</td> | |
108 | <td>interposer</td> | |
109 | <td>indirectly</td> | |
110 | <td>indirectly</td> | |
111 | <td>no</td> | |
2574936f JM |
112 | <td>no</td> |
113 | <td>no</td> | |
114 | <td>no</td> | |
115 | </tr> | |
e5d60a8b JM |
116 | </table> |
117 | ||
6ace64d3 | 118 | |
e5d60a8b JM |
119 | * Note 1: to use SSL/wss with python 2.5 or older, see the following |
120 | section on *Building the Python ssl module*. | |
121 | ||
122 | ||
123 | ### Building the Python ssl module (for python 2.5 and older) | |
124 | ||
125 | * Install the build dependencies. On Ubuntu use this command: | |
126 | ||
6502293f | 127 | `sudo aptitude install python-dev bluetooth-dev` |
e5d60a8b JM |
128 | |
129 | * Download, build the ssl module and symlink to it: | |
130 | ||
6502293f | 131 | `cd noVNC/utils` |
3dc3135b | 132 | |
6502293f | 133 | `wget http://pypi.python.org/packages/source/s/ssl/ssl-1.15.tar.gz` |
3dc3135b | 134 | |
6502293f | 135 | `tar xvzf ssl-1.15.tar.gz` |
3dc3135b | 136 | |
6502293f | 137 | `cd ssl-1.15` |
3dc3135b | 138 | |
6502293f | 139 | `make` |
3dc3135b | 140 | |
6502293f | 141 | `cd ../` |
3dc3135b | 142 | |
6502293f | 143 | `ln -sf ssl-1.15/build/lib.linux-*/ssl ssl` |
e5d60a8b | 144 |