我正在使用 certifi python 模块来验证 ssl 连接。我查看了 certifi (python2.7/site-packages/certifi/cacert.pem) 中包含的根证书,其中一些证书已过期。如何更新这些证书?我尝试使用 pip 更新 certifi 包,但这只会更新包而不是根 CA 文件。
我正在尝试获取badssl.com子域的服务器证书(例如https://expired.badssl.com).
import ssl
ssl.get_server_certificate(('expired.badssl.com', 443))
Run Code Online (Sandbox Code Playgroud)
但是在检查上面生成的证书时,我看到证书有
身份:badssl-fallback-unknown-subdomain-or-no-sni
这意味着SNI失败了.如何获取badssl.com的不同子域的服务器证书?(我使用的是python 2.7.12)
我正在运行以下代码以连接到 mqtt 服务器。
import paho.mqtt.client as mqtt
import ssl
import uuid
client = mqtt.Client(str(uuid.uuid1()))
client.tls_set(
"ca.crt",
"client.crt",
"client.key",
cert_reqs=ssl.CERT_REQUIRED,
tls_version=ssl.PROTOCOL_TLSv1
)
client.connect(
"127.0.0.1",
8883,
)
client.loop_forever()
Run Code Online (Sandbox Code Playgroud)
此代码适用于 python2.7 版本。但是当我使用 python3.7 版本运行它时,我收到以下错误。
Traceback (most recent call last):
File "test.py", line 29, in <module>
8883,
File "virtualenvs/mqtt-xG2h6zri/lib/python3.7/site-packages/paho/mqtt/client.py", line 839, in connect
return self.reconnect()
File "mqtt-xG2h6zri/lib/python3.7/site-packages/paho/mqtt/client.py", line 994, in reconnect
sock.do_handshake()
File ".pyenv/versions/3.7.0/lib/python3.7/ssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: IP address mismatch, certificate is not valid for '127.0.0.1'. …Run Code Online (Sandbox Code Playgroud)