Fall back to no-SNi context factory is Twisted<14 is used

This commit is contained in:
Paul Tremberth 2016-04-19 10:41:13 +02:00
parent 5cb071b466
commit 352d0d36ee
1 changed files with 8 additions and 3 deletions

View File

@ -122,9 +122,14 @@ class TunnelingTCP4ClientEndpoint(TCP4ClientEndpoint):
""" """
self._protocol.dataReceived = self._protocolDataReceived self._protocol.dataReceived = self._protocolDataReceived
if TunnelingTCP4ClientEndpoint._responseMatcher.match(bytes): if TunnelingTCP4ClientEndpoint._responseMatcher.match(bytes):
# this set proper Server Name Indication extension try:
sslOptions = self._contextFactory.creatorForNetloc( # this sets proper Server Name Indication extension
self._tunneledHost, self._tunneledPort) # but is only available for Twisted>=14.0
sslOptions = self._contextFactory.creatorForNetloc(
self._tunneledHost, self._tunneledPort)
except AttributeError:
# fall back to non-SNI SSL context factory
sslOptions = self._contextFactory
self._protocol.transport.startTLS(sslOptions, self._protocol.transport.startTLS(sslOptions,
self._protocolFactory) self._protocolFactory)
self._tunnelReadyDeferred.callback(self._protocol) self._tunnelReadyDeferred.callback(self._protocol)