在基于Linux的发行版上签名Windows应用程序

在基于Linux的发行版上签名Windows应用程序,linux,windows,certificate,exe,sign,Linux,Windows,Certificate,Exe,Sign,我已经准备了一个应用程序和网站,客户可以在此应用程序下载之前设置几个选项。设置以二进制格式存储在文件末尾(附加),然后将编辑的文件发送给最终用户。问题是,文件“内容”的更改将破坏文件签名-是否有机会使用任何命令行工具对更改后的文件重新签名?我曾尝试使用微软的SignTool,但它在Linux上无法正常工作。实际上是使用Mono的SignTool;棘手的部分(在链接的Mozilla文章中有更详细的描述)是以正确的格式将证书从Windows复制到Linux 将Windows PFX证书文件转换为PV

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

实际上是使用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.digicert.com/scripts/timstamp.dll \
 -tr 10 \
 MyApp.exe
你可以试试

要签署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
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
osslsigncode sign -pkcs12 <pkcs12-file> -pass <pkcs12-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/ \
        -jp low \
        -in yourapp.cab -out yourapp-signed.cab
osslsigncode签名-证书-密钥\
-n“你的申请”-ihttp://www.yourwebsite.com/ \
-在yourapp.exe中-退出yourapp-signed.exe
或者如果您同时使用PEM或PVK密钥文件和密码 持有PEM证书:

osslsigncode sign -certs <cert-file> -key <der-key-file> \
        -n "Your Application" -i http://www.yourwebsite.com/ \
        -in yourapp.exe -out yourapp-signed.exe
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
osslsigncode sign -pkcs12 <pkcs12-file> -pass <pkcs12-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/ \
        -jp low \
        -in yourapp.cab -out yourapp-signed.cab
osslsigncode签名-证书\
-关键传球\
-n“你的申请”-ihttp://www.yourwebsite.com/ \
-在yourapp.exe中-退出yourapp-signed.exe
或者如果您还想添加时间戳:

osslsigncode sign -certs <cert-file> -key <der-key-file> \
        -n "Your Application" -i http://www.yourwebsite.com/ \
        -in yourapp.exe -out yourapp-signed.exe
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
osslsigncode sign -pkcs12 <pkcs12-file> -pass <pkcs12-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/ \
        -jp low \
        -in yourapp.cab -out yourapp-signed.cab
osslsigncode签名-证书-密钥\
-n“你的申请”-ihttp://www.yourwebsite.com/ \
-thttp://timestamp.verisign.com/scripts/timstamp.dll \
-在yourapp.exe中-退出yourapp-signed.exe
您可以使用PKCS#12容器中存储的证书和密钥:

osslsigncode sign -certs <cert-file> -key <der-key-file> \
        -n "Your Application" -i http://www.yourwebsite.com/ \
        -in yourapp.exe -out yourapp-signed.exe
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
osslsigncode sign -pkcs12 <pkcs12-file> -pass <pkcs12-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/ \
        -jp low \
        -in yourapp.cab -out yourapp-signed.cab
osslsigncode符号-pkcs12-pass\
-n“你的申请”-ihttp://www.yourwebsite.com/ \
-在yourapp.exe中-退出yourapp-signed.exe
对包含java类文件的CAB文件进行签名:

osslsigncode sign -certs <cert-file> -key <der-key-file> \
        -n "Your Application" -i http://www.yourwebsite.com/ \
        -in yourapp.exe -out yourapp-signed.exe
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
osslsigncode sign -pkcs12 <pkcs12-file> -pass <pkcs12-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/ \
        -jp low \
        -in yourapp.cab -out yourapp-signed.cab
osslsigncode签名-证书-密钥\
-n“你的申请”-ihttp://www.yourwebsite.com/ \
-太平绅士低\
-在yourapp.cab中-退出yourapp-signed.cab

如果您想在运行时以编程方式执行此操作,可以使用E工具。特别是当您在后端通过请求签名来生成自执行归档文件时,它会非常有用。显然,您可以使用Java/Kotlin来实现这一点(该工具的名称就是这样建议的)。以下是官方网站提供的API:

只需将此依赖项添加到项目中:


net.jsign
有关API的更多详细信息

除了通过Java
KeyStore
AuthenticodeSigner
进行签名外,它还具有
(证书、私钥)
构造函数,您可以像我在“Spring on Kotlin”后端一样自由使用它:

@Bean
fun certsChain():数组{
val事实:CertificateFactory=CertificateFactory.getInstance(“X.509”)
val`is`=ResourceUtil.getResourceFileAsInputStream(“cert/certificate.pem”)
val cer:X509Certificate=fact.generateCertificate(`is`)作为X509Certificate
返回数组(cer)
}
@豆子
乐趣privateKey():privateKey{
var key=ResourceUtil.getResourceFileAsString(“cert/privateKey.pem”)
key=key.replace(“----开始私钥-------”,“”)
key=key。替换(“\n”和“”)
key=key.replace(“----结束私钥----”,“”)
val encoded=Base64.getDecoder().decode(键)
val kf=KeyFactory.getInstance(“RSA”)
val keySpec=PKCS8EncodedKeySpec(编码)
将kf.generatePrivate(keySpec)返回为RSAPrivateKey
}
@豆子
有趣的签名者(
证书:数组,
私钥
):AuthenticodeSigner=
Authenticode签名器(证书、私钥)
.withProgramName(“您的公司名称”)
.withProgramURL(“https://something.com")
.带时间戳(true)
.具有时间戳权限(“http://timestamp.comodoca.com/authenticode");

之后,您只需
@Autowire
签名者
bean,并使用所需文件调用其方法
sign()

您有使用此工具的个人经验吗?您所指的那篇文章是,所以如果能保证它仍然是最新的,那就太好了。@RobW我已经使用Mono 3.2.5使用该命令对可执行文件进行了签名,效果很好(事实上我刚刚测试过)。我现在无法测试从Windows导出证书的确切步骤,因为我不在Mac上,但我确实知道给出的流程与我最近使用的流程非常相似。谢谢您的确认!不要担心证书,OpenSSL可以将任何内容转换为任何内容。重新键入时可能会出错:
OpenSSL:error:'cr12pkcs7'是无效命令。
请注意,第三个字符是小写字母“L”,而不是数字1@user391035检查你的拼写。它是带有L而不是1的
crl2pkcs7
。这是对我有效的解决方案。signcode工具没有对文件进行签名(尽管它报告签名成功),这将有助于使用NSIS和Ant对在Mageia Linux下创建的Windows安装程序(包装Java软件)进行签名。非常感谢:)我很高兴我找到了这个伟大的解决方案!实际上,我想用微软在Windows中的signtool.exe对我的代码进行签名,所以在阅读了你的答案后,我在Windows上的Ubuntu上使用了Bash。如果有其他人也在同一条船上,下面是详细情况