[英]Signing Assemblies using Certificate Thumprint using Powershell
我想要实现的目标:我想使用现有的证书指纹签署我的文件。
我有一个现有的yml
文件,其中包含在 github 工作流中执行的以下代码位:
- name: Import signing cert
shell: pwsh
id: import_cert
run: |
$pfx = [System.Convert]::FromBase64String("${{ secrets.SIGNING_CERT }}")
$certPath = '.\CompanyCertificate.pfx'
[IO.File]::WriteAllBytes($certPath, $pfx)
$certPass = ConvertTo-SecureString '${{ secrets.SIGNING_CERT_PASSWORD }}' -AsPlainText -Force
Import-PfxCertificate -FilePath $certPath -CertStoreLocation Cert:\CurrentUser\My -Password $certPass
$thumbprint = (Get-PfxCertificate -FilePath $certPath -Password $certPass).Thumbprint
echo "::set-output name=THUMB_PRINT::$thumbprint"
然后,我遍历所有需要签名的程序集并尝试对程序集(dll 和 exe)进行签名:
Write-Host "Signing assemblies"
$filesToSign = Get-ChildItem -Path "${{ github.workspace }}\folder\Programs" -Include *.dll,*.exe -Recurse |
Get-AuthenticodeSignature |
Where-Object status -eq 'NotSigned'
Set-AuthenticodeSignature -FilePath $filesToSign.path -Certificate '${{ steps.import_cert.outputs.THUMB_PRINT }}'
但我收到以下错误:
无法绑定参数“证书”。 无法将值 <"Certificate Thumbprint Redacted"> 转换为类型 "System.Security.Cryptography.X509Certificates.X509Certificate2"。 错误:“系统找不到指定的文件。”
现在我假设这是因为我正在尝试使用证书中的指纹,该指纹是从我的Import signing cert
步骤中获得的,但这是现有代码,所以我不想更改它。
我的问题:我可以使用证书指纹签署我的文件吗?
谢谢
我找到了解决方案。 我需要根据指纹搜索证书,然后将其传递给Set-AuthenticodeSignature
:
$cert = Get-ChildItem -path 'Cert:\*${{ steps.import_cert.outputs.THUMB_PRINT }}' -Recurse
Set-AuthenticodeSignature -FilePath $filesToSign.path -Certificate $cert
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.