#requires -Version 7.4 [CmdletBinding()] param( [Parameter(Mandatory)][string]$Path, [Parameter(Mandatory)][string]$CertificateThumbprint, [switch]$SelfSigned ) $ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest $signature = Get-AuthenticodeSignature -LiteralPath $Path if ($signature.Status -eq 'NotSigned') { throw "The file has no embedded signature: $Path" } if (-not ('RmicWindowsSignature' -as [type])) { $references = @((Get-ChildItem -LiteralPath (Join-Path $PSHOME 'ref') -Filter '*.dll').FullName) + @([System.Security.Cryptography.Pkcs.SignedCms].Assembly.Location) Add-Type -Path (Join-Path $PSScriptRoot 'windows-signature.cs') -ReferencedAssemblies $references } $timestamp = [RmicWindowsSignature]::Verify([IO.Path]::GetFullPath($Path), $CertificateThumbprint, [bool]$SelfSigned) if (-not $SelfSigned -and $signature.Status -ne 'Valid') { throw "Windows does not trust the CA-signed output: $Path" } [pscustomobject]@{ file = [IO.Path]::GetFileName($Path); status = [string]$signature.Status; verificationStatus = $(if ($SelfSigned) { 'valid-pinned-self-signed' } else { 'valid-trusted-signature' }); windowsTrustMessage = $signature.StatusMessage; integrityVerified = $true; timestamped = $true; timestampVerified = $true; timestampUtc = $timestamp.ToString('o'); certificateThumbprint = $CertificateThumbprint; selfSigned = [bool]$SelfSigned; windowsTrusted = $signature.Status -eq 'Valid' }