Skip to content

Commit

Permalink
Add support of SSL certificate chain.
Browse files Browse the repository at this point in the history
According to http://webpy.org/cookbook/ssl you can provide only
certificate file and key file to ssl server in web.py.

Now you can also setup certificate chain file. For example:
    CherryPyWSGIServer.ssl_certificate = "/path/to/ssl_certificate"
    CherryPyWSGIServer.ssl_private_key = "/path/to/ssl_private_key"
    CherryPyWSGIServer.ssl_certificate_chain =
    "/path/to/ssl_certificate_chain"
  • Loading branch information
Mikhail Plekhanov committed Feb 9, 2015
1 parent 73f1119 commit 9f9f683
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions web/httpserver.py
Expand Up @@ -174,7 +174,7 @@ def WSGIServer(server_address, wsgi_app):

server = wsgiserver.CherryPyWSGIServer(server_address, wsgi_app, server_name="localhost")

def create_ssl_adapter(cert, key):
def create_ssl_adapter(cert, key, chain=None):
# wsgiserver tries to import submodules as cherrypy.wsgiserver.foo.
# That doesn't work as not it is web.wsgiserver.
# Patching sys.modules temporarily to make it work.
Expand All @@ -185,7 +185,7 @@ def create_ssl_adapter(cert, key):
sys.modules['cherrypy.wsgiserver'] = wsgiserver

from wsgiserver.ssl_pyopenssl import pyOpenSSLAdapter
adapter = pyOpenSSLAdapter(cert, key)
adapter = pyOpenSSLAdapter(cert, key, chain)

# We are done with our work. Cleanup the patches.
del sys.modules['cherrypy']
Expand All @@ -197,7 +197,8 @@ def create_ssl_adapter(cert, key):
if (server.ssl_adapter is None and
getattr(server, 'ssl_certificate', None) and
getattr(server, 'ssl_private_key', None)):
server.ssl_adapter = create_ssl_adapter(server.ssl_certificate, server.ssl_private_key)
server.ssl_adapter = create_ssl_adapter(server.ssl_certificate, server.ssl_private_key,
getattr(server, 'ssl_certificate_chain', None))

server.nodelay = not sys.platform.startswith('java') # TCP_NODELAY isn't supported on the JVM
return server
Expand Down

0 comments on commit 9f9f683

Please sign in to comment.