Test SNI for transparent mode.

This commit is contained in:
Aldo Cortesi 2013-03-02 15:06:49 +13:00
parent 10db82e9a0
commit a95d78438c
3 changed files with 25 additions and 12 deletions

View File

@ -140,6 +140,13 @@ class ProxyHandler(tcp.BaseHandler):
tcp.BaseHandler.__init__(self, connection, client_address, server) tcp.BaseHandler.__init__(self, connection, client_address, server)
def get_server_connection(self, cc, scheme, host, port, sni): def get_server_connection(self, cc, scheme, host, port, sni):
"""
When SNI is in play, this means we have an SSL-encrypted
connection, which means that the entire handler is dedicated to a
single server connection - no multiplexing. If this assumption ever
breaks, we'll have to do something different with the SNI host
variable on the handler object.
"""
sc = self.server_conn sc = self.server_conn
if not sni: if not sni:
sni = host sni = host
@ -329,7 +336,6 @@ class ProxyHandler(tcp.BaseHandler):
raise ProxyError(400, str(v)) raise ProxyError(400, str(v))
else: else:
scheme = "http" scheme = "http"
host = self.sni or host
line = self.get_line(self.rfile) line = self.get_line(self.rfile)
if line == "": if line == "":
return None return None

View File

@ -160,6 +160,12 @@ class TestTransparent(tservers.TransparentProxTest, CommonMixin):
class TestTransparentSSL(tservers.TransparentProxTest, CommonMixin): class TestTransparentSSL(tservers.TransparentProxTest, CommonMixin):
transparent = True transparent = True
ssl = True ssl = True
def test_sni(self):
f = self.pathod("304", sni="testserver.com")
assert f.status_code == 304
l = self.server.last_log()
assert self.server.last_log()["request"]["sni"] == "testserver.com"
class TestProxy(tservers.HTTPProxTest): class TestProxy(tservers.HTTPProxTest):

View File

@ -172,23 +172,24 @@ class TransparentProxTest(ProxTestBase):
) )
return d return d
def pathod(self, spec): def pathod(self, spec, sni=None):
""" """
Constructs a pathod request, with the appropriate base and proxy. Constructs a pathod GET request, with the appropriate base and proxy.
""" """
r = hurl.get( if self.ssl:
"%s://127.0.0.1:%s"%(self.scheme, self.proxy.port) + "/p/" + spec, p = self.pathoc(sni=sni)
validate_cert=False, q = "get:'/p/%s'"%spec
#debug=hurl.utils.stdout_debug else:
) p = self.pathoc()
return r q = "get:'/p/%s'"%spec
return p.request(q)
def pathoc(self, connect= None): def pathoc(self, sni=None):
""" """
Returns a connected Pathoc instance. Returns a connected Pathoc instance.
""" """
p = libpathod.pathoc.Pathoc("localhost", self.proxy.port) p = libpathod.pathoc.Pathoc("localhost", self.proxy.port, ssl=self.ssl, sni=sni)
p.connect(connect_to) p.connect()
return p return p