Skip to content

The tls block ​

Enables TLS on an inbound or outbound. The presence of the block already means "enabled"; enabled cannot be written. The server name is sni (not server_name: the loader rejects that field).

Which protocols take the block is in the table. TLS is mandatory for trojan (inbound and outbound), anytls (outbound), hysteria, hysteria2, tuic. REALITY is described separately: reality.md.

Outbound (client) ​

FieldTypeDefaultMeaning
snistringthe server addressThe server name in the ClientHello and for certificate verification
disable_sniboolfalseDo not send SNI; the certificate is still verified against the name
insecureboolfalseDo not verify the certificate chain
alpnstring or list—ALPN; with the field empty the transport supplies its own (h2 for gRPC and so on)
min_version, max_version"1.2", "1.3"1.2 … 1.3The version range; 1.0 and 1.1 are an error: TLS below 1.2 is not supported
cipher_suiteslistthe rustls setTLS 1.2 cipher suites by Go names (TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, …); TLS 1.3 suites are always on
curve_preferenceslistX25519MLKEM768, X25519, P256, P384Key exchange groups in order; P521 is not supported
certificate, certificate_pathPEM / paththe system storeYour own root certificates instead of the store
certificate_public_key_sha256list of base64—Public key pinning; incompatible with certificate*
certificate_sha256list of hex—SHA-256 of the server's certificate (the leaf or an issuer in the chain), Xray pinnedPeerCertSha256
verify_nameslist—Names the certificate may be issued for, instead of sni, Xray verifyPeerCertByName
clientblock—The client certificate (mTLS) the outbound presents to the server: certificate or certificate_path and key or key_path
utlsblock—A browser ClientHello fingerprint, see below
fragmentblock—ClientHello fragmentation, see below
ktlsblock—tx, rx: hand send/receive encryption to the kernel (kTLS, unstable), see below
handshake_timeoutduration15sThe handshake time limit
enginestringomittedAccepted only for sing-box compatibility: go or empty; apple, windows are an error
realityblock—REALITY

verify_names and certificate_sha256 are extensions from Xray; sing-box does not have them.

By default, like Go in sing-box, the client offers the post-quantum hybrid group X25519MLKEM768 and an X25519 key along with it, so a server without the hybrid picks X25519 without an extra handshake round trip; the server prefers X25519MLKEM768. An explicit curve_preferences sets both the set and the order. curve_preferences does not affect uTLS: the fingerprint sets the groups.

utls ​

yaml
tls:
  sni: example.com
  utls:
    fingerprint: chrome

fingerprint: chrome (the default; chrome_psk, chrome_pq and the other chrome variants give the same fingerprint), firefox, edge, safari, ios, qq, random (one of the modern browsers, chosen once per process), randomized (Chrome 133 or Chrome 131, chosen once per process). chrome, firefox and randomized offer X25519MLKEM768, which the REALITY server in Xray requires. firefox is Firefox 148, as in Xray (in sing-box it is Firefox 120 without the post-quantum group), with zlib, brotli and zstd certificate compression. 360 and android offer only TLS 1.2 and are rejected. With utls the client speaks only TLS 1.3: a max_version below 1.3 is an error.

Known limitations of the fingerprint ​

fingerprint repeats the browser's ClientHello byte for byte, but does not make the connection indistinguishable from a browser: after the ClientHello the behavior is ours, not the browser's.

  • TLS 1.3 only. If the server picks 1.2, the client answers with a protocol_version alert.
  • No session resumption: every connection is a full handshake. chrome_psk and the other psk variants are aliases of chrome.
  • The browser versions are Chrome 133, Edge 85, Safari 16.0, iOS 14, QQ 11.1 and Firefox 148; most of them are already rare in traffic.
  • The ws and httpupgrade transports under utls send the User-Agent of the same browser and version; the other request headers and their order are not a browser's. A User-Agent in headers takes precedence; without utls it is Go-http-client/1.1.
  • randomized picks Chrome 133 or 131 once per process. The extension order and random values change on every connection, as with Chrome.

ClientHello fragmentation ​

yaml
tls:
  sni: example.com
  fragment:
    packet: true
    record: true
    fallback_delay: 500ms

packet splits the first ClientHello at a random point inside the SNI into two socket writes with a fallback_delay pause between them (500ms by default; TCP_NODELAY for the duration of the handshake). record moves the same ClientHello into two valid TLS records. Together they give two TLS records sent separately. The rest of the traffic does not change. Over QUIC (hysteria*, tuic) fragmentation is an error.

kTLS (unstable) ​

kTLS is unstable and not part of the regular build: it is built only with cargo build -p ours --release --features unstable-ktls. Without it ktls in the config is a load error; with it, a warning at startup. kTLS is rarely faster; only splice forwarding (direct TCP, VLESS without a transport) can benefit.

ktls: {tx: true, rx: true} hands encryption to the Linux kernel after the handshake (the tls module is needed). kTLS requires TLS 1.3; with a TLS 1.2 handshake the connection ends with an error. Over QUIC it is an error.

Inbound (server) ​

FieldTypeDefaultMeaning
certificate, certificate_pathPEM / pathrequired (without REALITY)The certificate chain; the file is reread when it changes
key, key_pathPEM / pathrequired (without REALITY)The private key
insecureboolfalseWithout certificate and key, serve a self-signed certificate (for tests)
snistring—The server name; for REALITY, the name that is accepted
alpnlistfrom the transportThe server's ALPN
min_version, max_version, cipher_suites, curve_preferencesAs for the client
client_authblock—Verification of client certificates, see below
ktlsblock—kTLS, as for the client
handshake_timeoutduration15sThe handshake time limit
realityblock—REALITY

Built-in answer to a foreign client ​

A public trojan, vless or anytls server is best hidden behind REALITY or fallbacks to a real web server: then an active probe sees a live site. The built-in answer is a fallback for when there is neither. A TLS client that is not a client of the inbound gets the answer of an empty Caddy 2 site (200 OK, Server: Caddy; 400 to non-HTTP).

The inbound may wait for a request no longer than listener.first_request (60 s by default, as Caddy). A transport stream (ws, grpc, http and so on) in which the protocol itself refused is closed in the transport's normal way: WebSocket close, END_STREAM. An inbound with TLS on a non-loopback address without fallbacks and REALITY writes a warning at startup. The exact answers and how they differ from a real Caddy are in the differences.

client_auth ​

FieldTypeDefaultMeaning
modestringnono, request, require-any, verify-if-given, require-and-verify
certificate, certificate_pathPEM / list of paths—Roots for verifying client certificates
public_key_sha256list of base64—Pinning of client keys

The sing-box names (kernel_tx, record_fragment, client_key_path, client_authentication, …) are an error with a hint: tls: `kernel_tx` is `ktls.tx` .

Not supported ​

  • ech (Encrypted Client Hello) — the schema accepts the field, but neither the client nor the server starts with it: tls.ech: not implemented yet.
  • spoof: {sni, method} — tls.spoof: not implemented yet.

Example: client ​

yaml
outbounds:
  proxy:
    trojan:
      server: proxy.example.com:443
      password: secret
      tls:
        sni: proxy.example.com
        alpn: [h2, http/1.1]
        utls:
          fingerprint: firefox
        fragment:
          packet: true
route:
  final:
    outbound: proxy

Example: server that verifies clients ​

yaml
inbounds:
  trojan-in:
    trojan:
      listen: ":443"
      users:
        - name: alice
          password: secret
      tls:
        certificate_path: /etc/ours/cert.pem
        key_path: /etc/ours/key.pem
        min_version: "1.3"
        client_auth:
          mode: require-and-verify
          certificate_path: [/etc/ours/ca.pem]
outbounds:
  direct:
    direct:
route:
  final:
    outbound: direct

For developers: the tls module.

GPL-3.0-or-later