Search in sources :

Example 16 with Content

use of eu.siacs.conversations.xmpp.jingle.stanzas.Content in project Conversations by siacs.

the class JingleConnection method sendCandidateError.

private void sendCandidateError() {
    JinglePacket packet = bootstrapPacket("transport-info");
    Content content = new Content(this.contentCreator, this.contentName);
    content.setTransportId(this.transportId);
    content.socks5transport().addChild("candidate-error");
    packet.setContent(content);
    this.sentCandidate = true;
    if ((receivedCandidate) && (mJingleStatus == JINGLE_STATUS_ACCEPTED)) {
        connect();
    }
    this.sendJinglePacket(packet);
}
Also used : JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content)

Example 17 with Content

use of eu.siacs.conversations.xmpp.jingle.stanzas.Content in project Conversations by siacs.

the class JingleConnection method sendFallbackToIbb.

private void sendFallbackToIbb() {
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending fallback to ibb");
    JinglePacket packet = this.bootstrapPacket("transport-replace");
    Content content = new Content(this.contentCreator, this.contentName);
    this.transportId = this.mJingleConnectionManager.nextRandomId();
    content.setTransportId(this.transportId);
    content.ibbTransport().setAttribute("block-size", Integer.toString(this.ibbBlockSize));
    packet.setContent(content);
    this.sendJinglePacket(packet);
}
Also used : JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content)

Example 18 with Content

use of eu.siacs.conversations.xmpp.jingle.stanzas.Content in project Conversations by siacs.

the class JingleFileTransferConnection method sendProxyActivated.

private void sendProxyActivated(String cid) {
    final JinglePacket packet = bootstrapPacket(JinglePacket.Action.TRANSPORT_INFO);
    final Content content = new Content(this.contentCreator, this.contentName);
    content.setSenders(this.contentSenders);
    content.setTransport(new S5BTransportInfo(this.transportId, new Element("activated").setAttribute("cid", cid)));
    packet.addJingleContent(content);
    this.sendJinglePacket(packet);
}
Also used : JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content) Element(eu.siacs.conversations.xml.Element) S5BTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.S5BTransportInfo)

Example 19 with Content

use of eu.siacs.conversations.xmpp.jingle.stanzas.Content in project Conversations by siacs.

the class JingleFileTransferConnection method init.

private void init(JinglePacket packet) {
    // should move to deliverPacket
    // TODO if not 'OFFERED' reply with out-of-order
    this.mJingleStatus = JINGLE_STATUS_INITIATED;
    final Conversation conversation = this.xmppConnectionService.findOrCreateConversation(id.account, id.with.asBareJid(), false, false);
    this.message = new Message(conversation, "", Message.ENCRYPTION_NONE);
    this.message.setStatus(Message.STATUS_RECEIVED);
    this.mStatus = Transferable.STATUS_OFFER;
    this.message.setTransferable(this);
    this.message.setCounterpart(this.id.with);
    this.responder = this.id.account.getJid();
    final Content content = packet.getJingleContent();
    final GenericTransportInfo transportInfo = content.getTransport();
    this.contentCreator = content.getCreator();
    Content.Senders senders;
    try {
        senders = content.getSenders();
    } catch (final Exception e) {
        senders = Content.Senders.INITIATOR;
    }
    this.contentSenders = senders;
    this.contentName = content.getAttribute("name");
    if (transportInfo instanceof S5BTransportInfo) {
        final S5BTransportInfo s5BTransportInfo = (S5BTransportInfo) transportInfo;
        this.transportId = s5BTransportInfo.getTransportId();
        this.initialTransport = s5BTransportInfo.getClass();
        this.mergeCandidates(s5BTransportInfo.getCandidates());
    } else if (transportInfo instanceof IbbTransportInfo) {
        final IbbTransportInfo ibbTransportInfo = (IbbTransportInfo) transportInfo;
        this.initialTransport = ibbTransportInfo.getClass();
        this.transportId = ibbTransportInfo.getTransportId();
        final int remoteBlockSize = ibbTransportInfo.getBlockSize();
        if (remoteBlockSize <= 0) {
            Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": remote party requested invalid ibb block size");
            respondToIq(packet, false);
            this.fail();
        }
        this.ibbBlockSize = Math.min(MAX_IBB_BLOCK_SIZE, ibbTransportInfo.getBlockSize());
    } else {
        Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": remote tried to use unknown transport " + transportInfo.getNamespace());
        respondToIq(packet, false);
        this.fail();
        return;
    }
    this.description = (FileTransferDescription) content.getDescription();
    final Element fileOffer = this.description.getFileOffer();
    if (fileOffer != null) {
        boolean remoteIsUsingJet = false;
        Element encrypted = fileOffer.findChild("encrypted", AxolotlService.PEP_PREFIX);
        if (encrypted == null) {
            final Element security = content.findChild("security", Namespace.JINGLE_ENCRYPTED_TRANSPORT);
            if (security != null && AxolotlService.PEP_PREFIX.equals(security.getAttribute("type"))) {
                Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": received jingle file offer with JET");
                encrypted = security.findChild("encrypted", AxolotlService.PEP_PREFIX);
                remoteIsUsingJet = true;
            }
        }
        if (encrypted != null) {
            this.mXmppAxolotlMessage = XmppAxolotlMessage.fromElement(encrypted, packet.getFrom().asBareJid());
        }
        Element fileSize = fileOffer.findChild("size");
        final String path = fileOffer.findChildContent("name");
        if (path != null) {
            AbstractConnectionManager.Extension extension = AbstractConnectionManager.Extension.of(path);
            if (VALID_IMAGE_EXTENSIONS.contains(extension.main)) {
                message.setType(Message.TYPE_IMAGE);
                message.setRelativeFilePath(message.getUuid() + "." + extension.main);
            } else if (VALID_CRYPTO_EXTENSIONS.contains(extension.main)) {
                if (VALID_IMAGE_EXTENSIONS.contains(extension.secondary)) {
                    message.setType(Message.TYPE_IMAGE);
                    message.setRelativeFilePath(message.getUuid() + "." + extension.secondary);
                } else {
                    message.setType(Message.TYPE_FILE);
                    message.setRelativeFilePath(message.getUuid() + (extension.secondary != null ? ("." + extension.secondary) : ""));
                }
                message.setEncryption(Message.ENCRYPTION_PGP);
            } else {
                message.setType(Message.TYPE_FILE);
                message.setRelativeFilePath(message.getUuid() + (extension.main != null ? ("." + extension.main) : ""));
            }
            long size = parseLong(fileSize, 0);
            message.setBody(Long.toString(size));
            conversation.add(message);
            jingleConnectionManager.updateConversationUi(true);
            this.file = this.xmppConnectionService.getFileBackend().getFile(message, false);
            if (mXmppAxolotlMessage != null) {
                XmppAxolotlMessage.XmppAxolotlKeyTransportMessage transportMessage = id.account.getAxolotlService().processReceivingKeyTransportMessage(mXmppAxolotlMessage, false);
                if (transportMessage != null) {
                    message.setEncryption(Message.ENCRYPTION_AXOLOTL);
                    this.file.setKey(transportMessage.getKey());
                    this.file.setIv(transportMessage.getIv());
                    message.setFingerprint(transportMessage.getFingerprint());
                } else {
                    Log.d(Config.LOGTAG, "could not process KeyTransportMessage");
                }
            }
            message.resetFileParams();
            // legacy OMEMO encrypted file transfers reported the file size after encryption
            // JET reports the plain text size. however lower levels of our receiving code still
            // expect the cipher text size. so we just + 16 bytes (auth tag size) here
            this.file.setExpectedSize(size + (remoteIsUsingJet ? 16 : 0));
            respondToIq(packet, true);
            if (id.account.getRoster().getContact(id.with).showInContactList() && jingleConnectionManager.hasStoragePermission() && size < this.jingleConnectionManager.getAutoAcceptFileSize() && xmppConnectionService.isDataSaverDisabled()) {
                Log.d(Config.LOGTAG, "auto accepting file from " + id.with);
                this.acceptedAutomatically = true;
                this.sendAccept();
            } else {
                message.markUnread();
                Log.d(Config.LOGTAG, "not auto accepting new file offer with size: " + size + " allowed size:" + this.jingleConnectionManager.getAutoAcceptFileSize());
                this.xmppConnectionService.getNotificationService().push(message);
            }
            Log.d(Config.LOGTAG, "receiving file: expecting size of " + this.file.getExpectedSize());
            return;
        }
        respondToIq(packet, false);
    }
}
Also used : XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) Element(eu.siacs.conversations.xml.Element) Conversation(eu.siacs.conversations.entities.Conversation) AbstractConnectionManager(eu.siacs.conversations.services.AbstractConnectionManager) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) S5BTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.S5BTransportInfo) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content) GenericTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.GenericTransportInfo) IbbTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.IbbTransportInfo)

Example 20 with Content

use of eu.siacs.conversations.xmpp.jingle.stanzas.Content in project Conversations by siacs.

the class JingleFileTransferConnection method receiveFallbackToIbb.

private void receiveFallbackToIbb(final JinglePacket packet, final IbbTransportInfo transportInfo) {
    if (isInitiator()) {
        Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": received out of order transport-replace (we were initiating)");
        respondToIqWithOutOfOrder(packet);
        return;
    }
    final boolean validState = mJingleStatus == JINGLE_STATUS_ACCEPTED || (proxyActivationFailed && mJingleStatus == JINGLE_STATUS_TRANSMITTING);
    if (!validState) {
        Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": received out of order transport-replace");
        respondToIqWithOutOfOrder(packet);
        return;
    }
    // fallback received; now we no longer need to accept another one;
    this.proxyActivationFailed = false;
    Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": receiving fallback to ibb");
    final int remoteBlockSize = transportInfo.getBlockSize();
    if (remoteBlockSize > 0) {
        this.ibbBlockSize = Math.min(MAX_IBB_BLOCK_SIZE, remoteBlockSize);
    } else {
        Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": unable to parse block size in transport-replace");
    }
    // TODO: handle the case where this is null by the remote party
    this.transportId = transportInfo.getTransportId();
    this.transport = new JingleInBandTransport(this, this.transportId, this.ibbBlockSize);
    final JinglePacket answer = bootstrapPacket(JinglePacket.Action.TRANSPORT_ACCEPT);
    final Content content = new Content(contentCreator, contentName);
    content.setSenders(this.contentSenders);
    content.setTransport(new IbbTransportInfo(this.transportId, this.ibbBlockSize));
    answer.addJingleContent(content);
    respondToIq(packet, true);
    if (isInitiator()) {
        this.sendJinglePacket(answer, (account, response) -> {
            if (response.getType() == IqPacket.TYPE.RESULT) {
                Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + " recipient ACKed our transport-accept. creating ibb");
                transport.connect(onIbbTransportConnected);
            }
        });
    } else {
        this.transport.receive(file, onFileTransmissionStatusChanged);
        this.sendJinglePacket(answer);
    }
}
Also used : JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content) IbbTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.IbbTransportInfo)

Aggregations

Content (eu.siacs.conversations.xmpp.jingle.stanzas.Content)25 JinglePacket (eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)18 S5BTransportInfo (eu.siacs.conversations.xmpp.jingle.stanzas.S5BTransportInfo)9 Element (eu.siacs.conversations.xml.Element)7 IbbTransportInfo (eu.siacs.conversations.xmpp.jingle.stanzas.IbbTransportInfo)7 GenericTransportInfo (eu.siacs.conversations.xmpp.jingle.stanzas.GenericTransportInfo)4 Conversation (eu.siacs.conversations.entities.Conversation)3 FileNotFoundException (java.io.FileNotFoundException)3 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)2 Account (eu.siacs.conversations.entities.Account)2 Message (eu.siacs.conversations.entities.Message)2 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)2 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 AbstractConnectionManager (eu.siacs.conversations.services.AbstractConnectionManager)1 Jid (eu.siacs.conversations.xmpp.Jid)1 Jid (eu.siacs.conversations.xmpp.jid.Jid)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1