Windows: 如何使用Certum颁发的证书对exe进行签名?

Windows: How to sign exe using certificate issued by Certum?

我的目标是使用证书在 Windows 上签署一个未签名的可执行文件。根据我的常识,我知道我需要一个 public 和一个私钥对来进行数字签名。我还安装了Windows SDK,它提供了signtool.exemakecert.exe

我已经在线获得证书,包括CER、PEM和CRT文件。

我现在的问题是我必须如何使用这些工具和证书文件来签署可执行文件。根据here,CRT文件就是私钥。根据我目前所了解的情况,CER 和 PEM 文件基本相同,但编码不同。他们有什么用?它们是 public 键吗?我如何签署我的可执行文件?

编辑:我已尝试将 CRT 文件安装到证书存储区,然后使用该证书进行签名:

"C:\Program Files (x86)\Windows Kits.1\bin\x64\signtool.exe" sign /debug /fd SHA256 /a /n "<Issued_To>" /t http://timestamp.comodoca.com/authenticode <Filename>

这里 <Issued_To> 替换为证书中的数据, <Filename> 是我要签名的文件的名称。我从 signtool 得到的输出如下:

The following certificates were considered:
    ...

    Issued to: ...
    Issued by: Certum Code Signing CA SHA2
    Expires:   Thu Oct 12 14:37:04 2017
    SHA1 hash: BA081A67D3F2DDDC9268121DCBA04F43D6CD37FB

    ...

After EKU filter, 1 certs were left.
After expiry filter, 1 certs were left.
After Subject Name filter, 1 certs were left.
After Private Key filter, 0 certs were left.
SignTool Error: No certificates were found that met all the given criteria.

这解决了我的问题:http://www.anse.de/programming/code-signing-for-open-source-executable

我使用 Firefox 将证书导出为 PK2 文件。然后我将此证书安装在 Windows 上的 "Personal" 证书存储中。之后我可以使用上述命令来签署我的可执行文件:

signtool sign /fd SHA256 /a /n "<Issued_To>" /t http://timestamp.comodoca.com/authenticode <Filename>

这里<Issued_To>匹配证书中的值,<Filename>是要签名的文件名。然后对可执行文件进行签名。

为了物有所值,我为开源项目购买了 Certum Cloud Signing,下面是我如何让它工作的。 (我花了 5 个工作日的时间来处理邮件,尝试和错误并使用 google 翻译波兰语文档,所以也许我为某人节​​省了一点时间)

您首先提供您的个人信息,收到激活令牌后,您只有24小时的时间来激活它。 (即使没有指定这个信息,也不要像我一样让时间流逝)所以:

使用 link 中的 "Secret for regaining access to the SimplySign service" 看起来像:https://cloudsign.webnotarius.pl/arc/app/resetseed?token=...

在那里您将获得一个新代码,您应该在 SimplySign 移动应用程序(我相信是重置按钮)上使用它。

我无法在 google play 上找到 SimplySign 移动应用程序。所以我使用桌面浏览器找到应用程序(显示 "This app is not compatible with your device"、and/or 国家...)并使用 chrome 扩展下载 APK,然后手动安装在我的 phone.

设置移动应用程序后,它应该每分钟左右生成 6 位数的令牌。

现在在 Windows 上安装 SimplySign Desktop。使用您的电子邮件和手机中的 6 位数字令牌登录。一旦显示 "Status: Connected",它就安装了虚拟智能卡和您的证书。 SimplySign 必须保持连接才能使证书生效。

signtool.exe sign /n "Open Source Developer, Your Name" /fd SHA256 YourApp.exe

如果你不使用 /fd SHA256 你会得到:

SignTool Error: SignedCode::Sign returned error: 0x80090027
        The parameter is incorrect.
SignTool Error: An error occurred while attempting to sign: YourApp.exe 

如果您不登录 SimplySign,您将获得:

After EKU filter, 1 certs were left.
After expiry filter, 1 certs were left.
After Subject Name filter, 1 certs were left.
After Private Key filter, 0 certs were left.
SignTool Error: No certificates were found that met all the given criteria.

注意:无需安装proCertum SmartSign应用程序。