Re: Get at SSL context

Gertjan Klein <gklein-qWit8jRvyhVmR6Xm/[email protected]> Wed, 21 Sep 2016 14:17:46 +0200
Newsgroups gmane.comp.python.cherrypy
Message-ID <[email protected]>
Stefan Krüger wrote:

Thanks for your reply! It caused me to look at this again.

> in your example you are overriding the svr variable with the new 
> server settings?! is this only a copy and paste bug?

No, I create two server instances that I subscribe and then no longer 
need a reference to, so I just reuse the same name.

> ssl_context = None
> When using PyOpenSSL, an instance of SSL.Context.
>
> is this the thing you have searched for?

No. :-)  I use CherryPy with the standard ssl module, not with 
PyOpenSSL. I found, in ssl_builtin.py, that CherryPy will call the 
standard Python ssl module create_default_context, if it has one (mine, 
3.4, does). However, I couldn't find where in my source code to access 
this (or on what object).

> 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...?

I don't know if this works with PyOpenSSL, but with the builtin ssl 
module, the ssl_context property is still None at this point. Even after 
starting the engine, it is None.

However, I managed to get some debug logging going (somehow the logging 
I had setup previously did not work properly -- still have to figure out 
why!), and thanks to that I found the path to the context:

svr.httpserver.ssl_adapter.context

This only gets setup in cherrypy.engine.start(), so the above is only 
usable after that code has run. I still have to test whether changing 
things on this object actually works, but it's progress. ;-)  (One thing 
I'm worried about is whether threads that CherryPy uses will pick up 
those changes...)

Thanks, 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.