diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-10-09 13:11:25 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-10-09 13:11:25 +0200 |
commit | 3316cb65e6b739deb7d0652fcd16a9d9bedf8c5b (patch) | |
tree | 55646a5750f3c351c3f3bd33bc6be65fc42c9712 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui | |
parent | 83fef47ec89ce1baa92340bbd528dd23c66e5f53 (diff) | |
download | open-keychain-3316cb65e6b739deb7d0652fcd16a9d9bedf8c5b.tar.gz open-keychain-3316cb65e6b739deb7d0652fcd16a9d9bedf8c5b.tar.bz2 open-keychain-3316cb65e6b739deb7d0652fcd16a9d9bedf8c5b.zip |
viewkeyactivity: ask for passphrase for backup only if key has one
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java | 32 |
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 de859724b..0fb7cdf92 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 backupToFile() { |