summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFabian Henneke <FabianHenneke@users.noreply.github.com>2020-08-27 12:13:55 +0200
committerGitHub <noreply@github.com>2020-08-27 15:43:55 +0530
commitcba0bc2b29c0f30f6d55c0a43010d7557c89bed9 (patch)
tree434e16f83584047598960662950022aa10708291 /app
parent1093928d93c097c92934cbb02a0f91f3f3845e3e (diff)
Remember HTTPS password throughout a sync operation (#1062)
* Remember HTTPS password throughout a sync operation * Add CHANGELOG.md entry Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt17
1 files 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 eceb2b50..806bbb7c 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
}