Skip to content

Commit 1094314

Browse files
authored
Merge pull request #97 from hatoo/add-claude-md
Add CLAUDE.md documentation for Claude Code integration
2 parents d529169 + a793cd4 commit 1094314

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

CLAUDE.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a Rust HTTP MITM (Man-in-the-Middle) proxy library designed to be a backend for applications like Burp Proxy. It enables inspection of HTTP/HTTPS traffic by dynamically generating TLS certificates.
8+
9+
### Key Features
10+
- HTTP/HTTPS traffic interception via on-the-fly certificate signing
11+
- WebSocket support (raw traffic only)
12+
- Server-Sent Events support
13+
- Certificate caching with moka
14+
- Support for both native-tls and rustls TLS backends
15+
16+
## Development Commands
17+
18+
### Building and Testing
19+
```bash
20+
# Build the project
21+
cargo build
22+
23+
# Run tests
24+
cargo test
25+
26+
# Build documentation
27+
cargo doc --open
28+
29+
# Run clippy for linting
30+
cargo clippy
31+
32+
# Format code
33+
cargo fmt
34+
35+
# Build examples
36+
cargo build --examples
37+
38+
# Run a specific example (proxy server)
39+
cargo run --example proxy
40+
41+
# Run with specific features
42+
cargo build --no-default-features --features rustls-client
43+
```
44+
45+
### Testing with Different TLS Backends
46+
The crate supports two TLS client backends:
47+
- `native-tls-client` (default)
48+
- `rustls-client`
49+
50+
Only one can be enabled at a time due to compile-time checks.
51+
52+
## Architecture
53+
54+
### Core Components
55+
56+
**MitmProxy** (`src/lib.rs`): The main proxy server struct that handles:
57+
- HTTP CONNECT method tunneling for HTTPS
58+
- Certificate generation and caching
59+
- Service wrapping for request/response interception
60+
- Both HTTP/1.1 and HTTP/2 support with ALPN negotiation
61+
62+
**DefaultClient** (`src/default_client.rs`): HTTP client implementation with:
63+
- Automatic TLS connection handling
64+
- HTTP version negotiation (HTTP/1.1 vs HTTP/2)
65+
- WebSocket upgrade support
66+
- Connection pooling preparation (TODO)
67+
68+
**TLS Certificate Generation** (`src/tls.rs`):
69+
- Dynamic certificate creation signed by a root CA
70+
- Certificate serialization to DER format
71+
- Integration with rcgen for certificate generation
72+
73+
### Request Flow
74+
75+
1. **HTTP Requests**: Passed directly to the user-provided service
76+
2. **HTTPS Requests** (CONNECT method):
77+
- Proxy establishes TLS connection with dynamically generated certificate
78+
- Decrypts HTTPS traffic for inspection
79+
- Re-encrypts and forwards to destination
80+
- Falls back to TCP tunneling if no root certificate provided
81+
82+
### Certificate Management
83+
84+
The proxy can operate in two modes:
85+
- **With Root Certificate**: Full HTTPS inspection by generating fake certificates
86+
- **Without Root Certificate**: Simple TCP tunneling for HTTPS (no inspection)
87+
88+
Certificate caching is handled via moka::sync::Cache with hostname as the key.
89+
90+
## Development Notes
91+
92+
### Feature Flags
93+
- `native-tls-client`: Uses native-tls for TLS connections (default)
94+
- `rustls-client`: Uses rustls for TLS connections
95+
- Cannot enable both simultaneously (compile error)
96+
97+
### Testing Setup
98+
Tests use incremental port allocation starting from 3666 to avoid conflicts. The test suite includes:
99+
- HTTP/HTTPS proxy functionality
100+
- WebSocket proxying
101+
- Server-Sent Events
102+
- Certificate generation and validation
103+
104+
### Examples
105+
The `examples/` directory contains practical usage patterns:
106+
- `proxy.rs`: Basic HTTP/HTTPS proxy with certificate generation
107+
- `https.rs`: HTTPS-specific proxy setup
108+
- `websocket.rs`: WebSocket proxying demonstration
109+
- `reqwest_proxy.rs`: Integration with reqwest HTTP client
110+
- `dev_proxy.rs`: Development/debugging proxy setup

0 commit comments

Comments
 (0)