CAPICOM - Verify SignedCode is from a Trusted Publisher without UI
Asked Answered
F

3

8

I'm using CAPICOM in a .NET 3.0 C# app to check an Authenticode signature on an exe file. I need to make sure that the certificate is listed as a Trusted Publisher. Using signedCode.Verify(true) will show a dialog if the certificate is not already trusted, so the user can choose whether or not to do so. However, signedCode.Verify(false) is verifying the signature even if it is not from a trusted publisher - presumably this is only checking that the certificate is valid.

How can I check that the signature on a file is from a valid and trusted certificate without the UI?

Fca answered 27/3, 2009 at 10:6 Comment(0)
R
2

First, StrongNameSignatureVerificationEx is for assembly signature verification and not Authenticode signature verification. So, this is not relevant to the context of original poster's question.

Concerning the initial question, you can manually check that the signer certificate is correctly chained to a trusted root without any GUI by using the following code :

ICertificateStatus certStatus = signedCode.Signer.Certificate.IsValid();

The idea is to retrieve the signer's certificate and to tell CAPICom to check if it has a correct trust chain.

I hope this will help. Cheers,

Mounir IDRASSI, IDRIX, http://www.idrix.fr

Richmal answered 25/4, 2011 at 17:58 Comment(0)
W
0

What you would probably need to do is to use exposed through the mscoree.dll StrongNameSignatureVerificationEx function with P/Invoke:

[DllImport("mscoree.dll", CharSet=CharSet.Unicode)]
static extern bool StrongNameSignatureVerificationEx(string wszFilePath, bool fForceVerification, ref bool  pfWasVerified);
Wimsatt answered 13/4, 2011 at 3:27 Comment(0)
S
0

You can use WinVerifyTrust as shown here. It works beautifully on Windows XP/Vista/2008/7. If you also want to check the revocation list set

RevocationChecks = WinTrustDataRevocationChecks.WholeChain;
Schlimazel answered 5/5, 2011 at 6:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.