Search in sources :

Example 96 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class IqGenerator method discoResponse.

public IqPacket discoResponse(final IqPacket request) {
    final IqPacket packet = new IqPacket(IqPacket.TYPE.RESULT);
    packet.setId(request.getId());
    packet.setTo(request.getFrom());
    final Element query = packet.addChild("query", "http://jabber.org/protocol/disco#info");
    query.setAttribute("node", request.query().getAttribute("node"));
    final Element identity = query.addChild("identity");
    identity.setAttribute("category", "client");
    identity.setAttribute("type", getIdentityType());
    identity.setAttribute("name", getIdentityName());
    for (final String feature : getFeatures()) {
        query.addChild("feature").setAttribute("var", feature);
    }
    return packet;
}
Also used : Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 97 with Element

use of eu.siacs.conversations.xml.Element 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 98 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class JingleInbandTransport method connect.

public void connect(final OnTransportConnected callback) {
    IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
    iq.setTo(this.counterpart);
    Element open = iq.addChild("open", "http://jabber.org/protocol/ibb");
    open.setAttribute("sid", this.sessionId);
    open.setAttribute("stanza", "iq");
    open.setAttribute("block-size", Integer.toString(this.blockSize));
    this.connected = true;
    this.account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() != IqPacket.TYPE.RESULT) {
                callback.failed();
            } else {
                callback.established();
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 99 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class JinglePacket method addChild.

@Override
public Element addChild(Element child) {
    if ("jingle".equals(child.getName())) {
        Element contentElement = child.findChild("content");
        if (contentElement != null) {
            this.content = new Content();
            this.content.setChildren(contentElement.getChildren());
            this.content.setAttributes(contentElement.getAttributes());
        }
        Element reasonElement = child.findChild("reason");
        if (reasonElement != null) {
            this.reason = new Reason();
            this.reason.setChildren(reasonElement.getChildren());
            this.reason.setAttributes(reasonElement.getAttributes());
        }
        this.jingle.setAttributes(child.getAttributes());
    }
    return child;
}
Also used : Element(eu.siacs.conversations.xml.Element)

Example 100 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class XmppAxolotlMessage method toElement.

public Element toElement() {
    Element encryptionElement = new Element(CONTAINERTAG, AxolotlService.PEP_PREFIX);
    Element headerElement = encryptionElement.addChild(HEADER);
    headerElement.setAttribute(SOURCEID, sourceDeviceId);
    for (XmppAxolotlSession.AxolotlKey key : keys) {
        Element keyElement = new Element(KEYTAG);
        keyElement.setAttribute(REMOTEID, key.deviceId);
        if (key.prekey) {
            keyElement.setAttribute("prekey", "true");
        }
        keyElement.setContent(Base64.encodeToString(key.key, Base64.NO_WRAP));
        headerElement.addChild(keyElement);
    }
    headerElement.addChild(IVTAG).setContent(Base64.encodeToString(iv, Base64.NO_WRAP));
    if (ciphertext != null) {
        Element payload = encryptionElement.addChild(PAYLOAD);
        payload.setContent(Base64.encodeToString(ciphertext, Base64.NO_WRAP));
    }
    return encryptionElement;
}
Also used : Element(eu.siacs.conversations.xml.Element)

Aggregations

Element (eu.siacs.conversations.xml.Element)166 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)72 Jid (eu.siacs.conversations.xmpp.Jid)24 Account (eu.siacs.conversations.entities.Account)21 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)17 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)15 Contact (eu.siacs.conversations.entities.Contact)13 InvalidJid (eu.siacs.conversations.xmpp.InvalidJid)11 Conversation (eu.siacs.conversations.entities.Conversation)10 Data (eu.siacs.conversations.xmpp.forms.Data)9 ArrayList (java.util.ArrayList)9 Content (eu.siacs.conversations.xmpp.jingle.stanzas.Content)8 JinglePacket (eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)8 Bookmark (eu.siacs.conversations.entities.Bookmark)6 S5BTransportInfo (eu.siacs.conversations.xmpp.jingle.stanzas.S5BTransportInfo)6 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)6 IOException (java.io.IOException)6 JabberIdContact (eu.siacs.conversations.android.JabberIdContact)5 Message (eu.siacs.conversations.entities.Message)5 HashSet (java.util.HashSet)5