Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用Windows signtool对签名进行编码_Windows_Powershell_Cmd_Code Signing - Fatal编程技术网

无法使用Windows signtool对签名进行编码

无法使用Windows signtool对签名进行编码,windows,powershell,cmd,code-signing,Windows,Powershell,Cmd,Code Signing,我试图通过创建自己的自签名证书并成功对文件进行签名来理解Windows上可执行文件的代码签名。signtool抛出一个错误并表示“未找到满足所有给定条件的证书” 我做错了什么 以下是我所做的: 按照MS和其他博客的一些说明,我创建了一个自签名证书,如下所示: New-SelfSignedCertificate -certstorelocation Cert:\LocalMachine\my -dnsname cameronnokes.com $pwd = ConvertTo-SecureStr

我试图通过创建自己的自签名证书并成功对文件进行签名来理解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.

花了一点时间来记住certreq的怪癖,默认情况下它就在那里,您可以使用它为您生成一个密钥

发出此请求。inf:

[NewRequest]
Subject = "CN=cameronnokes.com"
Exportable = TRUE
KeyLength = 2048
KeySpec = 1
KeyUsage = 0xA0
RequestType = Cert

[EnhancedKeyUsageExtension]
OID = 1.3.6.1.5.5.7.3.3 ; Code signing
然后运行以下命令:

certreq -new request.inf nothing.csr
然后可以删除request.inf和nothing.csr。此时,您的个人存储中有一个自签名代码签名证书

$Certificate = Get-ChildItem cert:\CurrentUser\My |
    Where-Object { $_.EnhancedKeyUsageList.FriendlyName -eq 'Code Signing' -and $_.NotAfter -gt (Get-Date) } |
    Sort-Object NotAfter |
    Select-Object -Last 1
在选择证书时,您不会真的希望如此含糊,就像下面的示例一样

最后,签署ps1:

Set-AuthenticodeSignature test.ps1 -Certificate $Certificate

很简单,对吗?

花了一点时间来记住certreq的怪癖,默认情况下它就在那里,您可以使用它为您生成密钥

发出此请求。inf:

[NewRequest]
Subject = "CN=cameronnokes.com"
Exportable = TRUE
KeyLength = 2048
KeySpec = 1
KeyUsage = 0xA0
RequestType = Cert

[EnhancedKeyUsageExtension]
OID = 1.3.6.1.5.5.7.3.3 ; Code signing
然后运行以下命令:

certreq -new request.inf nothing.csr
然后可以删除request.inf和nothing.csr。此时,您的个人存储中有一个自签名代码签名证书

$Certificate = Get-ChildItem cert:\CurrentUser\My |
    Where-Object { $_.EnhancedKeyUsageList.FriendlyName -eq 'Code Signing' -and $_.NotAfter -gt (Get-Date) } |
    Sort-Object NotAfter |
    Select-Object -Last 1
在选择证书时,您不会真的希望如此含糊,就像下面的示例一样

最后,签署ps1:

Set-AuthenticodeSignature test.ps1 -Certificate $Certificate

很简单,对吗?

您必须生成具有代码签名增强密钥用法的证书。你没有,这就是为什么EKU过滤器后没有留下。新的SelfSignedCertificate不允许您指定EKU,因此无法将其用于此操作。您必须生成具有代码签名增强密钥用法的证书。你没有,这就是为什么EKU过滤器后没有留下。新的SelfSignedCertificate不允许您指定EKU,因此您无法将其用于此。太棒了,这成功了!我在寻找一种使用signtool专门签名的方法。创建证书后,我能够通过将SHA1传递给signtool成功地进行签名。非常简单。哈。这看起来和我需要的一模一样-除了当我运行
certreq
时,它会提示我选择一个智能卡设备,我不知道为什么。啊-将
ProviderName=“Microsoft Enhanced Cryptographic Provider v1.0”
添加到
[NewRequest]
部分修复了这一点,因为我发现它非常棒,它成功了!我在寻找一种使用signtool专门签名的方法。创建证书后,我能够通过将SHA1传递给signtool成功地进行签名。非常简单。哈。这看起来和我需要的一模一样-除了当我运行
certreq
时,它会提示我选择一个智能卡设备,我不知道为什么。啊-将
ProviderName=“Microsoft Enhanced Cryptographic Provider v1.0”
添加到
[NewRequest]
部分为我修复了这一问题,找到了