]>
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 JM |
61 | |
62 | ||
63 | <table> | |
64 | <tr> | |
2574936f JM |
65 | <th>Application</th> |
66 | <th>Language</th> | |
67 | <th>Proxy or Interposer</th> | |
fd758dd3 | 68 | <th>Multi-process</th> |
e5d60a8b JM |
69 | <th>Daemonizing</th> |
70 | <th>SSL/wss</th> | |
71 | <th>Flash Policy Server</th> | |
72 | <th>Session Recording</th> | |
73 | </tr> <tr> | |
2574936f | 74 | <td>wsproxy</td> |
e5d60a8b | 75 | <td>python</td> |
2574936f | 76 | <td>proxy</td> |
e5d60a8b | 77 | <td>yes</td> |
fd758dd3 | 78 | <td>yes</td> |
e5d60a8b JM |
79 | <td>yes 1</td> |
80 | <td>yes</td> | |
81 | <td>yes</td> | |
82 | </tr> <tr> | |
2574936f | 83 | <td>wsproxy</td> |
e5d60a8b | 84 | <td>C</td> |
2574936f | 85 | <td>proxy</td> |
e5d60a8b JM |
86 | <td>yes</td> |
87 | <td>yes</td> | |
88 | <td>yes</td> | |
fd758dd3 JM |
89 | <td>yes</td> |
90 | <td>no</td> | |
91 | </tr> | |
92 | </tr> <tr> | |
2574936f | 93 | <td>wsproxy</td> |
fd758dd3 | 94 | <td>Node (node.js)</td> |
2574936f | 95 | <td>proxy</td> |
fd758dd3 | 96 | <td>yes</td> |
fd758dd3 JM |
97 | <td>no</td> |
98 | <td>no</td> | |
99 | <td>no</td> | |
e5d60a8b JM |
100 | <td>no</td> |
101 | </tr> | |
2574936f JM |
102 | </tr> <tr> |
103 | <td>wswrapper</td> | |
104 | <td>C</td> | |
105 | <td>interposer</td> | |
106 | <td>indirectly</td> | |
107 | <td>indirectly</td> | |
108 | <td>no</td> | |
109 | <td>no</td> | |
110 | <td>no</td> | |
111 | </tr> | |
e5d60a8b JM |
112 | </table> |
113 | ||
114 | * Note 1: to use SSL/wss with python 2.5 or older, see the following | |
115 | section on *Building the Python ssl module*. | |
116 | ||
117 | ||
118 | ### Building the Python ssl module (for python 2.5 and older) | |
119 | ||
120 | * Install the build dependencies. On Ubuntu use this command: | |
121 | ||
6502293f | 122 | `sudo aptitude install python-dev bluetooth-dev` |
e5d60a8b JM |
123 | |
124 | * Download, build the ssl module and symlink to it: | |
125 | ||
6502293f | 126 | `cd noVNC/utils` |
3dc3135b | 127 | |
6502293f | 128 | `wget http://pypi.python.org/packages/source/s/ssl/ssl-1.15.tar.gz` |
3dc3135b | 129 | |
6502293f | 130 | `tar xvzf ssl-1.15.tar.gz` |
3dc3135b | 131 | |
6502293f | 132 | `cd ssl-1.15` |
3dc3135b | 133 | |
6502293f | 134 | `make` |
3dc3135b | 135 | |
6502293f | 136 | `cd ../` |
3dc3135b | 137 | |
6502293f | 138 | `ln -sf ssl-1.15/build/lib.linux-*/ssl ssl` |
e5d60a8b | 139 |