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

Commit 8c5cd0b

Browse files
Remember HTTPS password throughout a sync operation (#1062)
* Remember HTTPS password throughout a sync operation * Add CHANGELOG.md entry Co-authored-by: Harsh Shandilya <[email protected]> (cherry picked from commit cba0bc2) Signed-off-by: Harsh Shandilya <[email protected]>
1 parent 4a4e48d commit 8c5cd0b

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Fixed
8+
9+
- Delete stored HTTPS password on connection errors (such as failed authentication)
10+
711
## [1.11.2] - 2020-08-24
812

913
### Fixed

app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,21 @@ abstract class GitOperation(gitDir: File, internal val callingActivity: Fragment
5151
protected val git = Git(repository)
5252
protected val remoteBranch = GitSettings.branch
5353

54-
private class PasswordFinderCredentialsProvider(private val passwordFinder: PasswordFinder) : CredentialsProvider() {
54+
private class HttpsCredentialsProvider(private val passwordFinder: PasswordFinder) : CredentialsProvider() {
55+
56+
private var cachedPassword: CharArray? = null
5557

5658
override fun isInteractive() = true
5759

5860
override fun get(uri: URIish?, vararg items: CredentialItem): Boolean {
5961
for (item in items) {
6062
when (item) {
6163
is CredentialItem.Username -> item.value = uri?.user
62-
is CredentialItem.Password -> item.value = passwordFinder.reqPassword(null)
64+
is CredentialItem.Password -> {
65+
item.value = cachedPassword?.clone() ?: passwordFinder.reqPassword(null).also {
66+
cachedPassword = it.clone()
67+
}
68+
}
6369
else -> UnsupportedCredentialItem(uri, item.javaClass.name)
6470
}
6571
}
@@ -69,12 +75,17 @@ abstract class GitOperation(gitDir: File, internal val callingActivity: Fragment
6975
override fun supports(vararg items: CredentialItem) = items.all {
7076
it is CredentialItem.Username || it is CredentialItem.Password
7177
}
78+
79+
override fun reset(uri: URIish?) {
80+
cachedPassword?.fill(0.toChar())
81+
cachedPassword = null
82+
}
7283
}
7384

7485
private fun withPasswordAuthentication(passwordFinder: InteractivePasswordFinder): GitOperation {
7586
val sessionFactory = SshjSessionFactory(SshAuthData.Password(passwordFinder), hostKeyFile)
7687
SshSessionFactory.setInstance(sessionFactory)
77-
this.provider = PasswordFinderCredentialsProvider(passwordFinder)
88+
this.provider = HttpsCredentialsProvider(passwordFinder)
7889
return this
7990
}
8091

0 commit comments

Comments
 (0)