Skip to content

Support SVCB/HTTPS SvcParams presentation format from DoH (fixes #22) - #23

Merged
fjh1997 merged 1 commit into
fjh1997:mainfrom
gui16789:fix/ech-svcb-presentation-format
Aug 16, 2026
Merged

Support SVCB/HTTPS SvcParams presentation format from DoH (fixes #22)#23
fjh1997 merged 1 commit into
fjh1997:mainfrom
gui16789:fix/ech-svcb-presentation-format

Conversation

@gui16789

Copy link
Copy Markdown

背景

修复 #22:默认配置下(doh_endpoints = ["https://aaa.ddd.oaifree.com/query-dns"])访问 linux.do 返回 502,日志显示 ech=no

根因

src/proxy.rsparse_https_answer 只接受 RFC 3597 \# <len> <hex> 格式。但实测的主流 DoH(oaifree query-dns、cloudflare-dns.com、1.1.1.1)对 type=65 (HTTPS) 均返回 RFC 9460 presentation 文本格式

{"name":"linux.do","type":65,"data":"1 . alpn=h3,h2 ipv4hint=104.20.16.234,172.66.166.61 ech=AEX+DQBB5wAg... ipv6hint=..."}

strip_prefix("\\#") 失败 → HTTPS RR 解析报错 → 绑定列表为空 → ECH 配置不可用 → ECH 强制模式下直接 502。

修改

  1. 将 wire 解析提取为 parse_https_answer_wire
  2. 新增 encode_https_answer_svc_params:把 SVCB/HTTPS SvcParams presentation 格式(priority target key=value...)编码为 wire 字节,支持 mandatory / alpn / no-default-alpn / port / ipv4hint / ech / ipv6hint,未知键按 keyNNNN 处理并作 base64 解码;
  3. base64 兼容标准/URL-safe 字母表,无填充或有填充均可;
  4. 新增 4 个单元测试(RFC 3597 hex、presentation 格式、带 target name、非法输入);
  5. 更新 CHANGELOG.md,新增 base64 = "0.22" 依赖。

验证

  • cargo check 通过;
  • cargo test 23 个测试全部通过(含新增的 4 个 HTTPS RR 解析测试);
  • 本地桥接验证(issue 作者的对照实验):presentation 格式解析成功后日志为 ech=yes,ECH + HTTP/2 链路打通。

作者此前已在 issue 中确认解析器与 ECH 握手链路本身正常,问题仅在 presentation 格式支持缺失。

Some DoH servers (e.g. private query-dns endpoints) return HTTPS RR
answers in RFC 9460 presentation format (e.g. "1 . alpn=h3,h2
ech=AEX+...") instead of RFC 3597 \# <len> <hex>. This caused
parse_https_answer to fail and ECH to be unavailable (502 with
default config).

Refactor the wire parsing into parse_https_answer_wire and add an
encoder that translates the presentation format into wire bytes,
covering mandatory/alpn/no-default-alpn/port/ipv4hint/ech/ipv6hint.
Fixes fjh1997#22.
@fjh1997

fjh1997 commented Aug 16, 2026

Copy link
Copy Markdown
Owner

wow,谢谢你的贡献,赞一个!

@fjh1997
fjh1997 merged commit 99643bf into fjh1997:main Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants