mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
New method establish_ssl to avoid duplicated code
This commit is contained in:
parent
f33d128a7f
commit
7140323bdb
@ -310,6 +310,17 @@ class ProxyHandler(tcp.BaseHandler):
|
|||||||
raise ProxyError(502, "Unable to generate dummy cert.")
|
raise ProxyError(502, "Unable to generate dummy cert.")
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def establish_ssl(self, client_conn, host, port):
|
||||||
|
dummycert = self.find_cert(client_conn, host, port, host)
|
||||||
|
sni = HandleSNI(
|
||||||
|
self, client_conn, host, port,
|
||||||
|
dummycert, self.config.certfile or self.config.cacert
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
self.convert_to_ssl(dummycert, self.config.certfile or self.config.cacert, handle_sni=sni)
|
||||||
|
except tcp.NetLibError, v:
|
||||||
|
raise ProxyError(400, str(v))
|
||||||
|
|
||||||
def get_line(self, fp):
|
def get_line(self, fp):
|
||||||
"""
|
"""
|
||||||
Get a line, possibly preceded by a blank.
|
Get a line, possibly preceded by a blank.
|
||||||
@ -329,15 +340,7 @@ class ProxyHandler(tcp.BaseHandler):
|
|||||||
if port in self.config.transparent_proxy["sslports"]:
|
if port in self.config.transparent_proxy["sslports"]:
|
||||||
scheme = "https"
|
scheme = "https"
|
||||||
if not self.ssl_established:
|
if not self.ssl_established:
|
||||||
dummycert = self.find_cert(client_conn, host, port, host)
|
self.establish_ssl(client_conn, host, port)
|
||||||
sni = HandleSNI(
|
|
||||||
self, client_conn, host, port,
|
|
||||||
dummycert, self.config.certfile or self.config.cacert
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
self.convert_to_ssl(dummycert, self.config.certfile or self.config.cacert, handle_sni=sni)
|
|
||||||
except tcp.NetLibError, v:
|
|
||||||
raise ProxyError(400, str(v))
|
|
||||||
else:
|
else:
|
||||||
scheme = "http"
|
scheme = "http"
|
||||||
line = self.get_line(self.rfile)
|
line = self.get_line(self.rfile)
|
||||||
@ -372,15 +375,7 @@ class ProxyHandler(tcp.BaseHandler):
|
|||||||
'\r\n'
|
'\r\n'
|
||||||
)
|
)
|
||||||
self.wfile.flush()
|
self.wfile.flush()
|
||||||
dummycert = self.find_cert(client_conn, host, port, host)
|
self.establish_ssl(client_conn, host, port)
|
||||||
sni = HandleSNI(
|
|
||||||
self, client_conn, host, port,
|
|
||||||
dummycert, self.config.certfile or self.config.cacert
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
self.convert_to_ssl(dummycert, self.config.certfile or self.config.cacert, handle_sni=sni)
|
|
||||||
except tcp.NetLibError, v:
|
|
||||||
raise ProxyError(400, str(v))
|
|
||||||
self.proxy_connect_state = (host, port, httpversion)
|
self.proxy_connect_state = (host, port, httpversion)
|
||||||
line = self.rfile.readline(line)
|
line = self.rfile.readline(line)
|
||||||
|
|
||||||
@ -415,17 +410,8 @@ class ProxyHandler(tcp.BaseHandler):
|
|||||||
|
|
||||||
def read_request_reverse(self, client_conn):
|
def read_request_reverse(self, client_conn):
|
||||||
scheme, host, port = self.config.reverse_proxy
|
scheme, host, port = self.config.reverse_proxy
|
||||||
if scheme.lower() == "https":
|
if scheme.lower() == "https" and not self.ssl_established:
|
||||||
if not self.ssl_established:
|
self.establish_ssl(client_conn, host, port)
|
||||||
dummycert = self.find_cert(client_conn, host, port, host)
|
|
||||||
sni = HandleSNI(
|
|
||||||
self, client_conn, host, port,
|
|
||||||
dummycert, self.config.certfile or self.config.cacert
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
self.convert_to_ssl(dummycert, self.config.certfile or self.config.cacert, handle_sni=sni)
|
|
||||||
except tcp.NetLibError, v:
|
|
||||||
raise ProxyError(400, str(v))
|
|
||||||
line = self.get_line(self.rfile)
|
line = self.get_line(self.rfile)
|
||||||
if line == "":
|
if line == "":
|
||||||
return None
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user