diff options
Diffstat (limited to 'pathod')
-rw-r--r-- | pathod/language/base.py | 4 | ||||
-rw-r--r-- | pathod/language/http.py | 12 | ||||
-rw-r--r-- | pathod/language/http2.py | 4 | ||||
-rw-r--r-- | pathod/language/message.py | 2 | ||||
-rw-r--r-- | pathod/language/websockets.py | 20 | ||||
-rw-r--r-- | pathod/language/writer.py | 4 | ||||
-rw-r--r-- | pathod/log.py | 3 | ||||
-rw-r--r-- | pathod/pathoc.py | 22 | ||||
-rw-r--r-- | pathod/pathoc_cmdline.py | 6 | ||||
-rw-r--r-- | pathod/pathod.py | 28 | ||||
-rw-r--r-- | pathod/pathod_cmdline.py | 6 | ||||
-rw-r--r-- | pathod/protocols/http.py | 8 | ||||
-rw-r--r-- | pathod/protocols/http2.py | 26 | ||||
-rw-r--r-- | pathod/protocols/websockets.py | 8 | ||||
-rw-r--r-- | pathod/test.py | 2 | ||||
-rw-r--r-- | pathod/utils.py | 5 |
16 files changed, 84 insertions, 76 deletions
diff --git a/pathod/language/base.py b/pathod/language/base.py index 11f0899d..44a888c0 100644 --- a/pathod/language/base.py +++ b/pathod/language/base.py @@ -4,8 +4,8 @@ import abc import functools import pyparsing as pp -from netlib import strutils -from netlib import human +from mitmproxy.utils import strutils +from mitmproxy.utils import human from . import generators, exceptions diff --git a/pathod/language/http.py b/pathod/language/http.py index 32f990bb..8fcf9edc 100644 --- a/pathod/language/http.py +++ b/pathod/language/http.py @@ -2,12 +2,12 @@ import abc import pyparsing as pp -from netlib.http import url -import netlib.websockets -from netlib.http import status_codes, user_agents +from mitmproxy.net.http import url +import mitmproxy.net.websockets +from mitmproxy.net.http import status_codes, user_agents from . import base, exceptions, actions, message -# TODO: use netlib.semantics.protocol assemble method, +# TODO: use mitmproxy.net.semantics.protocol assemble method, # instead of duplicating the HTTP on-the-wire representation here. # see http2 language for an example @@ -198,7 +198,7 @@ class Response(_HTTPMessage): 1, StatusCode(101) ) - headers = netlib.websockets.server_handshake_headers( + headers = mitmproxy.net.websockets.server_handshake_headers( settings.websocket_key ) for i in headers.fields: @@ -310,7 +310,7 @@ class Request(_HTTPMessage): 1, Method("get") ) - for i in netlib.websockets.client_handshake_headers().fields: + for i in mitmproxy.net.websockets.client_handshake_headers().fields: if not get_header(i[0], self.headers): tokens.append( Header( diff --git a/pathod/language/http2.py b/pathod/language/http2.py index 35fc5ba8..08c5f6d7 100644 --- a/pathod/language/http2.py +++ b/pathod/language/http2.py @@ -1,7 +1,7 @@ import pyparsing as pp -from netlib import http -from netlib.http import user_agents, Headers +from mitmproxy.net import http +from mitmproxy.net.http import user_agents, Headers from . import base, message """ diff --git a/pathod/language/message.py b/pathod/language/message.py index 03b4a2cf..6cdaaa0b 100644 --- a/pathod/language/message.py +++ b/pathod/language/message.py @@ -1,6 +1,6 @@ import abc from . import actions, exceptions -from netlib import strutils +from mitmproxy.utils import strutils LOG_TRUNCATE = 1024 diff --git a/pathod/language/websockets.py b/pathod/language/websockets.py index 417944af..a237381c 100644 --- a/pathod/language/websockets.py +++ b/pathod/language/websockets.py @@ -1,7 +1,7 @@ import random import string -import netlib.websockets -from netlib import strutils +import mitmproxy.net.websockets +from mitmproxy.utils import strutils import pyparsing as pp from . import base, generators, actions, message @@ -14,12 +14,12 @@ class WF(base.CaselessLiteral): class OpCode(base.IntField): names = { - "continue": netlib.websockets.OPCODE.CONTINUE, - "text": netlib.websockets.OPCODE.TEXT, - "binary": netlib.websockets.OPCODE.BINARY, - "close": netlib.websockets.OPCODE.CLOSE, - "ping": netlib.websockets.OPCODE.PING, - "pong": netlib.websockets.OPCODE.PONG, + "continue": mitmproxy.net.websockets.OPCODE.CONTINUE, + "text": mitmproxy.net.websockets.OPCODE.TEXT, + "binary": mitmproxy.net.websockets.OPCODE.BINARY, + "close": mitmproxy.net.websockets.OPCODE.CLOSE, + "ping": mitmproxy.net.websockets.OPCODE.PING, + "pong": mitmproxy.net.websockets.OPCODE.PONG, } max = 15 preamble = "c" @@ -215,11 +215,11 @@ class WebsocketFrame(message.Message): v = getattr(self, i, None) if v is not None: frameparts[i] = v.value - frame = netlib.websockets.FrameHeader(**frameparts) + frame = mitmproxy.net.websockets.FrameHeader(**frameparts) vals = [bytes(frame)] if bodygen: if frame.masking_key and not self.rawbody: - masker = netlib.websockets.Masker(frame.masking_key) + masker = mitmproxy.net.websockets.Masker(frame.masking_key) vals.append( generators.TransformGenerator( bodygen, diff --git a/pathod/language/writer.py b/pathod/language/writer.py index b8081989..ac0f44da 100644 --- a/pathod/language/writer.py +++ b/pathod/language/writer.py @@ -1,5 +1,5 @@ import time -from netlib.exceptions import TcpDisconnect +from mitmproxy import exceptions BLOCKSIZE = 1024 # It's not clear what the upper limit for time.sleep is. It's lower than the @@ -62,5 +62,5 @@ def write_values(fp, vals, actions, sofar=0, blocksize=BLOCKSIZE): return True elif a[1] == "inject": send_chunk(fp, a[2], blocksize, 0, len(a[2])) - except TcpDisconnect: # pragma: no cover + except exceptions.TcpDisconnect: # pragma: no cover return True diff --git a/pathod/log.py b/pathod/log.py index 37100bb1..4e5f355f 100644 --- a/pathod/log.py +++ b/pathod/log.py @@ -1,6 +1,7 @@ import time -from netlib import strutils, human +from mitmproxy.utils import strutils +from mitmproxy.utils import human def write_raw(fp, lines, timestamp=True): diff --git a/pathod/pathoc.py b/pathod/pathoc.py index e9fa5c43..066c330c 100644 --- a/pathod/pathoc.py +++ b/pathod/pathoc.py @@ -11,15 +11,19 @@ import time import OpenSSL.crypto import logging -from netlib.tutils import treq -from netlib import strutils -from netlib import tcp, certutils, websockets, socks -from netlib import exceptions -from netlib.http import http1 -from netlib import basethread +from mitmproxy.test.tutils import treq +from mitmproxy.utils import strutils +from mitmproxy.net import tcp +from mitmproxy import certs +from mitmproxy.net import websockets +from mitmproxy.net import socks +from mitmproxy import exceptions +from mitmproxy.net.http import http1 +from mitmproxy.types import basethread -from . import log, language -from .protocols import http2 +from pathod import log +from pathod import language +from pathod.protocols import http2 logging.getLogger("hpack").setLevel(logging.WARNING) @@ -76,7 +80,7 @@ class SSLInfo: } t = types.get(pk.type(), "Uknown") parts.append("\tPubkey: %s bit %s" % (pk.bits(), t)) - s = certutils.SSLCert(i) + s = certs.SSLCert(i) if s.altnames: parts.append("\tSANs: %s" % " ".join(strutils.native(n, "utf8") for n in s.altnames)) return "\n".join(parts) diff --git a/pathod/pathoc_cmdline.py b/pathod/pathoc_cmdline.py index ab330505..3b738d47 100644 --- a/pathod/pathoc_cmdline.py +++ b/pathod/pathoc_cmdline.py @@ -3,9 +3,9 @@ import argparse import os import os.path -from netlib import tcp -from netlib import version -from netlib.http import user_agents +from mitmproxy.net import tcp +from mitmproxy import version +from mitmproxy.net.http import user_agents from . import pathoc, language diff --git a/pathod/pathod.py b/pathod/pathod.py index 0f659d40..a8658361 100644 --- a/pathod/pathod.py +++ b/pathod/pathod.py @@ -4,16 +4,18 @@ import os import sys import threading -from netlib import tcp -from netlib import certutils -from netlib import websockets -from netlib import version +from mitmproxy.net import tcp +from mitmproxy import certs as mcerts +from mitmproxy.net import websockets +from mitmproxy import version import urllib -from netlib.exceptions import HttpException, HttpReadDisconnect, TcpTimeout, TcpDisconnect, \ - TlsException +from mitmproxy import exceptions -from . import language, utils, log, protocols +from pathod import language +from pathod import utils +from pathod import log +from pathod import protocols DEFAULT_CERT_DOMAIN = b"pathod.net" @@ -52,7 +54,7 @@ class SSLOptions: self.ssl_options = ssl_options self.ciphers = ciphers self.alpn_select = alpn_select - self.certstore = certutils.CertStore.from_store( + self.certstore = mcerts.CertStore.from_store( os.path.expanduser(confdir), CERTSTORE_BASENAME ) @@ -128,9 +130,9 @@ class PathodHandler(tcp.BaseHandler): with logger.ctx() as lg: try: req = self.protocol.read_request(self.rfile) - except HttpReadDisconnect: + except exceptions.HttpReadDisconnect: return None, None - except HttpException as s: + except exceptions.HttpException as s: s = str(s) lg(s) return None, dict(type="error", msg=s) @@ -252,7 +254,7 @@ class PathodHandler(tcp.BaseHandler): options=self.server.ssloptions.ssl_options, alpn_select=self.server.ssloptions.alpn_select, ) - except TlsException as v: + except exceptions.TlsException as v: s = str(v) self.server.add_log( dict( @@ -384,7 +386,7 @@ class Pathod(tcp.TCPServer): try: h.handle() h.finish() - except TcpDisconnect: # pragma: no cover + except exceptions.TcpDisconnect: # pragma: no cover log.write_raw(self.logfp, "Disconnect") self.add_log( dict( @@ -393,7 +395,7 @@ class Pathod(tcp.TCPServer): ) ) return - except TcpTimeout: + except exceptions.TcpTimeout: log.write_raw(self.logfp, "Timeout") self.add_log( dict( diff --git a/pathod/pathod_cmdline.py b/pathod/pathod_cmdline.py index 3531b8f3..ef1e983f 100644 --- a/pathod/pathod_cmdline.py +++ b/pathod/pathod_cmdline.py @@ -4,9 +4,9 @@ import os import os.path import re -from netlib import tcp -from netlib import human -from netlib import version +from mitmproxy.net import tcp +from mitmproxy.utils import human +from mitmproxy import version from . import pathod diff --git a/pathod/protocols/http.py b/pathod/protocols/http.py index 17930320..4387b4fb 100644 --- a/pathod/protocols/http.py +++ b/pathod/protocols/http.py @@ -1,6 +1,6 @@ -from netlib import version -from netlib.exceptions import TlsException -from netlib.http import http1 +from mitmproxy import version +from mitmproxy import exceptions +from mitmproxy.net.http import http1 from .. import language @@ -37,7 +37,7 @@ class HTTPProtocol: options=self.pathod_handler.server.ssloptions.ssl_options, alpn_select=self.pathod_handler.server.ssloptions.alpn_select, ) - except TlsException as v: + except exceptions.TlsException as v: s = str(v) lg(s) return None, dict(type="error", msg=s) diff --git a/pathod/protocols/http2.py b/pathod/protocols/http2.py index 4dcc4b76..118163d2 100644 --- a/pathod/protocols/http2.py +++ b/pathod/protocols/http2.py @@ -4,11 +4,11 @@ import time import hyperframe.frame from hpack.hpack import Encoder, Decoder -from netlib import utils -from netlib.http import http2 -import netlib.http.headers -import netlib.http.response -import netlib.http.request +from mitmproxy.net.http import http2 +import mitmproxy.net.http.headers +import mitmproxy.net.http.response +import mitmproxy.net.http.request +from mitmproxy.types import bidi from .. import language @@ -22,7 +22,7 @@ class TCPHandler: class HTTP2StateProtocol: - ERROR_CODES = utils.BiDi( + ERROR_CODES = bidi.BiDi( NO_ERROR=0x0, PROTOCOL_ERROR=0x1, INTERNAL_ERROR=0x2, @@ -100,7 +100,7 @@ class HTTP2StateProtocol: first_line_format, method, scheme, host, port, path = http2.parse_headers(headers) - request = netlib.http.request.Request( + request = mitmproxy.net.http.request.Request( first_line_format, method, scheme, @@ -148,7 +148,7 @@ class HTTP2StateProtocol: else: timestamp_end = None - response = netlib.http.response.Response( + response = mitmproxy.net.http.response.Response( b"HTTP/2.0", int(headers.get(':status', 502)), b'', @@ -162,15 +162,15 @@ class HTTP2StateProtocol: return response def assemble(self, message): - if isinstance(message, netlib.http.request.Request): + if isinstance(message, mitmproxy.net.http.request.Request): return self.assemble_request(message) - elif isinstance(message, netlib.http.response.Response): + elif isinstance(message, mitmproxy.net.http.response.Response): return self.assemble_response(message) else: raise ValueError("HTTP message not supported.") def assemble_request(self, request): - assert isinstance(request, netlib.http.request.Request) + assert isinstance(request, mitmproxy.net.http.request.Request) authority = self.tcp_handler.sni if self.tcp_handler.sni else self.tcp_handler.address.host if self.tcp_handler.address.port != 443: @@ -194,7 +194,7 @@ class HTTP2StateProtocol: self._create_body(request.body, stream_id))) def assemble_response(self, response): - assert isinstance(response, netlib.http.response.Response) + assert isinstance(response, mitmproxy.net.http.response.Response) headers = response.headers.copy() @@ -394,7 +394,7 @@ class HTTP2StateProtocol: else: self._handle_unexpected_frame(frm) - headers = netlib.http.headers.Headers( + headers = mitmproxy.net.http.headers.Headers( [[k, v] for k, v in self.decoder.decode(header_blocks, raw=True)] ) diff --git a/pathod/protocols/websockets.py b/pathod/protocols/websockets.py index df83461a..00ae5aa8 100644 --- a/pathod/protocols/websockets.py +++ b/pathod/protocols/websockets.py @@ -1,8 +1,8 @@ import time -from netlib import websockets -from .. import language -from netlib.exceptions import NetlibException +from mitmproxy.net import websockets +from pathod import language +from mitmproxy import exceptions class WebsocketsProtocol: @@ -16,7 +16,7 @@ class WebsocketsProtocol: started = time.time() try: frm = websockets.Frame.from_file(self.pathod_handler.rfile) - except NetlibException as e: + except exceptions.NetlibException as e: lg("Error reading websocket frame: %s" % e) return None, None ended = time.time() diff --git a/pathod/test.py b/pathod/test.py index c92cc50b..b819d723 100644 --- a/pathod/test.py +++ b/pathod/test.py @@ -3,7 +3,7 @@ import time import queue from . import pathod -from netlib import basethread +from mitmproxy.types import basethread class Daemon: diff --git a/pathod/utils.py b/pathod/utils.py index 2d077c48..44ad1f87 100644 --- a/pathod/utils.py +++ b/pathod/utils.py @@ -1,6 +1,6 @@ import os import sys -import netlib.utils +from mitmproxy.utils import data as mdata class MemBool: @@ -17,7 +17,8 @@ class MemBool: return bool(v) -data = netlib.utils.Data(__name__) +# FIXME: change this name +data = mdata.Data(__name__) def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): # pragma: no cover |