微软是第一个宣布了SHA-1弃用计划,在2016年之后Windows和IE将不再信任SHA-1证书。正好我们公司的数字签名也到期了,索性就重新申请了sha256和sha1的新数字证书,用来给产品签名。


查阅signcode的文档发现,signcode的命令行-a是用来指定数字签名的签名算法,只支持sha1和md5,不支持sha256

/fd来指定签名,md5、sha1、sha256均支持:

SignTool.exe sign /v /as /ac /f D:\test\sign\sign_sha256\xxx.pfx /p xxxx /t http://timestamp.wosign.com/timestamp /fd sha256 被签名文件路径

常见问题:

as选项不识别的问题,可能原因:SignTool版本过低,使用win10的sdk,目录C:\Program Files (x86)\Windows Kits\10\bin\x86\signtool.exe。依赖的库有ncrypt.dll,bcrypt.dll等dll仅在vista及以上系统上有。需要拷贝到老系统上才能正常使用signtool.exe,同时拷贝同目录下的:

appxpackaging.dll
appxsip.dll
mssign32.dll
opcservices.dll
signtool.exe
signtool.exe.manifest
wintrust.dll
wintrust.dll.ini
Microsoft.Windows.Build.Appx.AppxPackaging.dll.manifest
Microsoft.Windows.Build.Appx.AppxSip.dll.manifest
Microsoft.Windows.Build.Appx.OpcServices.dll.manifest
Microsoft.Windows.Build.Signing.mssign32.dll.manifest
Microsoft.Windows.Build.Signing.wintrust.dll.manifest

再试验出现以下错误:

SignTool Error:The /t option is incompatible with the /as option.

SignTool Error: Specify the RFC 3161 timestamp server's URL instead with /tr.

 

把/t换成/tr,但是出现错误:

SignTool Error: The specified timestamp server either could not be reached orreturned an invalid response.

经过一番努力后,将http://timestamp.wosign.com/timestamp替换成http://timestamp.wosign.com/rfc3161或者ttp://timestamp.geotrust.com/tsa解决问题。http://timestamp.wosign.com/rfc3161和ttp://timestamp.geotrust.com/tsa是较新的时间戳服务格式,兼容/t和/tr,而http://timestamp.wosign.com/timestamp只适用于/t。最后将两个签名指令放到批处理文件里:

set sign_folder=%~dp0%

%sign_folder%\SignTool.exe sign /v /f %sign_folder%example.pfx /p examplepassword/tr http://timestamp.wosign.com/rfc3161 /fd sha1"%1"

%sign_folder%\SignTool.exe sign /v/as /f %sign_folder%example.pfx /p examplepassword /tr http://timestamp.wosign.com/rfc3161 /fd sha256 "%1"