Search in sources :

Example 6 with Content

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

the class JingleConnection method init.

public void init(Account account, JinglePacket packet) {
    this.mJingleStatus = JINGLE_STATUS_INITIATED;
    Conversation conversation = this.mXmppConnectionService.findOrCreateConversation(account, packet.getFrom().toBareJid(), false);
    this.message = new Message(conversation, "", Message.ENCRYPTION_NONE);
    this.message.setStatus(Message.STATUS_RECEIVED);
    this.mStatus = Transferable.STATUS_OFFER;
    this.message.setTransferable(this);
    final Jid from = packet.getFrom();
    this.message.setCounterpart(from);
    this.account = account;
    this.initiator = packet.getFrom();
    this.responder = this.account.getJid();
    this.sessionId = packet.getSessionId();
    Content content = packet.getJingleContent();
    this.contentCreator = content.getAttribute("creator");
    this.contentName = content.getAttribute("name");
    this.transportId = content.getTransportId();
    this.mergeCandidates(JingleCandidate.parse(content.socks5transport().getChildren()));
    this.ftVersion = content.getVersion();
    if (ftVersion == null) {
        this.sendCancel();
        this.fail();
        return;
    }
    this.fileOffer = content.getFileOffer(this.ftVersion);
    mXmppConnectionService.sendIqPacket(account, packet.generateResponse(IqPacket.TYPE.RESULT), null);
    if (fileOffer != null) {
        Element encrypted = fileOffer.findChild("encrypted", AxolotlService.PEP_PREFIX);
        if (encrypted != null) {
            this.mXmppAxolotlMessage = XmppAxolotlMessage.fromElement(encrypted, packet.getFrom().toBareJid());
        }
        Element fileSize = fileOffer.findChild("size");
        Element fileNameElement = fileOffer.findChild("name");
        if (fileNameElement != null) {
            String[] filename = fileNameElement.getContent().toLowerCase(Locale.US).toLowerCase().split("\\.");
            String extension = filename[filename.length - 1];
            if (VALID_IMAGE_EXTENSIONS.contains(extension)) {
                message.setType(Message.TYPE_IMAGE);
                message.setRelativeFilePath(message.getUuid() + "." + extension);
            } else if (VALID_CRYPTO_EXTENSIONS.contains(filename[filename.length - 1])) {
                if (filename.length == 3) {
                    extension = filename[filename.length - 2];
                    if (VALID_IMAGE_EXTENSIONS.contains(extension)) {
                        message.setType(Message.TYPE_IMAGE);
                        message.setRelativeFilePath(message.getUuid() + "." + extension);
                    } else {
                        message.setType(Message.TYPE_FILE);
                    }
                    if (filename[filename.length - 1].equals("otr")) {
                        message.setEncryption(Message.ENCRYPTION_OTR);
                    } else {
                        message.setEncryption(Message.ENCRYPTION_PGP);
                    }
                }
            } else {
                message.setType(Message.TYPE_FILE);
            }
            if (message.getType() == Message.TYPE_FILE) {
                String suffix = "";
                if (!fileNameElement.getContent().isEmpty()) {
                    String[] parts = fileNameElement.getContent().split("/");
                    suffix = parts[parts.length - 1];
                    if (message.getEncryption() == Message.ENCRYPTION_OTR && suffix.endsWith(".otr")) {
                        suffix = suffix.substring(0, suffix.length() - 4);
                    } else if (message.getEncryption() == Message.ENCRYPTION_PGP && (suffix.endsWith(".pgp") || suffix.endsWith(".gpg"))) {
                        suffix = suffix.substring(0, suffix.length() - 4);
                    }
                }
                message.setRelativeFilePath(message.getUuid() + "_" + suffix);
            }
            long size = Long.parseLong(fileSize.getContent());
            message.setBody(Long.toString(size));
            conversation.add(message);
            mJingleConnectionManager.updateConversationUi(true);
            if (mJingleConnectionManager.hasStoragePermission() && size < this.mJingleConnectionManager.getAutoAcceptFileSize() && mXmppConnectionService.isDataSaverDisabled()) {
                Log.d(Config.LOGTAG, "auto accepting file from " + packet.getFrom());
                this.acceptedAutomatically = true;
                this.sendAccept();
            } else {
                message.markUnread();
                Log.d(Config.LOGTAG, "not auto accepting new file offer with size: " + size + " allowed size:" + this.mJingleConnectionManager.getAutoAcceptFileSize());
                this.mXmppConnectionService.getNotificationService().push(message);
            }
            this.file = this.mXmppConnectionService.getFileBackend().getFile(message, false);
            if (mXmppAxolotlMessage != null) {
                XmppAxolotlMessage.XmppAxolotlKeyTransportMessage transportMessage = account.getAxolotlService().processReceivingKeyTransportMessage(mXmppAxolotlMessage);
                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");
                }
            } else if (message.getEncryption() == Message.ENCRYPTION_OTR) {
                byte[] key = conversation.getSymmetricKey();
                if (key == null) {
                    this.sendCancel();
                    this.fail();
                    return;
                } else {
                    this.file.setKeyAndIv(key);
                }
            }
            this.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file, message.getEncryption() == Message.ENCRYPTION_AXOLOTL);
            if (message.getEncryption() == Message.ENCRYPTION_OTR && Config.REPORT_WRONG_FILESIZE_IN_OTR_JINGLE) {
                this.file.setExpectedSize((size / 16 + 1) * 16);
            } else {
                this.file.setExpectedSize(size);
            }
            Log.d(Config.LOGTAG, "receiving file: expecting size of " + this.file.getExpectedSize());
        } else {
            this.sendCancel();
            this.fail();
        }
    } else {
        this.sendCancel();
        this.fail();
    }
}
Also used : XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) Jid(eu.siacs.conversations.xmpp.jid.Jid) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content) Element(eu.siacs.conversations.xml.Element) Conversation(eu.siacs.conversations.entities.Conversation) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)

Example 7 with Content

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

the class JingleConnection method sendInitRequest.

private void sendInitRequest() {
    JinglePacket packet = this.bootstrapPacket("session-initiate");
    Content content = new Content(this.contentCreator, this.contentName);
    if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) {
        content.setTransportId(this.transportId);
        this.file = this.mXmppConnectionService.getFileBackend().getFile(message, false);
        Pair<InputStream, Integer> pair;
        try {
            if (message.getEncryption() == Message.ENCRYPTION_OTR) {
                Conversation conversation = this.message.getConversation();
                if (!this.mXmppConnectionService.renewSymmetricKey(conversation)) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not set symmetric key");
                    cancel();
                }
                this.file.setKeyAndIv(conversation.getSymmetricKey());
                pair = AbstractConnectionManager.createInputStream(this.file, false);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, true, this.ftVersion);
            } else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
                this.file.setKey(mXmppAxolotlMessage.getInnerKey());
                this.file.setIv(mXmppAxolotlMessage.getIV());
                pair = AbstractConnectionManager.createInputStream(this.file, true);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, false, this.ftVersion).addChild(mXmppAxolotlMessage.toElement());
            } else {
                pair = AbstractConnectionManager.createInputStream(this.file, false);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, false, this.ftVersion);
            }
        } catch (FileNotFoundException e) {
            cancel();
            return;
        }
        this.mFileInputStream = pair.first;
        content.setTransportId(this.transportId);
        content.socks5transport().setChildren(getCandidatesAsElements());
        packet.setContent(content);
        this.sendJinglePacket(packet, new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(Account account, IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": other party received offer");
                    mJingleStatus = JINGLE_STATUS_INITIATED;
                    mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED);
                } else {
                    fail(IqParser.extractErrorMessage(packet));
                }
            }
        });
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Conversation(eu.siacs.conversations.entities.Conversation) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 8 with Content

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

the class JingleConnection method sendCandidateUsed.

private void sendCandidateUsed(final String cid) {
    JinglePacket packet = bootstrapPacket("transport-info");
    Content content = new Content(this.contentCreator, this.contentName);
    content.setTransportId(this.transportId);
    content.socks5transport().addChild("candidate-used").setAttribute("cid", cid);
    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 9 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 10 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)

Aggregations

Content (eu.siacs.conversations.xmpp.jingle.stanzas.Content)10 JinglePacket (eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)7 Account (eu.siacs.conversations.entities.Account)2 Conversation (eu.siacs.conversations.entities.Conversation)2 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)2 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)2 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)1 Message (eu.siacs.conversations.entities.Message)1 Element (eu.siacs.conversations.xml.Element)1 Jid (eu.siacs.conversations.xmpp.jid.Jid)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1