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

SSL: WRONG_VERSION_NUMBER #3829

Closed
04fsnape opened this issue Jun 8, 2019 · 1 comment
Closed

SSL: WRONG_VERSION_NUMBER #3829

04fsnape opened this issue Jun 8, 2019 · 1 comment
Labels

Comments

@04fsnape
Copy link

04fsnape commented Jun 8, 2019

Long story short

My program which uses aiohttp to asynchronously connect to a website via multiple instances, all running proxies leads to some errors.

Expected behaviour

I expect them to visit the website without errors.

Actual behaviour

They all work for a bit, then they start giving the error below

15:01:29.600 SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0x0873A0B0>
transport: <_SelectorSocketTransport fd=1492 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "C:\Users\x\AppData\Local\Programs\Python\Python37-32\lib\asyncio\sslproto.py", line 526, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "C:\Users\x\AppData\Local\Programs\Python\Python37-32\lib\asyncio\sslproto.py", line 207, in feed_ssldata
    self._sslobj.unwrap()
  File "C:\Users\x\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 767, in unwrap
    return self._sslobj.shutdown()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:2609)

Then some give this error

12:33:03.173 SSL handshake failed
protocol: <asyncio.sslproto.SSLProtocol object at 0x095B9A90>
transport: <_SelectorSocketTransport fd=1676 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "C:\Users\x\AppData\Local\Programs\Python\Python37-32\lib\asyncio\sslproto.py", line 625, in _on_handshake_complete
    raise handshake_exc
  File "C:\Users\x\AppData\Local\Programs\Python\Python37-32\lib\asyncio\sslproto.py", line 189, in feed_ssldata
Cannot connect to host www.<website>.co.uk:443 ssl:None [[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)]
    self._sslobj.do_handshake()
  File "C:\Users\x\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 763, in do_handshake
    self._sslobj.do_handshake()

And then they completely fail and give this error Cannot connect to host <proxy domain>:<proxy port> ssl:None [Connect call failed ('<proxy ip>', <proxy port>)], as well as this oneCannot connect to host www.<website>.co.uk:443 ssl:None [An existing connection was forcibly closed by the remote host]

Steps to reproduce

Run this with a different HTTP proxy for each instance:

import asyncio
import ClientSession from aiohttp

async def launch(url, ip, port):
    done = False
    proxy = "http://{}:{}".format(ip, port)
    async with ClientSession() as session:
        while not done:
            async with session.get(url, timeout=40, proxy=proxy) as initial:
                html_text = await initial.text()
                if x in html_text:
                    done = True
                else:
                    await asyncio.sleep(60)
        await session.close()


def main():
    tasks = []
    loop = asyncio.get_event_loop()
    for i in range(10):
        task = asyncio.ensure_future(launch(url, ip, port))
        tasks.append(task)
    loop.run_until_complete(asyncio.wait(tasks))


if __name__ == "__main__":
    main()

Your environment

Windows 10 1903, Python 3.7.3, aiohttp client 3.5.4.

@asvetlov
Copy link
Member

asvetlov commented Jun 8, 2019

aiohttp uses Python ssl module defaults.
The connected server uses too old (and insecure) SSL version that is not enabled by default (SSLv2 or SSLv3). See https://docs.python.org/3/library/ssl.html#ssl.SSLContext for creating ssl context with compromised security settings.

@asvetlov asvetlov closed this as completed Jun 8, 2019
@lock lock bot added the outdated label Jun 24, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants