Skip to content

Commit 292c9e5

Browse files
committed
sign engine
1 parent a47ae19 commit 292c9e5

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

scripts/Publish.ps1

+37-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ function Find-EnvironmentVariables([string[]] $variables) {
5050
}
5151
}
5252

53+
Find-Dependencies @("dotnet.exe", "wix.exe")
54+
5355
if ($sign) {
5456
Write-Host "Signing is enabled"
5557
Find-Dependencies java
@@ -97,7 +99,8 @@ if (Test-Path $outputPath.Replace(".exe", ".wixpdb")) {
9799
}
98100

99101
# Create a publish directory
100-
$buildPath = Join-Path $repoRoot "publish\buildtemp-$($version)-$($arch)"
102+
$publishDir = Join-Path $repoRoot "publish"
103+
$buildPath = Join-Path $publishDir "buildtemp-$($version)-$($arch)"
101104
if (Test-Path $buildPath) {
102105
Remove-Item -Recurse -Force $buildPath
103106
}
@@ -164,7 +167,39 @@ Add-CoderSignature $msiOutputPath
164167
--msi-path $msiOutputPath `
165168
--logo-png "scripts\files\logo.png"
166169
if ($LASTEXITCODE -ne 0) { throw "Failed to build bootstrapper" }
167-
Add-CoderSignature $outputPath
170+
171+
# Sign the bootstrapper, which is not as simple as just signing the exe.
172+
if ($sign) {
173+
$burnIntermediate = Join-Path $publishDir "burn-intermediate-$($version)-$($arch)"
174+
New-Item -ItemType Directory -Path $burnIntermediate -Force
175+
$burnEngine = Join-Path $publishDir "burn-engine-$($version)-$($arch).exe"
176+
177+
# Move the current output path
178+
$unsignedOutputPath = Join-Path (Split-Path $outputPath -Parent) ("UNSIGNED-" + (Split-Path $outputPath -Leaf))
179+
Move-Item $outputPath $unsignedOutputPath
180+
181+
# Extract the engine from the bootstrapper
182+
& wix.exe burn detach $unsignedOutputPath -intermediateFolder $burnIntermediate -engine $burnEngine
183+
if ($LASTEXITCODE -ne 0) { throw "Failed to extract engine from bootstrapper" }
184+
185+
# Sign the engine
186+
Add-CoderSignature $burnEngine
187+
188+
# Re-attach the signed engine to the bootstrapper
189+
& wix.exe burn reattach $unsignedOutputPath -intermediateFolder $burnIntermediate -engine $burnEngine -out $outputPath
190+
if ($LASTEXITCODE -ne 0) { throw "Failed to re-attach signed engine to bootstrapper" }
191+
if (!(Test-Path $outputPath)) { throw "Failed to create reattached bootstrapper at $outputPath" }
192+
193+
# Now sign the output path
194+
Add-CoderSignature $outputPath
195+
196+
# Clean up the intermediate files
197+
if (!$keepBuildTemp) {
198+
Remove-Item -Force $unsignedOutputPath
199+
Remove-Item -Recurse -Force $burnIntermediate
200+
Remove-Item -Force $burnEngine
201+
}
202+
}
168203

169204
if (!$keepBuildTemp) {
170205
Remove-Item -Recurse -Force $buildPath

scripts/Release.ps1

+9-8
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,18 @@ foreach ($arch in @("x64", "arm64")) {
2929
-version $assemblyVersion `
3030
-arch $arch `
3131
-msiOutputPath $msiOutputPath `
32-
-outputPath $outputPath
32+
-outputPath $outputPath `
33+
-sign
3334
if ($LASTEXITCODE -ne 0) { throw "Failed to publish" }
3435

3536
# Verify that the output exe is authenticode signed
36-
#$sig = Get-AuthenticodeSignature $outputPath
37-
#if ($sig.Status -ne "Valid") {
38-
# throw "Output file is not authenticode signed"
39-
#}
40-
#else {
41-
# Write-Host "Output file is authenticode signed"
42-
#}
37+
$sig = Get-AuthenticodeSignature $outputPath
38+
if ($sig.Status -ne "Valid") {
39+
throw "Output file is not authenticode signed"
40+
}
41+
else {
42+
Write-Host "Output file is authenticode signed"
43+
}
4344
}
4445
finally {
4546
Write-Host "::endgroup::"

0 commit comments

Comments
 (0)