home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / pyxmpp / sasl / plain.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  3.3 KB  |  87 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. __revision__ = '$Id: plain.py 714 2010-04-05 10:20:10Z jajcus $'
  5. __docformat__ = 'restructuredtext en'
  6. import logging
  7. from pyxmpp.utils import to_utf8, from_utf8
  8. from pyxmpp.sasl.core import ClientAuthenticator, ServerAuthenticator
  9. from pyxmpp.sasl.core import Success, Failure, Challenge, Response
  10.  
  11. class PlainClientAuthenticator(ClientAuthenticator):
  12.     
  13.     def __init__(self, password_manager):
  14.         ClientAuthenticator.__init__(self, password_manager)
  15.         self.username = None
  16.         self.finished = None
  17.         self.password = None
  18.         self.authzid = None
  19.         self._PlainClientAuthenticator__logger = logging.getLogger('pyxmpp.sasl.PlainClientAuthenticator')
  20.  
  21.     
  22.     def start(self, username, authzid):
  23.         self.username = username
  24.         if authzid:
  25.             self.authzid = authzid
  26.         else:
  27.             self.authzid = ''
  28.         self.finished = 0
  29.         return self.challenge('')
  30.  
  31.     
  32.     def challenge(self, challenge):
  33.         _unused = challenge
  34.         if self.finished:
  35.             self._PlainClientAuthenticator__logger.debug('Already authenticated')
  36.             return Failure('extra-challenge')
  37.         self.finished = 1
  38.         if self.password is None:
  39.             (self.password, pformat) = self.password_manager.get_password(self.username)
  40.         
  41.         if not (self.password) or pformat != 'plain':
  42.             self._PlainClientAuthenticator__logger.debug("Couldn't retrieve plain password")
  43.             return Failure('password-unavailable')
  44.         return Response('%s\x00%s\x00%s' % (to_utf8(self.authzid), to_utf8(self.username), to_utf8(self.password)))
  45.  
  46.     
  47.     def finish(self, data):
  48.         _unused = data
  49.         return Success(self.username, None, self.authzid)
  50.  
  51.  
  52.  
  53. class PlainServerAuthenticator(ServerAuthenticator):
  54.     
  55.     def __init__(self, password_manager):
  56.         ServerAuthenticator.__init__(self, password_manager)
  57.         self._PlainServerAuthenticator__logger = logging.getLogger('pyxmpp.sasl.PlainServerAuthenticator')
  58.  
  59.     
  60.     def start(self, response):
  61.         if not response:
  62.             return Challenge('')
  63.         return self.response(response)
  64.  
  65.     
  66.     def response(self, response):
  67.         s = response.split('\x00')
  68.         if len(s) != 3:
  69.             self._PlainServerAuthenticator__logger.debug('Bad response: %r' % (response,))
  70.             return Failure('not-authorized')
  71.         (authzid, username, password) = s
  72.         authzid = from_utf8(authzid)
  73.         username = from_utf8(username)
  74.         password = from_utf8(password)
  75.         if not self.password_manager.check_password(username, password):
  76.             self._PlainServerAuthenticator__logger.debug('Bad password. Response was: %r' % (response,))
  77.             return Failure('not-authorized')
  78.         info = {
  79.             'mechanism': 'PLAIN',
  80.             'username': username }
  81.         if self.password_manager.check_authzid(authzid, info):
  82.             return Success(username, None, authzid)
  83.         self._PlainServerAuthenticator__logger.debug('Authzid verification failed.')
  84.         return Failure('invalid-authzid')
  85.  
  86.  
  87.