From 2c2498b65846397ce708452ff45f81ecc25b502f Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 27 Nov 2012 19:53:04 -0500 Subject: [PATCH 1/3] Allow for more credential values to be user specified instead of auto-filled. --- .../features/feature_mechanisms/mechanisms.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/sleekxmpp/features/feature_mechanisms/mechanisms.py b/sleekxmpp/features/feature_mechanisms/mechanisms.py index b480d5be..a6e43a76 100644 --- a/sleekxmpp/features/feature_mechanisms/mechanisms.py +++ b/sleekxmpp/features/feature_mechanisms/mechanisms.py @@ -92,11 +92,7 @@ class FeatureMechanisms(BasePlugin): values = required_values.union(optional_values) for value in values: if value == 'username': - result[value] = self.xmpp.requested_jid.user - elif value == 'password': - result[value] = creds['password'] - elif value == 'authzid': - result[value] = creds.get('authzid', '') + result[value] = creds.get('username', self.xmpp.requested_jid.user) elif value == 'email': jid = self.xmpp.requested_jid.bare result[value] = creds.get('email', jid) @@ -106,13 +102,13 @@ class FeatureMechanisms(BasePlugin): else: result[value] = None elif value == 'host': - result[value] = self.xmpp.requested_jid.domain + result[value] = creds.get('host', self.xmpp.requested_jid.domain) elif value == 'realm': - result[value] = self.xmpp.requested_jid.domain + result[value] = creds.get('realm', self.xmpp.requested_jid.domain) elif value == 'service-name': - result[value] = self.xmpp._service_name + result[value] = creds.get('service-name', self.xmpp._service_name) elif value == 'service': - result[value] = 'xmpp' + result[value] = creds.get('service', 'xmpp') elif value in creds: result[value] = creds[value] return result From 0eb009496e4e2998f6387f835f8ae29830f1a61b Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 27 Nov 2012 19:53:43 -0500 Subject: [PATCH 2/3] Use the username credential instead of jid to enable ANONYMOUS auth. --- sleekxmpp/features/feature_mechanisms/mechanisms.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sleekxmpp/features/feature_mechanisms/mechanisms.py b/sleekxmpp/features/feature_mechanisms/mechanisms.py index a6e43a76..9f3c47f6 100644 --- a/sleekxmpp/features/feature_mechanisms/mechanisms.py +++ b/sleekxmpp/features/feature_mechanisms/mechanisms.py @@ -44,15 +44,16 @@ class FeatureMechanisms(BasePlugin): } def plugin_init(self): - if not self.use_mech and not self.xmpp.requested_jid.user: - self.use_mech = 'ANONYMOUS' - if self.sasl_callback is None: self.sasl_callback = self._default_credentials if self.security_callback is None: self.security_callback = self._default_security + creds = self.sasl_callback(set(['username']), set()) + if not self.use_mech and not creds['username']: + self.use_mech = 'ANONYMOUS' + self.mech = None self.mech_list = set() self.attempted_mechs = set() From b820351f6468e6718dc75b69a0088b2433a658af Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 27 Nov 2012 19:54:46 -0500 Subject: [PATCH 3/3] Fix DIGEST-MD5 support for picky servers --- sleekxmpp/features/feature_mechanisms/stanza/auth.py | 2 +- sleekxmpp/util/sasl/mechanisms.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sleekxmpp/features/feature_mechanisms/stanza/auth.py b/sleekxmpp/features/feature_mechanisms/stanza/auth.py index 7b665345..6b6f85a3 100644 --- a/sleekxmpp/features/feature_mechanisms/stanza/auth.py +++ b/sleekxmpp/features/feature_mechanisms/stanza/auth.py @@ -40,7 +40,7 @@ class Auth(StanzaBase): if not self['mechanism'] in self.plain_mechs: if values: self.xml.text = bytes(base64.b64encode(values)).decode('utf-8') - else: + elif values == b'': self.xml.text = '=' else: self.xml.text = bytes(values).decode('utf-8') diff --git a/sleekxmpp/util/sasl/mechanisms.py b/sleekxmpp/util/sasl/mechanisms.py index 55ae44dd..80cb7219 100644 --- a/sleekxmpp/util/sasl/mechanisms.py +++ b/sleekxmpp/util/sasl/mechanisms.py @@ -467,7 +467,8 @@ class DIGEST(Mech): 'qop': self.qop, 'digest-uri': quote(self.digest_uri()), 'response': self.response(b'AUTHENTICATE'), - 'maxbuf': self.maxbuf + 'maxbuf': self.maxbuf, + 'charset': 'utf-8' } resp = b'' for key, value in data.items(): @@ -480,7 +481,7 @@ class DIGEST(Mech): if self.cnonce and self.nonce and self.nonce_count and self.qop: self.nonce_count += 1 return self.respond() - return b'' + return None data = self.parse(challenge) if 'rspauth' in data: