netforward

package module
v0.0.0-...-6e22ef6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2016 License: MIT Imports: 7 Imported by: 0

README

Network forwarding GoDoc

Forward network packets between various protocols, e.g. TCP <-> UDP, TLS <-> TCP.

Install

go get github.com/goburrow/netforward/nf

Usage

nf [OPTIONS]

OPTIONS:
  -address string
        listen address (default "localhost:7000")
  -caFile string
        client certificate authorities file
  -certFile string
        certificate file
  -keyFile string
        certificate key file
  -network string
        network protocol (default "tcp")
  -remote.address string
        remote address (default "localhost:8000")
  -remote.caFile string
        server certificate authorities file
  -remote.certFile string
        certificate file
  -remote.keyFile string
        certificate key file
  -remote.network string
        network protocol (default "tcp")
  -remote.skipVerify
        Not to verify remote server certificate

With default options, nf will divert TCP packets from localhost:7000 to localhost:8000

Use cases

Protect an unsecure HTTP server
  • Many budget Internet of Things such as camera or sensor can only be accessed via a plain HTTP server.
  • By using port forwarding, they can be viewed from Internet but it is a risk to expose password when login.
  • VPN or SSL tunnel is too much overhead.

To mitigate, run a TLS endpoint in front of the unsecure HTTP server:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /path/to/cert.key -out /path/to/cert.crt

nf -certFile /path/to/cert.crt -keyFile /path/to/cert.key -address :8443 -remote.address 127.0.0.1:8080

Then only forward port 8443 in your router.

Certificates can also be acquired from https://letsencrypt.org or self-signed https://github.com/OpenVPN/easy-rsa

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Forward

func Forward(remote Dialer, local net.Listener) error

func ForwardPacket

func ForwardPacket(remote Dialer, local net.PacketConn) error

Types

type Dialer

type Dialer interface {
	Dial() (net.Conn, error)
}

Dialer dials to a remote address.

type Endpoint

type Endpoint struct {
	Network string
	Address string

	TLS *tls.Config

	// Remote
	Timeout time.Duration
}

Endpoint is a network endpoint which can dial to or listen from.

func (*Endpoint) Dial

func (e *Endpoint) Dial() (net.Conn, error)

Dial dials to the given network endpoint.

func (*Endpoint) Listen

func (e *Endpoint) Listen() (net.Listener, error)

Listen returns a listener of a local address. Network must be a stream type.

func (*Endpoint) ListenPacket

func (e *Endpoint) ListenPacket() (net.PacketConn, error)

ListenPacket returns a listener of a local address. Network must be a packet oriented type.

type Forwarder

type Forwarder interface {
	Forward(remote Dialer) error
}

Forwarder forwards packets sending to the local network to the remote network.

type NetForwarder

type NetForwarder struct {
	Local Endpoint
	// contains filtered or unexported fields
}

func (*NetForwarder) Close

func (f *NetForwarder) Close() error

func (*NetForwarder) Forward

func (f *NetForwarder) Forward(remote Dialer) error

func (*NetForwarder) Listen

func (f *NetForwarder) Listen() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL