Exemplo n.º 1
0
    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
Exemplo n.º 2
0
	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
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
	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)
Exemplo n.º 5
0
	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