Skip to content

TLS — Xray-core ​

Xray's TLS settings live under streamSettings.tlsSettings when streamSettings.security is "tls". The struct also covers ECH and the uTLS fingerprint family. For REALITY, see REALITY — that's a parallel streamSettings.security value with its own block.

TLS settings ​

FieldTypeDefaultAllowed valuesDescription
allowInsecureboolfalse(use pinnedPeerCertSha256 / verifyPeerCertByName)Not supported — true fails at startup with a message pointing to pinnedPeerCertSha256 and verifyPeerCertByName, which replace it.
certificates[]*TLSCertConfig[][TLSCertConfig]Server certificates (inbound) or trusted-CA pinning (outbound). Multiple entries enable SNI-based selection on inbound.
serverNamestring(inferred)<hostname>Expected server name. On outbound, the SNI sent and the value verified against the server's leaf cert. On inbound, the SNI used when ACME provisions a certificate.
alpn*StringList["h2", "http/1.1"]<ALPN string>Application-layer protocol negotiation list, offered to the peer.
enableSessionResumptionboolfalsetrue | falseEnable TLS session-ticket resumption (client side).
disableSystemRootboolfalsetrue | falseTrust no built-in roots — neither Xray's bundled root CAs nor the OS trust store. When true, only certificates entries (normally usage: verify) are trusted; takes precedence over useSystemCA.
minVersionstring1.21.0 | 1.1 | 1.2 | 1.3Minimum acceptable TLS version.
maxVersionstring1.31.0 | 1.1 | 1.2 | 1.3Maximum acceptable TLS version.
cipherSuitesstring(library default)<comma-separated cipher list>Override the cipher suite list. Uses OpenSSL-style names (e.g. TLS_AES_128_GCM_SHA256:...). Note: ignored for TLS 1.3 — only 1.2 cipher choice is configurable.
fingerprintstring(empty = chrome)chrome | firefox | safari | edge | 360 | qq | ios | android | random | randomized | randomizednoalpn | unsafeuTLS ClientHello fingerprint (case-insensitive). Empty uses the same Chrome preset as chrome. random picks one modern browser fingerprint at startup; randomized / randomizednoalpn build a randomized ClientHello with / without ALPN; uTLS's versioned names (e.g. hellochrome_131) are accepted too. A uTLS fingerprint drives the entire ClientHello shape (cipher suites, extensions, signature algorithms) — it overrides the explicit cipherSuites field. unsafe sends Go's own ClientHello instead (the fingerprint of REALITY rejects it). Unknown values fail at startup.
rejectUnknownSniboolfalsetrue | falseInbound — reject TLS connections whose SNI doesn't match any of the configured certificates.
curvePreferences*StringList(library default)X25519 | P-256 | P-384 | P-521 | X25519MLKEM768Override the key-exchange curve preference list. Order matters.
masterKeyLogstring(unset)<file path>SSLKEYLOGFILE-style path for capturing TLS keys (Wireshark decryption). Don't enable on production.
pinnedPeerCertSha256string(unset)<hex SHA-256>[,…]Outbound only — pin the peer by certificate SHA-256 (hex, colons allowed; comma-separate several values). A match on the leaf certificate is accepted as-is; a match on a CA certificate in the chain verifies the leaf against that CA instead of the root store. No match rejects the connection.
verifyPeerCertByNamestring(unset)<hostname>When set, verify the peer cert's Subject CN/SAN matches this name instead of serverName. Useful when the SNI differs from the canonical certificate name (REALITY-style setups).
echServerKeysstring(unset)<base64 ECHConfigList>Inbound — ECH server key set.
echConfigListstring(unset)<base64 ECHConfigList> | <DNS URL> | <domain>+<DNS URL>Outbound — enables ECH. Either a base64 ECHConfigList, or a DNS server URL (https://…, h2c://… or udp://…, optionally prefixed with domain+) to fetch it from the HTTPS record of serverName (or that domain). Unset means no ECH.
echSockopt*SocketConfig(unset)SocketConfigSocket options applied to the ECH-discovery DNS request.
useSystemCAboolfalsetrue | falseOutbound — verify servers against the operating system's trust store instead of Xray's bundled root-CA set. By default only the bundled set is used, so CAs added to the OS store are not trusted. certificates entries are trusted on top of either set; if the OS store can't be loaded, the bundled set is used.

Source: infra/conf/transport_security.go:300-320 · pinned at v26.11.9 (676eaf6)

certificates[] ​

FieldTypeDefaultAllowed valuesDescription
certificateFilestring(unset)<PEM file path>Path to a certificate PEM file. Mutually exclusive with certificate.
certificate[]string(unset)[<PEM line>]Inline certificate PEM as a string array (one element per line, or the whole PEM as one element).
keyFilestring(unset)<PEM file path>Path to the private-key PEM file.
key[]string(unset)[<PEM line>]Inline private-key PEM.
usagestringenciphermentencipherment | verify | issueRole of this certificate: encipherment (server cert), verify (trusted CA for peer verification), issue (CA used to issue per-connection certs in some forwarding modes).
ocspStaplinguint643600<seconds>How often to refresh the OCSP staple. 0 disables.
oneTimeLoadingboolfalsetrue | falseRead the cert and key once at startup instead of every reload. Auto-set to true when using inline certificate/key (no path to reload from).
buildChainboolfalsetrue | falseAuto-fetch intermediate CAs to build a complete chain if the supplied PEM has only the leaf.

Source: infra/conf/transport_security.go:248-257 · pinned at v26.11.9 (676eaf6)

Examples ​

Outbound — verify against the OS trust store instead of the bundled root CAs, force TLS 1.3, pin a chrome fingerprint:

json
{
  "streamSettings": {
    "security": "tls",
    "tlsSettings": {
      "serverName": "example.com",
      "alpn": ["h2", "http/1.1"],
      "minVersion": "1.3",
      "maxVersion": "1.3",
      "fingerprint": "chrome",
      "useSystemCA": true
    }
  }
}

Inbound — serve a Let's Encrypt cert:

json
{
  "streamSettings": {
    "security": "tls",
    "tlsSettings": {
      "serverName": "example.com",
      "certificates": [
        {
          "certificateFile": "/etc/ssl/cert.pem",
          "keyFile": "/etc/ssl/key.pem",
          "usage": "encipherment",
          "ocspStapling": 3600
        }
      ],
      "rejectUnknownSni": true
    }
  }
}

Pinned-cert outbound (lock to a specific SHA-256):

json
{
  "streamSettings": {
    "security": "tls",
    "tlsSettings": {
      "serverName": "example.com",
      "pinnedPeerCertSha256": "<hex-SHA256-of-leaf-cert>"
    }
  }
}

Notes ​

  • fingerprint is uTLS — it rewrites the entire ClientHello to mimic the chosen browser, and an empty value already selects the Chrome preset. Unless fingerprint is unsafe, cipherSuites, curvePreferences, and minVersion/maxVersion are mostly ignored because uTLS controls those itself.
  • TLS-1.3 ignores cipherSuites per the Go standard library — only TLS 1.2 cipher choice is configurable. Use curvePreferences to influence the key-exchange choice in TLS 1.3.
  • Outbound certificate verification uses Xray's bundled root-CA set by default, not the operating system's store — a CA injected into the OS is not trusted. Set useSystemCA: true to verify against the OS store instead.
  • The certificates[].usage field is critical:
    • encipherment — typical server certificate.
    • verify — used as a trusted CA root on the outbound side. Pair with disableSystemRoot: true to trust only these entries.
    • issue — used to issue per-connection certs in some forwarding modes (MITM HTTPS pass-through).
  • verifyPeerCertByName decouples SNI from the verified name — useful in REALITY-style setups where the SNI is a public site but the actual certificate is for the Xray server.
  • masterKeyLog is a debugging aid; the file format matches the SSLKEYLOGFILE specification that Wireshark consumes. Never enable on production.

Cross-core notes ​

  • sing-box uses a single tls: { ... } block embedded on every inbound and outbound. Field names are snake_case (server_name, cipher_suites), and REALITY / ECH / uTLS live as nested sub-blocks. See TLS — sing-box.
  • mihomo sprinkles TLS fields directly onto each proxy adapter — tls, sni, alpn, skip-cert-verify, etc. There is no consolidated TLS block. See TLS — mihomo.

Source: infra/conf/transport_security.go:248-320 · v26.11.9 (676eaf6)

Core Tutorial by Argsment