Skip to content

Commit de24874

Browse files
fix(desktop): wire trusted Developer ID team through upgrades
Keep Developer ID verification fail-closed when the publisher team is unconfigured. Pass the compile-time team from the packaging identity through download, revalidation and install. Fixes higress-group#218 Signed-off-by: nillikechatchat <yuanhenglizhen2050@163.com> Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
1 parent d5b8aba commit de24874

8 files changed

Lines changed: 161 additions & 63 deletions

File tree

‎apps/desktop/src-tauri/src/updates.rs‎

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//! Native updater lifecycle. WebView chooses actions; source, paths and trust stay native.
22
use hiroute_host_runtime::{
3-
DesktopPackageIdentity, DesktopRelease, UpgradeAction, verify_desktop_app,
3+
DesktopPackageIdentity, DesktopRelease, UpgradeAction, trusted_developer_id_team,
4+
verify_desktop_app,
45
};
56
use serde::Serialize;
67
use std::{
7-
path::PathBuf,
8+
path::{Path, PathBuf},
89
sync::{
910
Arc, Mutex,
1011
atomic::{AtomicBool, Ordering},
@@ -26,19 +27,28 @@ struct PreparedUpdate {
2627
}
2728
impl PreparedUpdate {
2829
fn revalidate(&self) -> Result<(), String> {
29-
if verify_desktop_app(&self.current, "ai.hiroute.desktop", None, None)? != self.old_identity
30-
|| verify_desktop_app(
31-
&self.staged,
32-
"ai.hiroute.desktop",
33-
Some(&self.release),
34-
None,
35-
)? != self.new_identity
30+
if verify_update_package(&self.current, None)? != self.old_identity
31+
|| verify_update_package(&self.staged, Some(&self.release))? != self.new_identity
3632
{
3733
return Err("UPGRADE_PACKAGE_CHANGED".into());
3834
}
3935
Ok(())
4036
}
4137
}
38+
39+
fn verify_update_package(
40+
app: &Path,
41+
release: Option<&DesktopRelease>,
42+
) -> Result<DesktopPackageIdentity, String> {
43+
verify_desktop_app(
44+
app,
45+
"ai.hiroute.desktop",
46+
release,
47+
trusted_developer_id_team(),
48+
)
49+
.map_err(str::to_owned)
50+
}
51+
4252
#[derive(Clone, Copy, Serialize)]
4353
#[serde(rename_all = "snake_case")]
4454
pub enum UpdateRecovery {
@@ -468,3 +478,22 @@ async fn recover_precommit(
468478
_ => UpdateRecovery::RestartRequired,
469479
}
470480
}
481+
482+
#[cfg(test)]
483+
mod trusted_publisher_tests {
484+
use super::*;
485+
486+
#[test]
487+
fn update_verifier_uses_compile_time_team_and_stays_host_owned() {
488+
assert_eq!(
489+
trusted_developer_id_team(),
490+
option_env!("HIROUTE_DEVELOPER_ID_TEAM").filter(|team| !team.is_empty())
491+
);
492+
let error = verify_update_package(Path::new("/"), None).unwrap_err();
493+
if cfg!(target_os = "macos") {
494+
assert_ne!(error, "UPGRADE_PLATFORM_UNSUPPORTED");
495+
} else {
496+
assert_eq!(error, "UPGRADE_PLATFORM_UNSUPPORTED");
497+
}
498+
}
499+
}

‎apps/desktop/src-tauri/src/updates/download.rs‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Bounded native download and read-only DMG staging; existing work keeps running throughout.
22
use super::{PreparedUpdate, Updates};
33
use hiroute_host_runtime::{
4-
DesktopRelease, MAX_RELEASE_FEED_BYTES, RELEASE_FEED, WebsiteReleasesV2, verify_desktop_app,
4+
DesktopRelease, MAX_RELEASE_FEED_BYTES, RELEASE_FEED, WebsiteReleasesV2,
55
};
66
use sha2::{Digest, Sha256};
77
use std::{fs, io::Write, path::Path, process::Command, sync::atomic::Ordering, time::Duration};
@@ -143,7 +143,7 @@ pub(super) async fn prepare(
143143
let mount = download_root.join("volume");
144144
let selected = release.clone();
145145
let (old_identity, new_identity) = tokio::task::spawn_blocking(move || {
146-
let old = verify_desktop_app(&source, "ai.hiroute.desktop", None, None)?;
146+
let old = super::verify_update_package(&source, None)?;
147147
let new = stage_dmg(&image, &mount, &next, &selected)?;
148148
Ok::<_, String>((old, new))
149149
})
@@ -219,14 +219,9 @@ fn stage_dmg(
219219
return Err("UPGRADE_DMG_INVALID".into());
220220
}
221221
let app = mount.join("HiRoute.app");
222-
verify_desktop_app(&app, "ai.hiroute.desktop", Some(release), None)?;
222+
super::verify_update_package(&app, Some(release))?;
223223
command("/usr/bin/ditto", &[app.as_os_str(), staged.as_os_str()])?;
224-
Ok(verify_desktop_app(
225-
staged,
226-
"ai.hiroute.desktop",
227-
Some(release),
228-
None,
229-
)?)
224+
Ok(super::verify_update_package(staged, Some(release))?)
230225
})();
231226
let detached = command("/usr/bin/hdiutil", &[O::new("detach"), mount.as_os_str()]);
232227
if detached.is_err() {

‎apps/desktop/src-tauri/src/updates/installer.rs‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,10 @@ fn finish(path: &Path, record: Handoff) -> Result<(), String> {
242242
}
243243

244244
fn verify_packages(record: &Handoff) -> Result<(), String> {
245-
if hiroute_host_runtime::verify_desktop_app(&record.current, "ai.hiroute.desktop", None, None)?
245+
if super::verify_update_package(&record.current, None)?
246246
!= record.old_identity
247-
|| hiroute_host_runtime::verify_desktop_app(
248-
&record.staged,
249-
"ai.hiroute.desktop",
250-
Some(&record.release),
251-
None,
252-
)? != record.new_identity
247+
|| super::verify_update_package(&record.staged, Some(&record.release))?
248+
!= record.new_identity
253249
{
254250
return Err("UPGRADE_PACKAGE_CHANGED".into());
255251
}

‎crates/host-runtime/src/desktop_package.rs‎

Lines changed: 86 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -230,20 +230,38 @@ fn tool(program: &str, args: &[&std::ffi::OsStr]) -> Result<String, &'static str
230230
String::from_utf8(bytes).map_err(|_| "PACKAGE_VERIFY_FAILED")
231231
}
232232

233-
/// `None` still requires a present TeamIdentifier plus Developer ID Application.
234-
/// A pinned team, when supplied, must match that identifier exactly.
233+
/// Apple Team ID baked in at compile time by the trusted packaging identity.
234+
/// A candidate package cannot supply this value.
235+
pub fn trusted_developer_id_team() -> Option<&'static str> {
236+
option_env!("HIROUTE_DEVELOPER_ID_TEAM").filter(|team| !team.is_empty())
237+
}
238+
239+
/// Self-signed packages stay adhoc. Developer ID requires a configured matching team.
235240
#[cfg(any(target_os = "macos", test))]
236-
fn developer_id_signature_ok(signature: &str, expected_team: Option<&str>) -> bool {
237-
let Some(team) = signature.lines().find_map(|line| {
238-
line.strip_prefix("TeamIdentifier=")
239-
.filter(|team| !team.is_empty() && *team != "not set")
240-
}) else {
241-
return false;
242-
};
243-
if expected_team.is_some_and(|expected| expected != team) {
244-
return false;
241+
fn publisher_identity_status(
242+
distribution: &str,
243+
signature: &str,
244+
expected_team: Option<&str>,
245+
) -> Result<(), &'static str> {
246+
if distribution == "controlled-trial" {
247+
if signature.lines().any(|line| line == "Signature=adhoc") {
248+
Ok(())
249+
} else {
250+
Err("PACKAGE_SIGNATURE_IDENTITY_MISMATCH")
251+
}
252+
} else {
253+
let team = expected_team
254+
.filter(|team| !team.is_empty())
255+
.ok_or("UPGRADE_SIGNATURE_IDENTITY_UNCONFIGURED")?;
256+
let expected = format!("TeamIdentifier={team}");
257+
if signature.lines().any(|line| line == expected)
258+
&& signature.contains("Authority=Developer ID Application:")
259+
{
260+
Ok(())
261+
} else {
262+
Err("PACKAGE_SIGNATURE_IDENTITY_MISMATCH")
263+
}
245264
}
246-
signature.contains("Authority=Developer ID Application:")
247265
}
248266

249267
#[cfg(target_os = "macos")]
@@ -317,14 +335,8 @@ pub fn verify_desktop_app(
317335
identity.app_path.as_os_str(),
318336
],
319337
)?;
320-
if identity.distribution == "controlled-trial" {
321-
if !signature.lines().any(|l| l == "Signature=adhoc") {
322-
return Err("PACKAGE_SIGNATURE_IDENTITY_MISMATCH");
323-
}
324-
} else {
325-
if !developer_id_signature_ok(&signature, expected_team) {
326-
return Err("PACKAGE_SIGNATURE_IDENTITY_MISMATCH");
327-
}
338+
publisher_identity_status(&identity.distribution, &signature, expected_team)?;
339+
if identity.distribution != "controlled-trial" {
328340
tool(
329341
"/usr/sbin/spctl",
330342
&[
@@ -426,26 +438,64 @@ mod tests {
426438
}
427439

428440
#[test]
429-
fn developer_id_signature_requires_present_team_without_pinning() {
441+
fn trusted_developer_id_team_matches_compile_time_env() {
442+
assert_eq!(
443+
trusted_developer_id_team(),
444+
option_env!("HIROUTE_DEVELOPER_ID_TEAM").filter(|team| !team.is_empty())
445+
);
446+
}
447+
448+
#[test]
449+
fn developer_id_requires_configured_matching_team_and_keeps_self_signed() {
430450
let signature = "\
431451
Authority=Developer ID Application: Example Org (ABCD123456)
432452
Authority=Developer ID Certification Authority
433453
TeamIdentifier=ABCD123456
434454
";
435-
assert!(developer_id_signature_ok(signature, None));
436-
assert!(developer_id_signature_ok(signature, Some("ABCD123456")));
437-
assert!(!developer_id_signature_ok(signature, Some("OTHERTEAM1")));
438-
assert!(!developer_id_signature_ok(
439-
"Signature=adhoc\nTeamIdentifier=not set\n",
440-
None
441-
));
442-
assert!(!developer_id_signature_ok(
443-
"Authority=Developer ID Application: Example Org (ABCD123456)\n",
444-
None
445-
));
446-
assert!(!developer_id_signature_ok(
447-
"TeamIdentifier=ABCD123456\n",
448-
None
449-
));
455+
assert_eq!(
456+
publisher_identity_status("developer-id", signature, None),
457+
Err("UPGRADE_SIGNATURE_IDENTITY_UNCONFIGURED")
458+
);
459+
assert_eq!(
460+
publisher_identity_status("developer-id", signature, Some("")),
461+
Err("UPGRADE_SIGNATURE_IDENTITY_UNCONFIGURED")
462+
);
463+
assert_eq!(
464+
publisher_identity_status("developer-id", signature, Some("ABCD123456")),
465+
Ok(())
466+
);
467+
assert_eq!(
468+
publisher_identity_status("developer-id", signature, Some("OTHERTEAM1")),
469+
Err("PACKAGE_SIGNATURE_IDENTITY_MISMATCH")
470+
);
471+
assert_eq!(
472+
publisher_identity_status(
473+
"developer-id",
474+
"Authority=Developer ID Application: Example Org (ABCD123456)\n",
475+
Some("ABCD123456")
476+
),
477+
Err("PACKAGE_SIGNATURE_IDENTITY_MISMATCH")
478+
);
479+
assert_eq!(
480+
publisher_identity_status(
481+
"developer-id",
482+
"TeamIdentifier=ABCD123456\n",
483+
Some("ABCD123456")
484+
),
485+
Err("PACKAGE_SIGNATURE_IDENTITY_MISMATCH")
486+
);
487+
let adhoc = "Signature=adhoc\nTeamIdentifier=not set\n";
488+
assert_eq!(
489+
publisher_identity_status("controlled-trial", adhoc, None),
490+
Ok(())
491+
);
492+
assert_eq!(
493+
publisher_identity_status("controlled-trial", adhoc, Some("ABCD123456")),
494+
Ok(())
495+
);
496+
assert_eq!(
497+
publisher_identity_status("controlled-trial", signature, None),
498+
Err("PACKAGE_SIGNATURE_IDENTITY_MISMATCH")
499+
);
450500
}
451501
}

‎docs/macos-installation.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ python3 scripts/package-desktop.py build \
188188
Credentials come only from the local keychain and never enter the repository or command
189189
output. The tool signs nested binaries and the app, submits and staples notarization, rebuilds
190190
the ZIP, then packages, signs, and notarizes the DMG; both notarizations must be Accepted.
191+
Developer ID upgrades compile that signing TeamIdentifier into the native updater as
192+
`HIROUTE_DEVELOPER_ID_TEAM`. Unconfigured or mismatched teams fail closed; a downloaded
193+
package cannot supply the trusted team.
191194
Self-signed builds are marked `controlled-trial` and make no Developer ID or notarization
192195
claim. That technical marker alone does not establish component disclosure, installation, or
193196
release review. Near-term public self-signed releases still require explicit applicable

‎docs/macos-installation.zh-CN.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ python3 scripts/package-desktop.py build \
137137
```
138138

139139
凭据只来自本机钥匙串,不放进仓库或命令输出。工具签名嵌套二进制和 App,提交公证,
140-
staple 并验证后重建 zip,再封装、签名和公证 DMG;两次公证均须 Accepted。自签名构建在包内明确标记
141-
`controlled-trial`,不声称 Developer ID 签名或公证;该技术标记本身也不代表已经完成组件声明、安装和发布审核。
140+
staple 并验证后重建 zip,再封装、签名和公证 DMG;两次公证均须 Accepted。
141+
Developer ID 升级会把该签名 TeamIdentifier 编译进原生更新器(`HIROUTE_DEVELOPER_ID_TEAM`)。
142+
未配置或团队不匹配时失败关闭;下载的安装包不能自行提供受信任团队。
143+
自签名构建在包内明确标记 `controlled-trial`,不声称 Developer ID 签名或公证;该技术标记本身也不代表已经完成组件声明、安装和发布审核。
142144
短期公开自签名版本仍须显式提供并核对适用组件材料,通过上述审核后才可进入官网发布清单。
143145

144146
安装场景需另行记录:安装位置/Finder 无覆盖启动、CLI 同服务和未运行错误、实际委派/结果、

‎scripts/package-desktop.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
BINARIES = ("hiroute-desktop", "hirouted", "hiroute", "cliproxyapi")
3232

3333

34+
def compile_time_publisher_team(identity, team_identifier):
35+
"""Trusted Team ID comes from the signing identity, never from a candidate package."""
36+
if identity == "-" or not team_identifier or team_identifier == "not set":
37+
return None
38+
return team_identifier
39+
40+
3441
def validate_release_versions(version):
3542
# Local Control uses the application-api package version for its exact
3643
# same-release handshake. It must track the shipped clients and daemon.
@@ -307,6 +314,10 @@ def build(args):
307314
environment["MACOSX_DEPLOYMENT_TARGET"] = MINIMUM_MACOS
308315
environment["HIROUTE_CPA_MANIFEST"] = str(manifest_path)
309316
environment["TAURI_CONFIG"] = json.dumps({"build": {"frontendDist": str(REPO / "apps/desktop/dist")}})
317+
environment.pop("HIROUTE_DEVELOPER_ID_TEAM", None)
318+
team = compile_time_publisher_team(args.identity, None if args.identity == "-" else teams[0])
319+
if team:
320+
environment["HIROUTE_DEVELOPER_ID_TEAM"] = team
310321
# Frontend is embedded by Tauri; no toolchain is needed on the installation machine.
311322
ui = REPO / "apps/desktop"
312323
run("npm", "ci", cwd=ui)

‎scripts/test-package-desktop.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ def test_final_signed_bytes_verified_and_resigning_rejected(self):
9292
with self.assertRaisesRegex(ValueError, "digest mismatch"):
9393
package.verify_contents(self.app, self.manifest)
9494

95+
def test_compile_time_publisher_team_comes_from_signing_identity(self):
96+
self.assertIsNone(package.compile_time_publisher_team("-", "ABCD123456"))
97+
self.assertIsNone(package.compile_time_publisher_team("-", "not set"))
98+
self.assertIsNone(package.compile_time_publisher_team(
99+
"Developer ID Application: Org (ABCD123456)", None))
100+
self.assertIsNone(package.compile_time_publisher_team(
101+
"Developer ID Application: Org (ABCD123456)", "not set"))
102+
self.assertEqual(
103+
package.compile_time_publisher_team(
104+
"Developer ID Application: Org (ABCD123456)", "ABCD123456"),
105+
"ABCD123456")
106+
95107
def test_cpa_is_explicitly_signed_before_release_probe(self):
96108
events = []
97109
release = ("CLIProxyAPI Version: 8.0.4-hiroute.8, Commit: "

0 commit comments

Comments
 (0)