Skip to content

[Feature] XMC: Yggdrasil third-party login + texture signature verification / XMC 支持 Yggdrasil 第三方登录与材质签名验证 #7394

Closed

Description

@yandujun363

Status: proposal / ready for discussion. Branch: feat/xmc-yggdrasil-login (based on c4561418), commits 109e8d2c + 74eb4feb.
状态:提案,欢迎讨论。分支:feat/xmc-yggdrasil-login(基于 c4561418),提交 109e8d2c + 74eb4feb。


中文

背景与动机

当前 XMC 的登录认证是自造的:

  • 客户端配置里手工填写 username / uuid / texturesValue / texturesSignature(需要自己去 Mojang 或皮肤站查 UUID、拉签名材质再复制进配置);
  • 服务端用预共享 password(同时作为 RSA 私钥的派生种子)加静态 profiles 白名单校验;
  • Verify Token 尾部追加预共享密码,和 Minecraft 协议本身没有关系。

维护成本高,且无法复用 Minecraft 生态已有的标准在线模式认证(Yggdrasil / authlib-injector / Blessing Skin)。更重要的是,如果后续要给 MC 模组实现 XMC 服务端(让真实 MC 客户端或服务端模组走标准 Yggdrasil 登录接入 XMC),预共享密码模型无法对接,因为模组侧只会实现标准的 authenticate / join / hasJoined 流程。

本次改动把 XMC 改成标准 Yggdrasil 登录客户端 + 标准 hasJoined 服务端校验,并补上材质签名验证,为后续 MC 模组实现 XMC 服务端铺路,也为 XMC 客户端将来接入真实 MC 服务端打基础。

修改内容

涉及文件:

  • transport/internet/finalmask/xmc/yggdrasil.go(新增:Yggdrasil HTTP 客户端、登录/刷新/join/hasJoined、验签)
  • transport/internet/finalmask/xmc/client.go(Yggdrasil 登录、标准 hash、材质验签接入)
  • transport/internet/finalmask/xmc/server.go(hasJoined 校验、随机密钥、断连语义)
  • transport/internet/finalmask/xmc/profile.go(多 properties 读写、身份/材质比较)
  • transport/internet/finalmask/xmc/config.go、config.proto、config.pb.go
  • infra/conf/transport_finalmask.go(yggdrasil 配置解析、随机密钥生成、警告输出)
  • 测试:yggdrasil_test.go、profile_test.go、handshake_test.go、infra/conf/transport_finalmask_xmc_test.go

1. 配置

XMC settings 新增可选的 yggdrasil 段:

{
  "type": "xmc",
  "settings": {
    "hostname": "mc.example.com",
    "yggdrasil": {
      "api": "https://skin.example.com/api/yggdrasil",
      "username": "[email protected]",
      "password": "<skin account password>",
      "player": "Steve"
    }
  }
}
  • api:Yggdrasil API root(例如 Blessing Skin 的 /api/yggdrasil);
  • username / password:客户端登录凭据(邮箱或角色名,取决于 API 实现);
  • player:可选;账号有多个角色时必须指定;
  • 服务端只需要 api,不需要账号密码。

Yggdrasil 模式下顶层 password 不再参与握手和密钥派生;旧配置(无 yggdrasil 段)行为完全不变。

2. 客户端(client.go / yggdrasil.go)

  • 通过 authserver/authenticate 登录,多角色时用 authserver/refresh 携带 selectedProfile 绑定 token;token/clientToken 进程内缓存,/join 遇到 403 自动重新登录重试一次。

  • Login Start 使用皮肤站返回的真实角色名和 UUID。

  • 加密协商完成后按原版算法计算 login hash:

    sha1(serverId + sharedSecret + serverPublicKey),并按 Java BigInteger#toString(16) 的二进制补码规则渲染(包含负号和去前导零)。

  • 使用 Encryption Request 中实际收到的公钥计算哈希,不再固定配置公钥;Yggdrasil 模式客户端不需要也不应该去“确认公钥”。

  • 用 accessToken 真实调用 sessionserver/session/minecraft/join。

  • 解析 Login Success 的多个 properties,并用 API root 中的 signaturePublickey 校验 textures 属性签名:

    • SHA1withRSA(与 Blessing Skin 的 openssl_sign 默认算法、Minecraft 客户端的签名校验一致);
    • 支持 PEM / 裸 base64 公钥;
    • 公钥按账号缓存,验签失败时自动重新拉取一次(覆盖皮肤站轮换密钥);
    • textures 缺失、无签名、签名不匹配都会拒绝登录;
    • 校验发生在发送 Login Acknowledged 之前,失败不会进入 play 阶段。
  • Yggdrasil 模式不再往 Verify Token 尾部追加预共享密码,保持和原版客户端一致的报文形状。

3. 服务端(server.go)

  • Yggdrasil 模式下每个进程随机生成 1024-bit RSA 密钥对(与原版服务端行为一致),不再从 password 派生;
  • 解密共享密钥后,用自己实际持有的公钥计算同一个 login hash,真实调用 sessionserver/session/minecraft/hasJoined;
  • 因为客户端 /join 与服务端 /hasJoined 存在天然竞态,服务端以 200ms 间隔轮询,最长 10s;
  • 校验返回的角色 UUID / 名称必须与 Login Start 一致;
  • Login Success 直接使用 hasJoined 返回的已签名 properties(含 textures、uploadableTextures);
  • 失败时按原版语义断连:未加入 → multiplayer.disconnect.unverified_username,API 异常 → multiplayer.disconnect.authservers_down;
  • 未配置 yggdrasil 时保留原预共享密码 + profiles 白名单逻辑。

4. 安全模型与警告

Yggdrasil 模式的安全绑定发生在 Yggdrasil 查询里:中间人两侧分别握手时,客户端提交的 hash 和服务端查询的 hash 必然不同,hasJoined 返回空,连接失败;即使不固定服务端公钥也无法完成中间人。

由于这时不再使用预共享密码、也不做密码派生,控制台会在 config 加载时输出一次警告(errors.LogWarning):

XMC: Yggdrasil mode is enabled. The RSA key pair is generated randomly and "password"
is no longer used to derive it or to authenticate the transport; players are verified
through https://skin.example.com/api/yggdrasil (client /join, server /hasJoined).
Both ends must be able to reach the Yggdrasil API. The configured "password" is ignored.

兼容性

  • 不配置 yggdrasil:完全保持旧行为(密码派生密钥 + verify token 预共享密码 + 静态 profiles)。
  • 配置 yggdrasil:password 可省略;如果保留会被忽略并打印警告。
  • 服务端与客户端都必须是包含本次改动的版本;新旧混合会因 verify token 形状不同而握手失败(这是预期行为)。
  • 依赖皮肤站安装并启用 Yggdrasil API 插件(例如 Blessing Skin 的 yggdrasil-api,API root 下需要能取到 signaturePublickey)。

测试流程与结果

环境:Linux(WSL2),Go 1.27.4,Xray-core c4561418 + 本分支改动。

步骤 命令 结果
XMC 包测试 go test ./transport/internet/finalmask/xmc/ 通过
并发/竞态 go test -race ./transport/internet/finalmask/xmc/ 通过(约 5.7s)
配置构建测试 go test ./infra/conf/ 通过
全量编译 go build ./... 通过
Protobuf 生成一致性 go run ./infra/vprotogen -pwd . -mode check 通过

测试覆盖点:

  1. login hash 已知向量:Notch / jeb_ / simon 三个来自 Java 实现的 SHA-1 十六进制(含负数补码)全部匹配。
  2. 端到端握手:用假 Yggdrasil 服务(httptest)实现 authenticate / refresh / join / hasJoined / API root;客户端与服务端完成完整 MC 握手,只有 client /join 和服务端 /hasJoined 使用同一个 hash 时才成功。
  3. 客户端不固定公钥:Yggdrasil 模式客户端传入 nil 公钥,仍能使用服务端实际公钥完成握手。
  4. 材质验签:合法签名通过;篡改 value、无签名、缺失 textures 全部拒绝;皮肤站轮换签名密钥后,缓存公钥自动刷新并通过。
  5. token 行为:token 缓存复用;/join 首次 403 后重新登录并重试成功;多角色未指定 player 时给出明确错误。
  6. 配置构建:Yggdrasil 模式生成随机密钥对并忽略 password;旧模式仍要求 password + profiles;非法 API URL / 凭据组合被拒绝。
  7. 旧模式回归:原有密码错误、状态查询、keep-alive、deadline、padding 等测试全部保留并通过。

说明:测试使用本地假 Yggdrasil 服务,没有连接真实皮肤站;真实 Blessing Skin 的接口路径与签名格式按 bs-community/blessing-skin-plugins 的 yggdrasil-api 插件实现对齐。

已知限制 / 后续工作

  • 当前只覆盖到 Login Success + Login Acknowledged;原版 1.20.2+ 的 Set Compression 和 Configuration 阶段尚未实现,因此暂不能直接连接真实 MC 服务端。本次改动先把标准 Yggdrasil 认证半段打通,后续再加压缩/configuration。
  • 材质验签目前默认严格开启,没有关闭开关;不提供 signaturePublickey 或不签 textures 的第三方实现会被拒绝。可以根据维护者意见增加显式配置项。
  • Yggdrasil 模式要求两端都能访问皮肤站 API;服务端每个新连接都会做 hasJoined 查询(有 10s 轮询上限)。
  • RSA 保持原版 1024-bit,未提升强度。

需要维护者确认的问题

  1. 是否接受 XMC 增加外部 Yggdrasil 依赖(登录与 hasJoined 都依赖皮肤站可用性)?
  2. Yggdrasil 模式下随机生成 RSA 密钥对(而不再从 password 派生)是否符合预期?是否希望保留一种“密码派生 + Yggdrasil”的混合模式?
  3. 是否接受默认严格验签?是否需要提供 verifyTextures: false 之类的 opt-out?
  4. 配置字段命名、yggdrasil 段是否应放在 xmc settings 内,还是拆到更高层?
  5. 是否希望拆分成多个 PR(登录 / 验签 / 文档)分别评审?

Agent 实现声明

  • 实现方式:由 Agent 编码完成。
  • Agent 客户端:DeepSeek Harness (DSH)。
  • 模型:deepseek-flash。
  • 提交信息中已注明 This commit is AI-generated.;欢迎维护者按项目对 AI 提交的要求调整。

English

Background and motivation

XMC's current login is bespoke:

  • The client configuration requires hand-copied username, uuid, texturesValue, and texturesSignature values (resolved manually from Mojang or a skin service).
  • The server authenticates with a pre-shared password (also used as the seed for a derived RSA key pair) plus a static profiles allow-list.
  • The pre-shared password is appended to the Verify Token, which has nothing to do with the Minecraft protocol itself.

This is costly to maintain and cannot reuse the standard Minecraft online-mode authentication ecosystem (Yggdrasil / authlib-injector / Blessing Skin). More importantly, a future Minecraft server-side mod that implements the XMC server (letting real MC clients or server mods speak XMC through standard Yggdrasil login) would only implement the standard authenticate / join / hasJoined flow; a pre-shared-password model cannot interoperate with it.

This change turns XMC into a standard Yggdrasil login client plus a standard hasJoined-verifying server, and adds texture signature verification. It paves the way for a future MC mod implementing the XMC server side, and lays the authentication groundwork for XMC clients to connect to real MC servers.

What changed

Files touched:

  • transport/internet/finalmask/xmc/yggdrasil.go (new: Yggdrasil HTTP client, login/refresh/join/hasJoined, signature verification)
  • transport/internet/finalmask/xmc/client.go (Yggdrasil login, vanilla hash, texture verification hook)
  • transport/internet/finalmask/xmc/server.go (hasJoined verification, random key pair, disconnect semantics)
  • transport/internet/finalmask/xmc/profile.go (multi-property read/write, identity/texture comparison)
  • transport/internet/finalmask/xmc/config.go, config.proto, config.pb.go
  • infra/conf/transport_finalmask.go (yggdrasil config parsing, random key generation, warning)
  • Tests: yggdrasil_test.go, profile_test.go, handshake_test.go, infra/conf/transport_finalmask_xmc_test.go

1. Configuration

A new optional yggdrasil block in XMC settings:

{
  "type": "xmc",
  "settings": {
    "hostname": "mc.example.com",
    "yggdrasil": {
      "api": "https://skin.example.com/api/yggdrasil",
      "username": "[email protected]",
      "password": "<skin account password>",
      "player": "Steve"
    }
  }
}
  • api: Yggdrasil API root (for example Blessing Skin's /api/yggdrasil).
  • username / password: client login credentials (email or player name, depending on the API implementation).
  • player: optional; required when the account owns multiple players.
  • The server only needs api; no account credentials.

In Yggdrasil mode the top-level password no longer participates in the handshake or key derivation. Configurations without a yggdrasil block keep their previous behavior.

2. Client (client.go / yggdrasil.go)

  • Logs in through authserver/authenticate; for multiple players it binds the token through authserver/refresh with selectedProfile. Tokens are cached per process, and a 403 from /join triggers one re-login retry.
  • Login Start uses the real player name and UUID returned by the skin service.
  • After encryption is negotiated, computes the vanilla login hash: sha1(serverId + sharedSecret + serverPublicKey), rendered like Java BigInteger#toString(16) (two's-complement sign, leading zeros trimmed).
  • Computes the hash with the public key actually received in Encryption Request and no longer pins the configured key. In Yggdrasil mode the client neither needs nor should "confirm" the server key.
  • Calls sessionserver/session/minecraft/join with the access token.
  • Parses multiple Login Success properties and verifies the textures property signature with the API root's signaturePublickey:
    • SHA1withRSA, matching Blessing Skin's default openssl_sign algorithm and the Minecraft client's signature validation.
    • Accepts PEM or raw base64 public keys.
    • Caches the key per account and refetches it once when verification fails (handles key rotation).
    • Missing, unsigned, or tampered textures are rejected.
    • Verification happens before Login Acknowledged, so a failure never enters the play phase.
  • Does not append a pre-shared password to the Verify Token in Yggdrasil mode, keeping the packet shape aligned with the vanilla client.

3. Server (server.go)

  • In Yggdrasil mode, generates a random 1024-bit RSA key pair per process (like a vanilla server) and no longer derives it from the password.
  • After decrypting the shared secret, computes the same login hash with its own actual public key and calls sessionserver/session/minecraft/hasJoined.
  • Because the client /join and the server /hasJoined race by nature, the server polls every 200 ms for up to 10 seconds.
  • Requires the returned player UUID and name to match Login Start.
  • Sends the signed properties returned by hasJoined (textures, uploadableTextures) in Login Success.
  • Disconnects with vanilla semantics: not joined → multiplayer.disconnect.unverified_username; API failure → multiplayer.disconnect.authservers_down.
  • Keeps the original pre-shared password + profiles allow-list when no yggdrasil block is configured.

4. Security model and warning

In Yggdrasil mode the binding happens inside the Yggdrasil lookup: if a MITM terminates two separate handshakes, the hash submitted by the client and the hash queried by the server necessarily differ, hasJoined returns nothing, and the connection fails. Pinning the server key is therefore unnecessary for MITM protection.

Because the transport no longer uses a pre-shared password or password-derived key, a warning is logged once at config load (errors.LogWarning):

XMC: Yggdrasil mode is enabled. The RSA key pair is generated randomly and "password"
is no longer used to derive it or to authenticate the transport; players are verified
through https://skin.example.com/api/yggdrasil (client /join, server /hasJoined).
Both ends must be able to reach the Yggdrasil API. The configured "password" is ignored.

Compatibility

  • Without yggdrasil: identical to the previous behavior (password-derived key + pre-shared password in the Verify Token + static profiles).
  • With yggdrasil: password is optional; when present it is ignored and a warning is printed.
  • Both peers must run a build containing this change; mixing old and new versions fails the handshake because the Verify Token shape differs (expected).
  • Requires a Yggdrasil API plugin on the skin service (for example Blessing Skin's yggdrasil-api; the API root must expose signaturePublickey).

Test plan and results

Environment: Linux (WSL2), Go 1.27.4, Xray-core c4561418 + this branch.

Step Command Result
XMC package tests go test ./transport/internet/finalmask/xmc/ pass
Race detector go test -race ./transport/internet/finalmask/xmc/ pass (~5.7s)
Config build tests go test ./infra/conf/ pass
Full build go build ./... pass
Protobuf freshness go run ./infra/vprotogen -pwd . -mode check pass

Coverage details:

  1. Known login-hash vectors: Notch / jeb_ / simon from the Java implementation (including a negative two's-complement hash) all match.
  2. End-to-end handshake: a fake Yggdrasil service (httptest) implements authenticate / refresh / join / hasJoined / API root; the client and server complete a full Minecraft handshake, succeeding only when client /join and server /hasJoined use the same hash.
  3. No key pinning: in Yggdrasil mode the client is constructed with a nil key and still completes the handshake using the server's actual key.
  4. Texture verification: a valid signature passes; tampered, unsigned, or missing textures are rejected; after the skin service rotates its key, the cached key is refreshed and verification succeeds.
  5. Token behavior: cached token is reused; a first /join 403 triggers re-login and a successful retry; multiple players without player produce a clear error.
  6. Config build: Yggdrasil mode generates a random key pair and ignores password; legacy mode still requires password + profiles; invalid API URLs or credential combinations are rejected.
  7. Legacy regression: existing tests for bad password, status query, keep-alive, deadlines, and padding are kept and pass.

Note: tests use a local fake Yggdrasil service rather than a live skin service; endpoint paths and signature formats are aligned with the yggdrasil-api plugin from bs-community/blessing-skin-plugins.

Known limitations / next steps

  • Only the Login Success + Login Acknowledged range is covered. The vanilla 1.20.2+ Set Compression and Configuration phases are not implemented yet, so connecting to a real MC server is not possible yet. This change establishes the standard Yggdrasil authentication half first; compression and configuration are follow-ups.
  • Texture verification is strict by default with no opt-out. Third-party implementations that do not expose signaturePublickey or do not sign textures are rejected. An explicit option can be added if maintainers prefer.
  • Yggdrasil mode requires both ends to reach the skin service API; the server performs a hasJoined lookup for every new connection (bounded by the 10s polling window).
  • RSA stays at the vanilla 1024-bit size; strength is not increased.

Questions for maintainers

  1. Is an external Yggdrasil dependency acceptable for XMC (login and hasJoined both depend on the skin service being reachable)?
  2. Is generating a random RSA key pair in Yggdrasil mode (instead of deriving it from password) the right trade-off? Would you prefer keeping a hybrid "password-derived + Yggdrasil" mode?
  3. Is strict texture verification by default acceptable? Should there be an opt-out such as verifyTextures: false?
  4. Are the configuration field names and the placement of the yggdrasil block inside xmc settings appropriate?
  5. Would you prefer this split into multiple PRs (login / verification / documentation) for review?

Agent disclosure

  • Implementation: written by an Agent.
  • Agent client: DeepSeek Harness (DSH).
  • Model: deepseek-flash.
  • Commits are marked with This commit is AI-generated.; adjust this disclosure as required by project policy.

Activity

  1. RPRX commented on Nov 13, 2026

    @RPRX
    Member

    我可以先把上一个 PR 合并了然后你先开个 PR 完成 #6769 (comment) ,没有问题吧?

  2. yandujun363 commented on Nov 14, 2026

    @yandujun363
    ContributorAuthor

    我可以先把上一个 PR 合并了然后你先开个 PR 完成 #6769 (comment) ,没有问题吧?

    我这边研究一下看看吧

  3. yandujun363 commented on Nov 14, 2026

    @yandujun363
    ContributorAuthor

    我可以先把上一个 PR 合并了然后你先开个 PR 完成 #6769 (comment) ,没有问题吧?

    我这边研究一下看看吧

    @RPRX 改了
    目前在yandujun363@bc39c47
    你看看有没有什么问题,没问题我再开接手,顺带目前这个PR还有一些问题

    1. 延迟不可取消,且没有实际上限 runPaddingSchedule 用 time.Sleep,不响应连接 Close、handshake deadline 或 context。现在 delay 可由配置决定,最坏可到 time.Duration 上限附近(约 292 年);连接关闭后 handshake goroutine 仍会睡到延迟结束才退出。建议后续改成可被 close/deadline 打断的 timer,或加一个合理上限。
    2. 自定义 paddings 是整体替换,不是只调“启动段” 省略 paddings 用 40 轮 preset;一旦配置,4 个 turn 就替代了全部 40 轮,包括后面 33 轮 join 尾段和 preset 的 chunk/write boundary。README 已写 “replaces”,但 PR 描述容易让人以为只是改启动长度;需要确认这是否是维护者本意。
    3. 交替方向上,delay 的 max 不一定体现在线上 receiver 只等 min;下一条 turn 若是对方发送,对方在 min 后即可发出。sender 随机到的 >min 只推迟它自己的下一步(读或发),不会让对端等到那个随机值。若期望线上间隔在 [min,max] 内抖动,这种两端无同步的随机是不可实现的;需要确认维护者只是要“至少 min”。
    4. 没有 turn 数量 / 总 padding 字节上限 每轮最大 8 MiB,但数组长度不限;误配可以产生数 GB 的握手数据或极长握手。配置是本地可信的,风险较低,但可考虑加总字节或轮数上限。
    5. paddings: [] 无法关闭 padding len(paddings)==0 会回落到 preset(原 README 也这么写);如果用户想“完全不 padding”,目前做不到。是否提供显式关闭选项需要确认。
    6. 没有“早到”检测 当前实现是“等 min 后再读/发”,不是“如果对端在 min 之前到达就失败”。若维护者说的“检查下一个 padding 是否到达”包含早到即报错,需要额外的 deadline/探测机制,目前没有。
    7. PR 正文/示例已过时 正文仍写 padding(单数)、没有 delay;开新 PR 时需要同步更新为 paddings + delay string 的示例。
    8. 原 int delay 的溢出隐患(已在我们这次修改中消掉) 原代码只检查 Delay < 0,然后 int(turn.Delay) 和 time.Duration(...) * time.Millisecond;在 32 位平台会截断,在 64 位大值会溢出,可能变成负 sleep 或错误时长。现在改为 delay_min/delay_max 并做上限校验。
    9. 原实现 receiver 完全不等待(已按维护者要求修掉) 交替方向上,下一条 padding 可能立即被发出,delay 实际只影响发送方自己的读时间。
    10. 原实现最后一个 turn 也会 sleep(已修掉) 最后一轮若由本端发送,会额外拖慢进入 proxy 的时间;现在两端都忽略最后一轮的 delay。
    11. 原 PR 没有 delay 时序测试(已补) 新增 TestPaddingScheduleDelayUsesSenderRangeAndReceiverMinimum,覆盖 sender 随机区间、receiver 等 min、最后一轮不等待。

    这边修改由deepseek-harness+deepseek-v4.1-flash处理

  4. RPRX commented on Nov 14, 2026

    @RPRX
    Member

    @spr334-a 很少上线,那就由你来接手 XMC 吧,这两天我会合并那个 PR,然后你开始 PR 就行

  5. yandujun363 commented on Nov 14, 2026

    @yandujun363
    ContributorAuthor

    @spr334-a 很少上线,那就由你来接手 XMC 吧,这两天我会合并那个 PR,然后你开始 PR 就行

    OK

  6. yandujun363 commented on Nov 15, 2026

    @yandujun363
    ContributorAuthor

    留个记录,记下后续要干嘛:

    灵感来源是 #6210 (comment) (人家都说要不整个模组了,但这边只是服务端在MC,客户端还是Xray)

    但这边如果要做就得让xray的xmc实现多版本兼容,并且兼容Fabric握手。
    如果不做多版本兼容目前只能在775实现

    仓库名称暂且叫xmc-server-lib和xmc-mcserver-core还有xmc-server-config 目前还没建,等这边的兼容
    lib负责和麻将的屎山代码交互,做出封装api
    core负责核心功能,依赖lib和config
    config负责配置加载

  7. yandujun363 commented on Nov 15, 2026

    @yandujun363
    ContributorAuthor
  8. yandujun363 commented on Nov 15, 2026

    @yandujun363
    ContributorAuthor

    补一个待处理点:MC 的压缩(和 Yggdrasil 无关,但会影响 XMC 客户端在默认服务端配置下的可用性)。

    • MC 在 Login 状态用 Set Compression(clientbound 0x03,threshold VarInt)协商 zlib,必须在 Login Success 之前发送;之后所有包都按 Packet Length + Data Length + body 走压缩,Configuration 里的 xmc:data / xmc:pad 也不例外。
    • 当前 XMC 客户端登录只处理 Login Success(0x02),遇到 0x03 会直接报错,所以服务端必须设 network-compression-threshold=-1;模组侧(Fabric)收发本身是压缩透明的,不用改。
    • 要在默认 256 下可用,需要:
      • 客户端 Login 处理 Set Compression,在 Login Success 前切到压缩 codec
      • 实现压缩 framing 读写(Data Length=0 的未压缩分支、threshold 边界、2^21-1 / 2^23 长度上限)
      • codec 覆盖 Login Success、Login Acknowledged、Configuration、padding、packetStream
      • 处理 padding 冲突:现在 padding 是全零,zlib 会压到几十字节,流量塑形基本失效;需要随机化 padding 或按压缩后的 wire profile 重标定 preset
      • 探针/测试覆盖 threshold=256 和 0
    • 备注:server.go 如果要模拟压缩服务端,也要自己发 Set Compression 并用同一套 codec。

    (仅记录,未开始改。)

  9. yandujun363 commented on Nov 15, 2026

    @yandujun363
    ContributorAuthor

    本地把压缩 codec 做了,落在 #7402 的 head 分支 takeover-6769 上(commit ba8aa05a,已 push 到 yandujun363/Xray-core,等上游合并):

    • transport/internet/finalmask/xmc/compression.go:压缩 framing 读写(Data Length=0 未压缩分支 + zlib 分支,2^21-1 包长 / 2^23 未压缩长度上限)
    • client.go:Login 里处理 Set Compression(0x03),在 Login Success 之前切 codec;threshold < 0 保持不压缩
    • compression_test.go:threshold 边界、分块写、多帧单次写、超阈值未压缩、非法帧
    • go build ./...、go test ./transport/internet/finalmask/... 全过

    为什么不做“无意义压缩”

    wiki 的原话是「未压缩的包超过 threshold 也接受」,所以不需要 Z_NO_COMPRESSION 那种“压缩了但没压小”的绕法:codec 只负责兼容,是否压缩交给 network-compression-threshold。

    实测

    环境:Fabric 26.1(协议 775)+ 模组 + authlib-injector(本地),Xray 客户端 → SOCKS → 本地 HTTP / 上传服务;回环,单次结果仅供参考。

    threshold 方向 大小 耗时 吞吐 校验
    256 下载 64 MiB 2.65–2.82 s 22.7–24.1 MB/s sha256 OK(3 次)
    65536 下载 64 MiB 2.03–2.14 s 29.9–31.6 MB/s sha256 OK(3 次)
    256 上传 64 MiB 4.37–4.92 s 13.0–14.7 MB/s 服务端算 sha256 OK(2 次)
    65536 上传 64 MiB 2.15–2.25 s 28.5–29.8 MB/s 服务端算 sha256 OK(2 次)
    256 下载 256 MiB 8.10–8.25 s 31.0–31.6 MB/s sha256 OK(2 次)
    65536 下载 256 MiB 5.40–5.62 s 45.6–47.4 MB/s sha256 OK(2 次)

    登录后先跑一个 10 字节文件,两种 threshold 下都正常,说明 Set Compression 之后的第一个包就已经按压缩 framing 解。

    观察

    1. 默认 256 下客户端不再报 bad login finished packet id: 3;Login Success / Login Acknowledged / Configuration / xmc:pad / xmc:data 全部走压缩帧,sha256 一致。
    2. 65536 下 xmc:pad(≤32767)和 xmc:data(≤24 KiB)都低于阈值,vanilla 直接发 Data Length=0 的未压缩帧,服务端照收——正好验证上面那句 wiki。
    3. 随机数据压缩的代价是实打实的:256 相对 65536,下载约慢 25–30%,上传约慢 50%(客户端单线程 zlib 压 24 KiB 随机块),而压缩收益≈0。所以“隧道数据压缩”就是白烧 CPU。
    4. 真正的语义差异在 padding:256 下 32 KiB 全零 pad 会被压到几十字节,padding 形状失效;65536 下保持原尺寸。所以部署上建议 network-compression-threshold=65536(或 -1),让 padding 和隧道数据不压、结构化大包(registry data)照常压。模组那条 “cannot read the login compression packet” 的 warning 已经过时,等这边合并后再去模组仓库改。

    和上面任务列表的对应

    • 客户端 Login 处理 Set Compression
    • 压缩 framing 读写(未压缩分支 / 边界 / 长度上限)
    • 覆盖 Login Success、Login Acknowledged、Configuration、padding、packetStream
    • padding 冲突:不改 padding 数据,用“高 threshold + 未压缩帧”保住形状(另一种做法是随机化 padding + 重标定 preset,暂时不做)
    • 测试:E2E 覆盖 256 和 65536;threshold=0(全部压缩)只在单测里覆盖,没有单独跑 E2E

    备注

    • 这次 E2E 用的是本地构建:XMC finalmask: Switch to native frame padding (breaking); delay supports range (receiver waits at least minimal ms) #7402 分支 + 临时合入 Yggdrasil 草案(仅本地,没 push),因为 Fabric 模组需要 online-mode 的 Yggdrasil 登录。codec 本身和 Yggdrasil 无关。
    • server.go 侧没动:如果以后 Xray 自己当 XMC 服务端,需要自己发 Set Compression 并复用同一套 codec。
    • 2026-11-15 22:35 更新:重测修正了阈值归属与吞吐。之前那版数字因为旧 Fabric JVM 没退出,部分“256”实际打到了 65536 的服务端上,以本表为准。
  10. caldwell-gh commented on Nov 15, 2026

    @caldwell-gh

    Yggdrasil不就是littleskin用的吗,除此之外还有哪个呢,我目前都没见到过用Yggdrasil登录的服务器,相比之下authlib出现的还多点,这样做比原来还麻烦

  11. yandujun363 commented on Nov 15, 2026

    @yandujun363
    ContributorAuthor

    Yggdrasil不就是littleskin用的吗,除此之外还有哪个呢,我目前都没见到过用Yggdrasil登录的服务器,相比之下authlib出现的还多点,这样做比原来还麻烦

    为了伪装(原版MC显然不认识密码派生)
    为了防护显然得上Yggdrasil
    并且我公会里的MC服务器就是Yggdrasil,并不是littleskin在用

  12. caldwell-gh commented on Nov 15, 2026

    @caldwell-gh

    为了伪装(原版MC显然不认识密码派生) 为了防护显然得上Yggdrasil 并且我公会里的MC服务器就是Yggdrasil,并不是littleskin在用

    那也不一定要用第三方登录呀,mc正版验证确实是主流,特别是在中国以外,而且原xmc加密也够安全

  13. RPRX commented on Nov 15, 2026

    @RPRX
    Member

    不惜冒着 GFW 干脆一条规则 ban 掉 25565 的风险也要为 XMC 作出贡献,先生大义,Update:查了下这里提的那些东西可能不是 TCP/25565

    那就更好了,总之 XMC 就是有人有新的想法的话随便造,说实话我都没研究过 MC、无法深度 review,但技多不压身,Xray 多条姿势多条路

    毕竟年初频道消息 https://t.me/projectXtls/1473 直接点名了 MC 所以它不得不首当其冲了,另外我比较希望 XMC 能代表过游戏加速器这条路

    即使过不了也没逝,反正 P2P 逃不掉的 #6210 (comment) ,就是不知道 GTA6 的 Online 模式还是不是 P2P,GFW:?游戏加速器也算翻墙哦


    顺便捕捉到了关键字 WebRTC 这整挺好,也算是互联网上的常见协议了吧,XWEBRTC/XSRTP 预定,应该是做前者吧,感觉能穿透的东西更多

    我研究一下,顺便也该把浏览器走 HTTP 代理时的 WebRTC 泄露纳入 core 的考虑范围内,这个问题必须得到解决,能从 core 的层面解决更好

  14. Exclude0122 commented on Nov 15, 2026

    @Exclude0122
    Contributor

    每次新建连接,都要等客户端+服务端和 Yggdrasil 服务器通信,延迟不会爆炸吗?

    客户端配置里手工填写 username / uuid / texturesValue / texturesSignature(需要自己去 Mojang 或皮肤站查 UUID、拉签名材质再复制进配置);

    可以 vibe 一个网页或 cli 自动通过正版 username 获取 uuid / texturesValue / texturesSignature,生成 xray json 配置

    服务端用预共享 password(同时作为 RSA 私钥的派生种子)加静态 profiles 白名单校验;
    Verify Token 尾部追加预共享密码,和 Minecraft 协议本身没有关系。

    通过密码派生 RSA 是为了防止 MITM(之前是客户端写死 RSA 公钥,风扇说太麻烦了就改成派生了),Verify Token 本身有 padding,所以加点东西也看不出来。这么做就是为了避免和 Yggdrasil 通信增加延迟。

    维护成本高,且无法复用 Minecraft 生态已有的标准在线模式认证(Yggdrasil / authlib-injector / Blessing Skin)。更重要的是,如果后续要给 MC 模组实现 XMC 服务端(让真实 MC 客户端或服务端模组走标准 Yggdrasil 登录接入 XMC),预共享密码模型无法对接,因为模组侧只会实现标准的 authenticate / join / hasJoined 流程。

    都写客户端 mod 了,直接 mixin 改登陆的代码,把 password 密钥加到 verify token 不就行了

  15. Exclude0122 commented on Nov 15, 2026

    @Exclude0122
    Contributor

    不惜冒着 GFW 干脆一条规则 ban 掉 25565 的风险也要为 XMC 作出贡献

    现在好多高校都上了墙中墙,XMC 说不定可以过这种墙中墙。过 GFW 可以接着用 reality xhttp 之类的,用不着 XMC

    https://minecraft.wiki/w/Mojang_API#Peer-to-peer_multiplayer_networking

    刚才发现了这个 mojang p2p 的 API 文档,有没有人去试试能不能用 🤣

  16. yandujun363 commented on Nov 16, 2026

    @yandujun363
    ContributorAuthor

    所以 #7402 可以合了吗
    因为我思考了一下还有处理

    所以 #7416 再等等

  17. spr334-a commented on Nov 16, 2026

    @spr334-a
    Contributor

    用Yggdrasil第三方认证不够隐私吧,客户端每次连接都要向皮肤站调join 服务端要调用hasJoined
    这样皮肤站能看到客户端的账号和ip,也能看到服务端的ip

  18. yandujun363 commented on Nov 16, 2026

    @yandujun363
    ContributorAuthor

    用Yggdrasil第三方认证不够隐私吧,客户端每次连接都要向皮肤站调join 服务端要调用hasJoined 这样皮肤站能看到客户端的账号和ip,也能看到服务端的ip

    那就自建,我记得有一个最小化Yggdrasil,不一定要完整皮肤站,可以试试看authlib-skin、Fraxinus、MineSkin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions