From ad893ad134cdc03f9152548e39a1dbce896cbee4 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 26 Jun 2012 20:08:24 +1200 Subject: [PATCH] Transparent proxy command-line flag stub. --- libmproxy/cmdline.py | 5 +++++ libmproxy/proxy.py | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libmproxy/cmdline.py b/libmproxy/cmdline.py index 8d57c7c7b..822bebec1 100644 --- a/libmproxy/cmdline.py +++ b/libmproxy/cmdline.py @@ -174,6 +174,11 @@ def common_options(parser): action="store", dest="stickycookie_filt", default=None, metavar="FILTER", help="Set sticky cookie filter. Matched against requests." ) + parser.add_option( + "-T", + action="store_true", dest="transparent_proxy", default=False, + help="Set transparent proxy mode." + ) parser.add_option( "-u", action="store", dest="stickyauth_filt", default=None, metavar="FILTER", diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index bdd71e196..3ab937908 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -379,6 +379,8 @@ def certificate_option_group(parser): parser.add_option_group(group) +TRANSPARENT_SSL_PORTS = [443, 8443] + def process_proxy_options(parser, options): if options.cert: options.cert = os.path.expanduser(options.cert) @@ -393,6 +395,17 @@ def process_proxy_options(parser, options): options.cache = os.path.expanduser(options.cache) body_size_limit = utils.parse_size(options.body_size_limit) + if options.reverse_proxy and options.transparent_proxy: + parser.errror("Can't set both reverse proxy and transparent proxy.") + + if options.transparent_proxy: + trans = dict( + resolver = None, + sslports = TRANSPARENT_SSL_PORTS + ) + else: + trans = None + if options.reverse_proxy: rp = utils.parse_proxy_spec(options.reverse_proxy) if not rp: @@ -412,5 +425,6 @@ def process_proxy_options(parser, options): cert_wait_time = options.cert_wait_time, body_size_limit = body_size_limit, upstream_cert = options.upstream_cert, - reverse_proxy = rp + reverse_proxy = rp, + transparent_proxy = trans )