mirror of
https://github.com/correl/SleekXMPP.git
synced 2025-01-02 03:00:36 +00:00
Fixed a defect where handlers for SASL authentication were being added multiple times. This caused issues when trying to reconnect. A handler for the auth mech would get added each reconnection attempt, causing digest-md5, success and failure to be called x times for each x number of retries.
Handlers for sasl authentication as well as success and failure are now added during the __init__ method.
This commit is contained in:
parent
c538ffae79
commit
fa7f72d0af
1 changed files with 6 additions and 4 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
See the file license.txt for copying permission.
|
See the file license.txt for copying permission.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
from . basexmpp import basexmpp
|
from . basexmpp import basexmpp
|
||||||
from xml.etree import cElementTree as ET
|
from xml.etree import cElementTree as ET
|
||||||
from . xmlstream.xmlstream import XMLStream
|
from . xmlstream.xmlstream import XMLStream
|
||||||
|
@ -77,6 +78,11 @@ class ClientXMPP(basexmpp, XMLStream):
|
||||||
self.digest_auth_started = False
|
self.digest_auth_started = False
|
||||||
XMLStream.registerHandler(self, Callback('Stream Features', MatchXPath('{http://etherx.jabber.org/streams}features'), self._handleStreamFeatures, thread=True))
|
XMLStream.registerHandler(self, Callback('Stream Features', MatchXPath('{http://etherx.jabber.org/streams}features'), self._handleStreamFeatures, thread=True))
|
||||||
XMLStream.registerHandler(self, Callback('Roster Update', MatchXPath('{%s}iq/{jabber:iq:roster}query' % self.default_ns), self._handleRoster, thread=True))
|
XMLStream.registerHandler(self, Callback('Roster Update', MatchXPath('{%s}iq/{jabber:iq:roster}query' % self.default_ns), self._handleRoster, thread=True))
|
||||||
|
#SASL Auth handlers
|
||||||
|
basexmpp.add_handler(self, "<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_sasl_digest_md5_auth, instream=True)
|
||||||
|
basexmpp.add_handler(self, "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>", self.handler_sasl_digest_md5_auth_fail, instream=True)
|
||||||
|
basexmpp.add_handler(self, "<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_success, instream=True)
|
||||||
|
basexmpp.add_handler(self, "<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_fail, instream=True)
|
||||||
#self.registerHandler(Callback('Roster Update', MatchXMLMask("<presence xmlns='%s' type='subscribe' />" % self.default_ns), self._handlePresenceSubscribe, thread=True))
|
#self.registerHandler(Callback('Roster Update', MatchXMLMask("<presence xmlns='%s' type='subscribe' />" % self.default_ns), self._handlePresenceSubscribe, thread=True))
|
||||||
self.registerFeature("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls' />", self.handler_starttls, True)
|
self.registerFeature("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls' />", self.handler_starttls, True)
|
||||||
self.registerFeature("<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_sasl_auth, True)
|
self.registerFeature("<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_sasl_auth, True)
|
||||||
|
@ -211,15 +217,11 @@ class ClientXMPP(basexmpp, XMLStream):
|
||||||
if '{urn:ietf:params:xml:ns:xmpp-tls}starttls' in self.features:
|
if '{urn:ietf:params:xml:ns:xmpp-tls}starttls' in self.features:
|
||||||
return False
|
return False
|
||||||
logging.debug("Starting SASL Auth")
|
logging.debug("Starting SASL Auth")
|
||||||
self.add_handler("<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_success, instream=True)
|
|
||||||
self.add_handler("<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_auth_fail, instream=True)
|
|
||||||
sasl_mechs = xml.findall('{urn:ietf:params:xml:ns:xmpp-sasl}mechanism')
|
sasl_mechs = xml.findall('{urn:ietf:params:xml:ns:xmpp-sasl}mechanism')
|
||||||
if len(sasl_mechs):
|
if len(sasl_mechs):
|
||||||
for sasl_mech in sasl_mechs:
|
for sasl_mech in sasl_mechs:
|
||||||
self.features.append("sasl:%s" % sasl_mech.text)
|
self.features.append("sasl:%s" % sasl_mech.text)
|
||||||
if 'sasl:DIGEST-MD5' in self.features:
|
if 'sasl:DIGEST-MD5' in self.features:
|
||||||
self.add_handler("<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self.handler_sasl_digest_md5_auth, instream=True)
|
|
||||||
self.add_handler("<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>", self.handler_sasl_digest_md5_auth_fail, instream=True)
|
|
||||||
self.sendPriorityRaw("""<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/>""")
|
self.sendPriorityRaw("""<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/>""")
|
||||||
elif 'sasl:PLAIN' in self.features:
|
elif 'sasl:PLAIN' in self.features:
|
||||||
if sys.version_info < (3,0):
|
if sys.version_info < (3,0):
|
||||||
|
|
Loading…
Reference in a new issue