Search in sources :

Example 51 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class AxolotlService method publishDeviceBundle.

private void publishDeviceBundle(final SignedPreKeyRecord signedPreKeyRecord, final Set<PreKeyRecord> preKeyRecords, final boolean announceAfter, final boolean wipe, final boolean firstAttempt) {
    final Bundle publishOptions = account.getXmppConnection().getFeatures().pepPublishOptions() ? PublishOptions.openAccess() : null;
    IqPacket publish = mXmppConnectionService.getIqGenerator().publishBundles(signedPreKeyRecord, axolotlStore.getIdentityKeyPair().getPublicKey(), preKeyRecords, getOwnDeviceId(), publishOptions);
    Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + ": Bundle " + getOwnDeviceId() + " in PEP not current. Publishing...");
    mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(final Account account, IqPacket packet) {
            Element error = packet.getType() == IqPacket.TYPE.ERROR ? packet.findChild("error") : null;
            if (firstAttempt && error != null && error.hasChild("precondition-not-met", Namespace.PUBSUB_ERROR)) {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": precondition wasn't met for bundle. pushing node configuration");
                final String node = AxolotlService.PEP_BUNDLES + ":" + getOwnDeviceId();
                mXmppConnectionService.pushNodeConfiguration(account, node, publishOptions, new XmppConnectionService.OnConfigurationPushed() {

                    @Override
                    public void onPushSucceeded() {
                        publishDeviceBundle(signedPreKeyRecord, preKeyRecords, announceAfter, wipe, false);
                    }

                    @Override
                    public void onPushFailed() {
                        publishDeviceBundle(signedPreKeyRecord, preKeyRecords, announceAfter, wipe, false);
                    }
                });
            } else if (packet.getType() == IqPacket.TYPE.RESULT) {
                Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Successfully published bundle. ");
                if (wipe) {
                    wipeOtherPepDevices();
                } else if (announceAfter) {
                    Log.d(Config.LOGTAG, getLogprefix(account) + "Announcing device " + getOwnDeviceId());
                    publishOwnDeviceIdIfNeeded();
                }
            } else if (packet.getType() == IqPacket.TYPE.ERROR) {
                pepBroken = true;
                Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while publishing bundle: " + packet.findChild("error"));
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Bundle(android.os.Bundle) PreKeyBundle(org.whispersystems.libsignal.state.PreKeyBundle) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 52 with Account

use of de.pixart.messenger.entities.Account 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 53 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class MessageParser method extractStanzaId.

private static String extractStanzaId(Element packet, boolean isTypeGroupChat, Conversation conversation) {
    final Jid by;
    final boolean safeToExtract;
    if (isTypeGroupChat) {
        by = conversation.getJid().toBareJid();
        safeToExtract = conversation.getMucOptions().hasFeature(Namespace.STANZA_IDS);
    } else {
        Account account = conversation.getAccount();
        by = account.getJid().toBareJid();
        safeToExtract = account.getXmppConnection().getFeatures().stanzaIds();
    }
    return safeToExtract ? extractStanzaId(packet, by) : null;
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid)

Example 54 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

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;
        }
        message.resetFileParams();
        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");
                    if (mJingleStatus == JINGLE_STATUS_OFFERED) {
                        mJingleStatus = JINGLE_STATUS_INITIATED;
                        mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED);
                    } else {
                        Log.d(Config.LOGTAG, "received ack for offer when status was " + mJingleStatus);
                    }
                } else {
                    fail(IqParser.extractErrorMessage(packet));
                }
            }
        });
    }
}
Also used : Account(de.pixart.messenger.entities.Account) JinglePacket(de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Content(de.pixart.messenger.xmpp.jingle.stanzas.Content) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Conversation(de.pixart.messenger.entities.Conversation) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 55 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class JingleConnection method connect.

private void connect() {
    final JingleSocks5Transport connection = chooseConnection();
    this.transport = connection;
    if (connection == null) {
        Log.d(Config.LOGTAG, "could not find suitable candidate");
        this.disconnectSocks5Connections();
        if (initiating()) {
            this.sendFallbackToIbb();
        }
    } else {
        this.mJingleStatus = JINGLE_STATUS_TRANSMITTING;
        if (connection.needsActivation()) {
            if (connection.getCandidate().isOurs()) {
                final String sid;
                if (ftVersion == Content.Version.FT_3) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": use session ID instead of transport ID to activate proxy");
                    sid = getSessionId();
                } else {
                    sid = getTransportId();
                }
                Log.d(Config.LOGTAG, "candidate " + connection.getCandidate().getCid() + " was our proxy. going to activate");
                IqPacket activation = new IqPacket(IqPacket.TYPE.SET);
                activation.setTo(connection.getCandidate().getJid());
                activation.query("http://jabber.org/protocol/bytestreams").setAttribute("sid", sid);
                activation.query().addChild("activate").setContent(this.getCounterPart().toString());
                mXmppConnectionService.sendIqPacket(account, activation, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket packet) {
                        if (packet.getType() != IqPacket.TYPE.RESULT) {
                            onProxyActivated.failed();
                        } else {
                            onProxyActivated.success();
                            sendProxyActivated(connection.getCandidate().getCid());
                        }
                    }
                });
            } else {
                Log.d(Config.LOGTAG, "candidate " + connection.getCandidate().getCid() + " was a proxy. waiting for other party to activate");
            }
        } else {
            if (initiating()) {
                Log.d(Config.LOGTAG, "we were initiating. sending file");
                connection.send(file, onFileTransmissionStatusChanged);
            } else {
                Log.d(Config.LOGTAG, "we were responding. receiving file");
                connection.receive(file, onFileTransmissionStatusChanged);
            }
        }
    }
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Aggregations

Account (de.pixart.messenger.entities.Account)104 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)39 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)31 Jid (de.pixart.messenger.xmpp.jid.Jid)26 Element (de.pixart.messenger.xml.Element)23 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)19 Conversation (de.pixart.messenger.entities.Conversation)18 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)12 Contact (de.pixart.messenger.entities.Contact)12 Bookmark (de.pixart.messenger.entities.Bookmark)10 PendingIntent (android.app.PendingIntent)9 Message (de.pixart.messenger.entities.Message)8 Bundle (android.os.Bundle)7 AlertDialog (android.support.v7.app.AlertDialog)7 MucOptions (de.pixart.messenger.entities.MucOptions)7 List (java.util.List)7 SuppressLint (android.annotation.SuppressLint)6 Bitmap (android.graphics.Bitmap)6 View (android.view.View)6