c# - 获取无效 SSL 证书 (.NET) 的详细说明

标签 c# ssl httpclient

我的服务对客户网站进行健康检查并报告他们的健康状况。网站宕机的常见问题之一是 SSL 证书出现问题。

ServicePointManager.ServerCertificateValidationCallback可以访问证书、链等并进行手动检查(当 SslPolicyErrors 不是 None 时)。

我想知道是否有一个库/方法可以解释错误(例如,证书已过期或根证书不受信任等)

最佳答案

X509Chain class可以详细解释为什么某些证书被视为无效。

  var errors = new List<string>();
  var chain = new X509Chain();
  // certificate is the one you want to check
  chain.Build(certificate);

  // traverse certificate chain
  foreach (var chainElement in chain.ChainElements)
  {
    // ChainElementStatus contains validation errors
    foreach (var status in chainElement.ChainElementStatus)
    {
      errors.Add(status.Status + " " + chainElement.Certificate + ": " + status.StatusInformation.Trim());
    }
  }

这类似于X509Certificate2.Verify确实如此(如果您查看源代码),尽管 Verify 仅返回 true 或 false。

关于c# - 获取无效 SSL 证书 (.NET) 的详细说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57879678/

相关文章:

java - 如何在底层连接有状态时使用 Apache HttpClient?

Apache HttpClient 在直接时能够通过 HTTPS 进行通信,但不能通过代理进行通信 错误 : javax.net.ssl.SSLPeerUnverifiedException:对等方未经过身份验证

file - httpClient,在分块模式下执行 Multipart 的 POST 时出现问题...

c# - wpf C# 中的内存泄漏

c# - 无法将 int 转换为 byte

ssl - 代理后面的 TYPO3 使用 http 而不是 https 生成绝对链接

c# - 使用 C# 客户端将文件上传到 https 网络服务器

c# - 从 C# 在现有 IE 窗口的选项卡中启动 URL

c# - 使用什么表达式方法来返回参数?

azure - 无法通过 mosquitto、paho 使用 X509 CA 证书连接 IoT 中心