Ejemplo n.º 1
0
    def send_file_approval(self, file_props):
        """
        Send iq, confirming that we want to download the file
        """
        # user response to ConfirmationDialog may come after we've disconneted
        if not self.connection or self.connected < 2:
            return

        # file transfer initiated by a jingle session
        log.info("send_file_approval: jingle session accept")
        if file_props.session_type == 'jingle':
            session = self.get_jingle_session(file_props.sender,
                                              file_props.sid)
            if not session:
                return
            content = None
            for c in session.contents.values():
                if c.transport.sid == file_props.transport_sid:
                    content = c
                    break
            if not content:
                return
            if not session.accepted:
                content = session.get_content('file', content.name)
                if content.use_security:
                    fingerprint = content.x509_fingerprint
                    if not jingle_xtls.check_cert(
                            app.get_jid_without_resource(file_props.sender),
                            fingerprint):
                        id_ = jingle_xtls.send_cert_request(
                            self, file_props.sender)
                        jingle_xtls.key_exchange_pend(id_,
                                                      content.on_cert_received,
                                                      [])
                        return
                session.approve_session()

            session.approve_content('file', content.name)
            return

        iq = nbxmpp.Iq(to=file_props.sender, typ='result')
        iq.setAttr('id', file_props.request_id)
        si = iq.setTag('si', namespace=nbxmpp.NS_SI)
        if file_props.offset:
            file_tag = si.setTag('file', namespace=nbxmpp.NS_FILE)
            range_tag = file_tag.setTag('range')
            range_tag.setAttr('offset', file_props.offset)
        feature = si.setTag('feature', namespace=nbxmpp.NS_FEATURE)
        _feature = nbxmpp.DataForm(typ='submit')
        feature.addChild(node=_feature)
        field = _feature.setField('stream-method')
        field.delAttr('type')
        if nbxmpp.NS_BYTESTREAM in file_props.stream_methods:
            field.setValue(nbxmpp.NS_BYTESTREAM)
        else:
            file_props.transport_sid = file_props.sid
            field.setValue(nbxmpp.NS_IBB)
        self.connection.send(iq)
Ejemplo n.º 2
0
 def __on_session_accept(self, stanza, content, error, action):
     log.info("__on_session_accept")
     con = self.session.connection
     security = content.getTag('security')
     if not security: # responder can not verify our fingerprint
         self.use_security = False
     else:
         fingerprint = security.getTag('fingerprint')
         if fingerprint:
             fingerprint = fingerprint.getData()
             self.x509_fingerprint = fingerprint
             if not jingle_xtls.check_cert(app.get_jid_without_resource(
                     self.session.responder), fingerprint):
                 id_ = jingle_xtls.send_cert_request(con,
                                                     self.session.responder)
                 jingle_xtls.key_exchange_pend(id_,
                                               self.continue_session_accept,
                                               [stanza])
                 raise nbxmpp.NodeProcessed
     self.continue_session_accept(stanza)
Ejemplo n.º 3
0
    def send_file_approval(self, file_props):
        """
        Send iq, confirming that we want to download the file
        """
        # user response to ConfirmationDialog may come after we've disconneted
        if not app.account_is_connected(self._account):
            return

        # file transfer initiated by a jingle session
        log.info("send_file_approval: jingle session accept")

        session = self._con.get_module('Jingle').get_jingle_session(
            file_props.sender, file_props.sid)
        if not session:
            return
        content = None
        for content_ in session.contents.values():
            if content_.transport.sid == file_props.transport_sid:
                content = content_
                break

        if not content:
            return

        if not session.accepted:
            content = session.get_content('file', content.name)
            if content.use_security:
                fingerprint = content.x509_fingerprint
                if not jingle_xtls.check_cert(
                        app.get_jid_without_resource(file_props.sender),
                        fingerprint):
                    id_ = jingle_xtls.send_cert_request(
                        self._con, file_props.sender)
                    jingle_xtls.key_exchange_pend(id_,
                                                  content.on_cert_received, [])
                    return
            session.approve_session()

        session.approve_content('file', content.name)