summaryrefslogtreecommitdiff
path: root/sleekxmpp/thirdparty/suelta/mechanisms/plain.py
diff options
context:
space:
mode:
authorNathan Fritz <nathan@andyet.net>2011-08-10 13:37:49 -0700
committerNathan Fritz <nathan@andyet.net>2011-08-10 13:37:49 -0700
commita189cb8333d5f59caa9015f0ded222696987d957 (patch)
tree467f202bc7f85a4cde85a5add3c372515f18adc3 /sleekxmpp/thirdparty/suelta/mechanisms/plain.py
parent0d4825d3ea0562f305939e653e3d414e70e4aaa8 (diff)
parent156b3200e3b5ad1b2e64eecc48cdc792f7b2ffd9 (diff)
downloadslixmpp-a189cb8333d5f59caa9015f0ded222696987d957.tar.gz
slixmpp-a189cb8333d5f59caa9015f0ded222696987d957.tar.bz2
slixmpp-a189cb8333d5f59caa9015f0ded222696987d957.tar.xz
slixmpp-a189cb8333d5f59caa9015f0ded222696987d957.zip
Merge branch 'develop' of github.com:fritzy/SleekXMPP into develop
Diffstat (limited to 'sleekxmpp/thirdparty/suelta/mechanisms/plain.py')
-rw-r--r--sleekxmpp/thirdparty/suelta/mechanisms/plain.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/sleekxmpp/thirdparty/suelta/mechanisms/plain.py b/sleekxmpp/thirdparty/suelta/mechanisms/plain.py
new file mode 100644
index 00000000..ab17095e
--- /dev/null
+++ b/sleekxmpp/thirdparty/suelta/mechanisms/plain.py
@@ -0,0 +1,61 @@
+import sys
+
+from sleekxmpp.thirdparty.suelta.util import bytes
+from sleekxmpp.thirdparty.suelta.sasl import Mechanism, register_mechanism
+from sleekxmpp.thirdparty.suelta.exceptions import SASLError, SASLCancelled
+
+
+class PLAIN(Mechanism):
+
+ """
+ """
+
+ def __init__(self, sasl, name):
+ """
+ """
+ super(PLAIN, self).__init__(sasl, name)
+
+ if not self.sasl.tls_active():
+ if not self.sasl.sec_query(self, '-ENCRYPTION, PLAIN'):
+ raise SASLCancelled(self.sasl, self)
+ else:
+ if not self.sasl.sec_query(self, '+ENCRYPTION, PLAIN'):
+ raise SASLCancelled(self.sasl, self)
+
+ self.check_values(['username', 'password'])
+
+ def prep(self):
+ """
+ Prepare for processing by deleting the password if
+ the user has not approved storing it in the clear.
+ """
+ if 'savepass' not in self.values:
+ if self.sasl.sec_query(self, 'CLEAR-PASSWORD'):
+ self.values['savepass'] = True
+
+ if 'savepass' not in self.values:
+ del self.values['password']
+
+ return True
+
+ def process(self, challenge=None):
+ """
+ Process a challenge request and return the response.
+
+ :param challenge: A challenge issued by the server that
+ must be answered for authentication.
+ """
+ user = bytes(self.values['username'])
+ password = bytes(self.values['password'])
+ return b'\x00' + user + b'\x00' + password
+
+ def okay(self):
+ """
+ Mutual authentication is not supported by PLAIN.
+
+ :returns: ``True``
+ """
+ return True
+
+
+register_mechanism('PLAIN', 1, PLAIN, use_hashes=False)