π§ hypertor
The Tor network library for Rust and Python β consume AND host onion services with the simplicity of reqwest and axum.
Why hypertor?
Most Tor libraries only do one thing: make requests. hypertor does both:
| Component | Purpose | Similar To |
|---|---|---|
| TorClient | Make HTTP requests over Tor | reqwest, httpx |
| OnionService | Host .onion services | axum, FastAPI |
Production-Ready Security β All features wired to real arti APIs:
| Feature | Purpose | arti API |
|---|---|---|
| π‘οΈ Vanguards | Guard discovery protection | VanguardConfigBuilder::mode() |
| β‘ Proof-of-Work | DoS protection (Equi-X) | OnionServiceConfigBuilder::enable_pow() |
| π¦ Rate Limiting | Intro point flooding protection | rate_limit_at_intro() |
| π Client Auth | Restricted service discovery | RestrictedDiscoveryConfigBuilder |
| π Bridges | Censorship circumvention | TorClientConfigBuilder::bridges() |
| π Pluggable Transports | Traffic obfuscation | TransportConfigBuilder |
Quick Start
Rust β Client
use ;
async
Rust β Server
use ;
async
Python β Client
# Check our Tor IP
= await
# Access an onion service
= await
Python β Server (FastAPI-style)
=
return
= await
return
return
# π§
Service live at: xyz...xyz.onion
Installation
Rust
[]
= "0.4"
= { = "1", = ["full"] }
Python
TLS Backends
hypertor defaults to rustls for security reasons:
| Backend | Default | Security | Notes |
|---|---|---|---|
rustls |
β | Best | Consistent TLS fingerprint, pure Rust, memory-safe |
native-tls |
Good | Uses OS TLS stack, platform-specific fingerprints |
Why rustls is the default
For anonymity-focused applications, TLS fingerprinting is a real threat. Different TLS libraries produce different fingerprints based on cipher suite ordering, extensions, and timing. Using native-tls means:
- Linux: OpenSSL fingerprint
- macOS: SecureTransport fingerprint (also has Tor stream compatibility issues)
- Windows: SChannel fingerprint
This leaks your operating system to any observer. With rustls, you get the same fingerprint on all platforms, making it harder to distinguish users.
Additionally, rustls is:
- Memory-safe: Pure Rust, no C library vulnerabilities
- Auditable: Easier to verify for security
- Isolated: Not affected by compromised system CA stores
If you need native-tls for specific compatibility:
[]
= { = "0.4", = false, = ["client", "native-tls"] }
Features
π TorClient β HTTP Client
use ;
use Duration;
// Builder pattern for full control
let client = builder
.timeout
.max_connections
.isolation // Fresh circuit per request
.follow_redirects
.build
.await?;
// POST with typed JSON
let resp = client.post?
.json
.send.await?;
// Query parameters
let resp = client.get?
.query
.send.await?;
π§ OnionApp β Hidden Service Framework
use ;
use Duration;
let config = new
.with_port
.with_timeout
.with_key_path; // Persist .onion address
let app = with_config
.get
.post
.route;
let addr = app.run.await?; // Returns "abc...xyz.onion"
π Security Configuration
hypertor provides security presets that configure real arti hardening features:
use ;
use OnionServiceConfig;
// Security presets for onion services
let standard = standard; // Basic protection
let enhanced = enhanced; // PoW + rate limiting
let maximum = maximum; // Full hardening
// Or configure manually with fluent API
let config = new
.with_pow // Proof-of-Work (Equi-X)
.pow_queue_depth // Queue depth
.rate_limit_at_intro // Rate: 10/s, burst: 20
.max_streams_per_circuit // Stream limit
.vanguards_full // Full vanguards
.num_intro_points; // High availability
π Censorship Circumvention (China, Iran, Russia)
use ;
let client = new
// Multiple bridges for redundancy
.bridge
.bridge
// Pluggable transport binary
.transport
// Full vanguards for hostile networks
.vanguards
.build
.await?;
π Stream Isolation
Keep different activities on separate Tor circuits:
use ;
let client = new.await?;
// Create isolated sessions
let banking = new;
let browsing = new;
// These use the same circuit (banking identity)
client.get?.isolation.send.await?;
client.get?.isolation.send.await?;
// This uses a different circuit (browsing identity)
client.get?.isolation.send.await?;
β‘ Resilience Features
use ;
// Circuit breaker - fail fast when service is down
let breaker = new;
// Adaptive retry - learns optimal behavior
let retry = new;
// Rate limiting
let limiter = new; // 100 req/sec
π Observability
use ;
let metrics = new;
// Record operations
metrics.record_request;
metrics.record_circuit_build;
// Export Prometheus format
let prometheus_text = metrics.export;
// # HELP hypertor_http_requests_total Total HTTP requests
// # TYPE hypertor_http_requests_total counter
// hypertor_http_requests_total{method="GET",status="200"} 1
π Bridge Support (Censorship Circumvention)
use ;
// Configure bridges and transports via builder
let client = new
.bridge
.transport
.vanguards
.build
.await?;
οΏ½ SOCKS5 Proxy
Run a local SOCKS5 proxy to route ANY application through Tor:
use ;
use ;
// Start SOCKS5 proxy on localhost:9050
let proxy = with_defaults;
proxy.run.await?; // Runs on 127.0.0.1:9050
Then use with any SOCKS5-compatible tool:
# curl
# Python requests
)
# wget, git, ssh, browsers...
οΏ½π WebSocket over Tor
use TorWebSocket;
// Connect to WebSocket over Tor
let mut ws = connect.await?;
// Send and receive messages
ws.send_text.await?;
let msg = ws.recv.await?;
π‘ HTTP/2 Support
use ;
// HTTP/2 multiplexing over Tor
let mut conn = client;
let stream_id = conn.create_stream?;
conn.send_headers?;
conn.send_data?;
Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β YOUR APPLICATION β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β TorClient β OnionService β OnionApp (serve) β
β (HTTP over Tor) β (host .onion) β (axum-like API) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β hypertor core β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββββββββββ β
β β Circuits β β Security β βResilienceβ β Observability β β
β β Pooling β β Vanguardsβ β Retry β β Metrics/Tracing β β
β β Isolationβ β PoW/Auth β β Breaker β β Health Checks β β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β arti-client 0.38 (Tor) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Module Overview
| Category | Modules |
|---|---|
| Core | client, serve, onion_service, config, error, body |
| Security | security (presets, vanguards, PoW, rate limiting) |
| Networking | pool, isolation, circuit, proxy (SOCKS5), dns, doh, tls |
| Resilience | retry, breaker, rotation, adaptive, backpressure |
| Performance | cache, dedup, ratelimit, queue, prewarm, batch |
| Protocols | http2, websocket |
| Observability | observability, prometheus, tracing, health, metrics |
Examples
Basic Client Usage
Security Features Demo
SOCKS5 Proxy
# Then: curl --socks5-hostname 127.0.0.1:9050 https://check.torproject.org/api/ip
Metrics
| Metric | Value |
|---|---|
| Source Files | 51 |
| Lines of Code | ~26,900 |
| Unit Tests | 207 |
| Integration Tests | 26 |
| Security Tests | 58 |
| Doc Tests | 1 |
| Total Tests | 292 |
| arti Version | 0.38 |
| Rust Edition | 2024 |
| MSRV | 1.85 |
Run all tests:
Security Considerations
What hypertor Protects Against
| Threat | Protection | Implementation |
|---|---|---|
| Guard discovery | Vanguards (Lite/Full) | VanguardConfigBuilder::mode() |
| DoS attacks | Proof-of-Work (Equi-X) | OnionServiceConfigBuilder::enable_pow() |
| Intro flooding | Rate limiting | rate_limit_at_intro() |
| Stream flooding | Stream limits | max_concurrent_streams_per_circuit() |
| IP exposure | Bridges + transports | TorClientConfigBuilder::bridges() |
| Unauthorized access | Client authorization | RestrictedDiscoveryConfigBuilder |
| Secret leaks | Zeroize on drop | SecretKey with ZeroizeOnDrop |
What hypertor Does NOT Protect Against
- β Application-level data leaks (your code)
- β Timing attacks from your application logic
- β Malware on your system
- β Compromised exit nodes (for clearnet access)
Development
# Run tests
# Run clippy
# Build Python wheel
# Run example
# Serve docs locally
Documentation
β οΈ Disclaimer
This software is provided for educational and research purposes only.
- No Anonymity Guarantee: While hypertor leverages the Tor network via arti, no software can guarantee complete anonymity. Your operational security practices, threat model, and usage patterns significantly impact your privacy.
- No Warranty: This software is provided "as is" without warranty of any kind. The authors are not responsible for any damages or legal consequences arising from its use.
- Legal Compliance: Users are solely responsible for ensuring their use of this software complies with all applicable laws and regulations in their jurisdiction.
- Not Endorsed by Tor Project: This is an independent project and is not affiliated with, endorsed by, or sponsored by The Tor Project.
- Security Considerations: Always review the Security Guide before deploying in production.
License
MIT License. See LICENSE for details.
Contributing
Contributions welcome! Please open issues and pull requests on GitHub.