Skip to content

Commit cb1d416

Browse files
authored
fix(bundler): sign the exe before the bundler step (#7487)
1 parent 6c408b7 commit cb1d416

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'tauri-bundler': 'patch:enhance'
3+
---
4+
5+
On Windows, code sign the application binaries before trying to create the WiX and NSIS bundles to always sign the executables even if no bundle types are enabled.
6+
7+
On Windows, code sign the sidecar binaries if they are not signed already.

tooling/bundler/src/bundle.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
6363
warn!("Cross-platform compilation is experimental and does not support all features. Please use a matching host system for full compatibility.");
6464
}
6565

66+
#[cfg(target_os = "windows")]
67+
{
68+
// Sign windows binaries before the bundling step in case neither wix and nsis bundles are enabled
69+
for bin in settings.binaries() {
70+
let bin_path = settings.binary_path(bin);
71+
windows::sign::try_sign(&bin_path, &settings)?;
72+
}
73+
74+
// Sign the sidecar binaries
75+
for bin in settings.external_binaries() {
76+
let path = bin?;
77+
let skip = std::env::var("TAURI_SKIP_SIDECAR_SIGNATURE_CHECK").map_or(false, |v| v == "true");
78+
79+
if !skip && windows::sign::verify(&path)? {
80+
info!(
81+
"sidecar at \"{}\" already signed. Skipping...",
82+
path.display()
83+
)
84+
} else {
85+
windows::sign::try_sign(&path, &settings)?;
86+
}
87+
}
88+
}
89+
6690
for package_type in &package_types {
6791
// bundle was already built! e.g. DMG already built .app
6892
if bundles.iter().any(|b| b.package_type == *package_type) {

tooling/bundler/src/bundle/windows/msi/wix.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,6 @@ pub fn build_wix_app_installer(
410410
.ok_or_else(|| anyhow::anyhow!("Failed to get main binary"))?;
411411
let app_exe_source = settings.binary_path(main_binary);
412412

413-
try_sign(&app_exe_source, settings)?;
414-
415413
let output_path = settings.project_out_directory().join("wix").join(arch);
416414

417415
if output_path.exists() {

tooling/bundler/src/bundle/windows/nsis.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,6 @@ fn build_nsis_app_installer(
157157

158158
info!("Target: {}", arch);
159159

160-
// Code signing is currently only supported on Windows hosts
161-
#[cfg(target_os = "windows")]
162-
{
163-
let main_binary = settings
164-
.binaries()
165-
.iter()
166-
.find(|bin| bin.main())
167-
.ok_or_else(|| anyhow::anyhow!("Failed to get main binary"))?;
168-
let app_exe_source = settings.binary_path(main_binary);
169-
try_sign(&app_exe_source, settings)?;
170-
}
171-
172160
#[cfg(not(target_os = "windows"))]
173161
info!("Code signing is currently only supported on Windows hosts, skipping...");
174162

tooling/bundler/src/bundle/windows/sign.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ fn locate_signtool() -> crate::Result<PathBuf> {
8888
Err(crate::Error::SignToolNotFound)
8989
}
9090

91+
/// Check if binary is already signed.
92+
/// Used to skip sidecar binaries that are already signed.
93+
pub fn verify(path: &Path) -> crate::Result<bool> {
94+
// Construct SignTool command
95+
let signtool = locate_signtool()?;
96+
97+
let mut cmd = Command::new(&signtool);
98+
cmd.arg("verify");
99+
cmd.arg("/pa");
100+
cmd.arg(path);
101+
102+
Ok(cmd.status()?.success())
103+
}
104+
91105
pub fn sign_command(path: &str, params: &SignParams) -> crate::Result<(Command, PathBuf)> {
92106
// Construct SignTool command
93107
let signtool = locate_signtool()?;

0 commit comments

Comments
 (0)