【问题标题】:Unable to use SSL on CherryPy 3.8.0无法在 CherryPy 3.8.0 上使用 SSL
【发布时间】:2016-03-05 05:47:51
【问题描述】:

我正在尝试在 CherryPy 3.8.0 上使用 SSL。我的基本示例在 SSL 上实现了 ping 响应。

我是这样设置 SSL 的配置的:

# start Web Service with some configuration
global_conf = {
       "global":    { "server.environment": "production",
                      "engine.autoreload.on": True,
                      "engine.autoreload.frequency": 5,
                      "server.socket_host": "0.0.0.0",
                      "server.socket_port": 443,
                      "cherrypy.server.ssl_module": "builtin",
                      "cherrypy.server.ssl_certificate": "cert.pem",
                      "cherrypy.server.ssl_private_key": "privkey.pem",
                      "environment": "production",
                      "log.error_file": "site.log"}
}
cherrypy.config.update(global_conf)
conf = {
    "/": {
        "request.dispatch": cherrypy.dispatch.MethodDispatcher(),
        "tools.encode.debug": True,
    }
}

但是,当我调用 Web 服务时,我得到了错误。 Httpie、cURL 和 openssl 日志如下。

httpie日志:

> http GET https://<host>:443/ping
http: error: SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:600)

cURL 日志:

> curl -v https://<host>:443/ping
* Connected to <host> (<host>) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
* Closing connection 0
curl: (35) error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

OpenSSL 日志:

> openssl s_client -host <host> -port 443
CONNECTED(00000003)
140197694400160:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:795:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 295 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
---

【问题讨论】:

    标签: python ssl curl https cherrypy


    【解决方案1】:

    简单示例:

    import cherrypy
    
    class RootServer:
        @cherrypy.expose
        def index(self, **keywords):
            return "it works!"
    
    if __name__ == '__main__':
        server_config={
            'server.socket_host': '0.0.0.0',
            'server.socket_port':443,
            'server.ssl_module':'builtin',
            'server.ssl_certificate':'cert.pem',
            'server.ssl_private_key':'privkey.pem'
        }
    
        cherrypy.config.update(server_config)
        cherrypy.quickstart(RootServer())
    

    有效。

    可能的问题:

    无效配置

    从配置中删除 cherrypy. 前缀:

    "server.ssl_module": "builtin",
    "server.ssl_certificate": "cert.pem",
    "server.ssl_private_key": "privkey.pem",
    

    当我有带有cherrypy前缀的配置时,我有完全相同的例外。当我修复它时,一切正常。

    Python 不支持 SSL

    尝试安装pyOpenSSL并将server.ssl_module替换为pyopenssl

    证书无效

    你确定你的证书是正确的吗?

    http://docs.cherrypy.org/en/latest/deploy.html#ssl-support

    【讨论】:

    【解决方案2】:

    据我所知,不同版本的 CherryPy 中的 SSL 存在一些问题。问题之一: Adding support for client certificate verification in SSLAdapter (patch included)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-24
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 2015-06-23
      • 1970-01-01
      相关资源
      最近更新 更多