【发布时间】:2020-04-06 02:29:30
【问题描述】:
我在使用 Set-Authenticode powershell 函数作为 Azure DevOps 管道的一部分对 .NET Standard 2.0 程序集进行签名时遇到问题。我已经写了一点powershell来通过一个目录中的汇编并将签名应用于文件夹中的每个DLL:
$project = "${{ parameters.projects }}"; # todo: what about multi-line values here
$folderPath = [System.IO.Directory]::GetParent($project)
$files = Get-ChildItem -Path $folderPath -Filter "*.dll" -Recurse
$securePassword = ConvertTo-SecureString $(CertificatePassword) -AsPlainText -Force
$certificate = Get-PfxCertificate -FilePath $(CodeSignCertificate.secureFilePath) -NoPromptForPassword -Password $securePassword
foreach($file in $files) {
Write-Host "Setting Authenticode Signature for $file"
$result = Set-AuthenticodeSignature -FilePath $file -Certificate $certificate -Force -HashAlgorithm SHA256 -IncludeChain All -TimestampServer "http://tsa.starfieldtech.com"
if ($result.Status.ToString().Contains("Error")) { Write-Error $result.StatusMessage }
else {
Write-Host $result.Status.ToString()
Write-Host $result.StatusMessage.ToString()
}
}
该过程似乎成功完成,每个已签名的 DLL 输出以下消息,根据我脚本中的三个 Write-Host 行:
Setting Authenticode Signature for D:\a\1\s\...\SomeAssembly.dll
Valid
Signature verified.
现在,在使用Nuget Package Explorer 检查构建结束时生成的 DLL 时,问题变得很明显。我看到以下错误:“文件已签名,但签名的哈希与计算的哈希不匹配”。这可以在此屏幕截图中看到(将鼠标悬停在红色错误图标上时,错误会显示为工具提示)。
我也试过了:
使用自签名证书在本地运行,似乎工作正常。
在较旧的构建代理上运行构建 - 在这种情况下,签名过程在构建过程中失败,并出现错误“Get-PfxCertificate : The specified network password is not correct”。
使用 signtool.exe。这会产生同样的错误。
我现在肯定已经没有想法了。我可能会错过什么?
【问题讨论】:
标签: powershell azure-devops azure-pipelines .net-standard authenticode