aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/git/config
diff options
context:
space:
mode:
authorMohamed Zenadi <zeapo@users.noreply.github.com>2015-01-04 21:49:56 +0100
committerMohamed Zenadi <zeapo@users.noreply.github.com>2015-01-04 21:49:56 +0100
commitdf8994d84f3923ba64cb36ecdad54aa29e28f2a0 (patch)
tree7eb85fa141183222ca565cb8ee6d5c977cd88729 /app/src/main/java/com/zeapo/pwdstore/git/config
parent33689cefc7a429e4f51607a013f6adc9c01ede94 (diff)
parent6922652173e05433bb9524b036baafb96c91ca1b (diff)
downloadHardenedPass-df8994d84f3923ba64cb36ecdad54aa29e28f2a0.tar.gz
HardenedPass-df8994d84f3923ba64cb36ecdad54aa29e28f2a0.zip
Merge pull request #57 from zeapo/feature/refactor-git
Refactoring of the git process
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.java24
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.java70
2 files changed, 94 insertions, 0 deletions
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
new file mode 100644
index 00000000..ab23361e
--- /dev/null
+++ b/app/src/main/java/com/zeapo/pwdstore/git/config/GitConfigSessionFactory.java
@@ -0,0 +1,24 @@
+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/SshConfigSessionFactory.java b/app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.java
new file mode 100644
index 00000000..333a6325
--- /dev/null
+++ b/app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.java
@@ -0,0 +1,70 @@
+package com.zeapo.pwdstore.git.config;
+
+import android.content.SharedPreferences;
+
+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");
+
+ 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);
+ }
+} \ No newline at end of file