Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ import kotlin.coroutines.suspendCoroutine
sealed class SshAuthData {
class Password(val passwordFinder: InteractivePasswordFinder) : SshAuthData() {
override fun clearCredentials() {
passwordFinder.clearPassword()
passwordFinder.clearPasswords()
}
}

class PublicKeyFile(val keyFile: File, val passphraseFinder: InteractivePasswordFinder) : SshAuthData() {
override fun clearCredentials() {
passphraseFinder.clearPassword()
passphraseFinder.clearPasswords()
}
}

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

private var isRetry = false
private var lastPassword: CharArray? = null
private val rememberToWipe: MutableList<CharArray> = mutableListOf()

fun resetForReuse() {
isRetry = false
}

fun clearPassword() {
lastPassword?.clear()
fun clearPasswords() {
rememberToWipe.forEach { it.clear() }
lastPassword = null
}

Expand All @@ -73,17 +74,20 @@ 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!!
return lastPassword!!.clone().also { rememberToWipe.add(it) }
}
clearPassword()
clearPasswords()
val password = runBlocking(Dispatchers.Main) {
suspendCoroutine<String?> { cont ->
askForPassword(cont, isRetry)
}
}
isRetry = true
return password?.toCharArray()?.also { lastPassword = it }
?: throw SSHException(DisconnectReason.AUTH_CANCELLED_BY_USER)
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) }
}

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