Re: Get at SSL context
Stefan Krüger <[email protected]> Tue, 20 Sep 2016 06:51:58 -0700 (PDT)
| Newsgroups | gmane.comp.python.cherrypy |
|---|---|
| Message-ID | <[email protected]> |
Hi Gertjan, i don't have tested something. only looked at the documentation. in your example you are overriding the svr variable with the new server settings?! is this only a copy and paste bug? i think you already know the documentation to ssl: http://docs.cherrypy.org/en/latest/deploy.html#ssl additionally i found multiple-http-servers at http://docs.cherrypy.org/en/latest/advanced.html#multiple-http-servers-support and at http://docs.cherrypy.org/en/latest/pkg/cherrypy.html#cherrypy._cpserver.Server.ssl_context ssl_context = None When using PyOpenSSL, an instance of SSL.Context. is this the thing you have searched for? (untested copy and pasted from the documentation:) from cherrypy._cpserver import Server normal_server = Server() normal_server.socket_port = 80 normal_server.subscribe() secure_server = Server() secure_server.socket_port = 443 secure_server.ssl_certificate = "cert.pem" .... my_ssl_context = secure_server.ssl_context # do something with this context...? # now both servers are following the cherrypy life-cycle. ... cherrypy.engine.start() ... hope that helps you in some way.. sunny greetings stefan On Tuesday, September 6, 2016 at 2:10:17 PM UTC+2, Gertjan Klein wrote: > > Hi, > > I'm using CherryPy to build a little appliance accessible over the web. > I use Python 3.4 and the 'builtin' SSL module, and therefore CherryPy > calls the ssl module's create_default_context(). I would like to get at > that context to change some settings, and I can't figure out how to do > this. > > An additional complication is that I configured CherryPy to run two > servers, one for port 80 and one for port 443. Am I doing this right? > This is the code that creates and starts the servers: > > def create_server(): > # Remove default server, we need two separate ones > cherrypy.server.unsubscribe() > > # Create server for HTTPS > svr = cherrypy._cpserver.Server() > svr._socket_host = '0.0.0.0' > svr.socket_port = 443 > svr.ssl_module = 'builtin' > svr.ssl_certificate = CERT_INFO['ssl_certificate'] > svr.ssl_private_key = CERT_INFO['ssl_private_key'] > svr.ssl_certificate_chain = CERT_INFO['ssl_certificate_chain'] > svr.subscribe() > > # Create server for HTTPS > svr = cherrypy._cpserver.Server() > svr._socket_host = "0.0.0.0" > svr.socket_port = 80 > svr.subscribe() > > # Mount root server and update global config > cherrypy.tree.mount(Root(), '', CONF) > cherrypy.config.update(CONF) > > # Start the server > cherrypy.engine.start() > cherrypy.engine.block() > > (Here, CONF is a configuration dictionary specifying static dir mount > point etc., Root is the actual server class, and CERT_INFO contains > (let's encrypt) certificate file locations.) As far as I can figure out, > the actual HTTP server is not instantiated until cherrypy.engine.start() > is called, and everything I do after that seems to be ignored (which is > odd in itself). > > What can I do to access the SSL context? Is it possible at all? > > Regards, > Gertjan. > > -- You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected] Visit this group at https://groups.google.com/group/cherrypy-users. For more options, visit https://groups.google.com/d/optout.