Ada*_*ery 7 powershell authenticode azure-devops azure-pipelines .net-standard
我在使用Set-Authenticodepowershell 函数作为 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()
}
}
Run Code Online (Sandbox Code Playgroud)
该过程似乎成功完成,根据Write-Host我脚本中的三行,每个签名的 DLL 都输出以下消息:
Setting Authenticode Signature for D:\a\1\s\...\SomeAssembly.dll
Valid
Signature verified.
Run Code Online (Sandbox Code Playgroud)
现在,在使用Nuget Package Explorer检查构建结束时生成的 DLL 时,问题变得明显。我看到以下错误:“文件已签名,但签名的哈希与计算的哈希不匹配”。这是在此屏幕截图中看到的(将鼠标悬停在红色错误图标上时,错误显示为工具提示)。
我也试过:
使用自签名证书在本地运行它,这似乎工作正常。
在较旧的构建代理上运行构建 - 在这种情况下,签名过程在构建过程中失败,并显示错误“Get-PfxCertificate:指定的网络密码不正确”。
使用 signtool.exe。这会产生相同的错误。
我现在肯定已经没有想法了。我可能会错过什么?
我实际上已经自己弄清楚了这一点。
我的代码签名管道步骤之后是强命名步骤。强命名步骤是更改程序集的哈希值,使其不再与签名中指定的哈希值匹配。
解决方案是将强命名步骤移至代码签名步骤之前。现在我可以成功地对程序集进行强命名,对其进行签名,然后在打包后,我可以对 nuget 包进行签名,并且所有签名在输出中都是有效的。
| 归档时间: |
|
| 查看次数: |
137 次 |
| 最近记录: |