diff options
author | Maximilian Hils <git@maximilianhils.com> | 2014-08-08 04:43:44 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2014-08-08 04:43:44 +0200 |
commit | de05484d9d08a4bc40c17c673b18bc2e0f910fff (patch) | |
tree | 10c80b64b8f4b72ea00938114db8ace230f8f7c2 /libmproxy | |
parent | a3c3e4e50434a891d702ee023d0b8925e513aa1d (diff) | |
download | mitmproxy-de05484d9d08a4bc40c17c673b18bc2e0f910fff.tar.gz mitmproxy-de05484d9d08a4bc40c17c673b18bc2e0f910fff.tar.bz2 mitmproxy-de05484d9d08a4bc40c17c673b18bc2e0f910fff.zip |
fix #318
Diffstat (limited to 'libmproxy')
-rw-r--r-- | libmproxy/proxy/config.py | 80 |
1 files changed, 47 insertions, 33 deletions
diff --git a/libmproxy/proxy/config.py b/libmproxy/proxy/config.py index 94a12bf4..a6a962ea 100644 --- a/libmproxy/proxy/config.py +++ b/libmproxy/proxy/config.py @@ -11,14 +11,32 @@ CONF_DIR = "~/.mitmproxy" class ProxyConfig: def __init__(self, confdir=CONF_DIR, clientcerts=None, - no_upstream_cert=False, body_size_limit=None, get_upstream_server=None, - http_form_in="absolute", http_form_out="relative", authenticator=None, - ciphers=None, certs=[], certforward = False - ): + no_upstream_cert=False, body_size_limit=None, + mode=None, upstream_server=None, http_form_in=None, http_form_out=None, + authenticator=None, + ciphers=None, certs=[], certforward=False): self.ciphers = ciphers self.clientcerts = clientcerts self.no_upstream_cert = no_upstream_cert self.body_size_limit = body_size_limit + + if mode == "transparent": + get_upstream_server = TransparentUpstreamServerResolver(platform.resolver(), TRANSPARENT_SSL_PORTS) + http_form_in_default, http_form_out_default = "relative", "relative" + elif mode == "reverse": + get_upstream_server = ConstUpstreamServerResolver(upstream_server) + http_form_in_default, http_form_out_default = "relative", "relative" + elif mode == "upstream": + get_upstream_server = ConstUpstreamServerResolver(upstream_server) + http_form_in_default, http_form_out_default = "absolute", "absolute" + elif upstream_server: + get_upstream_server = ConstUpstreamServerResolver(upstream_server) + http_form_in_default, http_form_out_default = "absolute", "relative" + else: + get_upstream_server, http_form_in_default, http_form_out_default = None, "absolute", "relative" + http_form_in = http_form_in or http_form_in_default + http_form_out = http_form_out or http_form_out_default + self.get_upstream_server = get_upstream_server self.http_form_in = http_form_in self.http_form_out = http_form_out @@ -35,32 +53,27 @@ def process_proxy_options(parser, options): body_size_limit = utils.parse_size(options.body_size_limit) c = 0 - http_form_in, http_form_out = "absolute", "relative" - get_upstream_server = None + mode, upstream_server = None, None if options.transparent_proxy: c += 1 if not platform.resolver: return parser.error("Transparent mode not supported on this platform.") - get_upstream_server = TransparentUpstreamServerResolver(platform.resolver(), TRANSPARENT_SSL_PORTS) - http_form_in, http_form_out = "relative", "relative" + mode = "transparent" if options.reverse_proxy: c += 1 - get_upstream_server = ConstUpstreamServerResolver(options.reverse_proxy) - http_form_in, http_form_out = "relative", "relative" + mode = "reverse" + upstream_server = options.reverse_proxy if options.upstream_proxy: c += 1 - get_upstream_server = ConstUpstreamServerResolver(options.upstream_proxy) - http_form_in, http_form_out = "absolute", "absolute" + mode = "upstream" + upstream_server = options.upstream_proxy if options.manual_destination_server: c += 1 - get_upstream_server = ConstUpstreamServerResolver(options.manual_destination_server) + mode = "manual" + upstream_server = options.manual_destination_server if c > 1: return parser.error("Transparent mode, reverse mode, upstream proxy mode and " "specification of an upstream server are mutually exclusive.") - if options.http_form_in: - http_form_in = options.http_form_in - if options.http_form_out: - http_form_out = options.http_form_out if options.clientcerts: options.clientcerts = os.path.expanduser(options.clientcerts) @@ -93,21 +106,22 @@ def process_proxy_options(parser, options): parts = ["*", parts[0]] parts[1] = os.path.expanduser(parts[1]) if not os.path.exists(parts[1]): - parser.error("Certificate file does not exist: %s"%parts[1]) + parser.error("Certificate file does not exist: %s" % parts[1]) certs.append(parts) return ProxyConfig( - clientcerts = options.clientcerts, - body_size_limit = body_size_limit, - no_upstream_cert = options.no_upstream_cert, - get_upstream_server = get_upstream_server, - confdir = options.confdir, - http_form_in = http_form_in, - http_form_out = http_form_out, - authenticator = authenticator, - ciphers = options.ciphers, - certs = certs, - certforward = options.certforward, + confdir=options.confdir, + clientcerts=options.clientcerts, + no_upstream_cert=options.no_upstream_cert, + body_size_limit=body_size_limit, + mode=mode, + upstream_server=upstream_server, + http_form_in=options.http_form_in, + http_form_out=options.http_form_out, + authenticator=authenticator, + ciphers=options.ciphers, + certs=certs, + certforward=options.certforward, ) @@ -115,10 +129,10 @@ def ssl_option_group(parser): group = parser.add_argument_group("SSL") group.add_argument( "--cert", dest='certs', default=[], type=str, - metavar = "SPEC", action="append", - help='Add an SSL certificate. SPEC is of the form "[domain=]path". '\ - 'The domain may include a wildcard, and is equal to "*" if not specified. '\ - 'The file at path is a certificate in PEM format. If a private key is included in the PEM, '\ + metavar="SPEC", action="append", + help='Add an SSL certificate. SPEC is of the form "[domain=]path". ' \ + 'The domain may include a wildcard, and is equal to "*" if not specified. ' \ + 'The file at path is a certificate in PEM format. If a private key is included in the PEM, ' \ 'it is used, else the default key in the conf dir is used. Can be passed multiple times.' ) group.add_argument( |