summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorMatthew Wong <wongma@protonmail.ch>2015-07-22 01:02:06 -0400
committerMatthew Wong <wongma@protonmail.ch>2015-07-22 01:02:06 -0400
commite45afa3392e63f72ebfc7418ebad4038e6c4539d (patch)
tree4ee151e050e2d6a5d219f1bcd2ad761b0b0d09f9 /app/src/main/java
parentd95286660ad5e626c75f4bc9f70e51277be67273 (diff)
Don't ask for ssh key passphrase if key is not encrypted with one #106
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java43
1 files changed, 25 insertions, 18 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 c4d7eea4..c52d08e5 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
@@ -9,6 +9,8 @@ import android.text.InputType;
import android.widget.EditText;
import android.widget.LinearLayout;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.KeyPair;
import com.zeapo.pwdstore.R;
import com.zeapo.pwdstore.UserPreference;
import com.zeapo.pwdstore.git.config.GitConfigSessionFactory;
@@ -133,26 +135,31 @@ public abstract class GitOperation {
passphrase.setHint("Passphrase");
passphrase.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
passphrase.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
+ JSch jsch = new JSch();
+ KeyPair keyPair = KeyPair.load(jsch, callingActivity.getFilesDir() + "/.ssh_key");
+ if (keyPair.isEncrypted()) {
+ new AlertDialog.Builder(callingActivity)
+ .setTitle(callingActivity.getResources().getString(R.string.passphrase_dialog_title))
+ .setMessage(callingActivity.getResources().getString(R.string.passphrase_dialog_text))
+ .setView(passphrase)
+ .setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ try {
+ // Authenticate using the ssh-key and then execute the command
+ setAuthentication(sshKey, username, passphrase.getText().toString()).execute();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
- new AlertDialog.Builder(callingActivity)
- .setTitle(callingActivity.getResources().getString(R.string.passphrase_dialog_title))
- .setMessage(callingActivity.getResources().getString(R.string.passphrase_dialog_text))
- .setView(passphrase)
- .setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- try {
- // Authenticate using the ssh-key and then execute the command
- setAuthentication(sshKey, username, passphrase.getText().toString()).execute();
- } catch (Exception e) {
- e.printStackTrace();
}
-
- }
- }).setNegativeButton(callingActivity.getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- // Do nothing.
- }
- }).show();
+ }).setNegativeButton(callingActivity.getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ // Do nothing.
+ }
+ }).show();
+ } else {
+ setAuthentication(sshKey, username, "").execute();
+ }
}
} else {
final EditText password = new EditText(callingActivity);