diff options
Diffstat (limited to 'libmproxy/protocol')
-rw-r--r-- | libmproxy/protocol/base.py | 3 | ||||
-rw-r--r-- | libmproxy/protocol/http.py | 12 | ||||
-rw-r--r-- | libmproxy/protocol/http_replay.py | 5 | ||||
-rw-r--r-- | libmproxy/protocol/rawtcp.py | 5 | ||||
-rw-r--r-- | libmproxy/protocol/tls.py | 22 |
5 files changed, 24 insertions, 23 deletions
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), |