def setMechanism(self): """ Select and setup authentication mechanism. """ token = self.xmlstream.authenticator.token mechanisms = sasl.get_mechanisms(self.xmlstream) if token is not None and 'KONTALK-TOKEN' in mechanisms: self.mechanism = KontalkTokenMechanism(token) else: raise sasl.SASLNoAcceptableMechanism()
def wrapper(self, *args, **kwargs): res = None try: res = f(self, *args, **kwargs) except SASLNoAcceptableMechanism: pass finally: jid = self.xmlstream.authenticator.jid password = self.xmlstream.authenticator.password mechanisms = set(get_mechanisms(self.xmlstream)) available_auth_methods = method_names.intersection(mechanisms) if jid.user is None or not available_auth_methods: raise SASLNoAcceptableMechanism() method = auth_methods[available_auth_methods.pop()] self.mechanism = method(jid, password) return res
def start(self): jid = self.xmlstream.authenticator.jid password = self.xmlstream.authenticator.password mechanisms = get_mechanisms(self.xmlstream) if 'DIGEST-MD5' in mechanisms: self.mechanism = sasl_mechanisms.DigestMD5('xmpp', jid.host, None, jid.user, password) elif 'PLAIN' in mechanisms: self.mechanism = sasl_mechanisms.Plain(None, jid.user, password) else: return defer.fail(SASLNoAcceptableMechanism) self._deferred = defer.Deferred() self.xmlstream.addObserver('/challenge', self.onChallenge) self.xmlstream.addOnetimeObserver('/success', self.onSuccess) self.xmlstream.addOnetimeObserver('/failure', self.onFailure) self.sendAuth(self.mechanism.getInitialResponse()) return self._deferred
def setMechanism(self): jid = self.xmlstream.authenticator.jid password = self.xmlstream.authenticator.password mechanisms = sasl.get_mechanisms(self.xmlstream) if jid.user is not None: if 'DIGEST-MD5' in mechanisms: self.mechanism = sasl_mechanisms.DigestMD5('xmpp', jid.host, None, jid.user, password) elif 'PLAIN' in mechanisms: self.mechanism = sasl_mechanisms.Plain(None, jid.user, password) else: raise sasl.SASLNoAcceptableMechanism() else: if 'ANONYMOUS' in mechanisms: self.mechanism = Anonymous() else: raise sasl.SASLNoAccetableMechanism()