Windows signtool未能使用时间戳对SHA2和SHA1进行双重签名

Windows signtool未能使用时间戳对SHA2和SHA1进行双重签名,windows,sha256,authenticode,signtool,verisign,Windows,Sha256,Authenticode,Signtool,Verisign,我们需要使用signtool.exe使用SHA1和SHA2对二进制文件进行双重签名,我们的证书支持256位SHA2 使用Windows 8 SDK的signtool: e、 g: signtool.exe sign/as/fd sha256/t/f“certificate.pfx”/p XXXXXXX“file.dll” (其中XXXXXXX是我们的证书密码) 失败,出现神秘错误: SignTool错误:SignedCode::Sign返回错误:0x80070057 参数不正确。 SignToo

我们需要使用signtool.exe使用SHA1和SHA2对二进制文件进行双重签名,我们的证书支持256位SHA2

使用Windows 8 SDK的signtool:

e、 g:

signtool.exe sign/as/fd sha256/t/f“certificate.pfx”/p XXXXXXX“file.dll”

(其中XXXXXXX是我们的证书密码)

失败,出现神秘错误:

SignTool错误:SignedCode::Sign返回错误:0x80070057 参数不正确。 SignTool错误:尝试签名时出错:file.dll

没有时间戳的签名是有效的,像SHA1或SH256那样单独签名是有效的,但是我们需要双重签名,想象一下没有时间戳是不行的

我试过signtool.exe的32位和64位版本,在Win7和Win8机器上试过,还试过使用命令行选项,但都没有用。以前有人提到过这个问题吗?

尝试使用

signtool.exe sign /as /fd sha256 /tr http://timestamp.geotrust.com /td sha256 /f certificate.pfx /p XXXXXX file.dll

/tr表示RFC3161时间戳,/td显然表示要使用散列。

我也得到了上述错误,但是在使用'-nest'选项时,它与实用程序一起工作:

osslsigncode sign -pkcs12 cert1.pfx -h sha1 -t http://timestamp.verisign.com/scripts/timestamp.dll -in original.exe -out intermediate.exe
osslsigncode sign -pkcs12 cert2.pfx -nest -h sha1 -t http://timestamp.verisign.com/scripts/timestamp.dll -in intermediate.exe -out final.exe

官方项目是针对Unix的,不过我自己也做了一些改进。

我一直在尝试做这件事,发现下面的方法成功了。此方法依赖于使用两个Authenticode证书,一个用于SHA-1,另一个用于SHA-256,以确保Windows Vista和Windows Server 2008接受文件为有效文件,即使使用SHA-1算法,也不支持由SHA-256证书签名:

signtool.exe sign /sha1 SHA1_Thumprint /v /d "FileDescription" /du "CompanyURL" /fd sha1 /tr http://timestamp.comodoca.com/rfc3161 /td sha1 "FileName.dll"
signtool.exe sign /sha1 SHA256_Thumprint /as /v /d "FileDescription" /du "CompanyURL" /fd sha256 /tr http://timestamp.comodoca.com/rfc3161 /td sha256 "FileName.dll"
请注意,使用
/sha1
开关为每个签名步骤明确指定SHA-1指纹,
/as
用于附加SHA-256签名。否则,SHA-256签名将覆盖SHA-1签名

我在这个过程中发现的另一个问题是,只有DLL和EXE支持双重签名。MSI安装程序不支持

2015年12月29日更新:

SHA-1/SHA-256指纹的格式为40个字符的十六进制大写字符串,不带空格。例如:

signtool.exe sign /sha1 0123456789ABCDEF0123456789ABCDEF01234567 /as /v /d "FileDescription" /du "CompanyURL" /fd sha256 /tr http://timestamp.comodoca.com/rfc3161 /td sha256 "FileName.dll"
2015年12月30日更新

要使用SHA-256证书但使用SHA-1哈希对MSI文件进行签名,请使用类似于以下命令的命令:

signtool.exe sign /sha1 SHA256_Thumprint /v /d "FileDescription" /du "CompanyURL" /t http://timestamp.comodoca.com/authenticode "FileName.msi"

除了martin_costello answer之外,XP和Vista不支持RFC时间戳。您需要对sha1签名使用/t选项

signtool.exe sign /sha1 SHA1_Thumprint /v /d "FileDescription" /du "CompanyURL" /fd sha1 /t http://timestamp.verisign.com/scripts/timestamp.dll "FileName.dll"
signtool.exe sign /sha1 SHA256_Thumprint /as /v /d "FileDescription" /du "CompanyURL" /fd sha256 /tr http://timestamp.comodoca.com/rfc3161 /td sha256 "FileName.dll"

我知道它有点老了,但我在这条线着陆,也许其他人也会

如果您先使用SHA1,然后使用SHA256签名,则该功能将起作用:

signtool.exe sign /f cert_file.pfx /t http://timestamp.comodoca.com/authenticode /p cert_password
signtool.exe sign /f cert_file.pfx /as /fd sha256 /tr http://timestamp.comodoca.com/rfc3161 /td sha256 /p cert_password 
它在两个签名中使用相同的证书。我使用了Windows10SDK中的signtool,不知道它是否适用于以前的版本。

我认为它有一些很好的指针。martin_costello的回答中提到了其中一些,但本文提供了更多细节。特别是:

  • 如果先对SHA1进行签名,并对SHA256使用/as,则可以使用“双重签名并包含SHA1文件摘要”。但它仅适用于Windows 8.1 SDK(或更高版本)中的signtool v6.3
  • XP sp3之前的windows版本需要具有“完整SHA1签名”的双重签名,需要两个不同的证书

(不过我自己还没有测试过所有这些。)

这个问题实际上要简单得多

问题在于时间戳服务器

而不是使用signtool.exe

/t http://timestamp.comodoca.com 
你需要像这样为SHA1使用它

/tr http://timestamp.comodoca.com /td sha1
SHA256呢

/tr http://timestamp.comodoca.com/?td=sha256 /td sha256

这是否意味着需要购买两种不同的证书?或者,复制和重命名就足够了吗?是的,不幸的是,这就足够了(除非有人知道得更清楚)。我无法获取用于生成SHA-1签名的SHA-256证书以在Windows Server 2008上被接受为有效。是否可以使用指纹格式进行更新?简单地从certmgr.msc复制字符串是不起作用的。我将对此进行更新。从记忆中看,都是大写,没有空格。谢谢,这很有帮助!只要我按此顺序操作,我就可以使用signtool Windows 8.1 SDK和MIS。MSI在Windows 2008上显示受信任。表示“请注意,您确实需要6.3版本的Signtool来完成此操作。它随Windows 8.1 SDK一起提供”。