ProxyConfig: cadir to options

This commit is contained in:
Aldo Cortesi 2016-07-18 14:50:10 +12:00
parent 6908dc4d90
commit b1b1a1b9cf
6 changed files with 19 additions and 21 deletions

View File

@ -16,6 +16,7 @@ from netlib.http import url
APP_HOST = "mitm.it"
APP_PORT = 80
CA_DIR = "~/.mitmproxy"
class ParseException(Exception):
@ -245,8 +246,8 @@ def basic_options(parser):
)
parser.add_argument(
"--cadir",
action="store", type=str, dest="cadir", default=config.CA_DIR,
help="Location of the default mitmproxy CA files. (%s)" % config.CA_DIR
action="store", type=str, dest="cadir", default=CA_DIR,
help="Location of the default mitmproxy CA files. (%s)" % CA_DIR
)
parser.add_argument(
"--host",
@ -699,8 +700,8 @@ def mitmproxy():
usage="%(prog)s [options]",
args_for_setting_config_path=["--conf"],
default_config_files=[
os.path.join(config.CA_DIR, "common.conf"),
os.path.join(config.CA_DIR, "mitmproxy.conf")
os.path.join(CA_DIR, "common.conf"),
os.path.join(CA_DIR, "mitmproxy.conf")
],
add_config_file_help=True,
add_env_var_help=True
@ -754,8 +755,8 @@ def mitmdump():
usage="%(prog)s [options] [filter]",
args_for_setting_config_path=["--conf"],
default_config_files=[
os.path.join(config.CA_DIR, "common.conf"),
os.path.join(config.CA_DIR, "mitmdump.conf")
os.path.join(CA_DIR, "common.conf"),
os.path.join(CA_DIR, "mitmdump.conf")
],
add_config_file_help=True,
add_env_var_help=True
@ -784,8 +785,8 @@ def mitmweb():
usage="%(prog)s [options]",
args_for_setting_config_path=["--conf"],
default_config_files=[
os.path.join(config.CA_DIR, "common.conf"),
os.path.join(config.CA_DIR, "mitmweb.conf")
os.path.join(CA_DIR, "common.conf"),
os.path.join(CA_DIR, "mitmweb.conf")
],
add_config_file_help=True,
add_env_var_help=True

View File

@ -1,6 +1,7 @@
from __future__ import absolute_import, print_function, division
from mitmproxy import options
from typing import Tuple, Optional, Sequence # noqa
from mitmproxy import cmdline
APP_HOST = "mitm.it"
APP_PORT = 80
@ -38,8 +39,9 @@ class Options(options.Options):
replay_ignore_host=False, # type: bool
# Proxy options
listen_host = "", # type: str
listen_port = 8080, # type: int
cadir = cmdline.CA_DIR, # type: str
listen_host = "", # type: str
listen_port = 8080, # type: int
):
# We could replace all assignments with clever metaprogramming,
# but type hints are a much more valueable asset.
@ -71,6 +73,7 @@ class Options(options.Options):
self.replay_ignore_payload_params = replay_ignore_payload_params
self.replay_ignore_host = replay_ignore_host
self.cadir = cadir
self.listen_host = listen_host
self.listen_port = listen_port

View File

@ -47,7 +47,7 @@ class PEM(tornado.web.RequestHandler):
return config.CONF_BASENAME + "-ca-cert.pem"
def get(self):
p = os.path.join(self.request.master.server.config.cadir, self.filename)
p = os.path.join(self.request.master.options.cadir, self.filename)
self.set_header("Content-Type", "application/x-x509-ca-cert")
self.set_header(
"Content-Disposition",
@ -65,7 +65,7 @@ class P12(tornado.web.RequestHandler):
return config.CONF_BASENAME + "-ca-cert.p12"
def get(self):
p = os.path.join(self.request.master.server.config.cadir, self.filename)
p = os.path.join(self.request.master.options.cadir, self.filename)
self.set_header("Content-Type", "application/x-pkcs12")
self.set_header(
"Content-Disposition",

View File

@ -14,7 +14,6 @@ from netlib import tcp
from netlib.http import authentication
CONF_BASENAME = "mitmproxy"
CA_DIR = "~/.mitmproxy"
# We manually need to specify this, otherwise OpenSSL may select a non-HTTP2 cipher by default.
# https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=apache-2.2.15&openssl=1.0.2&hsts=yes&profile=old
@ -60,7 +59,6 @@ class ProxyConfig:
def __init__(
self,
options,
cadir=CA_DIR,
clientcerts=None,
no_upstream_cert=False,
body_size_limit=None,
@ -101,9 +99,8 @@ class ProxyConfig:
self.http2 = http2
self.rawtcp = rawtcp
self.authenticator = authenticator
self.cadir = os.path.expanduser(cadir)
self.certstore = certutils.CertStore.from_store(
self.cadir,
os.path.expanduser(options.cadir),
CONF_BASENAME
)
for spec, cert in certs:
@ -214,7 +211,6 @@ def process_proxy_options(parser, options, args):
return ProxyConfig(
options,
cadir=args.cadir,
clientcerts=args.clientcerts,
no_upstream_cert=args.no_upstream_cert,
body_size_limit=body_size_limit,

View File

@ -105,10 +105,9 @@ class _Http2TestBase(object):
@classmethod
def get_proxy_config(cls):
opts = options.Options(listen_port=0)
cls.cadir = os.path.join(tempfile.gettempdir(), "mitmproxy")
opts.cadir = os.path.join(tempfile.gettempdir(), "mitmproxy")
d = dict(
no_upstream_cert=False,
cadir=cls.cadir,
authenticator=None,
)
return d, opts

View File

@ -122,11 +122,10 @@ class ProxyTestBase(object):
cls.cadir = os.path.join(tempfile.gettempdir(), "mitmproxy")
cnf = dict(
no_upstream_cert = cls.no_upstream_cert,
cadir = cls.cadir,
authenticator = cls.authenticator,
add_upstream_certs_to_client_chain = cls.add_upstream_certs_to_client_chain,
)
return cnf, options.Options(listen_port=0)
return cnf, options.Options(listen_port=0, cadir=cls.cadir)
class HTTPProxyTest(ProxyTestBase):