How to timestamp Authenticode signatures when our proxy requires authentication
Hi all,
The other day a customer of mine was trying to add an Authenticode signature with timestamp to their PowerShell scripts with PowerShell itself and its Set-AuthenticodeSignature cmdlet. He was able to sign the scripts just fine, but when using the timestamp option the cmdlet was not honoring Internet Explorer Proxy settings and the timestamping process failed.
If you have never seen how to add such a signature with PowerShell, check the following sample:
First we can create a test certificate in i.e. a cmd.exe:
c:\>makecert -n "CN=PowerShell Local Certificate Root" -a sha1 -eku 1.3.6.1.5.5.7.3.3 -r -sv root.pvk root.cer -ss Root -sr localMachine
c:\>makecert -pe -n "CN=Powershell User" -ss MY -a sha1 -eku 1.3.6.1.5.5.7.3.3 -iv root.pvk -ic root.cer
Then we can create a signature with timestamp in PowerShell:
C:\PS>$cert=Get-ChildItem -Path cert:\CurrentUser\my -CodeSigningCert
C:\PS>Set-AuthenticodeSignature -filepath c:\notepad.exe -certificate $cert -IncludeChain All -TimeStampServer "https://timestamp.globalsign.com/scripts/timstamp.dll"
Additionally, remember that we have several other ways to do Authenticode signing as I already commented here:
How to sign EXE files with an Authenticode certificate (VB.NET)
How to sign EXE files with an Authenticode certificate (part 2)
So my customer tried to use signtool.exe instead, with the same results: IE proxy settings are not getting used at all and they get an error like the following:
C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin>signtool timestamp /v /t https://timestamp.globalsign.com/scripts/timstamp.dll c:\notepad.exe
Timestamping: c:\notepad.exe
SignTool Error: The specified timestamp server could not be reached.
SignTool Error: An error occurred while attempting to timestamp: c:\notepad.exe
Number of files successfully timestamped: 0
Number of errors: 1
Note that if we open Internet Explorer and enter https://timestamp.globalsign.com/scripts/timstamp.dll into the address bar, IE presents the credentials dialog box to send to the proxy and we can access the timestamp server without problems.
The cause of this issue is the following:
All signing methods we saw in my previous posts (SignTool, CAPICOM, etc.) end up using SignerSignEx API to sign, and SignerTimeStampEx API to timestamp the signature. The same applies to PowerShell's Set-AuthenticodeSignature cmdlet.
SignerTimeStampEx will connect to the remote timestamp server in a very simple way, without using any proxy info or user credentials. And this is not configurable in any way.
So I'm afraid all signing methods we have at our disposal suffer from this limitation in the API.
In order to timestamp code, it is necessary to have unrestricted access to the Internet.
I hope this helps.
Regards,
Alex (Alejandro Campos Magencio)
Comments
- Anonymous
December 15, 2010
There is a solution to use "signtool timestamp" behind an authenticating proxy. You need to install Paros (http://www.parosproxy.org/), which is a free download. In the Paros Tools->Options->Connection, configure Paros to connect to your authenticating proxy (host, port, user, passwor). Then in Internet Explorer, change the LAN settings proxy to be localhost:8080 (i.e. connect to Paros local proxy). Check that IE internet access works via Paros. Then you will find signtool works. - Anonymous
January 06, 2011
The comment has been removed - Anonymous
January 26, 2011
the last comment in here did not work for me.signtool.exe still did not use the proxy under Win7. It does under XP