aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-08-11 17:10:47 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2014-08-11 17:10:47 +0200
commitb67356503511725df1b016d8a8513b6356cb450a (patch)
treea8a6a056fd25dfc1c9bce7d9b754c694771e94a1 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui
parent549feb69ed0a339f8320f52da9246aac74b60ba1 (diff)
downloadopen-keychain-b67356503511725df1b016d8a8513b6356cb450a.tar.gz
open-keychain-b67356503511725df1b016d8a8513b6356cb450a.tar.bz2
open-keychain-b67356503511725df1b016d8a8513b6356cb450a.zip
Get original filename for decryption
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java95
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java9
2 files changed, 94 insertions, 10 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java
index c33b1489a..845fbfa3b 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java
@@ -23,8 +23,10 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
+import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
+import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -38,6 +40,7 @@ import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
+import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Notify;
@@ -113,7 +116,8 @@ public class DecryptFileFragment extends DecryptFragment {
return;
}
- askForOutputFilename();
+// askForOutputFilename();
+ decryptOriginalFilename(null);
}
private String removeEncryptedAppend(String name) {
@@ -123,8 +127,13 @@ public class DecryptFileFragment extends DecryptFragment {
return name;
}
- private void askForOutputFilename() {
- String targetName = removeEncryptedAppend(FileHelper.getFilename(getActivity(), mInputUri));
+ private void askForOutputFilename(String originalFilename) {
+ String targetName;
+ if (!TextUtils.isEmpty(originalFilename)) {
+ targetName = originalFilename;
+ } else {
+ targetName = removeEncryptedAppend(FileHelper.getFilename(getActivity(), mInputUri));
+ }
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
File file = new File(mInputUri.getPath());
File parentDir = file.exists() ? file.getParentFile() : Constants.Path.APP_DIR;
@@ -136,6 +145,82 @@ public class DecryptFileFragment extends DecryptFragment {
}
}
+ private void decryptOriginalFilename(String passphrase) {
+ Log.d(Constants.TAG, "decryptOriginalFilename");
+
+ Intent intent = new Intent(getActivity(), KeychainIntentService.class);
+
+ // fill values for this action
+ Bundle data = new Bundle();
+ intent.setAction(KeychainIntentService.ACTION_DECRYPT_METADATA);
+
+ // data
+ Log.d(Constants.TAG, "mInputUri=" + mInputUri + ", mOutputUri=" + mOutputUri);
+
+ data.putInt(KeychainIntentService.SOURCE, KeychainIntentService.IO_URI);
+ data.putParcelable(KeychainIntentService.ENCRYPT_INPUT_URI, mInputUri);
+
+ data.putInt(KeychainIntentService.TARGET, KeychainIntentService.IO_URI);
+ data.putParcelable(KeychainIntentService.ENCRYPT_OUTPUT_URI, mOutputUri);
+
+ data.putString(KeychainIntentService.DECRYPT_PASSPHRASE, passphrase);
+
+ intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
+
+ // Message is received after decrypting is done in KeychainIntentService
+ KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(),
+ getString(R.string.progress_decrypting), ProgressDialog.STYLE_HORIZONTAL) {
+ public void handleMessage(Message message) {
+ // handle messages by standard KeychainIntentServiceHandler first
+ super.handleMessage(message);
+
+ if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
+ // get returned data bundle
+ Bundle returnData = message.getData();
+
+ PgpDecryptVerifyResult decryptVerifyResult =
+ returnData.getParcelable(KeychainIntentService.RESULT_DECRYPT_VERIFY_RESULT);
+
+ if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) {
+ showPassphraseDialogForFilename(decryptVerifyResult.getKeyIdPassphraseNeeded());
+ } else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED ==
+ decryptVerifyResult.getStatus()) {
+ showPassphraseDialogForFilename(Constants.key.symmetric);
+ } else {
+
+ // go on...
+ askForOutputFilename(decryptVerifyResult.getDecryptMetadata().getFilename());
+ }
+ }
+ }
+ };
+
+ // Create a new Messenger for the communication back
+ Messenger messenger = new Messenger(saveHandler);
+ intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
+
+ // show progress dialog
+ saveHandler.showProgressDialog(getActivity());
+
+ // start service with intent
+ getActivity().startService(intent);
+ }
+
+ protected void showPassphraseDialogForFilename(long keyId) {
+ PassphraseDialogFragment.show(getActivity(), keyId,
+ new Handler() {
+ @Override
+ public void handleMessage(Message message) {
+ if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
+ String passphrase =
+ message.getData().getString(PassphraseDialogFragment.MESSAGE_DATA_PASSPHRASE);
+ decryptOriginalFilename(passphrase);
+ }
+ }
+ }
+ );
+ }
+
@Override
protected void decryptStart(String passphrase) {
Log.d(Constants.TAG, "decryptStart");
@@ -161,7 +246,7 @@ public class DecryptFileFragment extends DecryptFragment {
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
- // Message is received after encrypting is done in KeychainIntentService
+ // Message is received after decrypting is done in KeychainIntentService
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(),
getString(R.string.progress_decrypting), ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
@@ -178,7 +263,7 @@ public class DecryptFileFragment extends DecryptFragment {
if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) {
showPassphraseDialog(decryptVerifyResult.getKeyIdPassphraseNeeded());
} else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED ==
- decryptVerifyResult.getStatus()) {
+ decryptVerifyResult.getStatus()) {
showPassphraseDialog(Constants.key.symmetric);
} else {
// display signature result in activity
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java
index ab26d539a..a5cf4d84d 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java
@@ -264,12 +264,12 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn
// fill values for this action
Bundle data = new Bundle();
- int compressionId;
if (isContentMessage()) {
data.putInt(KeychainIntentService.TARGET, KeychainIntentService.IO_BYTES);
data.putByteArray(KeychainIntentService.ENCRYPT_MESSAGE_BYTES, mMessage.getBytes());
- compressionId = Preferences.getPreferences(this).getDefaultMessageCompression();
+ data.putInt(KeychainIntentService.ENCRYPT_COMPRESSION_ID,
+ Preferences.getPreferences(this).getDefaultMessageCompression());
} else {
data.putInt(KeychainIntentService.SOURCE, KeychainIntentService.IO_URIS);
data.putParcelableArrayList(KeychainIntentService.ENCRYPT_INPUT_URIS, mInputUris);
@@ -277,10 +277,10 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn
data.putInt(KeychainIntentService.TARGET, KeychainIntentService.IO_URIS);
data.putParcelableArrayList(KeychainIntentService.ENCRYPT_OUTPUT_URIS, mOutputUris);
- compressionId = Preferences.getPreferences(this).getDefaultFileCompression();
+ data.putInt(KeychainIntentService.ENCRYPT_COMPRESSION_ID,
+ Preferences.getPreferences(this).getDefaultFileCompression());
}
- data.putInt(KeychainIntentService.ENCRYPT_COMPRESSION_ID, compressionId);
// Always use armor for messages
data.putBoolean(KeychainIntentService.ENCRYPT_USE_ASCII_ARMOR, mUseArmor || isContentMessage());
@@ -429,7 +429,6 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn
if (isModeSymmetric()) {
// symmetric encryption checks
-
if (mPassphrase == null) {
Notify.showNotify(this, R.string.passphrases_do_not_match, Notify.Style.ERROR);
return false;