A Server and client for proxying local ports through public interfaces
A Node.js client/server implementation of a secure tunnel over TLS/SSL. Useful for exposing local servers on public hosts. Initially implemented to expose a local server to browsers provided by BrowserStack to integrate their beta API with test scripts.
The idea is simple.
npm install tls-tunnel
To instantiate and start a server
var fs = require'fs';var Server = require'tls-tunnel'Server;var server =port: 8080 // port to listen for client connectionskey: fsreadFileSync'./keys/server-key.pem' // server's private keycert: fsreadFileSync'./keys/server-cert.pem' // server's SSL certificateca: fsreadFileSync'./keys/client-cert.pem' // list of authorized client SSL certificatesforwardedPorts:start: 8081 // Start of port range to assign to connecting clientscount: 10 // maximum number of ports and hence clients that can be supported;serverstart// server should be listening on port 8080 nowserverstop// server should have ended all connections and stopped;;
To instantiate and connect a client
var fs = require'fs';var http = require'http';var Client = require'tls-tunnel'Client;var client =tunnel:host: 'mytlstunnel.com' // the host where the server is runningport: 8080 // the port on which the server is runningkey: fsreadFileSync'./keys/client-key.pem' // client's private keycert: fsreadFileSync'./keys/client-cert.pem' // client's SSL certificateca: fsreadFileSync'./keys/server-cert.pem' // list of authorized server SSL certificatestarget:host: 'localhost' // the target host to expose through the tunnelport: 8000 // the target port to expose through the tunneltimeout: 5000 // Timeout in milliseconds to use when waiting for a server to assign a public port (default is 2000);clientconnectif error// errors could include not having enough ports available on// the server to support anotherelse// only if no errors were encountered will the <port> parameter// contain the public port that was assigned for the tunnelhttpget':' + portreson'data'// should receive the response from localhost:8000 here// (if it's listening of course);reson'end'clientdisconnect// client should have ended all connections;;;;
test/keys folder for certificates used by the tests. These can be regenerated at anytime using either
keys.sh (OSX, Linux) or
keys.bat (Windows). These scripts use OpenSSL. OSX and Linux most likely already ship with OpenSSL. If using Windows you will need to install OpenSSL first.
It should be noted that for the client to authorize server certificates they need to have the correct hosts listed as altnames in the v3 extensions (although this doesn't seem to be required on Windows).
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using
Copyright (c) 2012 Peter Halliday
Licensed under the MIT license.