title: Verifying authenticode signature upon execution of .NET app
body: <p>I feel like I'm missing something obvious here, but I don't see it written anywhere.</p>
  
  <p>I sign my executables using an Authenticode certificate, but as I've started to learn a bit more about it, I am questioning the value as-is. </p>
  
  <ul>
  <li>A signed exe has a digital certificate that shows as being a "valid" certificate. When you download such a file from the internet, it shows a warning in Windows saying you're about to run a program from a potentially unsafe location published by Xyz Corporation. </li>
  <li>Without the signature, the downloaded file will give a totally different-looking warning box saying the file is untrusted</li>
  </ul>
  
  <p>Now, what concerns me, is:</p>
  
  <ul>
  <li><p>If a signed exe is altered, when you go into Properties > Digital Signatures > Select signature > Details... it shows "This digital signature is not valid". That's a pretty obscure way to view what is likely a severe problem, and a huge indicator you shouldn't run the file. </p>
  
  <ul>
  <li>If you run this file from Windows (not downloaded), it will run just fine. No warning or any indication there is something wrong</li>
  <li>I didn't check what happens if you download the file and then try to run it. </li>
  </ul></li>
  <li><p>If you strip the signature from the file (using <a href="http://forum.xda-developers.com/showthread.php?p=2508061" rel="noreferrer">delcert</a>), there is no indication anything is wrong either. Again, you can run the file, and just no certificate is shown in the properties dialog.</p></li>
  </ul>
  
  <hr>
  
  <p>To make this more useful, I'm thinking that a signed file needs to verify itself. Upon start up, it should be checking that there is a valid signature, and potentially that the sha1 fingerprint of the signature matches the expected signature for the Xyz Corporation certificate. </p>
  
  <p>(Granted, this still doesn't handle the situation where someone strips the certificate, and then edits the file to remove the certificate check)</p>
  
  <hr>
  
  <p>I can't find anyone talking about how to do this (at least not in .NET, and certainly not with a simple API call like I'd expect) - so this leads to a couple questions:</p>
  
  <ol>
  <li>Is there a reason the signature isn't checked? What other benefits are there to signing without this check?</li>
  <li>Is trying to verify the signature as a means of tamper detection so futile that it's pointless to try?</li>
  <li>How do you check the certificate of the current executable in .NET?</li>
  </ol>