Search in sources :

Example 81 with Element

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

the class IqGenerator method generateSetUnblockRequest.

public IqPacket generateSetUnblockRequest(final Jid jid) {
    final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
    final Element block = iq.addChild("unblock", Namespace.BLOCKING);
    block.addChild("item").setAttribute("jid", jid.toBareJid().toString());
    return iq;
}
Also used : Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 82 with Element

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

the class IqGenerator method enablePush.

public IqPacket enablePush(Jid jid, String node, String secret) {
    IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
    Element enable = packet.addChild("enable", "urn:xmpp:push:0");
    enable.setAttribute("jid", jid.toString());
    enable.setAttribute("node", node);
    Data data = new Data();
    data.setFormType("http://jabber.org/protocol/pubsub#publish-options");
    data.put("secret", secret);
    data.submit();
    enable.addChild(data);
    return packet;
}
Also used : Element(eu.siacs.conversations.xml.Element) Data(eu.siacs.conversations.xmpp.forms.Data) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 83 with Element

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

the class IqGenerator method generateSetPassword.

public IqPacket generateSetPassword(final Account account, final String newPassword) {
    final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
    packet.setTo(account.getServer());
    final Element query = packet.addChild("query", Namespace.REGISTER);
    final Jid jid = account.getJid();
    query.addChild("username").setContent(jid.getLocalpart());
    query.addChild("password").setContent(newPassword);
    return packet;
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 84 with Element

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

the class XmppConnection method processPacket.

private Element processPacket(final Tag currentTag, final int packetType) throws XmlPullParserException, IOException {
    Element element;
    switch(packetType) {
        case PACKET_IQ:
            element = new IqPacket();
            break;
        case PACKET_MESSAGE:
            element = new MessagePacket();
            break;
        case PACKET_PRESENCE:
            element = new PresencePacket();
            break;
        default:
            return null;
    }
    element.setAttributes(currentTag.getAttributes());
    Tag nextTag = tagReader.readTag();
    if (nextTag == null) {
        throw new IOException("interrupted mid tag");
    }
    while (!nextTag.isEnd(element.getName())) {
        if (!nextTag.isNo()) {
            final Element child = tagReader.readElement(nextTag);
            final String type = currentTag.getAttribute("type");
            if (packetType == PACKET_IQ && "jingle".equals(child.getName()) && ("set".equalsIgnoreCase(type) || "get".equalsIgnoreCase(type))) {
                element = new JinglePacket();
                element.setAttributes(currentTag.getAttributes());
            }
            element.addChild(child);
        }
        nextTag = tagReader.readTag();
        if (nextTag == null) {
            throw new IOException("interrupted mid tag");
        }
    }
    if (stanzasReceived == Integer.MAX_VALUE) {
        resetStreamId();
        throw new IOException("time to restart the session. cant handle >2 billion pcks");
    }
    ++stanzasReceived;
    lastPacketReceived = SystemClock.elapsedRealtime();
    if (Config.BACKGROUND_STANZA_LOGGING && mXmppConnectionService.checkListeners()) {
        Log.d(Config.LOGTAG, "[background stanza] " + element);
    }
    return element;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) Element(eu.siacs.conversations.xml.Element) Tag(eu.siacs.conversations.xml.Tag) IOException(java.io.IOException) PresencePacket(eu.siacs.conversations.xmpp.stanzas.PresencePacket) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 85 with Element

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

the class XmppConnection method authenticate.

private void authenticate() throws IOException {
    final List<String> mechanisms = extractMechanisms(streamFeatures.findChild("mechanisms"));
    final Element auth = new Element("auth");
    auth.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl");
    if (mechanisms.contains("EXTERNAL") && account.getPrivateKeyAlias() != null) {
        saslMechanism = new External(tagWriter, account, mXmppConnectionService.getRNG());
    } else if (mechanisms.contains("SCRAM-SHA-256")) {
        saslMechanism = new ScramSha256(tagWriter, account, mXmppConnectionService.getRNG());
    } else if (mechanisms.contains("SCRAM-SHA-1")) {
        saslMechanism = new ScramSha1(tagWriter, account, mXmppConnectionService.getRNG());
    } else if (mechanisms.contains("PLAIN")) {
        saslMechanism = new Plain(tagWriter, account);
    } else if (mechanisms.contains("DIGEST-MD5")) {
        saslMechanism = new DigestMd5(tagWriter, account, mXmppConnectionService.getRNG());
    } else if (mechanisms.contains("ANONYMOUS")) {
        saslMechanism = new Anonymous(tagWriter, account, mXmppConnectionService.getRNG());
    }
    if (saslMechanism != null) {
        final int pinnedMechanism = account.getKeyAsInt(Account.PINNED_MECHANISM_KEY, -1);
        if (pinnedMechanism > saslMechanism.getPriority()) {
            Log.e(Config.LOGTAG, "Auth failed. Authentication mechanism " + saslMechanism.getMechanism() + " has lower priority (" + String.valueOf(saslMechanism.getPriority()) + ") than pinned priority (" + pinnedMechanism + "). Possible downgrade attack?");
            throw new SecurityException();
        }
        Log.d(Config.LOGTAG, account.getJid().toString() + ": Authenticating with " + saslMechanism.getMechanism());
        auth.setAttribute("mechanism", saslMechanism.getMechanism());
        if (!saslMechanism.getClientFirstMessage().isEmpty()) {
            auth.setContent(saslMechanism.getClientFirstMessage());
        }
        tagWriter.writeElement(auth);
    } else {
        throw new IncompatibleServerException();
    }
}
Also used : ScramSha256(eu.siacs.conversations.crypto.sasl.ScramSha256) Plain(eu.siacs.conversations.crypto.sasl.Plain) DigestMd5(eu.siacs.conversations.crypto.sasl.DigestMd5) Element(eu.siacs.conversations.xml.Element) External(eu.siacs.conversations.crypto.sasl.External) ScramSha1(eu.siacs.conversations.crypto.sasl.ScramSha1) Anonymous(eu.siacs.conversations.crypto.sasl.Anonymous)

Aggregations

Element (eu.siacs.conversations.xml.Element)93 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)43 Account (eu.siacs.conversations.entities.Account)21 Jid (eu.siacs.conversations.xmpp.jid.Jid)17 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)16 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)8 Contact (eu.siacs.conversations.entities.Contact)7 Conversation (eu.siacs.conversations.entities.Conversation)6 ArrayList (java.util.ArrayList)6 Data (eu.siacs.conversations.xmpp.forms.Data)5 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)5 IOException (java.io.IOException)5 MucOptions (eu.siacs.conversations.entities.MucOptions)4 PresencePacket (eu.siacs.conversations.xmpp.stanzas.PresencePacket)4 Pair (android.util.Pair)3 Bookmark (eu.siacs.conversations.entities.Bookmark)3 Message (eu.siacs.conversations.entities.Message)3 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3