Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hot-cars-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"electron-updater": patch
---

fix: auto-update powershell script
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { parseDn } from "builder-util-runtime"
import { execFile, execFileSync } from "child_process"
import { execFile, execFileSync, ExecFileOptions } from "child_process"
import * as os from "os"
import { Logger } from "./types"
import * as path from "path"

function preparePowerShellExec(command: string, timeout?: number) {
// https://github.com/electron-userland/electron-builder/issues/2421
// https://github.com/electron-userland/electron-builder/issues/2535
// Resetting PSModulePath is necessary https://github.com/electron-userland/electron-builder/issues/7127
// semicolon wont terminate the set command and run chcp thus leading to verification errors on certificats with special chars like german umlauts, so rather
// join commands using & https://github.com/electron-userland/electron-builder/issues/8162
const executable = `set "PSModulePath=" & chcp 65001 >NUL & powershell.exe`
const args = ["-NoProfile", "-NonInteractive", "-InputFormat", "None", "-Command", command]
const options: ExecFileOptions = {
shell: true,
timeout,
}
return [executable, args, options] as const
}

// $certificateInfo = (Get-AuthenticodeSignature 'xxx\yyy.exe'
// | where {$_.Status.Equals([System.Management.Automation.SignatureStatus]::Valid) -and $_.SignerCertificate.Subject.Contains("CN=siemens.com")})
// | Out-String ; if ($certificateInfo) { exit 0 } else { exit 1 }
Expand All @@ -30,24 +45,13 @@
const tempUpdateFile = unescapedTempUpdateFile.replace(/'/g, "''")
logger.info(`Verifying signature ${tempUpdateFile}`)

// https://github.com/electron-userland/electron-builder/issues/2421
// https://github.com/electron-userland/electron-builder/issues/2535
// Resetting PSModulePath is necessary https://github.com/electron-userland/electron-builder/issues/7127
// semicolon wont terminate the set command and run chcp thus leading to verification errors on certificats with special chars like german umlauts, so rather
// join commands using & https://github.com/electron-userland/electron-builder/issues/8162
execFile(
`set "PSModulePath=" & chcp 65001 >NUL & powershell.exe`,
["-NoProfile", "-NonInteractive", "-InputFormat", "None", "-Command", `"Get-AuthenticodeSignature -LiteralPath '${tempUpdateFile}' | ConvertTo-Json -Compress"`],
{
shell: true,
timeout: 20 * 1000,
},
execFile(...preparePowerShellExec(`"Get-AuthenticodeSignature -LiteralPath '${tempUpdateFile}' | ConvertTo-Json -Compress"`, 20 * 1000),

Check warning on line 48 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (winPackagerTest,winCodeSignTest,webInstallerTest)

Delete `⏎·····`

Check warning on line 48 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Delete `⏎·····`

Check warning on line 48 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (concurrentBuildsTest)

Delete `⏎·····`

Check warning on line 48 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (winPackagerTest,winCodeSignTest,webInstallerTest)

Delete `⏎·····`

Check warning on line 48 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (concurrentBuildsTest)

Delete `⏎·····`

Check warning on line 48 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Delete `⏎·····`

Check warning on line 48 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Delete `⏎·····`

Check warning on line 48 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Delete `⏎·····`

Check warning on line 48 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (oneClickInstallerTest,assistedInstallerTest)

Delete `⏎·····`

Check warning on line 48 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (oneClickInstallerTest,assistedInstallerTest)

Delete `⏎·····`

Check warning on line 48 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-updater

Delete `⏎·····`

Check warning on line 48 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-updater

Delete `⏎·····`
(error, stdout, stderr) => {
try {

Check warning on line 50 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (winPackagerTest,winCodeSignTest,webInstallerTest)

Replace `········` with `······`

Check warning on line 50 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Replace `········` with `······`

Check warning on line 50 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (concurrentBuildsTest)

Replace `········` with `······`

Check warning on line 50 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (winPackagerTest,winCodeSignTest,webInstallerTest)

Replace `········` with `······`

Check warning on line 50 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (concurrentBuildsTest)

Replace `········` with `······`

Check warning on line 50 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Replace `········` with `······`

Check warning on line 50 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Replace `········` with `······`

Check warning on line 50 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Replace `········` with `······`

Check warning on line 50 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (oneClickInstallerTest,assistedInstallerTest)

Replace `········` with `······`

Check warning on line 50 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (oneClickInstallerTest,assistedInstallerTest)

Replace `········` with `······`

Check warning on line 50 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-updater

Replace `········` with `······`

Check warning on line 50 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-updater

Replace `········` with `······`
if (error != null || stderr) {

Check warning on line 51 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (winPackagerTest,winCodeSignTest,webInstallerTest)

Delete `··`

Check warning on line 51 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Delete `··`

Check warning on line 51 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (concurrentBuildsTest)

Delete `··`

Check warning on line 51 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (winPackagerTest,winCodeSignTest,webInstallerTest)

Delete `··`

Check warning on line 51 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (concurrentBuildsTest)

Delete `··`

Check warning on line 51 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Delete `··`

Check warning on line 51 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Delete `··`

Check warning on line 51 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Delete `··`

Check warning on line 51 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (oneClickInstallerTest,assistedInstallerTest)

Delete `··`

Check warning on line 51 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (oneClickInstallerTest,assistedInstallerTest)

Delete `··`

Check warning on line 51 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-updater

Delete `··`

Check warning on line 51 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-updater

Delete `··`
handleError(logger, error, stderr, reject)

Check warning on line 52 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (winPackagerTest,winCodeSignTest,webInstallerTest)

Delete `··`

Check warning on line 52 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Delete `··`

Check warning on line 52 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (concurrentBuildsTest)

Delete `··`

Check warning on line 52 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (winPackagerTest,winCodeSignTest,webInstallerTest)

Delete `··`

Check warning on line 52 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (concurrentBuildsTest)

Delete `··`

Check warning on line 52 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Delete `··`

Check warning on line 52 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Delete `··`

Check warning on line 52 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Delete `··`

Check warning on line 52 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (oneClickInstallerTest,assistedInstallerTest)

Delete `··`

Check warning on line 52 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (oneClickInstallerTest,assistedInstallerTest)

Delete `··`

Check warning on line 52 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-updater

Delete `··`

Check warning on line 52 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-updater

Delete `··`
resolve(null)

Check warning on line 53 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (winPackagerTest,winCodeSignTest,webInstallerTest)

Delete `··`

Check warning on line 53 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Delete `··`

Check warning on line 53 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (concurrentBuildsTest)

Delete `··`

Check warning on line 53 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (winPackagerTest,winCodeSignTest,webInstallerTest)

Delete `··`

Check warning on line 53 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (concurrentBuildsTest)

Delete `··`

Check warning on line 53 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Delete `··`

Check warning on line 53 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Delete `··`

Check warning on line 53 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Delete `··`

Check warning on line 53 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (oneClickInstallerTest,assistedInstallerTest)

Delete `··`

Check warning on line 53 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (oneClickInstallerTest,assistedInstallerTest)

Delete `··`

Check warning on line 53 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-updater

Delete `··`

Check warning on line 53 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-updater

Delete `··`
return

Check warning on line 54 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (winPackagerTest,winCodeSignTest,webInstallerTest)

Delete `··`

Check warning on line 54 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Delete `··`

Check warning on line 54 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (concurrentBuildsTest)

Delete `··`

Check warning on line 54 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (winPackagerTest,winCodeSignTest,webInstallerTest)

Delete `··`

Check warning on line 54 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (concurrentBuildsTest)

Delete `··`

Check warning on line 54 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Delete `··`

Check warning on line 54 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Delete `··`

Check warning on line 54 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Delete `··`

Check warning on line 54 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (oneClickInstallerTest,assistedInstallerTest)

Delete `··`

Check warning on line 54 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-linux (oneClickInstallerTest,assistedInstallerTest)

Delete `··`

Check warning on line 54 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-updater

Delete `··`

Check warning on line 54 in packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts

View workflow job for this annotation

GitHub Actions / test-updater

Delete `··`
}
const data = parseOut(stdout)
if (data.Status === 0) {
Expand Down Expand Up @@ -123,7 +127,7 @@
}

try {
execFileSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", "ConvertTo-Json test"], { timeout: 10 * 1000 } as any)
execFileSync(...preparePowerShellExec("ConvertTo-Json test", 10 * 1000))
} catch (testError: any) {
logger.warn(
`Cannot execute ConvertTo-Json: ${testError.message}. Ignoring signature validation due to unsupported powershell version. Please upgrade to powershell 3 or higher.`
Expand Down
Loading