diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 11436b300..9bce72063 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -1347,7 +1347,12 @@ class HTTPHandler(ProtocolHandler): if self.c.config.mode == "sslspoof": # SNI is processed in server.py - return None + if not (flow.server_conn and flow.server_conn.ssl_established): + print ":::::::::::::::" + raise http.HttpError( + 400, + "Invalid request: No host information" + ) return None diff --git a/libmproxy/proxy/server.py b/libmproxy/proxy/server.py index df890f7ca..71704413a 100644 --- a/libmproxy/proxy/server.py +++ b/libmproxy/proxy/server.py @@ -123,14 +123,10 @@ class ConnectionHandler: self.set_server_address(("-", port)) self.establish_ssl(client=True) host = self.client_conn.connection.get_servername() - if host is None: - raise ProxyError( - 400, - "Invalid request: No host information" - ) - self.set_server_address((host, port)) - self.establish_server_connection() - self.establish_ssl(server=True, sni=host) + if host: + self.set_server_address((host, port)) + self.establish_server_connection() + self.establish_ssl(server=True, sni=host) # Delegate handling to the protocol handler protocol_handler( diff --git a/test/test_server.py b/test/test_server.py index 58a4b5b5b..07b8a5f23 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -413,13 +413,8 @@ class TestSSLSpoof(tservers.SSLSpoofModeTest): a = ("localhost", self.server.port) self.config.mode.sslport = a[1] p = self.pathoc(sni=None) - #assert p.ssl_established == False - try: - f = p.request("get:/p/304") - #assert f.status_code == 400 - assert False - except tcp.NetLibSSLError as v: - assert True + f = p.request("get:/p/304") + assert f.status_code == 400 class TestHttps2Http(tservers.ReverseProxTest):