From 082722a3cfbae408ae3df1f27b191c62a212ff2b Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 26 Oct 2014 22:00:57 +0100 Subject: prevent cancel dring consolidate, move logic into progressable --- .../java/org/sufficientlysecure/keychain/pgp/Progressable.java | 2 ++ .../org/sufficientlysecure/keychain/provider/ProviderHelper.java | 3 +++ .../keychain/service/KeychainIntentService.java | 8 ++++++-- .../java/org/sufficientlysecure/keychain/util/ProgressScaler.java | 6 ++++++ 4 files changed, 17 insertions(+), 2 deletions(-) (limited to 'OpenKeychain/src/main/java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/Progressable.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/Progressable.java index fd3e2db8f..5de69b887 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/Progressable.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/Progressable.java @@ -23,4 +23,6 @@ public interface Progressable { void setProgress(int resourceId, int current, int total); void setProgress(int current, int total); + + void setPreventCancel(); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index 46f294866..ce9a14a6f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -938,6 +938,9 @@ public class ProviderHelper { progress.setProgress(R.string.progress_con_saving, 0, 100); + // The consolidate operation can never be cancelled! + progress.setPreventCancel(); + try { log.add(LogType.MSG_CON_SAVE_SECRET, indent); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 044656a31..a2988f2b2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -472,8 +472,7 @@ public class KeychainIntentService extends IntentService implements Progressable // Special: consolidate on secret key import (cannot be cancelled!) if (result.mSecret > 0) { - // cannot cancel from here on out! - sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_PREVENT_CANCEL); + // TODO move this into the import operation providerHelper.consolidateDatabaseStep1(this); } @@ -676,6 +675,11 @@ public class KeychainIntentService extends IntentService implements Progressable setProgress(null, progress, max); } + @Override + public void setPreventCancel() { + sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_PREVENT_CANCEL); + } + private InputData createDecryptInputData(Bundle data) throws IOException, PgpGeneralException { return createCryptInputData(data, DECRYPT_CIPHERTEXT_BYTES); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressScaler.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressScaler.java index 5256f5212..6bec9ccab 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressScaler.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressScaler.java @@ -60,4 +60,10 @@ public class ProgressScaler implements Progressable { } } + @Override + public void setPreventCancel() { + if (mWrapped != null) { + mWrapped.setPreventCancel(); + } + } } -- cgit v1.2.3 From 5ce89c4af84ba4eec89bb62d723911d31388e4ff Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 26 Oct 2014 22:20:44 +0100 Subject: fix consolidate if no secret key are present --- .../org/sufficientlysecure/keychain/provider/ProviderHelper.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'OpenKeychain/src/main/java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index ce9a14a6f..b18b919c3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -950,11 +950,13 @@ public class ProviderHelper { KeyRings.PRIVKEY_DATA, KeyRings.FINGERPRINT, KeyRings.HAS_ANY_SECRET }, KeyRings.HAS_ANY_SECRET + " = 1", null, null); - if (cursor == null || !cursor.moveToFirst()) { + if (cursor == null) { log.add(LogType.MSG_CON_ERROR_DB, indent); return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); } + // No keys existing might be a legitimate option, we write an empty file in that case + cursor.moveToFirst(); ParcelableFileCache cache = new ParcelableFileCache(mContext, "consolidate_secret.pcl"); cache.writeCache(cursor.getCount(), new Iterator() { @@ -1010,11 +1012,13 @@ public class ProviderHelper { KeyRings.PUBKEY_DATA, KeyRings.FINGERPRINT }, null, null, null); - if (cursor == null || !cursor.moveToFirst()) { + if (cursor == null) { log.add(LogType.MSG_CON_ERROR_DB, indent); return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); } + // No keys existing might be a legitimate option, we write an empty file in that case + cursor.moveToFirst(); ParcelableFileCache cache = new ParcelableFileCache(mContext, "consolidate_public.pcl"); cache.writeCache(cursor.getCount(), new Iterator() { -- cgit v1.2.3 From ce58eb4b032c6919239bf407ed6cbd2dfeadfbbb Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 26 Oct 2014 22:25:44 +0100 Subject: disable cancel button instead of hiding it on cancel prevention --- .../sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenKeychain/src/main/java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java index d09be2d51..df7943f55 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java @@ -145,7 +145,7 @@ public class ProgressDialogFragment extends DialogFragment { mPreventCancel = preventCancel; final Button negative = ((ProgressDialog) getDialog()).getButton(DialogInterface.BUTTON_NEGATIVE); - negative.setVisibility(preventCancel ? View.GONE : View.VISIBLE); + negative.setEnabled(mIsCancelled && !preventCancel); } @Override -- cgit v1.2.3 From 84b234af3720368fcf6c61dcd61b8a7d8986a1b4 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 26 Oct 2014 22:29:47 +0100 Subject: Display error on certification attempt with yubikey Closes #978 --- .../org/sufficientlysecure/keychain/operations/CertifyOperation.java | 5 +++++ .../keychain/operations/results/OperationResult.java | 1 + 2 files changed, 6 insertions(+) (limited to 'OpenKeychain/src/main/java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java index 9af6713ba..3bd412c36 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java @@ -7,6 +7,7 @@ import org.sufficientlysecure.keychain.keyimport.HkpKeyserver; import org.sufficientlysecure.keychain.keyimport.Keyserver.AddKeyException; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; +import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; @@ -57,6 +58,10 @@ public class CertifyOperation extends BaseOperation { mProviderHelper.getCanonicalizedSecretKeyRing(parcel.mMasterKeyId); log.add(LogType.MSG_CRT_UNLOCK, 1); certificationKey = secretKeyRing.getSecretKey(); + if (certificationKey.getSecretKeyType() == SecretKeyType.DIVERT_TO_CARD) { + log.add(LogType.MSG_CRT_ERROR_DIVERT, 2); + return new CertifyResult(CertifyResult.RESULT_ERROR, log); + } if (!certificationKey.unlock(passphrase)) { log.add(LogType.MSG_CRT_ERROR_UNLOCK, 2); return new CertifyResult(CertifyResult.RESULT_ERROR, log); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java index 920c83ef7..dc45fabc3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java @@ -575,6 +575,7 @@ public abstract class OperationResult implements Parcelable { MSG_CRT_ERROR_MASTER_NOT_FOUND (LogLevel.ERROR, R.string.msg_crt_error_master_not_found), MSG_CRT_ERROR_NOTHING (LogLevel.ERROR, R.string.msg_crt_error_nothing), MSG_CRT_ERROR_UNLOCK (LogLevel.ERROR, R.string.msg_crt_error_unlock), + MSG_CRT_ERROR_DIVERT (LogLevel.ERROR, R.string.msg_crt_error_divert), MSG_CRT (LogLevel.START, R.string.msg_crt), MSG_CRT_MASTER_FETCH (LogLevel.DEBUG, R.string.msg_crt_master_fetch), MSG_CRT_SAVE (LogLevel.DEBUG, R.string.msg_crt_save), -- cgit v1.2.3