Click here to Skip to main content
15,910,303 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a .Net executable which I have digitally signed using a certificate generated through makecert.exe and signed using signtool. How to verify that exe has not been tampered or it is still using the certificate digitally signed by me.

For ex - A situation where anyone can replace the exe which is digitally signed by another certificate and placed into Trusted Root Authorities.

From various internet sources I read that the below code would just check if the certificate is valid

C#
X509Certificate signer = X509Certificate.CreateFromSignedFile(executablePath);
X509Certificate2 certificate = new X509Certificate2(signer);
var certificateChain = new X509Chain
{
    ChainPolicy = {
        RevocationFlag = X509RevocationFlag.EntireChain,
        RevocationMode = X509RevocationMode.Online,
        UrlRetrievalTimeout = new TimeSpan(0, 1, 0),
        VerificationFlags = X509VerificationFlags.NoFlag
    }
};

var chainIsValid = certificateChain.Build(certificate);
if (chainIsValid)
{}

And it is suggested to use WinVerifyTrust. My question is WinVerifyTrust would also validate the certificate, if the same exe is signed by another certificate deployed in Trusted Root Authorities. How can I associate the exe with my certificate? Or how the WinVerifyTrust can be helpful in this situation as mentioned everywhere? Please help!!

Thanks

What I have tried:

I have already tried using X509Certificate and WinVerifyTrust(). But I don't have much knowledge related to WinVerifyTrust()
Posted
Updated 13-Mar-19 5:33am
v2

1 solution

 
Share this answer
 
Comments
Divya B Nair 14-Mar-19 0:35am    
I want to check the validity of signature against my exe in C#.Net.
Maciej Los 14-Mar-19 5:16am    
So, use that tool!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900