I was able to sign a js file with PowerShell Set-AuthenticodeSignature. After that i can see signature appeared in file in form of:
// SIG // Begin signature block
// SIG // MIIKgAYJKoZIhvcNAQcCoIIKcTCCCm0CAQExCzAJBgUr
// SIG // ....
// SIG // End signature block
I can validate signature using Get-AuthenticodeSignature. It says that sig is valid, but I cant find a way to validate signature in C# code. All of those options failed:
- X509Certificate.CreateFromSignedFile
- X509Certificate object c# performance and memory issues alternative – fixed
- Used WinVerifyTrust from Wintrust.dll
- Ported part of Get-AuthenticodeSignature from PowerShell!
Maybe there are some specific apis to validate js signatures?
WinVerifyTrust supports verifying files other than executables using the WTD_CHOICE_BLOB flag. Make sure you provide the WINTRUST_BLOB_INFO struct with the correct subject interface package (SIP). From what I can see, Get-AuthenticodeSignature command uses the PowerShell SIP {603bcc1f-4b59-4e08-b724-d2c6297ef351} to verify the signature. I assume Set-AuthenticodeSignature uses the same SIP to sign the script.