Skip to content

Commit

Permalink
fix: add reject in handleError in Windows verifySignature function (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
beyondkmp committed Jan 17, 2023
1 parent 93930cf commit 7862e38
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-zebras-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"electron-updater": patch
---

fix: add reject in handleError in Windows `verifySignature` function
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Logger } from "./main"
// | where {$_.Status.Equals([System.Management.Automation.SignatureStatus]::Valid) -and $_.SignerCertificate.Subject.Contains("CN=siemens.com")})
// | Out-String ; if ($certificateInfo) { exit 0 } else { exit 1 }
export function verifySignature(publisherNames: Array<string>, unescapedTempUpdateFile: string, logger: Logger): Promise<string | null> {
return new Promise<string | null>(resolve => {
return new Promise<string | null>((resolve, reject) => {
// Escape quotes and backticks in filenames to prevent user from breaking the
// arguments and perform a remote command injection.
//
Expand Down Expand Up @@ -40,7 +40,7 @@ export function verifySignature(publisherNames: Array<string>, unescapedTempUpda
(error, stdout, stderr) => {
try {
if (error != null || stderr) {
handleError(logger, error, stderr)
handleError(logger, error, stderr, reject)
resolve(null)
return
}
Expand Down Expand Up @@ -72,7 +72,7 @@ export function verifySignature(publisherNames: Array<string>, unescapedTempUpda
logger.warn(`Sign verification failed, installer signed with incorrect certificate: ${result}`)
resolve(result)
} catch (e: any) {
handleError(logger, e, null)
handleError(logger, e, null, reject)
resolve(null)
return
}
Expand All @@ -99,7 +99,7 @@ function parseOut(out: string): any {
return data
}

function handleError(logger: Logger, error: Error | null, stderr: string | null): void {
function handleError(logger: Logger, error: Error | null, stderr: string | null, reject: (reason: any) => void): void {
if (isOldWin6()) {
logger.warn(
`Cannot execute Get-AuthenticodeSignature: ${error || stderr}. Ignoring signature validation due to unsupported powershell version. Please upgrade to powershell 3 or higher.`
Expand All @@ -117,11 +117,11 @@ function handleError(logger: Logger, error: Error | null, stderr: string | null)
}

if (error != null) {
throw error
reject(error)
}

if (stderr) {
throw new Error(`Cannot execute Get-AuthenticodeSignature, stderr: ${stderr}. Failing signature validation due to unknown stderr.`)
reject(new Error(`Cannot execute Get-AuthenticodeSignature, stderr: ${stderr}. Failing signature validation due to unknown stderr.`))
}
}

Expand Down

0 comments on commit 7862e38

Please sign in to comment.