コード例 #1
0
    def process_data(self, data):
        # Parse incoming data

        data = self.replace_non_character(data)

        if self._client.is_websocket:
            stanza = Node(node=data)
            if is_websocket_stream_error(stanza):
                for tag in stanza.getChildren():
                    name = tag.getName()
                    if (name != 'text'
                            and tag.getNamespace() == Namespace.XMPP_STREAMS):
                        self._websocket_stream_error = name

            elif is_websocket_close(stanza):
                self._log.info('Stream <close> received')
                self.notify('stream-end', self._websocket_stream_error)
                return

            self.dispatch(stanza)
            return

        try:
            self._parser.Parse(data)
        except (ExpatError, ValueError) as error:
            self._log.error('XML parsing error: %s', error)
            self.notify('parsing-error', error)
            return

        # end stream:stream tag received
        if self._parser.has_received_endtag():
            self._log.info('End of stream: %s', self._parser.streamError)
            self.notify('stream-end', self._parser.streamError)
            return
コード例 #2
0
 def to_node(self):
     node = Node(self.name)
     if self.parameters:
         node.addChild(node=make_parameters(self.parameters))
     add_children(node, 'surname', self.surname)
     add_children(node, 'given', self.given)
     add_children(node, 'additional', self.additional)
     add_children(node, 'prefix', self.prefix)
     add_children(node, 'suffix', self.suffix)
     return node
コード例 #3
0
 def to_node(self):
     vcard = Node(f'{Namespace.VCARD4} vcard')
     for group, props in self._properties:
         if group is None:
             vcard.addChild(node=props.to_node())
         else:
             group = Node(group)
             for prop in props:
                 group.addChild(node=prop.to_node())
             vcard.addChild(node=group)
     return vcard
コード例 #4
0
 def to_node(self):
     node = Node(self.name)
     if self.parameters:
         node.addChild(node=make_parameters(self.parameters))
     add_children(node, 'pobox', self.pobox)
     add_children(node, 'ext', self.ext)
     add_children(node, 'street', self.street)
     add_children(node, 'locality', self.locality)
     add_children(node, 'region', self.region)
     add_children(node, 'code', self.code)
     add_children(node, 'country', self.country)
     return node
コード例 #5
0
    def __init__(self, device_list):
        id_ = gajim.get_an_id()
        attrs = {'id': id_}
        Iq.__init__(self, typ='set', attrs=attrs)

        list_node = Node('list')
        for device in device_list:
            list_node.addChild('device').setAttr('id', device)

        publish = PublishNode(NS_DEVICE_LIST, list_node)
        pubsub = PubsubNode(publish)

        self.addChild(node=pubsub)
コード例 #6
0
ファイル: xmpp.py プロジェクト: mad-de/gajim-omemo
    def __init__(self, device_list):
        id_ = gajim.get_an_id()
        attrs = {'id': id_}
        Iq.__init__(self, typ='set', attrs=attrs)

        list_node = Node('list')
        for device in device_list:
            list_node.addChild('device').setAttr('id', device)

        publish = PublishNode(NS_DEVICE_LIST, list_node)
        pubsub = PubsubNode(publish)

        self.addChild(node=pubsub)
コード例 #7
0
 def to_node(self):
     node = Node(self.name)
     if self.parameters:
         node.addChild(node=make_parameters(self.parameters))
     node.addChild('sourceid', payload=self.sourceid)
     node.addChild('uri', payload=self.uri)
     return node
コード例 #8
0
ファイル: xmpp.py プロジェクト: amenk/gajim-omemo
    def __init__(self, device_list):
        assert isinstance(device_list, list)
        assert len(device_list) > 0
        id_ = gajim.get_an_id()
        attrs = {'id': id_}
        Iq.__init__(self, typ='set', attrs=attrs)

        list_node = Node('list', attrs={'xmlns': NS_DEVICE_LIST})
        for device in device_list:
            list_node.addChild('device').setAttr('id', device)

        publish = PublishNode(NS_DEVICE_LIST, list_node)
        pubsub = PubsubNode(publish)

        self.addChild(node=pubsub)
コード例 #9
0
ファイル: xmpp.py プロジェクト: Ape/gajim-plugins
    def __init__(self, device_list):
        assert isinstance(device_list, list)
        assert len(device_list) > 0
        id_ = gajim.get_an_id()
        attrs = {'id': id_}
        Iq.__init__(self, typ='set', attrs=attrs)

        list_node = Node('list', attrs={'xmlns': NS_OMEMO})
        for device in device_list:
            list_node.addChild('device').setAttr('id', device)

        publish = PublishNode(NS_DEVICE_LIST, list_node)
        pubsub = PubsubNode(publish)

        self.addChild(node=pubsub)
コード例 #10
0
def _make_delete(jid):
    return Iq('set',
              Namespace.ROSTER,
              payload=[Node('item', {
                  'jid': jid,
                  'subscription': 'remove'
              })])
コード例 #11
0
ファイル: util.py プロジェクト: thomasnet-mc/python-nbxmpp
def make_cancel_config_request(room_jid):
    cancel = Node(tag='x', attrs={'xmlns': Namespace.DATA, 'type': 'cancel'})
    iq = Iq(typ='set',
            queryNS=Namespace.MUC_OWNER,
            payload=cancel,
            to=room_jid)
    return iq
コード例 #12
0
 def __init__(self, contact_jid, device_id):
     id_ = gajim.get_an_id()
     attrs = {'id': id_}
     Iq.__init__(self, typ='get', attrs=attrs, to=contact_jid)
     items = Node('items', attrs={'node': NS_BUNDLES + str(device_id)})
     pubsub = PubsubNode(items)
     self.addChild(node=pubsub)
コード例 #13
0
 def __init__(self, contact_jid,):
     id_ = gajim.get_an_id()
     attrs = {'id': id_}
     Iq.__init__(self, typ='get', attrs=attrs, to=contact_jid)
     items = Node('items', attrs={'node': NS_DEVICE_LIST, 'max_items': 1})
     pubsub = PubsubNode(items)
     self.addChild(node=pubsub)
コード例 #14
0
ファイル: __init__.py プロジェクト: lheckemann/gajim-plugins
    def handle_outgoing_stanza(self, event):
        try:
            if not event.msg_iq.getTag('body'):
                return

            account = event.conn.name
            state = self.get_omemo_state(account)
            full_jid = str(event.msg_iq.getAttr('to'))
            to_jid = gajim.get_jid_without_resource(full_jid)
            if not state.encryption.is_active(to_jid):
                return

            # Delete previous Message out of Correction Message Stanza
            if event.msg_iq.getTag('replace', namespace=NS_CORRECT):
                event.msg_iq.delChild('encrypted')

            plaintext = event.msg_iq.getBody().encode('utf8')

            msg_dict = state.create_msg(gajim.get_jid_from_account(account),
                                        to_jid, plaintext)
            if not msg_dict:
                return True

            encrypted_node = OmemoMessage(msg_dict)
            event.msg_iq.delChild('body')
            event.msg_iq.addChild(node=encrypted_node)
            store = Node('store', attrs={'xmlns': NS_HINTS})
            event.msg_iq.addChild(node=store)
            self.print_msg_to_log(event.msg_iq)
        except Exception as e:
            log.debug(e)
            return True
コード例 #15
0
 def to_node(self):
     node = Node(self.name)
     if self.parameters:
         node.addChild(node=make_parameters(self.parameters))
     if self.sex:
         node.addChild('sex', payload=self.sex)
     if self.identity:
         node.addChild('identity', payload=self.identity)
     return node
コード例 #16
0
    def __init__(self, msg_dict):
        # , contact_jid, key, iv, payload, dev_id, my_dev_id):
        Node.__init__(self, 'encrypted', attrs={'xmlns': NS_OMEMO})
        header = Node('header', attrs={'sid': msg_dict['sid']})
        for rid, key in msg_dict['keys'].items():
            header.addChild('key', attrs={'rid': rid}).addData(b64encode(key))

        header.addChild('iv').addData(b64encode(msg_dict['iv']))
        self.addChild(node=header)
        self.addChild('payload').addData(b64encode(msg_dict['payload']))
コード例 #17
0
ファイル: xmpp.py プロジェクト: akallabeth/gajim-omemo
    def make_bundle_node(self, state_bundle):
        result = Node('bundle', attrs={'xmlns': NS_OMEMO})
        prekey_pub_node = result.addChild(
            'signedPreKeyPublic',
            attrs={'signedPreKeyId': state_bundle['signedPreKeyId']})
        prekey_pub_node.addData(state_bundle['signedPreKeyPublic'])

        prekey_sig_node = result.addChild('signedPreKeySignature')
        prekey_sig_node.addData(state_bundle['signedPreKeySignature'])

        identity_key_node = result.addChild('identityKey')
        identity_key_node.addData(state_bundle['identityKey'])
        prekeys = result.addChild('prekeys')

        for key in state_bundle['prekeys']:
            prekeys.addChild('preKeyPublic',
                             attrs={'preKeyId': key[0]}).addData(key[1])
        return result
コード例 #18
0
    def to_node(self):
        displaymarking = Node(tag='displaymarking')
        if self.fgcolor and self.fgcolor != '#000':
            displaymarking.setAttr('fgcolor', self.fgcolor)

        if self.bgcolor and self.bgcolor != '#FFF':
            displaymarking.setAttr('bgcolor', self.bgcolor)

        if self.name:
            displaymarking.setData(self.name)

        return displaymarking
コード例 #19
0
    def send_enable(self):
        if not self.sm_supported:
            return

        if self._client.sm_disabled:
            return

        enable = Node(Namespace.STREAM_MGMT + ' enable',
                      attrs={'resume': 'true'})
        self._client.send_nonza(enable, now=False)
        self._log.debug('Send enable')
        self._enable_sent = True
コード例 #20
0
ファイル: xmpp.py プロジェクト: klemens/gajim-omemo
    def __init__(self, msg_dict):
        # , contact_jid, key, iv, payload, dev_id, my_dev_id):
        Node.__init__(self, 'encrypted', attrs={'xmlns': NS_OMEMO})
        header = Node('header', attrs={'sid': msg_dict['sid']})
        for rid, key in msg_dict['keys'].items():
            header.addChild('key', attrs={'rid': rid}).addData(b64encode(key))

        header.addChild('iv').addData(b64encode(msg_dict['iv']))
        self.addChild(node=header)
        self.addChild('payload').addData(b64encode(msg_dict['payload']))
コード例 #21
0
 def to_node(self):
     security = Node(tag='securitylabel',
                     attrs={'xmlns': Namespace.SECLABEL})
     if self.displaymarking is not None:
         security.addChild(node=self.displaymarking.to_node())
     security.addChild(node=self.label)
     return security
コード例 #22
0
    def resume_request(self):
        if self._session_id is None:
            self._log.error('Attempted to resume without a valid session id')
            return

        # Save old messages in an extra "queue" to avoid race conditions
        # and to make it possible to replay stanzas even when resuming fails
        # Add messages here (instead of overwriting) so that repeated
        # connection errors don't delete unacked stanzas
        # (uqueue should be empty in this case anyways)
        self._old_uqueue += self._uqueue
        self._uqueue = []

        resume = Node(Namespace.STREAM_MGMT + ' resume',
                      attrs={
                          'h': self._in_h,
                          'previd': self._session_id
                      })

        self._acked_h = self._in_h
        self.resume_in_progress = True
        self._client.send_nonza(resume, now=False)
コード例 #23
0
 def to_node(self):
     vcard = Node(tag='vCard', attrs={'xmlns': Namespace.VCARD})
     for i in self.data:
         if i == 'jid':
             continue
         if isinstance(self.data[i], dict):
             child = vcard.addChild(i)
             for j in self.data[i]:
                 child.addChild(j).setData(self.data[i][j])
         elif isinstance(self.data[i], list):
             for j in self.data[i]:
                 child = vcard.addChild(i)
                 for k in j:
                     child.addChild(k).setData(j[k])
         else:
             vcard.addChild(i).setData(self.data[i])
     return vcard
コード例 #24
0
    def make_bundle_node(self, state_bundle):
        result = Node('bundle', attrs={'xmlns': NS_OMEMO})
        prekey_pub_node = result.addChild(
            'signedPreKeyPublic',
            attrs={'signedPreKeyId': state_bundle['signedPreKeyId']})
        prekey_pub_node.addData(state_bundle['signedPreKeyPublic'])

        prekey_sig_node = result.addChild('signedPreKeySignature')
        prekey_sig_node.addData(state_bundle['signedPreKeySignature'])

        identity_key_node = result.addChild('identityKey')
        identity_key_node.addData(state_bundle['identityKey'])
        prekeys = result.addChild('prekeys')

        for key in state_bundle['prekeys']:
            prekeys.addChild('preKeyPublic',
                             attrs={'preKeyId': key[0]}).addData(key[1])
        return result
コード例 #25
0
ファイル: omemoplugin.py プロジェクト: Ape/gajim-plugins
    def handle_outgoing_gc_stanza(self, event):
        """ Manipulates the outgoing groupchat stanza

            The body is getting encrypted

            Parameters
            ----------
            event : StanzaMessageOutgoingEvent

            Returns
            -------
            Return if encryption is not activated or any other
            exception or error occurs
        """
        account = event.conn.name
        if account in self.disabled_accounts:
            return
        try:
            # If we send a correction msg, the stanza is saved
            # in correction_msg
            if event.correction_msg:
                event.msg_iq = event.correction_msg
            if not event.msg_iq.getTag('body'):
                return
            state = self.get_omemo_state(account)
            full_jid = str(event.msg_iq.getAttr('to'))
            to_jid = gajim.get_jid_without_resource(full_jid)
            if to_jid not in self.groupchat:
                return
            if not state.encryption.is_active(to_jid):
                return
            # Delete previous Message out of Correction Message Stanza
            if event.msg_iq.getTag('replace', namespace=NS_CORRECT):
                event.msg_iq.delChild('encrypted', attrs={'xmlns': NS_OMEMO})

            plaintext = event.msg_iq.getBody()
            msg_dict = state.create_gc_msg(
                gajim.get_jid_from_account(account),
                to_jid,
                plaintext.encode('utf8'))
            if not msg_dict:
                return True

            self.gc_message[msg_dict['payload']] = plaintext
            encrypted_node = OmemoMessage(msg_dict)
            event.msg_iq.delChild('body')
            event.msg_iq.addChild(node=encrypted_node)

            # XEP-xxxx: Explicit Message Encryption
            if not event.msg_iq.getTag('encrypted', attrs={'xmlns': NS_EME}):
                eme_node = Node('encrypted', attrs={'xmlns': NS_EME,
                                                    'name': 'OMEMO',
                                                    'namespace': NS_OMEMO})
                event.msg_iq.addChild(node=eme_node)

            # Add Message for devices that dont support OMEMO
            support_msg = 'You received a message encrypted with ' \
                          'OMEMO but your client doesnt support OMEMO.'
            event.msg_iq.setBody(support_msg)

            # Store Hint for MAM
            store = Node('store', attrs={'xmlns': NS_HINTS})
            event.msg_iq.addChild(node=store)
            if event.correction_msg:
                event.correction_msg = event.msg_iq
                event.msg_iq = None
                self.print_msg_to_log(event.correction_msg)
            else:
                self.print_msg_to_log(event.msg_iq)
        except Exception as e:
            log.debug(e)
            return True
コード例 #26
0
 def __init__(self, data):
     assert data is Node
     Node.__init__(self, tag='pubsub', attrs={'xmlns': NS_PUBSUB})
     self.addChild(node=data)
コード例 #27
0
ファイル: xmpp.py プロジェクト: Ape/gajim-plugins
 def __init__(self, data):
     assert isinstance(data, Node)
     Node.__init__(self, tag='pubsub', attrs={'xmlns': NS_PUBSUB})
     self.addChild(node=data)
コード例 #28
0
ファイル: omemoplugin.py プロジェクト: Ape/gajim-plugins
    def handle_outgoing_stanza(self, event):
        """ Manipulates the outgoing stanza

            The body is getting encrypted

            Parameters
            ----------
            event : StanzaMessageOutgoingEvent

            Returns
            -------
            Return if encryption is not activated or any other
            exception or error occurs
        """
        account = event.conn.name
        if account in self.disabled_accounts:
            return
        try:
            if not event.msg_iq.getTag('body'):
                return

            state = self.get_omemo_state(account)
            full_jid = str(event.msg_iq.getAttr('to'))
            to_jid = gajim.get_jid_without_resource(full_jid)
            if not state.encryption.is_active(to_jid):
                return

            # Delete previous Message out of Correction Message Stanza
            if event.msg_iq.getTag('replace', namespace=NS_CORRECT):
                event.msg_iq.delChild('encrypted', attrs={'xmlns': NS_OMEMO})

            plaintext = event.msg_iq.getBody().encode('utf8')

            msg_dict = state.create_msg(
                gajim.get_jid_from_account(account), to_jid, plaintext)
            if not msg_dict:
                return True

            encrypted_node = OmemoMessage(msg_dict)

            # Check if non-OMEMO resource is online
            contacts = gajim.contacts.get_contacts(account, to_jid)
            non_omemo_resource_online = False
            for contact in contacts:
                if contact.show == 'offline':
                    continue
                if not contact.supports(NS_NOTIFY):
                    log.debug(contact.get_full_jid() +
                              ' => Contact doesnt support OMEMO, '
                              'adding Info Message to Body')
                    support_msg = 'You received a message encrypted with ' \
                                  'OMEMO but your client doesnt support OMEMO.'
                    event.msg_iq.setBody(support_msg)
                    non_omemo_resource_online = True
            if not non_omemo_resource_online:
                event.msg_iq.delChild('body')

            event.msg_iq.addChild(node=encrypted_node)

            # XEP-xxxx: Explicit Message Encryption
            if not event.msg_iq.getTag('encrypted', attrs={'xmlns': NS_EME}):
                eme_node = Node('encrypted', attrs={'xmlns': NS_EME,
                                                    'name': 'OMEMO',
                                                    'namespace': NS_OMEMO})
                event.msg_iq.addChild(node=eme_node)

            # Store Hint for MAM
            store = Node('store', attrs={'xmlns': NS_HINTS})
            event.msg_iq.addChild(node=store)
            self.print_msg_to_log(event.msg_iq)
        except Exception as e:
            log.debug(e)
            return True
コード例 #29
0
 def to_node(self):
     node = Node(self.name)
     if self.parameters:
         node.addChild(node=make_parameters(self.parameters))
     node.addChild('language-tag', payload=self.value)
     return node
コード例 #30
0
ファイル: xmpp.py プロジェクト: Ape/gajim-plugins
 def __init__(self, node_str, data):
     assert node_str is not None and isinstance(data, Node)
     Node.__init__(self, tag='publish', attrs={'node': node_str})
     self.addChild('item').addChild(node=data)
コード例 #31
0
 def _send_ack(self, *args):
     ack = Node(Namespace.STREAM_MGMT + ' a', attrs={'h': self._in_h})
     self._acked_h = self._in_h
     self._log.debug('Send ack, h: %s', self._in_h)
     self._client.send_nonza(ack, now=False)
コード例 #32
0
 def _request_ack(self):
     request = Node(Namespace.STREAM_MGMT + ' r')
     self._log.debug('Request ack')
     self._client.send_nonza(request, now=False)
コード例 #33
0
ファイル: xmpp.py プロジェクト: amenk/gajim-omemo
 def __init__(self, data):
     assert isinstance(data, Node)
     Node.__init__(self, tag='pubsub', attrs={'xmlns': NS_PUBSUB})
     self.addChild(node=data)
コード例 #34
0
 def to_node(self):
     node = Node(self.name)
     if self.parameters:
         node.addChild(node=make_parameters(self.parameters))
     add_children(node, 'text', self.values)
     return node
コード例 #35
0
ファイル: xmpp.py プロジェクト: akallabeth/gajim-omemo
 def __init__(self, data):
     assert data is Node
     Node.__init__(self, tag='pubsub', attrs={'xmlns': NS_PUBSUB})
     self.addChild(node=data)
コード例 #36
0
ファイル: xmpp.py プロジェクト: akallabeth/gajim-omemo
 def __init__(self, node_str, data):
     assert node_str is not None and data is Node
     Node.__init__(self, tag='publish', attrs={'node': node_str})
     self.addChild('item').addChild(node=data)
コード例 #37
0
 def to_node(self):
     node = Node(self.name)
     if self.parameters:
         node.addChild(node=make_parameters(self.parameters))
     node.addChild('timestamp', payload=self.value)
     return node