hypertor 0.2.2

Tor HTTP client and onion service library with Python bindings
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
---
layout: single
title: "hypertor"
excerpt: "The Tor network library for Rust and Python"
header:
  overlay_color: "#16213e"
  overlay_filter: "0.7"
classes: wide
sidebar: false
author_profile: false
---

<style>
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin: 2rem 0;
}
.feature-card {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  border: 1px solid #0f3460;
  border-radius: 12px;
  padding: 1.5rem;
  transition: transform 0.2s, box-shadow 0.2s;
}
.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 25px rgba(0, 255, 136, 0.15);
}
.feature-card h3 {
  color: #00ff88;
  margin-top: 0;
  font-size: 1.1rem;
}
.feature-card p {
  color: #a0a0a0;
  margin-bottom: 0;
  font-size: 0.95rem;
}
.hero-section {
  text-align: center;
  padding: 2rem 0 3rem;
}
.hero-section h1 {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}
.hero-section .tagline {
  font-size: 1.3rem;
  color: #888;
  margin-bottom: 2rem;
}
.cta-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}
.cta-buttons a {
  display: inline-block;
  padding: 0.8rem 1.8rem;
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s;
}
.cta-primary {
  background: #00ff88;
  color: #1a1a2e !important;
}
.cta-primary:hover {
  background: #00cc6a;
  transform: translateY(-2px);
}
.cta-secondary {
  background: transparent;
  border: 2px solid #00ff88;
  color: #00ff88 !important;
}
.cta-secondary:hover {
  background: rgba(0, 255, 136, 0.1);
}
.code-section {
  background: #0d1117;
  border-radius: 12px;
  padding: 1.5rem;
  margin: 2rem 0;
  border: 1px solid #30363d;
}
.code-section h4 {
  color: #00ff88;
  margin-top: 0;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.comparison-table {
  width: 100%;
  border-collapse: collapse;
  margin: 2rem 0;
}
.comparison-table th, .comparison-table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid #30363d;
}
.comparison-table th {
  background: #16213e;
  color: #00ff88;
}
.comparison-table tr:hover {
  background: rgba(0, 255, 136, 0.05);
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin: 2rem 0;
  text-align: center;
}
.stat-item {
  background: #16213e;
  padding: 1.5rem;
  border-radius: 8px;
  border: 1px solid #0f3460;
}
.stat-item .number {
  font-size: 2rem;
  font-weight: 700;
  color: #00ff88;
}
.stat-item .label {
  color: #888;
  font-size: 0.9rem;
}
.use-case-section {
  background: linear-gradient(135deg, #0d1117 0%, #161b22 100%);
  border-radius: 12px;
  padding: 2rem;
  margin: 2rem 0;
  border: 1px solid #30363d;
}
.use-case-section h3 {
  color: #00ff88;
  margin-top: 0;
}
.use-case-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.use-case-item {
  padding: 0.75rem 1rem;
  background: rgba(0, 255, 136, 0.05);
  border-radius: 8px;
  border-left: 3px solid #00ff88;
}
.arch-diagram {
  background: #0d1117;
  border-radius: 12px;
  padding: 1rem;
  margin: 2rem 0;
  border: 1px solid #30363d;
  overflow-x: auto;
}
.arch-diagram pre {
  margin: 0;
  color: #c9d1d9;
  font-size: 0.85rem;
}
@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .hero-section h1 {
    font-size: 2rem;
  }
}
</style>

<div class="hero-section">
  <h1>πŸ§… hypertor</h1>
  <p class="tagline">The Tor network library for Rust and Python</p>
  <p style="color: #666; max-width: 650px; margin: 0 auto 2rem;">
    Consume AND host onion services with the simplicity of <code>reqwest</code> and <code>axum</code>. 
    State-of-the-art security features including PoW DoS protection, Vanguards, and traffic analysis defense.
  </p>
  <div class="cta-buttons">
    <a href="{{ '/docs/quickstart/' | relative_url }}" class="cta-primary">Get Started</a>
    <a href="https://github.com/hupe1980/hypertor" class="cta-secondary">GitHub</a>
  </div>
</div>

<div class="stats-grid">
  <div class="stat-item">
    <div class="number">27K+</div>
    <div class="label">Lines of Code</div>
  </div>
  <div class="stat-item">
    <div class="number">51</div>
    <div class="label">Modules</div>
  </div>
  <div class="stat-item">
    <div class="number">292</div>
    <div class="label">Tests</div>
  </div>
  <div class="stat-item">
    <div class="number">71</div>
    <div class="label">Benchmarks</div>
  </div>
</div>

---

## Why hypertor?

Traditional Tor libraries force you to choose: either a complex low-level API for security researchers, or a simplified wrapper that sacrifices control. **hypertor** provides both: a batteries-included experience for common tasks, with full access to advanced security features when you need them.

<div class="use-case-section">
  <h3>🎯 Built For</h3>
  <div class="use-case-grid">
    <div class="use-case-item">Security Researchers</div>
    <div class="use-case-item">Penetration Testers</div>
    <div class="use-case-item">Privacy Applications</div>
    <div class="use-case-item">Anonymous APIs</div>
    <div class="use-case-item">Whistleblower Platforms</div>
    <div class="use-case-item">Censorship Circumvention</div>
    <div class="use-case-item">Secure Communication</div>
    <div class="use-case-item">Onion Service Hosting</div>
  </div>
</div>

---

## Two Libraries in One

<table class="comparison-table">
  <tr>
    <th>Component</th>
    <th>Purpose</th>
    <th>Similar To</th>
  </tr>
  <tr>
    <td><strong>TorClient</strong></td>
    <td>Make HTTP requests over Tor anonymously</td>
    <td><code>reqwest</code>, <code>httpx</code></td>
  </tr>
  <tr>
    <td><strong>OnionApp</strong></td>
    <td>Host .onion services with routing</td>
    <td><code>axum</code>, <code>FastAPI</code></td>
  </tr>
</table>

---

## Quick Examples

<div class="code-section" markdown="1">
<h4>Rust β€” Anonymous Client</h4>

```rust
use hypertor::{TorClient, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let client = TorClient::new().await?;
    
    let resp = client
        .get("http://duckduckgogg42xjoc72x3sjasowoarfbgcmvfimaftt6twagswzczad.onion")?
        .send()
        .await?;
    
    println!("Status: {}", resp.status());
    Ok(())
}
```
</div>

<div class="code-section" markdown="1">
<h4>Rust β€” Onion Service</h4>

```rust
use hypertor::{OnionApp, ServeResponse};

#[tokio::main]
async fn main() -> hypertor::Result<()> {
    let app = OnionApp::new()
        .get("/", || async { ServeResponse::text("Hello from .onion!") })
        .get("/api/status", || async {
            ServeResponse::json(&serde_json::json!({"status": "operational"}))
        });
    
    let addr = app.run().await?;
    println!("πŸ§… Live at: {}", addr);
    Ok(())
}
```
</div>

<div class="code-section" markdown="1">
<h4>Python β€” httpx-style Client</h4>

```python
import asyncio
from hypertor import AsyncClient

async def main():
    async with AsyncClient(timeout=60) as client:
        resp = await client.get("https://check.torproject.org/api/ip")
        print(f"Tor IP: {resp.json().get('IP')}")

asyncio.run(main())
```
</div>

<div class="code-section" markdown="1">
<h4>Python β€” FastAPI-style Server</h4>

```python
from hypertor import OnionApp

app = OnionApp()

@app.get("/")
async def home():
    return "Welcome to my .onion service!"

@app.post("/api/echo")
async def echo(request):
    data = await request.json()
    return {"received": data}

if __name__ == "__main__":
    app.run()  # πŸ§… Live at: xyz...xyz.onion
```
</div>

---

## Security Features

<div class="feature-grid">
  <div class="feature-card">
    <h3>πŸ›‘οΈ PoW DoS Protection</h3>
    <p>Tor 0.4.8+ Proof-of-Work defense with adaptive difficulty automatically protects your service from DDoS attacks without affecting legitimate users.</p>
  </div>
  <div class="feature-card">
    <h3>πŸ” Client Authorization</h3>
    <p>Basic & Stealth authorization modes with x25519 key derivation. Restrict access to authorized clients while hiding service existence from others.</p>
  </div>
  <div class="feature-card">
    <h3>πŸ“Š Vanguards Protection</h3>
    <p>Vanguards-lite guard relay protection prevents circuit enumeration attacks that could reveal your service's location.</p>
  </div>
  <div class="feature-card">
    <h3>🎭 Traffic Analysis Defense</h3>
    <p>WTF-PAD, Tamaraw padding, and circuit padding machines resist website fingerprinting and correlation attacks.</p>
  </div>
  <div class="feature-card">
    <h3>πŸ” Leak Detection</h3>
    <p>Comprehensive security scanner detects DNS leaks, header fingerprinting, timing patterns, and content leaks before they compromise anonymity.</p>
  </div>
  <div class="feature-card">
    <h3>⏱️ Timing Attack Protection</h3>
    <p>Built-in timing correlation defense with jitter injection and pattern detection to prevent traffic analysis attacks.</p>
  </div>
  <div class="feature-card">
    <h3>⚑ Congestion Control</h3>
    <p>Vegas RTT-based congestion control (Tor Proposal 324) provides optimal throughput without overwhelming the network.</p>
  </div>
  <div class="feature-card">
    <h3>πŸ”Œ WebSocket & gRPC</h3>
    <p>Real-time bidirectional WebSocket communication and gRPC services over Tor for modern application architectures.</p>
  </div>
  <div class="feature-card">
    <h3>πŸŒ‰ Bridge Support</h3>
    <p>Full support for obfs4, snowflake, meek, and webtunnel pluggable transports for censorship circumvention.</p>
  </div>
  <div class="feature-card">
    <h3>πŸ“ˆ Prometheus Metrics</h3>
    <p>Production-ready observability with counters, gauges, histograms, and automatic /metrics endpoint for monitoring.</p>
  </div>
</div>

---

## Security Presets

Choose your security level based on your threat model:

```rust
use hypertor::SecurityConfig;

// Basic Tor protection (fastest)
SecurityConfig::standard()

// PoW + Vanguards (recommended for most)
SecurityConfig::enhanced()

// Full Vanguards + Client Authorization
SecurityConfig::maximum()

// Stealth Auth + Max PoW + Tamaraw padding
SecurityConfig::paranoid()
```

| Preset | PoW | Vanguards | Client Auth | Traffic Padding | Use Case |
|--------|-----|-----------|-------------|-----------------|----------|
| `standard` | ❌ | ❌ | ❌ | ❌ | Development, low-risk |
| `enhanced` | βœ… | lite | ❌ | ❌ | Most production services |
| `maximum` | βœ… | full | basic | ❌ | High-value targets |
| `paranoid` | βœ… max | full | stealth | Tamaraw | State-level adversaries |

---

## Architecture

<div class="arch-diagram">
<pre>
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         YOUR APPLICATION                             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   TorClient            β”‚   OnionApp             β”‚   SOCKS5 Proxy    β”‚
β”‚   (consume .onion)     β”‚   (host .onion)        β”‚   (bridge tools)  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                           hypertor core                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Connection β”‚  β”‚  Privacy   β”‚  β”‚  Security  β”‚  β”‚ Observabilityβ”‚  β”‚
β”‚  β”‚  Pooling   β”‚  β”‚  Padding   β”‚  β”‚  PoW/Auth  β”‚  β”‚   Metrics    β”‚  β”‚
β”‚  β”‚   Retry    β”‚  β”‚ Vanguards  β”‚  β”‚  Analysis  β”‚  β”‚   Tracing    β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                       arti-client (Tor Protocol)                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                       Tor Network (6000+ relays)                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
</pre>
</div>

---

## Performance

| Operation | Time | Notes |
|-----------|------|-------|
| Circuit establishment | ~2-4s | Initial connection |
| HTTP request (warm) | ~200-500ms | With pooled circuit |
| OnionApp startup | ~3-5s | Service registration |
| Request throughput | ~50-100 req/s | Depends on circuit |

All benchmarks run with `cargo bench` β€” 71 benchmarks covering all major operations.

---

## Installation

### Rust

```toml
[dependencies]
hypertor = "0.3"
tokio = { version = "1", features = ["full"] }
```

### Python

```bash
pip install hypertor
```

---

## Documentation

<div class="feature-grid">
  <div class="feature-card">
    <h3><a href="{{ '/docs/quickstart/' | relative_url }}">πŸ“š Quick Start</a></h3>
    <p>Get up and running in 5 minutes with basic examples for both client and server usage.</p>
  </div>
  <div class="feature-card">
    <h3><a href="{{ '/docs/client/' | relative_url }}">🌐 TorClient Guide</a></h3>
    <p>Deep dive into the HTTP client: requests, authentication, streaming, and advanced options.</p>
  </div>
  <div class="feature-card">
    <h3><a href="{{ '/docs/server/' | relative_url }}">πŸ§… OnionApp Guide</a></h3>
    <p>Build and deploy onion services with routing, middleware, and security configuration.</p>
  </div>
  <div class="feature-card">
    <h3><a href="{{ '/docs/security/' | relative_url }}">πŸ”’ Security Guide</a></h3>
    <p>Configure PoW, Vanguards, client authorization, and traffic analysis defenses.</p>
  </div>
</div>

---

<div style="text-align: center; margin: 3rem 0;">
  <a href="{{ '/docs/quickstart/' | relative_url }}" class="cta-primary" style="font-size: 1.1rem; padding: 1rem 2rem;">
    πŸš€ Get Started Now
  </a>
</div>

---

## ⚠️ Disclaimer

<div style="background: linear-gradient(135deg, #2d1b1b 0%, #1a1a2e 100%); border: 1px solid #5c3a3a; border-radius: 12px; padding: 1.5rem; margin: 2rem 0;">

**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 <a href="{{ '/docs/security/' | relative_url }}">Security Guide</a> before deploying in production.

</div>