aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy
diff options
context:
space:
mode:
Diffstat (limited to 'libmproxy')
-rw-r--r--libmproxy/exceptions.py6
-rw-r--r--libmproxy/protocol/base.py3
-rw-r--r--libmproxy/protocol/http.py12
-rw-r--r--libmproxy/protocol/http_replay.py5
-rw-r--r--libmproxy/protocol/rawtcp.py5
-rw-r--r--libmproxy/protocol/tls.py22
-rw-r--r--libmproxy/proxy/modes/socks_proxy.py8
-rw-r--r--libmproxy/proxy/root_context.py4
-rw-r--r--libmproxy/proxy/server.py4
9 files changed, 35 insertions, 34 deletions
diff --git a/libmproxy/exceptions.py b/libmproxy/exceptions.py
index b55201be..8f23bd92 100644
--- a/libmproxy/exceptions.py
+++ b/libmproxy/exceptions.py
@@ -20,17 +20,17 @@ class ProtocolException(ProxyException):
pass
-class TlsException(ProtocolException):
+class TlsProtocolException(ProtocolException):
pass
-class ClientHandshakeException(TlsException):
+class ClientHandshakeException(TlsProtocolException):
def __init__(self, message, server):
super(ClientHandshakeException, self).__init__(message)
self.server = server
-class Socks5Exception(ProtocolException):
+class Socks5ProtocolException(ProtocolException):
pass
diff --git a/libmproxy/protocol/base.py b/libmproxy/protocol/base.py
index b92aeea1..af6b1c3b 100644
--- a/libmproxy/protocol/base.py
+++ b/libmproxy/protocol/base.py
@@ -6,6 +6,7 @@ import six
from netlib import tcp
from ..models import ServerConnection
from ..exceptions import ProtocolException
+from netlib.exceptions import TcpException
class _LayerCodeCompletion(object):
@@ -175,7 +176,7 @@ class ServerConnectionMixin(object):
self.channel.ask("serverconnect", self.server_conn)
try:
self.server_conn.connect()
- except tcp.NetLibError as e:
+ except TcpException as e:
six.reraise(
ProtocolException,
ProtocolException(
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py
index a876df41..baccec8c 100644
--- a/libmproxy/protocol/http.py
+++ b/libmproxy/protocol/http.py
@@ -6,10 +6,10 @@ import traceback
import six
from netlib import tcp
-from netlib.exceptions import HttpException, HttpReadDisconnect
+from netlib.exceptions import HttpException, HttpReadDisconnect, TcpException
from netlib.http import http1, Headers
from netlib.http import CONTENT_MISSING
-from netlib.tcp import NetLibError, Address
+from netlib.tcp import Address
from netlib.http.http2.connections import HTTP2Protocol
from netlib.http.http2.frame import GoAwayFrame, PriorityFrame, WindowUpdateFrame
from .. import utils
@@ -321,7 +321,7 @@ class HttpLayer(Layer):
except HttpReadDisconnect:
# don't throw an error for disconnects that happen before/between requests.
return
- except (HttpException, NetLibError) as e:
+ except (HttpException, TcpException) as e:
self.send_error_response(400, repr(e))
six.reraise(ProtocolException, ProtocolException("Error in HTTP connection: %s" % repr(e)), sys.exc_info()[2])
@@ -358,7 +358,7 @@ class HttpLayer(Layer):
self.handle_upstream_mode_connect(flow.request.copy())
return
- except (HttpException, NetLibError) as e:
+ except (HttpException, TcpException) as e:
self.send_error_response(502, repr(e))
if not flow.response:
@@ -375,7 +375,7 @@ class HttpLayer(Layer):
try:
response = make_error_response(code, message)
self.send_response(response)
- except NetLibError:
+ except TcpException:
pass
def change_upstream_proxy_server(self, address):
@@ -423,7 +423,7 @@ class HttpLayer(Layer):
try:
get_response()
- except (tcp.NetLibError, HttpException) as v:
+ except (TcpException, HttpException) as v:
self.log(
"server communication error: %s" % repr(v),
level="debug"
diff --git a/libmproxy/protocol/http_replay.py b/libmproxy/protocol/http_replay.py
index 9d61d75c..9e2a9735 100644
--- a/libmproxy/protocol/http_replay.py
+++ b/libmproxy/protocol/http_replay.py
@@ -1,10 +1,9 @@
from __future__ import (absolute_import, print_function, division)
import threading
from libmproxy.exceptions import ReplayException
-from netlib.exceptions import HttpException
+from netlib.exceptions import HttpException, TcpException
from netlib.http import http1
-from netlib.tcp import NetLibError
from ..controller import Channel
from ..models import Error, HTTPResponse, ServerConnection, make_connect_request
from .base import Kill
@@ -89,7 +88,7 @@ class RequestReplayThread(threading.Thread):
response_reply = self.channel.ask("response", self.flow)
if response_reply == Kill:
raise Kill()
- except (ReplayException, HttpException, NetLibError) as v:
+ except (ReplayException, HttpException, TcpException) as v:
self.flow.error = Error(repr(v))
if self.channel:
self.channel.ask("error", self.flow)
diff --git a/libmproxy/protocol/rawtcp.py b/libmproxy/protocol/rawtcp.py
index 24c19523..5f08fd17 100644
--- a/libmproxy/protocol/rawtcp.py
+++ b/libmproxy/protocol/rawtcp.py
@@ -5,8 +5,9 @@ import six
import sys
from OpenSSL import SSL
+from netlib.exceptions import TcpException
-from netlib.tcp import NetLibError, ssl_read_select
+from netlib.tcp import ssl_read_select
from netlib.utils import clean_bin
from ..exceptions import ProtocolException
from .base import Layer
@@ -64,7 +65,7 @@ class RawTCPLayer(Layer):
"info"
)
- except (socket.error, NetLibError, SSL.Error) as e:
+ except (socket.error, TcpException, SSL.Error) as e:
six.reraise(
ProtocolException,
ProtocolException("TCP connection closed unexpectedly: {}".format(repr(e))),
diff --git a/libmproxy/protocol/tls.py b/libmproxy/protocol/tls.py
index cf303ca1..d144e081 100644
--- a/libmproxy/protocol/tls.py
+++ b/libmproxy/protocol/tls.py
@@ -5,11 +5,11 @@ import sys
from construct import ConstructError
import six
+from netlib.exceptions import InvalidCertificateException, TcpException, TlsException
-from netlib.tcp import NetLibError, NetLibInvalidCertificateError
from netlib.http import ALPN_PROTO_HTTP1
from ..contrib.tls._constructs import ClientHello
-from ..exceptions import ProtocolException, TlsException, ClientHandshakeException
+from ..exceptions import ProtocolException, TlsProtocolException, ClientHandshakeException
from .base import Layer
@@ -295,11 +295,11 @@ class TlsLayer(Layer):
while len(client_hello) < client_hello_size:
record_header = self.client_conn.rfile.peek(offset + 5)[offset:]
if not is_tls_record_magic(record_header) or len(record_header) != 5:
- raise TlsException('Expected TLS record, got "%s" instead.' % record_header)
+ raise TlsProtocolException('Expected TLS record, got "%s" instead.' % record_header)
record_size = struct.unpack("!H", record_header[3:])[0] + 5
record_body = self.client_conn.rfile.peek(offset + record_size)[offset + 5:]
if len(record_body) != record_size - 5:
- raise TlsException("Unexpected EOF in TLS handshake: %s" % record_body)
+ raise TlsProtocolException("Unexpected EOF in TLS handshake: %s" % record_body)
client_hello += record_body
offset += record_size
client_hello_size = struct.unpack("!I", '\x00' + client_hello[1:4])[0] + 4
@@ -414,7 +414,7 @@ class TlsLayer(Layer):
# The reason for this might be difficult to find, so we try to peek here to see if it
# raises ann error.
self.client_conn.rfile.peek(1)
- except NetLibError as e:
+ except TlsException as e:
six.reraise(
ClientHandshakeException,
ClientHandshakeException(
@@ -466,7 +466,7 @@ class TlsLayer(Layer):
(tls_cert_err['depth'], tls_cert_err['errno']),
"error")
self.log("Ignoring server verification error, continuing with connection", "error")
- except NetLibInvalidCertificateError as e:
+ except InvalidCertificateException as e:
tls_cert_err = self.server_conn.ssl_verification_error
self.log(
"TLS verification failed for upstream server at depth %s with error: %s" %
@@ -474,18 +474,18 @@ class TlsLayer(Layer):
"error")
self.log("Aborting connection attempt", "error")
six.reraise(
- TlsException,
- TlsException("Cannot establish TLS with {address} (sni: {sni}): {e}".format(
+ TlsProtocolException,
+ TlsProtocolException("Cannot establish TLS with {address} (sni: {sni}): {e}".format(
address=repr(self.server_conn.address),
sni=self.sni_for_server_connection,
e=repr(e),
)),
sys.exc_info()[2]
)
- except NetLibError as e:
+ except TlsException as e:
six.reraise(
- TlsException,
- TlsException("Cannot establish TLS with {address} (sni: {sni}): {e}".format(
+ TlsProtocolException,
+ TlsProtocolException("Cannot establish TLS with {address} (sni: {sni}): {e}".format(
address=repr(self.server_conn.address),
sni=self.sni_for_server_connection,
e=repr(e),
diff --git a/libmproxy/proxy/modes/socks_proxy.py b/libmproxy/proxy/modes/socks_proxy.py
index 545c38d6..1eb7db5b 100644
--- a/libmproxy/proxy/modes/socks_proxy.py
+++ b/libmproxy/proxy/modes/socks_proxy.py
@@ -1,9 +1,9 @@
from __future__ import (absolute_import, print_function, division)
from netlib import socks
-from netlib.tcp import NetLibError
+from netlib.exceptions import TcpException
-from ...exceptions import Socks5Exception
+from ...exceptions import Socks5ProtocolException
from ...protocol import Layer, ServerConnectionMixin
@@ -47,8 +47,8 @@ class Socks5Proxy(Layer, ServerConnectionMixin):
connect_reply.to_file(self.client_conn.wfile)
self.client_conn.wfile.flush()
- except (socks.SocksError, NetLibError) as e:
- raise Socks5Exception("SOCKS5 mode failure: %s" % repr(e))
+ except (socks.SocksError, TcpException) as e:
+ raise Socks5ProtocolException("SOCKS5 mode failure: %s" % repr(e))
self.server_conn.address = connect_request.addr
diff --git a/libmproxy/proxy/root_context.py b/libmproxy/proxy/root_context.py
index 72243c59..48cb72a0 100644
--- a/libmproxy/proxy/root_context.py
+++ b/libmproxy/proxy/root_context.py
@@ -5,8 +5,8 @@ import sys
import six
from libmproxy.exceptions import ProtocolException
+from netlib.exceptions import TcpException
from netlib.http import ALPN_PROTO_H2, ALPN_PROTO_HTTP1
-from netlib.tcp import NetLibError
from ..protocol import (
RawTCPLayer, TlsLayer, Http1Layer, Http2Layer, is_tls_record_magic, ServerConnectionMixin
)
@@ -54,7 +54,7 @@ class RootContext(object):
try:
d = top_layer.client_conn.rfile.peek(3)
- except NetLibError as e:
+ except TcpException as e:
six.reraise(ProtocolException, ProtocolException(str(e)), sys.exc_info()[2])
client_tls = is_tls_record_magic(d)
diff --git a/libmproxy/proxy/server.py b/libmproxy/proxy/server.py
index 8b286458..8531b6dc 100644
--- a/libmproxy/proxy/server.py
+++ b/libmproxy/proxy/server.py
@@ -6,8 +6,8 @@ import socket
import six
from netlib import tcp
+from netlib.exceptions import TcpException
from netlib.http.http1 import assemble_response
-from netlib.tcp import NetLibError
from ..exceptions import ProtocolException, ServerException, ClientHandshakeException
from ..protocol import Kill
from ..models import ClientConnection, make_error_response
@@ -139,7 +139,7 @@ class ConnectionHandler(object):
try:
error_response = make_error_response(502, repr(e))
self.client_conn.send(assemble_response(error_response))
- except NetLibError:
+ except TcpException:
pass
except Exception:
self.log(traceback.format_exc(), "error")