Skip to main content

shadowvpn/
lib.rs

1//! # ShadowVPN
2//!
3//! A UDP-based, pre-shared-key (PSK), user-mode VPN written in Rust.
4//!
5//! ShadowVPN is a fixed point-to-point / multi-client tunnel. A TUN-based
6//! client reads IP packets from a virtual interface, encrypts each as a single
7//! UDP datagram, and sends it to the server; the server decrypts, routes, and
8//! tunnels return traffic back. The async runtime is [`tokio`].
9//!
10//! ## Wire protocol
11//!
12//! The on-wire crypto matches the **shadowsocks.org AEAD UDP scheme** exactly,
13//! so the construction is spec-correct and interoperable. Each UDP datagram is:
14//!
15//! ```text
16//! [ salt (salt_len bytes) ] ++ [ AEAD ciphertext ++ tag ]
17//! ```
18//!
19//! with `salt_len == key_len`, a random per-datagram salt, a subkey of
20//! `HKDF-SHA1(master_key, salt, "ss-subkey")`, and an all-zero 12-byte nonce.
21//! The master key is derived from the password with OpenSSL's legacy
22//! `EVP_BytesToKey` (MD5) KDF. See [`crypto`] for the full description.
23//!
24//! **Deviation from ss-proxy:** the plaintext is the raw IP packet from TUN,
25//! with no SOCKS address header — this is a tunnel, not a SOCKS proxy. See
26//! [`protocol`].
27//!
28//! ## Multiple clients
29//!
30//! One server serves many clients. By default it routes by *learning* each
31//! client's inner tunnel source IP, so clients need distinct addresses. With the
32//! server's NAT mode every client may share one identical config (same
33//! placeholder IP): the server tells them apart by UDP endpoint and maps each
34//! onto a distinct internal IP, rewriting inner addresses in flight. See [`nat`]
35//! and [`pool`].
36//!
37//! ## Binaries
38//!
39//! This crate ships three binaries: `shadowvpn-server` and `shadowvpn-client`
40//! (always built), and `shadowvpn-uri` — a config import/export tool gated behind
41//! the optional `uri` feature so the server/client builds stay lean (see the
42//! `uri` module, compiled only with that feature).
43//!
44//! ## Modules
45//!
46//! * [`crypto`] — cipher abstraction, key derivation, packet encrypt/decrypt.
47//! * [`config`] — JSON + CLI configuration for the server and client.
48//! * [`protocol`] — tunnel framing constants and buffer sizing.
49//! * [`obfs`] — optional carrier obfuscation (QUIC/HTTP3-shaped or base64).
50//! * [`tun_device`] — async TUN interface wrapper (macOS utun + Linux + Windows).
51//! * [`policy`] — client-side policy routing (gfwlist / chinadns split tunnel).
52//! * [`nat`] — server-side per-client NAT (multiple clients, one shared config).
53//! * [`pool`] — internal-IP allocation pool used by [`nat`].
54//! * `uri` — `shadowvpn://` config import/export + QR codes (feature `uri`).
55
56#![warn(missing_docs)]
57
58pub mod config;
59pub mod crypto;
60pub mod nat;
61pub mod obfs;
62pub mod policy;
63pub mod pool;
64pub mod protocol;
65pub mod tun_device;
66#[cfg(feature = "uri")]
67pub mod uri;