Search in sources :

Example 56 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class IqParser method bundle.

public PreKeyBundle bundle(final IqPacket bundle) {
    Element bundleItem = getItem(bundle);
    if (bundleItem == null) {
        return null;
    }
    final Element bundleElement = bundleItem.findChild("bundle");
    if (bundleElement == null) {
        return null;
    }
    ECPublicKey signedPreKeyPublic = signedPreKeyPublic(bundleElement);
    Integer signedPreKeyId = signedPreKeyId(bundleElement);
    byte[] signedPreKeySignature = signedPreKeySignature(bundleElement);
    IdentityKey identityKey = identityKey(bundleElement);
    if (signedPreKeyId == null || signedPreKeyPublic == null || identityKey == null) {
        return null;
    }
    return new PreKeyBundle(0, 0, 0, null, signedPreKeyId, signedPreKeyPublic, signedPreKeySignature, identityKey);
}
Also used : PreKeyBundle(org.whispersystems.libsignal.state.PreKeyBundle) IdentityKey(org.whispersystems.libsignal.IdentityKey) ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) Element(de.pixart.messenger.xml.Element)

Example 57 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class IqParser method signedPreKeyPublic.

public ECPublicKey signedPreKeyPublic(final Element bundle) {
    ECPublicKey publicKey = null;
    final Element signedPreKeyPublic = bundle.findChild("signedPreKeyPublic");
    if (signedPreKeyPublic == null) {
        return null;
    }
    try {
        publicKey = Curve.decodePoint(Base64.decode(signedPreKeyPublic.getContent(), Base64.DEFAULT), 0);
    } catch (Throwable e) {
        Log.e(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Invalid signedPreKeyPublic in PEP: " + e.getMessage());
    }
    return publicKey;
}
Also used : ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) Element(de.pixart.messenger.xml.Element)

Example 58 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class IqParser method rosterItems.

private void rosterItems(final Account account, final Element query) {
    final String version = query.getAttribute("ver");
    if (version != null) {
        account.getRoster().setVersion(version);
    }
    for (final Element item : query.getChildren()) {
        if (item.getName().equals("item")) {
            final Jid jid = item.getAttributeAsJid("jid");
            if (jid == null) {
                continue;
            }
            final String name = item.getAttribute("name");
            final String subscription = item.getAttribute("subscription");
            final Contact contact = account.getRoster().getContact(jid);
            boolean bothPre = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
            if (!contact.getOption(Contact.Options.DIRTY_PUSH)) {
                contact.setServerName(name);
                contact.parseGroupsFromElement(item);
            }
            if ("remove".equals(subscription)) {
                contact.resetOption(Contact.Options.IN_ROSTER);
                contact.resetOption(Contact.Options.DIRTY_DELETE);
                contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
            } else {
                contact.setOption(Contact.Options.IN_ROSTER);
                contact.resetOption(Contact.Options.DIRTY_PUSH);
                contact.parseSubscriptionFromElement(item);
            }
            boolean both = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
            if ((both != bothPre) && both) {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": gained mutual presence subscription with " + contact.getJid());
                AxolotlService axolotlService = account.getAxolotlService();
                if (axolotlService != null) {
                    axolotlService.clearErrorsInFetchStatusMap(contact.getJid());
                }
            }
            mXmppConnectionService.getAvatarService().clear(contact);
        }
    }
    mXmppConnectionService.updateConversationUi();
    mXmppConnectionService.updateRosterUi();
    mXmppConnectionService.getShortcutService().refresh();
}
Also used : AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService) Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) Contact(de.pixart.messenger.entities.Contact)

Example 59 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class IqParser method getItem.

public Element getItem(final IqPacket packet) {
    final Element pubsub = packet.findChild("pubsub", "http://jabber.org/protocol/pubsub");
    if (pubsub == null) {
        return null;
    }
    final Element items = pubsub.findChild("items");
    if (items == null) {
        return null;
    }
    return items.findChild("item");
}
Also used : Element(de.pixart.messenger.xml.Element)

Example 60 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class MessageParser method getTrueCounterpart.

private static Jid getTrueCounterpart(Element mucUserElement, Jid fallback) {
    final Element item = mucUserElement == null ? null : mucUserElement.findChild("item");
    Jid result = item == null ? null : item.getAttributeAsJid("jid");
    return result != null ? result : fallback;
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element)

Aggregations

Element (de.pixart.messenger.xml.Element)100 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)48 Account (de.pixart.messenger.entities.Account)23 Jid (de.pixart.messenger.xmpp.jid.Jid)19 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)17 Contact (de.pixart.messenger.entities.Contact)9 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)8 ArrayList (java.util.ArrayList)7 Conversation (de.pixart.messenger.entities.Conversation)6 IOException (java.io.IOException)6 Data (de.pixart.messenger.xmpp.forms.Data)5 Avatar (de.pixart.messenger.xmpp.pep.Avatar)5 HashSet (java.util.HashSet)5 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)4 MucOptions (de.pixart.messenger.entities.MucOptions)4 ECPublicKey (org.whispersystems.libsignal.ecc.ECPublicKey)4 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)4 Pair (android.util.Pair)3 Bookmark (de.pixart.messenger.entities.Bookmark)3 Message (de.pixart.messenger.entities.Message)3