Skip to content

Shadowsocks — Xray-core

Xray-core 同时支持传统 AEAD-Shadowsocks(AES-GCM、ChaCha20-Poly1305) 与 Shadowsocks-2022(2022-blake3-... 加密家族)及 EIH 多用户能力。 加载时会打印弃用横幅 —— Xray 开发者推荐使用 VLESS 加密作为现代替代。

入站

"protocol": "shadowsocks" 入站的 settings

字段类型默认值允许值描述
methodstring(required)none | plain | aes-128-gcm | aes-256-gcm | chacha20-poly1305 | xchacha20-poly1305 | 2022-blake3-aes-128-gcm | 2022-blake3-aes-256-gcm | 2022-blake3-chacha20-poly1305加密 / 密钥派生算法。未知值在解析阶段映射为 UNKNOWN。接受 AEAD 别名(`aead_aes_128_gcm` 等)与 IETF 别名(`chacha20-ietf-poly1305`)。
passwordstring(required for single-user, ignored for SS-2022 multi-user)<string> | <base64 key>单用户密码(AEAD)或 **服务端 EIH 密钥**(SS-2022)。SS-2022 下,取值为 base64 编码的原始密钥字节,长度需匹配加密算法(16 / 32 字节)。
levelbyte0<byte>未按用户单独设置时的默认策略等级。
emailstring(unset)<string>统计 / 日志中显示的标签。
users[]*ShadowsocksUserConfig[ShadowsocksUserConfig] | …入站账户列表;对象形状与 `clients` 相同。`users` 是近期 Xray 引入的较新名称,与 `clients` 一并接受。
clients[]*ShadowsocksUserConfig[][ShadowsocksUserConfig]单用户列表。只有 SS-2022 加密支持多用户;传统 AEAD 加密不支持。
network*NetworkListtcptcp | udp | tcp,udp支持的传输(逗号分隔列表或单值)。

源码: infra/conf/shadowsocks.go:43-51 · 锚定版本 v26.6.1 (94ffd50)

clients[]

字段类型默认值允许值描述
methodstring(inherits server)<see server methods>单用户加密(仅 SS-2022)。必须与服务端加密家族一致。
passwordstring(required)<base64 key>用户 EIH 密钥。长度需匹配加密算法(16 或 32 字节)。
levelbyte0<byte>该用户的策略等级。
emailstring(unset)<string>用户标识。
address*Address(unset)<host>可选的中继目标地址。仅 SS-2022 服务端中继支持。
portuint16(unset)<port>中继目标端口(与 address 成对出现)。

源码: infra/conf/shadowsocks.go:34-41 · 锚定版本 v26.6.1 (94ffd50)

多用户仅适用于 SS-2022

clients[] 仅在使用 2022-blake3-... 加密之一时才会生效。使用传统 AEAD 加密时,只会读取顶层 password,列表中的额外用户会被静默忽略。

出站

"protocol": "shadowsocks" 出站的 settings

字段类型默认值允许值描述
address*Address(unset)<host>简化形式 —— 服务器主机名或 IP。
portuint16(required with address)<port>服务器端口。
levelbyte0<byte>用户等级。
emailstring(unset)<string>用户标识。
methodstring(required)<see inbound methods>与服务端协商使用的加密。
passwordstring(required)<string> | <base64 key>服务端密码 / SS-2022 密钥。
uotboolfalsetrue | false把 UDP 包包装进 TCP 流(UDP-over-TCP)。
uotVersionint21 | 2UoT 帧版本。版本 2 是现代默认;版本 1 仅用于与最早期的 sing-box / shadowsocks-2022 客户端兼容。
servers[]*ShadowsocksServerTarget(use simplified shape)[ShadowsocksServerTarget]完整形式,恰好一个条目。

源码: infra/conf/shadowsocks.go:192-202 · 锚定版本 v26.6.1 (94ffd50)

servers[]

字段类型默认值允许值描述
address*Address(required)<host>服务器主机名或 IP。
portuint16(required)<port>服务器端口。
levelbyte0<byte>用户等级。
emailstring(unset)<string>用户标识。
methodstring(required)<cipher>加密算法。
passwordstring(required)<string> | <base64 key>密码 / SS-2022 密钥。
uotboolfalsetrue | falseUDP-over-TCP 开关。
uotVersionint21 | 2UoT 版本。

源码: infra/conf/shadowsocks.go:181-190 · 锚定版本 v26.6.1 (94ffd50)

出站接受 要么 简化形式(顶层 addressportmethodpassword),要么 完整的 servers 形式且恰好一个条目。

示例

传统 AEAD 入站:

json
{
  "inbounds": [
    {
      "tag": "ss-in",
      "listen": "0.0.0.0",
      "port": 8388,
      "protocol": "shadowsocks",
      "settings": {
        "method": "aes-256-gcm",
        "password": "<password>",
        "network": "tcp,udp"
      }
    }
  ]
}

SS-2022 入站,双用户:

json
{
  "inbounds": [
    {
      "tag": "ss22-in",
      "listen": "0.0.0.0",
      "port": 8388,
      "protocol": "shadowsocks",
      "settings": {
        "method": "2022-blake3-aes-128-gcm",
        "password": "<base64 16-byte server key>",
        "clients": [
          { "password": "<base64 16-byte alice key>", "email": "alice" },
          { "password": "<base64 16-byte bob key>",   "email": "bob"   }
        ],
        "network": "tcp,udp"
      }
    }
  ]
}

启用 UDP-over-TCP 的出站:

json
{
  "outbounds": [
    {
      "tag": "ss-out",
      "protocol": "shadowsocks",
      "settings": {
        "address": "example.com",
        "port": 8388,
        "method": "2022-blake3-aes-256-gcm",
        "password": "<base64 32-byte key>",
        "uot": true,
        "uotVersion": 2
      }
    }
  ]
}

说明

  • 加密算法集合:传统 AEAD 家族取自 cipherFromStringinfra/conf/shadowsocks.go:16-31), SS-2022 家族取自 shadowaead_2022.List(vendored 上游常量)。 未知加密返回 UNKNOWN,构建失败。
  • method: "none"(或 "plain")完全禁用加密 —— Shadowsocks 帧 结构保留,但载荷以明文发送。仅在外层已有加密时使用。
  • SS-2022 密码是 原始密钥材料,以 base64 编码。AEAD-128 系列使用 16 字节密钥;AEAD-256 系列使用 32 字节密钥;ChaCha20 使用 32 字节 密钥。长度不符会在握手阶段解码失败(而非配置解析阶段)。
  • uotVersion: 1 仅用于旧客户端兼容。新配置应使用默认值 2, 除非要兼容非常早期的 shadowsocks-2022 部署。
  • 加载时打印的弃用横幅 "Shadowsocks (with no Forward Secrecy, etc.)" 位于 infra/conf/shadowsocks.go:52, 185

跨内核说明

  • sing-box SS-2022 多用户使用 users[],并新增 destinations[] 数组表示服务端中继形式(一台 SS-2022 服务器分流到多个上游地址)。 另外支持外部插件(pluginplugin_opts)。参见 Shadowsocks — sing-box
  • mihomo 使用 cipher(而非 method)作为字段名;插件参数以 通用 plugin-opts 映射形式按插件名键入;并支持丰富的混淆插件 (obfsv2ray-pluginshadow-tlsrestlskcptun)。 参见 Shadowsocks — mihomo

源码: infra/conf/shadowsocks.go:34-202 · v26.6.1 (94ffd50)

由 Argsment 出品的 Core Tutorial