Skip to content

GreenSSLContext does not handle the SSLContext minimum_version property and results in RecursionErrors #726

@bobh66

Description

@bobh66

This is similar to #371

Running httpx==0.19.0 with eventlet==0.30.2 results in RecursionError exceptions when httpx tries to set the minimum TLS version in the SSLContext object (encode/httpx#1873 (comment))

For example, running the following with httpx==0.19.0:

from eventlet import monkey_patch
monkey_patch(socket=False)
from httpx import Client

x = Client()

results in:

Traceback (most recent call last):
  File "eventletfoo.py", line 5, in <module>
    x = Client()
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_client.py", line 648, in __init__
    self._transport = self._init_transport(
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_client.py", line 696, in _init_transport
    return HTTPTransport(
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_transports/default.py", line 129, in __init__
    ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_config.py", line 50, in create_ssl_context
    return SSLConfig(
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_config.py", line 74, in __init__
    self.ssl_context = self.load_ssl_context()
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_config.py", line 86, in load_ssl_context
    return self.load_ssl_context_verify()
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_config.py", line 123, in load_ssl_context_verify
    context = self._create_default_ssl_context()
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_config.py", line 158, in _create_default_ssl_context
    set_minimum_tls_version_1_2(context)
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_compat.py", line 37, in set_minimum_tls_version_1_2
    context.minimum_version = ssl.TLSVersion.TLSv1_2
  File "/usr/lib/python3.8/ssl.py", line 586, in minimum_version
    super(SSLContext, SSLContext).minimum_version.__set__(self, value)
  File "/usr/lib/python3.8/ssl.py", line 586, in minimum_version
    super(SSLContext, SSLContext).minimum_version.__set__(self, value)
  File "/usr/lib/python3.8/ssl.py", line 586, in minimum_version
    super(SSLContext, SSLContext).minimum_version.__set__(self, value)
  [Previous line repeated 490 more times]
  File "/usr/lib/python3.8/ssl.py", line 584, in minimum_version
    if value == TLSVersion.SSLv3:
RecursionError: maximum recursion depth exceeded while calling a Python object

Running the same code with httpx==0.18.2 does not have the problem because they don't try to set the minimum TLS version.

The "easy" solution is for the GreenSSLContext object to handle the SSLContext minimum_version property the same way it handles the other properties. However there are additional SSLContext properties that are also not handled by GreenSSLContext, such as maximum_version, _msg_callback and hostname_checks_common_name. The maximum_version property is similar to minimum_version, but the others are more complicated so a generic solution does not appear to be trivial.

I'll push a PR for these two properties for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions