/* Authnet verifies signature of Authenticode-signed files Requires CAPICOM 2 COM interop assembly with namespace "CAPICOM" Copyright M. Gallant 02/18/2003 */ using System; using System.IO; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Collections; using CAPICOM; public class authnet { static String title = "AuthNet"; public static void Main(){ DialogResult result; Certificates oCerts; SignedCodeClass oSigCode; String[] args = Environment.GetCommandLineArgs(); if(args.Length<2) { MessageBox.Show("Usage:\nauthnet.exe ", title, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } String fname = args[1]; if (!File.Exists(fname)){ MessageBox.Show("File '" + fname + "' not found ", title ,MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } oSigCode = new SignedCodeClass() ; oSigCode.FileName = fname; try{ oSigCode.Verify(false) ; result = MessageBox.Show("Authenticode signature VERIFIED on file:\n" + fname + " \n\nDisplay certificates? ", title ,MessageBoxButtons.YesNo, MessageBoxIcon.Information); oCerts = oSigCode.Certificates ; if(result == DialogResult.Yes) ShowAllCerts(oCerts); } catch(COMException) { MessageBox.Show("NO VALID SIGNATURE on file:\n" + fname + " ", title ,MessageBoxButtons.OK, MessageBoxIcon.Error); } } private static void ShowAllCerts(Certificates oCerts) { Certificate oCert; IEnumerator _enum = (IEnumerator)oCerts.GetEnumerator(); int i = 0; while (_enum.MoveNext() == true) { oCert = (Certificate) _enum.Current; oCert.Display(); i++; } } }