diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-07-03 02:45:12 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-07-03 02:45:12 +0200 |
commit | 880c66fe48c5a6bb4779a8149a3551f007ff5b09 (patch) | |
tree | 8ffe1263597d7f2261cdee123bb5cce4f5d7de11 /netlib | |
parent | 9aaf10120d08e12e7aa82fc2184ca7faa35349c3 (diff) | |
download | mitmproxy-880c66fe48c5a6bb4779a8149a3551f007ff5b09.tar.gz mitmproxy-880c66fe48c5a6bb4779a8149a3551f007ff5b09.tar.bz2 mitmproxy-880c66fe48c5a6bb4779a8149a3551f007ff5b09.zip |
socks: optionally fail early
Diffstat (limited to 'netlib')
-rw-r--r-- | netlib/socks.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/netlib/socks.py b/netlib/socks.py index eef98f5c..d38b88c8 100644 --- a/netlib/socks.py +++ b/netlib/socks.py @@ -69,11 +69,16 @@ class ClientGreeting(object): ) @classmethod - def from_file(cls, f): + def from_file(cls, f, fail_early=False): + """ + :param fail_early: If true, a SocksError will be raised if the first byte does not indicate socks5. + """ ver, nmethods = struct.unpack("!BB", f.safe_read(2)) - methods = array.array("B") - methods.fromstring(f.safe_read(nmethods)) - return cls(ver, methods.tolist()) + client_greeting = cls(ver, []) + if fail_early: + client_greeting.assert_socks5() + client_greeting.methods.fromstring(f.safe_read(nmethods)) + return client_greeting def to_file(self, f): f.write(struct.pack("!BB", self.ver, len(self.methods))) @@ -115,7 +120,7 @@ class Message(object): self.ver = ver self.msg = msg self.atyp = atyp - self.addr = addr + self.addr = tcp.Address.wrap(addr) def assert_socks5(self): if self.ver != VERSION.SOCKS5: |