aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-10-09 13:11:25 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2015-10-09 14:56:02 +0200
commit315ed608ae977f1a25f1cd06a4e2d52ca09e01b2 (patch)
treee88001a5b53c626ad2aff555f72c563dda2b3b14 /OpenKeychain/src/main
parent6cf7e3e541ff954f5f9065ab52e6cee93c0643d3 (diff)
downloadopen-keychain-315ed608ae977f1a25f1cd06a4e2d52ca09e01b2.tar.gz
open-keychain-315ed608ae977f1a25f1cd06a4e2d52ca09e01b2.tar.bz2
open-keychain-315ed608ae977f1a25f1cd06a4e2d52ca09e01b2.zip
viewkeyactivity: ask for passphrase for backup only if key has one
Diffstat (limited to 'OpenKeychain/src/main')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java32
1 files changed, 29 insertions, 3 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
index 4b3889737..48edbcbd6 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
@@ -65,12 +65,14 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult;
+import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
+import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
import org.sufficientlysecure.keychain.ui.ViewKeyFragment.PostponeType;
import org.sufficientlysecure.keychain.ui.base.BaseNfcActivity;
@@ -450,9 +452,33 @@ public class ViewKeyActivity extends BaseNfcActivity implements
}
private void startPassphraseActivity(int requestCode) {
- Intent intent = new Intent(this, PassphraseDialogActivity.class);
- intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, mMasterKeyId);
- startActivityForResult(intent, requestCode);
+
+ if (keyHasPassphrase()) {
+ Intent intent = new Intent(this, PassphraseDialogActivity.class);
+ intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, mMasterKeyId);
+ startActivityForResult(intent, requestCode);
+ } else {
+ startBackupActivity();
+ }
+ }
+
+ private boolean keyHasPassphrase() {
+ try {
+ SecretKeyType secretKeyType =
+ mProviderHelper.getCachedPublicKeyRing(mMasterKeyId).getSecretKeyType(mMasterKeyId);
+ switch (secretKeyType) {
+ // all of these make no sense to ask
+ case PASSPHRASE_EMPTY:
+ case GNU_DUMMY:
+ case DIVERT_TO_CARD:
+ case UNAVAILABLE:
+ return false;
+ default:
+ return true;
+ }
+ } catch (NotFoundException e) {
+ return false;
+ }
}
private void startBackupActivity() {