Coder Social home page Coder Social logo

sni-passthrough's Introduction

sni-passthrough

A minimalistic SNI pass-through proxy. Not a full featured TLS termination or load-balancer!

Usage

require('sni-passthrough').createServer({
    sni: {
        'sni-1.com': '127.0.0.1:444',
        'sni-2.com': '> 127.0.0.1:445',
        'sni-3.com': '[::1]:446',
        '*':         '127.0.0.1:444'
    }
})
.listen(443)

API

createServer(opts) => net.Server

opts.sni

Either an object or a function

The object: hostname => destination mapping
destination is a "host:port" string, port must NOT be omitted.
Wildcard and RegExp are not supported.
Use destination null to blacklist a domain name.
Prepend > to destination to mark a compatible backend. Use hostname '*' to designate a fallback.

The function: (hostname) => forwardFunc(conn, buf) || undefined
If SNI is not sent, hostname will be null
If function returns undefined, incoming connection is dropped.
Use this to implement load-balancing or complicated logic.
forwardFunc should connect and pipe conn to backend.

opts will be passed to net.createServer, you can specify additional options

Remote peer IP address

Use > to mark a compatible backend destination.
In this case, remote peer's information is injected before piping.
For example, see sni-passthrough-backend

Do not specify this flag for incompatible backend!

Maybe a X-Forwarded-For TLS extension? ๐Ÿ™ƒ

Performance

On loopback, with my 2015 MBP @ 2.4Ghz, I was able to achieve:

  • ~8Ghz thorough-put
  • ~1800 QPS for a single 2000 QPS backend (~10% loss, wrk -c100)

Testing

  1. Generate key, self-sign certificate
  2. Put them at key.pem, cert.pem
  3. In terminal, run mocha

License

MIT

sni-passthrough's People

Contributors

wacky6 avatar

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.