ShadowTLS: v1, v2 and v3 explained, and how it differs from Reality

ShadowTLS is a wrapper that starts a proxy connection with a genuine TLS handshake with someone else's website, real certificate included, and then switches the same TCP connection to a hidden proxy, usually Shadowsocks. It encrypts nothing itself: that is the inner protocol's job. The current version, v3 from 2023, checks both sides with HMAC, so probes and tampered connections end up at the real site.

Updated

On this page

Facts

What it is

Disguise layer in front of another proxy, usually Shadowsocks

Since, by

2022, ihciah (shadow-tls, written in Rust)

Transport

TCP only

Encryption

None of its own; v3 adds HMAC tags

To the network it looks like

TLS to a popular site, with that site's real certificate

Usual port

443

Comes as

No common link; sing-box JSON or a mihomo plugin

License

MIT

Latest release

shadow-tls v0.2.25, December 13, 2023

In Veli

Not supported

Versions and history

  1. Aug 2022

    v1

    The relay passes the handshake to a real site and watches for its end, so only TLS 1.2 works; after it the proxy's bytes go raw.

  2. Oct 2022

    v2

    shadow-tls 0.2.0. The client puts an 8-byte HMAC over everything the server sent in front of its first data, data goes in TLS records, and TLS 1.3 works. Connections without the tag stay with the real site.

  3. Feb 2023

    v3

    The ClientHello carries an HMAC, the relay proves itself by tagging the real site's records, and every data record has a 4-byte HMAC. Strict mode allows only handshake sites with TLS 1.3. The handshake idea comes from restls.

  4. 2023

    “Chasing Shadows” at FOCI

    Researchers from the University of Colorado Boulder and elsewhere find v1 relays by three probes, about 15,000 suspects on the Internet. Their fix went into v0.2.3.

  5. Dec 2023

    shadow-tls 0.2.25

    The last release of the original program so far. The protocol lives on in sing-box (v3 since 1.2) and mihomo.

How ShadowTLS works

On the server there are three parties: the ShadowTLS relay on port 443, a handshake site you pick (a popular one, such as a large company's domain) and the data server, usually Shadowsocks on the same machine. In v3 a connection goes like this:

  1. 1

    ClientHello with a signature

    The client starts TLS with the handshake site's name in SNI. The last 4 bytes of its 32-byte session ID are an HMAC of the ClientHello, keyed with the password.

  2. 2

    The real site answers

    The relay checks the HMAC. Without it, the connection is simply relayed to the real site, so a probe or a browser meets that site. With it, the handshake is still forwarded, and the real site answers with its own certificate.

  3. 3

    The relay proves itself

    The relay alters the real site's Application Data records: XOR with SHA-256 of the password and ServerRandom, plus a 4-byte HMAC. The client recognises them. If they don't match, someone is in the middle, and the client sends a decoy HTTP request and closes.

  4. 4

    The switch

    The client sends its first data record with an HMAC; the relay stops talking to the real site and joins the stream to the data server.

  5. 5

    Data

    Each record is TLS Application Data with a 4-byte HMAC inside, keyed separately for each direction. A bad tag gets a TLS alert, as a real TLS server would send.

v1, v2 and v3: what each version changed

Both sides must speak the same version. In sing-box version defaults to 1, so a v3 config has to say "version": 3; the original program takes --v3 on both sides. The v3 document explains the move from v2: a man in the middle could tamper with data, split records or take over the connection, and the server had no quiet way to prove who it was.

  • TLS of the handshake site

    v1 (2022)1.2 only

    v2 (2022)1.2 or 1.3

    v3 (2023)1.3 in strict mode, 1.2 allowed otherwise

  • Client proves itself

    v1 (2022)No

    v2 (2022)8-byte HMAC in its first data

    v3 (2023)HMAC in the ClientHello session ID

  • Relay proves itself

    v1 (2022)No

    v2 (2022)No

    v3 (2023)HMAC on the real site's records

  • Data after the handshake

    v1 (2022)Raw proxy bytes

    v2 (2022)In TLS records

    v3 (2023)In TLS records, 4-byte HMAC each

  • Known problem

    v1 (2022)Found by probes and passive analysis

    v2 (2022)Open to a hijacked connection

    v3 (2023)No published attack known to us

A sing-box client config, field by field

Client: Shadowsocks 2022 through ShadowTLS v3
{
  "outbounds": [
    {
      "type": "shadowtls",
      "tag": "st",
      "server": "203.0.113.10",
      "server_port": 443,
      "version": 3,
      "password": "Wq7vK2pTz9",
      "tls": {
        "enabled": true,
        "server_name": "www.example.com",
        "utls": { "enabled": true, "fingerprint": "chrome" }
      }
    },
    {
      "type": "shadowsocks",
      "tag": "ss",
      "server": "203.0.113.10",
      "server_port": 443,
      "method": "2022-blake3-aes-128-gcm",
      "password": "q3Vx0dK2mY7cL1pN9sT4wA==",
      "udp_over_tcp": true,
      "detour": "st"
    }
  ],
  "route": { "final": "ss" }
}
Server: the original program in front of a Shadowsocks server on 127.0.0.1:8388
shadow-tls --v3 server --listen 0.0.0.0:443 --server 127.0.0.1:8388 --tls www.example.com --password Wq7vK2pTz9

The same in sing-box: a shadowtls inbound with handshake, users and strict_mode, whose detour names a shadowsocks inbound.

  • server, server_port of shadowtls: your server, on 443 like a real site.
  • version: 3 and password: must match the server.
  • tls.server_name: the borrowed site, not yours. The client sees its real certificate.
  • utls: Chrome's ClientHello instead of Go's. The FOCI 2023 paper found the original client's ClientHello unique; sing-box's docs now mark uTLS as not recommended, as it has been fingerprinted before.
  • detour: st: Shadowsocks goes through the ShadowTLS outbound. Its own server and server_port are then ignored: ShadowTLS connects where it is told.
  • udp_over_tcp: ShadowTLS carries TCP only, so UDP rides inside Shadowsocks by sing-box's own protocol; the server must be sing-box or mihomo for that.
  • route.final: ss: without it sing-box takes the first outbound, and ShadowTLS alone carries nothing useful.

ShadowTLS, Reality and AnyTLS

ShadowTLS v3 (February 2023) and Reality (Xray 1.8.0, March 2023) came out within weeks of each other and solve the same problem: a server that shows a popular site's name without a domain of its own. They do it differently, and AnyTLS, often named next to them, deals with another part of the traffic.

  • Who completes the TLS handshake

    ShadowTLS v3The real site; the relay passes it on

    RealityYour server, as the chosen site

    AnyTLSYour server, with your certificate

  • Own domain

    ShadowTLS v3Not needed

    RealityNot needed

    AnyTLSNeeded for a real certificate

  • Encryption after the handshake

    ShadowTLS v3None of its own; Shadowsocks inside

    RealityThe TLS 1.3 session with your server

    AnyTLSThe TLS session with your server

  • A probe without the key

    ShadowTLS v3Relayed to the real site

    RealityForwarded to the chosen site

    AnyTLSClosed, or a fallback web server

  • TLS inside TLS

    ShadowTLS v3Not padded

    RealityPadded by VLESS's Vision flow

    AnyTLSFirst writes padded

  • Where

    ShadowTLS v3sing-box, mihomo, shadow-tls

    RealityXray, sing-box, mihomo

    AnyTLSsing-box, mihomo

What a censor sees

On the wire: a ClientHello with the borrowed site's name, that site's genuine ServerHello and certificate chain, then TLS Application Data. Nothing in the handshake is fake. What doesn't fit is the address: the site's name resolves to its own servers, not to your VPS. The FOCI 2023 authors looked at redirecting such connections to the “right” address and judged it likely to break legitimate traffic.

That paper, “Chasing Shadows: A security analysis of the ShadowTLS proxy” (Gaukas Wang, Jackson Sippe, Hai Chi, Eric Wustrow and an anonymous co-author, FOCI 2023), tested v1 (shadow-tls 0.1.4). Its client's TLS fingerprint was absent from a university network's dataset; a plain HTTP request to port 443 got a bare FIN, as from 17% of servers; random bytes after the handshake were silently ignored, as by 0.14% of 30 million TLS hosts; a corrupted data record got no alert, as from 0.12%. Combined, only 0.05% of hosts, about 15,000, behaved this way. The fix, forwarding anything unauthenticated to the real site, went into v0.2.3, and v3 keeps it.

The traffic after the handshake is another matter. In the USENIX Security 2024 study by Diwen Xue and colleagues, the classifier recognised 83% of Shadowsocks-over-ShadowTLS flows by the browser's TLS handshake showing through: ShadowTLS doesn't pad, and multiplexing was off, as by default. The paper doesn't say which version it tested.

What isn't known: we found no published measurement of v3 against a national filter, and none of an attack on v3's own design.

Strengths and weaknesses

Strengths

  • Shows a real popular site's handshake and certificate, no domain needed
  • v3 sends probes and unauthenticated connections on to the real site
  • v3 notices a hijacked connection and backs off with a decoy request
  • Works in front of any TCP proxy; Shadowsocks 2022 is the usual pair

Weaknesses

  • No padding: TLS inside TLS shows through, 83% detected in a 2024 study
  • TCP only; UDP needs udp-over-tcp inside Shadowsocks
  • Two protocols to configure, and no common share link
  • The server's address doesn't belong to the borrowed site's name
  • The original shadow-tls hasn't had a release since 2023 and has no Windows build

Where it works

Programs and servers from our comparison tables that list this protocol.

Clients

  • Hiddify
  • NekoBox for Android

Servers and panels

  • S-UI

Compare these programs

Sources

How we write and check

In Veli

ShadowTLS and Veli

Veli doesn't connect ShadowTLS: the app has no ShadowTLS links and no ShadowTLS profiles.

It opens VLESS, VMess, Trojan, Shadowsocks, Hysteria2, TUIC, WireGuard, AmneziaWG and OpenVPN, and on a computer AnyTLS too, as a sing-box JSON configuration.

Questions

What changed in ShadowTLS v3?

The client signs its ClientHello, the relay proves itself by tagging the real site's records, and every data record carries an HMAC. Probes go on to the real site, tampered data gets a TLS alert, and strict mode accepts only handshake sites with TLS 1.3.

ShadowTLS or Reality: what is the difference?

Both show a popular site's name without a domain of your own. In ShadowTLS the real site completes the handshake and Shadowsocks encrypts the data; with Reality your server completes a TLS 1.3 handshake itself and the data stays inside that TLS. Reality usually goes with VLESS and its Vision flow, which also pads the inner handshake.

ShadowTLS or AnyTLS?

They cover different halves: ShadowTLS borrows another site's handshake and leaves the traffic after it as it is, AnyTLS needs your own TLS but reshapes the first packets and reuses connections. mihomo's documentation suggests putting AnyTLS behind ShadowTLS to hide the SNI.

Does ShadowTLS encrypt traffic?

No. It authenticates records but leaves encryption to the protocol inside, which is why it is paired with Shadowsocks 2022 or something like it.

Which site should the handshake go to?

A popular site that is reachable where you are, with low latency to your server. For strict mode in v3 it must support TLS 1.3: openssl s_client -tls1_3 -connect site:443 shows that.

Does ShadowTLS support UDP?

No, it carries TCP only. sing-box can pass UDP inside Shadowsocks with its udp-over-tcp, if the server side is sing-box or mihomo.