GithubHelp home page GithubHelp logo

node-ssltunnel's Introduction

Build Status

What is ssltunnel?

This is a lightweight TCP over SSL / TLS tunnel running over node. If you need to add confidentiality (privacy), integrity, and authenticity to your TCP stream this is the tool for you.

Installation

Please follow the following steps to get it up and running:

  1. Download and install latest node (don't worry, it is small)
  2. Enter CMD and run: npm install ssltunnel
  3. The ssltunnel package now resides under ./node_modules/ssltunnel

Creating certificates

ssltunnel uses client and server certificates for creating proper TLS connection. While server certificate is enough to assure confidentiality and integrity, client certificate is required for assuring authenticity.

Test certificates are provided in the testcerts folder. You can start playing with sltunnel using them.

Please do not use test certificates for production.

You can easily create your certificates using openssl. Each certificate is represented by a key pair. The steps are the same for both client and server certificates. See some example of certificate generation below.

  dimast@DIMAST-LAPTOP /d/src/mygithub/temp
  $ openssl genrsa -out private.pem 2048
  Generating RSA private key, 2048 bit long modulus
  ...+++
  ............+++
  e is 65537 (0x10001)

  dimast@DIMAST-LAPTOP /d/src/mygithub/temp
  $ ls
  private.pem

  dimast@DIMAST-LAPTOP /d/src/mygithub/temp
  $ openssl req -new -x509 -key private.pem -out public.pem -days 365
  You are about to be asked to enter information that will be incorporated
  into your certificate request.
  What you are about to enter is what is called a Distinguished Name or a DN.
  There are quite a few fields but you can leave some blank
  For some fields there will be a default value,
  If you enter '.', the field will be left blank.
  -----
  Country Name (2 letter code) [AU]:IL
  State or Province Name (full name) [Some-State]:
  Locality Name (eg, city) []:
  Organization Name (eg, company) [Internet Widgits Pty Ltd]:
  Organizational Unit Name (eg, section) []:
  Common Name (eg, YOUR name) []:my_server
  Email Address []:

  dimast@DIMAST-LAPTOP /d/src/mygithub/temp
  $ ls
  private.pem  public.pem

PLEASE KEEP YOUR PRIVATE KEYS SECURE

Running the ssltunnel

Imagine you have a client-server application. The server is running on my_host:8080. You can route the traffic via ssl tunnel by creating both ssltunnel's server and client:

d:\src\ssltunnel\bin>ssltunnel.cmd -r server \
--proxy_port 54443 \
--server_port 8080 \
--server_host my_host \
--srv_pub_cert ..\testcerts\sc_public.pem \
--clt_pub_cert ..\testcerts\cc_public.pem \
--srv_prv_cert ..\testcerts\sc_private.pem \

Running 'server' role. Listening on 54443, decrypting and forwarding to real server machine on my_host:8080
d:\src\ssltunnel\bin>ssltunnel.cmd -r client \
--proxy_port 54080 \
--server_port 54443 \
--server_host my_ssltunnel_server_host \
--srv_pub_cert ..\testcerts\sc_public.pem \
--clt_pub_cert ..\testcerts\cc_public.pem \
--clt_prv_cert ..\testcerts\cc_private.pem \


Running 'client' role. Listening on 54080, encrypting and forwarding to ssltunnel's server on my_ssltunnel_server_host:54443

Now, just point you client to the machine where ssltunnel's client is running (localhost?) port 54808, and ssltunnel will take care of forwarding the data to the server securely.

This is the list of all arguments ssltunnel supports:

d:\src\ssltunnel\bin>ssltunnel
Usage node d:\src\ssltunnel\bin\run_ssltunnel.js

Options:
  -r, --role      The role of the tunnel component, either 'client' or 'server'              [required]
  --proxy_port    The proxy listener's port                                                  [required]
  --server_host   The server's hostname. Either ssltunnel's server role or back-end server   [default: "localhost"]
  --server_port   The server's port. Either ssltunnel's server role or back-end server       [required]
  --log_level     SSLTunnel logging level. One of: 'error', 'warn', 'info', or 'log'         [default: "log"]
  --keep_alive    Use TCP keep-alive when connecting to an sslserver. 
                  Provide keep-alive delay in ms. Use negative value for
                  turning keep-alive off. Relevant for client role only.                     [default: "30000"]
  --srv_pub_cert  Public certificate file for ssltunnel's server                             [required]
  --srv_prv_cert  Private certificate file for ssltunnel's server
  --clt_pub_cert  Public certificate for ssltunnel's client                                  [required]
  --clt_prv_cert  Private certificate for ssltunnel's client


Missing required arguments: r, proxy_port, server_port, srv_pub_cert, clt_pub_cert

API

You can use the library in your node project. The are two exported methods:

var ssltunnel = require('ssltunnel');

var options = {
  
    'proxy_port' : 8080,
    'server_host' : my_host,
    'server_port' : 54443,
    //...
}

ssltunnel.createServer(options);

// or

ssltunnel.createClient(options);

The options are basically property bag with data similar to what arguments contain. See run_ssltunnel.js for usage example.

The full list is below:

  • proxy_port : the listening proxy port. Receives cleartext for client role and ciphertext for server role.
  • server_port : the port of the server to forward the data to.
  • server_host : the host name of the server to forward the data to.
  • client_public_cert : client's role public certificate.
  • server_public_cert : client's role private certificate.
  • client_private_cert : servers's role public certificate.
  • server_private_cert : servers's role public certificate.
  • log_level : One of: 'error', 'warn', 'info', or 'log'.
  • keep_alive : Whether to use TCP keep alive when connecting to server role. This setting is relevant to client role only.

Enjoy!

node-ssltunnel's People

Contributors

dimastopel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-ssltunnel's Issues

Error is not shown and have error level at log

Using client mode with log level. I am able to get it listening on a port and says it will forward request and most likely i have a cert issue but I can't tell because it reports this back:

Error communicating with the server. Error: {}
connection to server was closed

I need more info if possible

NPN support

OpenSSL 1.0.1+ ships with Next Protocol Negotiation (NPN) support, which is required for SPDY protocol negotiation.

node-spdy supports this already, but it would be great to have this support baked right into node-ssltunnel and then deliver the frames over a regular TCP stream.

occasional crash on crypto stream

tls.js:96
throw new Error('CryptoStream is not writable');
^
Error: CryptoStream is not writable
at CleartextStream.write (tls.js:96:11)
at Socket. (C:\Users\dimast.MIDDLEEAST\node_modules\ssltunnel\lib\ssltunnel.js:82:27)
at Socket.emit (events.js:67:17)
at TCP.onread (net.js:347:14)

"node run_ssltunnel.js ..." encounter error

hi.

node run_ssltunnel.js --role client --proxy_port 54080 --server_port 64443 --server_host my-vps-ip --srv_pub_cert ~/node_modules/ssltunnel/gen-certs/server-public.pem --clt_pub_cert ~/node_modules/ssltunnel/gen-certs/client-public.pem --clt_prv_cert ~/node_modules/ssltunnel/gen-certs/client-private.pem
Running 'client' role. Listening on 54080, encrypting and forwarding to ssltunnel's server on my-vps-ip:64443
ssltunnel's client is listening on port: 54080

Connected to the real BE server
/Users/brite/node_modules/ssltunnel/lib/ssltunnel.js:141
log.info('Error communicating with the server. Error: ' + JSON.stringify(exception));
^

TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object'
--- property 'issuerCertificate' closes the circle
at JSON.stringify ()
at TLSSocket. (/Users/brite/node_modules/ssltunnel/lib/ssltunnel.js:141:70)
at TLSSocket.emit (events.js:208:15)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)

how to fix it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.