onion

package module
v0.0.0-...-90a95e1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2015 License: Apache-2.0 Imports: 4 Imported by: 0

README

onion

GoDoc

Make an onion made of net and crypto layers.

o := onion.New(
  net.NewLayer(),
  tor.NewLayer(
    tor.WithPort(80), // Hidden service port
    tor.WithBin("/usr/bin/tor"),
    tor.WithVerbose(true),
  ),
  sch.NewLayer(
    sch.WithPubKey(readPubKey()),
    sch.WithPrivKey(readPrivKey()),
  ),
  tls.NewLayer(
    tls.WithCertKeyFile("ca.pem", "ca.key"),
  ),
  sch.NewLayer(
    sch.WithPubKey(readPubKey()),
    sch.WithPrivKey(readPrivKey()),
  ),
  sch.NewLayer(
    sch.WithPubKey(readPubKey()),
    sch.WithPrivKey(readPrivKey()),
  ),
)

TOR Hidden service

To create a tor hidden service, all You need to do is create an Onion:

o := onion.New(
  net.NewLayer(),
  tor.NewLayer(
    tor.WithPort(80), // Hidden service port
    tor.WithBin("/usr/bin/tor"),
  ),
)

Then you can start listening through TOR:

listener, err := o.Listener(nil)
if err != nil {
	glog.Fatal(err)
}

// Will output {address}.onion
glog.Infof("Listening on %s", listener.Addr())

for {
	c, err := listener.Accept()
	if err != nil {
		glog.Warning(err)
		continue
	}

	go serve(c)
}

You can also dial to TOR .onion services using this Onion:

conn, err := o.Connect("{address}.onion", time.Minute)
if err != nil {
	glog.Fatal(err)
}

conn.Write([]byte("Hello world!\n"))

Documentation

Overview

Package onion implements protocols and encryption onion.

Example onion could look like this:

onion := New(
	NetLayer(),
	TorLayer(),
	TLSLayer(),
	NaClLayer(),
	JWTLayer(keyLookupFunc),
	NaClLayer(),
)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTP

func HTTP(o Onion) *http.Client

HTTP - Returns http Client that dials through an onion.

Types

type Layer

type Layer interface {
	// Name - Layer name.
	Name() string

	// Conn - Wraps connection with a layer.
	// Some layers do nothing - for example TOR cant wrap existing connection.
	// It's usable for encryption layers.
	Conn(net.Conn) (net.Conn, error)

	// Listener - Wraps listener with a layer.
	Listener(net.Listener) (net.Listener, error)

	// Dial - Dials to address with a timeout.
	Dial(addr string, timeout time.Duration) (net.Conn, error) // Bool is false when it should be ignored

	// IsDialer - Returns false if the layer is just an encryption (and/or listening) layer.
	// Returns true if layer can dial. For example net, tor etc.
	IsDialer() bool

	// Close - Closes the layer, removes the keys, closes tor instance etc.
	Close() error
}

Layer - Onion layer.

type Onion

type Onion interface {
	// Dial - Connect for net.Dialer.
	Dial(string, string) (net.Conn, error)

	// Connect - Dials to a target through an onion.
	Connect(string, time.Duration) (net.Conn, error)

	// Listener - Wraps a listener with an onion.
	// Sometimes listener can or even should be empty.
	Listener(net.Listener) (net.Listener, error)

	// Close - Closes all layers of the onion.
	Close() error
}

Onion - Onion interface.

func New

func New(layers ...Layer) Onion

New - Creates a new onion from given layers.

Directories

Path Synopsis
layer
net
Package net implements net interface.
Package net implements net interface.
sch
tls
tor

Jump to

Keyboard shortcuts

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