Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use pyOpenSSL unless no SNI is detected #5443

Merged
merged 2 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ Release History
dev
---

**Bugfixes**
**Improvements**

- pyOpenSSL TLS implementation is now only used if Python
either doesn't have an `ssl` module or doesn't support
SNI. Previously pyOpenSSL was unconditionally used if available.
This applies even if pyOpenSSL is installed via the
`requests[security]` extra (#5443)

- \[Short description of non-trivial change.\]

2.23.0 (2020-02-19)
-------------------
Expand Down
20 changes: 14 additions & 6 deletions requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,22 @@ def _check_cryptography(cryptography_version):
"version!".format(urllib3.__version__, chardet.__version__),
RequestsDependencyWarning)

# Attempt to enable urllib3's SNI support, if possible
# Attempt to enable urllib3's fallback for SNI support
# if the standard library doesn't support SNI or the
# 'ssl' library isn't available.
try:
from urllib3.contrib import pyopenssl
pyopenssl.inject_into_urllib3()
try:
import ssl
except ImportError:
ssl = None

if not getattr(ssl, "HAS_SNI", False):
from urllib3.contrib import pyopenssl
pyopenssl.inject_into_urllib3()

# Check cryptography version
from cryptography import __version__ as cryptography_version
_check_cryptography(cryptography_version)
# Check cryptography version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub is rendering this oddly. Is this a tab or some kind of mixed white space?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a strange render but as far as I can tell they're all spaces.

from cryptography import __version__ as cryptography_version
_check_cryptography(cryptography_version)
except ImportError:
pass

Expand Down