Search in sources :

Example 1 with AxolotlService

use of eu.siacs.conversations.crypto.axolotl.AxolotlService in project Conversations by siacs.

the class IqParser method rosterItems.

private void rosterItems(final Account account, final Element query) {
    final String version = query.getAttribute("ver");
    if (version != null) {
        account.getRoster().setVersion(version);
    }
    for (final Element item : query.getChildren()) {
        if (item.getName().equals("item")) {
            final Jid jid = InvalidJid.getNullForInvalid(item.getAttributeAsJid("jid"));
            if (jid == null) {
                continue;
            }
            final String name = item.getAttribute("name");
            final String subscription = item.getAttribute("subscription");
            final Contact contact = account.getRoster().getContact(jid);
            boolean bothPre = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
            if (!contact.getOption(Contact.Options.DIRTY_PUSH)) {
                contact.setServerName(name);
                contact.parseGroupsFromElement(item);
            }
            if ("remove".equals(subscription)) {
                contact.resetOption(Contact.Options.IN_ROSTER);
                contact.resetOption(Contact.Options.DIRTY_DELETE);
                contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
            } else {
                contact.setOption(Contact.Options.IN_ROSTER);
                contact.resetOption(Contact.Options.DIRTY_PUSH);
                contact.parseSubscriptionFromElement(item);
            }
            boolean both = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
            if ((both != bothPre) && both) {
                Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": gained mutual presence subscription with " + contact.getJid());
                AxolotlService axolotlService = account.getAxolotlService();
                if (axolotlService != null) {
                    axolotlService.clearErrorsInFetchStatusMap(contact.getJid());
                }
            }
            mXmppConnectionService.getAvatarService().clear(contact);
        }
    }
    mXmppConnectionService.updateConversationUi();
    mXmppConnectionService.updateRosterUi();
    mXmppConnectionService.getShortcutService().refresh();
    mXmppConnectionService.syncRoster(account);
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) InvalidJid(eu.siacs.conversations.xmpp.InvalidJid) Jid(eu.siacs.conversations.xmpp.Jid) Element(eu.siacs.conversations.xml.Element) Contact(eu.siacs.conversations.entities.Contact)

Example 2 with AxolotlService

use of eu.siacs.conversations.crypto.axolotl.AxolotlService in project Conversations by siacs.

the class MessageParser method parseAxolotlChat.

private Message parseAxolotlChat(Element axolotlMessage, Jid from, Conversation conversation, int status, final boolean checkedForDuplicates, boolean postpone) {
    final AxolotlService service = conversation.getAccount().getAxolotlService();
    final XmppAxolotlMessage xmppAxolotlMessage;
    try {
        xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlMessage, from.asBareJid());
    } catch (Exception e) {
        Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": invalid omemo message received " + e.getMessage());
        return null;
    }
    if (xmppAxolotlMessage.hasPayload()) {
        final XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage;
        try {
            plaintextMessage = service.processReceivingPayloadMessage(xmppAxolotlMessage, postpone);
        } catch (BrokenSessionException e) {
            if (checkedForDuplicates) {
                if (service.trustedOrPreviouslyResponded(from.asBareJid())) {
                    service.reportBrokenSessionException(e, postpone);
                    return new Message(conversation, "", Message.ENCRYPTION_AXOLOTL_FAILED, status);
                } else {
                    Log.d(Config.LOGTAG, "ignoring broken session exception because contact was not trusted");
                    return new Message(conversation, "", Message.ENCRYPTION_AXOLOTL_FAILED, status);
                }
            } else {
                Log.d(Config.LOGTAG, "ignoring broken session exception because checkForDuplicates failed");
                return null;
            }
        } catch (NotEncryptedForThisDeviceException e) {
            return new Message(conversation, "", Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE, status);
        } catch (OutdatedSenderException e) {
            return new Message(conversation, "", Message.ENCRYPTION_AXOLOTL_FAILED, status);
        }
        if (plaintextMessage != null) {
            Message finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status);
            finishedMessage.setFingerprint(plaintextMessage.getFingerprint());
            Log.d(Config.LOGTAG, AxolotlService.getLogprefix(finishedMessage.getConversation().getAccount()) + " Received Message with session fingerprint: " + plaintextMessage.getFingerprint());
            return finishedMessage;
        }
    } else {
        Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": received OMEMO key transport message");
        service.processReceivingKeyTransportMessage(xmppAxolotlMessage, postpone);
    }
    return null;
}
Also used : OutdatedSenderException(eu.siacs.conversations.crypto.axolotl.OutdatedSenderException) AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) BrokenSessionException(eu.siacs.conversations.crypto.axolotl.BrokenSessionException) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) NotEncryptedForThisDeviceException(eu.siacs.conversations.crypto.axolotl.NotEncryptedForThisDeviceException) BrokenSessionException(eu.siacs.conversations.crypto.axolotl.BrokenSessionException) NotEncryptedForThisDeviceException(eu.siacs.conversations.crypto.axolotl.NotEncryptedForThisDeviceException) OutdatedSenderException(eu.siacs.conversations.crypto.axolotl.OutdatedSenderException)

Example 3 with AxolotlService

use of eu.siacs.conversations.crypto.axolotl.AxolotlService in project Conversations by siacs.

the class Account method initAccountServices.

public void initAccountServices(final XmppConnectionService context) {
    this.axolotlService = new AxolotlService(this, context);
    this.pgpDecryptionService = new PgpDecryptionService(context);
    if (xmppConnection != null) {
        xmppConnection.addOnAdvancedStreamFeaturesAvailableListener(axolotlService);
    }
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) PgpDecryptionService(eu.siacs.conversations.crypto.PgpDecryptionService)

Example 4 with AxolotlService

use of eu.siacs.conversations.crypto.axolotl.AxolotlService in project Conversations by siacs.

the class XmppConnectionService method createConnection.

public XmppConnection createConnection(final Account account) {
    final XmppConnection connection = new XmppConnection(account, this);
    connection.setOnMessagePacketReceivedListener(this.mMessageParser);
    connection.setOnStatusChangedListener(this.statusListener);
    connection.setOnPresencePacketReceivedListener(this.mPresenceParser);
    connection.setOnUnregisteredIqPacketReceivedListener(this.mIqParser);
    connection.setOnJinglePacketReceivedListener(((a, jp) -> mJingleConnectionManager.deliverPacket(a, jp)));
    connection.setOnBindListener(this.mOnBindListener);
    connection.setOnMessageAcknowledgeListener(this.mOnMessageAcknowledgedListener);
    connection.addOnAdvancedStreamFeaturesAvailableListener(this.mMessageArchiveService);
    connection.addOnAdvancedStreamFeaturesAvailableListener(this.mAvatarService);
    AxolotlService axolotlService = account.getAxolotlService();
    if (axolotlService != null) {
        connection.addOnAdvancedStreamFeaturesAvailableListener(axolotlService);
    }
    return connection;
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) Conversational(eu.siacs.conversations.entities.Conversational) Arrays(java.util.Arrays) Bundle(android.os.Bundle) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket) ReplacingSerialSingleThreadExecutor(eu.siacs.conversations.utils.ReplacingSerialSingleThreadExecutor) Uri(android.net.Uri) LruCache(android.util.LruCache) NetworkCapabilities(android.net.NetworkCapabilities) BoolRes(androidx.annotation.BoolRes) SecureRandom(java.security.SecureRandom) Manifest(android.Manifest) StringUtils(eu.siacs.conversations.utils.StringUtils) PhoneStateListener(android.telephony.PhoneStateListener) Map(java.util.Map) MimeUtils(eu.siacs.conversations.utils.MimeUtils) ContextCompat(androidx.core.content.ContextCompat) Resolver(eu.siacs.conversations.utils.Resolver) TargetApi(android.annotation.TargetApi) Log(android.util.Log) ConnectivityManager(android.net.ConnectivityManager) XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Contact(eu.siacs.conversations.entities.Contact) IntentFilter(android.content.IntentFilter) Set(java.util.Set) Network(android.net.Network) Executors(java.util.concurrent.Executors) Conscrypt(org.conscrypt.Conscrypt) MucOptions(eu.siacs.conversations.entities.MucOptions) CountDownLatch(java.util.concurrent.CountDownLatch) OnContactStatusChanged(eu.siacs.conversations.xmpp.OnContactStatusChanged) PresencePacket(eu.siacs.conversations.xmpp.stanzas.PresencePacket) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) DatabaseBackend(eu.siacs.conversations.persistance.DatabaseBackend) OnUpdateBlocklist(eu.siacs.conversations.xmpp.OnUpdateBlocklist) FingerprintStatus(eu.siacs.conversations.crypto.axolotl.FingerprintStatus) AbstractParser(eu.siacs.conversations.parser.AbstractParser) IqParser(eu.siacs.conversations.parser.IqParser) SerialSingleThreadExecutor(eu.siacs.conversations.utils.SerialSingleThreadExecutor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Config(eu.siacs.conversations.Config) Environment(android.os.Environment) OpenPgpApi(org.openintents.openpgp.util.OpenPgpApi) OnMessagePacketReceived(eu.siacs.conversations.xmpp.OnMessagePacketReceived) PresenceTemplate(eu.siacs.conversations.entities.PresenceTemplate) SystemClock(android.os.SystemClock) PresenceParser(eu.siacs.conversations.parser.PresenceParser) Account(eu.siacs.conversations.entities.Account) Element(eu.siacs.conversations.xml.Element) ArrayList(java.util.ArrayList) ChatState(eu.siacs.conversations.xmpp.chatstate.ChatState) Strings(com.google.common.base.Strings) UiCallback(eu.siacs.conversations.ui.UiCallback) OnAvatarPublication(eu.siacs.conversations.ui.interfaces.OnAvatarPublication) OnMediaLoaded(eu.siacs.conversations.ui.interfaces.OnMediaLoaded) Patches(eu.siacs.conversations.xmpp.Patches) PgpDecryptionService(eu.siacs.conversations.crypto.PgpDecryptionService) PgpEngine(eu.siacs.conversations.crypto.PgpEngine) ChooseAccountForProfilePictureActivity(eu.siacs.conversations.ui.ChooseAccountForProfilePictureActivity) Avatar(eu.siacs.conversations.xmpp.pep.Avatar) Executor(java.util.concurrent.Executor) QuickLoader(eu.siacs.conversations.utils.QuickLoader) ComponentName(android.content.ComponentName) AbstractJingleConnection(eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection) RtpEndUserState(eu.siacs.conversations.xmpp.jingle.RtpEndUserState) TextUtils(android.text.TextUtils) File(java.io.File) Data(eu.siacs.conversations.xmpp.forms.Data) AtomicLong(java.util.concurrent.atomic.AtomicLong) SharedPreferences(android.content.SharedPreferences) MessageGenerator(eu.siacs.conversations.generator.MessageGenerator) HttpConnectionManager(eu.siacs.conversations.http.HttpConnectionManager) LocalizedContent(eu.siacs.conversations.xml.LocalizedContent) IntegerRes(androidx.annotation.IntegerRes) KeyguardManager(android.app.KeyguardManager) X509Certificate(java.security.cert.X509Certificate) KeyChain(android.security.KeyChain) PackageManager(android.content.pm.PackageManager) ListIterator(java.util.ListIterator) OnStatusChanged(eu.siacs.conversations.xmpp.OnStatusChanged) Security(java.security.Security) PendingIntent(android.app.PendingIntent) IBinder(android.os.IBinder) ReplacingTaskManager(eu.siacs.conversations.utils.ReplacingTaskManager) Blockable(eu.siacs.conversations.entities.Blockable) WakeLock(android.os.PowerManager.WakeLock) JingleRtpConnection(eu.siacs.conversations.xmpp.jingle.JingleRtpConnection) PowerManager(android.os.PowerManager) JingleConnectionManager(eu.siacs.conversations.xmpp.jingle.JingleConnectionManager) ContactsContract(android.provider.ContactsContract) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) JabberIdContact(eu.siacs.conversations.android.JabberIdContact) AbstractGenerator(eu.siacs.conversations.generator.AbstractGenerator) PreferenceManager(android.preference.PreferenceManager) Objects(com.google.common.base.Objects) MessageParser(eu.siacs.conversations.parser.MessageParser) NotificationManager(android.app.NotificationManager) Service(android.app.Service) Collection(java.util.Collection) NetworkInfo(android.net.NetworkInfo) PhoneHelper(eu.siacs.conversations.utils.PhoneHelper) PresenceGenerator(eu.siacs.conversations.generator.PresenceGenerator) OmemoSetting(eu.siacs.conversations.crypto.OmemoSetting) OnBindListener(eu.siacs.conversations.xmpp.OnBindListener) BroadcastReceiver(android.content.BroadcastReceiver) DisplayMetrics(android.util.DisplayMetrics) ContentObserver(android.database.ContentObserver) List(java.util.List) Message(eu.siacs.conversations.entities.Message) OnRenameListener(eu.siacs.conversations.entities.MucOptions.OnRenameListener) PublishOptions(eu.siacs.conversations.xmpp.pep.PublishOptions) Notification(android.app.Notification) ConversationsFileObserver(eu.siacs.conversations.utils.ConversationsFileObserver) Bookmark(eu.siacs.conversations.entities.Bookmark) ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult) EasyOnboardingInvite(eu.siacs.conversations.utils.EasyOnboardingInvite) Context(android.content.Context) Roster(eu.siacs.conversations.entities.Roster) OnKeyStatusUpdated(eu.siacs.conversations.xmpp.OnKeyStatusUpdated) Pair(android.util.Pair) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Intent(android.content.Intent) IOpenPgpService2(org.openintents.openpgp.IOpenPgpService2) OnPresencePacketReceived(eu.siacs.conversations.xmpp.OnPresencePacketReceived) AtomicReference(java.util.concurrent.atomic.AtomicReference) FileBackend(eu.siacs.conversations.persistance.FileBackend) AudioManager(android.media.AudioManager) OpenPgpServiceConnection(org.openintents.openpgp.util.OpenPgpServiceConnection) Conversation(eu.siacs.conversations.entities.Conversation) Binder(android.os.Binder) HashSet(java.util.HashSet) Compatibility(eu.siacs.conversations.utils.Compatibility) CryptoHelper(eu.siacs.conversations.utils.CryptoHelper) SuppressLint(android.annotation.SuppressLint) RemoteInput(androidx.core.app.RemoteInput) Presence(eu.siacs.conversations.entities.Presence) TelephonyManager(android.telephony.TelephonyManager) AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) RtpSessionActivity(eu.siacs.conversations.ui.RtpSessionActivity) Build(android.os.Build) Hashtable(java.util.Hashtable) WeakHashMap(java.util.WeakHashMap) ExceptionHelper(eu.siacs.conversations.utils.ExceptionHelper) OnSearchResultsAvailable(eu.siacs.conversations.ui.interfaces.OnSearchResultsAvailable) Iterator(java.util.Iterator) R(eu.siacs.conversations.R) AlarmManager(android.app.AlarmManager) Media(eu.siacs.conversations.xmpp.jingle.Media) SettingsActivity(eu.siacs.conversations.ui.SettingsActivity) CertificateException(java.security.cert.CertificateException) IqGenerator(eu.siacs.conversations.generator.IqGenerator) WakeLockHelper(eu.siacs.conversations.utils.WakeLockHelper) ShortcutBadger(me.leolin.shortcutbadger.ShortcutBadger) OnMessageAcknowledged(eu.siacs.conversations.xmpp.OnMessageAcknowledged) TorServiceUtils(eu.siacs.conversations.utils.TorServiceUtils) Namespace(eu.siacs.conversations.xml.Namespace) Bitmap(android.graphics.Bitmap) Collections(java.util.Collections) XmppUri(eu.siacs.conversations.utils.XmppUri) Jid(eu.siacs.conversations.xmpp.Jid) MamReference(eu.siacs.conversations.xmpp.mam.MamReference) AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService)

Example 5 with AxolotlService

use of eu.siacs.conversations.crypto.axolotl.AxolotlService in project Conversations by siacs.

the class XmppConnectionService method reconnectAccount.

private void reconnectAccount(final Account account, final boolean force, final boolean interactive) {
    synchronized (account) {
        XmppConnection connection = account.getXmppConnection();
        if (connection == null) {
            connection = createConnection(account);
            account.setXmppConnection(connection);
        }
        boolean hasInternet = hasInternetConnection();
        if (account.isEnabled() && hasInternet) {
            if (!force) {
                disconnect(account, false);
            }
            Thread thread = new Thread(connection);
            connection.setInteractive(interactive);
            connection.prepareNewConnection();
            connection.interrupt();
            thread.start();
            scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode());
        } else {
            disconnect(account, force || account.getTrueStatus().isError() || !hasInternet);
            account.getRoster().clearPresences();
            connection.resetEverything();
            final AxolotlService axolotlService = account.getAxolotlService();
            if (axolotlService != null) {
                axolotlService.resetBrokenness();
            }
            if (!hasInternet) {
                account.setStatus(Account.State.NO_INTERNET);
            }
        }
    }
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService)

Aggregations

AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)18 Jid (eu.siacs.conversations.xmpp.Jid)10 Contact (eu.siacs.conversations.entities.Contact)6 XmppUri (eu.siacs.conversations.utils.XmppUri)6 Element (eu.siacs.conversations.xml.Element)6 Intent (android.content.Intent)5 PendingIntent (android.app.PendingIntent)4 FingerprintStatus (eu.siacs.conversations.crypto.axolotl.FingerprintStatus)4 XmppConnection (eu.siacs.conversations.xmpp.XmppConnection)4 SuppressLint (android.annotation.SuppressLint)3 SharedPreferences (android.content.SharedPreferences)3 Uri (android.net.Uri)3 Build (android.os.Build)3 Bundle (android.os.Bundle)3 Account (eu.siacs.conversations.entities.Account)3 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 PreferenceManager (android.preference.PreferenceManager)2 Menu (android.view.Menu)2 MenuItem (android.view.MenuItem)2