Search in sources :

Example 51 with Element

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

the class AxolotlService method publishOwnDeviceIdIfNeeded.

public void publishOwnDeviceIdIfNeeded() {
    if (pepBroken) {
        Log.d(Config.LOGTAG, getLogprefix(account) + "publishOwnDeviceIdIfNeeded called, but PEP is broken. Ignoring... ");
        return;
    }
    IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(account.getJid().toBareJid());
    mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.TIMEOUT) {
                Log.d(Config.LOGTAG, getLogprefix(account) + "Timeout received while retrieving own Device Ids.");
            } else {
                Element item = mXmppConnectionService.getIqParser().getItem(packet);
                Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": retrieved own device list: " + deviceIds);
                registerDevices(account.getJid().toBareJid(), deviceIds);
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) Set(java.util.Set) HashSet(java.util.HashSet) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 52 with Element

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

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 (int i = 0; i < keys.size(); ++i) {
        Element keyElement = new Element(KEYTAG);
        keyElement.setAttribute(REMOTEID, keys.keyAt(i));
        if (keys.valueAt(i).prekey) {
            keyElement.setAttribute("prekey", "true");
        }
        keyElement.setContent(Base64.encodeToString(keys.valueAt(i).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(de.pixart.messenger.xml.Element)

Example 53 with Element

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

the class IqParser method preKeyPublics.

public Map<Integer, ECPublicKey> preKeyPublics(final IqPacket packet) {
    Map<Integer, ECPublicKey> preKeyRecords = new HashMap<>();
    Element item = getItem(packet);
    if (item == null) {
        Log.d(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Couldn't find <item> in bundle IQ packet: " + packet);
        return null;
    }
    final Element bundleElement = item.findChild("bundle");
    if (bundleElement == null) {
        return null;
    }
    final Element prekeysElement = bundleElement.findChild("prekeys");
    if (prekeysElement == null) {
        Log.d(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Couldn't find <prekeys> in bundle IQ packet: " + packet);
        return null;
    }
    for (Element preKeyPublicElement : prekeysElement.getChildren()) {
        if (!preKeyPublicElement.getName().equals("preKeyPublic")) {
            Log.d(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Encountered unexpected tag in prekeys list: " + preKeyPublicElement);
            continue;
        }
        Integer preKeyId = null;
        try {
            preKeyId = Integer.valueOf(preKeyPublicElement.getAttribute("preKeyId"));
            final ECPublicKey preKeyPublic = Curve.decodePoint(Base64.decode(preKeyPublicElement.getContent(), Base64.DEFAULT), 0);
            preKeyRecords.put(preKeyId, preKeyPublic);
        } catch (NumberFormatException e) {
            Log.e(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "could not parse preKeyId from preKey " + preKeyPublicElement.toString());
        } catch (Throwable e) {
            Log.e(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Invalid preKeyPublic (ID=" + preKeyId + ") in PEP: " + e.getMessage() + ", skipping...");
        }
    }
    return preKeyRecords;
}
Also used : ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) HashMap(java.util.HashMap) Element(de.pixart.messenger.xml.Element)

Example 54 with Element

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

the class IqParser method avatarData.

public String avatarData(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 super.avatarData(items);
}
Also used : Element(de.pixart.messenger.xml.Element)

Example 55 with Element

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

the class IqParser method identityKey.

public IdentityKey identityKey(final Element bundle) {
    IdentityKey identityKey = null;
    final Element identityKeyElement = bundle.findChild("identityKey");
    if (identityKeyElement == null) {
        return null;
    }
    try {
        identityKey = new IdentityKey(Base64.decode(identityKeyElement.getContent(), Base64.DEFAULT), 0);
    } catch (Throwable e) {
        Log.e(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Invalid identityKey in PEP: " + e.getMessage());
    }
    return identityKey;
}
Also used : IdentityKey(org.whispersystems.libsignal.IdentityKey) 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