From 1e75e9a32fbc9fae7abf624737c599d806c99e2e Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Thu, 2 Feb 2023 19:37:10 +0100 Subject: [PATCH] Clear password fields onStop() --- app/libcryfs | 2 +- .../droidfs/ChangePasswordActivity.kt | 7 ++++ .../sushi/hardcore/droidfs/MainActivity.kt | 1 + .../sushi/hardcore/droidfs/VolumeOpener.kt | 38 +++++++++++-------- .../add_volume/CreateVolumeFragment.kt | 6 +++ gradle.properties | 2 - 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/app/libcryfs b/app/libcryfs index a1c3f81..ba5df73 160000 --- a/app/libcryfs +++ b/app/libcryfs @@ -1 +1 @@ -Subproject commit a1c3f814d5c2597401918944094d16aa37b15bec +Subproject commit ba5df7390b68fba3dba53d2231e2fb38d1c7632c diff --git a/app/src/main/java/sushi/hardcore/droidfs/ChangePasswordActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/ChangePasswordActivity.kt index 5acb8ed..d4d0098 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/ChangePasswordActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/ChangePasswordActivity.kt @@ -207,4 +207,11 @@ class ChangePasswordActivity: BaseActivity() { } } } + + override fun onStop() { + super.onStop() + binding.editCurrentPassword.text.clear() + binding.editNewPassword.text.clear() + binding.editPasswordConfirm.text.clear() + } } \ No newline at end of file diff --git a/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt index dc7667e..d4e2c79 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt @@ -475,6 +475,7 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener { override fun onStop() { super.onStop() + volumeOpener.wipeSensitive() if (explorerRouter.pickMode && !usfKeepOpen && shouldCloseVolume) { IntentUtils.getParcelableExtra(intent, "volume")?.close() RestrictedFileProvider.wipeAll(this) diff --git a/app/src/main/java/sushi/hardcore/droidfs/VolumeOpener.kt b/app/src/main/java/sushi/hardcore/droidfs/VolumeOpener.kt index 873e723..bdc114c 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/VolumeOpener.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/VolumeOpener.kt @@ -30,6 +30,7 @@ class VolumeOpener( private val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity) var themeValue = sharedPrefs.getString(ConstValues.THEME_VALUE_KEY, ConstValues.DEFAULT_THEME_VALUE)!! var defaultVolumeName: String? = sharedPrefs.getString(DEFAULT_VOLUME_KEY, null) + private var dialogBinding: DialogOpenVolumeBinding? = null init { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -90,10 +91,14 @@ class VolumeOpener( } } - private fun onPasswordSubmitted(volume: VolumeData, isVolumeSaved: Boolean, dialogBinding: DialogOpenVolumeBinding, callbacks: VolumeOpenerCallbacks) { - if (dialogBinding.checkboxDefaultOpen.isChecked xor (defaultVolumeName == volume.name)) { + fun wipeSensitive() { + dialogBinding?.editPassword?.text?.clear() + } + + private fun onPasswordSubmitted(volume: VolumeData, isVolumeSaved: Boolean, callbacks: VolumeOpenerCallbacks) { + if (dialogBinding!!.checkboxDefaultOpen.isChecked xor (defaultVolumeName == volume.name)) { with (sharedPrefs.edit()) { - defaultVolumeName = if (dialogBinding.checkboxDefaultOpen.isChecked) { + defaultVolumeName = if (dialogBinding!!.checkboxDefaultOpen.isChecked) { putString(DEFAULT_VOLUME_KEY, volume.name) volume.name } else { @@ -103,41 +108,44 @@ class VolumeOpener( apply() } } + val password = WidgetUtil.encodeEditTextContent(dialogBinding!!.editPassword) + val savePasswordHash = dialogBinding!!.checkboxSavePassword.isChecked + dialogBinding = null // openVolumeWithPassword is responsible for wiping the password openVolumeWithPassword( volume, - WidgetUtil.encodeEditTextContent(dialogBinding.editPassword), + password, isVolumeSaved, - dialogBinding.checkboxSavePassword.isChecked, + savePasswordHash, callbacks, ) } private fun askForPassword(volume: VolumeData, isVolumeSaved: Boolean, callbacks: VolumeOpenerCallbacks, savePasswordHash: Boolean = false) { - val dialogBinding = DialogOpenVolumeBinding.inflate(activity.layoutInflater) + dialogBinding = DialogOpenVolumeBinding.inflate(activity.layoutInflater) if (isVolumeSaved) { if (!sharedPrefs.getBoolean("usf_fingerprint", false) || fingerprintProtector == null || volume.encryptedHash != null) { - dialogBinding.checkboxSavePassword.visibility = View.GONE + dialogBinding!!.checkboxSavePassword.visibility = View.GONE } else { - dialogBinding.checkboxSavePassword.isChecked = savePasswordHash + dialogBinding!!.checkboxSavePassword.isChecked = savePasswordHash } - dialogBinding.checkboxDefaultOpen.isChecked = defaultVolumeName == volume.name + dialogBinding!!.checkboxDefaultOpen.isChecked = defaultVolumeName == volume.name } else { - dialogBinding.checkboxSavePassword.visibility = View.GONE - dialogBinding.checkboxDefaultOpen.visibility = View.GONE + dialogBinding!!.checkboxSavePassword.visibility = View.GONE + dialogBinding!!.checkboxDefaultOpen.visibility = View.GONE } val dialog = CustomAlertDialogBuilder(activity, themeValue) .setTitle(activity.getString(R.string.open_dialog_title, volume.shortName)) - .setView(dialogBinding.root) + .setView(dialogBinding!!.root) .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.open) { _, _ -> - onPasswordSubmitted(volume, isVolumeSaved, dialogBinding, callbacks) + onPasswordSubmitted(volume, isVolumeSaved, callbacks) } .create() - dialogBinding.editPassword.apply { + dialogBinding!!.editPassword.apply { setOnEditorActionListener { _, _, _ -> dialog.dismiss() - onPasswordSubmitted(volume, isVolumeSaved, dialogBinding, callbacks) + onPasswordSubmitted(volume, isVolumeSaved, callbacks) true } if (sharedPrefs.getBoolean(ConstValues.PIN_PASSWORDS_KEY, false)) { diff --git a/app/src/main/java/sushi/hardcore/droidfs/add_volume/CreateVolumeFragment.kt b/app/src/main/java/sushi/hardcore/droidfs/add_volume/CreateVolumeFragment.kt index 0cb5b55..0752c1b 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/add_volume/CreateVolumeFragment.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/add_volume/CreateVolumeFragment.kt @@ -263,4 +263,10 @@ class CreateVolumeFragment: Fragment() { } } } + + override fun onStop() { + super.onStop() + binding.editPassword.text.clear() + binding.editPasswordConfirm.text.clear() + } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 4b2efe1..155fba7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,8 +15,6 @@ org.gradle.jvmargs=-Xmx2048m # Android operating system, and which are packaged with your app"s APK # https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true -# Automatically convert third-party libraries to use AndroidX -android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official