English
shadowtls
ShadowTLS (sing-box's protocol/shadowtls on top of sing-shadowtls): a TLS handshake with a real server, which the client and this server only observe; then the connection itself — bare (v1), as application data records (v2) or as records with a running HMAC (v3).
| Crate | ours-mod-shadowtls, modules/protocols/shadowtls |
| Binary features | shadowtls-inbound, shadowtls-outbound (shadowtls enables both) (enables tls) |
| Crate features | none |
requires
dial, tls — connections to the server; the TLS client (v3 — client_sealed, which signs the session ID). The handshake runs through ours_api::tls::connect_inner, which hands back the stream under TLS.
provides
Provide::Blocks { section: "outbounds", key: "shadowtls", blocks: ["tls", "dial"] }.Provide::Inbound { key: "shadowtls", decode: inbound::decode }— its own decoder: the handshake server and thedetourto an inbound;Provide::Outbound { key: "shadowtls" }; schemas.
Syntax: shadowtls.
Dependencies
ours-tls-options, ours-net-sys, ours-api, ours-codec, ours-json, hmac, sha1, sha2, rand_core + getrandom.
Design
src/outbound.rs— a connection to the ShadowTLS server regardless of the requested destination: another outbound uses it as itsdetour. No UDP.src/inbound.rs— the client's handshake is proxied to the real TLS server until the client proves itself; then the connection goes to the inbound named in itsdetour. The handshake server is chosen by SNI (handshake_for_server_name,wildcard_sni:off/authed/all).src/v2.rs— v2: proof by a hash of what the server sent in the handshake.src/v3.rs— v3: the server signs and masks the real server's records; after the handshake every record is signed with an HMAC over everything sent.src/frame.rs— whole TLS records by their 5-byte header.
Limitations
The inbound's netns is rejected.
Tests
No integration tests; unit tests in src/frame.rs and src/inbound.rs; fuzzing in fuzz/.