Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit cc2bb76

Browse files
FabianHennekemsfjarvis
authored andcommitted
Prevent cached passwords from being wiped (#884)
(cherry picked from commit 889208b) Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
1 parent 8f7d305 commit cc2bb76

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

app/src/main/java/com/zeapo/pwdstore/git/config/SshjSessionFactory.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ import kotlin.coroutines.suspendCoroutine
3838
sealed class SshAuthData {
3939
class Password(val passwordFinder: InteractivePasswordFinder) : SshAuthData() {
4040
override fun clearCredentials() {
41-
passwordFinder.clearPassword()
41+
passwordFinder.clearPasswords()
4242
}
4343
}
4444

4545
class PublicKeyFile(val keyFile: File, val passphraseFinder: InteractivePasswordFinder) : SshAuthData() {
4646
override fun clearCredentials() {
47-
passphraseFinder.clearPassword()
47+
passphraseFinder.clearPasswords()
4848
}
4949
}
5050

@@ -57,13 +57,14 @@ abstract class InteractivePasswordFinder : PasswordFinder {
5757

5858
private var isRetry = false
5959
private var lastPassword: CharArray? = null
60+
private val rememberToWipe: MutableList<CharArray> = mutableListOf()
6061

6162
fun resetForReuse() {
6263
isRetry = false
6364
}
6465

65-
fun clearPassword() {
66-
lastPassword?.clear()
66+
fun clearPasswords() {
67+
rememberToWipe.forEach { it.clear() }
6768
lastPassword = null
6869
}
6970

@@ -73,17 +74,20 @@ abstract class InteractivePasswordFinder : PasswordFinder {
7374
// now being reused for a new one. We try the previous password so that the user
7475
// does not have to type it again.
7576
isRetry = true
76-
return lastPassword!!
77+
return lastPassword!!.clone().also { rememberToWipe.add(it) }
7778
}
78-
clearPassword()
79+
clearPasswords()
7980
val password = runBlocking(Dispatchers.Main) {
8081
suspendCoroutine<String?> { cont ->
8182
askForPassword(cont, isRetry)
8283
}
8384
}
8485
isRetry = true
85-
return password?.toCharArray()?.also { lastPassword = it }
86-
?: throw SSHException(DisconnectReason.AUTH_CANCELLED_BY_USER)
86+
if (password == null)
87+
throw SSHException(DisconnectReason.AUTH_CANCELLED_BY_USER)
88+
val passwordChars = password.toCharArray().also { rememberToWipe.add(it) }
89+
lastPassword = passwordChars
90+
return passwordChars.clone().also { rememberToWipe.add(it) }
8791
}
8892

8993
final override fun shouldRetry(resource: Resource<*>?) = true

0 commit comments

Comments
 (0)