【问题标题】:SSLError(SSLCertVerificationError) when presenting client side cert and key呈现客户端证书和密钥时出现 SSLError(SSLCertVerificationError)
【发布时间】:2021-06-30 12:34:40
【问题描述】:

我有一个托管在公司网络后面的网站。您只能使用client.crtclient.key 连接到它。这个client.crt 由一个自签名的ca.crt 签名,在apache 配置文件中引用。

我在我的机器上安装了服务器证书(servercrt.crt),并且可以毫无问题地发出 curl 请求:

curl https://my_url.com:53234 --cert path/to/client.crt --key path/to/client.key

我还在浏览器中导入了client.crt。当导航到url 时,浏览器会要求选择客户端证书。一旦选择了正确的客户端证书,它就会毫无问题地打开页面。

但是,我在使用 python 时遇到了问题。当我尝试使用 python 连接时:

import requests
clientcertfile = './client.crt'
clientcertkeyfile = './client.key'
servercert = './servercert.pem'
requests.get(url='https://my_url.com:53234, cert= (clientcertfile, clientcertkeyfile), verify = servercert)

我收到以下错误:

SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)')

但是,当设置我不想要的 verify=False 时,我可以连接到这个 url。 requests 包只显示一个警告,最好不要设置 verify=False 选项。

我看过 hereherehere,但没有任何乐趣。

有什么想法吗?

【问题讨论】:

  • 问题不是客户端证书,而是服务器证书的验证。使用 curl 您将服务器证书添加到现有证书中,浏览器也一样。使用 python,您完全依赖于服务器证书,所以这可能是一个问题。另一个可能是服务器证书没有基本约束 CA:true,尽管在 Python/OpenSSL 中用作信任锚时需要它。检查openssl x509 -in servercert.pem -text

标签: apache ssl python-requests mutual-authentication


【解决方案1】:

显然,我为服务器使用了错误的 ca.crt。一旦我用正确的证书替换它。它解决了这个问题。

@Steffen 的评论帮助解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-21
    相关资源
    最近更新 更多