Skip to content

Commit 84edc69

Browse files
committed
CI: run the Windows runner trust probe under Windows PowerShell 5.1
pwsh is not installed on every Windows runner label, while Windows PowerShell (powershell) is. Switch the probe step to `shell: powershell` and make the probe script and the shared eMudhra helper compatible with both Windows PowerShell 5.1 and PowerShell 7+: - Build certificates from the PEM body instead of CreateFromPem (.NET 5+). - Compute SHA-256 from RawData instead of GetCertHashString('SHA256'). - Set ChainPolicy.DisableCertificateDownloads only when it exists. - Drop Invoke-WebRequest -SkipHttpErrorCheck and treat any HTTP response as a successful connection. - Append the step summary as BOM-less UTF-8.
1 parent 0d3cc26 commit 84edc69

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

‎.github/actions/upgrade-ca-certificates/emudhra_intermediates.ps1‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,30 @@
1414
$EmudhraIntermediatesPath = Join-Path $PSScriptRoot 'impacted-intermediates.json'
1515
$EmudhraIntermediatesCount = 16
1616

17+
# Uppercase hex SHA-256 of the certificate's DER encoding. Computed directly
18+
# because X509Certificate.GetCertHashString(HashAlgorithmName) does not exist
19+
# in Windows PowerShell 5.1 (.NET Framework).
20+
function Get-CertificateSha256([System.Security.Cryptography.X509Certificates.X509Certificate2]$Cert) {
21+
$sha256 = [System.Security.Cryptography.SHA256]::Create()
22+
try {
23+
return [System.BitConverter]::ToString($sha256.ComputeHash($Cert.RawData)).Replace('-', '')
24+
} finally {
25+
$sha256.Dispose()
26+
}
27+
}
28+
1729
# Returns the certificates as X509Certificate2 objects; callers dispose them.
30+
# Works on both Windows PowerShell 5.1 and PowerShell 7+.
1831
function Get-EmudhraIntermediates {
1932
$entries = @(Get-Content -LiteralPath $EmudhraIntermediatesPath -Raw | ConvertFrom-Json)
2033
if ($entries.Count -ne $EmudhraIntermediatesCount) {
2134
throw "Expected $EmudhraIntermediatesCount certificates in $EmudhraIntermediatesPath, found $($entries.Count)."
2235
}
2336
foreach ($entry in $entries) {
24-
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::CreateFromPem($entry.pem)
25-
if ($cert.GetCertHashString('SHA256') -ne $entry.sha256.ToUpperInvariant()) {
37+
# X509Certificate2.CreateFromPem is .NET 5+ only; decode the PEM body manually.
38+
$der = [System.Convert]::FromBase64String(($entry.pem -replace '-----[A-Z ]+-----', '' -replace '\s', ''))
39+
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($der)
40+
if ((Get-CertificateSha256 $cert) -ne $entry.sha256.ToUpperInvariant()) {
2641
$cert.Dispose()
2742
throw "SHA-256 mismatch for $($entry.name) (issued by $($entry.issued_by))."
2843
}
@@ -40,7 +55,10 @@ function Test-ExplicitlyDistrusted([System.Security.Cryptography.X509Certificate
4055
$chain = [System.Security.Cryptography.X509Certificates.X509Chain]::new()
4156
try {
4257
$chain.ChainPolicy.RevocationMode = [System.Security.Cryptography.X509Certificates.X509RevocationMode]::NoCheck
43-
$chain.ChainPolicy.DisableCertificateDownloads = $true
58+
# DisableCertificateDownloads does not exist on .NET Framework (Windows PowerShell 5.1).
59+
if ($chain.ChainPolicy | Get-Member -Name DisableCertificateDownloads) {
60+
$chain.ChainPolicy.DisableCertificateDownloads = $true
61+
}
4462
[void]$chain.Build($Cert)
4563
$statuses = @($chain.ChainStatus) + @($chain.ChainElements | ForEach-Object { $_.ChainElementStatus })
4664
return [bool]($statuses | Where-Object { $_.Status.HasFlag($explicitDistrust) })

‎.github/workflows/runner-trust-probe.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
135135
- name: Probe Windows OS trust store
136136
if: ${{ runner.os == 'Windows' }}
137-
shell: pwsh
137+
shell: powershell
138138
run: ./ci/tools/runner_trust_probe.ps1
139139

140140
- name: Probe Node 20 action runtime (informational)

‎ci/tools/runner_trust_probe.ps1‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
# runner_trust_probe.ps1 -- probe the Windows certificate store on a CI runner
66
# for the compromised eMudhra intermediates and their Sectigo cross-signs.
7+
# Compatible with Windows PowerShell 5.1 (`shell: powershell`) and PowerShell 7+.
78

89
$ErrorActionPreference = 'Stop'
910

@@ -21,7 +22,8 @@ $SummaryFile = $env:GITHUB_STEP_SUMMARY
2122

2223
function Append-Summary([string]$Line) {
2324
if ($SummaryFile) {
24-
Add-Content -Path $SummaryFile -Value $Line -Encoding utf8
25+
# Windows PowerShell 5.1's `-Encoding utf8` emits a BOM; write BOM-less UTF-8 explicitly.
26+
[System.IO.File]::AppendAllText($SummaryFile, "$Line`n", [System.Text.UTF8Encoding]::new($false))
2527
}
2628
}
2729

@@ -40,9 +42,9 @@ Append-Summary "| --- | --- | --- |"
4042
# 1. Root anchor state (informational). Microsoft's fix blocks the
4143
# intermediates and leaves the root in place, so this is not a pass criterion.
4244
$rootCerts = @(Get-ChildItem -Path 'Cert:\LocalMachine\Root' -ErrorAction Stop)
43-
$inRoot = [bool]($rootCerts | Where-Object { $_.GetCertHashString('SHA256') -eq $EmSignG3Hex })
45+
$inRoot = [bool]($rootCerts | Where-Object { (Get-CertificateSha256 $_) -eq $EmSignG3Hex })
4446
$inDisallowed = [bool](Get-ChildItem -Path 'Cert:\LocalMachine\Disallowed' -ErrorAction SilentlyContinue |
45-
Where-Object { $_.GetCertHashString('SHA256') -eq $EmSignG3Hex })
47+
Where-Object { (Get-CertificateSha256 $_) -eq $EmSignG3Hex })
4648
Record-Check 'emSign ECC Root CA - G3 store state' 'INFO' "LocalMachine\Root=$inRoot ($($rootCerts.Count) certs), LocalMachine\Disallowed=$inDisallowed"
4749

4850
# 2. All compromised intermediates and cross-signs explicitly distrusted (gating)
@@ -59,23 +61,30 @@ if ($notDistrusted.Count -eq 0) {
5961
$GatingFailures++
6062
}
6163

62-
# 3. OS-store client (Invoke-WebRequest) rejects each test endpoint (only a successful connection fails the job)
64+
# 3. OS-store client (Invoke-WebRequest) rejects each test endpoint (only a successful connection fails the job).
65+
# -SkipHttpErrorCheck is PowerShell 7+ only, so HTTP error statuses are caught below instead:
66+
# any response at all means the TLS handshake (and thus the certificate chain) succeeded.
6367
$progTmp = $ProgressPreference
6468
$ProgressPreference = 'SilentlyContinue'
6569
try {
6670
foreach ($endpoint in $TestEndpoints) {
6771
$checkName = "Invoke-WebRequest rejects ``$endpoint``"
6872
try {
69-
$res = Invoke-WebRequest -Uri $endpoint -UseBasicParsing -SkipHttpErrorCheck -TimeoutSec 15
73+
$res = Invoke-WebRequest -Uri $endpoint -UseBasicParsing -TimeoutSec 15
7074
Record-Check $checkName 'FAIL' "Connection succeeded with HTTP $($res.StatusCode) (certificate was trusted)"
7175
$GatingFailures++
7276
} catch {
77+
if ($null -ne $_.Exception.Response) {
78+
Record-Check $checkName 'FAIL' "Connection succeeded with HTTP $([int]$_.Exception.Response.StatusCode) (certificate was trusted)"
79+
$GatingFailures++
80+
continue
81+
}
7382
$certRejected = $false
7483
$hostnameMismatchOnly = $false
7584
$ex = $_.Exception
7685
while ($null -ne $ex) {
7786
if (
78-
($ex -is [System.Security.Authentication.AuthenticationException] -and $ex.Message -match 'certificate chain|UntrustedRoot|RemoteCertificateChainErrors') -or
87+
($ex -is [System.Security.Authentication.AuthenticationException] -and $ex.Message -match 'certificate chain|UntrustedRoot|RemoteCertificateChainErrors|remote certificate is invalid') -or
7988
($ex -is [System.Net.WebException] -and $ex.Status -eq [System.Net.WebExceptionStatus]::TrustFailure)
8089
) {
8190
$certRejected = $true

0 commit comments

Comments
 (0)