【问题标题】:Set-Authenticode appears to incorrectly sign the specified assemblySet-Authenticode 似乎错误地签署了指定的程序集
【发布时间】: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


    【解决方案1】:

    其实我是自己想出来的。

    我的代码签名管道步骤之后是强命名步骤。强命名步骤是更改程序集的哈希,使其不再匹配签名中指定的哈希。

    解决方案是将强命名步骤移到代码签名之前。现在我可以成功地对程序集进行强命名,对其进行签名,然后打包后,我可以对 nuget 包进行签名,并且所有签名在输出中都是有效的。

    【讨论】:

      猜你喜欢
      • 2018-03-24
      • 1970-01-01
      • 2011-01-05
      • 2010-09-30
      • 2018-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-02
      相关资源
      最近更新 更多