gpt4 book ai didi

python - 如何使用 cherrypy 内置 ssl 模块(python 3)禁用 SSL3 和弱密码

转载 作者:太空狗 更新时间:2023-10-29 23:58:11 24 4
gpt4 key购买 nike

我已将 Cherrypy 3.8.0 与 Python 3 配置为使用 SSL/TLS。但是,我想禁用 SSL3 以避免 POODLE。我搜索了文档,但不确定如何实现它。

我使用的是 cherrypy/python 内置的 ssl 模块,而不是我无法在 Python 3 下使用的 pyOpenSSL

最佳答案

要禁用 SSL3,您应该自己设置 ssl_context 变量,而不是接受默认值。下面是一个使用 Python 内置 ssl 模块(代替内置 cherrypy ssl 模块)的示例。

import cherrypy
import ssl

ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ctx.options |= ssl.OP_NO_SSLv2
ctx.options |= ssl.OP_NO_SSLv3

cherrypy.config.update(server_config)

在这种情况下,SSL 来自 OpenSSL 模块。

值得注意的是,从 Python 3.2.3 开始,ssl 模块默认禁用某些弱密码。

此外,您可以专门设置所有您想要的密码

ciphers = {
'DHE-RSA-AE256-SHA',
...
'RC4-SHA'
}

ctx.set_ciphers(':'.join(ciphers))

如果您使用 web.wsgiserver 模块中的 CherryPyWSGIServer,您可以设置默认密码

CherryPyWSGIServer.ssl_adapter.context.set_cipher_list(':'.join(ciphers))

这是详细说明上述内容的部分文档:http://docs.cherrypy.org/en/latest/pkg/cherrypy.wsgiserver.html#module-cherrypy.wsgiserver.ssl_builtin

最后,这里有一些您可能想要查看的来源(提出类似问题):

关于python - 如何使用 cherrypy 内置 ssl 模块(python 3)禁用 SSL3 和弱密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34740951/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com