Update legacy auth to be used outside of stream features.
Also, add detection of legacy XMPP version.
This commit is contained in:
parent
94488fa2ea
commit
657102e938
@ -212,6 +212,10 @@ class BaseXMPP(XMLStream):
|
|||||||
self.stream_version = xml.get('version', '')
|
self.stream_version = xml.get('version', '')
|
||||||
self.peer_default_lang = xml.get('{%s}lang' % XML_NS, None)
|
self.peer_default_lang = xml.get('{%s}lang' % XML_NS, None)
|
||||||
|
|
||||||
|
if not self.is_component and not self.stream_version:
|
||||||
|
log.warning('Legacy XMPP 0.9 protocol detected.')
|
||||||
|
self.event('legacy_protocol')
|
||||||
|
|
||||||
def process(self, *args, **kwargs):
|
def process(self, *args, **kwargs):
|
||||||
"""Initialize plugins and begin processing the XML stream.
|
"""Initialize plugins and begin processing the XML stream.
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class FeatureMechanisms(BasePlugin):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def plugin_init(self):
|
def plugin_init(self):
|
||||||
if not self.use_mech and not self.xmpp.boundjid.user:
|
if not self.use_mech and not self.xmpp.requested_jid.user:
|
||||||
self.use_mech = 'ANONYMOUS'
|
self.use_mech = 'ANONYMOUS'
|
||||||
|
|
||||||
if self.sasl_callback is None:
|
if self.sasl_callback is None:
|
||||||
|
@ -44,16 +44,27 @@ class XEP_0078(BasePlugin):
|
|||||||
restart=False,
|
restart=False,
|
||||||
order=self.order)
|
order=self.order)
|
||||||
|
|
||||||
|
self.xmpp.add_event_handler('legacy_protocol',
|
||||||
|
self._handle_legacy_protocol)
|
||||||
|
|
||||||
register_stanza_plugin(Iq, stanza.IqAuth)
|
register_stanza_plugin(Iq, stanza.IqAuth)
|
||||||
register_stanza_plugin(StreamFeatures, stanza.AuthFeature)
|
register_stanza_plugin(StreamFeatures, stanza.AuthFeature)
|
||||||
|
|
||||||
def plugin_end(self):
|
def plugin_end(self):
|
||||||
|
self.xmpp.del_event_handler('legacy_protocol',
|
||||||
|
self._handle_legacy_protocol)
|
||||||
self.xmpp.unregister_feature('auth', self.order)
|
self.xmpp.unregister_feature('auth', self.order)
|
||||||
|
|
||||||
def _handle_auth(self, features):
|
def _handle_auth(self, features):
|
||||||
# If we can or have already authenticated with SASL, do nothing.
|
# If we can or have already authenticated with SASL, do nothing.
|
||||||
if 'mechanisms' in features['features']:
|
if 'mechanisms' in features['features']:
|
||||||
return False
|
return False
|
||||||
|
return self.authenticate()
|
||||||
|
|
||||||
|
def _handle_legacy_protocol(self, event):
|
||||||
|
self.authenticate()
|
||||||
|
|
||||||
|
def authenticate(self):
|
||||||
if self.xmpp.authenticated:
|
if self.xmpp.authenticated:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -62,8 +73,8 @@ class XEP_0078(BasePlugin):
|
|||||||
# Step 1: Request the auth form
|
# Step 1: Request the auth form
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'get'
|
iq['type'] = 'get'
|
||||||
iq['to'] = self.xmpp.boundjid.host
|
iq['to'] = self.xmpp.requested_jid.host
|
||||||
iq['auth']['username'] = self.xmpp.boundjid.user
|
iq['auth']['username'] = self.xmpp.requested_jid.user
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = iq.send(now=True)
|
resp = iq.send(now=True)
|
||||||
@ -81,11 +92,11 @@ class XEP_0078(BasePlugin):
|
|||||||
# Step 2: Fill out auth form for either password or digest auth
|
# Step 2: Fill out auth form for either password or digest auth
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'set'
|
iq['type'] = 'set'
|
||||||
iq['auth']['username'] = self.xmpp.boundjid.user
|
iq['auth']['username'] = self.xmpp.requested_jid.user
|
||||||
|
|
||||||
# A resource is required, so create a random one if necessary
|
# A resource is required, so create a random one if necessary
|
||||||
if self.xmpp.boundjid.resource:
|
if self.xmpp.requested_jid.resource:
|
||||||
iq['auth']['resource'] = self.xmpp.boundjid.resource
|
iq['auth']['resource'] = self.xmpp.requested_jid.resource
|
||||||
else:
|
else:
|
||||||
iq['auth']['resource'] = '%s' % random.random()
|
iq['auth']['resource'] = '%s' % random.random()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user