torch

package module
v0.0.0-...-8402838 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2018 License: Apache-2.0 Imports: 28 Imported by: 0

README

This code probably does not fit your needs. Do not use this unless you have read and understood tor-spec.txt and really know what you are doing.

In here you will find an implementation of a subset of the TOR client protocol and a TOR consensus parser. As a rule, only the latest versons of the subprotocols are implemented.

Documentation

Index

Constants

View Source
const (
	HASH_LEN = 20
	KEY_LEN  = 16
)
View Source
const (
	PAYLOAD_LEN   = 509
	CIRCID_LEN_v1 = 2
	CIRCID_LEN_v4 = 4
)
View Source
const (
	CELL_PADDING = iota
	CELL_CREATE
	CELL_CREATED
	CELL_RELAY
	CELL_DESTROY
	CELL_CREATE_FAST
	CELL_CREATED_FAST
	CELL_VERSIONS // variable-length
	CELL_NETINFO
	CELL_RELAY_EARLY
	CELL_CREATE2
	CELL_CREATED2
)
View Source
const (
	CELL_VPADDING = 128 + iota
	CELL_CERTS
	CELL_AUTH_CHALLENGE
	CELL_AUTHENTICATE
	CELL_AUTHORIZE
)
View Source
const (
	RELAY_BEGIN = 1 + iota
	RELAY_DATA
	RELAY_END
	RELAY_CONNECTED
	RELAY_SENDME
	RELAY_EXTEND
	RELAY_EXTENDED
	RELAY_TRUNCATE
	RELAY_TRUNCATED
	RELAY_DROP
	RELAY_RESOLVE
	RELAY_RESOLVED
	RELAY_BEGIN_DIR
	RELAY_EXTEND2
	RELAY_EXTENDED2
)
View Source
const (
	RELAY_ESTABLISH_INTRO = 32 + iota
	RELAY_ESTABLISH_RENDEZVOUS
	RELAY_INTRODUCE1
	RELAY_INTRODUCE2
	RELAY_RENDEZVOUS1
	RELAY_RENDEZVOUS2
	RELAY_INTRO_ESTABLISHED
	RELAY_RENDEZVOUS_ESTABLISHED
	RELAY_INTRODUCE_ACK
)
View Source
const (
	REASON_MISC = 1 + iota
	REASON_RESOLVEFAILED
	REASON_CONNECTREFUSED
	REASON_EXITPOLICY
	REASON_DESTROY
	REASON_DONE
	REASON_TIMEOUT
	REASON_NOROUTE
	REASON_HIBERNATING
	REASON_INTERNAL
	REASON_RESOURCELIMIT
	REASON_CONNRESET
	REASON_TORPROTOCOL
	REASON_NOTDIRECTORY
)
View Source
const (
	RELAY_PAYLOAD_LEN = PAYLOAD_LEN - 11
)

Variables

View Source
var ErrStreamClosed = fmt.Errorf("stream closed")

Functions

func BuildCircuit

func BuildCircuit(ctx context.Context, dialer proxy.Dialer, nodes []*directory.NodeInfo) (*TorConn, *Circuit, error)

func BuildDirectoryCircuit

func BuildDirectoryCircuit(ctx context.Context, dirs []*directory.MinimalNodeInfo, dialer proxy.Dialer) (tc *TorConn, circ *Circuit, err error)

func DownloadConsensus

func DownloadConsensus(dirClient *http.Client, authorityFingerprints []string) (*directory.Consensus, directory.Authorities, error)

func DownloadMicrodescriptors

func DownloadMicrodescriptors(dirClient *http.Client, snis []*directory.ShortNodeInfo) ([]*directory.NodeInfo, error)

Types

type Circuit

type Circuit struct {
	// contains filtered or unexported fields
}

func (*Circuit) Close

func (circ *Circuit) Close() error

func (*Circuit) Dial

func (circ *Circuit) Dial(network, addr string) (c net.Conn, err error)

Dial implements proxy.Dialer using DialTCP and DialDir based on the hostname, returning multiplexed connections.

func (*Circuit) DialDir

func (circ *Circuit) DialDir(ctx context.Context) (*Stream, error)

DialDir connects to the directory port of the relay

func (*Circuit) DialRendezvousRaw

func (circ *Circuit) DialRendezvousRaw(cookie, payload []byte) error

DialRendezvousRaw executes the "server" part of the rendezvous protocol. Requires len(cookie) = 20, len(payload) = 148. The Circuit should not be used for other purposes after this. On success, this circuit will be connected to the rendezvous peer and the circuit will enter raw mode.

func (*Circuit) DialTCP

func (circ *Circuit) DialTCP(ctx context.Context, net, address string) (*Stream, error)

DialTCP connects to a TCP server on the public Internet.

func (*Circuit) Extend

func (circ *Circuit) Extend(ip net.IP, port uint16, routerid, ntorPublic []byte) error

func (*Circuit) ListenRendezvousRaw

func (circ *Circuit) ListenRendezvousRaw(cookie []byte) (func() ([]byte, error), error)

ListenRendezvousRaw executes the "client" part of the rendezvous protocol. Requires len(cookie) = 20. The returned function, accept, waits for the server to complete the rendezvous protocol and returns the 148-byte server handshake message and on success, this circuit will be connected to the rendezvous peer and the circuit will enter raw mode.

func (*Circuit) ReadRaw

func (circ *Circuit) ReadRaw() ([]byte, error)

func (*Circuit) WriteRaw

func (circ *Circuit) WriteRaw(payload []byte) error

WriteRaw encrypts and sends payload over the circuit in a RELAY cell. The payload slice IS MODIFIED.

type MultiplexConn

type MultiplexConn Stream

MultiplexConn wraps a Stream to provide a net.Conn interface without interereing with other streams on the same circuit. However, this means that we cannot use TCP-level deadlines, and there currently is no deadline support (soft deadlines may be implemented in the future).

func (*MultiplexConn) Close

func (c *MultiplexConn) Close() error

func (*MultiplexConn) LocalAddr

func (c *MultiplexConn) LocalAddr() net.Addr

func (*MultiplexConn) Read

func (c *MultiplexConn) Read(buf []byte) (int, error)

func (*MultiplexConn) RemoteAddr

func (c *MultiplexConn) RemoteAddr() net.Addr

func (*MultiplexConn) SetDeadline

func (c *MultiplexConn) SetDeadline(t time.Time) error

func (*MultiplexConn) SetReadDeadline

func (c *MultiplexConn) SetReadDeadline(t time.Time) error

func (*MultiplexConn) SetWriteDeadline

func (c *MultiplexConn) SetWriteDeadline(t time.Time) error

func (*MultiplexConn) Write

func (c *MultiplexConn) Write(buf []byte) (int, error)

type SingleStreamConn

type SingleStreamConn struct {
	// contains filtered or unexported fields
}

SingleStreamConn uses one TOR connection carrying a single circuit carrying a single stream as a net.Conn. This enables direct access to TCP-level deadlines, but incurs the overhead of torconn and circuit creation.

func (*SingleStreamConn) Close

func (c *SingleStreamConn) Close() error

func (*SingleStreamConn) LocalAddr

func (c *SingleStreamConn) LocalAddr() net.Addr

func (*SingleStreamConn) Read

func (c *SingleStreamConn) Read(buf []byte) (int, error)

func (*SingleStreamConn) RemoteAddr

func (c *SingleStreamConn) RemoteAddr() net.Addr

func (*SingleStreamConn) SetDeadline

func (c *SingleStreamConn) SetDeadline(t time.Time) error

func (*SingleStreamConn) SetReadDeadline

func (c *SingleStreamConn) SetReadDeadline(t time.Time) error

func (*SingleStreamConn) SetWriteDeadline

func (c *SingleStreamConn) SetWriteDeadline(t time.Time) error

func (*SingleStreamConn) Write

func (c *SingleStreamConn) Write(buf []byte) (int, error)

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

func (*Stream) Close

func (stream *Stream) Close() error

func (*Stream) Read

func (stream *Stream) Read(out []byte) (int, error)

func (*Stream) RemoteAddr

func (stream *Stream) RemoteAddr() net.Addr

func (*Stream) Write

func (stream *Stream) Write(b []byte) (int, error)

type TorConn

type TorConn struct {
	// contains filtered or unexported fields
}

torConn implements the TOR link protocol. Only link protocol version 4 is supported.

func DialOnionRouter

func DialOnionRouter(ctx context.Context, address string, ID []byte, dialer proxy.Dialer) (*TorConn, error)

func (*TorConn) Close

func (tc *TorConn) Close() error

func (*TorConn) CreateCircuit

func (tc *TorConn) CreateCircuit(ctx context.Context, routerid, ntorPublic []byte) (*Circuit, error)

type Torch

type Torch struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, dialer proxy.Dialer) (*Torch, error)

New initializes a new TOR client, loading the consensus information. When New returns, the resulting TOR client is in a good state for selecting and establishing circuits.

func (*Torch) Pick

func (t *Torch) Pick(weighWith func(w *directory.BandwidthWeights, n *directory.NodeInfo) int64, rnd *mathrand.Rand) *directory.NodeInfo

func (*Torch) Stop

func (t *Torch) Stop() error

func (*Torch) UnguardedCircuitTo

func (t *Torch) UnguardedCircuitTo(ctx context.Context, n int, dst *directory.NodeInfo) (*TorConn, *Circuit, error)

func (*Torch) UnguardedExitCircuit

func (t *Torch) UnguardedExitCircuit(ctx context.Context, n int) (*TorConn, *Circuit, error)

func (*Torch) WithDirectory

func (t *Torch) WithDirectory(f func(*directory.Directory) interface{}) interface{}

Directories

Path Synopsis
bufio
Package bufio implements buffered I/O. It wraps an io.Reader or io.Writer object, creating another object (Reader or Writer) that also implements the interface but provides buffering and some help for textual I/O.
Package bufio implements buffered I/O. It wraps an io.Reader or io.Writer object, creating another object (Reader or Writer) that also implements the interface but provides buffering and some help for textual I/O.

Jump to

Keyboard shortcuts

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