Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- Delete stored HTTPS password on connection errors (such as failed authentication)

## [1.11.2] - 2020-08-24
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,21 @@ 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

override fun get(uri: URIish?, vararg items: CredentialItem): Boolean {
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)
}
}
Expand All @@ -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
}

Expand Down