diff --git a/aiosocks/__init__.py b/aiosocks/__init__.py index a1246d1..67b7866 100644 --- a/aiosocks/__init__.py +++ b/aiosocks/__init__.py @@ -8,7 +8,7 @@ ) from .protocols import Socks4Protocol, Socks5Protocol, DEFAULT_LIMIT -__version__ = '0.2.5' +__version__ = '0.2.6' __all__ = ('Socks4Protocol', 'Socks5Protocol', 'Socks4Auth', 'Socks5Auth', 'Socks4Addr', 'Socks5Addr', 'SocksError', diff --git a/aiosocks/protocols.py b/aiosocks/protocols.py index a1fa4ff..0488756 100644 --- a/aiosocks/protocols.py +++ b/aiosocks/protocols.py @@ -1,6 +1,8 @@ import asyncio import socket import struct +from asyncio import sslproto + from . import constants as c from .helpers import ( Socks4Addr, Socks5Addr, Socks5Auth, Socks4Auth @@ -67,20 +69,20 @@ async def negotiate(self, reader, writer): if self._ssl: # Creating a ssl transport needs to be reworked. # See details: http://bugs.python.org/issue23749 - sock = self._transport.get_extra_info('socket') - - # temporary fix: - self._transport.pause_reading() - self._transport._closing = True - self._transport._sock = None - self._transport._protocol = None - self._transport._loop = None - - self._transport = self._loop._make_ssl_transport( - rawsock=sock, protocol=self._app_protocol, - sslcontext=self._ssl, server_side=False, - server_hostname=self._server_hostname, - waiter=self._waiter) + self._tls_protocol = sslproto.SSLProtocol( + app_protocol=self, sslcontext=self._ssl, server_side=False, + server_hostname=self._server_hostname, waiter=self._waiter, + loop=self._loop, call_connection_made=False) + + # starttls + original_transport = self._transport + self._transport.set_protocol(self._tls_protocol) + self._transport = self._tls_protocol._app_transport + + self._tls_protocol.connection_made(original_transport) + + self._loop.call_soon(self._app_protocol.connection_made, + self._transport) else: self._loop.call_soon(self._app_protocol.connection_made, self._transport) diff --git a/setup.py b/setup.py index 62dea31..279db07 100644 --- a/setup.py +++ b/setup.py @@ -19,8 +19,8 @@ raise RuntimeError('Unable to determine version.') -if sys.version_info < (3, 5, 0): - raise RuntimeError("aiosocks requires Python 3.5+") +if sys.version_info < (3, 5, 3): + raise RuntimeError("aiosocks requires Python 3.5.3+") setup( diff --git a/tests/test_functional.py b/tests/test_functional.py index 798de9b..dcd56da 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -265,8 +265,12 @@ async def handler(request): ws = RawTestServer(handler, scheme='https', host='127.0.0.1', loop=loop) await ws.start_server(loop=loop, ssl=sslcontext) - v_fp = b's\x93\xfd:\xed\x08\x1do\xa9\xaeq9\x1a\xe3\xc5\x7f\x89\xe7l\xf9' - inv_fp = b's\x93\xfd:\xed\x08\x1do\xa9\xaeq9\x1a\xe3\xc5\x7f\x89\xe7l\x10' + v_fp = (b'0\x9a\xc9D\x83\xdc\x91\'\x88\x91\x11\xa1d\x97\xfd' + b'\xcb~7U\x14D@L' + b'\x11\xab\x99\xa8\xae\xb7\x14\xee\x8b') + inv_fp = (b'0\x9d\xc9D\x83\xdc\x91\'\x88\x91\x11\xa1d\x97\xfd' + b'\xcb~7U\x14D@L' + b'\x11\xab\x99\xa8\xae\xb7\x14\xee\x9e') async with FakeSocks4Srv(loop) as srv: v_conn = ProxyConnector(loop=loop, remote_resolve=False, diff --git a/tests/test_protocols.py b/tests/test_protocols.py index ee529f7..d242be6 100644 --- a/tests/test_protocols.py +++ b/tests/test_protocols.py @@ -4,7 +4,7 @@ import socket import ssl as ssllib from unittest import mock -from asyncio import coroutine as coro +from asyncio import coroutine as coro, sslproto from aiohttp.test_utils import make_mocked_coro import aiosocks.constants as c from aiosocks.protocols import BaseSocksProtocol @@ -272,10 +272,7 @@ async def test_base_make_ssl_proto(): proto._transport = mock.Mock() await proto.negotiate(None, None) - mtr = loop_mock._make_ssl_transport - - assert mtr.called - assert mtr.call_args[1]['sslcontext'] is ssl_context + assert isinstance(proto._transport, sslproto._SSLProtocolTransport) async def test_base_func_negotiate_cb_call():