【问题标题】:How to disable SSL3 and weak ciphers with cherrypy builtin ssl module (python 3)如何使用cherrypy内置ssl模块(python 3)禁用SSL3和弱密码
【发布时间】:2016-04-16 21:47:38
【问题描述】:

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

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

【问题讨论】:

    标签: python python-3.x ssl cherrypy


    【解决方案1】:

    要禁用 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 的内置 ssl 模块,CherryPy,而不是 pyopenssl - 它提供了 OpenSSL 模块。我尝试了您的解决方案,但使用 openssl s_client ... -ssl3 检查它与 ssl3 连接,我需要确保将其禁用。
    • @fbrundu -- 我错了,我看到你说的是 Python3,但我还是给了你 Python2 的答案!我已经编辑了上面的答案。让我知道它是否有效。
    • 很抱歉,它不起作用。与openssl s_client ... -ssl3 一起运行它总是给我Protocol : SSLv3 .. 难道ssl_context 只适用于pyOpenSSL,它不适用于Python3 上的cherrypy?
    • 我在 python2 中实现了一个“代理”,只是为了测试您的解决方案。现在它无法连接:它给了我SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
    • @MichaelRecachinas - 任何机会您都可以在 stackoverflow.com/questions/34832932/… 上重新发布您的 python 2 解决方案。谢谢!
    猜你喜欢
    • 2016-04-22
    • 2018-08-24
    • 2012-12-05
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 2017-04-02
    • 1970-01-01
    • 2020-06-30
    相关资源
    最近更新 更多