diff --git a/app/src/main/java/com/zeapo/pwdstore/git/config/GitConfigSessionFactory.java b/app/src/main/java/com/zeapo/pwdstore/git/config/GitConfigSessionFactory.java deleted file mode 100644 index 58762888..00000000 --- a/app/src/main/java/com/zeapo/pwdstore/git/config/GitConfigSessionFactory.java +++ /dev/null @@ -1,22 +0,0 @@ -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; - -public class GitConfigSessionFactory extends JschConfigSessionFactory { - - protected void configure(OpenSshConfig.Host hc, Session session) { - session.setConfig("StrictHostKeyChecking", "no"); - } - - @Override - protected JSch getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException { - JSch jsch = super.getJSch(hc, fs); - jsch.removeAllIdentity(); - return jsch; - } -} \ No newline at end of file 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 new file mode 100644 index 00000000..6485a73c --- /dev/null +++ b/app/src/main/java/com/zeapo/pwdstore/git/config/GitConfigSessionFactory.kt @@ -0,0 +1,22 @@ +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 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.java b/app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.java deleted file mode 100644 index 38c5fb7e..00000000 --- a/app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.zeapo.pwdstore.git.config; - -import com.jcraft.jsch.JSch; -import com.jcraft.jsch.JSchException; -import com.jcraft.jsch.Session; -import com.jcraft.jsch.UserInfo; -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.OpenSshConfig; -import org.eclipse.jgit.transport.URIish; -import org.eclipse.jgit.util.FS; - -public class SshConfigSessionFactory extends GitConfigSessionFactory { - private String sshKey; - private String passphrase; - private String username; - - public SshConfigSessionFactory(String sshKey, String username, String passphrase) { - this.sshKey = sshKey; - this.passphrase = passphrase; - this.username = username; - } - - @Override - protected JSch - getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException { - JSch jsch = super.getJSch(hc, fs); - jsch.removeAllIdentity(); - jsch.addIdentity(sshKey); - return jsch; - } - - @Override - protected void configure(OpenSshConfig.Host hc, Session session) { - session.setConfig("StrictHostKeyChecking", "no"); - session.setConfig("PreferredAuthentications", "publickey,password"); - - CredentialsProvider provider = new CredentialsProvider() { - @Override - public boolean isInteractive() { - return false; - } - - @Override - public boolean supports(CredentialItem... items) { - return true; - } - - @Override - public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem { - for (CredentialItem item : items) { - if (item instanceof CredentialItem.Username) { - ((CredentialItem.Username) item).setValue(username); - continue; - } - if (item instanceof CredentialItem.StringType) { - ((CredentialItem.StringType) item).setValue(passphrase); - } - } - return true; - } - }; - UserInfo userInfo = new CredentialsProviderUserInfo(session, provider); - session.setUserInfo(userInfo); - } -} diff --git a/app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.kt b/app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.kt new file mode 100644 index 00000000..e859f609 --- /dev/null +++ b/app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.kt @@ -0,0 +1,54 @@ +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.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.OpenSshConfig +import org.eclipse.jgit.transport.URIish +import org.eclipse.jgit.util.FS + +class SshConfigSessionFactory(private val sshKey: String, private val username: String, private val passphrase: String) : GitConfigSessionFactory() { + + @Throws(JSchException::class) + override fun getJSch(hc: OpenSshConfig.Host, fs: FS): JSch { + val jsch = super.getJSch(hc, fs) + jsch.removeAllIdentity() + jsch.addIdentity(sshKey) + return jsch + } + + override fun configure(hc: OpenSshConfig.Host, session: Session) { + session.setConfig("StrictHostKeyChecking", "no") + session.setConfig("PreferredAuthentications", "publickey,password") + + val provider = object : CredentialsProvider() { + override fun isInteractive(): Boolean { + return false + } + + override fun supports(vararg items: CredentialItem): Boolean { + return true + } + + @Throws(UnsupportedCredentialItem::class) + override fun get(uri: URIish, vararg items: CredentialItem): Boolean { + for (item in items) { + if (item is CredentialItem.Username) { + item.value = username + continue + } + if (item is CredentialItem.StringType) { + item.value = passphrase + } + } + return true + } + } + val userInfo = CredentialsProviderUserInfo(session, provider) + session.userInfo = userInfo + } +}