Browse Source

Merge pull request #22 from nibrag/starttls

New starttls implemenation
main
nibrag 7 years ago
committed by GitHub
parent
commit
932374cce7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 24 deletions
  1. +1
    -1
      aiosocks/__init__.py
  2. +16
    -14
      aiosocks/protocols.py
  3. +2
    -2
      setup.py
  4. +6
    -2
      tests/test_functional.py
  5. +2
    -5
      tests/test_protocols.py

+ 1
- 1
aiosocks/__init__.py View File

@@ -8,7 +8,7 @@ from .helpers import (
)
from .protocols import Socks4Protocol, Socks5Protocol, DEFAULT_LIMIT

__version__ = '0.2.5'
__version__ = '0.2.6'

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


+ 16
- 14
aiosocks/protocols.py View File

@@ -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 @@ class BaseSocksProtocol(asyncio.StreamReaderProtocol):
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)


+ 2
- 2
setup.py View File

@@ -19,8 +19,8 @@ with codecs.open(os.path.join(os.path.abspath(os.path.dirname(
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(


+ 6
- 2
tests/test_functional.py View File

@@ -265,8 +265,12 @@ async def test_https_connect(loop):
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,


+ 2
- 5
tests/test_protocols.py View File

@@ -4,7 +4,7 @@ import pytest
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():


Loading…
Cancel
Save