diff options
author | zeapo <mohamed@zenadi.com> | 2014-08-23 21:22:05 +0200 |
---|---|---|
committer | zeapo <mohamed@zenadi.com> | 2014-08-23 21:22:05 +0200 |
commit | 6ba4acfc47e0197f81eefe3aed5e9badd7e71928 (patch) | |
tree | 2d9feecda5eb762e2e3b1972711b02d24a008eb2 /app/src/main/java | |
parent | 9784af6d66fc88651f260f084e28ddee42ea8cab (diff) |
store initialization supports ssh-key now
Diffstat (limited to 'app/src/main/java')
3 files changed, 60 insertions, 28 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/GitHandler.java b/app/src/main/java/com/zeapo/pwdstore/GitHandler.java index 619c0611..2544efe5 100644 --- a/app/src/main/java/com/zeapo/pwdstore/GitHandler.java +++ b/app/src/main/java/com/zeapo/pwdstore/GitHandler.java @@ -166,7 +166,7 @@ public class GitHandler extends Activity { String hostname = settings.getString("git_remote_username", "") + "@" + - settings.getString("git_remote_server", "") + settings.getString("git_remote_server", "").trim() + ":" + settings.getString("git_remote_location", ""); @@ -483,7 +483,7 @@ public class GitHandler extends Activity { // check that the remote origin is here, else add it PasswordRepository.addRemote("origin", settings.getString("git_remote_username", "user") + "@" + - settings.getString("git_remote_server", "server.com") + settings.getString("git_remote_server", "server.com").trim() + ":" + settings.getString("git_remote_location", "path/to/repository")); @@ -507,7 +507,7 @@ public class GitHandler extends Activity { public void pushOperation(UsernamePasswordCredentialsProvider provider) { if (settings.getString("git_remote_username", "user").isEmpty() || - settings.getString("git_remote_server", "server.com").isEmpty() || + settings.getString("git_remote_server", "server.com").trim().isEmpty() || settings.getString("git_remote_location", "path/to/repository").isEmpty() ) new AlertDialog.Builder(this) .setMessage("You have to set the information about the server before synchronizing with the server") @@ -532,7 +532,7 @@ public class GitHandler extends Activity { // check that the remote origin is here, else add it PasswordRepository.addRemote("origin", settings.getString("git_remote_username", "user") + "@" + - settings.getString("git_remote_server", "server.com") + settings.getString("git_remote_server", "server.com").trim() + ":" + settings.getString("git_remote_location", "path/to/repository")); diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index dff6721d..cc9d4b6d 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -15,6 +15,7 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.widget.AdapterView; import android.widget.EditText; import android.widget.ExpandableListView; import android.widget.LinearLayout; @@ -138,12 +139,30 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI startActivity(intent); } + private void createRepository() { + final String keyId = settings.getString("openpgp_key_ids", ""); + + File localDir = new File(getFilesDir() + "/store/"); + localDir.mkdir(); + try { + // we take only the first key-id, we have to think about how to handle multiple keys, and why should we do that... + // also, for compatibility use short-version of the key-id + FileUtils.writeStringToFile(new File(localDir.getAbsolutePath() + "/.gpg-id"), + keyId.substring(keyId.length() - 8)); + } catch (Exception e) { + localDir.delete(); + return; + } + PasswordRepository.createRepository(localDir); + checkLocalRepository(); + } + public void initRepository(View view) { - String keyId = settings.getString("openpgp_key_ids", ""); + final String keyId = settings.getString("openpgp_key_ids", ""); if (keyId.isEmpty()) new AlertDialog.Builder(this) - .setMessage("You have to set the information about the server before synchronizing with the server") + .setMessage("You have to select your \"PGP-Key ID\" before initializing the repository") .setPositiveButton("On my way!", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { @@ -160,19 +179,27 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI .show(); else { - File localDir = new File(getFilesDir() + "/store/"); - localDir.mkdir(); - try { - // we take only the first key-id, we have to think about how to handle multiple keys, and why should we do that... - // also, for compatibility use short-version of the key-id - FileUtils.writeStringToFile(new File(localDir.getAbsolutePath() + "/.gpg-id"), - keyId.substring(keyId.length() - 8)); - } catch (Exception e) { - localDir.delete(); - return; - } - PasswordRepository.createRepository(localDir); - checkLocalRepository(); + new AlertDialog.Builder(this) + .setMessage("Which connection method do you prefer?") + .setPositiveButton("ssh-key", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + settings.edit().putString("git_remote_auth", "ssh-key").apply(); + createRepository(); + } + }) + .setNegativeButton("username/password", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + settings.edit().putString("git_remote_auth", "username/password").apply(); + createRepository(); + } + }) + .setCancelable(false) + + + .show(); + } } diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java index 47d21834..32f1237e 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java @@ -250,6 +250,9 @@ public class PgpHandler extends Activity implements OpenPgpServiceConnection.OnB decryptAndVerify(data); break; } + case REQUEST_CODE_GET_KEY_IDS: + getKeyIds(data); + break; } } else if (resultCode == RESULT_CANCELED) { bindingDialog.dismiss(); @@ -332,13 +335,14 @@ public class PgpHandler extends Activity implements OpenPgpServiceConnection.OnB } keyIDs = StringUtils.join(keys, ", "); - settings.edit().putString("openpgp_key_ids", keyIDs).commit(); - if (!keyIDs.isEmpty()) { String mKeys = keyIDs.split(",").length > 1 ? keyIDs : keyIDs.split(",")[0]; - ((TextView) findViewById(R.id.crypto_key_ids)).setText(mKeys); +// ((TextView) findViewById(R.id.crypto_key_ids)).setText(mKeys); + settings.edit().putString("openpgp_key_ids", keyIDs).apply(); + Log.i("PGP", mKeys); } - + setResult(RESULT_OK); + finish(); } break; } @@ -481,12 +485,13 @@ public class PgpHandler extends Activity implements OpenPgpServiceConnection.OnB ((TextView) findViewById(R.id.crypto_password_category)).setText(cat); } else if (extra.getString("Operation").equals("GET_KEY_ID")) { bindingDialog.dismiss(); + getKeyIds(new Intent()); - setContentView(R.layout.key_id); - if (!keyIDs.isEmpty()) { - String keys = keyIDs.split(",").length > 1 ? keyIDs : keyIDs.split(",")[0]; - ((TextView) findViewById(R.id.crypto_key_ids)).setText(keys); - } +// setContentView(R.layout.key_id); +// if (!keyIDs.isEmpty()) { +// String keys = keyIDs.split(",").length > 1 ? keyIDs : keyIDs.split(",")[0]; +// ((TextView) findViewById(R.id.crypto_key_ids)).setText(keys); +// } } } |