How to use unmanaged function in PowerShell to get all the chains in this signed file?

80 Views Asked by At

I have this file: https://ufile.io/1j5pleow

it has 4 certificates in its path.

Using this method

$FilePath = '.\NordPassSetup_x86.exe'

# Get the certificate from the file path
$Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $FilePath

# Build the certificate chain
$Chain = New-Object System.Security.Cryptography.X509Certificates.X509Chain
[void]$Chain.Build($Cert)

$Chain.ChainElements.count

foreach ($Element in $Chain.ChainElements) {
    $Element.Certificate | ft -AutoSize
}

Only returns the shortest chain which only include 3 certificates, but in file explorer I can see the longest/full chain of the certificates, which are 4.

enter image description here

I have other files with similar behavior, one of them has 5 certificates but in PowerShell I can only see 3, because it's the shortest chain.

The question is related to this other one. I was told it's possible to do this using CertGetCertificateChain unmanaged function.

0

There are 0 best solutions below