SRX — Stochastic Routing eXtended
A next-generation VPN protocol library for Rust.
Key features
- Multi-transport channel splitting — simultaneous operation over TCP, UDP, QUIC, WebSocket, gRPC, and HTTP/2-3 with stochastic transport selection
- QUIC multi-stream multiplexing - one QUIC connection can carry multiple logical bidi channels in parallel
- DPI evasion — protocol mimicry (TLS 1.3, HTTP/2 DATA, DTLS 1.2 record headers), jitter modeling, randomized padding, cover traffic, no static signatures
- Post-quantum cryptography — hybrid Kyber + X25519 key exchange with HKDF-SHA256 derivation
- Stochastic routing — seed-synchronized pseudo-random decisions for port hopping, transport selection, and traffic shaping
- Health-aware routing — per-transport RTT/failure tracking, automatic fallback when DPI blocks a transport
- gRPC TLS-first - secure
https://gRPC client path by default; plaintext requires explicit insecure API - AEAD encryption — ChaCha20-Poly1305 or AES-256-GCM with automatic deterministic re-keying (both peers rotate keys at the same packet boundary)
- Persistent anti-replay protection - sliding 1024-packet replay window with pluggable storage backends (
file, optionalsqlite/redis), monotonic clustered merge (CAS+retry), replay snapshot integrity checks (checksum/hmac), and replay-store CAS telemetry counters - Certificate pinning option - TLS TCP / WSS / QUIC clients can enforce SHA-256 certificate pins after handshake
- Cover traffic - background noise matching messenger/web/API profiles, indistinguishable from real data
- Obfuscated wire format — frame IDs are XOR-masked, no sequential counters visible on the wire
- In-band signaling — encrypted control signals (re-key, seed rotation, transport switch) embedded in normal traffic, indistinguishable from data
- Self-healing — automatic DPI interference detection with exponential backoff, seed rotation, and environment-aware transport reordering (Wifi/Cellular/Corporate)
- Decoy endpoints — external-facing HTTP endpoints (REST API, health-check, Prometheus metrics) that answer probes with plausible responses; hidden control data embedded via base64 payload injection
Installation
[]
= "1.0.2"
The library name is srx, so imports use the short form:
use ;
use ;
For app-level usage without manual handshake wiring, use:
use SecureTcpSession;
Feature flags
| Feature | Default | Description |
|---|---|---|
quic |
yes | QUIC transport |
websocket |
yes | WebSocket transport |
grpc |
yes | gRPC stream transport |
http-tunnel |
yes | HTTP/2-3 tunnel transport |
replay-sqlite |
no | SQLite replay-state backend |
replay-redis |
no | Redis replay-state backend |
full |
no | All transports enabled |
Quick start
High-level API (SrxNode)
use ;
// Both peers share a master secret (from handshake).
let master = ;
let config = default;
// Replay state is persisted by default at ".srx/replay_state.json" (file backend).
// Optional: config.replay.backend = ReplayBackend::Sqlite { .. } / Redis { .. }
// Integrity defaults to SHA-256 checksum; for tamper-resistance use HMAC mode.
// HMAC key source is configurable:
// StaticConfig / EnvVar / File / Custom (app-registered provider).
// Build a node from the shared secret.
let mut node = from_master_secret.unwrap;
// Prepare an encrypted, framed, mimicry-wrapped envelope.
let envelope = node.prepare_outgoing.unwrap;
// On the other side, process_incoming recovers the plaintext.
let plaintext = node.process_incoming.unwrap;
assert_eq!;
High-level secure session API (no manual handshake)
use ;
let cfg = default;
let session = connect.await?;
session.send_data.await?;
Pipeline with real transport
use Arc;
use ;
use ;
use PaddingStrategy;
use SeedRng;
use ;
// Shared session parameters (from handshake).
let seed = ;
let key = ;
let aead = new;
// Connect a TCP transport.
// let tcp = TcpTransport::connect("127.0.0.1:9000".parse().unwrap()).await?;
// let mut mgr = TransportManager::new();
// mgr.add_transport(Arc::new(tcp));
// Build the pipeline.
let mut pipe = new;
// Send: pad -> encrypt -> frame -> mimicry -> dispatch
// pipe.send(b"payload").await?;
// Recv: transport -> unwrap -> decode -> decrypt -> unpad
// let data = pipe.recv_from(TransportKind::Tcp).await?;
Handshake (3-message hybrid PQC/ECDH)
use Handshake;
let mut client = new_initiator;
let mut server = new_responder;
let client_hello = client.client_hello.unwrap;
let server_hello = server.server_hello.unwrap;
let client_finished = client.finalize.unwrap;
server.server_finish.unwrap;
// Both sides now share the same master secret.
assert_eq!;
Examples
The project ships with a full SRX messenger demo:
# Terminal 1 - server (monitor-only UI)
# Terminal 2 - client alice
# Terminal 3 - client bob
Demo capabilities:
- Username auth and multi-client chat (
broadcast+/w user msg). - Tabbed console UI (
Chat,Contacts,Metrics,Logs). - SRX handshake + encrypted pipeline + in-band signaling.
- Automatic and manual transport rotation across all transport kinds.
See examples/README.md and examples/RUN.md.
Testing
Unit/integration tests and Criterion benchmark suites:
Focused benchmark suites:
Publish script
# Dry run (default)
powershell -ExecutionPolicy Bypass -File scripts/publish.ps1
# Real publish
powershell -ExecutionPolicy Bypass -File scripts/publish.ps1 -Publish
Architecture
See ARCHITECTURE.md for a detailed description of all modules and data flows.
License
Licensed under the Apache License, Version 2.0 (LICENSE).