Search in sources :

Example 6 with S5BTransportInfo

use of eu.siacs.conversations.xmpp.jingle.stanzas.S5BTransportInfo 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 7 with S5BTransportInfo

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

the class JingleFileTransferConnection method sendCandidateUsed.

private void sendCandidateUsed(final String cid) {
    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("candidate-used").setAttribute("cid", cid)));
    packet.addJingleContent(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) Element(eu.siacs.conversations.xml.Element) S5BTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.S5BTransportInfo)

Example 8 with S5BTransportInfo

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

the class JingleFileTransferConnection method sendAcceptSocks.

private void sendAcceptSocks() {
    gatherAndConnectDirectCandidates();
    this.jingleConnectionManager.getPrimaryCandidate(this.id.account, isInitiator(), (success, candidate) -> {
        final JinglePacket packet = bootstrapPacket(JinglePacket.Action.SESSION_ACCEPT);
        final Content content = new Content(contentCreator, contentName);
        content.setSenders(this.contentSenders);
        content.setDescription(this.description);
        if (success && candidate != null && !equalCandidateExists(candidate)) {
            final JingleSocks5Transport socksConnection = new JingleSocks5Transport(this, candidate);
            connections.put(candidate.getCid(), socksConnection);
            socksConnection.connect(new OnTransportConnected() {

                @Override
                public void failed() {
                    Log.d(Config.LOGTAG, "connection to our own proxy65 candidate failed");
                    content.setTransport(new S5BTransportInfo(transportId, getOurCandidates()));
                    packet.addJingleContent(content);
                    sendJinglePacket(packet);
                    connectNextCandidate();
                }

                @Override
                public void established() {
                    Log.d(Config.LOGTAG, "connected to proxy65 candidate");
                    mergeCandidate(candidate);
                    content.setTransport(new S5BTransportInfo(transportId, getOurCandidates()));
                    packet.addJingleContent(content);
                    sendJinglePacket(packet);
                    connectNextCandidate();
                }
            });
        } else {
            Log.d(Config.LOGTAG, "did not find a proxy65 candidate for ourselves");
            content.setTransport(new S5BTransportInfo(transportId, getOurCandidates()));
            packet.addJingleContent(content);
            sendJinglePacket(packet);
            connectNextCandidate();
        }
    });
}
Also used : JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content) S5BTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.S5BTransportInfo)

Example 9 with S5BTransportInfo

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

the class JingleFileTransferConnection method sendCandidateError.

private void sendCandidateError() {
    Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": sending candidate error");
    JinglePacket packet = bootstrapPacket(JinglePacket.Action.TRANSPORT_INFO);
    Content content = new Content(this.contentCreator, this.contentName);
    content.setSenders(this.contentSenders);
    content.setTransport(new S5BTransportInfo(this.transportId, new Element("candidate-error")));
    packet.addJingleContent(content);
    this.sentCandidate = true;
    this.sendJinglePacket(packet);
    if (receivedCandidate && mJingleStatus == JINGLE_STATUS_ACCEPTED) {
        connect();
    }
}
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)

Aggregations

Content (eu.siacs.conversations.xmpp.jingle.stanzas.Content)9 S5BTransportInfo (eu.siacs.conversations.xmpp.jingle.stanzas.S5BTransportInfo)9 Element (eu.siacs.conversations.xml.Element)6 JinglePacket (eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)6 GenericTransportInfo (eu.siacs.conversations.xmpp.jingle.stanzas.GenericTransportInfo)3 IbbTransportInfo (eu.siacs.conversations.xmpp.jingle.stanzas.IbbTransportInfo)3 FileNotFoundException (java.io.FileNotFoundException)2 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)1 Conversation (eu.siacs.conversations.entities.Conversation)1 Message (eu.siacs.conversations.entities.Message)1 AbstractConnectionManager (eu.siacs.conversations.services.AbstractConnectionManager)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1