A pure GO implementation of tor protocol https://spec.torproject.org/intro/index.html
  • Go 99.9%
  • Python 0.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-25 00:03:27 +00:00
.github/workflows feat(path): implement path-bias usable probes 2026-11-14 15:44:37 -03:00
examples/embed feat(path): implement path-bias usable probes 2026-11-14 15:44:37 -03:00
internal chore: update fallback directory 2026-11-25 00:03:27 +00:00
pkg feat(path): implement path-bias usable probes 2026-11-14 15:44:37 -03:00
tools refactor(parsers): extract consensus and microdesc parsing into pkg/parsers 2026-08-27 19:51:02 -03:00
torspec/guard-spec docs(guard-spec): vendor authoritative guard specification 2026-11-07 19:54:58 -03:00
.gitignore feat: microdesc parsing 2026-03-22 21:44:06 -03:00
AGENTS.md feat(core): add persistent guards, trust boundary, and recovery hardening 2026-11-07 19:54:58 -03:00
atomic.go ref: storing last data bearing cell checksum in the window struct; stop using mutex and started to use atomics in window 2026-07-01 17:26:14 -03:00
bench_stream_test.go test(ci): add fuzz benchmarks and platform gates 2026-11-08 15:59:23 -03:00
bootstraping.go feat(core): add persistent guards, trust boundary, and recovery hardening 2026-11-07 19:54:58 -03:00
bootstraping_recovery_test.go feat(core): add persistent guards, trust boundary, and recovery hardening 2026-11-07 19:54:58 -03:00
bootstraping_test.go feat(core): add persistent guards, trust boundary, and recovery hardening 2026-11-07 19:54:58 -03:00
capi_adapter.go feat(path): implement path-bias usable probes 2026-11-14 15:44:37 -03:00
circuit.go feat(path): implement path-bias usable probes 2026-11-14 15:44:37 -03:00
circuit_build.go feat(core): harden circuit lifecycle and resource ownership 2026-11-08 15:58:55 -03:00
circuit_loop.go feat(path): implement path-bias usable probes 2026-11-14 15:44:37 -03:00
circuit_methods.go feat(core): add persistent guards, trust boundary, and recovery hardening 2026-11-07 19:54:58 -03:00
circuit_probe.go feat(path): implement path-bias usable probes 2026-11-14 15:44:37 -03:00
circuit_probe_test.go feat(path): implement path-bias usable probes 2026-11-14 15:44:37 -03:00
circuit_service.go feat(hs): add rollover coverage and bounded maintenance 2026-11-08 15:59:03 -03:00
circuit_service_test.go feat(hs): add rollover coverage and bounded maintenance 2026-11-08 15:59:03 -03:00
circuit_teardown_test.go feat(core): harden circuit lifecycle and resource ownership 2026-11-08 15:58:55 -03:00
conn.go fix(conn): use context deadlines for link handshake 2026-11-09 15:02:25 -03:00
conn_authorities_test.go feat(core): add persistent guards, trust boundary, and recovery hardening 2026-11-07 19:54:58 -03:00
conn_handshake_deadline_test.go fix(conn): use context deadlines for link handshake 2026-11-09 15:02:25 -03:00
conn_identity_test.go feat(embed): add pinned bridge routing and Snowflake defaults 2026-10-10 21:49:10 -03:00
conn_loop.go feat(core): harden circuit lifecycle and resource ownership 2026-11-08 15:58:55 -03:00
errors.go feat: logging system to better debugging and can be useful if the lib is 2026-07-24 15:47:48 -03:00
errors_test.go ref(test): better tests 2026-07-24 16:08:47 -03:00
go.mod feat(core): add persistent guards, trust boundary, and recovery hardening 2026-11-07 19:54:58 -03:00
go.sum feat(core): add persistent guards, trust boundary, and recovery hardening 2026-11-07 19:54:58 -03:00
helpers.go fix(circuit): wait for link delivery and serialize relay crypto per hop 2026-09-26 13:57:20 -03:00
http.go feat: add BuildPath and Dial helpers for exit streams 2026-07-28 22:48:25 -03:00
icon.png docs: added gonion icon 2026-05-24 12:29:02 -03:00
leak_gates_test.go test(core): add leak and soak resource gates 2026-11-09 15:02:25 -03:00
LICENSE chore(license): changed license 2026-08-03 21:05:28 -03:00
log.go feat(embed): add pinned bridge routing and Snowflake defaults 2026-10-10 21:49:10 -03:00
log_test.go feat(embed): add pinned bridge routing and Snowflake defaults 2026-10-10 21:49:10 -03:00
README.md feat(path): implement path-bias usable probes 2026-11-14 15:44:37 -03:00
SECURITY.md docs: update production status and limitations 2026-11-08 15:59:29 -03:00
soak_test.go feat(path): implement path-bias usable probes 2026-11-14 15:44:37 -03:00
stream.go feat(core): harden circuit lifecycle and resource ownership 2026-11-08 15:58:55 -03:00
stream_buff.go fix(circuit): wait for link delivery and serialize relay crypto per hop 2026-09-26 13:57:20 -03:00
stream_open.go feat(path): implement path-bias usable probes 2026-11-14 15:44:37 -03:00
stream_stress_test.go feat(core): add persistent guards, trust boundary, and recovery hardening 2026-11-07 19:54:58 -03:00
stream_test.go fix(circuit): wait for link delivery and serialize relay crypto per hop 2026-09-26 13:57:20 -03:00

Gonion

Gonion

An experimental pure-Go Tor client and onion-v3 service designed for embedding. No CGO, native bindings, libtor, external Tor daemon or local SOCKS proxy is required by the client implementation.

Not production-ready or an anonymity boundary. Persistent public guard state is required for every circuit and path-bias accounting is implemented, but the guard/trust/path-bias code is new and awaiting independent review, and no full security audit has been completed. Successful TCP/HTTPS/onion interoperability tests do not establish anonymity, censorship resistance, reduced detectability, or complete Tor compatibility.

Supported scope

Production-oriented use must stay inside this scope; anything outside fails closed and requires separate specification review and acceptance evidence:

  • Surface TCP/IPv4 Dial and onion-v3 Dial/Listen, over direct networking or one caller-pinned bridge. Options.Guards (persistent, caller-owned public guard state) is mandatory outside bridge mode.
  • Deliberately unsupported and rejected: IPv6 exit streams, multi-bridge selection, authorized onion services, congestion-control/PoW negotiation, multi-port service routing, and full ns server-descriptor hydration.
  • Known path-bias limits: §7.3 scaling and §7.4 rate tiers are implemented; the §7.2 END-echo probe and pb_dropguards=1 remain explicitly unsupported and fail closed.
  • Vulnerability disclosure: SECURITY.md.

Current functionality

  • TLS/OR link negotiation, relay CERTS authentication and expected identity pins.
  • Tor cell framing, ntor circuit construction, per-hop cryptography, streams, SENDME flow control and deadlines. Circuit ownership now has one idempotent teardown path, random collision-checked IDs, context/deadline-aware build and stream APIs, and per-connection circuit/stream/queue ceilings.
  • Authenticated consensus download, microdescriptor hydration, refresh, connection-owned refresh recovery after channel loss, crash-consistent atomic cache replacement, and separate raw/hydrated cache files. The Tor cache backend requires an explicit caller-owned directory.
  • pkg/embed: DefaultOptions, caller-controlled bootstrap/guard dialers and storage, persistent caller-owned public guard state (Options.Guards, one guard choice shared across exit and onion circuit construction; construction fails closed without it), TCP/HTTPS/onion Dial, circuit pooling and lifecycle management. A privacy-safe optional log writer and Stats snapshot expose bootstrap, guard, bridge and listener failure classes without destination labels.
  • Onion-v3 descriptor validation, introduction/rendezvous, service publication, deterministic SRV/period rollover, bounded maintenance backoff and restart revision anti-rollback.
  • A Tor-backed net.Listener for onion services, without a local listening socket. Service identities and durable descriptor revision allocation belong to callers.
  • Transport adapters for meek, webtunnel, Snowflake and obfs4. Meek and webtunnel honor context cancellation; obfs4 requires a pinned RSA identity and has local server-handshake evidence. The link handshake bounds itself with context and tolerates ENOTSUP deadlines, so the former obfs4 deadline incompatibility is resolved; a live public obfs4 bootstrap is the remaining evidence step.

See the embedding guide, runnable examples, and detailed implementation status and remaining work.

The published tree documents current behavior through this file, SECURITY.md, pkg/embed/README.md, and pkg/hs/IMPLEMENTATION_STATUS.md. Historical results belong only to the trees on which they were produced; rerun the current validation commands before relying on them.

Architecture

Area Responsibility
Root conn*.go OR/TLS handshake, relay authentication, cell I/O and connection lifetime
Root circuit*.go Circuit construction, relay encryption/control, routing and service-side acceptance
Root stream*.go Tor-backed net.Conn, buffering, deadlines, flow control and close behavior
pkg/cells, pkg/lspec Bounded wire encoding/decoding for link/relay cells and link specifiers
pkg/crypto, internal/hops, internal/window Ordinary circuit crypto, per-hop state and flow-control accounting
pkg/common, pkg/parsers Directory models, consensus signature/quorum verification, text/JSON/microdescriptor parsing
Root bootstraping.go, helpers.go Directory download, hash-checked hydration and consensus refresh
pkg/storage Caller-selected in-memory or on-disk public directory caches
pkg/path Weighted relay selection, family/identity/subnet constraints, persistent public-default guard manager (pkg/path/guards.go)
pkg/hs/onion, pkg/hs/crypto, pkg/hs/desc Onion address checks, key blinding, HS-ntor, signed/encrypted descriptors
pkg/hs, pkg/hs/capi Client/service orchestration and integration with real circuits
pkg/embed Application-facing Dial/HTTP/Listen APIs and resource ownership
pkg/transports Transport adapters, independent of application network policy
internal/tests Opt-in public-network interoperability tests
torspec, tor-source Local protocol and C Tor references; not runtime dependencies

The implementation keeps ordinary circuit state separate from HS end-to-end AES-256/SHA3-256 state. Descriptor fetching/publication uses directory streams on dedicated circuits. A service's accepted stream is delivered directly to the application rather than forwarded to a local TCP server.

Consensus formats

The normal ns consensus and microdesc consensus are distinct signed formats. Neither contains every relay key by itself. Embedded bootstrap uses the microdesc consensus plus matching microdescriptors.

  • cached-consensus: original signed ns text.
  • cached-microdesc-consensus: original signed microdesc text.
  • gonion-consensus.json: hydrated Gonion snapshot with original signed and descriptor bytes, reverified before use.

See the cache and ownership contract.

Validation

go test ./...
go vet ./...
go test -race ./...

For weak local machines use go test -short ./...; full, race, Chutney, and benchmark validation belongs to scheduled CI.

The default suite is offline. Opt-in tests have exercised public exit TCP/HTTPS, the Tor Project's onion website, and Gonion service publication with both a Gonion client and an independent C Tor client. The service test checks 1 MiB in each direction and listener/client close semantics. Commands, dependencies and limits are documented in the status report.

Public-network tests are not availability guarantees. They do not replace fixed protocol vectors, negative tests, fuzzing, controlled-network testing or audit.

Development priorities

  1. Review the implemented persistent guard state/persistence and the integrated path-bias accounting. §7.3 scaling and §7.4 rate tiers are implemented; the §7.2 END-echo probe and pb_dropguards=1 remain explicitly unsupported.
  2. Rerun controlled Chutney/current C Tor interoperability for surface Dial, onion Dial, service publication, refresh and the new SRV/period rollover and maintenance-backoff flows.
  3. Review the immutable directory trust boundary and expand CERTS/parser negative and concurrency tests.
  4. Record benchmark baselines and profiles, then optimize only measured costs.
  5. Add unsupported capabilities only with their corresponding spec review and interoperability tests: bridge-aware guard state instances, IPv6 streams, normal consensus server-descriptor hydration and high-level authorized services.

Correctness, explicit validation and readable/auditable code take priority over speculative optimizations. Performance and fingerprinting claims require measurements; being embedded is not evidence of either.

Protocol source of truth: Tor specifications.