fix: support powershell constrained language mode #7230
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #6917
In environments where PowerShell is in Constrained Language Mode,
[Convert]::ToBase64String
and[System.Text.Encoding]::UTF8.GetBytes
won't work.We're currently converting the output of
Get-AuthenticodeSignature -LiteralPath '${tempUpdateFile}' | ConvertTo-Json -Compress
to base64 in powershell to get possibly non-ascii data, which would otherwise be output in the current ANSI code page. This workaround was added in #5071, FYI @orzFly @hezhuojie.I first tried setting PowerShell's
[console]::OutputEncoding
, but that is also not allowed in Constrained Language Mode. So this fix is to runchcp 65001 > NUL
before running powershell.exe. See PowerShell/PowerShell#7233 for more context on this issue.In order to test that this works with non-ascii certificate subject names, I created a github release signed with a self-signed certificate with a subject name of
CN=你好
at https://github.com/jeremyspiegel/electron-updater-powershell-test/releases/tag/v1.0.1. I then added the certificate to my Trusted Root Certificate Authorities and added the following test in test/src/updater/nsisUpdaterTest.ts:In order to test that this works in PowerShell Constrained Language Mode, I created a system environment variable
__PSLockDownPolicy=4
and ran the above test.