mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-05-12 17:48:49 +08:00
Merge branch 'master' into integrate_honeyproxy
This commit is contained in:
@@ -1,27 +1,11 @@
|
||||
# Copyright (C) 2012 Aldo Cortesi
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
import sys, os, string, socket, time
|
||||
import shutil, tempfile, threading
|
||||
import SocketServer
|
||||
from OpenSSL import SSL
|
||||
from netlib import odict, tcp, http, wsgi, certutils, http_status, http_auth
|
||||
import utils, flow, version, platform, controller, app
|
||||
import utils, flow, version, platform, controller
|
||||
|
||||
|
||||
APP_DOMAIN = "mitm"
|
||||
APP_IP = "1.1.1.1"
|
||||
KILL = 0
|
||||
|
||||
|
||||
@@ -39,8 +23,7 @@ class Log:
|
||||
|
||||
|
||||
class ProxyConfig:
|
||||
def __init__(self, app=False, certfile = None, cacert = None, clientcerts = None, no_upstream_cert=False, body_size_limit = None, reverse_proxy=None, transparent_proxy=None, certdir = None, authenticator=None):
|
||||
self.app = app
|
||||
def __init__(self, certfile = None, cacert = None, clientcerts = None, no_upstream_cert=False, body_size_limit = None, reverse_proxy=None, transparent_proxy=None, certdir = None, authenticator=None):
|
||||
self.certfile = certfile
|
||||
self.cacert = cacert
|
||||
self.clientcerts = clientcerts
|
||||
@@ -61,7 +44,6 @@ class ServerConnection(tcp.TCPClient):
|
||||
self.tcp_setup_timestamp = None
|
||||
self.ssl_setup_timestamp = None
|
||||
|
||||
|
||||
def connect(self):
|
||||
tcp.TCPClient.connect(self)
|
||||
self.tcp_setup_timestamp = time.time()
|
||||
@@ -86,11 +68,12 @@ class ServerConnection(tcp.TCPClient):
|
||||
self.wfile.flush()
|
||||
|
||||
def terminate(self):
|
||||
try:
|
||||
self.wfile.flush()
|
||||
if self.connection:
|
||||
try:
|
||||
self.wfile.flush()
|
||||
except tcp.NetLibDisconnect: # pragma: no cover
|
||||
pass
|
||||
self.connection.close()
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -179,6 +162,8 @@ class ProxyHandler(tcp.BaseHandler):
|
||||
return self.server_conn
|
||||
|
||||
def del_server_connection(self):
|
||||
if self.server_conn:
|
||||
self.server_conn.terminate()
|
||||
self.server_conn = None
|
||||
|
||||
def handle(self):
|
||||
@@ -188,6 +173,7 @@ class ProxyHandler(tcp.BaseHandler):
|
||||
while self.handle_request(cc) and not cc.close:
|
||||
pass
|
||||
cc.close = True
|
||||
self.del_server_connection()
|
||||
|
||||
cd = flow.ClientDisconnect(cc)
|
||||
self.log(
|
||||
@@ -213,7 +199,7 @@ class ProxyHandler(tcp.BaseHandler):
|
||||
return
|
||||
else:
|
||||
request_reply = self.channel.ask(request)
|
||||
if request_reply == KILL:
|
||||
if request_reply is None or request_reply == KILL:
|
||||
return
|
||||
elif isinstance(request_reply, flow.Response):
|
||||
request = False
|
||||
@@ -510,17 +496,6 @@ class ProxyServer(tcp.TCPServer):
|
||||
raise ProxyServerError('Error starting proxy server: ' + v.strerror)
|
||||
self.channel = None
|
||||
self.apps = AppRegistry()
|
||||
if config.app:
|
||||
self.apps.add(
|
||||
app.mapp,
|
||||
APP_DOMAIN,
|
||||
80
|
||||
)
|
||||
self.apps.add(
|
||||
app.mapp,
|
||||
APP_IP,
|
||||
80
|
||||
)
|
||||
|
||||
def start_slave(self, klass, channel):
|
||||
slave = klass(channel, self)
|
||||
@@ -653,7 +628,6 @@ def process_proxy_options(parser, options):
|
||||
authenticator = http_auth.NullProxyAuth(None)
|
||||
|
||||
return ProxyConfig(
|
||||
app = options.app,
|
||||
certfile = options.cert,
|
||||
cacert = cacert,
|
||||
clientcerts = options.clientcerts,
|
||||
|
||||
Reference in New Issue
Block a user