Search in sources :

Example 6 with AxolotlService

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

the class MessageParser method parseEvent.

private void parseEvent(final Element event, final Jid from, final Account account) {
    Element items = event.findChild("items");
    String node = items == null ? null : items.getAttribute("node");
    if ("urn:xmpp:avatar:metadata".equals(node)) {
        Avatar avatar = Avatar.parseMetadata(items);
        if (avatar != null) {
            avatar.owner = from.toBareJid();
            if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
                if (account.getJid().toBareJid().equals(from)) {
                    if (account.setAvatar(avatar.getFilename())) {
                        mXmppConnectionService.databaseBackend.updateAccount(account);
                    }
                    mXmppConnectionService.getAvatarService().clear(account);
                    mXmppConnectionService.updateConversationUi();
                    mXmppConnectionService.updateAccountUi();
                } else {
                    Contact contact = account.getRoster().getContact(from);
                    contact.setAvatar(avatar);
                    mXmppConnectionService.getAvatarService().clear(contact);
                    mXmppConnectionService.updateConversationUi();
                    mXmppConnectionService.updateRosterUi();
                }
            } else if (mXmppConnectionService.isDataSaverDisabled()) {
                mXmppConnectionService.fetchAvatar(account, avatar);
            }
        }
    } else if ("http://jabber.org/protocol/nick".equals(node)) {
        Element i = items.findChild("item");
        Element nick = i == null ? null : i.findChild("nick", "http://jabber.org/protocol/nick");
        if (nick != null && nick.getContent() != null) {
            Contact contact = account.getRoster().getContact(from);
            contact.setPresenceName(nick.getContent());
            mXmppConnectionService.getAvatarService().clear(account);
            mXmppConnectionService.updateConversationUi();
            mXmppConnectionService.updateAccountUi();
        }
    } else if (AxolotlService.PEP_DEVICE_LIST.equals(node)) {
        Element item = items.findChild("item");
        Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
        Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received PEP device list (" + deviceIds + ") update from " + from + ", processing...");
        AxolotlService axolotlService = account.getAxolotlService();
        axolotlService.registerDevices(from, deviceIds);
        mXmppConnectionService.updateAccountUi();
    }
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) Element(eu.siacs.conversations.xml.Element) Avatar(eu.siacs.conversations.xmpp.pep.Avatar) Contact(eu.siacs.conversations.entities.Contact)

Example 7 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) {
    AxolotlService service = conversation.getAccount().getAxolotlService();
    XmppAxolotlMessage xmppAxolotlMessage;
    try {
        xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlMessage, from.toBareJid());
    } catch (Exception e) {
        Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": invalid omemo message received " + e.getMessage());
        return null;
    }
    XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceivingPayloadMessage(xmppAxolotlMessage);
    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 {
        return null;
    }
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)

Example 8 with AxolotlService

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

the class ConversationActivity method quickOmemoDebugger.

private boolean quickOmemoDebugger(Conversation c) {
    if (c != null) {
        boolean single = c.getMode() == Conversation.MODE_SINGLE;
        AxolotlService axolotlService = c.getAccount().getAxolotlService();
        Pair<AxolotlService.AxolotlCapability, Jid> capabilityJidPair = axolotlService.isConversationAxolotlCapableDetailed(c);
        switch(capabilityJidPair.first) {
            case MISSING_PRESENCE:
                Toast.makeText(ConversationActivity.this, single ? getString(R.string.missing_presence_subscription) : getString(R.string.missing_presence_subscription_with_x, capabilityJidPair.second.toBareJid().toString()), Toast.LENGTH_SHORT).show();
                return true;
            case MISSING_KEYS:
                Toast.makeText(ConversationActivity.this, single ? getString(R.string.missing_omemo_keys) : getString(R.string.missing_keys_from_x, capabilityJidPair.second.toBareJid().toString()), Toast.LENGTH_SHORT).show();
                return true;
            case WRONG_CONFIGURATION:
                Toast.makeText(ConversationActivity.this, R.string.wrong_conference_configuration, Toast.LENGTH_SHORT).show();
                return true;
            case NO_MEMBERS:
                Toast.makeText(ConversationActivity.this, R.string.this_conference_has_no_members, Toast.LENGTH_SHORT).show();
                return true;
        }
    }
    return false;
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) Jid(eu.siacs.conversations.xmpp.jid.Jid)

Example 9 with AxolotlService

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

the class ConversationActivity method trustKeysIfNeeded.

protected boolean trustKeysIfNeeded(int requestCode, int attachmentChoice) {
    AxolotlService axolotlService = mSelectedConversation.getAccount().getAxolotlService();
    final List<Jid> targets = axolotlService.getCryptoTargets(mSelectedConversation);
    boolean hasUnaccepted = !mSelectedConversation.getAcceptedCryptoTargets().containsAll(targets);
    boolean hasUndecidedOwn = !axolotlService.getKeysWithTrust(FingerprintStatus.createActiveUndecided()).isEmpty();
    boolean hasUndecidedContacts = !axolotlService.getKeysWithTrust(FingerprintStatus.createActiveUndecided(), targets).isEmpty();
    boolean hasPendingKeys = !axolotlService.findDevicesWithoutSession(mSelectedConversation).isEmpty();
    boolean hasNoTrustedKeys = axolotlService.anyTargetHasNoTrustedKeys(targets);
    if (hasUndecidedOwn || hasUndecidedContacts || hasPendingKeys || hasNoTrustedKeys || hasUnaccepted) {
        axolotlService.createSessionsIfNeeded(mSelectedConversation);
        Intent intent = new Intent(getApplicationContext(), TrustKeysActivity.class);
        String[] contacts = new String[targets.size()];
        for (int i = 0; i < contacts.length; ++i) {
            contacts[i] = targets.get(i).toString();
        }
        intent.putExtra("contacts", contacts);
        intent.putExtra(EXTRA_ACCOUNT, mSelectedConversation.getAccount().getJid().toBareJid().toString());
        intent.putExtra("choice", attachmentChoice);
        intent.putExtra("conversation", mSelectedConversation.getUuid());
        startActivityForResult(intent, requestCode);
        return true;
    } else {
        return false;
    }
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) Jid(eu.siacs.conversations.xmpp.jid.Jid) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint)

Example 10 with AxolotlService

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

the class XmppConnectionService method verifyFingerprints.

public boolean verifyFingerprints(Account account, List<XmppUri.Fingerprint> fingerprints) {
    final AxolotlService axolotlService = account.getAxolotlService();
    boolean verifiedSomething = false;
    for (XmppUri.Fingerprint fp : fingerprints) {
        if (fp.type == XmppUri.FingerprintType.OMEMO) {
            String fingerprint = "05" + fp.fingerprint.replaceAll("\\s", "");
            Log.d(Config.LOGTAG, "trying to verify own fp=" + fingerprint);
            FingerprintStatus fingerprintStatus = axolotlService.getFingerprintTrust(fingerprint);
            if (fingerprintStatus != null) {
                if (!fingerprintStatus.isVerified()) {
                    axolotlService.setFingerprintTrust(fingerprint, fingerprintStatus.toVerified());
                    verifiedSomething = true;
                }
            } else {
                axolotlService.preVerifyFingerprint(account, fingerprint);
                verifiedSomething = true;
            }
        }
    }
    return verifiedSomething;
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) XmppUri(eu.siacs.conversations.utils.XmppUri) FingerprintStatus(eu.siacs.conversations.crypto.axolotl.FingerprintStatus)

Aggregations

AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)12 Jid (eu.siacs.conversations.xmpp.jid.Jid)4 FingerprintStatus (eu.siacs.conversations.crypto.axolotl.FingerprintStatus)2 Contact (eu.siacs.conversations.entities.Contact)2 XmppUri (eu.siacs.conversations.utils.XmppUri)2 Element (eu.siacs.conversations.xml.Element)2 XmppConnection (eu.siacs.conversations.xmpp.XmppConnection)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 OtrService (eu.siacs.conversations.crypto.OtrService)1 PgpDecryptionService (eu.siacs.conversations.crypto.PgpDecryptionService)1 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)1