-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Description
The requests library seems to grow more and more keyword arguments to try to provide all of the flexibility that SSL users need. As of Python 3.2, the Standard Library now offers a different approach: an SSLContext that can accept settings for TLS protocol version, CA certificate list, identity certificate, secret key, allowable cipher list, Diffie-Hellman parameters, server-name callback function, whether to verify server hostnames, and so forth. It has a wrap_socket() method that starts up TLS on a socket using precisely the settings it has been configured with.
This lets protocol libraries in the Python 3 Standard Library opt out of needing keyword arguments for any of the above settings. They can simply accept a context= keyword argument, use the context to wrap their encrypted sockets, and stay out of the business of understanding SSL and all of its different settings.
If the requests library under Python 3 started supporting a context= parameter like the Standard Library protocols, then users could fine-tune their encryption settings without requests having to become more complicated.
A use-case: many users today are concerned about Perfect Forward Security (PFS) and want to only make connections with ciphers that at least make it possible to build connections that cannot be decrypted later if a secret key is captured. But the current requests library, so far as I can see, makes no provision for this. Nor do I want it to: adding a new ciphers= keyword would be only the first of a dozen other keywords that SSL users will need added over the coming years. But if requests accepted a context= parameter, then I can create an SSLContext and tell it which protocols I am willing to use and have requests (and urllib3) use that context for building their SSL connections.