Beispiel #1
0
 def start(self):
     iq = (XML.iq(type='set', id=self.get_id())
             .add(XML.bind(xmlns=self.NS_BIND)))
     if self.resource is not None:
         iq[0].add(XML.resource.add(self.resource))
     self.client.write(iq)
     self.client.process()
Beispiel #2
0
 def handle(self, xml_obj):
     if self.state == 0:
         challenge = base64.b64decode(xml_obj.text)
         logging.debug(challenge)
         digest = RFC2831(challenge).get_challenge()
         response = digest.get_response(self.username, self.password)
         response_b64 = base64.b64encode(str(response))
         self.write(XML.response(xmlns=NS_SASL).add(response_b64))
         self.state = 1
         self.client.process()
     elif self.state == 1:
         if xml_obj.tag.endswith('success'):
             rspauth = base64.b64decode(xml_obj.text)
             self.rspauth = rspauth.lstrip('rspauth=')
             self.is_done = True
             return self.PlugOut()
         elif xml_obj.tag.endswith('challenge'):
             rspauth = base64.b64decode(xml_obj.text)
             self.rspauth = rspauth.lstrip('rspauth=')
             self.write('<response xmlns="%s"/>' % NS_SASL)
             self.state = 2
             self.client.process()
         elif xml_obj.tag.endswith('failure'):
             raise Exception('Auth failure', xml_obj)
         else: pass
     elif self.state == 2:
         self.is_done = True
         return self.PlugOut()
     else:
         return # exit
Beispiel #3
0
 def set_attributes(self, attribs):
     """Auth with digest"""
     iq = XML.iq(type='set', id='auth_2')
     query = XML.query(xmlns=NS_AUTH)
     iq.add(query)
     if 'username' in attribs:
         query.add(XML.username.add(self.username))
     if 'resource' in attribs:
         if not self.resource:
             self.resource = uuid4().hex[:8]
         query.add(XML.resource.add(self.resource))
     if 'digest' in attribs:
         query.add(XML.digest.add(self.get_digest()))
     elif 'password' in attribs:
         query.add(XML.password.add(self.password))
     self.write(iq)
Beispiel #4
0
 def start(self):
     self.sasl_handler = DigestMD5(self.client, self.username,
                                   self.password)
     mech = 'DIGEST-MD5'
     logging.info('Effective mechanism: %s' % mech)
     self.client.write(XML.auth(xmlns=NS_SASL, mechanism=mech))
     self.effective_mechanism = mech
     self.client.process()
Beispiel #5
0
 def start(self):
     # Query for methods
     self.write(XML.iq(type='get', id='auth_1').add(
         XML.query(xmlns=NS_AUTH).add(
             XML.username.add(self.username))))
     self.client.process()