Looking for a way to get the TBS of a file that has digital signature in PowerShell 7.3+
Tried a few things like:
add-type -AssemblyName system.security.cryptography.X509Certificates
$cert = new-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList <file path>
$RawdDta = $cert.RawData
But not sure what the next steps are.
Let me clarify
This is the TBS value
I want to get them in PowerShell. The image is the XML output of running commands from the built-in ConfigCI module.
Get-AuthenticodeSignature doesn't show that value.
The TBS value shown in the screenshot belongs to this certificate which is not installed in the local cert store
Update:
For well-known roots, the TBS hashes for the certificates are baked into the code for Windows Defender Application Control. For example, they don’t need to be listed as TBS hashes in the policy file.
This is saying the TBS value is hash.


Apparently the systems I used for extracting the tbsCertificate and/or hashing it let me down. The algorithm for this value is the hash of the tbsCertificate using whatever algorithm the CA used to sign the certificate. So it's the hash value that the CA computes when signing (and that a verifier computes when verifying the chain). This program demonstrates it:
When run on the PCA 2010 certificate (as downloaded from crt.sh cert 12729283), it outputs your expected
121AF4B922A74247EA49DF50DE37609CC1451A1FE06B2CB7E1E079B492BD8195This is not a thing that is built into .NET, and it probably isn't a PowerShell intrinsic cmdlet/function for it, either. The System.Formats.Asn1 package used here should be callable from PowerShell, but you'll have to translate the C# to PS, of course.