In my C#
/.NET
application I have to check if a given executable is digitally signed (preferably without Exception
testing.)
Then I need to check if its certificate is valid (based on installed root certificates) and if the files content is valid for the signature.
There are so many classes in the BCL
, I don't know where to start & what to use, and anything I've found so far doesn't eliminate my confusion...
I'd like to do something like this, without P/Invoke
if possible:
bool IsSignedFile(string path);
Cert GetCertificateFromSignedFile(string path);
bool IsValidCertificate(Cert cert)
Sig GetSignatureFromSignedFile(string path);
bool IsValidSignature(string path, Sig sig, Cert cert);
Added clarification:
The big problem I currently have is that I don't find a way to obtain the signature of such a file in an easy way. Still hope there is a provided, managed, BCL
solution as I would be surprised if exactly that part is missing. (For the certificate this can be done with just X509Certificate.CreateFromSignedFile
, validating that is possible, too)
I'd prefer not mixing that 50% work done with P/Invoke
code or a big different library.
I've found a AuthenticodeSignatureInformation
class, no information about using that for a given executable though.