Search in sources :

Example 11 with AxolotlService

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

the class EditAccountActivity method updateAccountInformation.

private void updateAccountInformation(boolean init) {
    if (init) {
        this.mAccountJid.getEditableText().clear();
        if (mUsernameMode) {
            this.mAccountJid.getEditableText().append(this.mAccount.getJid().getLocalpart());
        } else {
            this.mAccountJid.getEditableText().append(this.mAccount.getJid().toBareJid().toString());
        }
        this.mPassword.setText(this.mAccount.getPassword());
        this.mHostname.setText("");
        this.mHostname.getEditableText().append(this.mAccount.getHostname());
        this.mPort.setText("");
        this.mPort.getEditableText().append(String.valueOf(this.mAccount.getPort()));
        this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
    }
    if (!mInitMode) {
        this.mAvatar.setVisibility(View.VISIBLE);
        this.mAvatar.setImageBitmap(avatarService().get(this.mAccount, getPixel(72)));
    } else {
        this.mAvatar.setVisibility(View.GONE);
    }
    if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) {
        this.mRegisterNew.setVisibility(View.VISIBLE);
        this.mRegisterNew.setChecked(true);
        this.mPasswordConfirm.setText(this.mAccount.getPassword());
    } else {
        this.mRegisterNew.setVisibility(View.GONE);
        this.mRegisterNew.setChecked(false);
    }
    if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) {
        Features features = this.mAccount.getXmppConnection().getFeatures();
        this.mStats.setVisibility(View.VISIBLE);
        boolean showBatteryWarning = !xmppConnectionService.getPushManagementService().availableAndUseful(mAccount) && isOptimizingBattery();
        boolean showDataSaverWarning = isAffectedByDataSaver();
        showOsOptimizationWarning(showBatteryWarning, showDataSaverWarning);
        this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection().getLastSessionEstablished()));
        if (features.rosterVersioning()) {
            this.mServerInfoRosterVersion.setText(R.string.server_info_available);
        } else {
            this.mServerInfoRosterVersion.setText(R.string.server_info_unavailable);
        }
        if (features.carbons()) {
            this.mServerInfoCarbons.setText(R.string.server_info_available);
        } else {
            this.mServerInfoCarbons.setText(R.string.server_info_unavailable);
        }
        if (features.mam()) {
            this.mServerInfoMam.setText(R.string.server_info_available);
        } else {
            this.mServerInfoMam.setText(R.string.server_info_unavailable);
        }
        if (features.csi()) {
            this.mServerInfoCSI.setText(R.string.server_info_available);
        } else {
            this.mServerInfoCSI.setText(R.string.server_info_unavailable);
        }
        if (features.blocking()) {
            this.mServerInfoBlocking.setText(R.string.server_info_available);
        } else {
            this.mServerInfoBlocking.setText(R.string.server_info_unavailable);
        }
        if (features.sm()) {
            this.mServerInfoSm.setText(R.string.server_info_available);
        } else {
            this.mServerInfoSm.setText(R.string.server_info_unavailable);
        }
        if (features.pep()) {
            AxolotlService axolotlService = this.mAccount.getAxolotlService();
            if (axolotlService != null && axolotlService.isPepBroken()) {
                this.mServerInfoPep.setText(R.string.server_info_broken);
            } else {
                this.mServerInfoPep.setText(R.string.server_info_available);
            }
        } else {
            this.mServerInfoPep.setText(R.string.server_info_unavailable);
        }
        if (features.httpUpload(0)) {
            this.mServerInfoHttpUpload.setText(R.string.server_info_available);
        } else {
            this.mServerInfoHttpUpload.setText(R.string.server_info_unavailable);
        }
        this.mPushRow.setVisibility(xmppConnectionService.getPushManagementService().isStub() ? View.GONE : View.VISIBLE);
        if (xmppConnectionService.getPushManagementService().available(mAccount)) {
            this.mServerInfoPush.setText(R.string.server_info_available);
        } else {
            this.mServerInfoPush.setText(R.string.server_info_unavailable);
        }
        final String otrFingerprint = this.mAccount.getOtrFingerprint();
        if (otrFingerprint != null && Config.supportOtr()) {
            this.mOtrFingerprintBox.setVisibility(View.VISIBLE);
            this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
            this.mOtrFingerprintToClipboardButton.setVisibility(View.VISIBLE);
            this.mOtrFingerprintToClipboardButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    if (copyTextToClipboard(CryptoHelper.prettifyFingerprint(otrFingerprint), R.string.otr_fingerprint)) {
                        Toast.makeText(EditAccountActivity.this, R.string.toast_message_otr_fingerprint, Toast.LENGTH_SHORT).show();
                    }
                }
            });
        } else {
            this.mOtrFingerprintBox.setVisibility(View.GONE);
        }
        final String ownAxolotlFingerprint = this.mAccount.getAxolotlService().getOwnFingerprint();
        if (ownAxolotlFingerprint != null && Config.supportOmemo()) {
            this.mAxolotlFingerprintBox.setVisibility(View.VISIBLE);
            if (ownAxolotlFingerprint.equals(messageFingerprint)) {
                this.mOwnFingerprintDesc.setTextColor(getResources().getColor(R.color.accent));
            } else {
                this.mOwnFingerprintDesc.setTextColor(getSecondaryTextColor());
            }
            this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(ownAxolotlFingerprint.substring(2)));
            this.mAxolotlFingerprintToClipboardButton.setVisibility(View.VISIBLE);
            this.mAxolotlFingerprintToClipboardButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    copyOmemoFingerprint(ownAxolotlFingerprint);
                }
            });
        } else {
            this.mAxolotlFingerprintBox.setVisibility(View.GONE);
        }
        boolean hasKeys = false;
        keys.removeAllViews();
        for (XmppAxolotlSession session : mAccount.getAxolotlService().findOwnSessions()) {
            if (!session.getTrust().isCompromised()) {
                boolean highlight = session.getFingerprint().equals(messageFingerprint);
                addFingerprintRow(keys, session, highlight);
                hasKeys = true;
            }
        }
        if (hasKeys && Config.supportOmemo()) {
            keysCard.setVisibility(View.VISIBLE);
            Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
            if (otherDevices == null || otherDevices.isEmpty()) {
                mClearDevicesButton.setVisibility(View.GONE);
            } else {
                mClearDevicesButton.setVisibility(View.VISIBLE);
            }
        } else {
            keysCard.setVisibility(View.GONE);
        }
    } else {
        if (this.mAccount.errorStatus()) {
            final EditText errorTextField;
            if (this.mAccount.getStatus() == Account.State.UNAUTHORIZED) {
                errorTextField = this.mPassword;
            } else if (mShowOptions && this.mAccount.getStatus() == Account.State.SERVER_NOT_FOUND && this.mHostname.getText().length() > 0) {
                errorTextField = this.mHostname;
            } else {
                errorTextField = this.mAccountJid;
            }
            errorTextField.setError(getString(this.mAccount.getStatus().getReadableId()));
            if (init || !accountInfoEdited()) {
                errorTextField.requestFocus();
            }
        } else {
            this.mAccountJid.setError(null);
            this.mPassword.setError(null);
            this.mHostname.setError(null);
        }
        this.mStats.setVisibility(View.GONE);
    }
}
Also used : XmppAxolotlSession(eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EditText(android.widget.EditText) AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) Features(eu.siacs.conversations.xmpp.XmppConnection.Features) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 12 with AxolotlService

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

the class TrustKeysActivity method reloadFingerprints.

private boolean reloadFingerprints() {
    List<Jid> acceptedTargets = mConversation == null ? new ArrayList<Jid>() : mConversation.getAcceptedCryptoTargets();
    ownKeysToTrust.clear();
    AxolotlService service = this.mAccount.getAxolotlService();
    Set<IdentityKey> ownKeysSet = service.getKeysWithTrust(FingerprintStatus.createActiveUndecided());
    for (final IdentityKey identityKey : ownKeysSet) {
        if (!ownKeysToTrust.containsKey(identityKey)) {
            ownKeysToTrust.put(identityKey.getFingerprint().replaceAll("\\s", ""), false);
        }
    }
    synchronized (this.foreignKeysToTrust) {
        foreignKeysToTrust.clear();
        for (Jid jid : contactJids) {
            Set<IdentityKey> foreignKeysSet = service.getKeysWithTrust(FingerprintStatus.createActiveUndecided(), jid);
            if (hasNoOtherTrustedKeys(jid) && ownKeysSet.size() == 0) {
                foreignKeysSet.addAll(service.getKeysWithTrust(FingerprintStatus.createActive(false), jid));
            }
            Map<String, Boolean> foreignFingerprints = new HashMap<>();
            for (final IdentityKey identityKey : foreignKeysSet) {
                if (!foreignFingerprints.containsKey(identityKey)) {
                    foreignFingerprints.put(identityKey.getFingerprint().replaceAll("\\s", ""), false);
                }
            }
            if (foreignFingerprints.size() > 0 || !acceptedTargets.contains(jid)) {
                foreignKeysToTrust.put(jid, foreignFingerprints);
            }
        }
    }
    return ownKeysSet.size() + foreignKeysToTrust.size() > 0;
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) IdentityKey(org.whispersystems.libaxolotl.IdentityKey) Jid(eu.siacs.conversations.xmpp.jid.Jid) HashMap(java.util.HashMap)

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