Search in sources :

Example 1 with FingerprintStatus

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

the class XmppConnectionService method verifyFingerprints.

public boolean verifyFingerprints(Contact contact, List<XmppUri.Fingerprint> fingerprints) {
    boolean needsRosterWrite = false;
    boolean performedVerification = false;
    final AxolotlService axolotlService = contact.getAccount().getAxolotlService();
    for (XmppUri.Fingerprint fp : fingerprints) {
        if (fp.type == XmppUri.FingerprintType.OTR) {
            performedVerification |= contact.addOtrFingerprint(fp.fingerprint);
            needsRosterWrite |= performedVerification;
        } else if (fp.type == XmppUri.FingerprintType.OMEMO) {
            String fingerprint = "05" + fp.fingerprint.replaceAll("\\s", "");
            FingerprintStatus fingerprintStatus = axolotlService.getFingerprintTrust(fingerprint);
            if (fingerprintStatus != null) {
                if (!fingerprintStatus.isVerified()) {
                    performedVerification = true;
                    axolotlService.setFingerprintTrust(fingerprint, fingerprintStatus.toVerified());
                }
            } else {
                axolotlService.preVerifyFingerprint(contact, fingerprint);
            }
        }
    }
    if (needsRosterWrite) {
        syncRosterToDisk(contact.getAccount());
    }
    return performedVerification;
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) XmppUri(eu.siacs.conversations.utils.XmppUri) FingerprintStatus(eu.siacs.conversations.crypto.axolotl.FingerprintStatus)

Example 2 with FingerprintStatus

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

the class OmemoActivity method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    Object account = v.getTag(R.id.TAG_ACCOUNT);
    Object fingerprint = v.getTag(R.id.TAG_FINGERPRINT);
    Object fingerprintStatus = v.getTag(R.id.TAG_FINGERPRINT_STATUS);
    ;
    if (account != null && fingerprint != null && account instanceof Account && fingerprintStatus != null && fingerprint instanceof String && fingerprintStatus instanceof FingerprintStatus) {
        getMenuInflater().inflate(R.menu.omemo_key_context, menu);
        MenuItem distrust = menu.findItem(R.id.distrust_key);
        MenuItem verifyScan = menu.findItem(R.id.verify_scan);
        if (this instanceof TrustKeysActivity) {
            distrust.setVisible(false);
            verifyScan.setVisible(false);
        } else {
            FingerprintStatus status = (FingerprintStatus) fingerprintStatus;
            if (!status.isActive() || status.isVerified()) {
                verifyScan.setVisible(false);
            }
            distrust.setVisible(status.isVerified());
        }
        this.mSelectedAccount = (Account) account;
        this.mSelectedFingerprint = (String) fingerprint;
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) FingerprintStatus(eu.siacs.conversations.crypto.axolotl.FingerprintStatus) MenuItem(android.view.MenuItem)

Example 3 with FingerprintStatus

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

the class DatabaseBackend method getFingerprintStatus.

public FingerprintStatus getFingerprintStatus(Account account, String fingerprint) {
    Cursor cursor = getIdentityKeyCursor(account, fingerprint);
    final FingerprintStatus status;
    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        status = FingerprintStatus.fromCursor(cursor);
    } else {
        status = null;
    }
    cursor.close();
    return status;
}
Also used : FingerprintStatus(eu.siacs.conversations.crypto.axolotl.FingerprintStatus) Cursor(android.database.Cursor)

Example 4 with FingerprintStatus

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

the class ContactDetailsActivity method populateView.

private void populateView() {
    if (contact == null) {
        return;
    }
    invalidateOptionsMenu();
    setTitle(contact.getDisplayName());
    if (contact.showInRoster()) {
        send.setVisibility(View.VISIBLE);
        receive.setVisibility(View.VISIBLE);
        addContactButton.setVisibility(View.GONE);
        send.setOnCheckedChangeListener(null);
        receive.setOnCheckedChangeListener(null);
        List<String> statusMessages = contact.getPresences().getStatusMessages();
        if (statusMessages.size() == 0) {
            statusMessage.setVisibility(View.GONE);
        } else {
            StringBuilder builder = new StringBuilder();
            statusMessage.setVisibility(View.VISIBLE);
            int s = statusMessages.size();
            for (int i = 0; i < s; ++i) {
                if (s > 1) {
                    builder.append("• ");
                }
                builder.append(statusMessages.get(i));
                if (i < s - 1) {
                    builder.append("\n");
                }
            }
            statusMessage.setText(builder);
        }
        if (contact.getOption(Contact.Options.FROM)) {
            send.setText(R.string.send_presence_updates);
            send.setChecked(true);
        } else if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
            send.setChecked(false);
            send.setText(R.string.send_presence_updates);
        } else {
            send.setText(R.string.preemptively_grant);
            if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
                send.setChecked(true);
            } else {
                send.setChecked(false);
            }
        }
        if (contact.getOption(Contact.Options.TO)) {
            receive.setText(R.string.receive_presence_updates);
            receive.setChecked(true);
        } else {
            receive.setText(R.string.ask_for_presence_updates);
            if (contact.getOption(Contact.Options.ASKING)) {
                receive.setChecked(true);
            } else {
                receive.setChecked(false);
            }
        }
        if (contact.getAccount().isOnlineAndConnected()) {
            receive.setEnabled(true);
            send.setEnabled(true);
        } else {
            receive.setEnabled(false);
            send.setEnabled(false);
        }
        send.setOnCheckedChangeListener(this.mOnSendCheckedChange);
        receive.setOnCheckedChangeListener(this.mOnReceiveCheckedChange);
    } else {
        addContactButton.setVisibility(View.VISIBLE);
        send.setVisibility(View.GONE);
        receive.setVisibility(View.GONE);
        statusMessage.setVisibility(View.GONE);
    }
    if (contact.isBlocked() && !this.showDynamicTags) {
        lastseen.setVisibility(View.VISIBLE);
        lastseen.setText(R.string.contact_blocked);
    } else {
        if (showLastSeen && contact.getLastseen() > 0) {
            lastseen.setVisibility(View.VISIBLE);
            lastseen.setText(UIHelper.lastseen(getApplicationContext(), contact.isActive(), contact.getLastseen()));
        } else {
            lastseen.setVisibility(View.GONE);
        }
    }
    if (contact.getPresences().size() > 1) {
        contactJidTv.setText(contact.getDisplayJid() + " (" + contact.getPresences().size() + ")");
    } else {
        contactJidTv.setText(contact.getDisplayJid());
    }
    String account;
    if (Config.DOMAIN_LOCK != null) {
        account = contact.getAccount().getJid().getLocalpart();
    } else {
        account = contact.getAccount().getJid().toBareJid().toString();
    }
    accountJidTv.setText(getString(R.string.using_account, account));
    badge.setImageBitmap(avatarService().get(contact, getPixel(72)));
    badge.setOnClickListener(this.onBadgeClick);
    keys.removeAllViews();
    boolean hasKeys = false;
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (Config.supportOtr()) {
        for (final String otrFingerprint : contact.getOtrFingerprints()) {
            hasKeys = true;
            View view = inflater.inflate(R.layout.contact_key, keys, false);
            TextView key = (TextView) view.findViewById(R.id.key);
            TextView keyType = (TextView) view.findViewById(R.id.key_type);
            ImageButton removeButton = (ImageButton) view.findViewById(R.id.button_remove);
            removeButton.setVisibility(View.VISIBLE);
            key.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
            if (otrFingerprint != null && otrFingerprint.equals(messageFingerprint)) {
                keyType.setText(R.string.otr_fingerprint_selected_message);
                keyType.setTextColor(getResources().getColor(R.color.accent));
            } else {
                keyType.setText(R.string.otr_fingerprint);
            }
            keys.addView(view);
            removeButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    confirmToDeleteFingerprint(otrFingerprint);
                }
            });
        }
    }
    if (Config.supportOmemo()) {
        boolean skippedInactive = false;
        boolean showsInactive = false;
        for (final XmppAxolotlSession session : contact.getAccount().getAxolotlService().findSessionsForContact(contact)) {
            final FingerprintStatus trust = session.getTrust();
            hasKeys |= !trust.isCompromised();
            if (!trust.isActive()) {
                if (showInactiveOmemo) {
                    showsInactive = true;
                } else {
                    skippedInactive = true;
                    continue;
                }
            }
            if (!trust.isCompromised()) {
                boolean highlight = session.getFingerprint().equals(messageFingerprint);
                addFingerprintRow(keys, session, highlight);
            }
        }
        if (showsInactive || skippedInactive) {
            mShowInactiveDevicesButton.setText(showsInactive ? R.string.hide_inactive_devices : R.string.show_inactive_devices);
            mShowInactiveDevicesButton.setVisibility(View.VISIBLE);
        } else {
            mShowInactiveDevicesButton.setVisibility(View.GONE);
        }
    } else {
        mShowInactiveDevicesButton.setVisibility(View.GONE);
    }
    if (Config.supportOpenPgp() && contact.getPgpKeyId() != 0) {
        hasKeys = true;
        View view = inflater.inflate(R.layout.contact_key, keys, false);
        TextView key = (TextView) view.findViewById(R.id.key);
        TextView keyType = (TextView) view.findViewById(R.id.key_type);
        keyType.setText(R.string.openpgp_key_id);
        if ("pgp".equals(messageFingerprint)) {
            keyType.setTextColor(getResources().getColor(R.color.accent));
        }
        key.setText(OpenPgpUtils.convertKeyIdToHex(contact.getPgpKeyId()));
        view.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                PgpEngine pgp = ContactDetailsActivity.this.xmppConnectionService.getPgpEngine();
                if (pgp != null) {
                    PendingIntent intent = pgp.getIntentForKey(contact);
                    if (intent != null) {
                        try {
                            startIntentSenderForResult(intent.getIntentSender(), 0, null, 0, 0, 0);
                        } catch (SendIntentException e) {
                        }
                    }
                }
            }
        });
        keys.addView(view);
    }
    keysWrapper.setVisibility(hasKeys ? View.VISIBLE : View.GONE);
    List<ListItem.Tag> tagList = contact.getTags(this);
    if (tagList.size() == 0 || !this.showDynamicTags) {
        tags.setVisibility(View.GONE);
    } else {
        tags.setVisibility(View.VISIBLE);
        tags.removeAllViewsInLayout();
        for (final ListItem.Tag tag : tagList) {
            final TextView tv = (TextView) inflater.inflate(R.layout.list_item_tag, tags, false);
            tv.setText(tag.getName());
            tv.setBackgroundColor(tag.getColor());
            tags.addView(tv);
        }
    }
}
Also used : FingerprintStatus(eu.siacs.conversations.crypto.axolotl.FingerprintStatus) PgpEngine(eu.siacs.conversations.crypto.PgpEngine) View(android.view.View) TextView(android.widget.TextView) SendIntentException(android.content.IntentSender.SendIntentException) XmppAxolotlSession(eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession) ImageButton(android.widget.ImageButton) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) PendingIntent(android.app.PendingIntent) ListItem(eu.siacs.conversations.entities.ListItem)

Example 5 with FingerprintStatus

use of eu.siacs.conversations.crypto.axolotl.FingerprintStatus 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

FingerprintStatus (eu.siacs.conversations.crypto.axolotl.FingerprintStatus)6 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)2 XmppUri (eu.siacs.conversations.utils.XmppUri)2 PendingIntent (android.app.PendingIntent)1 SendIntentException (android.content.IntentSender.SendIntentException)1 Cursor (android.database.Cursor)1 SpannableString (android.text.SpannableString)1 LayoutInflater (android.view.LayoutInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageButton (android.widget.ImageButton)1 TextView (android.widget.TextView)1 PgpEngine (eu.siacs.conversations.crypto.PgpEngine)1 XmppAxolotlSession (eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession)1 Account (eu.siacs.conversations.entities.Account)1 ListItem (eu.siacs.conversations.entities.ListItem)1 FileParams (eu.siacs.conversations.entities.Message.FileParams)1 Transferable (eu.siacs.conversations.entities.Transferable)1