Total Pageviews

Wednesday, 28 September 2016


 Build Status

Shadowsocks-NaCl is a Native Client port of shadowsocks, provides high performance crypto and network relay on web browser which support Native Client.
Note: This port of shadowsocks is for Web App developers ONLY, NOT for the end user. For end user, use shadowsocks-chromeapp instead.


  1. Download and install Native Client SDK.
  2. Set environment variable NACL_SDK_ROOT to SDK path (e.g., ~/nacl_sdk/pepper_47).
  3. Checkout webports, a.k.a. naclports.
  4. Follow the instructions in webports/ to install webports.
  5. Build and install OpenSSL to Native Client SDK. (e.g., $ NACL_ARCH=pnacl make openssl)
  6. For webports branch below pepper_47: Update libsodium in webports from 0.4.5 to 1.0.3 since ChaCha20 was added in 0.6.0. You may change the content of webports/src/ports/libsodium/pkg_info to
  7. Build and install libsodium to Native Client SDK. (e.g., $ NACL_ARCH=pnacl make libsodium)
  8. Clone this repository and use $ make to build.


You can use Shadowsocks-NaCl JavaScript API to communicate with native client module. You just need include src/shadowsocks.js into your webapp page, initialize it, and use it.


You can initialize Shadowsocks-NaCl JavaScript API like this:
var shadowsocks = new Shadowsocks('path/to/nmf');
It will return a Shadowsocks object, then you can invoke API commands or add event listeners.


Raw Native Client Progress Events

This type of events includes loadstartprogresserrorabortloadloadend and crash, they indicates the native client module load status, see native client document for more information.

Raw Native Client Message Event

message is the raw native client message event, all shadowsocks command call rely on this event, typically you don't need to listen on this event. If you really want, see native client document for more information.

Shadowsocks status event

status is the shadowsocks status event. All runtime information, like server listen state, link error message, will be passed to the callback of status event, in an object form like: { type: 'status', level: 'foo', message: 'bar' }.
level in object could be one of the successinfowarning or danger, and the message could be a string or an object.


Profile is a JavaScript object, it can be passed to API connect directly.
    server: "",  // Domain/IP Address in string form
    server_port: 8388,      // Value must be a number
    local_port: 1080,       // Value must be a number
    method: "aes-256-cfb",  // Value must be a string and in supported cipher list
    password: "password",   // Value must be a string
    timeout: 300,           // Value in seconds and must be a number
    one_time_auth: false    // Value must be a boolean, optional, default to false


  • shadowsocks.addEventListener(event, callback, context)

    Add an event listener, context is an optional this for callback.
  • shadowsocks.on(event, callback, context)

    Alias of shadowsocks.addEventListener(event, callback, context)
  • shadowsocks.removeEventListener(event, callback, context)

    Remove an event listener, eventcallbackcontext must be the same one of which passed to addEventListener.
  •, callback, context)

    Alias of shadowsocks.removeEventListener(event, callback, context)
  • shadowsocks.load()

    Load shadowsocks native client module. After invoke, it will trigger progress events.
  • shadowsocks.unload()

    Unload shadowsocks native client module. It will also clear all registered event listeners.
  • shadowsocks.getElement()

    Return the native client <embed> element.
  • shadowsocks.connect(profile, callback, context)

    Connect to a server, callback will be called with argument 0.
  • shadowsocks.disconnect(callback, context)

    Disconnect from a server, callback will be called with argument 0.
  • shadowsocks.sweep(callback, context)

    Sweep timeout connection from connection pool, the native client module cannot do sweep automatically, so you must sweep it by yourself.
    Typically, you should invoke this function repeatedly in fixed time (could same as timeout in profile).
    The callback function will be called with argument 0.
  • shadowsocks.version(callback, context)

    callback function will be called with the native client module version in string form.
    If callback is not specified, it will log version string into console.
  • shadowsocks.listCipher(callback, context)

    callback function will be called with the array of supported cipher name in string form.

Test flight

A Chromium App is provided to help testing and debugging.
You can open chrome://extensions/, check Developer Mode, click Load Unpacked Extension, select the root directory of this project.
You will find a new App named Shadowsocks NaCl Test flight in chrome://extensions/, click Inspect views: background page will open a developer tools window and you can try above-mentioned command here.