有没有办法关闭 SSL 检查,以便在 python 中使用 SOAPpy 时不会生成 WrongHost 异常。
最佳答案
您可以像这样在 M2Crypto 中禁用所有对等证书检查:
from M2Crypto import SSL, httpslib
context = SSL.Context("sslv3")
# Disable certificate checking
context.set_verify(0, depth = 0)
connection = httpslib.HTTPSConnection("somehostname", 443, ssl_context=context)
# Hack (!!!) for disabling host name check <CN> == <expected host name>.
# Will affect any future SSL connections made by M2Crypto!
SSL.Connection.postConnectionCheck = None
connection.connect() # <-- this would normally raise SSL verification errors
connection.request("GET", "/")
...
我希望您知道,这实际上会禁用使用 M2Crypto 创建的任何 SSL 连接的安全性。因此,这根本不值得推荐,除非您只与一台服务器通信,并且认为中间人风险比未加密的 HTTP 更容易接受。
到目前为止,对于 M2Crypto 解决方案,但由于您的问题(与您的标题相对)要求 SOAPpy(我还没有使用过),解决方案可能会有所不同,因为 SOAPpy config似乎使用 socket
模块而不是 M2Crypto.SSL
(参见第 132 行)。我不知道如何防止 socket.ssl
模块检查主机名。
关于python - 在 Python 的 M2Crypto 中关闭 SSLchecking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2328265/