diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-09-27 16:11:55 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-09-27 16:11:55 -0700 |
commit | 31f7b2a5a65d2d640343013dac4bb836c3bfba5f (patch) | |
tree | e677a00733440e57ab61fb00a696284c1d7b960b /third_party | |
parent | e546b42883bbcabb4657dfcdb523a93d0458f5b3 (diff) |
initial (not-yet-working) sockets implementation
Diffstat (limited to 'third_party')
72 files changed, 10395 insertions, 0 deletions
diff --git a/third_party/websockify/.gitignore b/third_party/websockify/.gitignore new file mode 100644 index 00000000..86b78922 --- /dev/null +++ b/third_party/websockify/.gitignore @@ -0,0 +1,10 @@ +*.pyc +*.o +*.so +other/.lein-deps-sum +other/classes +other/lib +.project +.pydevproject +target.cfg +target.cfg.d diff --git a/third_party/websockify/CHANGES.txt b/third_party/websockify/CHANGES.txt new file mode 100644 index 00000000..cbd3f73f --- /dev/null +++ b/third_party/websockify/CHANGES.txt @@ -0,0 +1,18 @@ +Changes +======= + +0.2.0 - Sep 17, 2012 +-------------------- + + * Binary data support in websock.js + * Target config file/dir and multiple targets with token selector + * IPv6 fixes + * SSL target support + * Proxy to/from unix socket + + +0.1.0 - May 11, 2012 +-------------------- + + * Initial versioned release. + diff --git a/third_party/websockify/LICENSE.txt b/third_party/websockify/LICENSE.txt new file mode 100644 index 00000000..916a77a0 --- /dev/null +++ b/third_party/websockify/LICENSE.txt @@ -0,0 +1,11 @@ +websockify is licensed under the LGPL version 3 (see docs/LICENSE.GPL-3 and +docs/LICENSE.LGPL-3) with the following exceptions: + + include/base64.js : Choice of MIT 1.1, GPL-2 or LGPL-2.1 + + include/web-socket-js/ : New BSD license. Source code at + https://github.com/gimite/web-socket-js + + other/kumina.c : Simplified BSD license (2 clause). + Original source at + https://github.com/kumina/wsproxy diff --git a/third_party/websockify/MANIFEST.in b/third_party/websockify/MANIFEST.in new file mode 100644 index 00000000..2dd46d25 --- /dev/null +++ b/third_party/websockify/MANIFEST.in @@ -0,0 +1 @@ +include CHANGES.txt *.py README.md LICENSE.txt diff --git a/third_party/websockify/Makefile b/third_party/websockify/Makefile new file mode 100644 index 00000000..7dc1bc4f --- /dev/null +++ b/third_party/websockify/Makefile @@ -0,0 +1,11 @@ +TARGETS=rebind.so +CFLAGS += -fPIC + +all: $(TARGETS) + +rebind.so: rebind.o + $(CC) $(LDFLAGS) $^ -shared -fPIC -ldl -o $@ + +clean: + rm -f rebind.o rebind.so + diff --git a/third_party/websockify/README.md b/third_party/websockify/README.md new file mode 100644 index 00000000..48c790af --- /dev/null +++ b/third_party/websockify/README.md @@ -0,0 +1,155 @@ +## websockify: WebSockets support for any application/server + +websockify was formerly named wsproxy and was part of the +[noVNC](https://github.com/kanaka/noVNC) project. + +At the most basic level, websockify just translates WebSockets traffic +to normal socket traffic. Websockify accepts the WebSockets handshake, +parses it, and then begins forwarding traffic between the client and +the target in both directions. + +### WebSockets binary data + +Websockify supports all versions of the WebSockets protocol (Hixie and +HyBI). The older Hixie versions of the protocol only support UTF-8 +text payloads. In order to transport binary data over UTF-8 an +encoding must used to encapsulate the data within UTF-8. Websockify +uses base64 to encode all traffic to and from the client. This does +not affect the data between websockify and the server. + +### Encrypted WebSocket connections (wss://) + +To encrypt the traffic using the WebSocket 'wss://' URI scheme you +need to generate a certificate for websockify to load. By default websockify +loads a certificate file name `self.pem` but the `--cert=CERT` option can +override the file name. You can generate a self-signed certificate using +openssl. When asked for the common name, use the hostname of the server where +the proxy will be running: + +``` +openssl req -new -x509 -days 365 -nodes -out self.pem -keyout self.pem +``` + + +### Websock Javascript library + + +The `include/websock.js` Javascript library library provides a Websock +object that is similar to the standard WebSocket object but Websock +enables communication with raw TCP sockets (i.e. the binary stream) +via websockify. This is accomplished by base64 encoding the data +stream between Websock and websockify. + +Websock has built-in receive queue buffering; the message event +does not contain actual data but is simply a notification that +there is new data available. Several rQ* methods are available to +read binary data off of the receive queue. + +The Websock API is documented on the [websock.js API wiki page](https://github.com/kanaka/websockify/wiki/websock.js) + +See the "Wrap a Program" section below for an example of using Websock +and websockify as a browser telnet client (`wstelnet.html`). + + +### Additional websockify features + +These are not necessary for the basic operation. + +* Daemonizing: When the `-D` option is specified, websockify runs + in the background as a daemon process. + +* SSL (the wss:// WebSockets URI): This is detected automatically by + websockify by sniffing the first byte sent from the client and then + wrapping the socket if the data starts with '\x16' or '\x80' + (indicating SSL). + +* Flash security policy: websockify detects flash security policy + requests (again by sniffing the first packet) and answers with an + appropriate flash security policy response (and then closes the + port). This means no separate flash security policy server is needed + for supporting the flash WebSockets fallback emulator. + +* Session recording: This feature that allows recording of the traffic + sent and received from the client to a file using the `--record` + option. + +* Mini-webserver: websockify can detect and respond to normal web + requests on the same port as the WebSockets proxy and Flash security + policy. This functionality is activate with the `--web DIR` option + where DIR is the root of the web directory to serve. + +* Wrap a program: see the "Wrap a Program" section below. + + +### Implementations of websockify + +The primary implementation of websockify is in python. There are +several alternate implementations in other languages (C, Node.js, +Clojure, Ruby) in the `other/` subdirectory (with varying levels of +functionality). + +In addition there are several other external projects that implement +the websockify "protocol". See the alternate implementation [Feature +Matrix](https://github.com/kanaka/websockify/wiki/Feature_Matrix) for +more information. + + +### Wrap a Program + +In addition to proxying from a source address to a target address +(which may be on a different system), websockify has the ability to +launch a program on the local system and proxy WebSockets traffic to +a normal TCP port owned/bound by the program. + +The is accomplished with a small LD_PRELOAD library (`rebind.so`) +which intercepts bind() system calls by the program. The specified +port is moved to a new localhost/loopback free high port. websockify +then proxies WebSockets traffic directed to the original port to the +new (moved) port of the program. + +The program wrap mode is invoked by replacing the target with `--` +followed by the program command line to wrap. + + `./websockify 2023 -- PROGRAM ARGS` + +The `--wrap-mode` option can be used to indicate what action to take +when the wrapped program exits or daemonizes. + +Here is an example of using websockify to wrap the vncserver command +(which backgrounds itself) for use with +[noVNC](https://github.com/kanaka/noVNC): + + `./websockify 5901 --wrap-mode=ignore -- vncserver -geometry 1024x768 :1` + +Here is an example of wrapping telnetd (from krb5-telnetd).telnetd +exits after the connection closes so the wrap mode is set to respawn +the command: + + `sudo ./websockify 2023 --wrap-mode=respawn -- telnetd -debug 2023` + +The `wstelnet.html` page demonstrates a simple WebSockets based telnet +client. + + +### Building the Python ssl module (for python 2.5 and older) + +* Install the build dependencies. On Ubuntu use this command: + + `sudo aptitude install python-dev bluetooth-dev` + +* Download, build the ssl module and symlink to it: + + `cd websockify/` + + `wget http://pypi.python.org/packages/source/s/ssl/ssl-1.15.tar.gz` + + `tar xvzf ssl-1.15.tar.gz` + + `cd ssl-1.15` + + `make` + + `cd ../` + + `ln -sf ssl-1.15/build/lib.linux-*/ssl ssl` + diff --git a/third_party/websockify/Windows/Windows Service Readme.txt b/third_party/websockify/Windows/Windows Service Readme.txt new file mode 100644 index 00000000..1ddc2f82 --- /dev/null +++ b/third_party/websockify/Windows/Windows Service Readme.txt @@ -0,0 +1,39 @@ +----------------------------------- +Windows noVNC Websockify Service +----------------------------------- + +The "noVNC Websocket Service.exe" file is a windows service wrapper created with Visual Studio 2010 to create a windows service to start stop the noVNC Websocket Server. All files used to create the wrapper can be found in 'noVNC Websocket Service Project' folder. + +To download the precompiled executables please grab the zip in the downloads section of websockify project: +https://github.com/kanaka/websockify + +--------------------------- +Installation +--------------------------- + +1. This service requires websockify.exe be in the same directory. Instructions on how to compile websockify python script as a windows executable can be found here: +https://github.com/kanaka/noVNC/wiki/Compiling-Websockify-to-Windows-Executable + +2.To add this service to a Windows PC you need to run the commandline as administrator and then run this line: + +sc create "noVNC Websocket Server" binPath= "PATH TO noVNC eg C:\noVNC\utils\Windows\Websocket Service.exe" DisplayName= "noVNC Websocket Server" + +3 .Once this is run you will be able to access the service via Control Panel > Admin Tools > Services. In here you can specify whether you want the service to run automatically and start at stop the service. + +--------------------------- +Configuration +--------------------------- +The file noVNCConfig.ini must be in the same directory as "noVNC Websocket Service.exe". + +This file contains a single line which is the websockify.exe statup arguements. An example is: +192.168.0.1:5901 192.168.0.1:5900 + +All websockify supported arguements will work if added here. + +--------------------------- +Deletion +--------------------------- + +You can delete the service at any time by running the commandline as admin and using this command: +sc delete "noVNC Websocket Server". + diff --git a/third_party/websockify/Windows/noVNC Websocket Service Project/Program.cs b/third_party/websockify/Windows/noVNC Websocket Service Project/Program.cs new file mode 100644 index 00000000..2d07c330 --- /dev/null +++ b/third_party/websockify/Windows/noVNC Websocket Service Project/Program.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.ServiceProcess; +using System.Text; + +namespace MELT_Command_Websocket +{ + static class Program + { + /// <summary> + /// The main entry point for the application. + /// </summary> + static void Main() + { + ServiceBase[] ServicesToRun; + ServicesToRun = new ServiceBase[] + { + new Service1() + }; + ServiceBase.Run(ServicesToRun); + } + } +} diff --git a/third_party/websockify/Windows/noVNC Websocket Service Project/ProjectInstaller.Designer.cs b/third_party/websockify/Windows/noVNC Websocket Service Project/ProjectInstaller.Designer.cs new file mode 100644 index 00000000..3dab5bb7 --- /dev/null +++ b/third_party/websockify/Windows/noVNC Websocket Service Project/ProjectInstaller.Designer.cs @@ -0,0 +1,61 @@ +namespace MELT_Command_Websocket +{ + partial class ProjectInstaller + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller(); + this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller(); + // + // serviceProcessInstaller1 + // + this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.NetworkService; + this.serviceProcessInstaller1.Installers.AddRange(new System.Configuration.Install.Installer[] { + this.serviceInstaller1}); + this.serviceProcessInstaller1.Password = null; + this.serviceProcessInstaller1.Username = null; + // + // serviceInstaller1 + // + this.serviceInstaller1.Description = "noVNC Websocket Service"; + this.serviceInstaller1.DisplayName = "noVNC Websocket Service"; + this.serviceInstaller1.ServiceName = "noVNC Websocket Service"; + this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic; + // + // ProjectInstaller + // + this.Installers.AddRange(new System.Configuration.Install.Installer[] { + this.serviceProcessInstaller1}); + + } + + #endregion + + private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1; + private System.ServiceProcess.ServiceInstaller serviceInstaller1; + } +}
\ No newline at end of file diff --git a/third_party/websockify/Windows/noVNC Websocket Service Project/ProjectInstaller.cs b/third_party/websockify/Windows/noVNC Websocket Service Project/ProjectInstaller.cs new file mode 100644 index 00000000..783bb15b --- /dev/null +++ b/third_party/websockify/Windows/noVNC Websocket Service Project/ProjectInstaller.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Configuration.Install; +using System.Linq; + + +namespace MELT_Command_Websocket +{ + [RunInstaller(true)] + public partial class ProjectInstaller : System.Configuration.Install.Installer + { + public ProjectInstaller() + { + InitializeComponent(); + } + } +} diff --git a/third_party/websockify/Windows/noVNC Websocket Service Project/ProjectInstaller.resx b/third_party/websockify/Windows/noVNC Websocket Service Project/ProjectInstaller.resx new file mode 100644 index 00000000..fbda1aec --- /dev/null +++ b/third_party/websockify/Windows/noVNC Websocket Service Project/ProjectInstaller.resx @@ -0,0 +1,129 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0 |