aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/git/config
diff options
context:
space:
mode:
authorFabian Henneke <FabianHenneke@users.noreply.github.com>2020-05-30 19:39:17 +0200
committerGitHub <noreply@github.com>2020-05-30 19:39:17 +0200
commit2428d4c0deb5d088112ed10391932acf325e84d5 (patch)
tree692b15264e45ea4cb59b7d45dfa47edd7d4af033 /app/src/main/java/com/zeapo/pwdstore/git/config
parent72ede314ef02dfc255b3a28b3540e6fef10da9ac (diff)
downloadHardenedPass-2428d4c0deb5d088112ed10391932acf325e84d5.tar.gz
HardenedPass-2428d4c0deb5d088112ed10391932acf325e84d5.zip
Switch password authentication over to SSHJ (#811)
* Switch password authentication over to SSHJ * Address review comments and refactor further
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/git/config')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/config/GitConfigSessionFactory.kt26
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/config/SshApiSessionFactory.java3
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/config/SshjSessionFactory.kt8
3 files changed, 7 insertions, 30 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/config/GitConfigSessionFactory.kt b/app/src/main/java/com/zeapo/pwdstore/git/config/GitConfigSessionFactory.kt
deleted file mode 100644
index eb4365fa..00000000
--- a/app/src/main/java/com/zeapo/pwdstore/git/config/GitConfigSessionFactory.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-package com.zeapo.pwdstore.git.config
-
-import com.jcraft.jsch.JSch
-import com.jcraft.jsch.JSchException
-import com.jcraft.jsch.Session
-import org.eclipse.jgit.transport.JschConfigSessionFactory
-import org.eclipse.jgit.transport.OpenSshConfig
-import org.eclipse.jgit.util.FS
-
-open class GitConfigSessionFactory : JschConfigSessionFactory() {
-
- override fun configure(hc: OpenSshConfig.Host, session: Session) {
- session.setConfig("StrictHostKeyChecking", "no")
- }
-
- @Throws(JSchException::class)
- override fun getJSch(hc: OpenSshConfig.Host, fs: FS): JSch {
- val jsch = super.getJSch(hc, fs)
- jsch.removeAllIdentity()
- return jsch
- }
-}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/config/SshApiSessionFactory.java b/app/src/main/java/com/zeapo/pwdstore/git/config/SshApiSessionFactory.java
index c21ec053..e5a5fd17 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/config/SshApiSessionFactory.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/config/SshApiSessionFactory.java
@@ -26,6 +26,7 @@ import org.eclipse.jgit.errors.UnsupportedCredentialItem;
import org.eclipse.jgit.transport.CredentialItem;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.CredentialsProviderUserInfo;
+import org.eclipse.jgit.transport.JschConfigSessionFactory;
import org.eclipse.jgit.transport.OpenSshConfig;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.util.Base64;
@@ -43,7 +44,7 @@ import org.openintents.ssh.authentication.util.SshAuthenticationApiUtils;
import java.util.List;
import java.util.concurrent.CountDownLatch;
-public class SshApiSessionFactory extends GitConfigSessionFactory {
+public class SshApiSessionFactory extends JschConfigSessionFactory {
/**
* Intent request code indicating a completed signature that should be posted to an outstanding
* ApiIdentity
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/config/SshjSessionFactory.kt b/app/src/main/java/com/zeapo/pwdstore/git/config/SshjSessionFactory.kt
index 5287989a..146fdb43 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/config/SshjSessionFactory.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/config/SshjSessionFactory.kt
@@ -37,12 +37,14 @@ sealed class SshAuthData {
class PublicKeyFile(val keyFile: File, val passphraseFinder: InteractivePasswordFinder) : SshAuthData()
}
-class InteractivePasswordFinder(val askForPassword: (cont: Continuation<String?>, isRetry: Boolean) -> Unit) : PasswordFinder {
+abstract class InteractivePasswordFinder : PasswordFinder {
private var isRetry = false
private var shouldRetry = true
- override fun reqPassword(resource: Resource<*>?): CharArray {
+ abstract fun askForPassword(cont: Continuation<String?>, isRetry: Boolean)
+
+ final override fun reqPassword(resource: Resource<*>?): CharArray {
val password = runBlocking(Dispatchers.Main) {
suspendCoroutine<String?> { cont ->
askForPassword(cont, isRetry)
@@ -57,7 +59,7 @@ class InteractivePasswordFinder(val askForPassword: (cont: Continuation<String?>
}
}
- override fun shouldRetry(resource: Resource<*>?) = shouldRetry
+ final override fun shouldRetry(resource: Resource<*>?) = shouldRetry
}
class SshjSessionFactory(private val username: String, private val authData: SshAuthData, private val hostKeyFile: File) : SshSessionFactory() {