PowerShell 代码签名:如何使用带密码保护的自签名证书?
PowerShell Code Sigining: How to do use a self signed certificate with password protection?
我不熟悉使用 PowerShell 签署代码。我使用以下命令成功创建了自签名证书和签名代码
New-SelfSignedCertificate -certstorelocation cert:\LocalMachine\My -dnsname "xyz" -Type CodeSigningCert
$codecert = (Get-ChildItem cert:\LocalMachine\My\DF0E60B359BBADF625DCF4CA52C947F23713487F -CodeSigningCert)[0]
Set-AuthenticodeSignature .\test.ps1 $codecert
到目前为止一切正常。但是,我有点惊讶它在使用证书时没有提供保护。如果我使用没有管理权限的其他用户登录,我也可以使用此证书签署代码。
我试过像这样使用参数 -PIN
:
$pwd = ConvertTo-SecureString -String "meingeheimespasswort"
New-SelfSignedCertificate -certstorelocation cert:\LocalMachine\My -dnsname "xyz" -Type CodeSigningCert -PIN $pwd
$codecert = (Get-ChildItem cert:\LocalMachine\My\DF0E60B359BBADF625DCF4CA52C947F23713487F -CodeSigningCert)[0]
Set-AuthenticodeSignature .\test.ps1 $codecert
最后一个命令Set-AuthenticodeSignature
然后returns状态"unknown error"。似乎没有-password或-pin之类的参数。这是设计的原因吗?据说自签名证书仅用于测试?
对我来说,如果每个人都可以使用现有证书来签署代码,这似乎是一种安全风险。
在此先感谢您的帮助
马丁
bluuf 是正确的。
您将密钥存储在 Windows 证书存储库的本地机器节点中,然后您抱怨本地机器上的另一个用户可以访问该证书。这实际上不是 Powershell 问题。这是一个你需要学习把你的东西放在哪里的问题。
Local machine certificate store: This type of certificate store is
local to the computer and is global to all users on the computer.
Current user certificate store: This type of certificate store is local
to a user account on the computer.
参考:Local Machine and Current User Certificate Stores
安全密钥和证书存储本身就是一个行业。如果你想签署你的代码,你需要保证你的密钥和签名证书的安全。以下是 Thawte 的一篇好文章:
https://www.thawte.com/code-signing/whitepaper/best-practices-for-code-signing-certificates.pdf
我不熟悉使用 PowerShell 签署代码。我使用以下命令成功创建了自签名证书和签名代码
New-SelfSignedCertificate -certstorelocation cert:\LocalMachine\My -dnsname "xyz" -Type CodeSigningCert
$codecert = (Get-ChildItem cert:\LocalMachine\My\DF0E60B359BBADF625DCF4CA52C947F23713487F -CodeSigningCert)[0]
Set-AuthenticodeSignature .\test.ps1 $codecert
到目前为止一切正常。但是,我有点惊讶它在使用证书时没有提供保护。如果我使用没有管理权限的其他用户登录,我也可以使用此证书签署代码。
我试过像这样使用参数 -PIN
:
$pwd = ConvertTo-SecureString -String "meingeheimespasswort"
New-SelfSignedCertificate -certstorelocation cert:\LocalMachine\My -dnsname "xyz" -Type CodeSigningCert -PIN $pwd
$codecert = (Get-ChildItem cert:\LocalMachine\My\DF0E60B359BBADF625DCF4CA52C947F23713487F -CodeSigningCert)[0]
Set-AuthenticodeSignature .\test.ps1 $codecert
最后一个命令Set-AuthenticodeSignature
然后returns状态"unknown error"。似乎没有-password或-pin之类的参数。这是设计的原因吗?据说自签名证书仅用于测试?
对我来说,如果每个人都可以使用现有证书来签署代码,这似乎是一种安全风险。
在此先感谢您的帮助
马丁
bluuf 是正确的。
您将密钥存储在 Windows 证书存储库的本地机器节点中,然后您抱怨本地机器上的另一个用户可以访问该证书。这实际上不是 Powershell 问题。这是一个你需要学习把你的东西放在哪里的问题。
Local machine certificate store: This type of certificate store is local to the computer and is global to all users on the computer.
Current user certificate store: This type of certificate store is local to a user account on the computer.
参考:Local Machine and Current User Certificate Stores
安全密钥和证书存储本身就是一个行业。如果你想签署你的代码,你需要保证你的密钥和签名证书的安全。以下是 Thawte 的一篇好文章:
https://www.thawte.com/code-signing/whitepaper/best-practices-for-code-signing-certificates.pdf