viewkeyactivity: ask for passphrase for backup only if key has one
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user