【发布时间】:2016-01-27 23:46:25
【问题描述】:
Windows 7 x64、PowerShell 4.0。
我是数字签名的初学者,因此我以前阅读过这些文章:
- https://technet.microsoft.com/en-us/magazine/2008.04.powershell.aspx
- https://msdn.microsoft.com/en-us/library/bfsktky3%28v=vs.100%29.aspx
- https://msdn.microsoft.com/en-us/library/f5cs0acs%28v=vs.100%29.aspx
我需要签署我的 PowerShell 脚本。我们 Windows 域的所有用户都可以访问这些脚本。但一开始我想学着在我的电脑上做。
我将执行策略设置为AllSigned 值(具有管理员权限):
Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy AllSigned
根据 Don Jones 的文章,我创建了自己的证书(通过 VS2015 的开发人员命令提示符 [即通过 cmd.exe],具有管理员权限):
cd c:\temp
makecert -n "CN=Andrey Bushman" -a md5 -r -sv Andrey.Bushman.pvk -ss Root -sr localMachine Andrey.Bushman.cer
我在当前目录中找到了 Andrey.Bushman.cer 和 Andrey.Bushman.pvk 文件。其中第一个大小为 1 kb,第二个大小为 2 kb。所以,我看到私钥的大小超过了证书的大小。
问题 #1
这是否意味着我的证书不包含我的私钥副本?
现在我在证书存储中看到了新项目:
PS Cert:\LocalMachine\Root> Get-ChildItem | where -Property Issuer -EQ "CN=Andrey Bushman"
Directory: Microsoft.PowerShell.Security\Certificate::LocalMachine\Root
Thumbprint Subject
---------- -------
CF26A00BB7C8EB2B1EA66CA307C4B5025F636F9A CN=Andrey Bushman
然后唐·琼斯做到了:
makecert -pe -n "CN=MyCertificate" -ss MY
–a sh1 -eku 1.3.6.1.5.5.7.3.3 -iv root.pvk
–c root.cer
问题 #2
他为什么这样做? 在他这样做之前,我们已经在 cert:LocalMachine\Root 存储中拥有了我们的证书。
以此类推,我是为自己的情况做的:
makecert -pe -n "CN=Andrey Bushman" -ss MY -a md5 -iv Andrey.Bushman.pvk -ic Andrey.Bushman.cer
但是当我启动它时,我什么都没有:
gci cert:\CurrentUser\My -codesigning
没有-codesigning 标志我得到这个:
PS C:\temp> gci cert:\CurrentUser\My
Directory: Microsoft.PowerShell.Security\Certificate::CurrentUser\My
Thumbprint Subject
---------- -------
8F0D753ACA7F6631C3D967921BD06E158E1AB1AF CN=Andrey Bushman
问题 #3
为什么我在使用 -codesigning 标志时什么也得不到?
好的,我尝试签署一些文件并解决问题:
PS C:\temp> $cert = @(gci cert:\CurrentUser\My)[0]
PS C:\temp> Set-AuthenticodeSignature -FilePath .\123.ps1 -Certificate $cert
Set-AuthenticodeSignature : It isn't possible to sign the code. The specified certificate isn't suitable for the code signing
а.
line:1 char:1
+ Set-AuthenticodeSignature -FilePath .\123.ps1 -Certificate $cert
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-AuthenticodeSignature], PSArgumentException
+ FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.SetAuthenticodeSignatureCommand
问题 #4
如何使我的证书适合代码签名?
UPD
我不能问我的问题here,因为我不能在那个网站上注册(我的电子邮件没有任何内容)。我写信给支持团队的电子邮件,但他们从未回复。几年前我尝试这样做,几天前我又尝试这样做,但我得到了相同的结果。
【问题讨论】:
-
明确一点 - powershell.com 是一个(很棒的)社区网站 - 它绝不是微软针对 PowerShell 相关问题的官方支持渠道
-
我明白这一点。但是如果我不能在那个网站上注册,那么我就不能在他们的论坛上提出任何问题。为我的旧帐户(其他电子邮件)恢复密码也不起作用。
标签: powershell code-signing code-signing-certificate