Skip to content

AnyTLS — mihomo

mihomo 双端支持 AnyTLS,沿用 mihomo 常规约定(无 cipher,出站把 TLS / ECH / uTLS 旋钮放在顶层)。

出站

proxies:type: anytls 条目。内嵌 BasicOption

字段类型默认值允许值描述
namestring(required)<string>唯一的代理名。
serverstring(required)<host>上游服务器主机名或 IP。
portint(required)<port>上游服务器端口。
passwordstring(required)<string>服务端密码。
alpn[]string[]h2 | http/1.1TLS 握手时宣告的 ALPN 列表。
snistring(server)<SNI>TLS Server Name Indication。
ech-optsECHOptions(disabled)ECHOptionsEncrypted Client Hello 配置。
shadow-tls-optsShadowTLSOptions(disabled)ShadowTLSOptionsShadow-TLS 伪装块(`{ password, version }`)。每个代理最多只能启用一个 TLS 伪装块。
restls-optsRestlsOptions(disabled)RestlsOptionsRestls 伪装块(`{ password, version-hint, restls-script }`)。每个代理最多只能启用一个 TLS 伪装块。
jls-optsJLSOptions(disabled)JLSOptionsJLS 伪装块(`{ username, password }`)。每个代理最多只能启用一个 TLS 伪装块。
client-fingerprintstring(global)chrome | firefox | safari | ios | edge | random | randomizeduTLS ClientHello 指纹。
skip-cert-verifyboolfalsetrue | false禁用 TLS 校验(仅供测试)。
name-cert-verifystring(unset)<hostname>改为按此主机名(而非 SNI)校验服务器证书。
fingerprintstring(unset)<SHA256 hex>锚定服务端 TLS 证书指纹。
certificatestring(unset)<PEM file path>客户端证书(mTLS)。
private-keystring(unset)<key file path>与 `certificate` 配对的私钥。
udpboolfalsetrue | false允许 UDP 包经此出站转发。
idle-session-check-intervalint0<seconds>会话池扫描间隔。0 使用运行时默认。
idle-session-timeoutint0<seconds>空闲超过该秒数的会话会被回收。0 使用运行时默认。
min-idle-sessionint0<int>池中需保持温热的最少会话数。
disable-reuseboolfalsetrue | false不缓存空闲会话 —— 每个流都新开一个 AnyTLS 会话,用完即关。

源码: adapter/outbound/anytls.go:27-50 · 锚定版本 v1.19.29 (e26714a)

入站

listeners:type: anytls 条目。内嵌 BaseOption

字段类型默认值允许值描述
usersmap[string]string{}{<username>: <password>}用户表 —— 用户名到密码的映射。
certificatestring(required)<PEM file path>TLS 服务端证书。
private-keystring(required)<key file path>TLS 私钥。
client-auth-typestring(none)no-client-cert | request-client-cert | require-any-client-cert | verify-client-cert-if-given | require-and-verify-client-certmTLS 客户端鉴权模式。
client-auth-certstring(unset)<PEM file path>作为客户端根的 CA 集合。
ech-keystring(unset)<ECH config>Encrypted Client Hello 配置 / 密钥。
shadow-tlsShadowTLS(disabled)ShadowTLS服务端 Shadow-TLS 伪装块(`{ enable, version, password, users, handshake, ... }`)。
res-tlsResTLS(disabled)ResTLS服务端 Restls 伪装块(`{ enable, dest, password, ... }`);未通过认证的客户端会被中继到 `dest`。
jls-configJLSConfig(disabled)JLSConfig服务端 JLS 伪装块(`{ enable, users, sni, dest, ... }`);未通过认证的客户端会被中继到 `dest`。
allow-insecureboolfalsetrue | false在监听器上跳过 TLS 客户端证书校验(仅供测试)。
padding-schemestring(server default)<scheme>自定义 padding 方案。单字符串,遵循上游协议规范。

源码: listener/inbound/anytls.go:12-25 · 锚定版本 v1.19.29 (e26714a)

示例

出站:

yaml
proxies:
  - name: anytls
    type: anytls
    server: example.com
    port: 443
    password: <password>
    sni: example.com
    alpn: [h2, http/1.1]
    udp: true
    client-fingerprint: chrome
    idle-session-check-interval: 30
    idle-session-timeout: 60
    min-idle-session: 4

入站:

yaml
listeners:
  - name: anytls-in
    type: anytls
    listen: 0.0.0.0
    port: 443
    users:
      alice: <alice-password>
      bob: <bob-password>
    certificate: /etc/mihomo/server.crt
    private-key: /etc/mihomo/server.key

说明

  • mihomo 对三个会话池超时使用 ;sing-box 对同样字段使用时长字符串("30s")。字段拼写也不同 —— 这里 kebab-case,sing-box 那边 snake_case。
  • users: 是 username → password 的 YAML 映射,与 mihomo 的 TUIC、Hysteria2 入站保持一致。
  • mihomo 出站把 TLS、ECH、uTLS 指纹旋钮内联在代理对象上。sing-box 把它们放在内嵌的 tls: 块中。
  • shadow-tls-optsrestls-optsjls-opts 是互斥的 TLS 伪装模式 —— 最多启用一个。入站对应的 shadow-tlsres-tlsjls-config 同样互斥。
  • disable-reuse 会完全关闭空闲会话池;此时三个 idle-session-* / min-idle-session 旋钮不再生效。

跨内核说明

  • Xray-core 不支持 AnyTLS。参见 AnyTLS — Xray-core
  • sing-box 使用 snake_case 字段名,会话池超时使用 Go 风格时长字符串,用户列表为 [{name, password}] 数组。参见 AnyTLS — sing-box

源码: adapter/outbound/anytls.go:27-50 · v1.19.29 (e26714a)

由 Argsment 出品的 Core Tutorial