From beaec159e8ee76c9cb598ec3a1a6cff8c46c355b Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Fri, 17 Apr 2020 23:42:48 +0530 Subject: Update SSH clear passphrase preference to handle HTTPS (#716) * Update SSH clear passphrase preference to handle HTTPS Signed-off-by: Harsh Shandilya * Address review comments Signed-off-by: Harsh Shandilya * Address review comments Signed-off-by: Harsh Shandilya * Explicitly set preference to visible if it can do anything * Address review comments Co-authored-by: Fabian Henneke Co-authored-by: Fabian Henneke --- .../main/java/com/zeapo/pwdstore/UserPreference.kt | 40 ++++++++++++++++++---- app/src/main/res/values-es/strings.xml | 1 - app/src/main/res/values-fr/strings.xml | 1 - app/src/main/res/values-ru/strings.xml | 1 - app/src/main/res/values/strings.xml | 3 +- app/src/main/res/xml/preference.xml | 4 +-- 6 files changed, 36 insertions(+), 14 deletions(-) (limited to 'app') diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt b/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt index eabc35f4..5756d477 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt @@ -8,6 +8,7 @@ import android.accessibilityservice.AccessibilityServiceInfo import android.annotation.SuppressLint import android.app.Activity import android.content.Intent +import android.content.SharedPreferences import android.content.pm.ShortcutManager import android.net.Uri import android.os.Build @@ -23,6 +24,7 @@ import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.AppCompatTextView import androidx.biometric.BiometricManager +import androidx.core.content.edit import androidx.core.content.getSystemService import androidx.documentfile.provider.DocumentFile import androidx.preference.CheckBoxPreference @@ -67,15 +69,17 @@ class UserPreference : AppCompatActivity() { class PrefsFragment : PreferenceFragmentCompat() { private var autoFillEnablePreference: SwitchPreferenceCompat? = null + private var clearSavedPassPreference: Preference? = null private lateinit var autofillDependencies: List private lateinit var oreoAutofillDependencies: List private lateinit var callingActivity: UserPreference + private lateinit var encryptedPreferences: SharedPreferences override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { callingActivity = requireActivity() as UserPreference val context = requireContext() val sharedPreferences = preferenceManager.sharedPreferences - val encryptedPreferences = requireActivity().applicationContext.getEncryptedPrefs("git_operation") + encryptedPreferences = requireActivity().applicationContext.getEncryptedPrefs("git_operation") addPreferencesFromResource(R.xml.preference) @@ -85,7 +89,7 @@ class UserPreference : AppCompatActivity() { val gitConfigPreference = findPreference("git_config") val sshKeyPreference = findPreference("ssh_key") val sshKeygenPreference = findPreference("ssh_keygen") - val sshClearPassphrasePreference = findPreference("ssh_key_clear_passphrase") + clearSavedPassPreference = findPreference("clear_saved_pass") val clearHotpIncrementPreference = findPreference("hotp_remember_clear_choice") val viewSshKeyPreference = findPreference("ssh_see_key") val deleteRepoPreference = findPreference("git_delete_repo") @@ -124,8 +128,6 @@ class UserPreference : AppCompatActivity() { selectExternalGitRepositoryPreference?.summary = sharedPreferences.getString("git_external_repo", getString(R.string.no_repo_selected)) viewSshKeyPreference?.isVisible = sharedPreferences.getBoolean("use_generated_key", false) deleteRepoPreference?.isVisible = !sharedPreferences.getBoolean("git_external", false) - sshClearPassphrasePreference?.isVisible = encryptedPreferences.getString("ssh_key_local_passphrase", null)?.isNotEmpty() - ?: false clearHotpIncrementPreference?.isVisible = sharedPreferences.getBoolean("hotp_remember_check", false) clearAfterCopyPreference?.isVisible = sharedPreferences.getString("general_show_time", "45")?.toInt() != 0 clearClipboard20xPreference?.isVisible = sharedPreferences.getString("general_show_time", "45")?.toInt() != 0 @@ -142,6 +144,7 @@ class UserPreference : AppCompatActivity() { ?: false updateAutofillSettings() + updateClearSavedPassphrasePrefs() appVersionPreference?.summary = "Version: ${BuildConfig.VERSION_NAME}" @@ -174,9 +177,14 @@ class UserPreference : AppCompatActivity() { true } - sshClearPassphrasePreference?.onPreferenceClickListener = ClickListener { - encryptedPreferences.edit().putString("ssh_key_local_passphrase", null).apply() - it.isVisible = false + clearSavedPassPreference?.onPreferenceClickListener = ClickListener { + encryptedPreferences.edit { + if (encryptedPreferences.getString("https_password", null) != null) + remove("https_password") + else if (encryptedPreferences.getString("ssh_key_local_passphrase", null) != null) + remove("ssh_key_local_passphrase") + } + updateClearSavedPassphrasePrefs() true } @@ -374,6 +382,23 @@ class UserPreference : AppCompatActivity() { } } + private fun updateClearSavedPassphrasePrefs() { + clearSavedPassPreference?.apply { + val sshPass = encryptedPreferences.getString("ssh_key_local_passphrase", null) + val httpsPass = encryptedPreferences.getString("https_password", null) + if (sshPass == null && httpsPass == null) { + isVisible = false + return@apply + } + title = when { + httpsPass != null -> getString(R.string.clear_saved_passphrase_https) + sshPass != null -> getString(R.string.clear_saved_passphrase_ssh) + else -> null + } + isVisible = true + } + } + private fun onEnableAutofillClick() { if (callingActivity.isAccessibilityServiceEnabled) { startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)) @@ -431,6 +456,7 @@ class UserPreference : AppCompatActivity() { override fun onResume() { super.onResume() updateAutofillSettings() + updateClearSavedPassphrasePrefs() } } diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index aeb0a133..55cc3cda 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -216,7 +216,6 @@ La subida fue rechazada por el servidor, Ejecuta \'Descargar desde servidor\' antes de subir o pulsa \'Sincronizar con servidor\' para realizar ambas acciones. El envío fue rechazado por el servidor, la razón: Ocurrió un error durante el envío: - Limpiar contraseña guardada de llave SSH Limpiar preferencia para incremento HOTP Recordar contraseñagit (inseguro) Hackish tools diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 8461d96d..7a28dd82 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -217,7 +217,6 @@ Poussée rejetée par le dépôt distant, raison: Pousser au dépôt distant sans avance rapide rejetée. Vérifiez la variable receive.denyNonFastForwards dans le fichier de configuration du répertoire de destination. Une erreur s\'est produite lors de l\'opération de poussée: - Effacer la phrase secrète enregistrée par ssh-key Effacer les préférences enregistrées pour l’incrémentation HOTP Se rappeler de la phrase secrète dans la configuration de l\'application (peu sûr) Outils de hack diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 04d7b837..051ab024 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -279,7 +279,6 @@ Запись изменений была отклонена удаленным репозиторием, причина: Удаленный репозиторий отклонил запись изменений без быстрой перемотки вперед. Проверьте переменную receive.denyNonFastForwards в файле конфигурации репозитория назначения. В хоте операции записи изменений возникла ошибка: - Очистить сохраненную парольную фразу ключа ssh Очистить сохраненные настройки для увеличения HOTP Заполнить парольную фразу в конфигурации приложнеия (небезопасно) Костыльные инструменты diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dafad85a..acedf8e3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -307,7 +307,8 @@ Push was rejected by remote, reason: Remote rejected non-fast-forward push. Check receive.denyNonFastForwards variable in config file of destination repository. Error occurred during the push operation: - Clear ssh-key saved passphrase + Clear saved passphrase for local SSH key + Clear saved HTTPS password Clear saved preference for HOTP incrementing Remember key passphrase Hackish tools diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index fc041ee1..abc40a8e 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -45,9 +45,7 @@ - + -- cgit v1.2.3