From 00965e19d20e8a0e2cd4ebc7968fc3f9cc5bc944 Mon Sep 17 00:00:00 2001 From: AskaEth Date: Wed, 11 Nov 2026 22:00:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(core):=20trust.rs=20=E7=9A=84=20PinnedKey?= =?UTF-8?q?=20=E4=BA=A4=E5=9B=9E=20rustfmt=20=E6=8E=92=E7=89=88=EF=BC=88?= =?UTF-8?q?=E5=A4=9A=E8=A1=8C=E5=AD=97=E6=AE=B5=EF=BC=89+=20=E8=87=AA?= =?UTF-8?q?=E6=B5=8B=E9=94=81=E4=BD=8F=E5=A4=9A=E8=A1=8C=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v0.2.4 推 main 后 CI 的 fmt job 红:cargo fmt --all --check 退出码 1,唯一 diff 在 crates/core/src/update/trust.rs:60 —— PRODUCTION 里那条 PinnedKey 被写成单行。 * trust.rs:由 `cargo fmt --all` 直接生成(不是手写对齐)。git diff 只有这一处; 两个 PINNED-KEYS 标记行的字形与行位置未动;public_key_hex 与 HEAD 逐字比对 identical。 * sign_manifest.py --self-test:补一条多行(rustfmt)形态样例的解析断言。解析器本身无需改 (KID_RE 字段之间是 \s*,本来就跨行),但旧自测只喂单行样例 —— 变异重放(换成单行整行正则) 时旧自测全绿、新断言红,正是这次事故的形状。 验证(真实退出码):cargo fmt --all --check = 0;python packaging/sign_manifest.py --check-pinned-keyring --key <私钥路径> = 0;signing_ready_selftest.py = 0; signing_ready_wiring_selftest.py = 0;sign_manifest.py --self-test = 0; cargo test -p unlucky-core --lib update = 0(114 passed / 0 failed)。 --- crates/core/src/update/trust.rs | 5 ++++- packaging/sign_manifest.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/core/src/update/trust.rs b/crates/core/src/update/trust.rs index 94f26f7..a4992cc 100644 --- a/crates/core/src/update/trust.rs +++ b/crates/core/src/update/trust.rs @@ -60,7 +60,10 @@ pub(crate) struct PinnedKey { /// (`packaging/sign_manifest.py --check-pinned-keyring` 按标记解析这一段,标记变了它就找不到表)。 pub(crate) const PRODUCTION: &[PinnedKey] = &[ // >>> PINNED-KEYS >>> - PinnedKey { key_id: "ull-release", public_key_hex: "1c3687ecd656a29fda87a7afb56e07d2b9e223b62cf3a6f1a901fb499a97b122" }, + PinnedKey { + key_id: "ull-release", + public_key_hex: "1c3687ecd656a29fda87a7afb56e07d2b9e223b62cf3a6f1a901fb499a97b122", + }, // <<< PINNED-KEYS <<< ]; diff --git a/packaging/sign_manifest.py b/packaging/sign_manifest.py index 0984304..45fddea 100644 --- a/packaging/sign_manifest.py +++ b/packaging/sign_manifest.py @@ -256,6 +256,12 @@ def do_self_test() -> int: if pinned_keys(sample) != [("k1", "ab" * 32)]: print("FAIL: pinned_keys() 没解析出示例条目", file=sys.stderr) failures += 1 + # 多行形态(M261):`trust.rs` 里那一条是 `cargo fmt` 生成的,字段一行一个 —— 靠 `KID_RE` 的 `\s*` + # 跨行命中。若解析器退化成按行匹配,一次 fmt 就会把整张信任表**静默**读成空表(= 全量客户端验签失败)。 + multiline = f'{PIN_BEGIN}\n PinnedKey {{\n key_id: "k1",\n public_key_hex: "{"ab" * 32}",\n }},\n{PIN_END}' + if pinned_keys(multiline) != [("k1", "ab" * 32)]: + print("FAIL: pinned_keys() 没解析出多行(rustfmt)形态的条目", file=sys.stderr) + failures += 1 if pinned_keys(f"{PIN_BEGIN}\n{PIN_END}") != []: print("FAIL: pinned_keys() 在空表上应返回空", file=sys.stderr) failures += 1