7

例如,在 Powershell 4 中,

$StackExAPIResponse = Invoke-WebRequest https://api.stackexchange.com/users/104624?site=serverfault -TimeoutSec 3 -ErrorAction Stop

该命令运行良好,但是,我有什么方法可以获取有关该请求中使用的 SSL 证书的信息,例如哈希算法、到期日期等?

编辑:我也会接受一些东西Invoke-RestMethod,等等......

4

1 回答 1

11

PowerShell cmdlet 没有执行此操作的本机方法。如果您需要证书信息,您可能必须下拉到 .Net 库。

一种方法是使用System.Net.ServicePointManager类。具体来说,FindServicePoint方法。

这必须作为与Invoke-WebRequest. 有关方法返回值的更多详细信息,请参阅 MSDN 文档,以获取有关您可以执行的操作的更多详细信息,但以下内容将为您提供您特别提到的数据。需要注意的一件事:我注意到,当我FindServicePoint在实际调用Invoke-WebRequestor之前尝试调用时,服务点上Invoke-RestMethodCertificate属性为空。

$StackExAPIResponse = Invoke-WebRequest https://api.stackexchange.com/users/104624?site=serverfault -TimeoutSec 3 -ErrorAction Stop
$servicePoint = [System.Net.ServicePointManager]::FindServicePoint("https://api.stackexchange.com")
$servicePoint.Certificate.GetCertHashString()
$servicePoint.Certificate.GetExpirationDateString()
于 2013-11-16T04:54:37.870 回答