Authenticode - Signtools /di - Sign the hash of a file with an external tool

Chico 0 Reputation points
2023-05-11T08:57:08.62+00:00

Hello,

I try to use signtool to sign the hash of an executable file with an external tool.

Unfortunately the option /di to inject the sign hash doesn't work.
There is no error message, but when I check the properties of the file there is the message "no signature was present in the subject", the cert is present but not the signature it seems.

I have followed vcsjones.dev on Custom Keys with Authenticode Signing

  • Compute the hash and add the public cert:
    signtool sign /dg "C:\scratch\dir" /fd SHA256 /f public-cert.cer notepad.exe
  • Decode the base64 hash (I have tried also without decoding)
  • Sign the hash with an external tool (RSA 1.5 - 4096 - SHA256)
  • Encode the signature in base64 (I have tried also without encoding)
  • Inject the signature (add a .signed file)
    signtool sign /di "C:\scratch\dir" notepad.exe

I think the problem is from the signature returned by my external tool but there is no much documentation on how to use and what signature is expected.

I try different permutation since 3 weeks now, any help will be so much appreciated.

Windows for business Windows Client for IT Pros User experience Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Chico 0 Reputation points
    2023-05-26T11:44:40.1033333+00:00

    The solution is to add the SHA header to the digest before signing it. The digest provided by Signtools does not contain this header, even though it is necessary for the signature to be recognized by Signtools.

    It should be documented ...


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.