From 1dc5d82604d7c56ec5c993871725dd9ce5ba1519 Mon Sep 17 00:00:00 2001 From: Fabian Henneke Date: Wed, 12 Aug 2020 12:09:29 +0200 Subject: [PATCH] Revert "Prevent cached passwords from being wiped (#884)" This reverts commit 889208b2644fd5676de8e05b81b4712dd11fa58b. --- .../pwdstore/git/config/SshjSessionFactory.kt | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/zeapo/pwdstore/git/config/SshjSessionFactory.kt b/app/src/main/java/com/zeapo/pwdstore/git/config/SshjSessionFactory.kt index 066f8ac61..aaa7b5dc1 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/config/SshjSessionFactory.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/config/SshjSessionFactory.kt @@ -39,14 +39,14 @@ sealed class SshAuthData { class Password(val passwordFinder: InteractivePasswordFinder) : SshAuthData() { override fun clearCredentials() { - passwordFinder.clearPasswords() + passwordFinder.clearPassword() } } class PublicKeyFile(val keyFile: File, val passphraseFinder: InteractivePasswordFinder) : SshAuthData() { override fun clearCredentials() { - passphraseFinder.clearPasswords() + passphraseFinder.clearPassword() } } @@ -59,14 +59,13 @@ abstract class InteractivePasswordFinder : PasswordFinder { private var isRetry = false private var lastPassword: CharArray? = null - private val rememberToWipe: MutableList = mutableListOf() fun resetForReuse() { isRetry = false } - fun clearPasswords() { - rememberToWipe.forEach { it.clear() } + fun clearPassword() { + lastPassword?.clear() lastPassword = null } @@ -76,20 +75,17 @@ abstract class InteractivePasswordFinder : PasswordFinder { // now being reused for a new one. We try the previous password so that the user // does not have to type it again. isRetry = true - return lastPassword!!.clone().also { rememberToWipe.add(it) } + return lastPassword!! } - clearPasswords() + clearPassword() val password = runBlocking(Dispatchers.Main) { suspendCoroutine { cont -> askForPassword(cont, isRetry) } } isRetry = true - if (password == null) - throw SSHException(DisconnectReason.AUTH_CANCELLED_BY_USER) - val passwordChars = password.toCharArray().also { rememberToWipe.add(it) } - lastPassword = passwordChars - return passwordChars.clone().also { rememberToWipe.add(it) } + return password?.toCharArray()?.also { lastPassword = it } + ?: throw SSHException(DisconnectReason.AUTH_CANCELLED_BY_USER) } final override fun shouldRetry(resource: Resource<*>?) = true