diff options
author | Harsh Shandilya <msfjarvis@gmail.com> | 2020-04-17 23:42:48 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-17 20:12:48 +0200 |
commit | beaec159e8ee76c9cb598ec3a1a6cff8c46c355b (patch) | |
tree | 8083bb9459db5c4bef25343b5974d697e0bb0a6c | |
parent | 0e1dd641d2d3cfc61b1deb54fe0bb340315f03a1 (diff) |
Update SSH clear passphrase preference to handle HTTPS (#716)
* Update SSH clear passphrase preference to handle HTTPS
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
* Address review comments
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
* Address review comments
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
* Explicitly set preference to visible if it can do anything
* Address review comments
Co-authored-by: Fabian Henneke <FabianHenneke@users.noreply.github.com>
Co-authored-by: Fabian Henneke <fabian@henneke.me>
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/UserPreference.kt | 40 | ||||
-rw-r--r-- | app/src/main/res/values-es/strings.xml | 1 | ||||
-rw-r--r-- | app/src/main/res/values-fr/strings.xml | 1 | ||||
-rw-r--r-- | app/src/main/res/values-ru/strings.xml | 1 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 3 | ||||
-rw-r--r-- | app/src/main/res/xml/preference.xml | 4 |
6 files changed, 36 insertions, 14 deletions
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<Preference> private lateinit var oreoAutofillDependencies: List<Preference> 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<Preference>("git_config") val sshKeyPreference = findPreference<Preference>("ssh_key") val sshKeygenPreference = findPreference<Preference>("ssh_keygen") - val sshClearPassphrasePreference = findPreference<Preference>("ssh_key_clear_passphrase") + clearSavedPassPreference = findPreference("clear_saved_pass") val clearHotpIncrementPreference = findPreference<Preference>("hotp_remember_clear_choice") val viewSshKeyPreference = findPreference<Preference>("ssh_see_key") val deleteRepoPreference = findPreference<Preference>("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 @@ <string name="git_push_nff_error">La subida fue rechazada por el servidor, Ejecuta \'Descargar desde servidor\' antes de subir o pulsa \'Sincronizar con servidor\' para realizar ambas acciones.</string> <string name="git_push_generic_error">El envío fue rechazado por el servidor, la razón:</string> <string name="jgit_error_push_dialog_text">Ocurrió un error durante el envío:</string> - <string name="ssh_key_clear_passphrase">Limpiar contraseña guardada de llave SSH</string> <string name="hotp_remember_clear_choice">Limpiar preferencia para incremento HOTP</string> <string name="remember_the_passphrase">Recordar contraseñagit (inseguro)</string> <string name="hackish_tools">Hackish tools</string> 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 @@ <string name="git_push_generic_error">Poussée rejetée par le dépôt distant, raison:</string> <string name="git_push_other_error">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.</string> <string name="jgit_error_push_dialog_text">Une erreur s\'est produite lors de l\'opération de poussée:</string> - <string name="ssh_key_clear_passphrase">Effacer la phrase secrète enregistrée par ssh-key</string> <string name="hotp_remember_clear_choice">Effacer les préférences enregistrées pour l’incrémentation HOTP</string> <string name="remember_the_passphrase">Se rappeler de la phrase secrète dans la configuration de l\'application (peu sûr)</string> <string name="hackish_tools">Outils de hack</string> 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 @@ <string name="git_push_generic_error">Запись изменений была отклонена удаленным репозиторием, причина:</string> <string name="git_push_other_error">Удаленный репозиторий отклонил запись изменений без быстрой перемотки вперед. Проверьте переменную receive.denyNonFastForwards в файле конфигурации репозитория назначения.</string> <string name="jgit_error_push_dialog_text">В хоте операции записи изменений возникла ошибка:</string> - <string name="ssh_key_clear_passphrase">Очистить сохраненную парольную фразу ключа ssh</string> <string name="hotp_remember_clear_choice">Очистить сохраненные настройки для увеличения HOTP</string> <string name="remember_the_passphrase">Заполнить парольную фразу в конфигурации приложнеия (небезопасно)</string> <string name="hackish_tools">Костыльные инструменты</string> 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 @@ <string name="git_push_generic_error">Push was rejected by remote, reason:</string> <string name="git_push_other_error">Remote rejected non-fast-forward push. Check receive.denyNonFastForwards variable in config file of destination repository.</string> <string name="jgit_error_push_dialog_text">Error occurred during the push operation:</string> - <string name="ssh_key_clear_passphrase">Clear ssh-key saved passphrase</string> + <string name="clear_saved_passphrase_ssh">Clear saved passphrase for local SSH key</string> + <string name="clear_saved_passphrase_https">Clear saved HTTPS password</string> <string name="hotp_remember_clear_choice">Clear saved preference for HOTP incrementing</string> <string name="remember_the_passphrase">Remember key passphrase</string> <string name="hackish_tools">Hackish tools</string> 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 @@ <androidx.preference.Preference app:key="ssh_keygen" app:title="@string/pref_ssh_keygen_title" /> - <androidx.preference.Preference - app:key="ssh_key_clear_passphrase" - app:title="@string/ssh_key_clear_passphrase" /> + <androidx.preference.Preference app:key="clear_saved_pass" /> <androidx.preference.Preference app:key="hotp_remember_clear_choice" app:title="@string/hotp_remember_clear_choice" /> |