Example #1
0
            def _send_signed(userid, var_pkey):
                # verify and link key
                pkey = base64.b64decode(var_pkey.value.__str__().encode('utf-8'))
                signed_pkey = self.parent.link_public_key(pkey, userid)
                if signed_pkey:
                    iq = xmlstream2.toResponse(stanza, 'result')
                    query = iq.addElement((xmlstream2.NS_IQ_REGISTER, 'query'))

                    form = query.addElement(('jabber:x:data', 'x'))
                    form['type'] = 'form'

                    hidden = form.addElement((None, 'field'))
                    hidden['type'] = 'hidden'
                    hidden['var'] = 'FORM_TYPE'
                    hidden.addElement((None, 'value'), content='http://kontalk.org/protocol/register#key')

                    signed = form.addElement((None, 'field'))
                    signed['type'] = 'text-single'
                    signed['label'] = 'Signed public key'
                    signed['var'] = 'publickey'
                    signed.addElement((None, 'value'), content=base64.b64encode(signed_pkey))

                    self.parent.send(iq, True)

                else:
                    # key not signed or verified
                    self.parent.error(stanza, 'forbidden', 'Invalid public key.')
Example #2
0
            def _send_signed(userid, var_pkey):
                # verify and link key
                pkey = base64.b64decode(var_pkey.value.__str__().encode('utf-8'))
                signed_pkey = self.parent.link_public_key(pkey, userid)
                if signed_pkey:
                    iq = xmlstream2.toResponse(stanza, 'result')
                    query = iq.addElement((xmlstream2.NS_IQ_REGISTER, 'query'))

                    form = query.addElement(('jabber:x:data', 'x'))
                    form['type'] = 'form'

                    hidden = form.addElement((None, 'field'))
                    hidden['type'] = 'hidden'
                    hidden['var'] = 'FORM_TYPE'
                    hidden.addElement((None, 'value'), content='http://kontalk.org/protocol/register#key')

                    signed = form.addElement((None, 'field'))
                    signed['type'] = 'text-single'
                    signed['label'] = 'Signed public key'
                    signed['var'] = 'publickey'
                    signed.addElement((None, 'value'), content=base64.b64encode(signed_pkey))

                    self.parent.send(iq, True)

                else:
                    # key not signed or verified
                    self.parent.error(stanza, 'forbidden', 'Invalid public key.')
Example #3
0
        def bounceError(_):
            resetConnecting(None)
            log.debug("unable to connect to remote server, bouncing error")
            if otherHost in self._outgoingQueues:
                for element in self._outgoingQueues[otherHost]:
                    log.debug("ERROR pre: %s" % (element.toXml().encode('utf-8'),))
                    # do not send routing errors for presence
                    if element.name == 'message':
                        e = error.StanzaError('network-server-timeout', 'wait')
                        log.debug("ERROR back %s" % (e.toResponse(element).toXml(), ))
                        err = e.toResponse(element)
                        # append original stanza
                        c = err.addElement((None, 'original'))
                        c.addChild(element)
                        self.router.send(err)
                    # send back presence with type error for presence probes
                    elif element.name == 'presence' and element.getAttribute('type') == 'probe':
                        e = xmlstream2.toResponse(element, 'error')
                        if e.hasAttribute('destination'):
                            e['to'] = e['destination']
                            del e['destination']

                        gid = e.getAttribute('id')
                        if gid:
                            group = e.addElement((xmlstream2.NS_XMPP_STANZA_GROUP, 'group'))
                            group['id'] = gid
                            group['count'] = str(1)
                        self.router.send(e)
                del self._outgoingQueues[otherHost]
Example #4
0
 def version(self, stanza):
     stanza.consumed = True
     response = xmlstream2.toResponse(stanza, 'result')
     query = domish.Element((xmlstream2.NS_IQ_VERSION, 'query'))
     query.addElement((None, 'name'), content=version.NAME + '-c2s')
     query.addElement((None, 'version'), content=version.VERSION)
     response.addChild(query)
     self.send(response)
Example #5
0
 def execute(self, stanza):
     # TODO actually implement the command :)
     stanza.consumed = True
     res = xmlstream2.toResponse(stanza, 'result')
     cmd = res.addElement((xmlstream2.NS_PROTO_COMMANDS, 'command'))
     cmd['node'] = stanza.command['node']
     cmd['status'] = 'completed'
     self.handler.send(res)
Example #6
0
 def execute(self, stanza):
     # TODO actually implement the command :)
     stanza.consumed = True
     res = xmlstream2.toResponse(stanza, 'result')
     cmd = res.addElement((xmlstream2.NS_PROTO_COMMANDS, 'command'))
     cmd['node'] = stanza.command['node']
     cmd['status'] = 'completed'
     self.handler.send(res)
Example #7
0
 def version(self, stanza):
     stanza.consumed = True
     response = xmlstream2.toResponse(stanza, 'result')
     query = domish.Element((xmlstream2.NS_IQ_VERSION, 'query'))
     query.addElement((None, 'name'), content=version.NAME + '-c2s')
     query.addElement((None, 'version'), content=version.VERSION)
     response.addChild(query)
     self.send(response)
Example #8
0
    def bounce(self, stanza):
        """Bounce stanzas as results."""
        if not stanza.consumed:
            util.resetNamespace(stanza, self.namespace)

            if self.router.logTraffic:
                log.debug("bouncing %s" % (stanza.toXml(), ))

            stanza.consumed = True
            self.send(xmlstream2.toResponse(stanza, 'result'))
Example #9
0
    def onDiscoInfo(self, stanza):
        if not stanza.consumed:
            stanza.consumed = True
            response = xmlstream2.toResponse(stanza, 'result')
            query = response.addElement((xmlstream2.NS_DISCO_INFO, 'query'))
            query.addChild(domish.Element((None, 'identity'), attribs={'category': 'server', 'type' : 'im', 'name': version.IDENTITY}))

            for feature in self.supportedFeatures:
                query.addChild(domish.Element((None, 'feature'), attribs={'var': feature }))
            self.send(response)
Example #10
0
    def bounce(self, stanza):
        """Bounce stanzas as results."""
        if not stanza.consumed:
            util.resetNamespace(stanza, self.namespace)

            if self.router.logTraffic:
                log.debug("bouncing %s" % (stanza.toXml(), ))

            stanza.consumed = True
            self.send(xmlstream2.toResponse(stanza, 'result'))
Example #11
0
    def onDiscoInfo(self, stanza):
        if not stanza.consumed:
            stanza.consumed = True
            response = xmlstream2.toResponse(stanza, 'result')
            query = response.addElement((xmlstream2.NS_DISCO_INFO, 'query'))
            query.addChild(domish.Element((None, 'identity'), attribs={'category': 'server', 'type' : 'im', 'name': version.IDENTITY}))

            for feature in self.supportedFeatures:
                query.addChild(domish.Element((None, 'feature'), attribs={'var': feature }))
            self.send(response)
Example #12
0
    def onDiscoItems(self, stanza):
        if not stanza.consumed:
            stanza.consumed = True
            response = xmlstream2.toResponse(stanza, 'result')
            query = response.addElement((xmlstream2.NS_DISCO_ITEMS, 'query'))
            node = stanza.query.getAttribute('node')
            if node:
                query['node'] = node
                if node in self.items:
                    for item in self.items[node]:
                        n = query.addElement((None, 'item'))
                        n['jid'] = item['jid']
                        n['node'] = item['node']
                        n['name'] = item['name']

            self.send(response)
Example #13
0
    def onDiscoItems(self, stanza):
        if not stanza.consumed:
            stanza.consumed = True
            response = xmlstream2.toResponse(stanza, 'result')
            query = response.addElement((xmlstream2.NS_DISCO_ITEMS, 'query'))
            node = stanza.query.getAttribute('node')
            if node:
                query['node'] = node
                if node in self.items:
                    for item in self.items[node]:
                        n = query.addElement((None, 'item'))
                        n['jid'] = item['jid']
                        n['node'] = item['node']
                        n['name'] = item['name']

            self.send(response)
Example #14
0
 def received(self, stanza):
     ack = xmlstream2.toResponse(stanza, stanza['type'])
     ack.addElement((xmlstream2.NS_XMPP_SERVER_RECEIPTS, 'ack'))
     self.send(ack)
Example #15
0
 def received(self, stanza):
     ack = xmlstream2.toResponse(stanza, stanza['type'])
     ack.addElement((xmlstream2.NS_XMPP_SERVER_RECEIPTS, 'ack'))
     self.send(ack)
Example #16
0
 def last_activity(self, stanza):
     stanza.consumed = True
     seconds = self.parent.router.uptime()
     response = xmlstream2.toResponse(stanza, 'result')
     response.addChild(domish.Element((xmlstream2.NS_IQ_LAST, 'query'), attribs={'seconds': str(int(seconds))}))
     self.send(response)
Example #17
0
 def last_activity(self, stanza):
     stanza.consumed = True
     seconds = self.parent.router.uptime()
     response = xmlstream2.toResponse(stanza, 'result')
     response.addChild(domish.Element((xmlstream2.NS_IQ_LAST, 'query'), attribs={'seconds': str(int(seconds))}))
     self.send(response)