Search in sources :

Example 11 with InvalidJidException

use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.

the class XmppConnection method sendBindRequest.

private void sendBindRequest() {
    try {
        mXmppConnectionService.restoredFromDatabaseLatch.await();
    } catch (InterruptedException e) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": interrupted while waiting for DB restore during bind");
        return;
    }
    clearIqCallbacks();
    if (account.getJid().isBareJid()) {
        account.setResource(this.createNewResource());
    }
    final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
    final String resource = Config.USE_RANDOM_RESOURCE_ON_EVERY_BIND ? nextRandomId() : account.getResource();
    iq.addChild("bind", Namespace.BIND).addChild("resource").setContent(resource);
    this.sendUnmodifiedIqPacket(iq, (account, packet) -> {
        if (packet.getType() == IqPacket.TYPE.TIMEOUT) {
            return;
        }
        final Element bind = packet.findChild("bind");
        if (bind != null && packet.getType() == IqPacket.TYPE.RESULT) {
            isBound = true;
            final Element jid = bind.findChild("jid");
            if (jid != null && jid.getContent() != null) {
                try {
                    Jid assignedJid = Jid.fromString(jid.getContent());
                    if (!account.getJid().getDomainpart().equals(assignedJid.getDomainpart())) {
                        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server tried to re-assign domain to " + assignedJid.getDomainpart());
                        throw new StateChangingError(Account.State.BIND_FAILURE);
                    }
                    if (account.setJid(assignedJid)) {
                        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": jid changed during bind. updating database");
                        mXmppConnectionService.databaseBackend.updateAccount(account);
                    }
                    if (streamFeatures.hasChild("session") && !streamFeatures.findChild("session").hasChild("optional")) {
                        sendStartSession();
                    } else {
                        sendPostBindInitialization();
                    }
                    return;
                } catch (final InvalidJidException e) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server reported invalid jid (" + jid.getContent() + ") on bind");
                }
            } else {
                Log.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure. (no jid)");
            }
        } else {
            Log.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure (" + packet.toString());
        }
        final Element error = packet.findChild("error");
        if (packet.getType() == IqPacket.TYPE.ERROR && error != null && error.hasChild("conflict")) {
            account.setResource(createNewResource());
        }
        throw new StateChangingError(Account.State.BIND_FAILURE);
    }, true);
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 12 with InvalidJidException

use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.

the class OtrService method sendOtrErrorMessage.

public void sendOtrErrorMessage(SessionID session, String errorText) {
    try {
        Jid jid = Jid.fromSessionID(session);
        Conversation conversation = mXmppConnectionService.find(account, jid);
        String id = conversation == null ? null : conversation.getLastReceivedOtrMessageId();
        if (id != null) {
            MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateOtrError(jid, id, errorText);
            packet.setFrom(account.getJid());
            mXmppConnectionService.sendMessagePacket(account, packet);
            Log.d(Config.LOGTAG, packet.toString());
            Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": unreadable OTR message in " + conversation.getName());
        }
    } catch (InvalidJidException e) {
        return;
    }
}
Also used : MessagePacket(de.pixart.messenger.xmpp.stanzas.MessagePacket) Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation)

Example 13 with InvalidJidException

use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.

the class AxolotlService method verifySessionWithPEP.

private void verifySessionWithPEP(final XmppAxolotlSession session) {
    Log.d(Config.LOGTAG, "trying to verify fresh session (" + session.getRemoteAddress().getName() + ") with pep");
    final SignalProtocolAddress address = session.getRemoteAddress();
    final IdentityKey identityKey = session.getIdentityKey();
    try {
        IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveVerificationForDevice(Jid.fromString(address.getName()), address.getDeviceId());
        mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(Account account, IqPacket packet) {
                Pair<X509Certificate[], byte[]> verification = mXmppConnectionService.getIqParser().verification(packet);
                if (verification != null) {
                    try {
                        Signature verifier = Signature.getInstance("sha256WithRSA");
                        verifier.initVerify(verification.first[0]);
                        verifier.update(identityKey.serialize());
                        if (verifier.verify(verification.second)) {
                            try {
                                mXmppConnectionService.getMemorizingTrustManager().getNonInteractive().checkClientTrusted(verification.first, "RSA");
                                String fingerprint = session.getFingerprint();
                                Log.d(Config.LOGTAG, "verified session with x.509 signature. fingerprint was: " + fingerprint);
                                setFingerprintTrust(fingerprint, FingerprintStatus.createActiveVerified(true));
                                axolotlStore.setFingerprintCertificate(fingerprint, verification.first[0]);
                                fetchStatusMap.put(address, FetchStatus.SUCCESS_VERIFIED);
                                Bundle information = CryptoHelper.extractCertificateInformation(verification.first[0]);
                                try {
                                    final String cn = information.getString("subject_cn");
                                    final Jid jid = Jid.fromString(address.getName());
                                    Log.d(Config.LOGTAG, "setting common name for " + jid + " to " + cn);
                                    account.getRoster().getContact(jid).setCommonName(cn);
                                } catch (final InvalidJidException ignored) {
                                // ignored
                                }
                                finishBuildingSessionsFromPEP(address);
                                return;
                            } catch (Exception e) {
                                Log.d(Config.LOGTAG, "could not verify certificate");
                            }
                        }
                    } catch (Exception e) {
                        Log.d(Config.LOGTAG, "error during verification " + e.getMessage());
                    }
                } else {
                    Log.d(Config.LOGTAG, "no verification found");
                }
                fetchStatusMap.put(address, FetchStatus.SUCCESS);
                finishBuildingSessionsFromPEP(address);
            }
        });
    } catch (InvalidJidException e) {
        fetchStatusMap.put(address, FetchStatus.SUCCESS);
        finishBuildingSessionsFromPEP(address);
    }
}
Also used : Account(de.pixart.messenger.entities.Account) IdentityKey(org.whispersystems.libsignal.IdentityKey) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Jid(de.pixart.messenger.xmpp.jid.Jid) Bundle(android.os.Bundle) PreKeyBundle(org.whispersystems.libsignal.state.PreKeyBundle) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) X509Certificate(java.security.cert.X509Certificate) UntrustedIdentityException(org.whispersystems.libsignal.UntrustedIdentityException) InvalidKeyIdException(org.whispersystems.libsignal.InvalidKeyIdException) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket) Signature(java.security.Signature) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) Pair(android.util.Pair)

Example 14 with InvalidJidException

use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.

the class AbstractParser method parseItem.

public static MucOptions.User parseItem(Conversation conference, Element item, Jid fullJid) {
    final String local = conference.getJid().getLocalpart();
    final String domain = conference.getJid().getDomainpart();
    String affiliation = item.getAttribute("affiliation");
    String role = item.getAttribute("role");
    String nick = item.getAttribute("nick");
    if (nick != null && fullJid == null) {
        try {
            fullJid = Jid.fromParts(local, domain, nick);
        } catch (InvalidJidException e) {
            fullJid = null;
        }
    }
    Jid realJid = item.getAttributeAsJid("jid");
    MucOptions.User user = new MucOptions.User(conference.getMucOptions(), fullJid);
    user.setRealJid(realJid);
    user.setAffiliation(affiliation);
    user.setRole(role);
    return user;
}
Also used : MucOptions(de.pixart.messenger.entities.MucOptions) Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException)

Example 15 with InvalidJidException

use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.

the class PushManagementService method registerPushTokenOnServer.

public void registerPushTokenOnServer(final Account account) {
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": has push support");
    retrieveGcmInstanceToken(new OnGcmInstanceTokenRetrieved() {

        @Override
        public void onGcmInstanceTokenRetrieved(String token) {
            try {
                final String deviceId = Settings.Secure.getString(mXmppConnectionService.getContentResolver(), Settings.Secure.ANDROID_ID);
                IqPacket packet = mXmppConnectionService.getIqGenerator().pushTokenToAppServer(Jid.fromString(APP_SERVER), token, deviceId);
                mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket packet) {
                        Element command = packet.findChild("command", "http://jabber.org/protocol/commands");
                        if (packet.getType() == IqPacket.TYPE.RESULT && command != null) {
                            Element x = command.findChild("x", Namespace.DATA);
                            if (x != null) {
                                Data data = Data.parse(x);
                                try {
                                    String node = data.getValue("node");
                                    String secret = data.getValue("secret");
                                    Jid jid = Jid.fromString(data.getValue("jid"));
                                    if (node != null && secret != null) {
                                        enablePushOnServer(account, jid, node, secret);
                                    }
                                } catch (InvalidJidException e) {
                                    e.printStackTrace();
                                }
                            }
                        } else {
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": invalid response from app server");
                        }
                    }
                });
            } catch (InvalidJidException ignored) {
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Data(de.pixart.messenger.xmpp.forms.Data) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Aggregations

InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)33 Jid (de.pixart.messenger.xmpp.jid.Jid)25 Account (de.pixart.messenger.entities.Account)14 Conversation (de.pixart.messenger.entities.Conversation)13 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)5 AlertDialog (android.support.v7.app.AlertDialog)4 Contact (de.pixart.messenger.entities.Contact)4 Message (de.pixart.messenger.entities.Message)4 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)4 View (android.view.View)3 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)3 ArrayList (java.util.ArrayList)3 SuppressLint (android.annotation.SuppressLint)2 Bundle (android.os.Bundle)2 SpannableString (android.text.SpannableString)2 Pair (android.util.Pair)2 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)2 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)2