python - 在 Python 的 M2Crypto 中关闭 SSLchecking

标签 python ssl soappy

有没有办法关闭 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/

相关文章:

email - 了解安全电子邮件

java - 即使在安装和验证证书后仍出现 SSL 握手错误

apache - 更改 Lets Encrypt SSL 证书的基本域名

python - 安装 SOAPpy 模块的困难

python - 按字符串拆分列表和字符串的列表

python - PySide 中出现 "QTimeLine already running"消息的原因是什么?

python - 当选择标签样式属性设置为显示: none; in python selenium时如何从下拉列表中检索值

python - 调用 Python 静态方法对象