| @@ -8,7 +8,7 @@ from .helpers import ( | |||||
| ) | ) | ||||
| from .protocols import Socks4Protocol, Socks5Protocol, DEFAULT_LIMIT | from .protocols import Socks4Protocol, Socks5Protocol, DEFAULT_LIMIT | ||||
| __version__ = '0.2.5' | |||||
| __version__ = '0.2.6' | |||||
| __all__ = ('Socks4Protocol', 'Socks5Protocol', 'Socks4Auth', | __all__ = ('Socks4Protocol', 'Socks5Protocol', 'Socks4Auth', | ||||
| 'Socks5Auth', 'Socks4Addr', 'Socks5Addr', 'SocksError', | 'Socks5Auth', 'Socks4Addr', 'Socks5Addr', 'SocksError', | ||||
| @@ -1,6 +1,8 @@ | |||||
| import asyncio | import asyncio | ||||
| import socket | import socket | ||||
| import struct | import struct | ||||
| from asyncio import sslproto | |||||
| from . import constants as c | from . import constants as c | ||||
| from .helpers import ( | from .helpers import ( | ||||
| Socks4Addr, Socks5Addr, Socks5Auth, Socks4Auth | Socks4Addr, Socks5Addr, Socks5Auth, Socks4Auth | ||||
| @@ -67,20 +69,20 @@ class BaseSocksProtocol(asyncio.StreamReaderProtocol): | |||||
| if self._ssl: | if self._ssl: | ||||
| # Creating a ssl transport needs to be reworked. | # Creating a ssl transport needs to be reworked. | ||||
| # See details: http://bugs.python.org/issue23749 | # 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: | else: | ||||
| self._loop.call_soon(self._app_protocol.connection_made, | self._loop.call_soon(self._app_protocol.connection_made, | ||||
| self._transport) | self._transport) | ||||
| @@ -19,8 +19,8 @@ with codecs.open(os.path.join(os.path.abspath(os.path.dirname( | |||||
| raise RuntimeError('Unable to determine version.') | 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( | setup( | ||||
| @@ -265,8 +265,12 @@ async def test_https_connect(loop): | |||||
| ws = RawTestServer(handler, scheme='https', host='127.0.0.1', loop=loop) | ws = RawTestServer(handler, scheme='https', host='127.0.0.1', loop=loop) | ||||
| await ws.start_server(loop=loop, ssl=sslcontext) | 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: | async with FakeSocks4Srv(loop) as srv: | ||||
| v_conn = ProxyConnector(loop=loop, remote_resolve=False, | v_conn = ProxyConnector(loop=loop, remote_resolve=False, | ||||
| @@ -4,7 +4,7 @@ import pytest | |||||
| import socket | import socket | ||||
| import ssl as ssllib | import ssl as ssllib | ||||
| from unittest import mock | 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 | from aiohttp.test_utils import make_mocked_coro | ||||
| import aiosocks.constants as c | import aiosocks.constants as c | ||||
| from aiosocks.protocols import BaseSocksProtocol | from aiosocks.protocols import BaseSocksProtocol | ||||
| @@ -272,10 +272,7 @@ async def test_base_make_ssl_proto(): | |||||
| proto._transport = mock.Mock() | proto._transport = mock.Mock() | ||||
| await proto.negotiate(None, None) | 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(): | async def test_base_func_negotiate_cb_call(): | ||||