Skip to content

Commit 932374c

Browse files
authored
Merge pull request #22 from nibrag/starttls
New starttls implemenation
2 parents d6fef33 + efd1ff0 commit 932374c

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

aiosocks/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
)
99
from .protocols import Socks4Protocol, Socks5Protocol, DEFAULT_LIMIT
1010

11-
__version__ = '0.2.5'
11+
__version__ = '0.2.6'
1212

1313
__all__ = ('Socks4Protocol', 'Socks5Protocol', 'Socks4Auth',
1414
'Socks5Auth', 'Socks4Addr', 'Socks5Addr', 'SocksError',

aiosocks/protocols.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import asyncio
22
import socket
33
import struct
4+
from asyncio import sslproto
5+
46
from . import constants as c
57
from .helpers import (
68
Socks4Addr, Socks5Addr, Socks5Auth, Socks4Auth
@@ -67,20 +69,20 @@ async def negotiate(self, reader, writer):
6769
if self._ssl:
6870
# Creating a ssl transport needs to be reworked.
6971
# See details: http://bugs.python.org/issue23749
70-
sock = self._transport.get_extra_info('socket')
71-
72-
# temporary fix:
73-
self._transport.pause_reading()
74-
self._transport._closing = True
75-
self._transport._sock = None
76-
self._transport._protocol = None
77-
self._transport._loop = None
78-
79-
self._transport = self._loop._make_ssl_transport(
80-
rawsock=sock, protocol=self._app_protocol,
81-
sslcontext=self._ssl, server_side=False,
82-
server_hostname=self._server_hostname,
83-
waiter=self._waiter)
72+
self._tls_protocol = sslproto.SSLProtocol(
73+
app_protocol=self, sslcontext=self._ssl, server_side=False,
74+
server_hostname=self._server_hostname, waiter=self._waiter,
75+
loop=self._loop, call_connection_made=False)
76+
77+
# starttls
78+
original_transport = self._transport
79+
self._transport.set_protocol(self._tls_protocol)
80+
self._transport = self._tls_protocol._app_transport
81+
82+
self._tls_protocol.connection_made(original_transport)
83+
84+
self._loop.call_soon(self._app_protocol.connection_made,
85+
self._transport)
8486
else:
8587
self._loop.call_soon(self._app_protocol.connection_made,
8688
self._transport)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
raise RuntimeError('Unable to determine version.')
2020

2121

22-
if sys.version_info < (3, 5, 0):
23-
raise RuntimeError("aiosocks requires Python 3.5+")
22+
if sys.version_info < (3, 5, 3):
23+
raise RuntimeError("aiosocks requires Python 3.5.3+")
2424

2525

2626
setup(

tests/test_functional.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,12 @@ async def handler(request):
265265
ws = RawTestServer(handler, scheme='https', host='127.0.0.1', loop=loop)
266266
await ws.start_server(loop=loop, ssl=sslcontext)
267267

268-
v_fp = b's\x93\xfd:\xed\x08\x1do\xa9\xaeq9\x1a\xe3\xc5\x7f\x89\xe7l\xf9'
269-
inv_fp = b's\x93\xfd:\xed\x08\x1do\xa9\xaeq9\x1a\xe3\xc5\x7f\x89\xe7l\x10'
268+
v_fp = (b'0\x9a\xc9D\x83\xdc\x91\'\x88\x91\x11\xa1d\x97\xfd'
269+
b'\xcb~7U\x14D@L'
270+
b'\x11\xab\x99\xa8\xae\xb7\x14\xee\x8b')
271+
inv_fp = (b'0\x9d\xc9D\x83\xdc\x91\'\x88\x91\x11\xa1d\x97\xfd'
272+
b'\xcb~7U\x14D@L'
273+
b'\x11\xab\x99\xa8\xae\xb7\x14\xee\x9e')
270274

271275
async with FakeSocks4Srv(loop) as srv:
272276
v_conn = ProxyConnector(loop=loop, remote_resolve=False,

tests/test_protocols.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import socket
55
import ssl as ssllib
66
from unittest import mock
7-
from asyncio import coroutine as coro
7+
from asyncio import coroutine as coro, sslproto
88
from aiohttp.test_utils import make_mocked_coro
99
import aiosocks.constants as c
1010
from aiosocks.protocols import BaseSocksProtocol
@@ -272,10 +272,7 @@ async def test_base_make_ssl_proto():
272272
proto._transport = mock.Mock()
273273
await proto.negotiate(None, None)
274274

275-
mtr = loop_mock._make_ssl_transport
276-
277-
assert mtr.called
278-
assert mtr.call_args[1]['sslcontext'] is ssl_context
275+
assert isinstance(proto._transport, sslproto._SSLProtocolTransport)
279276

280277

281278
async def test_base_func_negotiate_cb_call():

0 commit comments

Comments
 (0)