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

Fix OpenSSL error with servers that do unsafe renegotiation #19

Merged
merged 1 commit into from
Jun 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions what_vpn/requests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import requests

from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
from urllib3 import PoolManager
import ssl


# https://lukasa.co.uk/2013/01/Choosing_SSL_Version_In_Requests/
# https://github.com/psf/requests/issues/4775#issuecomment-478198879
class SSLVersionAdapter(HTTPAdapter):
'''An HTTPS Transport Adapter that uses an arbitrary SSL version.'''
SSLv23 = ssl.PROTOCOL_SSLv23
Expand All @@ -18,10 +19,13 @@ def __init__(self, ssl_version=None, **kwargs):
super().__init__(**kwargs)

def init_poolmanager(self, connections, maxsize, block=False):
ssl_context = ssl.SSLContext(self.ssl_version) if self.ssl_version else ssl.SSLContext()
ssl_context.set_ciphers('DEFAULT@SECLEVEL=0')
ssl_context.options |= 1<<2 # OP_LEGACY_SERVER_CONNECT
self.poolmanager = PoolManager(num_pools=connections,
maxsize=maxsize,
block=block,
ssl_version=self.ssl_version)
ssl_context=ssl_context)


class TimeoutSession(requests.Session):
Expand All @@ -40,5 +44,4 @@ def __init__(self, *a, **kw):
super().__init__(*a, **kw)
del self.headers['user-agent']
self.verify = False
if ssl_version:
self.mount('https://', SSLVersionAdapter(ssl_version))
self.mount('https://', SSLVersionAdapter(ssl_version))