aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/crypto
diff options
context:
space:
mode:
authorMatthew Wong <wongma7@outlook.com>2016-05-14 20:30:55 -0400
committerMatthew Wong <wongma7@outlook.com>2016-05-14 20:30:55 -0400
commitcacf739f6d5af79ddfe623cc764b07ff8a6136f6 (patch)
tree9699a66bd7a411fe1098ec11b91fc30468c8222b /app/src/main/java/com/zeapo/pwdstore/crypto
parent2b01219e5c4a47b685d49b8aeb7671fafe9de8b0 (diff)
downloadHardenedPass-cacf739f6d5af79ddfe623cc764b07ff8a6136f6.tar.gz
HardenedPass-cacf739f6d5af79ddfe623cc764b07ff8a6136f6.zip
add edit long press action
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/crypto')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java67
1 files changed, 66 insertions, 1 deletions
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 fd92a1f7..a80e4800 100644
--- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java
+++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java
@@ -65,6 +65,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
public static final int REQUEST_CODE_DECRYPT_AND_VERIFY = 9913;
public static final int REQUEST_CODE_GET_KEY = 9914;
public static final int REQUEST_CODE_GET_KEY_IDS = 9915;
+ public static final int REQUEST_CODE_EDIT = 9916;
public final class Constants {
public static final String TAG = "Keychain";
@@ -146,7 +147,8 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
public void editPassword() {
- // if in encrypt or (in decrypt and password is invisible), do nothing
+ // if in encrypt or in decrypt and password is invisible
+ // (because !showPassword, so this will instantly close), do nothing
if (findViewById(R.id.crypto_password_show) == null
|| findViewById(R.id.crypto_container).getVisibility() != View.VISIBLE)
return;
@@ -353,6 +355,10 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
case REQUEST_CODE_GET_KEY_IDS:
getKeyIds(data);
break;
+ case REQUEST_CODE_EDIT: {
+ edit(data);
+ break;
+ }
}
} else if (resultCode == RESULT_CANCELED) {
setResult(RESULT_CANCELED, data);
@@ -456,6 +462,39 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
setResult(RESULT_OK);
finish();
}
+
+ // edit
+ if (requestCode == REQUEST_CODE_EDIT && os != null) {
+ try {
+ if (returnToCiphertextField) {
+ findViewById(R.id.progress_bar).setVisibility(View.GONE);
+ findViewById(R.id.progress_bar_label).setVisibility(View.GONE);
+
+ findViewById(R.id.crypto_container).setVisibility(View.VISIBLE);
+
+ Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf");
+ String[] passContent = os.toString("UTF-8").split("\n");
+ ((TextView) findViewById(R.id.crypto_password_show))
+ .setTypeface(monoTypeface);
+ ((TextView) findViewById(R.id.crypto_password_show))
+ .setText(passContent[0]);
+
+ String extraContent = os.toString("UTF-8").replaceFirst(".*\n", "");
+ if (extraContent.length() != 0) {
+ ((TextView) findViewById(R.id.crypto_extra_show))
+ .setTypeface(monoTypeface);
+ ((TextView) findViewById(R.id.crypto_extra_show))
+ .setText(extraContent);
+ }
+
+ editPassword();
+ } else {
+ Log.d("PGPHANDLER", "Error message after decrypt : " + os.toString());
+ }
+ } catch (UnsupportedEncodingException e) {
+ Log.e(Constants.TAG, "UnsupportedEncodingException", e);
+ }
+ }
break;
}
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: {
@@ -560,6 +599,24 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
}
+ public void edit(Intent data) {
+ // exactly same as decrypt, only we want a different callback
+ data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
+
+ findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
+
+ try {
+ InputStream is = FileUtils.openInputStream(new File(getIntent().getExtras().getString("FILE_PATH")));
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService());
+ api.executeApiAsync(data, is, os, new PgpCallback(true, os, REQUEST_CODE_EDIT));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
// TODO (low priority but still...) android M potential permissions crashes
@Override
public void onBound(IOpenPgpService2 service) {
@@ -591,6 +648,14 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
// String keys = keyIDs.split(",").length > 1 ? keyIDs : keyIDs.split(",")[0];
// ((TextView) findViewById(R.id.crypto_key_ids)).setText(keys);
// }
+ } else if (extra.getString("Operation").equals("EDIT")) {
+ setContentView(R.layout.decrypt_layout);
+ ((TextView) findViewById(R.id.crypto_password_file)).setText(extra.getString("NAME"));
+ String cat = new File(extra.getString("FILE_PATH").replace(PasswordRepository.getWorkTree().getAbsolutePath(), ""))
+ .getParentFile().getName();
+
+ ((TextView) findViewById(R.id.crypto_password_category)).setText(cat + "/");
+ edit(new Intent());
}
}