An open API service indexing awesome lists of open source software.

https://github.com/pratik-codes/rust-forward-proxy

A high-performance HTTP/HTTPS forward proxy server written in Rust with full tunneling support and comprehensive logging.
https://github.com/pratik-codes/rust-forward-proxy

Last synced: 7 months ago
JSON representation

A high-performance HTTP/HTTPS forward proxy server written in Rust with full tunneling support and comprehensive logging.

Awesome Lists containing this project

README

          

# ๐Ÿš€ Rust Forward Proxy

[![Rust](https://img.shields.io/badge/rust-1.70+-blue.svg)](https://www.rust-lang.org)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg)]()

A **high-performance HTTP/HTTPS forward proxy server** written in Rust with advanced TLS interception, certificate management, and comprehensive logging capabilities.

## โœจ Features

### ๐Ÿ”’ **Complete HTTPS Interception**
- **TLS Termination & Re-encryption** - Full decrypt/inspect/re-encrypt capability
- **Certificate Generation** - Automatic domain certificate creation with CA signing
- **Certificate Caching** - Memory & Redis backends for 25-30x performance improvement
- **Multiple Certificate Modes** - Support for rootCA and Securly CA certificates

### ๐ŸŒ **Full Proxy Capabilities**
- **HTTP Request Interception** - Complete request/response logging and modification
- **HTTPS CONNECT Tunneling** - Standards-compliant tunnel for encrypted traffic
- **Dual Server Mode** - Simultaneous HTTP (8080) and HTTPS (8443) operation
- **Production Logging** - Clean INFO level for production, detailed DEBUG for development

### โšก **High Performance**
- **Async Architecture** - Built on Tokio/Hyper for maximum throughput
- **Connection Pooling** - Efficient upstream connection management
- **Smart Body Handling** - Optimized request/response body processing
- **Certificate Caching** - Sub-millisecond certificate retrieval

### ๐Ÿ”ง **Developer Experience**
- **Comprehensive CLI Tools** - Certificate generation, validation, and server management
- **Flexible Configuration** - Environment variables + configuration files
- **Docker Support** - Production-ready containerization with Redis
- **Extensive Documentation** - Complete guides for setup, deployment, and usage

## ๐Ÿš€ Quick Start

### **Simple HTTP Proxy**
```bash
# Start basic HTTP proxy
make dev

# Test HTTP request
curl -x http://127.0.0.1:8080 http://httpbin.org/get

# Test HTTPS tunneling
curl -x http://127.0.0.1:8080 https://httpbin.org/get
```

### **HTTPS Interception (See Encrypted Content)**
```bash
# Setup root CA certificate for browser
make setup-ca

# Start HTTPS interception proxy
make dev

# Configure browser proxy: 127.0.0.1:8080
# Install rootCA.crt in browser (see BROWSER_SETUP.md)
# Browse to https://httpbin.org/get
# Check proxy logs - you'll see complete HTTPS content!
```

### **Production Deployment**
```bash
# Production with Docker + Redis caching
make prod-docker

# Local production mode
make prod
```

## ๐Ÿ“ Project Structure

```
rust-forward-proxy/
โ”œโ”€โ”€ ๐Ÿ“ฆ src/ # Core implementation
โ”‚ โ”œโ”€โ”€ ๐ŸŒ proxy/ # HTTP/HTTPS proxy logic
โ”‚ โ”‚ โ”œโ”€โ”€ server.rs # Main server implementation
โ”‚ โ”‚ โ”œโ”€โ”€ http_client.rs # Optimized upstream client
โ”‚ โ”‚ โ””โ”€โ”€ streaming.rs # Smart body handling
โ”‚ โ”œโ”€โ”€ ๐Ÿ”’ tls/ # TLS & certificate management
โ”‚ โ”‚ โ”œโ”€โ”€ server.rs # HTTPS termination server
โ”‚ โ”‚ โ”œโ”€โ”€ cert_gen.rs # Certificate generation
โ”‚ โ”‚ โ”œโ”€โ”€ cache.rs # Certificate caching (Memory/Redis)
โ”‚ โ”‚ โ””โ”€โ”€ config.rs # TLS configuration
โ”‚ โ”œโ”€โ”€ โš™๏ธ config/ # Configuration management
โ”‚ โ”œโ”€โ”€ ๐Ÿ“‹ logging/ # Production-grade logging
โ”‚ โ”œโ”€โ”€ ๐Ÿ› ๏ธ utils/ # HTTP/URL/Time utilities
โ”‚ โ”œโ”€โ”€ ๐ŸŽฎ cli/ # Command-line interface
โ”‚ โ””โ”€โ”€ ๐Ÿ“Š models/ # Data structures
โ”œโ”€โ”€ ๐Ÿ“š docs/ # Comprehensive documentation
โ”œโ”€โ”€ ๐Ÿณ docker-compose.yml # Docker deployment
โ”œโ”€โ”€ ๐Ÿ“‹ Makefile # Development commands
โ””โ”€โ”€ ๐Ÿงช scripts/ # Testing & setup scripts
```

## ๐ŸŽฏ How It Works

### **HTTP Request Flow**
```
Client โ†’ [HTTP Proxy:8080] โ†’ [Full Interception] โ†’ [Log Everything] โ†’ Upstream
โ†– โ†™
โ†– [Response Logging] โ†™
โ†– โ†™
โ†–โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Clean Response โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ†™
```

### **HTTPS Interception Flow**
```
Client โ†’ [HTTPS Proxy:8443] โ†’ [TLS Terminate] โ†’ [Decrypt] โ†’ [Log Content] โ†’ [Re-encrypt] โ†’ Upstream
โ†– โ†™
โ†– [Certificate Cache] โ†™
โ†– โ†™
โ†–โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Encrypted Response โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ†™
```

### **Certificate Generation Flow**
```
Request for domain.com
โ†“
[Cache Check] โ†’ Hit: Return cached cert (0ms)
โ†“
Miss: Generate new cert (5-10ms)
โ†“
[Sign with CA] โ†’ Cache for 24h โ†’ Return cert
```

## ๐Ÿ”ง Configuration

### **Certificate Modes**
```bash
# Default mode (uses rootCA)
make dev

# Securly CA mode
CERT=securly make dev
# or
make dev-securly
```

### **Environment Variables**
```bash
# Proxy Configuration
PROXY_LISTEN_ADDR=127.0.0.1:8080
HTTPS_LISTEN_ADDR=127.0.0.1:8443

# TLS Configuration
TLS_ENABLED=true
TLS_INTERCEPTION_ENABLED=true
TLS_CA_CERT_PATH=ca-certs/rootCA.crt
TLS_CA_KEY_PATH=ca-certs/rootCA.key

# Logging
RUST_LOG=info # Clean production logs
RUST_LOG=debug # Verbose development logs

# Redis (for certificate caching)
REDIS_URL=redis://redis:6379
```

## ๐Ÿ“– Documentation

### **๐Ÿš€ Getting Started**
- **[Quick Setup Guide](docs/SETUP.md)** - Get running in 5 minutes
- **[Browser Configuration](docs/BROWSER_SETUP.md)** - Setup HTTPS interception
- **[Certificate Management](docs/CERTIFICATES.md)** - Complete certificate guide

### **๐Ÿ—๏ธ Architecture & Implementation**
- **[Architecture Overview](docs/architecture.md)** - System design and flow diagrams
- **[TLS Implementation](docs/CERTIFICATES.md)** - HTTPS termination and certificate handling
- **[Performance Optimization](docs/performance.md)** - Caching, pooling, and benchmarks

### **๐Ÿš€ Deployment & Operations**
- **[Deployment Guide](docs/deployment.md)** - Docker, Kubernetes, cloud deployment
- **[Configuration Reference](docs/CONFIGURATION.md)** - Complete config documentation
- **[CLI Reference](docs/CONFIGURATION.md)** - CLI commands and configuration options

## ๐Ÿงช Testing

```bash
# Test basic functionality
make test

# Test HTTPS interception
make test-intercept

# Test Docker deployment
make test-docker

# Run all tests
make test-all
```

## ๐ŸŽฏ Use Cases

### **๐Ÿ” Development & Debugging**
- **API Development** - See exactly what your applications send/receive
- **Security Testing** - Analyze encrypted traffic for vulnerabilities
- **Network Debugging** - Troubleshoot mysterious network issues

### **๐Ÿ›ก๏ธ Security & Monitoring**
- **Traffic Analysis** - Monitor and log all HTTP/HTTPS traffic
- **Content Filtering** - Inspect and potentially modify requests/responses
- **Compliance Auditing** - Log all network communications

### **โšก Performance Testing**
- **Load Testing** - Proxy traffic for performance analysis
- **Caching Analysis** - Understand application caching behavior
- **Bandwidth Monitoring** - Track data usage and patterns

## ๐Ÿš€ Performance

### **Benchmarks**
- **HTTP Throughput**: 1000+ requests/second
- **HTTPS Latency**: +2-5ms overhead for interception
- **Certificate Generation**: 5-10ms first request, <1ms cached
- **Memory Usage**: ~10-50MB depending on load
- **Concurrent Connections**: 1000+ simultaneous HTTPS sessions

### **Certificate Caching Performance**
```
Without Caching: 25-30ms per HTTPS request
With Caching: <1ms per HTTPS request
Performance Gain: 25-30x improvement
```

## ๐Ÿค Contributing

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## ๐Ÿ“ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ™ Acknowledgments

- Built with [Rust](https://www.rust-lang.org/) and [Tokio](https://tokio.rs/)
- Uses [Hyper](https://hyper.rs/) for HTTP implementation
- TLS powered by [rustls](https://github.com/rustls/rustls)
- Certificate generation via [rcgen](https://github.com/est31/rcgen)

---

## ๐ŸŽ‰ Ready to Start?

```bash
# Clone and run
git clone
cd rust-forward-proxy
make dev

# Start intercepting HTTP traffic in seconds!
curl -x http://127.0.0.1:8080 http://httpbin.org/get
```

**๐Ÿ”ฅ For HTTPS interception, see our [Browser Setup Guide](docs/BROWSER_SETUP.md) to configure certificate trust!**