Skip to content

trojan ​

Trojan: the client opens a TLS connection and first writes the SHA-224 of the password (hex), a command and the destination address; the server answers nothing and then forwards the stream. UDP goes inside the same TCP connection: each packet is an address, a length and the data. Compatible with sing-box and Xray trojan.

TLS is required on both sides (a `tls` block is required). A transport can be added (ws, grpc, http, httpupgrade, xhttp).

Inbound ​

FieldTypeDefaultMeaning
userslist of {name, password}requiredThe users' passwords; a repeated password is an error
fallbackslist—Where to hand a connection that is not Trojan: fallbacks

Socket settings are the listener block. Blocks: tls (required), transport, mux.

The inbound always accepts trojan-go multiplexing (command 0x7f, an smux session), as sing-box does, without a mux block.

Fallbacks ​

A client that came without Trojan ends up at the site behind the inbound. The first read after TLS decides, as in sing-box: fewer than 56 bytes or a key no user has means a fallback; an error after a known key is an ordinary error. For an inbound open to the internet the main mode is fallbacks to a real web server or REALITY: a probe sees a live site. Without them the inbound answers by itself, like Caddy without a site for that name (built-in answer), and writes a warning about this at startup. The list of rules is the same as for vless (server, name, alpn, path, xver), and so is the choice:

yaml
inbounds:
  trojan-in:
    trojan:
      listen: :443
      users:
        - name: alice
          password: secret
      fallbacks:
        - server: 8080              # default
        - alpn: h2
          server: 127.0.0.1:8081    # HTTP/2 clients
      tls:
        alpn: [h2, http/1.1]
        certificate_path: /etc/ours/cert.pem
        key_path: /etc/ours/key.pem

The sing-box fallback and fallback_for_alpn are an error with a hint on how to write them as rules: fallback is a rule without alpn, fallback_for_alpn rules with alpn. The difference: in sing-box an ALPN without its own rule closes the connection, while here, as in Xray, it goes to the rule without alpn.

Outbound ​

FieldTypeDefaultMeaning
serverhost:portrequiredThe server address
passwordstringrequiredThe password
networktcp, udp or a listbothWhat to pass

Blocks: tls (required; uTLS and fragmentation optional), transport, mux, dial.

Example ​

A server behind TLS with WebSocket:

yaml
inbounds:
  trojan-in:
    trojan:
      listen: ":443"
      users:
        - name: alice
          password: secret
        - name: bob
          password: another-secret
      tls:
        certificate_path: /etc/ours/cert.pem
        key_path: /etc/ours/key.pem
      transport:
        ws:
          path: /tj
outbounds:
  direct:
    direct:
route:
  final:
    outbound: direct

Client:

yaml
outbounds:
  trojan-out:
    trojan:
      server: trojan.example.com:443
      password: secret
      tls:
        sni: trojan.example.com
        utls:
          fingerprint: chrome
      transport:
        ws:
          path: /tj
route:
  final:
    outbound: trojan-out

A minimal client has no transport and utls.

Module description for developers: modules/trojan.

GPL-3.0-or-later