Documentation
¶
Overview ¶
Package tor implements a minimal pure-Go Tor client. The public entry point is Client.DialContext, which is compatible with proxy.ContextDialer and *net.Dialer.DialContext, so it can be installed directly as an http.Transport.DialContext.
Stage 1 supports clearnet streams over 3-hop circuits and v3 onion services. Only modern protocol features are implemented: ntor handshakes, link protocol v4/v5, and the microdescriptor consensus.
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) DialContext(ctx context.Context, network, addr string) (net.Conn, error)
- func (c *Client) DirGet(ctx context.Context, path string) ([]byte, error)
- func (c *Client) NewIdentity()
- func (c *Client) RotateGuard(ctx context.Context) error
- func (c *Client) Stats() Stats
- type Config
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a bootstrapped Tor client.
func NewClient ¶
NewClient bootstraps the client: it verifies a fresh consensus, selects and connects an entry guard, and returns a ready Client.
func (*Client) Close ¶
Close stops the janitor, tears down all pooled circuits, and closes the guard channel (which drops the directory circuit and every other circuit on it).
func (*Client) DialContext ¶
DialContext opens a stream through Tor. addr is "host:port"; a ".onion" host is routed through the v3 onion-service flow, anything else through a 3-hop circuit and an exit relay.
func (*Client) DirGet ¶
DirGet implements directory.Tunnel: it fetches a directory document through Tor over a reusable BEGIN_DIR circuit, anonymizing post-bootstrap directory requests (microdescriptors, consensus refreshes). The circuit's stream manager is shared and persistent, so concurrent DirGet calls multiplex distinct streams over it instead of each resetting the circuit's cell handler.
func (*Client) NewIdentity ¶
func (c *Client) NewIdentity()
NewIdentity drops all pooled circuits so subsequent dials build fresh paths — the NEWNYM equivalent. It performs no network I/O: idle circuits are torn down immediately; in-use ones are retired and reaped once their last stream closes, so existing open streams keep working until the caller closes them.
func (*Client) RotateGuard ¶
RotateGuard closes the current guard channel (tearing down every circuit on it, including all pooled and directory circuits) and connects to a different entry guard. In-flight streams break; callers should expect to redial.
type Config ¶
type Config struct {
// DataDir, if set, persists the selected guard between runs and, unless
// Cache is provided, backs an on-disk directory cache (consensus, certs,
// microdescriptors) for faster startup.
DataDir string
// Logger receives debug/info logs; defaults to slog.Default().
Logger *slog.Logger
// DirAuthorities overrides the hardcoded authority set (for tests).
DirAuthorities []directory.Authority
// Cache overrides the directory cache implementation. When nil and DataDir
// is set, an on-disk cache under DataDir/cache is used; when nil and DataDir
// is empty, caching is disabled.
Cache directory.Cache
// OnionClientAuth maps an onion address (the 56-char base32 label, with or
// without the ".onion" suffix) to a 32-byte x25519 client-authorization
// private key, for connecting to restricted-discovery onion services.
OnionClientAuth map[string][]byte
// MaxCircuitDirtiness bounds how long a pooled circuit accepts new streams
// after first use, mirroring tor's option of the same name. Zero selects the
// 10-minute default.
MaxCircuitDirtiness time.Duration
// AllowDirectDirFallback permits post-bootstrap directory fetches to fall back
// to direct HTTP (from the local IP) when the Tor tunnel fails. Default false:
// once the tunnel is up, tunnel failures are returned as errors rather than
// silently deanonymizing the request. The cold-start consensus is always
// fetched directly regardless of this setting.
AllowDirectDirFallback bool
}
Config configures a Client. The zero value is usable; all fields optional.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
go-tor-client
command
Command go-tor-client is a command-line front end for the pure-Go Tor client.
|
Command go-tor-client is a command-line front end for the pure-Go Tor client. |
|
internal
|
|
|
byteutil
Package byteutil provides small big-endian and buffer helpers used across the Tor client.
|
Package byteutil provides small big-endian and buffer helpers used across the Tor client. |
|
relay
Package relay copies data bidirectionally between two connections for proxy tunnels (SOCKS CONNECT, HTTP CONNECT).
|
Package relay copies data bidirectionally between two connections for proxy tunnels (SOCKS CONNECT, HTTP CONNECT). |
|
pkg
|
|
|
cell
Package cell implements the Tor link-protocol cell codec for link versions 4 and 5 (4-byte circuit IDs), plus the baseline relay-cell layout.
|
Package cell implements the Tor link-protocol cell codec for link versions 4 and 5 (4-byte circuit IDs), plus the baseline relay-cell layout. |
|
channel
Package channel implements a Tor link connection (an "OR connection") to a single relay: a TLS transport, the VERSIONS/CERTS/NETINFO link handshake for link protocol v4/v5, verification of the relay's Ed25519 identity, and multiplexed cell framing for the circuits running over it.
|
Package channel implements a Tor link connection (an "OR connection") to a single relay: a TLS transport, the VERSIONS/CERTS/NETINFO link handshake for link protocol v4/v5, verification of the relay's Ed25519 identity, and multiplexed cell framing for the circuits running over it. |
|
circuit
Package circuit builds and operates Tor circuits over a link channel: the ntor v1 CREATE2/EXTEND2 telescoping handshake, the per-hop onion crypto (persistent AES-128-CTR keystreams plus a rolling SHA-1 digest), the RELAY_EARLY budget, and inbound cell recognition/decryption.
|
Package circuit builds and operates Tor circuits over a link channel: the ntor v1 CREATE2/EXTEND2 telescoping handshake, the per-hop onion crypto (persistent AES-128-CTR keystreams plus a rolling SHA-1 digest), the RELAY_EARLY budget, and inbound cell recognition/decryption. |
|
directory
Package directory bootstraps the Tor network view: it fetches and verifies the microdescriptor consensus, fetches the referenced microdescriptors, and validates consensus signatures against the hardcoded directory authorities.
|
Package directory bootstraps the Tor network view: it fetches and verifies the microdescriptor consensus, fetches the referenced microdescriptors, and validates consensus signatures against the hardcoded directory authorities. |
|
httpproxy
Package httpproxy implements a minimal HTTP forward proxy (RFC 7230) that is dialer-agnostic: the caller supplies a Dialer, so every proxied connection — both CONNECT tunnels and plain forwarded HTTP requests — is dialed through that transport.
|
Package httpproxy implements a minimal HTTP forward proxy (RFC 7230) that is dialer-agnostic: the caller supplies a Dialer, so every proxied connection — both CONNECT tunnels and plain forwarded HTTP requests — is dialed through that transport. |
|
onion
Package onion implements the v3 onion-service client: address parsing, the time-period / shared-random HSDir hash ring, two-layer descriptor decryption, and the intro/rendezvous handshake plumbing (hs_ntor).
|
Package onion implements the v3 onion-service client: address parsing, the time-period / shared-random HSDir hash ring, two-layer descriptor decryption, and the intro/rendezvous handshake plumbing (hs_ntor). |
|
pathsel
Package pathsel selects circuit paths from a verified consensus: flag filtering, bandwidth-weighted sampling, and position exclusions (same relay, same IPv4 /16 or IPv6 /32).
|
Package pathsel selects circuit paths from a verified consensus: flag filtering, bandwidth-weighted sampling, and position exclusions (same relay, same IPv4 /16 or IPv6 /32). |
|
proxyauth
Package proxyauth defines the credential-isolated dialer abstraction shared by the SOCKS and HTTP proxy servers.
|
Package proxyauth defines the credential-isolated dialer abstraction shared by the SOCKS and HTTP proxy servers. |
|
socks
Package socks implements a minimal SOCKS5 proxy server (RFC 1928) with optional username/password authentication (RFC 1929).
|
Package socks implements a minimal SOCKS5 proxy server (RFC 1928) with optional username/password authentication (RFC 1929). |
|
stream
Package stream multiplexes application streams over a single Tor circuit: RELAY_BEGIN/CONNECTED/DATA/END exchange, stream-ID allocation, and stream-level flow control via SENDME cells.
|
Package stream multiplexes application streams over a single Tor circuit: RELAY_BEGIN/CONNECTED/DATA/END exchange, stream-ID allocation, and stream-level flow control via SENDME cells. |
|
torcrypto
Package torcrypto implements the cryptographic primitives used by the Tor client: the ntor v1 and hs_ntor handshakes, AES-CTR relay keystreams, the running relay digest, HKDF-SHA256, SHA3-256/SHAKE256 helpers, X25519 ECDH, and ed25519 key blinding for v3 onion services.
|
Package torcrypto implements the cryptographic primitives used by the Tor client: the ntor v1 and hs_ntor handshakes, AES-CTR relay keystreams, the running relay digest, HKDF-SHA256, SHA3-256/SHAKE256 helpers, X25519 ECDH, and ed25519 key blinding for v3 onion services. |