【发布时间】:2016-12-12 10:08:08
【问题描述】:
我试图通过创建我自己的自签名证书并成功签署文件来了解 Windows 上可执行文件的代码签名。 signtool 抛出错误并说“未找到符合所有给定条件的证书”。
我做错了什么?
这是我所做的:
按照 MS 和其他博客的一些说明,我创建了一个自签名证书,如下所示:
New-SelfSignedCertificate -certstorelocation Cert:\LocalMachine\my -dnsname cameronnokes.com
$pwd = ConvertTo-SecureString -String "password" -Force -AsPlainText
Export-PfxCertificate -cert Cert:\LocalMachine\my\C7A94086D80A42151551A9FCCEACBC0B4A9ABA1A -FilePath 'C:\Users\Cameron Nokes\selfcert.pfx' -Password $pwd
Get-ChildItem -Recurse Cert:\LocalMachine\my
最后一个 Get-ChildItem 命令显示指纹和主题,看起来就像我期望的那样。
现在,我在 cmd 中运行:
signtool.exe sign /f selfcert.pfx /p password /debug test.ps1
The following certificates were considered:
Issued to: cameronnokes.com
Issued by: cameronnokes.com
Expires: Sat Aug 05 12:37:28 2017
SHA1 hash: C7A94086D80A42151551A9FCCEACBC0B4A9ABA1A
After EKU filter, 0 certs were left.
After expiry filter, 0 certs were left.
After Private Key filter, 0 certs were left.
SignTool Error: No certificates were found that met all the given criteria.
【问题讨论】:
-
您必须生成具有代码签名增强密钥用法的证书。你不是,这就是为什么它说在 EKU 过滤器之后没有留下任何东西。 New-SelfSignedCertificate 不允许您指定 EKU,因此您不能为此使用它。
标签: windows powershell cmd code-signing