fix(m190): r1 复审——0x01 修成 \1 + YAML 门禁、被调方声明 secret、拆两个超限测试文件、验签换 ed25519-dalek

四条 P1 + 四条 P2 一并处置(不变的是判据,变的是「谁在承重」)。

P1-1 `.github/workflows/release-build.yml` 的 sed 替换串是裸 0x01(本意 `\1`):GitHub 解析该文件会
失败 ⇒ 整个 run 起不来;即便容忍,版本号也会被求值成单字节,PE 判据报「与 Cargo.toml 不同源?」把
排障引向错方向。修成字面 `\1`,并新增 `packaging/check_workflows_yaml.py`(真 YAML 解析器 parse
全部 workflow + 裸 C0 控制字符字节判据;带 --self-test 注入 0x01/坏结构断言必红),接进
`release-guard.yml` 两步。文本扫描型守卫看不见这类字节,这道门禁专门挡它。

P1-2 `release-publish.yml` 没在 `on.workflow_call.secrets` 里声明 `ULL_MANIFEST_SIGNING_KEY`,调用方
却传了:可复用工作流只拿得到自己声明过的 secret ⇒ 用户配好钥也会在签名步红,而错误文案反过来指控
Secret 没配。补声明(required: false,fail-closed 由步内 ::error:: + exit 1 承担,同
ULL_MSA_CLIENT_ID 的模式)。

P1-3 两个测试支撑文件越过 400 行守卫:签名夹具拆到 `tests/support_sign.rs`(support.rs 458→392),
CLI e2e 的签名部分拆到 `support/update_e2e_sign.rs`(update_e2e.rs 406→348)。纯搬家。

P2-2 「唯一收口点」改成结构事实:从 `UpdateSource` 删掉 `fetch_manifest` 默认实现,调用方只能拿
`verified_manifest(&source, channel)`(源只交原文,想绕过验签就得自己重写解析与渠道判据)。
P2-3 文档写的第 ④ 条命令补进流水线:`sign_manifest.py --verify-pinned` 用 trust.rs 里钉住的公钥
回验刚落盘的 .sig(不碰私钥),发布侧因此验证的是「客户端的判据」而不是「签名脚本的自我声明」。
P2-4 随自写实现一起删除(`Fe` 的错误 PartialEq 不再存在)。
P2-5 app-iced/build.rs 注释里那个 windows_subsystem 属性本分支不存在(M196 才有),改为说明
「本文件只写版本资源,子系统由 rustc 属性决定,check_pe_version.py 会把 subsystem 打出来」。
P2-6 坏清单不再带 error.path 是有意降级(来源 id 在 message 里),保持。

裁定项:自写 Ed25519 换成 `ed25519-dalek::verify_strict`(信任锚不许自写密码学;此刻信任表还是空表,
零兼容负担)。删除 `update/ed25519/{field,group,mod}.rs`(含只服务它们的单测),新 `update/ed25519.rs`
只剩一个薄封装;拒绝类用例(可锻 S+L / 小阶公钥 / 非规范 R / 空签名 / 未知 key)**一条没删**,
改成钉 dalek 的 strict 语义——实测 dalek 对全部五类的结论与旧实现一致(非规范 R 的拒绝理由不同:
dalek 走「小阶点」而非「编码非规范」,用例注释里写明)。签名侧留在 `packaging/ed25519_ref.py`
(纯 Python、零 pip 依赖),`--self-test` 用 RFC 8032 同一组向量钉两边。
This commit is contained in:
AskaEth committed 2026-11-09 02:14:32 +08:00
1 parent b7d9b99e12
commit 918d826645
28 files changed
+860 -1085

No files matched your search

+143
View File
@@ -0,0 +1,143 @@
#!/usr/bin/env python3
"""Parse every workflow file with a **real YAML parser** (M190 r1 复审 P1-1).
Why this exists: a raw 0x01 byte slipped into `.github/workflows/release-build.yml` (a `sed` replacement
string that should have been `\\1`). GitHub refuses to parse such a file, so the whole run would not even
start — and no other guard noticed, because they all read workflow files as *text* (`check_release_semantics.py`
does `yaml_scalars()`, the file-size job only counts lines). A text scanner cannot see a control byte that
a YAML 1.2 reader rejects outright.
So: hand every `.github/workflows/*.yml` to PyYAML. Two checks, both cheap:
① it parses (real error message with position, not a mystery red);
② no C0 control character other than TAB/LF/CR is present (YAML 1.2 forbids them; parsers differ in
whether they reject, so this is the belt-and-braces half).
PyYAML is preinstalled on GitHub-hosted runners; if it is not, this script installs it. If that fails too
the gate **fails** rather than degrading to a text scan ("工具缺失也 fail" — same rule as the other guards).
python3 packaging/check_workflows_yaml.py
python3 packaging/check_workflows_yaml.py --self-test
"""
from __future__ import annotations
import argparse
import subprocess
import sys
from pathlib import Path
WORKFLOW_DIR = Path(__file__).resolve().parent.parent / ".github/workflows"
ALLOWED_CONTROL = {0x09, 0x0A, 0x0D}
def load_yaml():
"""Import PyYAML, installing it once if the runner lacks it."""
try:
import yaml # noqa: PLC0415
return yaml
except ImportError:
print("PyYAML 缺失,尝试安装一次(pip install --quiet pyyaml)…", file=sys.stderr)
done = subprocess.run(
[sys.executable, "-m", "pip", "install", "--quiet", "pyyaml"],
capture_output=True,
text=True,
check=False,
)
if done.returncode != 0:
print(
"error: 装不上 PyYAML,YAML 门禁无法运行(门禁不降级)。输出:\n" + done.stdout + done.stderr,
file=sys.stderr,
)
raise SystemExit(2) from None
import yaml # noqa: PLC0415
return yaml
def control_characters(data: bytes) -> list[tuple[int, int]]:
"""`[(位置, 字节)]`:YAML 1.2 不许出现的 C0 控制字符(TAB/LF/CR 除外)。"""
return [(index, byte) for index, byte in enumerate(data) if byte < 0x20 and byte not in ALLOWED_CONTROL]
def check_file(path: Path, yaml) -> list[str]:
"""返回该文件没过的判据(空 = 通过)。"""
failures: list[str] = []
data = path.read_bytes()
for index, byte in control_characters(data):
line = data[:index].count(b"\n") + 1
failures.append(
f"::error file={path},line={line}::第 {line} 行含裸控制字符 {byte:#04x}(YAML 1.2 禁止;"
"常见成因是 sed/printf 把 `\\1` 写成了 0x01)"
)
try:
text = data.decode("utf-8")
except UnicodeDecodeError as error:
failures.append(f"::error file={path}::不是合法 UTF-8({error})")
return failures
try:
yaml.safe_load(text)
except Exception as error: # noqa: BLE001 - 解析器的异常类型随版本变,这里只关心「没通过」
first = str(error).splitlines()[0] if str(error) else repr(error)
failures.append(f"::error file={path}::YAML 解析失败:{first}")
return failures
def self_test() -> int:
"""注入一枚 0x01 到临时副本,断言门禁**会红**(否则这条门禁对任何输入都绿)。"""
import tempfile
yaml = load_yaml()
failures = 0
sample = "name: x\non: push\njobs:\n a:\n runs-on: ubuntu-latest\n steps:\n - run: |\n echo hi\n"
with tempfile.TemporaryDirectory() as tmp:
good = Path(tmp) / "good.yml"
good.write_text(sample, encoding="utf-8")
if check_file(good, yaml):
print("FAIL: 合法 YAML 被判红(误杀)", file=sys.stderr)
failures += 1
bad = Path(tmp) / "bad.yml"
bad.write_bytes(sample.replace('"/\\1/p"', "").encode("utf-8") + b'x\n v=$(s/"' + bytes([1]) + b'/p)\n')
if not check_file(bad, yaml):
print("FAIL: 含裸 0x01 的 YAML 竟然通过(判据失效)", file=sys.stderr)
failures += 1
# 只让 PyYAML 判的那一半也要能红:把控制字节换成合法字符,但结构坏掉。
broken = Path(tmp) / "broken.yml"
broken.write_text("a: [1, 2\nb: 3\n", encoding="utf-8")
if not check_file(broken, yaml):
print("FAIL: 结构坏的 YAML 竟然通过", file=sys.stderr)
failures += 1
print("self-test:", "ok" if failures == 0 else f"{failures} 处失败")
return 0 if failures == 0 else 1
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description="用真 YAML 解析器 parse 全部 workflow(M190 r1 P1-1)")
parser.add_argument("--self-test", action="store_true", help="自检:注入 0x01 / 坏结构必须红")
parser.add_argument("--dir", type=Path, default=WORKFLOW_DIR, help="workflow 目录(默认 .github/workflows)")
args = parser.parse_args(argv)
if args.self_test:
return self_test()
yaml = load_yaml()
files = sorted(args.dir.glob("*.yml")) + sorted(args.dir.glob("*.yaml"))
if not files:
print(f"error: {args.dir} 里一个 workflow 都没有(路径错了?门禁不降级)", file=sys.stderr)
return 2
failures: list[str] = []
for path in files:
failures.extend(check_file(path, yaml))
for line in failures:
print(line, file=sys.stderr)
if failures:
print(f"FAIL:{len(failures)} 条判据没过({len(files)} 个文件)", file=sys.stderr)
return 1
print(f"ok: {len(files)} 个 workflow 全部能被真 YAML 解析器 parse,且无裸控制字符")
return 0
if __name__ == "__main__":
raise SystemExit(main())