SRV lookup is now an option and is turned off when we use SSL
This commit is contained in:
parent
eb7d3cc381
commit
67c9312d37
|
@ -166,6 +166,7 @@ class Config:
|
||||||
'keyid': [ opt_str, '' ],
|
'keyid': [ opt_str, '' ],
|
||||||
'keyname': [ opt_str, '' ],
|
'keyname': [ opt_str, '' ],
|
||||||
'usessl': [ opt_bool, False ],
|
'usessl': [ opt_bool, False ],
|
||||||
|
'use_srv': [ opt_bool, True ],
|
||||||
'use_custom_host': [ opt_bool, False ],
|
'use_custom_host': [ opt_bool, False ],
|
||||||
'custom_port': [ opt_int, 5222 ],
|
'custom_port': [ opt_int, 5222 ],
|
||||||
'custom_host': [ opt_str, '' ],
|
'custom_host': [ opt_str, '' ],
|
||||||
|
|
|
@ -1326,14 +1326,17 @@ class Connection:
|
||||||
p = 5222
|
p = 5222
|
||||||
# autodetect [for SSL in 5223/443 and for TLS if broadcasted]
|
# autodetect [for SSL in 5223/443 and for TLS if broadcasted]
|
||||||
secur = None
|
secur = None
|
||||||
|
use_srv = gajim.config.get_per('accounts', self.name, 'use_srv')
|
||||||
if usessl:
|
if usessl:
|
||||||
p = 5223
|
p = 5223
|
||||||
secur=1 #1 means force SSL no matter what the port will be
|
secur = 1 #1 means force SSL no matter what the port will be
|
||||||
|
use_srv = False # wants ssl? disable srv lookup
|
||||||
if gajim.config.get_per('accounts', self.name, 'use_custom_host'):
|
if gajim.config.get_per('accounts', self.name, 'use_custom_host'):
|
||||||
h = gajim.config.get_per('accounts', self.name, 'custom_host')
|
h = gajim.config.get_per('accounts', self.name, 'custom_host')
|
||||||
p = gajim.config.get_per('accounts', self.name, 'custom_port')
|
p = gajim.config.get_per('accounts', self.name, 'custom_port')
|
||||||
|
use_srv = False
|
||||||
|
|
||||||
con_type = con.connect((h, p), proxy = proxy, secure=secur) #FIXME: blocking
|
con_type = con.connect((h, p), proxy=proxy, secure=secur, use_srv=use_srv)
|
||||||
if not con_type:
|
if not con_type:
|
||||||
gajim.log.debug("Couldn't connect to %s" % self.name)
|
gajim.log.debug("Couldn't connect to %s" % self.name)
|
||||||
if not self.retrycount:
|
if not self.retrycount:
|
||||||
|
|
|
@ -156,11 +156,11 @@ class CommonClient:
|
||||||
if hasattr(self, 'Connection'):
|
if hasattr(self, 'Connection'):
|
||||||
return self.Connection._sock.getsockname()
|
return self.Connection._sock.getsockname()
|
||||||
|
|
||||||
def connect(self,server=None,proxy=None, ssl=None):
|
def connect(self,server=None,proxy=None, ssl=None, use_srv=None):
|
||||||
""" Make a tcp/ip connection, protect it with tls/ssl if possible and start XMPP stream. """
|
""" Make a tcp/ip connection, protect it with tls/ssl if possible and start XMPP stream. """
|
||||||
if not server: server=(self.Server,self.Port)
|
if not server: server=(self.Server,self.Port)
|
||||||
if proxy: connected=transports.HTTPPROXYsocket(proxy,server).PlugIn(self)
|
if proxy: connected=transports.HTTPPROXYsocket(proxy,server,use_srv).PlugIn(self)
|
||||||
else: connected=transports.TCPsocket(server).PlugIn(self)
|
else: connected=transports.TCPsocket(server,use_srv).PlugIn(self)
|
||||||
if not connected: return
|
if not connected: return
|
||||||
self._Server,self._Proxy=server,proxy
|
self._Server,self._Proxy=server,proxy
|
||||||
self.connected='tcp'
|
self.connected='tcp'
|
||||||
|
@ -179,7 +179,7 @@ class CommonClient:
|
||||||
|
|
||||||
class Client(CommonClient):
|
class Client(CommonClient):
|
||||||
""" Example client class, based on CommonClient. """
|
""" Example client class, based on CommonClient. """
|
||||||
def connect(self,server=None,proxy=None, secure=None):
|
def connect(self,server=None,proxy=None,secure=None,use_srv=True):
|
||||||
""" Connect to jabber server. If you want to specify different ip/port to connect to you can
|
""" Connect to jabber server. If you want to specify different ip/port to connect to you can
|
||||||
pass it as tuple as first parameter. If there is HTTP proxy between you and server -
|
pass it as tuple as first parameter. If there is HTTP proxy between you and server -
|
||||||
specify it's address and credentials (if needed) in the second argument
|
specify it's address and credentials (if needed) in the second argument
|
||||||
|
@ -188,7 +188,7 @@ class Client(CommonClient):
|
||||||
If you want to disable tls/ssl support completely, set it to 0
|
If you want to disable tls/ssl support completely, set it to 0
|
||||||
Example: connect(('192.168.5.5',5222),{'host':'proxy.my.net','port':8080,'user':'me','password':'secret'})
|
Example: connect(('192.168.5.5',5222),{'host':'proxy.my.net','port':8080,'user':'me','password':'secret'})
|
||||||
Returns '' (on no connection) or 'tcp' or 'tls', depending on the result."""
|
Returns '' (on no connection) or 'tcp' or 'tls', depending on the result."""
|
||||||
if not CommonClient.connect(self,server,proxy,secure) or secure<>None and not secure: return self.connected
|
if not CommonClient.connect(self,server,proxy,secure,use_srv) or secure<>None and not secure: return self.connected
|
||||||
transports.TLS().PlugIn(self)
|
transports.TLS().PlugIn(self)
|
||||||
if not self.Dispatcher.Stream._document_attrs.has_key('version') or not self.Dispatcher.Stream._document_attrs['version']=='1.0': return self.connected
|
if not self.Dispatcher.Stream._document_attrs.has_key('version') or not self.Dispatcher.Stream._document_attrs['version']=='1.0': return self.connected
|
||||||
while not self.Dispatcher.Stream.features and self.Process(): pass # If we get version 1.0 stream the features tag MUST BE presented
|
while not self.Dispatcher.Stream.features and self.Process(): pass # If we get version 1.0 stream the features tag MUST BE presented
|
||||||
|
|
|
@ -61,7 +61,7 @@ class error:
|
||||||
|
|
||||||
class TCPsocket(PlugIn):
|
class TCPsocket(PlugIn):
|
||||||
""" This class defines direct TCP connection method. """
|
""" This class defines direct TCP connection method. """
|
||||||
def __init__(self, server=None):
|
def __init__(self, server=None, use_srv=True):
|
||||||
""" Cache connection point 'server'. 'server' is the tuple of (host, port)
|
""" Cache connection point 'server'. 'server' is the tuple of (host, port)
|
||||||
absolutely the same as standart tcp socket uses. """
|
absolutely the same as standart tcp socket uses. """
|
||||||
PlugIn.__init__(self)
|
PlugIn.__init__(self)
|
||||||
|
@ -69,7 +69,7 @@ class TCPsocket(PlugIn):
|
||||||
self._exported_methods=[self.send,self.disconnect]
|
self._exported_methods=[self.send,self.disconnect]
|
||||||
|
|
||||||
# SRV resolver
|
# SRV resolver
|
||||||
if HAVE_DNSPYTHON or HAVE_PYDNS:
|
if use_srv and (HAVE_DNSPYTHON or HAVE_PYDNS):
|
||||||
host, port = server
|
host, port = server
|
||||||
possible_queries = ['_xmpp-client._tcp.' + host]
|
possible_queries = ['_xmpp-client._tcp.' + host]
|
||||||
|
|
||||||
|
@ -78,8 +78,8 @@ class TCPsocket(PlugIn):
|
||||||
if HAVE_DNSPYTHON:
|
if HAVE_DNSPYTHON:
|
||||||
answers = [x for x in dns.resolver.query(query, 'SRV')]
|
answers = [x for x in dns.resolver.query(query, 'SRV')]
|
||||||
if answers:
|
if answers:
|
||||||
host = str (answers[0].target)
|
host = str(answers[0].target)
|
||||||
port = int (answers[0].port)
|
port = int(answers[0].port)
|
||||||
break
|
break
|
||||||
elif HAVE_PYDNS:
|
elif HAVE_PYDNS:
|
||||||
# ensure we haven't cached an old configuration
|
# ensure we haven't cached an old configuration
|
||||||
|
@ -189,12 +189,12 @@ class HTTPPROXYsocket(TCPsocket):
|
||||||
""" HTTP (CONNECT) proxy connection class. Uses TCPsocket as the base class
|
""" HTTP (CONNECT) proxy connection class. Uses TCPsocket as the base class
|
||||||
redefines only connect method. Allows to use HTTP proxies like squid with
|
redefines only connect method. Allows to use HTTP proxies like squid with
|
||||||
(optionally) simple authentication (using login and password). """
|
(optionally) simple authentication (using login and password). """
|
||||||
def __init__(self,proxy,server):
|
def __init__(self,proxy,server,use_srv=True):
|
||||||
""" Caches proxy and target addresses.
|
""" Caches proxy and target addresses.
|
||||||
'proxy' argument is a dictionary with mandatory keys 'host' and 'port' (proxy address)
|
'proxy' argument is a dictionary with mandatory keys 'host' and 'port' (proxy address)
|
||||||
and optional keys 'user' and 'password' to use for authentication.
|
and optional keys 'user' and 'password' to use for authentication.
|
||||||
'server' argument is a tuple of host and port - just like TCPsocket uses. """
|
'server' argument is a tuple of host and port - just like TCPsocket uses. """
|
||||||
TCPsocket.__init__(self,server)
|
TCPsocket.__init__(self,server,use_srv)
|
||||||
self.DBG_LINE=DBG_CONNECT_PROXY
|
self.DBG_LINE=DBG_CONNECT_PROXY
|
||||||
self._proxy=proxy
|
self._proxy=proxy
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue