コード例 #1
0
ファイル: sm.py プロジェクト: nagecai/xmppserver
            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.')
コード例 #2
0
ファイル: sm.py プロジェクト: BillTheBest/xmppserver
            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.')
コード例 #3
0
ファイル: net.py プロジェクト: BillTheBest/xmppserver
        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]
コード例 #4
0
ファイル: sm.py プロジェクト: nagecai/xmppserver
 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)
コード例 #5
0
ファイル: sm.py プロジェクト: nagecai/xmppserver
 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)
コード例 #6
0
ファイル: sm.py プロジェクト: BillTheBest/xmppserver
 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)
コード例 #7
0
ファイル: sm.py プロジェクト: BillTheBest/xmppserver
 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)
コード例 #8
0
ファイル: sm.py プロジェクト: BillTheBest/xmppserver
    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'))
コード例 #9
0
ファイル: sm.py プロジェクト: BillTheBest/xmppserver
    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)
コード例 #10
0
ファイル: sm.py プロジェクト: nagecai/xmppserver
    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'))
コード例 #11
0
ファイル: sm.py プロジェクト: nagecai/xmppserver
    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)
コード例 #12
0
ファイル: sm.py プロジェクト: BillTheBest/xmppserver
    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)
コード例 #13
0
ファイル: sm.py プロジェクト: nagecai/xmppserver
    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)
コード例 #14
0
ファイル: sm.py プロジェクト: BillTheBest/xmppserver
 def received(self, stanza):
     ack = xmlstream2.toResponse(stanza, stanza['type'])
     ack.addElement((xmlstream2.NS_XMPP_SERVER_RECEIPTS, 'ack'))
     self.send(ack)
コード例 #15
0
ファイル: sm.py プロジェクト: nagecai/xmppserver
 def received(self, stanza):
     ack = xmlstream2.toResponse(stanza, stanza['type'])
     ack.addElement((xmlstream2.NS_XMPP_SERVER_RECEIPTS, 'ack'))
     self.send(ack)
コード例 #16
0
ファイル: sm.py プロジェクト: BillTheBest/xmppserver
 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)
コード例 #17
0
ファイル: sm.py プロジェクト: nagecai/xmppserver
 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)