Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 942d8e4a authored by ByteHamster's avatar ByteHamster
Browse files

Authenticate user before showing password

parent 591af9cd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ dependencies {
    implementation "com.takisoft.preferencex:preferencex-datetimepicker:${versions.preferencesFix}"
    implementation "com.takisoft.preferencex:preferencex-colorpicker:${versions.preferencesFix}"
    implementation "com.takisoft.preferencex:preferencex-ringtone:${versions.preferencesFix}"
    implementation "androidx.biometric:biometric:${versions.androidxBiometric}"
    implementation "androidx.recyclerview:recyclerview:${versions.androidxRecyclerView}"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:${versions.androidxLifecycle}"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:${versions.androidxLifecycle}"
+42 −2
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
@@ -19,11 +20,13 @@ import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.biometric.BiometricManager.Authenticators;
import androidx.biometric.BiometricPrompt;
import androidx.core.content.ContextCompat;
import com.fsck.k9.Account;
import com.fsck.k9.Account.FolderMode;
import com.fsck.k9.DI;
import com.fsck.k9.LocalKeyStoreManager;
import com.fsck.k9.Preferences;
@@ -182,6 +185,18 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener

        boolean editSettings = Intent.ACTION_EDIT.equals(getIntent().getAction());

        mPasswordLayoutView.setEndIconOnClickListener(v -> {
            if (mPasswordView.getTransformationMethod() instanceof PasswordTransformationMethod) {
                if (editSettings) {
                    authenticateUserAndShowPassword();
                } else {
                    mPasswordView.setTransformationMethod(null);
                }
            } else {
                mPasswordView.setTransformationMethod(PasswordTransformationMethod.getInstance());
            }
        });

        try {
            ServerSettings settings = mAccount.getIncomingServerSettings();

@@ -616,6 +631,31 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener

    }

    private void authenticateUserAndShowPassword() {
        new BiometricPrompt(this, ContextCompat.getMainExecutor(this), new BiometricPrompt.AuthenticationCallback() {
            @Override
            public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
                mPasswordView.setTransformationMethod(null);
            }

            @Override
            public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
                if (errorCode == BiometricPrompt.ERROR_HW_NOT_PRESENT
                        || errorCode == BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL) {
                    Toast.makeText(AccountSetupIncoming.this, R.string.account_setup_basics_show_password_need_lock,
                            Toast.LENGTH_SHORT).show();
                } else if (errString.length() != 0) {
                    Toast.makeText(AccountSetupIncoming.this, errString, Toast.LENGTH_SHORT).show();
                }
            }
        }).authenticate(new BiometricPrompt.PromptInfo.Builder()
                .setAllowedAuthenticators(Authenticators.BIOMETRIC_STRONG
                        | Authenticators.BIOMETRIC_WEAK | Authenticators.DEVICE_CREDENTIAL)
                .setTitle(getString(R.string.account_setup_basics_show_password_biometrics_title))
                .setSubtitle(getString(R.string.account_setup_basics_show_password_biometrics_subtitle))
                .build());
    }

    public void onClick(View v) {
        try {
            if (v.getId() == R.id.next) {
+44 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
@@ -20,6 +21,10 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Spinner;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.biometric.BiometricManager.Authenticators;
import androidx.biometric.BiometricPrompt;
import androidx.core.content.ContextCompat;
import com.fsck.k9.Account;
import com.fsck.k9.DI;
import com.fsck.k9.LocalKeyStoreManager;
@@ -148,6 +153,20 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
            mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
        }

        boolean editSettings = Intent.ACTION_EDIT.equals(getIntent().getAction());

        mPasswordLayoutView.setEndIconOnClickListener(v -> {
            if (mPasswordView.getTransformationMethod() instanceof PasswordTransformationMethod) {
                if (editSettings) {
                    authenticateUserAndShowPassword();
                } else {
                    mPasswordView.setTransformationMethod(null);
                }
            } else {
                mPasswordView.setTransformationMethod(PasswordTransformationMethod.getInstance());
            }
        });

        try {
            ServerSettings settings = mAccount.getOutgoingServerSettings();

@@ -498,6 +517,31 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
        AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.OUTGOING);
    }

    private void authenticateUserAndShowPassword() {
        new BiometricPrompt(this, ContextCompat.getMainExecutor(this), new BiometricPrompt.AuthenticationCallback() {
            @Override
            public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
                mPasswordView.setTransformationMethod(null);
            }

            @Override
            public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
                if (errorCode == BiometricPrompt.ERROR_HW_NOT_PRESENT
                        || errorCode == BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL) {
                    Toast.makeText(AccountSetupOutgoing.this, R.string.account_setup_basics_show_password_need_lock,
                            Toast.LENGTH_SHORT).show();
                } else if (errString.length() != 0) {
                    Toast.makeText(AccountSetupOutgoing.this, errString, Toast.LENGTH_SHORT).show();
                }
            }
        }).authenticate(new BiometricPrompt.PromptInfo.Builder()
                .setAllowedAuthenticators(Authenticators.BIOMETRIC_STRONG
                        | Authenticators.BIOMETRIC_WEAK | Authenticators.DEVICE_CREDENTIAL)
                .setTitle(getString(R.string.account_setup_basics_show_password_biometrics_title))
                .setSubtitle(getString(R.string.account_setup_basics_show_password_biometrics_subtitle))
                .build());
    }

    public void onClick(View v) {
        if (v.getId() == R.id.next) {
            onNext();
+1 −1
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/account_setup_margin_between_items_incoming_and_outgoing"
                    app:passwordToggleEnabled="true">
                    app:endIconMode="password_toggle">

                <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/account_password"
+1 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/account_setup_margin_between_items_incoming_and_outgoing"
                    app:passwordToggleEnabled="true">
                    app:endIconMode="password_toggle">

                    <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/account_password"
Loading