summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/GitHandler.java6
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.java15
2 files changed, 16 insertions, 5 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/GitHandler.java b/app/src/main/java/com/zeapo/pwdstore/GitHandler.java
index 38af8a81..ecbf68af 100644
--- a/app/src/main/java/com/zeapo/pwdstore/GitHandler.java
+++ b/app/src/main/java/com/zeapo/pwdstore/GitHandler.java
@@ -75,6 +75,8 @@ public class GitHandler extends Activity {
public static final int REQUEST_CLONE = 103;
public static final int REQUEST_INIT = 104;
+ private static final int GET_SSH_KEY = 201;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -582,7 +584,7 @@ public class GitHandler extends Activity {
public void onClick(DialogInterface dialog, int id) {
try {
Intent intent = new Intent(getApplicationContext(), UserPreference.class);
- startActivity(intent);
+ startActivityForResult(intent, GET_SSH_KEY);
} catch (Exception e) {
System.out.println("Exception caught :(");
e.printStackTrace();
@@ -691,6 +693,8 @@ public class GitHandler extends Activity {
case REQUEST_PUSH:
authenticateAndRun("pushOperation");
break;
+ case GET_SSH_KEY:
+ authenticateAndRun("pullOperation");
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
index 69459226..09e61fbf 100644
--- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
+++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
@@ -15,8 +15,11 @@ import com.zeapo.pwdstore.crypto.PgpHandler;
import com.zeapo.pwdstore.utils.PasswordRepository;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
import java.net.URI;
public class UserPreference extends PreferenceActivity implements Preference.OnPreferenceClickListener {
@@ -49,7 +52,6 @@ public class UserPreference extends PreferenceActivity implements Preference.OnP
@Override
public boolean onPreferenceClick(Preference pref) {
- System.out.println(pref);
if (pref.getKey().equals("openpgp_key_id")) {
Intent intent = new Intent(this, PgpHandler.class);
intent.putExtra("Operation", "GET_KEY_ID");
@@ -66,11 +68,16 @@ public class UserPreference extends PreferenceActivity implements Preference.OnP
Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
- Uri sshFile = data.getData();
+// Uri sshFile = data.getData();
try {
- FileUtils.copyFile(new File(sshFile.getPath()), new File(getFilesDir() + "/.ssh_key"));
- } catch (Exception e) {
+ byte[] privateKey = IOUtils.toByteArray(this.getContentResolver().openInputStream(data.getData()));
+ FileUtils.writeByteArrayToFile(new File(getFilesDir() + "/.ssh_key"), privateKey);
+ Log.i("PREF", "Got key");
+ setResult(RESULT_OK);
+ finish();
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
}