【问题标题】:Get chain of certificates for a file with PowerShell?使用 PowerShell 获取文件的证书链?
【发布时间】:2015-03-21 23:23:42
【问题描述】:

我正在寻找一种方法,仅使用 PowerShell 来列出签名文件的证书链。专门用来获取Root证书。

因为我需要获取某些可执行文件(在已安装的软件上)所依赖的非 Microsoft 根证书的列表。这是由于使用 Microsoft KB293781 中的 PKI 过程的操作系统基线指南。只有特定的根证书应放在特定的计算机上。例如,经常使用的“VeriSign Class 3 Primary CA - G5”,只能在必要时使用。

Get-AuthenticodeSignature 仅列出颁发者。例如:Get-AuthenticodeSignature C:\windows\system32\MRT.exe

诸如“SysInternals SigCheck”之类的工具能够做到这一点sigcheck.exe -i C:\windows\System32\mrt.exe,并且可以进一步解析此信息。其他工具,如来自 Windows SDK 的 SignTool.exe 和 Didier Stevens 的 AnalyzePESig 也可以获取此信息。

但这可以仅使用 PowerShell 完成吗?也许在 Windows 中使用 WinVerifyTrust API。 https://msdn.microsoft.com/en-us/library/windows/desktop/aa382384(v=vs.85).aspx http://support2.microsoft.com/kb/323809/en-us

干杯, 泰克

【问题讨论】:

    标签: powershell scripting certificate pki authenticode


    【解决方案1】:

    这应该可以通过直接在 PowerShell 中访问 .NET 来实现。这是我使用您在问题中引用的示例文件创建的 sn-p:

    # Get a X590Certificate2 certificate object for a file
    $cert = (Get-AuthenticodeSignature -FilePath C:\windows\system32\MRT.exe).SignerCertificate
    # Create a new chain to store the certificate chain
    $chain = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Chain
    # Build the certificate chain from the file certificate
    $chain.Build($cert)
    # Return the list of certificates in the chain (the root will be the last one)
    $chain.ChainElements | ForEach-Object {$_.Certificate}
    

    这能满足您的需求吗?

    【讨论】:

    • 此方法仅在 Windows 连接到 Internet 并且能够解析 CTL / OCSP 时才有效,这在环境中是不可能的在事件查看器中打开 CAPI2 的日志记录,并获得以下信息(缩短): 名称:Microsoft-Windows-CAPI2 EventID:30 UserData - 结果无法将证书链构建到受信任的根颁发机构。 EventID: 11 - RevocationResult 由于吊销服务器脱机,吊销功能无法检查吊销。 - 结果无法将证书链构建到受信任的根权限。
    猜你喜欢
    • 2013-12-10
    • 2015-01-08
    • 1970-01-01
    • 2019-08-30
    • 1970-01-01
    • 1970-01-01
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多