コード例 #1
0
ファイル: component.py プロジェクト: Hetal728/SMP-ClassiCube
    def initialize(self):
        xs = self.xmlstream
        hs = domish.Element((self.xmlstream.namespace, "handshake"))
        hs.addContent(
            xmlstream.hashPassword(xs.sid, unicode(xs.authenticator.password)))

        # Setup observer to watch for handshake result
        xs.addOnetimeObserver("/handshake", self._cbHandshake)
        xs.send(hs)
        self._deferred = defer.Deferred()
        return self._deferred
コード例 #2
0
ファイル: component.py プロジェクト: Hetal728/SMP-ClassiCube
    def initialize(self):
        xs = self.xmlstream
        hs = domish.Element((self.xmlstream.namespace, "handshake"))
        hs.addContent(xmlstream.hashPassword(xs.sid,
                                             unicode(xs.authenticator.password)))

        # Setup observer to watch for handshake result
        xs.addOnetimeObserver("/handshake", self._cbHandshake)
        xs.send(hs)
        self._deferred = defer.Deferred()
        return self._deferred
コード例 #3
0
ファイル: component.py プロジェクト: Hetal728/SMP-ClassiCube
    def onHandshake(self, handshake):
        """
        Called upon receiving the handshake request.

        This checks that the given hash in C{handshake} is equal to a
        calculated hash, responding with a handshake reply or a stream error.
        If the handshake was ok, the stream is authorized, and  XML Stanzas may
        be exchanged.
        """
        calculatedHash = xmlstream.hashPassword(self.xmlstream.sid,
                                                unicode(self.secret))
        if handshake != calculatedHash:
            exc = error.StreamError('not-authorized', text='Invalid hash')
            self.xmlstream.sendStreamError(exc)
        else:
            self.xmlstream.send('<handshake/>')
            self.xmlstream.dispatch(self.xmlstream,
                                    xmlstream.STREAM_AUTHD_EVENT)
コード例 #4
0
ファイル: component.py プロジェクト: Hetal728/SMP-ClassiCube
    def onHandshake(self, handshake):
        """
        Called upon receiving the handshake request.

        This checks that the given hash in C{handshake} is equal to a
        calculated hash, responding with a handshake reply or a stream error.
        If the handshake was ok, the stream is authorized, and  XML Stanzas may
        be exchanged.
        """
        calculatedHash = xmlstream.hashPassword(self.xmlstream.sid,
                                                unicode(self.secret))
        if handshake != calculatedHash:
            exc = error.StreamError('not-authorized', text='Invalid hash')
            self.xmlstream.sendStreamError(exc)
        else:
            self.xmlstream.send('<handshake/>')
            self.xmlstream.dispatch(self.xmlstream,
                                    xmlstream.STREAM_AUTHD_EVENT)
コード例 #5
0
ファイル: client.py プロジェクト: Hetal728/SMP-ClassiCube
    def _cbAuthQuery(self, iq):
        jid = self.xmlstream.authenticator.jid
        password = self.xmlstream.authenticator.password

        # Construct auth request
        reply = xmlstream.IQ(self.xmlstream, "set")
        reply.addElement(("jabber:iq:auth", "query"))
        reply.query.addElement("username", content = jid.user)
        reply.query.addElement("resource", content = jid.resource)

        # Prefer digest over plaintext
        if DigestAuthQry.matches(iq):
            digest = xmlstream.hashPassword(self.xmlstream.sid, unicode(password))
            reply.query.addElement("digest", content = digest)
        else:
            reply.query.addElement("password", content = password)

        d = reply.send()
        d.addCallbacks(self._cbAuth, self._ebAuth)
        return d
コード例 #6
0
 def test_unicodeSecret(self):
     """
     The concatenated sid and password must be encoded to UTF-8 before hashing.
     """
     hash = xmlstream.hashPassword(u"12345", u"secr\u00e9t")
     self.assertEqual('659bf88d8f8e179081f7f3b4a8e7d224652d2853', hash)
コード例 #7
0
 def test_basic(self):
     """
     The sid and secret are concatenated to calculate sha1 hex digest.
     """
     hash = xmlstream.hashPassword(u"12345", u"secret")
     self.assertEqual('99567ee91b2c7cabf607f10cb9f4a3634fa820e0', hash)