From db99c10339dc6e9ca3028b1bf8326ad62c136708 Mon Sep 17 00:00:00 2001 From: Fabian Henneke Date: Thu, 27 Aug 2020 09:45:54 +0200 Subject: [PATCH 1/2] Remember HTTPS password throughout a sync operation --- .../pwdstore/git/operation/GitOperation.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt index d537ba7f0c..9c014341c9 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt @@ -50,7 +50,9 @@ abstract class GitOperation(gitDir: File, internal val callingActivity: Fragment protected val git = Git(repository) protected val remoteBranch = GitSettings.branch - private class PasswordFinderCredentialsProvider(private val passwordFinder: PasswordFinder) : CredentialsProvider() { + private class HttpsCredentialsProvider(private val passwordFinder: PasswordFinder) : CredentialsProvider() { + + private var cachedPassword: CharArray? = null override fun isInteractive() = true @@ -58,7 +60,11 @@ abstract class GitOperation(gitDir: File, internal val callingActivity: Fragment for (item in items) { when (item) { is CredentialItem.Username -> item.value = uri?.user - is CredentialItem.Password -> item.value = passwordFinder.reqPassword(null) + is CredentialItem.Password -> { + item.value = cachedPassword?.clone() ?: passwordFinder.reqPassword(null).also { + cachedPassword = it.clone() + } + } else -> UnsupportedCredentialItem(uri, item.javaClass.name) } } @@ -68,12 +74,17 @@ abstract class GitOperation(gitDir: File, internal val callingActivity: Fragment override fun supports(vararg items: CredentialItem) = items.all { it is CredentialItem.Username || it is CredentialItem.Password } + + override fun reset(uri: URIish?) { + cachedPassword?.fill(0.toChar()) + cachedPassword = null + } } private fun withPasswordAuthentication(passwordFinder: InteractivePasswordFinder): GitOperation { val sessionFactory = SshjSessionFactory(SshAuthData.Password(passwordFinder), hostKeyFile) SshSessionFactory.setInstance(sessionFactory) - this.provider = PasswordFinderCredentialsProvider(passwordFinder) + this.provider = HttpsCredentialsProvider(passwordFinder) return this } From d0d31862c42753b505ff5933105c7709ca654cab Mon Sep 17 00:00:00 2001 From: Fabian Henneke Date: Thu, 27 Aug 2020 11:11:26 +0200 Subject: [PATCH 2/2] Add CHANGELOG.md entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc7e4a733f..c8212e9b0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file. - Password creation UI will scroll if it does not fit on the screen - Git server protocol and authentication mode are only updated when explicitly saved +- Remember HTTPS password during a sync operation ## [1.11.2] - 2020-08-24