2013-08-17 52 views
16

我准备了一个应用程序和网站,客户可以在下载之前为其设置多个选项。设置以二进制格式存储在文件末尾(附加),然后编辑后的文件发送给最终用户。问题在于文件“内容”的更改会破坏文件签名 - 是否有机会使用任何命令行工具重新签署此更改的文件?我试图使用微软的SignTool,但它在Linux上无法正常工作。在基于Linux的发行版上签署Windows应用程序

回答

15

它实际上是quite straight forward使用Mono的signtool;棘手的部分(在链接的Mozilla文章中有更详细的描述)将以正确的格式将证书从Windows复制到Linux。

将Windows PFX证书文件转换为PVK和SPC文件只需在将证书从Windows复制到Linux时执行一次;

openssl pkcs12 -in authenticode.pfx -nocerts -nodes -out key.pem 
openssl rsa -in key.pem -outform PVK -pvk-strong -out authenticode.pvk 
openssl pkcs12 -in authenticode.pfx -nokeys -nodes -out cert.pem 
openssl crl2pkcs7 -nocrl -certfile cert.pem -outform DER -out authenticode.spc 

实际上对exe的签名是直截了当的;

signcode \ 
-spc authenticode.spc \ 
-v authenticode.pvk \ 
-a sha1 -$ commercial \ 
-n My\ Application \ 
-i http://www.example.com/ \ 
-t http://timestamp.verisign.com/scripts/timstamp.dll \ 
-tr 10 \ 
MyApp.exe 
+0

你有使用这个工具的个人经验吗?您提到的那篇文章是[超过2年](https://developer.mozilla.org/en-US/docs/Signing_an_executable_with_Authenticode$history),所以有些保证它仍然是最新的会很好。 –

+0

@RobW我已经使用Mono 3.2.5使用该命令签署了可执行文件,它运行良好(实际上我只是测试过)。我现在无法测试从Windows导出证书的确切步骤,因为我不在Mac上,但我知道给出的流程与我最近使用的非常相似。 –

+0

感谢您的确认!不要担心证书,OpenSSL能够将任何东西转换为任何东西。 –

15

您可以尝试osslsigncode

要注册的EXE或MSI文件,你现在可以做的:

osslsigncode sign -certs <cert-file> -key <der-key-file> \ 
     -n "Your Application" -i http://www.yourwebsite.com/ \ 
     -in yourapp.exe -out yourapp-signed.exe 

,或者如果您使用的是PEM或PVK密钥文件用密码 带PEM证书:

osslsigncode sign -certs <cert-file> \ 
     -key <key-file> -pass <key-password> \ 
     -n "Your Application" -i http://www.yourwebsite.com/ \ 
     -in yourapp.exe -out yourapp-signed.exe 

,或者如果你想添加一个时间戳,以及:

osslsigncode sign -certs <cert-file> -key <key-file> \ 
     -n "Your Application" -i http://www.yourwebsite.com/ \ 
     -t http://timestamp.verisign.com/scripts/timstamp.dll \ 
     -in yourapp.exe -out yourapp-signed.exe 

您可以使用存储在PKCS#12容器中的证书和密钥:

osslsigncode sign -pkcs12 <pkcs12-file> -pass <pkcs12-password> \ 
     -n "Your Application" -i http://www.yourwebsite.com/ \ 
     -in yourapp.exe -out yourapp-signed.exe 

要登录一个包含java类文件的CAB文件:

osslsigncode sign -certs <cert-file> -key <key-file> \ 
     -n "Your Application" -i http://www.yourwebsite.com/ \ 
     -jp low \ 
     -in yourapp.cab -out yourapp-signed.cab 
+0

这是为我工作的解决方案。 signcode工具没有签名文件(虽然它报告签名成功) – treaz

+0

这对于在Mageia Linux下用NSIS和Ant签名我的Windows安装程序(包装Java软件)很有用。非常感谢:) – gouessej

+0

我很高兴我找到了这个伟大的解决方案!我实际上想在Windows中使用微软的signtool.exe来签署我的代码,所以我在阅读你的答案后在Windows上的Ubuntu上使用了Bash。如果其他人在同一条船上,这里是简要说明https://blog.synapp.nz/2017/06/16/code-signing-a-windows-application-on-linux-on-windows/ –

相关问题