From c3696b2f495425436a42e058e7f50a7229d343cc Mon Sep 17 00:00:00 2001 From: Zeapo Date: Wed, 6 Aug 2014 20:35:03 +0100 Subject: some refactoring with nicer icons... --- README.md | 38 +++++ .../java/com/zeapo/pwdstore/PasswordStore.java | 11 +- .../java/com/zeapo/pwdstore/crypto/PgpHandler.java | 66 +++++---- app/src/main/res/drawable-xxhdpi/red_rectangle.xml | 24 +++ app/src/main/res/layout/activity_pwdstore.xml | 2 +- app/src/main/res/layout/decrypt_layout.xml | 164 ++++++++++++--------- app/src/main/res/layout/encrypt_layout.xml | 4 +- app/src/main/res/menu/pwdstore.xml | 10 +- app/src/main/res/xml/preference.xml | 3 - 9 files changed, 208 insertions(+), 114 deletions(-) create mode 100644 README.md create mode 100644 app/src/main/res/drawable-xxhdpi/red_rectangle.xml diff --git a/README.md b/README.md new file mode 100644 index 00000000..c7781b17 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +PwdStore +======== + +This application tries to be 100% compatible with [pass](http://www.zx2c4.com/projects/password-store/) + +Feautres +======== +- Clone an existing pass repository +- List the passwords +- Handle the directories as categories +- Decrypt the password files (first line is the password, the rest is extra data) +- Add a new password to the current category (or no category if added at the root) + +Libraries +========= +This project uses three libraries: +- [OpenKeyChain](https://github.com/open-keychain/open-keychain) for encryption and decryption of passwords +- [JGit]() a pretty good git lib +- [Apache's FileUtils]() for files manipulations + +TODOs +===== +- Initialize a new pass repository +- Pull from/Push to a pass repository +- Create a new cateogry +- Multi-select (for password deletion) +- Multiple password stores (multiple git repositories). +- More UI enhancements + +Needed +====== +- Icons: the current ones are CC, but would be great to have our own icons +- UI enhancements: any UI changes or suggestions are welcome + + + + + diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index 890a76bc..da90e33b 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -80,6 +80,13 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI } return true; + case R.id.menu_add_password: + createPassword(getCurrentFocus()); + break; + + case R.id.menu_add_category: + break; + case R.id.referesh: PasswordFragment plist; if (null != @@ -204,7 +211,6 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI try { Intent intent = new Intent(this, PgpHandler.class); intent.putExtra("PGP-ID", FileUtils.readFileToString(PasswordRepository.getFile("/.gpg-id"))); - intent.putExtra("NAME", "test.gpg"); intent.putExtra("FILE_PATH", this.currentDir.getAbsolutePath()); intent.putExtra("Operation", "ENCRYPT"); // TODO Define different operations here @@ -217,6 +223,7 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI protected void onActivityResult(int requestCode, int resultCode, Intent data) { System.out.println(resultCode); - checkLocalRepository(this.currentDir); + if (resultCode == RESULT_OK) + checkLocalRepository(this.currentDir); } } 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 fec575ac..8e7cfe65 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java @@ -2,7 +2,9 @@ package com.zeapo.pwdstore.crypto; import android.app.ActionBar; import android.app.Activity; +import android.app.AlertDialog; import android.app.PendingIntent; +import android.content.DialogInterface; import android.content.Intent; import android.content.IntentSender; import android.content.SharedPreferences; @@ -20,7 +22,6 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; -import android.widget.GridLayout.LayoutParams; import com.zeapo.pwdstore.R; import com.zeapo.pwdstore.UserPreference; @@ -37,7 +38,6 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.InputStream; import java.io.OutputStream; -import java.io.StringReader; import java.io.UnsupportedEncodingException; public class PgpHandler extends Activity { @@ -67,14 +67,9 @@ public class PgpHandler extends Activity { Bundle extra = getIntent().getExtras(); if (extra.getString("Operation").equals("DECRYPT")) { setContentView(R.layout.decrypt_layout); - ((TextView) findViewById(R.id.crypto_password_file)).setText(extra.getString("NAME")); - findViewById(R.id.crypto_show_button).setVisibility(View.VISIBLE); } else if (extra.getString("Operation").equals("ENCRYPT")) { setContentView(R.layout.encrypt_layout); - - ((EditText) findViewById(R.id.crypto_password_edit)).setText(extra.getString("NAME")); - findViewById(R.id.crypto_password_edit_layout).setVisibility(View.VISIBLE); } // some persistance @@ -113,6 +108,7 @@ public class PgpHandler extends Activity { int id = item.getItemId(); switch (id) { case android.R.id.home: + setResult(RESULT_OK); finish(); return true; } @@ -130,6 +126,8 @@ public class PgpHandler extends Activity { case R.id.crypto_cancel_add: finish(); break; + case R.id.crypto_delete_button: + deletePassword(); default: // should not happen @@ -267,7 +265,7 @@ public class PgpHandler extends Activity { showToast(os.toString()); } - setResult(998); + setResult(RESULT_OK); finish(); } catch (Exception e) { Log.e(Constants.TAG, "UnsupportedEncodingException", e); @@ -341,9 +339,20 @@ public class PgpHandler extends Activity { data.putExtra(OpenPgpApi.EXTRA_USER_IDS, new String[] {"default"}); data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); + String name = ((EditText) findViewById(R.id.crypto_password_file_edit)).getText().toString(); String pass = ((EditText) findViewById(R.id.crypto_password_edit)).getText().toString(); String extra = ((EditText) findViewById(R.id.crypto_extra_edit)).getText().toString(); + if (name.isEmpty()) { + showToast("Please provide a file name"); + return; + } + + if (pass.isEmpty()) { + showToast("You cannot use an empty password or empty extra content"); + return; + } + ByteArrayInputStream is; try { @@ -360,13 +369,26 @@ public class PgpHandler extends Activity { } + private void deletePassword() { + new AlertDialog.Builder(this). + setMessage("Are you sure you want to delete the password " + + getIntent().getExtras().getString("NAME") + ) + .setPositiveButton("YES", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + (new File(getIntent().getExtras().getString("FILE_PATH"))).delete(); + setResult(RESULT_OK); + finish(); + } + }) + .setNegativeButton("NO", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { - public void getKeyIds(Intent data) { - data.setAction(OpenPgpApi.ACTION_GET_KEY_IDS); - data.putExtra(OpenPgpApi.EXTRA_USER_IDS, new String[]{getIntent().getExtras().getString("PGP-ID")}); - - OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService()); - api.executeApiAsync(data, null, null, new MyCallback(false, null, REQUEST_CODE_GET_KEY_IDS)); + } + }) + .show(); } @Override @@ -383,30 +405,14 @@ public class PgpHandler extends Activity { * interaction, for example selected key ids. */ switch (requestCode) { -// case REQUEST_CODE_SIGN: { -// sign(data); -// break; -// } case REQUEST_CODE_ENCRYPT: { encrypt(data); break; } -// case REQUEST_CODE_SIGN_AND_ENCRYPT: { -// signAndEncrypt(data); -// break; -// } case REQUEST_CODE_DECRYPT_AND_VERIFY: { decryptAndVerify(data); break; } -// case REQUEST_CODE_GET_KEY: { -// getKey(data); -// break; -// } - case REQUEST_CODE_GET_KEY_IDS: { - getKeyIds(data); - break; - } } } } diff --git a/app/src/main/res/drawable-xxhdpi/red_rectangle.xml b/app/src/main/res/drawable-xxhdpi/red_rectangle.xml new file mode 100644 index 00000000..b8e6a5d6 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/red_rectangle.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_pwdstore.xml b/app/src/main/res/layout/activity_pwdstore.xml index de559be0..08dcf2ad 100644 --- a/app/src/main/res/layout/activity_pwdstore.xml +++ b/app/src/main/res/layout/activity_pwdstore.xml @@ -20,7 +20,7 @@ - - - - - - - - + android:layout_height="fill_parent" + android:orientation="vertical"> + android:layout_height="wrap_content" + android:background="@drawable/rectangle" + android:orientation="horizontal"> - + + - - - + + + + + + + + + - + android:text="Extra content: "/> + + + + + - \ No newline at end of file + + + \ No newline at end of file diff --git a/app/src/main/res/layout/encrypt_layout.xml b/app/src/main/res/layout/encrypt_layout.xml index c4949c9a..abc75fe5 100644 --- a/app/src/main/res/layout/encrypt_layout.xml +++ b/app/src/main/res/layout/encrypt_layout.xml @@ -98,7 +98,7 @@ + + + + + android:orderInCategory="100"/> diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index 402a1bd3..8686dff7 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -5,8 +5,5 @@ - \ No newline at end of file -- cgit v1.2.3