aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
diff options
context:
space:
mode:
authorvexofp <vexofp@gmail.com>2019-04-05 18:14:38 -0400
committerMohamed Zenadi <zeapo@users.noreply.github.com>2019-04-06 00:14:38 +0200
commitf272e4dde2c05de64681a0e089387ef9c54bd7c7 (patch)
tree3e75e9c7a3a996c3f6d7762dac644ab3f4e7c700 /app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
parent94bf103b337d9df1d6232d85f5edf4673ede651c (diff)
downloadHardenedPass-f272e4dde2c05de64681a0e089387ef9c54bd7c7.tar.gz
HardenedPass-f272e4dde2c05de64681a0e089387ef9c54bd7c7.zip
Authentication using OpenKeystore SSH API (#486)
* Implemented OpenKeystore SSH API as a new authentication option * Fix formatting problems Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com> * Addressed review comments. Removed leftover debugging code. Wrapped excessively long lines. Added missing new parameter to Javadoc. * Merge remote-tracking branch 'upstream/master' into gpg-ssh-key
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java41
1 files changed, 34 insertions, 7 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
index 51ea92d3..39edf158 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
@@ -11,16 +11,20 @@ import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
+
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
+
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.KeyPair;
import com.zeapo.pwdstore.R;
import com.zeapo.pwdstore.UserPreference;
import com.zeapo.pwdstore.git.config.GitConfigSessionFactory;
+import com.zeapo.pwdstore.git.config.SshApiSessionFactory;
import com.zeapo.pwdstore.git.config.SshConfigSessionFactory;
import com.zeapo.pwdstore.utils.PasswordRepository;
+
import org.eclipse.jgit.api.GitCommand;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.JschConfigSessionFactory;
@@ -77,6 +81,18 @@ public abstract class GitOperation {
}
/**
+ * Sets the authentication using OpenKeystore scheme
+ *
+ * @param identity The identiy to use
+ * @return the current object
+ */
+ GitOperation setAuthentication(String username, SshApiSessionFactory.ApiIdentity identity) {
+ SshSessionFactory.setInstance(new SshApiSessionFactory(username, identity));
+ this.provider = null;
+ return this;
+ }
+
+ /**
* Executes the GitCommand in an async task
*/
public abstract void execute();
@@ -86,10 +102,14 @@ public abstract class GitOperation {
*
* @param connectionMode the server-connection mode
* @param username the username
- * @param sshKey the ssh-key file
+ * @param sshKey the ssh-key file to use in ssh-key connection mode
+ * @param identity the api identity to use for auth in OpenKeychain connection mode
*/
- public void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey) {
- executeAfterAuthentication(connectionMode, username, sshKey, false);
+ public void executeAfterAuthentication(final String connectionMode,
+ final String username,
+ @Nullable final File sshKey,
+ SshApiSessionFactory.ApiIdentity identity) {
+ executeAfterAuthentication(connectionMode, username, sshKey, identity, false);
}
/**
@@ -97,10 +117,15 @@ public abstract class GitOperation {
*
* @param connectionMode the server-connection mode
* @param username the username
- * @param sshKey the ssh-key file
+ * @param sshKey the ssh-key file to use in ssh-key connection mode
+ * @param identity the api identity to use for auth in OpenKeychain connection mode
* @param showError show the passphrase edit text in red
*/
- private void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey, final boolean showError) {
+ private void executeAfterAuthentication(final String connectionMode,
+ final String username,
+ @Nullable final File sshKey,
+ SshApiSessionFactory.ApiIdentity identity,
+ final boolean showError) {
if (connectionMode.equalsIgnoreCase("ssh-key")) {
if (sshKey == null || !sshKey.exists()) {
new AlertDialog.Builder(callingActivity)
@@ -153,7 +178,7 @@ public abstract class GitOperation {
setAuthentication(sshKey, username, sshKeyPassphrase).execute();
} else {
// call back the method
- executeAfterAuthentication(connectionMode, username, sshKey, true);
+ executeAfterAuthentication(connectionMode, username, sshKey, identity, true);
}
} else {
new AlertDialog.Builder(callingActivity)
@@ -171,7 +196,7 @@ public abstract class GitOperation {
} else {
settings.edit().putString("ssh_key_passphrase", null).apply();
// call back the method
- executeAfterAuthentication(connectionMode, username, sshKey, true);
+ executeAfterAuthentication(connectionMode, username, sshKey, identity, true);
}
}).setNegativeButton(callingActivity.getResources().getString(R.string.dialog_cancel), (dialog, whichButton) -> {
// Do nothing.
@@ -189,6 +214,8 @@ public abstract class GitOperation {
}).show();
}
}
+ } else if (connectionMode.equalsIgnoreCase("OpenKeychain")) {
+ setAuthentication(username, identity).execute();
} else {
final EditText password = new EditText(callingActivity);
password.setHint("Password");