Search in sources :

Example 41 with Jid

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

the class BlocklistActivity method filterContacts.

@Override
protected void filterContacts(final String needle) {
    getListItems().clear();
    if (account != null) {
        for (final Jid jid : account.getBlocklist()) {
            final Contact contact = account.getRoster().getContact(jid);
            if (contact.match(this, needle) && contact.isBlocked()) {
                getListItems().add(contact);
            }
        }
        Collections.sort(getListItems());
    }
    getListItemAdapter().notifyDataSetChanged();
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Contact(eu.siacs.conversations.entities.Contact)

Example 42 with Jid

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

the class XmppConnectionService method createAccountFromKey.

public void createAccountFromKey(final String alias, final OnAccountCreated callback) {
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                X509Certificate[] chain = KeyChain.getCertificateChain(XmppConnectionService.this, alias);
                Pair<Jid, String> info = CryptoHelper.extractJidAndName(chain[0]);
                if (findAccountByJid(info.first) == null) {
                    Account account = new Account(info.first, "");
                    account.setPrivateKeyAlias(alias);
                    account.setOption(Account.OPTION_DISABLED, true);
                    account.setDisplayName(info.second);
                    createAccount(account);
                    callback.onAccountCreated(account);
                    if (Config.X509_VERIFICATION) {
                        try {
                            getMemorizingTrustManager().getNonInteractive(account.getJid().getDomainpart()).checkClientTrusted(chain, "RSA");
                        } catch (CertificateException e) {
                            callback.informUser(R.string.certificate_chain_is_not_trusted);
                        }
                    }
                } else {
                    callback.informUser(R.string.account_already_exists);
                }
            } catch (Exception e) {
                e.printStackTrace();
                callback.informUser(R.string.unable_to_parse_certificate);
            }
        }
    }).start();
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate) OtrException(net.java.otr4j.OtrException) FileNotFoundException(java.io.FileNotFoundException) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) CertificateException(java.security.cert.CertificateException)

Example 43 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid 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 44 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid 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)

Example 45 with Jid

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

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(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

Jid (eu.siacs.conversations.xmpp.jid.Jid)59 Account (eu.siacs.conversations.entities.Account)22 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)19 Element (eu.siacs.conversations.xml.Element)17 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)14 Conversation (eu.siacs.conversations.entities.Conversation)13 Contact (eu.siacs.conversations.entities.Contact)9 MucOptions (eu.siacs.conversations.entities.MucOptions)9 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)9 Message (eu.siacs.conversations.entities.Message)7 ArrayList (java.util.ArrayList)6 Intent (android.content.Intent)5 SuppressLint (android.annotation.SuppressLint)4 AlertDialog (android.app.AlertDialog)4 TextView (android.widget.TextView)4 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)4 Bookmark (eu.siacs.conversations.entities.Bookmark)4 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)4 HashMap (java.util.HashMap)4 PendingIntent (android.app.PendingIntent)3