Search in sources :

Example 16 with InvalidJidException

use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.

the class ConversationActivity method handleViewConversationIntent.

private void handleViewConversationIntent(final Intent intent) {
    final String uuid = intent.getStringExtra(CONVERSATION);
    final String downloadUuid = intent.getStringExtra(EXTRA_DOWNLOAD_UUID);
    final String text = intent.getStringExtra(TEXT);
    final String nick = intent.getStringExtra(NICK);
    final boolean pm = intent.getBooleanExtra(PRIVATE_MESSAGE, false);
    if (selectConversationByUuid(uuid)) {
        this.mConversationFragment.reInit(getSelectedConversation());
        if (nick != null) {
            if (pm) {
                Jid jid = getSelectedConversation().getJid();
                try {
                    Jid next = Jid.fromParts(jid.getLocalpart(), jid.getDomainpart(), nick);
                    this.mConversationFragment.privateMessageWith(next);
                } catch (final InvalidJidException ignored) {
                //do nothing
                }
            } else {
                this.mConversationFragment.highlightInConference(nick);
            }
        } else {
            this.mConversationFragment.appendText(text);
        }
        hideConversationsOverview();
        mUnprocessedNewIntent = false;
        openConversation();
        if (mContentView instanceof SlidingPaneLayout) {
            //fixes bug where slp isn't properly closed yet
            updateActionBarTitle(true);
        }
        if (downloadUuid != null) {
            final Message message = mSelectedConversation.findMessageWithFileAndUuid(downloadUuid);
            if (message != null) {
                startDownloadable(message);
            }
        }
    } else {
        mUnprocessedNewIntent = false;
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Message(eu.siacs.conversations.entities.Message) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) SlidingPaneLayout(android.support.v4.widget.SlidingPaneLayout)

Example 17 with InvalidJidException

use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.

the class XmppConnectionService method createAdhocConference.

public boolean createAdhocConference(final Account account, final String subject, final Iterable<Jid> jids, final UiCallback<Conversation> callback) {
    Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": creating adhoc conference with " + jids.toString());
    if (account.getStatus() == Account.State.ONLINE) {
        try {
            String server = findConferenceServer(account);
            if (server == null) {
                if (callback != null) {
                    callback.error(R.string.no_conference_server_found, null);
                }
                return false;
            }
            final Jid jid = Jid.fromParts(new BigInteger(64, getRNG()).toString(Character.MAX_RADIX), server, null);
            final Conversation conversation = findOrCreateConversation(account, jid, true, false);
            joinMuc(conversation, new OnConferenceJoined() {

                @Override
                public void onConferenceJoined(final Conversation conversation) {
                    pushConferenceConfiguration(conversation, IqGenerator.defaultRoomConfiguration(), new OnConfigurationPushed() {

                        @Override
                        public void onPushSucceeded() {
                            if (subject != null && !subject.trim().isEmpty()) {
                                pushSubjectToConference(conversation, subject.trim());
                            }
                            for (Jid invite : jids) {
                                invite(conversation, invite);
                            }
                            if (account.countPresences() > 1) {
                                directInvite(conversation, account.getJid().toBareJid());
                            }
                            saveConversationAsBookmark(conversation, subject);
                            if (callback != null) {
                                callback.success(conversation);
                            }
                        }

                        @Override
                        public void onPushFailed() {
                            archiveConversation(conversation);
                            if (callback != null) {
                                callback.error(R.string.conference_creation_failed, conversation);
                            }
                        }
                    });
                }
            });
            return true;
        } catch (InvalidJidException e) {
            if (callback != null) {
                callback.error(R.string.conference_creation_failed, null);
            }
            return false;
        }
    } else {
        if (callback != null) {
            callback.error(R.string.not_connected_try_again, null);
        }
        return false;
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) BigInteger(java.math.BigInteger) Conversation(eu.siacs.conversations.entities.Conversation)

Example 18 with InvalidJidException

use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.

the class XmppConnectionService method onOtrSessionEstablished.

public void onOtrSessionEstablished(Conversation conversation) {
    final Account account = conversation.getAccount();
    final Session otrSession = conversation.getOtrSession();
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + " otr session established with " + conversation.getJid() + "/" + otrSession.getSessionID().getUserID());
    conversation.findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, new Conversation.OnMessageFound() {

        @Override
        public void onMessageFound(Message message) {
            SessionID id = otrSession.getSessionID();
            try {
                message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
            } catch (InvalidJidException e) {
                return;
            }
            if (message.needsUploading()) {
                mJingleConnectionManager.createNewConnection(message);
            } else {
                MessagePacket outPacket = mMessageGenerator.generateOtrChat(message);
                if (outPacket != null) {
                    mMessageGenerator.addDelay(outPacket, message.getTimeSent());
                    message.setStatus(Message.STATUS_SEND);
                    databaseBackend.updateMessage(message);
                    sendMessagePacket(account, outPacket);
                }
            }
            updateConversationUi();
        }
    });
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Account(eu.siacs.conversations.entities.Account) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation) SessionID(net.java.otr4j.session.SessionID) Session(net.java.otr4j.session.Session)

Example 19 with InvalidJidException

use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.

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 AxolotlAddress 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(eu.siacs.conversations.entities.Account) IdentityKey(org.whispersystems.libaxolotl.IdentityKey) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Jid(eu.siacs.conversations.xmpp.jid.Jid) Bundle(android.os.Bundle) PreKeyBundle(org.whispersystems.libaxolotl.state.PreKeyBundle) AxolotlAddress(org.whispersystems.libaxolotl.AxolotlAddress) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) X509Certificate(java.security.cert.X509Certificate) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) InvalidKeyException(org.whispersystems.libaxolotl.InvalidKeyException) InvalidKeyIdException(org.whispersystems.libaxolotl.InvalidKeyIdException) UntrustedIdentityException(org.whispersystems.libaxolotl.UntrustedIdentityException) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket) Signature(java.security.Signature) Pair(android.util.Pair) IdentityKeyPair(org.whispersystems.libaxolotl.IdentityKeyPair)

Example 20 with InvalidJidException

use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.

the class OtrService method injectMessage.

@Override
public void injectMessage(SessionID session, String body) throws OtrException {
    MessagePacket packet = new MessagePacket();
    packet.setFrom(account.getJid());
    if (session.getUserID().isEmpty()) {
        packet.setAttribute("to", session.getAccountID());
    } else {
        packet.setAttribute("to", session.getAccountID() + "/" + session.getUserID());
    }
    packet.setBody(body);
    MessageGenerator.addMessageHints(packet);
    try {
        Jid jid = Jid.fromSessionID(session);
        Conversation conversation = mXmppConnectionService.find(account, jid);
        if (conversation != null && conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
            if (mXmppConnectionService.sendChatStates()) {
                packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
            }
        }
    } catch (final InvalidJidException ignored) {
    }
    packet.setType(MessagePacket.TYPE_CHAT);
    packet.addChild("encryption", "urn:xmpp:eme:0").setAttribute("namespace", "urn:xmpp:otr:0");
    account.getXmppConnection().sendMessagePacket(packet);
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Jid(eu.siacs.conversations.xmpp.jid.Jid) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation)

Aggregations

InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)30 Jid (eu.siacs.conversations.xmpp.jid.Jid)18 Account (eu.siacs.conversations.entities.Account)13 Conversation (eu.siacs.conversations.entities.Conversation)11 AlertDialog (android.app.AlertDialog)4 View (android.view.View)4 Message (eu.siacs.conversations.entities.Message)4 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)4 DialogInterface (android.content.DialogInterface)3 TextView (android.widget.TextView)3 Contact (eu.siacs.conversations.entities.Contact)3 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)3 SuppressLint (android.annotation.SuppressLint)2 OnClickListener (android.content.DialogInterface.OnClickListener)2 Bundle (android.os.Bundle)2 SpannableString (android.text.SpannableString)2 Pair (android.util.Pair)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)2