【问题标题】:getting error using self certificate verification in python ssl在 python ssl 中使用自我证书验证时出错
【发布时间】:2021-04-02 14:27:05
【问题描述】:

得到以下错误:

[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)

我在多台服务器之间使用自签名证书,现在需要在系统中集成python但无法验证自签名证书。

我正在使用的代码

context = ssl.create_default_context()
context.load_verify_locations("/var/certs.crt")
context.load_cert_chain(certfile=cert_path, keyfile=key_path)
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_REQ

resp = urllib.request.urlopen(url_string, context=ctx)

var/certs.crt 包含我正在与其建立 ssl 连接的特定服务器的证书。

cert_path & key_path 是我自己的证书和私钥,用于建立 2 路 ssl。

我检查过的东西:

1.我可以看到我的证书在context.get_ca_certs()中的load_cert_chain之后被加载

2.我试过context.verify_flags |= 0x80000,但没用。

如果ctx.verify_mode = False,那么我可以正常连接,但不会受到保护。

由于 StackOverflow 上现有的最佳答案是使用 ctx.verify = False 而不是这样,我希望这次能找到真正修复它的人。

谢谢

【问题讨论】:

    标签: python python-3.x ssl urllib3


    【解决方案1】:

    检查wireshark后,我看到python抛出了错误的错误。问题不在于自我证书,而是“证书未知”并且 SSL 握手失败。

    所以可以用 ssl.CERT_REQ 来完成

    【讨论】:

      猜你喜欢
      • 2010-11-08
      • 1970-01-01
      • 2018-12-25
      • 2013-02-18
      • 2017-08-29
      • 1970-01-01
      • 2015-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多