How to check if a file has a digital signature

The important missing part of the answer mentioning signtool is:

Yes, with the well known signtool.exe you can also find out, if a file is signed. No need to download another tool!

E.g. with the simple line:

signtool verify /pa myfile.exe
if %ERRORLEVEL% GEQ 1 echo This file is not signed.

(For verbose output, add a /v after /pa.)

One may ask: Why this is important? I just sign the files (again) which shall be signed and it works.

My objective is to keep builds clean, and don’t sign files a second time because not only the date is changed, but the is binary different after that.

Business example:
My client has a streamlined automated “dev ops” kind build and post build process. There are multiple sources for different file sets, and at the end all is build, tested and bundled to distribution- and for that some files have to be signed. To guarantee that some files don’t leave the unit without being signed, we used to sign all important files found on the media, even if they were already signed.

But this hasnĀ“t been clean enough ! Generally:

  1. If we sign a file again, which is already signed, the file date and binary fingerprint changes, and the file looses comparability with it’s sources, if it was simply copied.
    (At least if you sign with a timestamp, which we always do and I think is highly recommended.)

This is a severe quality loss, because this file is no longer identical to it’s predecessors although the file itself has not changed.

  1. If we sign a file again, this also could be a fault when it is a third party file which shouldn’t be signed by our company.

You can avoid both by making the signing itself conditional depending on the return code of the preceding signtool verify call mentioned.

Leave a Comment