【问题标题】:CAPICOM - Verify SignedCode is from a Trusted Publisher without UICAPICOM - 验证 SignedCode 来自没有 UI 的受信任的发布者
【发布时间】:2011-05-05 14:27:10
【问题描述】:
我在 .NET 3.0 C# 应用程序中使用 CAPICOM 来检查 exe 文件上的 Authenticode 签名。我需要确保证书被列为受信任的发布者。如果证书尚未受信任,使用signedCode.Verify(true) 将显示一个对话框,因此用户可以选择是否这样做。但是,signedCode.Verify(false) 正在验证签名,即使它不是来自受信任的发布者 - 大概这只是检查证书是否有效。
如何在没有 UI 的情况下检查文件上的签名是否来自有效且受信任的证书?
【问题讨论】:
标签:
c#
digital-signature
authenticode
capicom
【解决方案1】:
首先,StrongNameSignatureVerificationEx 用于程序集签名验证,而不是 Authenticode 签名验证。因此,这与原始发帖人问题的上下文无关。
关于最初的问题,您可以使用以下代码手动检查签名者证书是否正确链接到受信任的根,无需任何 GUI:
ICertificateStatus certStatus = signedCode.Signer.Certificate.IsValid();
这个想法是检索签名者的证书并告诉 CAPICom 检查它是否具有正确的信任链。
我希望这会有所帮助。
干杯,
穆尼尔 IDRASSI,IDRIX,http://www.idrix.fr
【解决方案2】:
您可能需要做的是通过带有 P/Invoke 的 mscoree.dll StrongNameSignatureVerificationEx 函数使用暴露:
[DllImport("mscoree.dll", CharSet=CharSet.Unicode)]
static extern bool StrongNameSignatureVerificationEx(string wszFilePath, bool fForceVerification, ref bool pfWasVerified);
【解决方案3】:
您可以使用 WinVerifyTrust,如 here 所示。它在 Windows XP/Vista/2008/7 上运行良好。如果您还想检查撤销列表集
RevocationChecks = WinTrustDataRevocationChecks.WholeChain;