mitmproxy/libmproxy/protocol2/socks_proxy.py

24 lines
804 B
Python
Raw Normal View History

from __future__ import (absolute_import, print_function, division)
2015-07-24 16:29:13 +00:00
from ..exceptions import ProtocolException
from ..proxy import ProxyError, Socks5ProxyMode
2015-07-25 11:31:55 +00:00
from .layer import Layer, ServerConnectionMixin
2015-07-24 16:29:13 +00:00
2015-08-11 18:27:34 +00:00
2015-08-16 21:25:02 +00:00
class Socks5Proxy(ServerConnectionMixin, Layer):
2015-07-24 16:29:13 +00:00
def __call__(self):
try:
s5mode = Socks5ProxyMode(self.config.ssl_ports)
address = s5mode.get_upstream_server(self.client_conn)[2:]
except ProxyError as e:
# TODO: Unmonkeypatch
raise ProtocolException(str(e), e)
2015-07-24 16:29:13 +00:00
2015-08-16 21:25:02 +00:00
self.server_conn.address = address
2015-07-24 16:29:13 +00:00
2015-08-11 18:27:34 +00:00
layer = self.ctx.next_layer(self)
2015-07-24 16:29:13 +00:00
for message in layer():
if not self._handle_server_message(message):
yield message
2015-08-18 12:15:08 +00:00
if self.server_conn:
self._disconnect()