mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
Make sni_handler an argument to BaseHandler.convert_to_ssl
This commit is contained in:
parent
97e11a219f
commit
f30df13384
@ -254,15 +254,27 @@ class BaseHandler:
|
|||||||
self.ssl_established = False
|
self.ssl_established = False
|
||||||
self.clientcert = None
|
self.clientcert = None
|
||||||
|
|
||||||
def convert_to_ssl(self, cert, key, method=SSLv23_METHOD, options=None):
|
def convert_to_ssl(self, cert, key, method=SSLv23_METHOD, options=None, handle_sni=None):
|
||||||
"""
|
"""
|
||||||
method: One of SSLv2_METHOD, SSLv3_METHOD, SSLv23_METHOD, or TLSv1_METHOD
|
method: One of SSLv2_METHOD, SSLv3_METHOD, SSLv23_METHOD, or TLSv1_METHOD
|
||||||
|
handle_sni: SNI handler, should take a connection object. Server
|
||||||
|
name can be retrieved like this:
|
||||||
|
|
||||||
|
connection.get_servername()
|
||||||
|
|
||||||
|
And you can specify the connection keys as follows:
|
||||||
|
|
||||||
|
new_context = Context(TLSv1_METHOD)
|
||||||
|
new_context.use_privatekey(key)
|
||||||
|
new_context.use_certificate(cert)
|
||||||
|
connection.set_context(new_context)
|
||||||
"""
|
"""
|
||||||
ctx = SSL.Context(method)
|
ctx = SSL.Context(method)
|
||||||
if not options is None:
|
if not options is None:
|
||||||
ctx.set_options(options)
|
ctx.set_options(options)
|
||||||
# SNI callback happens during do_handshake()
|
if handle_sni:
|
||||||
ctx.set_tlsext_servername_callback(self.handle_sni)
|
# SNI callback happens during do_handshake()
|
||||||
|
ctx.set_tlsext_servername_callback(handle_sni)
|
||||||
ctx.use_privatekey_file(key)
|
ctx.use_privatekey_file(key)
|
||||||
ctx.use_certificate_file(cert)
|
ctx.use_certificate_file(cert)
|
||||||
def ver(*args):
|
def ver(*args):
|
||||||
@ -290,23 +302,6 @@ class BaseHandler:
|
|||||||
# Remote has disconnected
|
# Remote has disconnected
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def handle_sni(self, connection):
|
|
||||||
"""
|
|
||||||
Called if the client has given a server name indication.
|
|
||||||
|
|
||||||
Server name can be retrieved like this:
|
|
||||||
|
|
||||||
connection.get_servername()
|
|
||||||
|
|
||||||
And you can specify the connection keys as follows:
|
|
||||||
|
|
||||||
new_context = Context(TLSv1_METHOD)
|
|
||||||
new_context.use_privatekey(key)
|
|
||||||
new_context.use_certificate(cert)
|
|
||||||
connection.set_context(new_context)
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
def handle(self): # pragma: no cover
|
def handle(self): # pragma: no cover
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ class TServer(tcp.TCPServer):
|
|||||||
self.ssl["key"],
|
self.ssl["key"],
|
||||||
method = method,
|
method = method,
|
||||||
options = options,
|
options = options,
|
||||||
|
handle_sni = getattr(h, "handle_sni", None)
|
||||||
)
|
)
|
||||||
h.handle()
|
h.handle()
|
||||||
h.finish()
|
h.finish()
|
||||||
|
Loading…
Reference in New Issue
Block a user