aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2015-09-20 20:35:45 +0200
committerMaximilian Hils <git@maximilianhils.com>2015-09-20 20:35:45 +0200
commitdaebd1bd275a398d42cc4dbfe5c6399c7fe3b3a0 (patch)
tree5dcc3f742539b6cfd6f3dc18b53c310c37bbf291 /netlib
parent292a0aa9e671748f0ad77a5e8f8f21d40314b030 (diff)
downloadmitmproxy-daebd1bd275a398d42cc4dbfe5c6399c7fe3b3a0.tar.gz
mitmproxy-daebd1bd275a398d42cc4dbfe5c6399c7fe3b3a0.tar.bz2
mitmproxy-daebd1bd275a398d42cc4dbfe5c6399c7fe3b3a0.zip
python3++
Diffstat (limited to 'netlib')
-rw-r--r--netlib/http/authentication.py4
-rw-r--r--netlib/tcp.py28
2 files changed, 14 insertions, 18 deletions
diff --git a/netlib/http/authentication.py b/netlib/http/authentication.py
index 2055f843..5831660b 100644
--- a/netlib/http/authentication.py
+++ b/netlib/http/authentication.py
@@ -12,7 +12,7 @@ def parse_http_basic_auth(s):
user = binascii.a2b_base64(words[1])
except binascii.Error:
return None
- parts = user.split(':')
+ parts = user.split(b':')
if len(parts) != 2:
return None
return scheme, parts[0], parts[1]
@@ -69,7 +69,7 @@ class BasicProxyAuth(NullProxyAuth):
if not parts:
return False
scheme, username, password = parts
- if scheme.lower() != 'basic':
+ if scheme.lower() != b'basic':
return False
if not self.password_manager.test(username, password):
return False
diff --git a/netlib/tcp.py b/netlib/tcp.py
index f6f7d06f..40ffbd48 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -7,6 +7,7 @@ import threading
import time
import traceback
+import binascii
from six.moves import range
import certifi
@@ -78,14 +79,11 @@ class SSLKeyLogger(object):
d = os.path.dirname(self.filename)
if not os.path.isdir(d):
os.makedirs(d)
- self.f = open(self.filename, "a")
- self.f.write("\r\n")
- client_random = connection.client_random().encode("hex")
- masterkey = connection.master_key().encode("hex")
- self.f.write(
- "CLIENT_RANDOM {} {}\r\n".format(
- client_random,
- masterkey))
+ self.f = open(self.filename, "ab")
+ self.f.write(b"\r\n")
+ client_random = binascii.hexlify(connection.client_random())
+ masterkey = binascii.hexlify(connection.master_key())
+ self.f.write(b"CLIENT_RANDOM %s %s\r\n" % (client_random, masterkey))
self.f.flush()
def close(self):
@@ -140,7 +138,7 @@ class _FileLike(object):
"""
if not self.is_logging():
raise ValueError("Not logging!")
- return "".join(self._log)
+ return b"".join(self._log)
def add_log(self, v):
if self.is_logging():
@@ -216,9 +214,9 @@ class Reader(_FileLike):
except SSL.SysCallError as e:
if e.args == (-1, 'Unexpected EOF'):
break
- raise TlsException(e.message)
+ raise TlsException(str(e))
except SSL.Error as e:
- raise TlsException(e.message)
+ raise TlsException(str(e))
self.first_byte_timestamp = self.first_byte_timestamp or time.time()
if not data:
break
@@ -240,7 +238,7 @@ class Reader(_FileLike):
break
else:
result += ch
- if ch == '\n':
+ if ch == b'\n':
break
return result
@@ -757,7 +755,7 @@ class BaseHandler(_Connection):
if OpenSSL._util.lib.Cryptography_HAS_ALPN and self.ssl_established:
return self.connection.get_alpn_proto_negotiated()
else:
- return ""
+ return b""
class TCPServer(object):
@@ -829,9 +827,7 @@ class TCPServer(object):
exc = six.text_type(traceback.format_exc())
print(u'-' * 40, file=fp)
print(
- u"Error in processing of request from %s:%s" % (
- client_address.host, client_address.port
- ), file=fp)
+ u"Error in processing of request from %s" % repr(client_address), file=fp)
print(exc, file=fp)
print(u'-' * 40, file=fp)