同様の問題がありました..NET 4.0以降のマシンで動作することを意図した.NET 4.0アプリケーションがあります。コード署名証明書の有効期限が切れたため、新しいものを購入し、Sha1 が廃止される予定であるため、Sha256 のものを受け取りました。私たちのビルド マシンには .NET 4.5 がインストールされているので、フレームワーク アセンブリはすべてそのマシンで更新されます。
新しい証明書に移行すると、次のエラーが .NET 4.0 マシンでのみ表示されるようになったことに気付きました。
* Activation of http://localhost/publish/Test.application resulted in exception. Following failure messages were detected:
+ Exception reading manifest from http://localhost/publish/Test.application: the manifest may not be valid or the file could not be opened.
+ Manifest XML signature is not valid.
+ SignatureDescription could not be created for the signature algorithm supplied.
少し調査した結果、このスレッドやその他のスレッドが見つかり、.NET 4.5 へのアップグレードが提案されましたが、これは私たちにとって有効な解決策ではありません。クライアントに .NET フレームワークの更新を強制したくありません (~20% はまだ使用しています)。 .NET 4.0)。私たちが思いついた解決策は次のとおりです。
- .NET 4.0 のみがインストールされているマシンでマニフェストに署名する
- mage.exe を使用する代わりに、次の PowerShell スクリプトで署名します。
function SignFile($filePath, $timeStampUri, $certThumbprint)
{
#Add-Type System.Security
$x509Store = New-Object -TypeName ([System.Security.Cryptography.X509Certificates.X509Store]) -ArgumentList ([System.Security.Cryptography.X509Certificates.StoreName]::My),([System.Security.Cryptography.X509Certificates. StoreLocation]::CurrentUser)
試す
{
$x509Store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)
$x509Certificate2Collection = $x509Store.Certificates.Find([System.Security.Cryptography.X509Certificates.X509FindType]::FindByThumbprint, $certThumbprint, $false);
もし ($x509Certificate2Collection.Count -eq 1)
{
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]@($x509Certificate2Collection)[0]
# これにより、SHA256 の代わりに SHA1 の使用が強制されます
$cert.SignatureAlgorithm.FriendlyName = ""
Add-Type -AssemblyName "Microsoft.Build.Tasks.v4.0"
[Microsoft.Build.Tasks.Deployment.ManifestUtilities.SecurityUtilities]::SignFile($cert, $timeStampUri, $filePath)
}
}
最後に
{
$x509Store.Close();
}
}
編集:私は実際にこのコマンドレットを使用してマニフェスト ファイルに署名します:
https://gist.github.com/nedyalkov/a563dd4fb04d21cb91dc
この情報が誰かの時間と労力を節約してくれることを願っています!