diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-05-29 11:14:46 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-05-29 11:14:46 +1200 |
commit | ed415877d48251774012bd6aad4be91e9d558b79 (patch) | |
tree | e12a399c6df498f24aa5eeb9652dfaa90ab98dae /mitmproxy | |
parent | 00426534982ab7fba5617ad6422c13483a8e6521 (diff) | |
parent | 7971dce2231bc32c25b962d425d8ad935568a699 (diff) | |
download | mitmproxy-ed415877d48251774012bd6aad4be91e9d558b79.tar.gz mitmproxy-ed415877d48251774012bd6aad4be91e9d558b79.tar.bz2 mitmproxy-ed415877d48251774012bd6aad4be91e9d558b79.zip |
Merge branch 'master' into solidcore
Diffstat (limited to 'mitmproxy')
-rw-r--r-- | mitmproxy/controller.py | 6 | ||||
-rw-r--r-- | mitmproxy/dump.py | 4 | ||||
-rw-r--r-- | mitmproxy/exceptions.py | 4 | ||||
-rw-r--r-- | mitmproxy/filt.py | 1 | ||||
-rw-r--r-- | mitmproxy/flow.py | 6 | ||||
-rw-r--r-- | mitmproxy/flow_export.py | 7 | ||||
-rw-r--r-- | mitmproxy/models/connections.py | 6 | ||||
-rw-r--r-- | mitmproxy/models/http.py | 9 | ||||
-rw-r--r-- | mitmproxy/models/tcp.py | 2 | ||||
-rw-r--r-- | mitmproxy/protocol/http_replay.py | 2 | ||||
-rw-r--r-- | mitmproxy/protocol/rawtcp.py | 4 | ||||
-rw-r--r-- | mitmproxy/protocol/tls.py | 7 | ||||
-rw-r--r-- | mitmproxy/proxy/config.py | 6 | ||||
-rw-r--r-- | mitmproxy/script/script.py | 1 | ||||
-rw-r--r-- | mitmproxy/tnetstring.py | 4 |
15 files changed, 41 insertions, 28 deletions
diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py index ac7c6cbc..c43fbb84 100644 --- a/mitmproxy/controller.py +++ b/mitmproxy/controller.py @@ -12,6 +12,7 @@ class ControlError(Exception): class Master(object): + """ The master handles mitmproxy's main event loop. """ @@ -60,6 +61,7 @@ class Master(object): class ServerMaster(Master): + """ The ServerMaster adds server thread support to the master. """ @@ -86,6 +88,7 @@ class ServerMaster(Master): class ServerThread(threading.Thread): + def __init__(self, server): self.server = server super(ServerThread, self).__init__() @@ -97,6 +100,7 @@ class ServerThread(threading.Thread): class Channel(object): + """ The only way for the proxy server to communicate with the master is to use the channel it has been given. @@ -137,6 +141,7 @@ class Channel(object): class DummyReply(object): + """ A reply object that does nothing. Useful when we need an object to seem like it has a channel, and during testing. @@ -187,6 +192,7 @@ def handler(f): class Reply(object): + """ Messages sent through a channel are decorated with a "reply" attribute. This object is used to respond to the message through the return diff --git a/mitmproxy/dump.py b/mitmproxy/dump.py index c43b4c2a..cbf4b3da 100644 --- a/mitmproxy/dump.py +++ b/mitmproxy/dump.py @@ -75,8 +75,8 @@ class DumpMaster(flow.FlowMaster): if self.server and self.server.config.http2 and not tcp.HAS_ALPN: # pragma: no cover print("ALPN support missing (OpenSSL 1.0.2+ required)!\n" - "HTTP/2 is disabled. Use --no-http2 to silence this warning.", - file=sys.stderr) + "HTTP/2 is disabled. Use --no-http2 to silence this warning.", + file=sys.stderr) if options.filtstr: self.filt = filt.parse(options.filtstr) diff --git a/mitmproxy/exceptions.py b/mitmproxy/exceptions.py index 8f989063..7e3e6d86 100644 --- a/mitmproxy/exceptions.py +++ b/mitmproxy/exceptions.py @@ -13,6 +13,7 @@ import sys class ProxyException(Exception): + """ Base class for all exceptions thrown by mitmproxy. """ @@ -22,6 +23,7 @@ class ProxyException(Exception): class Kill(ProxyException): + """ Signal that both client and server connection(s) should be killed immediately. """ @@ -37,6 +39,7 @@ class TlsProtocolException(ProtocolException): class ClientHandshakeException(TlsProtocolException): + def __init__(self, message, server): super(ClientHandshakeException, self).__init__(message) self.server = server @@ -67,6 +70,7 @@ class ReplayException(ProxyException): class ScriptException(ProxyException): + @classmethod def from_exception_context(cls, cut_tb=1): """ diff --git a/mitmproxy/filt.py b/mitmproxy/filt.py index f34969dd..6228d364 100644 --- a/mitmproxy/filt.py +++ b/mitmproxy/filt.py @@ -38,6 +38,7 @@ import pyparsing as pp class _Token(object): + def dump(self, indent=0, fp=sys.stdout): print("{spacing}{name}{expr}".format( spacing="\t" * indent, diff --git a/mitmproxy/flow.py b/mitmproxy/flow.py index ba8dec5d..1b4a999a 100644 --- a/mitmproxy/flow.py +++ b/mitmproxy/flow.py @@ -8,13 +8,13 @@ import hashlib import sys import six -from six.moves import http_cookies, http_cookiejar, urllib +from six.moves import http_cookiejar +from six.moves import urllib import os import re -from typing import List, Optional, Set -from netlib import wsgi, odict +from netlib import wsgi from netlib.exceptions import HttpException from netlib.http import Headers, http1, cookies from netlib.utils import clean_bin diff --git a/mitmproxy/flow_export.py b/mitmproxy/flow_export.py index ae282fce..0f3847f1 100644 --- a/mitmproxy/flow_export.py +++ b/mitmproxy/flow_export.py @@ -5,7 +5,9 @@ import netlib.http from netlib.utils import parse_content_type import re -from six.moves.urllib.parse import urlparse, quote, quote_plus +from six.moves.urllib.parse import quote +from six.moves.urllib.parse import quote_plus + def curl_command(flow): data = "curl " @@ -123,13 +125,12 @@ def locust_code(flow): max_wait = 3000 """).strip() - components = map(lambda x: quote(x, safe=""), flow.request.path_components) file_name = "_".join(components) name = re.sub('\W|^(?=\d)', '_', file_name) url = flow.request.scheme + "://" + flow.request.host + "/" + "/".join(components) if name == "" or name is None: - new_name = "_".join([str(flow.request.host) , str(flow.request.timestamp_start)]) + new_name = "_".join([str(flow.request.host), str(flow.request.timestamp_start)]) name = re.sub('\W|^(?=\d)', '_', new_name) args = "" headers = "" diff --git a/mitmproxy/models/connections.py b/mitmproxy/models/connections.py index 91590bca..24cdff74 100644 --- a/mitmproxy/models/connections.py +++ b/mitmproxy/models/connections.py @@ -10,6 +10,7 @@ from .. import stateobject, utils class ClientConnection(tcp.BaseHandler, stateobject.StateObject): + """ A client connection @@ -21,6 +22,7 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject): timestamp_ssl_setup: TLS established timestamp timestamp_end: Connection end timestamp """ + def __init__(self, client_connection, address, server): # Eventually, this object is restored from state. We don't have a # connection then. @@ -101,6 +103,7 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject): class ServerConnection(tcp.TCPClient, stateobject.StateObject): + """ A server connection @@ -117,6 +120,7 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject): timestamp_ssl_setup: TLS established timestamp timestamp_end: Connection end timestamp """ + def __init__(self, address, source_address=None): tcp.TCPClient.__init__(self, address, source_address) @@ -182,7 +186,7 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject): timestamp_ssl_setup=None, timestamp_end=None, via=None - )) + )) def copy(self): return copy.copy(self) diff --git a/mitmproxy/models/http.py b/mitmproxy/models/http.py index 75ffbfd0..43618ef8 100644 --- a/mitmproxy/models/http.py +++ b/mitmproxy/models/http.py @@ -72,9 +72,9 @@ class HTTPRequest(MessageMixin, Request): def get_state(self): state = super(HTTPRequest, self).get_state() state.update( - stickycookie = self.stickycookie, - stickyauth = self.stickyauth, - is_replay = self.is_replay, + stickycookie=self.stickycookie, + stickyauth=self.stickyauth, + is_replay=self.is_replay, ) return state @@ -109,6 +109,7 @@ class HTTPRequest(MessageMixin, Request): class HTTPResponse(MessageMixin, Response): + """ A mitmproxy HTTP response. This is a very thin wrapper on top of :py:class:`netlib.http.Response` and @@ -124,7 +125,7 @@ class HTTPResponse(MessageMixin, Response): content, timestamp_start=None, timestamp_end=None, - is_replay = False + is_replay=False ): Response.__init__( self, diff --git a/mitmproxy/models/tcp.py b/mitmproxy/models/tcp.py index 7e966b95..b87a74ac 100644 --- a/mitmproxy/models/tcp.py +++ b/mitmproxy/models/tcp.py @@ -6,6 +6,7 @@ from .flow import Flow class TCPMessage(Serializable): + def __init__(self, from_client, content, timestamp=None): self.content = content self.from_client = from_client @@ -33,6 +34,7 @@ class TCPMessage(Serializable): class TCPFlow(Flow): + """ A TCPFlow is a simplified representation of a TCP session. """ diff --git a/mitmproxy/protocol/http_replay.py b/mitmproxy/protocol/http_replay.py index e78af074..f7f27148 100644 --- a/mitmproxy/protocol/http_replay.py +++ b/mitmproxy/protocol/http_replay.py @@ -62,7 +62,7 @@ class RequestReplayThread(threading.Thread): ) r.first_line_format = "relative" else: - r.first_line_format= "absolute" + r.first_line_format = "absolute" else: server_address = (r.host, r.port) server = ServerConnection(server_address, (self.config.host, 0)) diff --git a/mitmproxy/protocol/rawtcp.py b/mitmproxy/protocol/rawtcp.py index 1b546c40..05342844 100644 --- a/mitmproxy/protocol/rawtcp.py +++ b/mitmproxy/protocol/rawtcp.py @@ -1,14 +1,10 @@ from __future__ import (absolute_import, print_function, division) import socket -import six -import sys from OpenSSL import SSL from netlib.exceptions import TcpException from netlib.tcp import ssl_read_select -from netlib.utils import clean_bin -from ..exceptions import ProtocolException from ..models import Error from ..models.tcp import TCPFlow, TCPMessage diff --git a/mitmproxy/protocol/tls.py b/mitmproxy/protocol/tls.py index 74c55ab4..5facff73 100644 --- a/mitmproxy/protocol/tls.py +++ b/mitmproxy/protocol/tls.py @@ -312,6 +312,7 @@ class TlsClientHello(object): class TlsLayer(Layer): + """ The TLS layer implements transparent TLS connections. @@ -469,9 +470,9 @@ class TlsLayer(Layer): cert, key, chain_file = self._find_cert() if self.config.add_upstream_certs_to_client_chain: - extra_certs = self.server_conn.server_certs + extra_certs = self.server_conn.server_certs else: - extra_certs = None + extra_certs = None try: self.client_conn.convert_to_ssl( @@ -482,7 +483,7 @@ class TlsLayer(Layer): dhparams=self.config.certstore.dhparams, chain_file=chain_file, alpn_select_callback=self.__alpn_select_callback, - extra_chain_certs = extra_certs, + extra_chain_certs=extra_certs, ) # Some TLS clients will not fail the handshake, # but will immediately throw an "unexpected eof" error on the first read. diff --git a/mitmproxy/proxy/config.py b/mitmproxy/proxy/config.py index 58b568ea..5587e111 100644 --- a/mitmproxy/proxy/config.py +++ b/mitmproxy/proxy/config.py @@ -58,7 +58,7 @@ class ProxyConfig: body_size_limit=None, mode="regular", upstream_server=None, - upstream_auth = None, + upstream_auth=None, authenticator=None, ignore_hosts=tuple(), tcp_hosts=tuple(), @@ -120,7 +120,7 @@ def process_proxy_options(parser, options): body_size_limit = utils.parse_size(options.body_size_limit) c = 0 - mode, upstream_server, upstream_auth = "regular", None, None + mode, upstream_server, upstream_auth = "regular", None, None if options.transparent_proxy: c += 1 if not platform.resolver: @@ -161,7 +161,7 @@ def process_proxy_options(parser, options): options.clientcerts = os.path.expanduser(options.clientcerts) if not os.path.exists(options.clientcerts): return parser.error( - "Client certificate path does not exist: %s" % options.clientcerts + "Client certificate path does not exist: %s" % options.clientcerts ) if options.auth_nonanonymous or options.auth_singleuser or options.auth_htpasswd: diff --git a/mitmproxy/script/script.py b/mitmproxy/script/script.py index 484025b4..4ec9af97 100644 --- a/mitmproxy/script/script.py +++ b/mitmproxy/script/script.py @@ -6,7 +6,6 @@ by the mitmproxy-specific ScriptContext. # Do not import __future__ here, this would apply transitively to the inline scripts. import os import shlex -import traceback import sys import six diff --git a/mitmproxy/tnetstring.py b/mitmproxy/tnetstring.py index d9d61258..acf563ac 100644 --- a/mitmproxy/tnetstring.py +++ b/mitmproxy/tnetstring.py @@ -68,6 +68,7 @@ like so:: """ import six +from collections import deque __ver_major__ = 0 __ver_minor__ = 2 @@ -77,9 +78,6 @@ __version__ = "%d.%d.%d%s" % ( __ver_major__, __ver_minor__, __ver_patch__, __ver_sub__) -from collections import deque - - def dumps(value, encoding=None): """dumps(object,encoding=None) -> string |