| Crates.io | ohttp-gateway |
| lib.rs | ohttp-gateway |
| version | 0.2.5 |
| created_at | 2025-07-17 12:32:43.360131+00 |
| updated_at | 2025-07-24 11:22:36.510307+00 |
| description | A OHTTP Gateway server, meant to run between a OHTTP Relay and a target web service. |
| homepage | |
| repository | https://github.com/gruberb/ohttp-gateway |
| max_upload_size | |
| id | 1757414 |
| size | 213,335 |
An RFC 9458 compliant Oblivious HTTP gateway implementation in Rust.
This gateway implements the Oblivious HTTP protocol as defined in RFC 9458, providing a privacy-preserving HTTP proxy that prevents servers from linking requests to individual clients. The gateway acts as the decryption endpoint in the OHTTP architecture, receiving encrypted requests from relays and forwarding them to target servers.
OHTTP enables clients to make HTTP requests without revealing their identity to the target server by routing requests through a trusted relay that forwards encrypted messages to this gateway. The gateway decrypts the requests using HPKE (Hybrid Public Key Encryption), forwards them to the target server, and returns encrypted responses back through the relay.
Client -> Relay -> Gateway -> Target Server
| |
| v
| [Decrypt Request]
| [Forward to Target]
| [Encrypt Response]
| |
<--------+
This implementation serves as the Gateway component, handling:
ohttp crate with HPKE for secure request/response handlingThe gateway is configured via environment variables:
PORT="8080" # Server port
BACKEND_URL=http://localhost:8080 # Default backend URL
REQUEST_TIMEOUT=30 # Request timeout in seconds
MAX_BODY_SIZE=10485760 # Maximum request body size (10MB)
KEY_ROTATION_INTERVAL=2592000 # Key rotation interval in seconds (30 days)
KEY_RETENTION_PERIOD=604800 # Key retention period in seconds (7 days)
KEY_ROTATION_ENABLED=true # Enable automatic key rotation
SEED_SECRET_KEY=hex_encoded_32_byte_seed # Optional deterministic key generation
ALLOWED_TARGET_ORIGINS=example.com,api.example.com # Comma-separated allowed origins
TARGET_REWRITES='{"old.com":{"scheme":"https","host":"new.com"}}' # JSON target rewrites
RATE_LIMIT_RPS=100 # Requests per second limit
RATE_LIMIT_BURST=200 # Burst size for rate limiting
RATE_LIMIT_BY_IP=true # Rate limit by client IP
METRICS_ENABLED=true # Enable Prometheus metrics
GATEWAY_DEBUG=false # Enable debug mode
LOG_FORMAT=json # Log format: json or default
LOG_LEVEL=info # Log level: debug, info, warn, error
# Build the image
docker build -t ohttp-gateway .
# Run with basic configuration
docker run -p 8080:8080 \
-e BACKEND_URL=https://httpbin.org \
-e ALLOWED_TARGET_ORIGINS=httpbin.org \
ohttp-gateway
cargo build --release
# Run with environment configuration
export BACKEND_URL=https://httpbin.org
export ALLOWED_TARGET_ORIGINS=httpbin.org
./target/release/ohttp-gateway
POST /gateway - Main OHTTP request handler
message/ohttp-req content typemessage/ohttp-res content typeGET /ohttp-configs - Retrieve current key configuration
application/ohttp-keys content typeGET /health - Basic health checkGET /health/keys - Key management health checkGET /metrics - Prometheus metricsClients need the key configuration to encrypt requests:
# Fetch key configuration
curl -H "Accept: application/ohttp-keys" https://gateway:8080/ohttp-configs
# Send OHTTP request (encrypted)
curl -X POST \
-H "Content-Type: message/ohttp-req" \
--data-binary @encrypted_request.bin \
https://gateway:8080/gateway
Security Considerations
Configure ALLOWED_TARGET_ORIGINS to restrict which domains the gateway can reach. Without this, the gateway may be used to proxy requests to unintended targets.
Enable rate limiting to prevent abuse:
RATE_LIMIT_RPS=50
RATE_LIMIT_BURST=100
RATE_LIMIT_BY_IP=true
KEY_ROTATION_INTERVALKEY_RETENTION_PERIOD to handle delayed requestsSEED_SECRET_KEY for deterministic key generation in clustered deploymentsThe gateway validates:
Prometheus metrics are available at /metrics:
ohttp_requests_total - Total requests processedohttp_request_duration_seconds - Request processing timeohttp_decryption_errors_total - Decryption failuresohttp_encryption_errors_total - Encryption failuresohttp_backend_errors_total - Backend request failures/health - Basic service health/health/keys - Key management statusStructured logging with configurable levels and formats. Set LOG_FORMAT=json for machine-readable logs.
apiVersion: apps/v1
kind: Deployment
metadata:
name: ohttp-gateway
spec:
replicas: 3
selector:
matchLabels:
app: ohttp-gateway
template:
metadata:
labels:
app: ohttp-gateway
spec:
containers:
- name: gateway
image: ohttp-gateway:latest
ports:
- containerPort: 8080
env:
- name: BACKEND_URL
value: "https://api.example.com"
- name: ALLOWED_TARGET_ORIGINS
value: "api.example.com"
- name: RATE_LIMIT_RPS
value: "100"
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
cargo build --release
cargo test
cargo clippy
cargo fmt