From d577257bd5c9dc6f1e7cfef67d7eb4a825e12fbf Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 20 Feb 2017 16:20:20 +0100 Subject: [PATCH 01/11] rename ProviderHelper -> DatabaseInteractor --- .../keychain/TestHelpers.java | 7 +- .../keychain/actions/CustomActions.java | 6 +- .../keychain/operations/BackupOperation.java | 14 +-- .../keychain/operations/BaseOperation.java | 16 ++-- .../operations/BenchmarkOperation.java | 11 ++- .../keychain/operations/CertifyOperation.java | 20 ++--- .../operations/ChangeUnlockOperation.java | 12 +-- .../operations/ConsolidateOperation.java | 10 +-- .../keychain/operations/DeleteOperation.java | 10 +-- .../keychain/operations/EditKeyOperation.java | 15 ++-- .../keychain/operations/ImportOperation.java | 24 +++--- .../operations/InputDataOperation.java | 10 +-- .../KeybaseVerificationOperation.java | 8 +- .../operations/PromoteKeyOperation.java | 12 +-- .../keychain/operations/RevokeOperation.java | 12 +-- .../operations/SignEncryptOperation.java | 10 +-- .../keychain/operations/UploadOperation.java | 10 +-- .../keychain/pgp/CanonicalizedSecretKey.java | 4 +- .../pgp/OpenPgpSignatureResultBuilder.java | 12 +-- .../pgp/PgpDecryptVerifyOperation.java | 18 ++-- .../keychain/pgp/PgpSignEncryptOperation.java | 20 ++--- .../keychain/pgp/PgpSignatureChecker.java | 18 ++-- .../provider/CachedPublicKeyRing.java | 86 +++++++++---------- ...derHelper.java => DatabaseInteractor.java} | 12 +-- .../keychain/remote/OpenPgpService.java | 22 ++--- .../ui/RequestKeyPermissionPresenter.java | 16 ++-- .../keychain/service/KeychainService.java | 32 +++---- .../service/KeyserverSyncAdapterService.java | 6 +- .../service/PassphraseCacheService.java | 12 +-- .../ui/CertifyFingerprintFragment.java | 4 +- .../keychain/ui/CertifyKeyFragment.java | 16 +--- .../keychain/ui/CreateKeyActivity.java | 4 +- .../keychain/ui/CreateKeyFinalFragment.java | 6 +- .../keychain/ui/DecryptFragment.java | 4 +- .../keychain/ui/DeleteKeyDialogActivity.java | 20 ++--- .../keychain/ui/EditIdentitiesFragment.java | 6 +- .../keychain/ui/EditKeyFragment.java | 6 +- .../ui/EncryptModeAsymmetricFragment.java | 13 ++- .../keychain/ui/KeyListFragment.java | 6 +- .../keychain/ui/PassphraseDialogActivity.java | 13 ++- .../keychain/ui/QrCodeViewActivity.java | 10 +-- .../keychain/ui/SafeSlingerActivity.java | 8 +- .../ui/SecurityTokenOperationActivity.java | 14 +-- .../keychain/ui/ViewCertActivity.java | 6 +- .../keychain/ui/ViewKeyActivity.java | 30 +++---- .../keychain/ui/ViewKeyAdvActivity.java | 8 +- .../keychain/ui/ViewKeyAdvShareFragment.java | 16 ++-- .../ui/adapter/ImportKeysAdapter.java | 12 +-- .../ui/base/BaseSecurityTokenActivity.java | 4 +- .../keychain/ui/linked/LinkedIdWizard.java | 4 +- .../keychain/util/NfcHelper.java | 15 ++-- .../operations/BackupOperationTest.java | 16 ++-- .../operations/BenchmarkOperationTest.java | 4 +- .../operations/CertifyOperationTest.java | 26 +++--- .../operations/PromoteKeyOperationTest.java | 18 ++-- .../keychain/pgp/InputDataOperationTest.java | 6 +- .../keychain/pgp/PgpEncryptDecryptTest.java | 60 ++++++------- ...ava => DatabaseInteractorKeyringTest.java} | 2 +- ...t.java => DatabaseInteractorSaveTest.java} | 44 +++++----- .../keychain/provider/InteropTest.java | 2 +- .../remote/KeychainExternalProviderTest.java | 14 +-- ...rStub.java => DatabaseInteractorStub.java} | 6 +- .../support/KeyringTestingHelper.java | 18 ++-- 63 files changed, 439 insertions(+), 467 deletions(-) rename OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/{ProviderHelper.java => DatabaseInteractor.java} (99%) rename OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/{ProviderHelperKeyringTest.java => DatabaseInteractorKeyringTest.java} (98%) rename OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/{ProviderHelperSaveTest.java => DatabaseInteractorSaveTest.java} (83%) rename OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/{ProviderHelperStub.java => DatabaseInteractorStub.java} (86%) diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java index 29d6c7262..6d957e6fc 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java @@ -31,18 +31,15 @@ import android.content.Context; import android.support.annotation.StringRes; import android.support.test.espresso.UiController; import android.support.test.espresso.ViewAction; -import android.support.test.espresso.base.DefaultFailureHandler; import android.support.test.espresso.matcher.ViewMatchers; import android.view.View; import com.nispok.snackbar.Snackbar; -import com.tokenautocomplete.TokenCompleteTextView; -import org.hamcrest.CoreMatchers; import org.hamcrest.Matcher; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow; import org.sufficientlysecure.keychain.provider.KeychainDatabase; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.util.ProgressScaler; @@ -100,7 +97,7 @@ public class TestHelpers { IteratorWithIOThrow stream = UncachedKeyRing.fromStream( getInstrumentation().getContext().getAssets().open(name)); - ProviderHelper helper = new ProviderHelper(context); + DatabaseInteractor helper = new DatabaseInteractor(context); while(stream.hasNext()) { UncachedKeyRing ring = stream.next(); if (ring.isSecret()) { diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java index 75197ac9e..ee532ab92 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java @@ -22,14 +22,12 @@ package org.sufficientlysecure.keychain.actions; import android.support.test.espresso.UiController; import android.support.test.espresso.ViewAction; import android.support.test.espresso.matcher.ViewMatchers; -import android.support.v4.view.GravityCompat; -import android.support.v4.widget.DrawerLayout; import android.view.View; import com.tokenautocomplete.TokenCompleteTextView; import org.hamcrest.Matcher; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter; import static android.support.test.InstrumentationRegistry.getTargetContext; @@ -39,7 +37,7 @@ public abstract class CustomActions { public static ViewAction tokenEncryptViewAddToken(long keyId) throws Exception { CanonicalizedPublicKeyRing ring = - new ProviderHelper(getTargetContext()).getCanonicalizedPublicKeyRing(keyId); + new DatabaseInteractor(getTargetContext()).getCanonicalizedPublicKeyRing(keyId); final Object item = new KeyAdapter.KeyItem(ring); return new ViewAction() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java index 0895e5251..f8568ee3c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java @@ -53,7 +53,7 @@ import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.BackupKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -86,14 +86,14 @@ public class BackupOperation extends BaseOperation { private static final int INDEX_SECKEY_DATA = 2; private static final int INDEX_HAS_ANY_SECRET = 3; - public BackupOperation(Context context, ProviderHelper providerHelper, Progressable + public BackupOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { - super(context, providerHelper, progressable); + super(context, databaseInteractor, progressable); } - public BackupOperation(Context context, ProviderHelper providerHelper, + public BackupOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } @NonNull @@ -170,7 +170,7 @@ public class BackupOperation extends BaseOperation { private PgpSignEncryptResult encryptBackupData(@NonNull BackupKeyringParcel backupInput, @NonNull CryptoInputParcel cryptoInput, @Nullable OutputStream outputStream, Uri plainUri, long exportedDataSize) throws FileNotFoundException { - PgpSignEncryptOperation signEncryptOperation = new PgpSignEncryptOperation(mContext, mProviderHelper, mProgressable, mCancelled); + PgpSignEncryptOperation signEncryptOperation = new PgpSignEncryptOperation(mContext, mDatabaseInteractor, mProgressable, mCancelled); PgpSignEncryptData data = new PgpSignEncryptData(); data.setSymmetricPassphrase(cryptoInput.getPassphrase()); @@ -326,7 +326,7 @@ public class BackupOperation extends BaseOperation { + " IN (" + placeholders + ")"; } - return mProviderHelper.getContentResolver().query( + return mDatabaseInteractor.getContentResolver().query( KeyRings.buildUnifiedKeyRingsUri(), PROJECTION, selection, selectionArgs, Tables.KEYS + "." + KeyRings.MASTER_KEY_ID ); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java index 99d1768b1..ee21eb007 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java @@ -26,8 +26,8 @@ import org.sufficientlysecure.keychain.Constants.key; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.PassphraseCacheInterface; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Passphrase; @@ -40,7 +40,7 @@ public abstract class BaseOperation implements Passphrase final public Progressable mProgressable; final public AtomicBoolean mCancelled; - final public ProviderHelper mProviderHelper; + final public DatabaseInteractor mDatabaseInteractor; /** An abstract base class for all *Operation classes. It provides a number * of common methods for progress, cancellation and passphrase cache handling. @@ -64,18 +64,18 @@ public abstract class BaseOperation implements Passphrase * if there is no prefix it is considered Android-related. * */ - public BaseOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { + public BaseOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { this.mContext = context; this.mProgressable = progressable; - this.mProviderHelper = providerHelper; + this.mDatabaseInteractor = databaseInteractor; mCancelled = null; } - public BaseOperation(Context context, ProviderHelper providerHelper, + public BaseOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { mContext = context; mProgressable = progressable; - mProviderHelper = providerHelper; + mDatabaseInteractor = databaseInteractor; mCancelled = cancelled; } @@ -114,7 +114,7 @@ public abstract class BaseOperation implements Passphrase public Passphrase getCachedPassphrase(long subKeyId) throws NoSecretKeyException { try { if (subKeyId != key.symmetric) { - long masterKeyId = mProviderHelper.getMasterKeyId(subKeyId); + long masterKeyId = mDatabaseInteractor.getMasterKeyId(subKeyId); return getCachedPassphrase(masterKeyId, subKeyId); } return getCachedPassphrase(key.symmetric, key.symmetric); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java index a179fa66a..ece2d5487 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java @@ -41,12 +41,11 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.Operat import org.sufficientlysecure.keychain.operations.results.SignEncryptResult; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; -import org.sufficientlysecure.keychain.pgp.PgpSecurityConstants; import org.sufficientlysecure.keychain.pgp.PgpSecurityConstants.OpenKeychainSymmetricKeyAlgorithmTags; import org.sufficientlysecure.keychain.pgp.PgpSignEncryptData; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.BenchmarkInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Log; @@ -56,9 +55,9 @@ import org.sufficientlysecure.keychain.util.ProgressScaler; public class BenchmarkOperation extends BaseOperation { - public BenchmarkOperation(Context context, ProviderHelper providerHelper, Progressable + public BenchmarkOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { - super(context, providerHelper, progressable); + super(context, databaseInteractor, progressable); } @NonNull @@ -82,7 +81,7 @@ public class BenchmarkOperation extends BaseOperation { int i = 0; do { SignEncryptOperation op = - new SignEncryptOperation(mContext, mProviderHelper, + new SignEncryptOperation(mContext, mDatabaseInteractor, new ProgressScaler(mProgressable, i*(50/numRepeats), (i+1)*(50/numRepeats), 100), mCancelled); PgpSignEncryptData data = new PgpSignEncryptData(); data.setSymmetricPassphrase(passphrase); @@ -104,7 +103,7 @@ public class BenchmarkOperation extends BaseOperation { do { DecryptVerifyResult decryptResult; PgpDecryptVerifyOperation op = - new PgpDecryptVerifyOperation(mContext, mProviderHelper, + new PgpDecryptVerifyOperation(mContext, mDatabaseInteractor, new ProgressScaler(mProgressable, 50 +i*(50/numRepeats), 50 +(i+1)*(50/numRepeats), 100)); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(encryptResult.getResultBytes()); input.setAllowSymmetricDecryption(true); 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 b4b27f7ab..17d30f75f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java @@ -39,8 +39,8 @@ import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; @@ -62,9 +62,9 @@ import org.sufficientlysecure.keychain.util.Passphrase; */ public class CertifyOperation extends BaseOperation { - public CertifyOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean + public CertifyOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } @NonNull @@ -81,7 +81,7 @@ public class CertifyOperation extends BaseOperation { log.add(LogType.MSG_CRT_MASTER_FETCH, 1); - CachedPublicKeyRing cachedPublicKeyRing = mProviderHelper.getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing cachedPublicKeyRing = mDatabaseInteractor.getCachedPublicKeyRing(masterKeyId); Passphrase passphrase; switch (cachedPublicKeyRing.getSecretKeyType(masterKeyId)) { @@ -121,7 +121,7 @@ public class CertifyOperation extends BaseOperation { // Get actual secret key CanonicalizedSecretKeyRing secretKeyRing = - mProviderHelper.getCanonicalizedSecretKeyRing(parcel.mMasterKeyId); + mDatabaseInteractor.getCanonicalizedSecretKeyRing(parcel.mMasterKeyId); certificationKey = secretKeyRing.getSecretKey(); log.add(LogType.MSG_CRT_UNLOCK, 1); @@ -165,7 +165,7 @@ public class CertifyOperation extends BaseOperation { } CanonicalizedPublicKeyRing publicRing = - mProviderHelper.getCanonicalizedPublicKeyRing(action.mMasterKeyId); + mDatabaseInteractor.getCanonicalizedPublicKeyRing(action.mMasterKeyId); PgpCertifyOperation op = new PgpCertifyOperation(); PgpCertifyResult result = op.certify(certificationKey, publicRing, @@ -206,7 +206,7 @@ public class CertifyOperation extends BaseOperation { // these variables are used inside the following loop, but they need to be created only once UploadOperation uploadOperation = null; if (parcel.keyServerUri != null) { - uploadOperation = new UploadOperation(mContext, mProviderHelper, mProgressable, mCancelled); + uploadOperation = new UploadOperation(mContext, mDatabaseInteractor, mProgressable, mCancelled); } // Write all certified keys into the database @@ -222,8 +222,8 @@ public class CertifyOperation extends BaseOperation { log.add(LogType.MSG_CRT_SAVE, 2, KeyFormattingUtils.convertKeyIdToHex(certifiedKey.getMasterKeyId())); // store the signed key in our local cache - mProviderHelper.clearLog(); - SaveKeyringResult result = mProviderHelper.savePublicKeyRing(certifiedKey); + mDatabaseInteractor.clearLog(); + SaveKeyringResult result = mDatabaseInteractor.savePublicKeyRing(certifiedKey); if (uploadOperation != null) { UploadKeyringParcel uploadInput = diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ChangeUnlockOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ChangeUnlockOperation.java index f9ae13b1a..4cf76e5a3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ChangeUnlockOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ChangeUnlockOperation.java @@ -29,7 +29,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -38,8 +38,8 @@ import org.sufficientlysecure.keychain.util.ProgressScaler; public class ChangeUnlockOperation extends BaseOperation { - public ChangeUnlockOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { - super(context, providerHelper, progressable); + public ChangeUnlockOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { + super(context, databaseInteractor, progressable); } @NonNull @@ -63,7 +63,7 @@ public class ChangeUnlockOperation extends BaseOperation { KeyFormattingUtils.convertKeyIdToHex(unlockParcel.mMasterKeyId)); CanonicalizedSecretKeyRing secRing = - mProviderHelper.getCanonicalizedSecretKeyRing(unlockParcel.mMasterKeyId); + mDatabaseInteractor.getCanonicalizedSecretKeyRing(unlockParcel.mMasterKeyId); modifyResult = keyOperations.modifyKeyRingPassphrase(secRing, cryptoInput, unlockParcel); if (modifyResult.isPending()) { @@ -71,7 +71,7 @@ public class ChangeUnlockOperation extends BaseOperation { log.add(modifyResult, 1); return new EditKeyResult(log, modifyResult); } - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { log.add(OperationResult.LogType.MSG_ED_ERROR_KEY_NOT_FOUND, 2); return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null); } @@ -90,7 +90,7 @@ public class ChangeUnlockOperation extends BaseOperation { // It's a success, so this must be non-null now UncachedKeyRing ring = modifyResult.getRing(); - SaveKeyringResult saveResult = mProviderHelper + SaveKeyringResult saveResult = mDatabaseInteractor .saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 70, 95, 100)); log.add(saveResult, 1); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ConsolidateOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ConsolidateOperation.java index 782cd6800..1142b085e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ConsolidateOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ConsolidateOperation.java @@ -24,15 +24,15 @@ import android.support.annotation.NonNull; import org.sufficientlysecure.keychain.operations.results.ConsolidateResult; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ConsolidateInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; public class ConsolidateOperation extends BaseOperation { - public ConsolidateOperation(Context context, ProviderHelper providerHelper, Progressable + public ConsolidateOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { - super(context, providerHelper, progressable); + super(context, databaseInteractor, progressable); } @NonNull @@ -40,9 +40,9 @@ public class ConsolidateOperation extends BaseOperation public ConsolidateResult execute(ConsolidateInputParcel consolidateInputParcel, CryptoInputParcel cryptoInputParcel) { if (consolidateInputParcel.mConsolidateRecovery) { - return mProviderHelper.consolidateDatabaseStep2(mProgressable); + return mDatabaseInteractor.consolidateDatabaseStep2(mProgressable); } else { - return mProviderHelper.consolidateDatabaseStep1(mProgressable); + return mDatabaseInteractor.consolidateDatabaseStep1(mProgressable); } } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java index 8227fea02..e86591d6b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java @@ -27,7 +27,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.LogTyp import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.DeleteKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -43,8 +43,8 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; */ public class DeleteOperation extends BaseOperation { - public DeleteOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { - super(context, providerHelper, progressable); + public DeleteOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { + super(context, databaseInteractor, progressable); } @NonNull @@ -81,7 +81,7 @@ public class DeleteOperation extends BaseOperation { cancelled = true; break; } - int count = mProviderHelper.getContentResolver().delete( + int count = mDatabaseInteractor.getContentResolver().delete( KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null ); if (count > 0) { @@ -95,7 +95,7 @@ public class DeleteOperation extends BaseOperation { if (isSecret && success > 0) { log.add(LogType.MSG_DEL_CONSOLIDATE, 1); - ConsolidateResult sub = mProviderHelper.consolidateDatabaseStep1(mProgressable); + ConsolidateResult sub = mDatabaseInteractor.consolidateDatabaseStep1(mProgressable); log.add(sub, 2); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java index 8af2fdc67..ab4e95fcc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java @@ -35,10 +35,9 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; -import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -58,9 +57,9 @@ import org.sufficientlysecure.keychain.util.ProgressScaler; */ public class EditKeyOperation extends BaseOperation { - public EditKeyOperation(Context context, ProviderHelper providerHelper, + public EditKeyOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } /** @@ -95,7 +94,7 @@ public class EditKeyOperation extends BaseOperation { log.add(LogType.MSG_ED_FETCHING, 1, KeyFormattingUtils.convertKeyIdToHex(saveParcel.mMasterKeyId)); CanonicalizedSecretKeyRing secRing = - mProviderHelper.getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId); + mDatabaseInteractor.getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId); modifyResult = keyOperations.modifySecretKeyRing(secRing, cryptoInput, saveParcel); if (modifyResult.isPending()) { @@ -148,7 +147,7 @@ public class EditKeyOperation extends BaseOperation { new UploadKeyringParcel(saveParcel.getUploadKeyserver(), keyringBytes); UploadResult uploadResult = - new UploadOperation(mContext, mProviderHelper, mProgressable, mCancelled) + new UploadOperation(mContext, mDatabaseInteractor, mProgressable, mCancelled) .execute(exportKeyringParcel, cryptoInput); log.add(uploadResult, 2); @@ -162,7 +161,7 @@ public class EditKeyOperation extends BaseOperation { } // Save the new keyring. - SaveKeyringResult saveResult = mProviderHelper + SaveKeyringResult saveResult = mDatabaseInteractor .saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 60, 95, 100)); log.add(saveResult, 1); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java index d465bde04..4757d7874 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java @@ -39,7 +39,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -86,14 +86,14 @@ public class ImportOperation extends BaseOperation { public static final String CACHE_FILE_NAME = "key_import.pcl"; - public ImportOperation(Context context, ProviderHelper providerHelper, Progressable + public ImportOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { - super(context, providerHelper, progressable); + super(context, databaseInteractor, progressable); } - public ImportOperation(Context context, ProviderHelper providerHelper, + public ImportOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } // Overloaded functions for using progressable supplied in constructor during import @@ -314,15 +314,15 @@ public class ImportOperation extends BaseOperation { SaveKeyringResult result; // synchronizing prevents https://github.com/open-keychain/open-keychain/issues/1221 // and https://github.com/open-keychain/open-keychain/issues/1480 - synchronized (mProviderHelper) { - mProviderHelper.clearLog(); + synchronized (mDatabaseInteractor) { + mDatabaseInteractor.clearLog(); ProgressScaler progressScaler = new ProgressScaler(progressable, (int) (position * progSteps), (int) ((position + 1) * progSteps), 100); if (key.isSecret()) { - result = mProviderHelper.saveSecretKeyRing(key, progressScaler, + result = mDatabaseInteractor.saveSecretKeyRing(key, progressScaler, canKeyRings, skipSave); } else { - result = mProviderHelper.savePublicKeyRing(key, progressScaler, + result = mDatabaseInteractor.savePublicKeyRing(key, progressScaler, entry.mExpectedFingerprint, canKeyRings, skipSave); } } @@ -343,7 +343,7 @@ public class ImportOperation extends BaseOperation { // synonymous to isDownloadFromKeyserver. // If no byte data was supplied, import from keyserver took place // this prevents file imports being noted as keyserver imports - mProviderHelper.renewKeyLastUpdatedTime(key.getMasterKeyId(), + mDatabaseInteractor.renewKeyLastUpdatedTime(key.getMasterKeyId(), GregorianCalendar.getInstance().getTimeInMillis(), TimeUnit.MILLISECONDS); } @@ -365,8 +365,8 @@ public class ImportOperation extends BaseOperation { if (!skipSave && (secret > 0)) { setPreventCancel(); ConsolidateResult result; - synchronized (mProviderHelper) { - result = mProviderHelper.consolidateDatabaseStep1(progressable); + synchronized (mDatabaseInteractor) { + result = mDatabaseInteractor.consolidateDatabaseStep1(progressable); } log.add(result, 1); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java index 68220857b..2c62778b8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java @@ -50,7 +50,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.Operat import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.InputDataParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -71,8 +71,8 @@ public class InputDataOperation extends BaseOperation { private final byte[] buf = new byte[256]; - public InputDataOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { - super(context, providerHelper, progressable); + public InputDataOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { + super(context, databaseInteractor, progressable); } Uri mSignedDataUri; @@ -101,7 +101,7 @@ public class InputDataOperation extends BaseOperation { log.add(LogType.MSG_DATA_OPENPGP, 1); PgpDecryptVerifyOperation op = - new PgpDecryptVerifyOperation(mContext, mProviderHelper, mProgressable); + new PgpDecryptVerifyOperation(mContext, mDatabaseInteractor, mProgressable); decryptInput.setInputUri(input.getInputUri()); @@ -269,7 +269,7 @@ public class InputDataOperation extends BaseOperation { decryptInput.setDetachedSignature(detachedSig.toByteArray()); PgpDecryptVerifyOperation op = - new PgpDecryptVerifyOperation(mContext, mProviderHelper, mProgressable); + new PgpDecryptVerifyOperation(mContext, mDatabaseInteractor, mProgressable); DecryptVerifyResult verifyResult = op.execute(decryptInput, cryptoInput); log.addByMerge(verifyResult, 4); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java index 2bcb84592..4f4a8b0db 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java @@ -36,7 +36,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.KeybaseVerificationParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -59,9 +59,9 @@ import de.measite.minidns.record.TXT; public class KeybaseVerificationOperation extends BaseOperation { - public KeybaseVerificationOperation(Context context, ProviderHelper providerHelper, + public KeybaseVerificationOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { - super(context, providerHelper, progressable); + super(context, databaseInteractor, progressable); } @NonNull @@ -147,7 +147,7 @@ public class KeybaseVerificationOperation extends BaseOperation { - public PromoteKeyOperation(Context context, ProviderHelper providerHelper, + public PromoteKeyOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } @NonNull @@ -70,7 +70,7 @@ public class PromoteKeyOperation extends BaseOperation { log.add(LogType.MSG_PR_FETCHING, 1, KeyFormattingUtils.convertKeyIdToHex(promoteKeyringParcel.mKeyRingId)); CanonicalizedPublicKeyRing pubRing = - mProviderHelper.getCanonicalizedPublicKeyRing(promoteKeyringParcel.mKeyRingId); + mDatabaseInteractor.getCanonicalizedPublicKeyRing(promoteKeyringParcel.mKeyRingId); if (promoteKeyringParcel.mSubKeyIds == null) { log.add(LogType.MSG_PR_ALL, 1); @@ -114,7 +114,7 @@ public class PromoteKeyOperation extends BaseOperation { setPreventCancel(); // Save the new keyring. - SaveKeyringResult saveResult = mProviderHelper + SaveKeyringResult saveResult = mDatabaseInteractor .saveSecretKeyRing(promotedRing, new ProgressScaler(mProgressable, 60, 95, 100)); log.add(saveResult, 1); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/RevokeOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/RevokeOperation.java index 3e787560a..920efb1ef 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/RevokeOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/RevokeOperation.java @@ -32,7 +32,7 @@ import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.RevokeKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -41,8 +41,8 @@ import org.sufficientlysecure.keychain.util.Log; public class RevokeOperation extends BaseOperation { - public RevokeOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { - super(context, providerHelper, progressable); + public RevokeOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { + super(context, databaseInteractor, progressable); } @NonNull @@ -62,7 +62,7 @@ public class RevokeOperation extends BaseOperation { try { Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(masterKeyId); - CachedPublicKeyRing keyRing = mProviderHelper.getCachedPublicKeyRing(secretUri); + CachedPublicKeyRing keyRing = mDatabaseInteractor.getCachedPublicKeyRing(secretUri); // check if this is a master secret key we can work with switch (keyRing.getSecretKeyType(masterKeyId)) { @@ -81,7 +81,7 @@ public class RevokeOperation extends BaseOperation { saveKeyringParcel.mRevokeSubKeys.add(masterKeyId); EditKeyResult revokeAndUploadResult = new EditKeyOperation(mContext, - mProviderHelper, mProgressable, mCancelled).execute(saveKeyringParcel, cryptoInputParcel); + mDatabaseInteractor, mProgressable, mCancelled).execute(saveKeyringParcel, cryptoInputParcel); if (revokeAndUploadResult.isPending()) { return revokeAndUploadResult; @@ -97,7 +97,7 @@ public class RevokeOperation extends BaseOperation { return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId); } - } catch (PgpKeyNotFoundException | ProviderHelper.NotFoundException e) { + } catch (PgpKeyNotFoundException | DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "could not find key to revoke", e); log.add(OperationResult.LogType.MSG_REVOKE_ERROR_KEY_FAIL, 1); return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java index dedc03553..fb5c941fb 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java @@ -33,7 +33,7 @@ import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.SecurityTokenSignOperationsBuilder; @@ -55,9 +55,9 @@ import java.util.concurrent.atomic.AtomicBoolean; */ public class SignEncryptOperation extends BaseOperation { - public SignEncryptOperation(Context context, ProviderHelper providerHelper, + public SignEncryptOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } @@ -81,7 +81,7 @@ public class SignEncryptOperation extends BaseOperation { if (data.getSignatureMasterKeyId() != Constants.key.none && data.getSignatureSubKeyId() == null) { try { - long signKeyId = mProviderHelper.getCachedPublicKeyRing( + long signKeyId = mDatabaseInteractor.getCachedPublicKeyRing( data.getSignatureMasterKeyId()).getSecretSignId(); data.setSignatureSubKeyId(signKeyId); } catch (PgpKeyNotFoundException e) { @@ -96,7 +96,7 @@ public class SignEncryptOperation extends BaseOperation { return new SignEncryptResult(SignEncryptResult.RESULT_CANCELLED, log, results); } - PgpSignEncryptOperation op = new PgpSignEncryptOperation(mContext, mProviderHelper, + PgpSignEncryptOperation op = new PgpSignEncryptOperation(mContext, mDatabaseInteractor, new ProgressScaler(mProgressable, 100 * count / total, 100 * ++count / total, 100), mCancelled); PgpSignEncryptInputParcel inputParcel = new PgpSignEncryptInputParcel(input.getData()); if (inputBytes != null) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java index 9e60f22e0..bc75d0ae7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java @@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -58,9 +58,9 @@ import java.util.concurrent.atomic.AtomicBoolean; */ public class UploadOperation extends BaseOperation { - public UploadOperation(Context context, ProviderHelper providerHelper, + public UploadOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } @NonNull @@ -120,7 +120,7 @@ public class UploadOperation extends BaseOperation { if (hasMasterKeyId) { log.add(LogType.MSG_UPLOAD_KEY, 0, KeyFormattingUtils.convertKeyIdToHex(uploadInput.mMasterKeyId)); - return mProviderHelper.getCanonicalizedPublicKeyRing(uploadInput.mMasterKeyId); + return mDatabaseInteractor.getCanonicalizedPublicKeyRing(uploadInput.mMasterKeyId); } CanonicalizedKeyRing canonicalizedRing = @@ -132,7 +132,7 @@ public class UploadOperation extends BaseOperation { log.add(LogType.MSG_UPLOAD_KEY, 0, KeyFormattingUtils.convertKeyIdToHex(canonicalizedRing.getMasterKeyId())); return (CanonicalizedPublicKeyRing) canonicalizedRing; - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { log.add(LogType.MSG_UPLOAD_ERROR_NOT_FOUND, 1); return null; } catch (IOException | PgpGeneralException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java index 29ea17e64..ee8a2b050 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java @@ -47,7 +47,7 @@ import org.bouncycastle.openpgp.operator.jcajce.SessionKeySecretKeyDecryptorBuil import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Passphrase; @@ -127,7 +127,7 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey { * passphrase in the process. * * This method can potentially take a LONG time (i.e. seconds), so it should only - * ever be called by {@link ProviderHelper} for the purpose of caching its output + * ever be called by {@link DatabaseInteractor} for the purpose of caching its output * in the database. */ public SecretKeyType getSecretKeyTypeSuperExpensive() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java index e327180c3..34fdc20c3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java @@ -27,8 +27,8 @@ import org.openintents.openpgp.util.OpenPgpUtils; import org.openintents.openpgp.util.OpenPgpUtils.UserId; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.util.Log; /** @@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.util.Log; */ public class OpenPgpSignatureResultBuilder { // injected - private final ProviderHelper mProviderHelper; + private final DatabaseInteractor mDatabaseInteractor; // OpenPgpSignatureResult private String mPrimaryUserId; @@ -57,8 +57,8 @@ public class OpenPgpSignatureResultBuilder { private String mSenderAddress; private Date mSignatureTimestamp; - public OpenPgpSignatureResultBuilder(ProviderHelper providerHelper) { - this.mProviderHelper = providerHelper; + public OpenPgpSignatureResultBuilder(DatabaseInteractor databaseInteractor) { + this.mDatabaseInteractor = databaseInteractor; } public void setPrimaryUserId(String userId) { @@ -127,7 +127,7 @@ public class OpenPgpSignatureResultBuilder { try { ArrayList allUserIds = signingRing.getUnorderedUserIds(); - ArrayList confirmedUserIds = mProviderHelper.getConfirmedUserIds(signingRing.getMasterKeyId()); + ArrayList confirmedUserIds = mDatabaseInteractor.getConfirmedUserIds(signingRing.getMasterKeyId()); setUserIds(allUserIds, confirmedUserIds); if (mSenderAddress != null) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java index 88334e9af..b7662b44e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java @@ -72,7 +72,7 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -87,8 +87,8 @@ public class PgpDecryptVerifyOperation extends BaseOperation encryptSubKeyIds = keyRing.getEncryptIds(); for (Long subKeyId : encryptSubKeyIds) { @@ -356,7 +356,7 @@ public class PgpSignEncryptOperation extends BaseOperation 0; - } catch(ProviderHelper.NotFoundException e) { + } catch(DatabaseInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -158,11 +158,11 @@ public class CachedPublicKeyRing extends KeyRing { @Override public boolean canCertify() throws PgpKeyNotFoundException { try { - Object data = mProviderHelper.getGenericData(mUri, + Object data = mDatabaseInteractor.getGenericData(mUri, KeychainContract.KeyRings.HAS_CERTIFY, - ProviderHelper.FIELD_TYPE_NULL); + DatabaseInteractor.FIELD_TYPE_NULL); return !((Boolean) data); - } catch(ProviderHelper.NotFoundException e) { + } catch(DatabaseInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -170,11 +170,11 @@ public class CachedPublicKeyRing extends KeyRing { @Override public long getEncryptId() throws PgpKeyNotFoundException { try { - Object data = mProviderHelper.getGenericData(mUri, + Object data = mDatabaseInteractor.getGenericData(mUri, KeyRings.HAS_ENCRYPT, - ProviderHelper.FIELD_TYPE_INTEGER); + DatabaseInteractor.FIELD_TYPE_INTEGER); return (Long) data; - } catch(ProviderHelper.NotFoundException e) { + } catch(DatabaseInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -192,11 +192,11 @@ public class CachedPublicKeyRing extends KeyRing { */ public long getSecretSignId() throws PgpKeyNotFoundException { try { - Object data = mProviderHelper.getGenericData(mUri, + Object data = mDatabaseInteractor.getGenericData(mUri, KeyRings.HAS_SIGN, - ProviderHelper.FIELD_TYPE_INTEGER); + DatabaseInteractor.FIELD_TYPE_INTEGER); return (Long) data; - } catch(ProviderHelper.NotFoundException e) { + } catch(DatabaseInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -204,35 +204,35 @@ public class CachedPublicKeyRing extends KeyRing { @Override public int getVerified() throws PgpKeyNotFoundException { try { - Object data = mProviderHelper.getGenericData(mUri, + Object data = mDatabaseInteractor.getGenericData(mUri, KeychainContract.KeyRings.VERIFIED, - ProviderHelper.FIELD_TYPE_INTEGER); + DatabaseInteractor.FIELD_TYPE_INTEGER); return ((Long) data).intValue(); - } catch(ProviderHelper.NotFoundException e) { + } catch(DatabaseInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } public boolean hasAnySecret() throws PgpKeyNotFoundException { try { - Object data = mProviderHelper.getGenericData(mUri, + Object data = mDatabaseInteractor.getGenericData(mUri, KeychainContract.KeyRings.HAS_ANY_SECRET, - ProviderHelper.FIELD_TYPE_INTEGER); + DatabaseInteractor.FIELD_TYPE_INTEGER); return (Long) data > 0; - } catch(ProviderHelper.NotFoundException e) { + } catch(DatabaseInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } private Cursor getSubkeys() throws PgpKeyNotFoundException { Uri keysUri = KeychainContract.Keys.buildKeysUri(extractOrGetMasterKeyId()); - return mProviderHelper.getContentResolver().query(keysUri, null, null, null, null); + return mDatabaseInteractor.getContentResolver().query(keysUri, null, null, null, null); } public SecretKeyType getSecretKeyType(long keyId) throws NotFoundException { - Object data = mProviderHelper.getGenericData(Keys.buildKeysUri(mUri), + Object data = mDatabaseInteractor.getGenericData(Keys.buildKeysUri(mUri), KeyRings.HAS_SECRET, - ProviderHelper.FIELD_TYPE_INTEGER, + DatabaseInteractor.FIELD_TYPE_INTEGER, KeyRings.KEY_ID + " = " + Long.toString(keyId)); return SecretKeyType.fromNum(((Long) data).intValue()); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java similarity index 99% rename from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java rename to OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java index 9b42c0cab..1d1b93d93 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java @@ -91,21 +91,21 @@ import java.util.concurrent.TimeUnit; * the lifetime of the executing ProviderHelper object unless the resetLog() * method is called to start a new one specifically. */ -public class ProviderHelper { +public class DatabaseInteractor { private final Context mContext; private final ContentResolver mContentResolver; private OperationLog mLog; private int mIndent; - public ProviderHelper(Context context) { + public DatabaseInteractor(Context context) { this(context, new OperationLog(), 0); } - public ProviderHelper(Context context, OperationLog log) { + public DatabaseInteractor(Context context, OperationLog log) { this(context, log, 0); } - public ProviderHelper(Context context, OperationLog log, int indent) { + public DatabaseInteractor(Context context, OperationLog log, int indent) { mContext = context; mContentResolver = context.getContentResolver(); mLog = log; @@ -1335,7 +1335,7 @@ public class ProviderHelper { private ConsolidateResult consolidateDatabaseStep2( OperationLog log, int indent, Progressable progress, boolean recovery) { - synchronized (ProviderHelper.class) { + synchronized (DatabaseInteractor.class) { if (mConsolidateCritical) { log.add(LogType.MSG_CON_ERROR_CONCURRENT, indent); return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); @@ -1540,7 +1540,7 @@ public class ProviderHelper { public String getKeyRingAsArmoredString(Uri uri) throws NotFoundException, IOException, PgpGeneralException { byte[] data = (byte[]) getGenericData( - uri, KeyRingData.KEY_RING_DATA, ProviderHelper.FIELD_TYPE_BLOB); + uri, KeyRingData.KEY_RING_DATA, DatabaseInteractor.FIELD_TYPE_BLOB); return getKeyRingAsArmoredString(data); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index 816f80600..167302440 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -66,7 +66,7 @@ import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAccounts; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.remote.OpenPgpServiceKeyIdExtractor.KeyIdResult; import org.sufficientlysecure.keychain.service.BackupKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -88,7 +88,7 @@ public class OpenPgpService extends Service { Collections.unmodifiableList(Arrays.asList(3, 4, 5, 6, 7, 8, 9, 10, 11)); private ApiPermissionHelper mApiPermissionHelper; - private ProviderHelper mProviderHelper; + private DatabaseInteractor mDatabaseInteractor; private ApiDataAccessObject mApiDao; private OpenPgpServiceKeyIdExtractor mKeyIdExtractor; private ApiPendingIntentFactory mApiPendingIntentFactory; @@ -97,7 +97,7 @@ public class OpenPgpService extends Service { public void onCreate() { super.onCreate(); mApiPermissionHelper = new ApiPermissionHelper(this, new ApiDataAccessObject(this)); - mProviderHelper = new ProviderHelper(this); + mDatabaseInteractor = new DatabaseInteractor(this); mApiDao = new ApiDataAccessObject(this); mApiPendingIntentFactory = new ApiPendingIntentFactory(getBaseContext()); @@ -135,7 +135,7 @@ public class OpenPgpService extends Service { // get first usable subkey capable of signing try { - long signSubKeyId = mProviderHelper.getCachedPublicKeyRing( + long signSubKeyId = mDatabaseInteractor.getCachedPublicKeyRing( pgpData.getSignatureMasterKeyId()).getSecretSignId(); pgpData.setSignatureSubKeyId(signSubKeyId); } catch (PgpKeyNotFoundException e) { @@ -167,7 +167,7 @@ public class OpenPgpService extends Service { } // execute PGP operation! - PgpSignEncryptOperation pse = new PgpSignEncryptOperation(this, new ProviderHelper(this), null); + PgpSignEncryptOperation pse = new PgpSignEncryptOperation(this, new DatabaseInteractor(this), null); PgpSignEncryptResult pgpResult = pse.execute(pseInput, inputParcel, inputData, outputStream); if (pgpResult.isPending()) { @@ -254,7 +254,7 @@ public class OpenPgpService extends Service { // get first usable subkey capable of signing try { - long signSubKeyId = mProviderHelper.getCachedPublicKeyRing( + long signSubKeyId = mDatabaseInteractor.getCachedPublicKeyRing( pgpData.getSignatureMasterKeyId()).getSecretSignId(); pgpData.setSignatureSubKeyId(signSubKeyId); } catch (PgpKeyNotFoundException e) { @@ -294,7 +294,7 @@ public class OpenPgpService extends Service { new Passphrase(data.getCharArrayExtra(OpenPgpApi.EXTRA_PASSPHRASE)); } - PgpSignEncryptOperation op = new PgpSignEncryptOperation(this, mProviderHelper, null); + PgpSignEncryptOperation op = new PgpSignEncryptOperation(this, mDatabaseInteractor, null); // execute PGP operation! PgpSignEncryptResult pgpResult = op.execute(pseInput, inputParcel, inputData, outputStream); @@ -356,7 +356,7 @@ public class OpenPgpService extends Service { byte[] detachedSignature = data.getByteArrayExtra(OpenPgpApi.EXTRA_DETACHED_SIGNATURE); String senderAddress = data.getStringExtra(OpenPgpApi.EXTRA_SENDER_ADDRESS); - PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(this, mProviderHelper, progressable); + PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(this, mDatabaseInteractor, progressable); long inputLength = data.getLongExtra(OpenPgpApi.EXTRA_DATA_LENGTH, InputData.UNKNOWN_FILESIZE); InputData inputData = new InputData(inputStream, inputLength); @@ -526,7 +526,7 @@ public class OpenPgpService extends Service { try { // try to find key, throws NotFoundException if not in db! CanonicalizedPublicKeyRing keyRing = - mProviderHelper.getCanonicalizedPublicKeyRing( + mDatabaseInteractor.getCanonicalizedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(masterKeyId)); Intent result = new Intent(); @@ -555,7 +555,7 @@ public class OpenPgpService extends Service { mApiPendingIntentFactory.createShowKeyPendingIntent(data, masterKeyId)); return result; - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { // If keys are not in db we return an additional PendingIntent // to retrieve the missing key Intent result = new Intent(); @@ -630,7 +630,7 @@ public class OpenPgpService extends Service { // the backup code is cached in CryptoInputParcelCacheService, now we can proceed BackupKeyringParcel input = new BackupKeyringParcel(masterKeyIds, backupSecret, true, enableAsciiArmorOutput, null); - BackupOperation op = new BackupOperation(this, mProviderHelper, null); + BackupOperation op = new BackupOperation(this, mDatabaseInteractor, null); ExportResult pgpResult = op.execute(input, inputParcel, outputStream); if (pgpResult.success()) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java index b4de0fe7d..467d51675 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java @@ -16,8 +16,8 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.remote.ApiPermissionHelper; import org.sufficientlysecure.keychain.remote.ApiPermissionHelper.WrongPackageCertificateException; import org.sufficientlysecure.keychain.util.Log; @@ -33,26 +33,26 @@ class RequestKeyPermissionPresenter { private String packageName; private long masterKeyId; - private ProviderHelper providerHelper; + private DatabaseInteractor databaseInteractor; static RequestKeyPermissionPresenter createRequestKeyPermissionPresenter(Context context) { PackageManager packageManager = context.getPackageManager(); ApiDataAccessObject apiDataAccessObject = new ApiDataAccessObject(context); ApiPermissionHelper apiPermissionHelper = new ApiPermissionHelper(context, apiDataAccessObject); - ProviderHelper providerHelper = new ProviderHelper(context); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(context); return new RequestKeyPermissionPresenter(context, apiDataAccessObject, apiPermissionHelper, packageManager, - providerHelper); + databaseInteractor); } private RequestKeyPermissionPresenter(Context context, ApiDataAccessObject apiDataAccessObject, - ApiPermissionHelper apiPermissionHelper, PackageManager packageManager, ProviderHelper providerHelper) { + ApiPermissionHelper apiPermissionHelper, PackageManager packageManager, DatabaseInteractor databaseInteractor) { this.context = context; this.apiDataAccessObject = apiDataAccessObject; this.apiPermissionHelper = apiPermissionHelper; this.packageManager = packageManager; - this.providerHelper = providerHelper; + this.databaseInteractor = databaseInteractor; } void setView(RequestKeyPermissionMvpView view) { @@ -101,7 +101,7 @@ class RequestKeyPermissionPresenter { CachedPublicKeyRing publicFallbackRing = null; for (long candidateSubKeyId : subKeyIds) { try { - CachedPublicKeyRing cachedPublicKeyRing = providerHelper.getCachedPublicKeyRing( + CachedPublicKeyRing cachedPublicKeyRing = databaseInteractor.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(candidateSubKeyId) ); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java index c287f6b38..c9b8f2103 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java @@ -48,7 +48,7 @@ import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ServiceProgressHandler.MessageStatus; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Log; @@ -112,35 +112,35 @@ public class KeychainService extends Service implements Progressable { // just for brevity KeychainService outerThis = KeychainService.this; if (inputParcel instanceof SignEncryptParcel) { - op = new SignEncryptOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new SignEncryptOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof PgpDecryptVerifyInputParcel) { - op = new PgpDecryptVerifyOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new PgpDecryptVerifyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof SaveKeyringParcel) { - op = new EditKeyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new EditKeyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof ChangeUnlockParcel) { - op = new ChangeUnlockOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new ChangeUnlockOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof RevokeKeyringParcel) { - op = new RevokeOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new RevokeOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof CertifyActionsParcel) { - op = new CertifyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new CertifyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof DeleteKeyringParcel) { - op = new DeleteOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new DeleteOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof PromoteKeyringParcel) { - op = new PromoteKeyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new PromoteKeyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof ImportKeyringParcel) { - op = new ImportOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new ImportOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof BackupKeyringParcel) { - op = new BackupOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new BackupOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof UploadKeyringParcel) { - op = new UploadOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new UploadOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof ConsolidateInputParcel) { - op = new ConsolidateOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new ConsolidateOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof KeybaseVerificationParcel) { - op = new KeybaseVerificationOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new KeybaseVerificationOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof InputDataParcel) { - op = new InputDataOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new InputDataOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof BenchmarkInputParcel) { - op = new BenchmarkOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new BenchmarkOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else { throw new AssertionError("Unrecognized input parcel in KeychainService!"); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java index e72df4d7c..30e4387ef 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java @@ -36,7 +36,7 @@ import org.sufficientlysecure.keychain.operations.ImportOperation; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.network.NetworkReceiver; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity; @@ -320,7 +320,7 @@ public class KeyserverSyncAdapterService extends Service { private ImportKeyResult directUpdate(Context context, ArrayList keyList, CryptoInputParcel cryptoInputParcel) { Log.d(Constants.TAG, "Starting normal update"); - ImportOperation importOp = new ImportOperation(context, new ProviderHelper(context), null); + ImportOperation importOp = new ImportOperation(context, new DatabaseInteractor(context), null); return importOp.execute( new ImportKeyringParcel(keyList, Preferences.getPreferences(context).getPreferredKeyserver()), @@ -380,7 +380,7 @@ public class KeyserverSyncAdapterService extends Service { new OperationResult.OperationLog()); } ImportKeyResult result = - new ImportOperation(context, new ProviderHelper(context), null, mCancelled) + new ImportOperation(context, new DatabaseInteractor(context), null, mCancelled) .execute( new ImportKeyringParcel( keyWrapper, diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index f9ab58f5b..fb6f1e08b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.Preferences; @@ -224,7 +224,7 @@ public class PassphraseCacheService extends Service { /** * Internal implementation to get cached passphrase. */ - private Passphrase getCachedPassphraseImpl(long masterKeyId, long subKeyId) throws ProviderHelper.NotFoundException { + private Passphrase getCachedPassphraseImpl(long masterKeyId, long subKeyId) throws DatabaseInteractor.NotFoundException { // on "none" key, just do nothing if (masterKeyId == Constants.key.none) { return null; @@ -245,16 +245,16 @@ public class PassphraseCacheService extends Service { + masterKeyId + ", subKeyId " + subKeyId); // get the type of key (from the database) - CachedPublicKeyRing keyRing = new ProviderHelper(this).getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing keyRing = new DatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId); SecretKeyType keyType = keyRing.getSecretKeyType(subKeyId); switch (keyType) { case PASSPHRASE_EMPTY: return new Passphrase(""); case UNAVAILABLE: - throw new ProviderHelper.NotFoundException("secret key for this subkey is not available"); + throw new DatabaseInteractor.NotFoundException("secret key for this subkey is not available"); case GNU_DUMMY: - throw new ProviderHelper.NotFoundException("secret key for stripped subkey is not available"); + throw new DatabaseInteractor.NotFoundException("secret key for stripped subkey is not available"); } // get cached passphrase @@ -398,7 +398,7 @@ public class PassphraseCacheService extends Service { bundle.putParcelable(EXTRA_PASSPHRASE, passphrase); msg.setData(bundle); } - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "PassphraseCacheService: Passphrase for unknown key was requested!"); msg.what = MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java index 3c1be0e2b..ad65fde71 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java @@ -35,7 +35,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.experimental.SentenceConfirm; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.base.LoaderFragment; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; @@ -213,7 +213,7 @@ public class CertifyFingerprintFragment extends LoaderFragment implements private void certify(Uri dataUri) { long keyId = 0; try { - keyId = new ProviderHelper(getActivity()) + keyId = new DatabaseInteractor(getActivity()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java index ad39ff43d..b44969b7c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -20,37 +20,25 @@ package org.sufficientlysecure.keychain.ui; import android.app.Activity; import android.content.Intent; -import android.database.Cursor; -import android.database.MatrixCursor; import android.graphics.PorterDuff; -import android.net.Uri; import android.os.Bundle; -import android.os.Parcel; -import android.support.v4.app.LoaderManager; -import android.support.v4.content.CursorLoader; -import android.support.v4.content.Loader; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.CheckBox; import android.widget.ImageView; -import android.widget.ListView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; -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.UserPackets; -import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; -import org.sufficientlysecure.keychain.ui.adapter.MultiUserIdsAdapter; import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.FormattingUtils; @@ -80,7 +68,7 @@ public class CertifyKeyFragment .getLongExtra(CertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, Constants.key.none); if (certifyKeyId != Constants.key.none) { try { - CachedPublicKeyRing key = (new ProviderHelper(getActivity())) + CachedPublicKeyRing key = (new DatabaseInteractor(getActivity())) .getCachedPublicKeyRing(certifyKeyId); if (key.canCertify()) { mCertifyKeySpinner.setPreSelectedKeyId(certifyKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java index 19cbb7660..84a39108d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java @@ -30,7 +30,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.securitytoken.KeyFormat; import org.sufficientlysecure.keychain.ui.base.BaseSecurityTokenActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -180,7 +180,7 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity { if (containsKeys(mScannedFingerprints)) { try { long masterKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mScannedFingerprints); - CachedPublicKeyRing ring = new ProviderHelper(this).getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing ring = new DatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId); ring.getMasterKeyId(); Intent intent = new Intent(this, ViewKeyActivity.class); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index 924a97df2..a3e8c3fe2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -41,14 +41,12 @@ import org.sufficientlysecure.keychain.operations.results.EditKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.UploadResult; import org.sufficientlysecure.keychain.pgp.KeyRing; -import org.sufficientlysecure.keychain.pgp.PgpSecurityConstants; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; -import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; @@ -413,7 +411,7 @@ public class CreateKeyFinalFragment extends Fragment { CreateKeyActivity activity = (CreateKeyActivity) getActivity(); final SaveKeyringParcel changeKeyringParcel; - CachedPublicKeyRing key = (new ProviderHelper(activity)) + CachedPublicKeyRing key = (new DatabaseInteractor(activity)) .getCachedPublicKeyRing(saveKeyResult.mMasterKeyId); try { changeKeyringParcel = new SaveKeyringParcel(key.getMasterKeyId(), key.getFingerprint()); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index 4458fd2b0..2bc84687e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -47,7 +47,7 @@ import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -192,7 +192,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager. try { Intent viewKeyIntent = new Intent(getActivity(), ViewKeyActivity.class); - long masterKeyId = new ProviderHelper(getActivity()).getCachedPublicKeyRing( + long masterKeyId = new DatabaseInteractor(getActivity()).getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId) ).getMasterKeyId(); viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId)); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java index 1827fd4e4..84d94586b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java @@ -35,16 +35,14 @@ import android.widget.AdapterView; import android.widget.Spinner; import android.widget.TextView; -import org.openintents.openpgp.util.OpenPgpUtils; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver; import org.sufficientlysecure.keychain.operations.results.DeleteResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.RevokeResult; -import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.DeleteKeyringParcel; import org.sufficientlysecure.keychain.service.RevokeKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -91,13 +89,13 @@ public class DeleteKeyDialogActivity extends FragmentActivity { if (mMasterKeyIds.length == 1 && mHasSecret) { // if mMasterKeyIds.length == 0 we let the DeleteOperation respond try { - HashMap data = new ProviderHelper(this).getUnifiedData( + HashMap data = new DatabaseInteractor(this).getUnifiedData( mMasterKeyIds[0], new String[]{ KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.IS_REVOKED }, new int[]{ - ProviderHelper.FIELD_TYPE_STRING, - ProviderHelper.FIELD_TYPE_INTEGER + DatabaseInteractor.FIELD_TYPE_STRING, + DatabaseInteractor.FIELD_TYPE_INTEGER } ); @@ -114,7 +112,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { } else { showRevokeDeleteDialog(name); } - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "Secret key to delete not found at DeleteKeyDialogActivity for " + mMasterKeyIds[0], e); @@ -271,13 +269,13 @@ public class DeleteKeyDialogActivity extends FragmentActivity { long masterKeyId = masterKeyIds[0]; try { - HashMap data = new ProviderHelper(activity).getUnifiedData( + HashMap data = new DatabaseInteractor(activity).getUnifiedData( masterKeyId, new String[]{ KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.HAS_ANY_SECRET }, new int[]{ - ProviderHelper.FIELD_TYPE_STRING, - ProviderHelper.FIELD_TYPE_INTEGER + DatabaseInteractor.FIELD_TYPE_STRING, + DatabaseInteractor.FIELD_TYPE_INTEGER } ); String name; @@ -295,7 +293,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { } else { mMainMessage.setText(getString(R.string.public_key_deletetion_confirmation, name)); } - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { dismiss(); return null; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java index 248cd71b3..c34b2b994 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java @@ -51,8 +51,8 @@ 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.UserPackets; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; @@ -170,7 +170,7 @@ public class EditIdentitiesFragment extends Fragment try { Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri); CachedPublicKeyRing keyRing = - new ProviderHelper(getActivity()).getCachedPublicKeyRing(secretUri); + new DatabaseInteractor(getActivity()).getCachedPublicKeyRing(secretUri); long masterKeyId = keyRing.getMasterKeyId(); // check if this is a master secret key we can work with diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index 6bf7cae15..c766472f4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -50,8 +50,8 @@ 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.UserPackets; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange; @@ -203,7 +203,7 @@ public class EditKeyFragment extends QueueingCryptoOperationFragment return; } - ProviderHelper providerHelper = new ProviderHelper(activity); - Cursor cursor = providerHelper.getContentResolver().query( + DatabaseInteractor databaseInteractor = new DatabaseInteractor(activity); + Cursor cursor = databaseInteractor.getContentResolver().query( KeyRings.buildUnifiedKeyRingsUri(), new String[]{ KeyRings.FINGERPRINT }, null, null, null diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java index b7da02096..e0b4b1ba6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java @@ -31,7 +31,6 @@ import android.support.v4.app.FragmentActivity; import android.support.v7.app.AlertDialog; import android.text.Editable; import android.text.InputType; -import android.text.Layout; import android.text.TextWatcher; import android.text.method.PasswordTransformationMethod; import android.view.ContextThemeWrapper; @@ -59,8 +58,8 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -113,7 +112,7 @@ public class PassphraseDialogActivity extends FragmentActivity { // handle empty passphrases by directly returning an empty crypto input parcel try { CachedPublicKeyRing pubRing = - new ProviderHelper(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId()); + new DatabaseInteractor(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId()); // use empty passphrase for empty passphrase if (pubRing.getSecretKeyType(requiredInput.getSubKeyId()) == SecretKeyType.PASSPHRASE_EMPTY) { // also return passphrase back to activity @@ -232,7 +231,7 @@ public class PassphraseDialogActivity extends FragmentActivity { try { long subKeyId = mRequiredInput.getSubKeyId(); - ProviderHelper helper = new ProviderHelper(activity); + DatabaseInteractor helper = new DatabaseInteractor(activity); CachedPublicKeyRing cachedPublicKeyRing = helper.getCachedPublicKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); // yes the inner try/catch block is necessary, otherwise the final variable @@ -267,7 +266,7 @@ public class PassphraseDialogActivity extends FragmentActivity { throw new AssertionError("Unhandled SecretKeyType (should not happen)"); } - } catch (PgpKeyNotFoundException | ProviderHelper.NotFoundException e) { + } catch (PgpKeyNotFoundException | DatabaseInteractor.NotFoundException e) { alert.setTitle(R.string.title_key_not_found); alert.setMessage(getString(R.string.key_not_found, mRequiredInput.getSubKeyId())); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @@ -458,7 +457,7 @@ public class PassphraseDialogActivity extends FragmentActivity { Long subKeyId = mRequiredInput.getSubKeyId(); CanonicalizedSecretKeyRing secretKeyRing = - new ProviderHelper(getActivity()).getCanonicalizedSecretKeyRing( + new DatabaseInteractor(getActivity()).getCanonicalizedSecretKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); CanonicalizedSecretKey secretKeyToUnlock = secretKeyRing.getSecretKey(subKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java index e54852f1b..2f99a0b68 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java @@ -29,7 +29,7 @@ import android.widget.ImageView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.Notify; @@ -74,11 +74,11 @@ public class QrCodeViewActivity extends BaseActivity { } }); - ProviderHelper providerHelper = new ProviderHelper(this); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(this); try { - byte[] blob = (byte[]) providerHelper.getGenericData( + byte[] blob = (byte[]) databaseInteractor.getGenericData( KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri), - KeychainContract.KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB); + KeychainContract.KeyRings.FINGERPRINT, DatabaseInteractor.FIELD_TYPE_BLOB); if (blob == null) { Log.e(Constants.TAG, "key not found!"); Notify.create(this, R.string.error_key_not_found, Style.ERROR).show(); @@ -102,7 +102,7 @@ public class QrCodeViewActivity extends BaseActivity { mQrCode.setImageBitmap(scaled); } }); - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); Notify.create(this, R.string.error_key_not_found, Style.ERROR).show(); ActivityCompat.finishAfterTransition(QrCodeViewActivity.this); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java index 410e511fa..4dec17128 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java @@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.operations.ImportOperation; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; @@ -105,8 +105,8 @@ public class SafeSlingerActivity extends BaseActivity // retrieve public key blob and start SafeSlinger Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId); try { - byte[] keyBlob = (byte[]) new ProviderHelper(this).getGenericData( - uri, KeychainContract.KeyRingData.KEY_RING_DATA, ProviderHelper.FIELD_TYPE_BLOB); + byte[] keyBlob = (byte[]) new DatabaseInteractor(this).getGenericData( + uri, KeychainContract.KeyRingData.KEY_RING_DATA, DatabaseInteractor.FIELD_TYPE_BLOB); Intent slingerIntent = new Intent(this, ExchangeActivity.class); @@ -114,7 +114,7 @@ public class SafeSlingerActivity extends BaseActivity slingerIntent.putExtra(ExchangeConfig.extra.USER_DATA, keyBlob); slingerIntent.putExtra(ExchangeConfig.extra.HOST_NAME, Constants.SAFESLINGER_SERVER); startActivityForResult(slingerIntent, REQUEST_CODE_SAFE_SLINGER); - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "personal key not found", e); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java index c663a2f18..94415e154 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java @@ -36,7 +36,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.securitytoken.KeyType; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -193,12 +193,12 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity { throw new IOException(getString(R.string.error_wrong_security_token)); } - ProviderHelper providerHelper = new ProviderHelper(this); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(this); CanonicalizedPublicKeyRing publicKeyRing; try { - publicKeyRing = providerHelper.getCanonicalizedPublicKeyRing( + publicKeyRing = databaseInteractor.getCanonicalizedPublicKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mRequiredInput.getMasterKeyId())); - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { throw new IOException("Couldn't find subkey for key to token operation."); } @@ -232,13 +232,13 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity { mSecurityTokenHelper.setPin(new Passphrase("123456")); mSecurityTokenHelper.setAdminPin(new Passphrase("12345678")); - ProviderHelper providerHelper = new ProviderHelper(this); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(this); CanonicalizedSecretKeyRing secretKeyRing; try { - secretKeyRing = providerHelper.getCanonicalizedSecretKeyRing( + secretKeyRing = databaseInteractor.getCanonicalizedSecretKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mRequiredInput.getMasterKeyId()) ); - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { throw new IOException("Couldn't find subkey for key to token operation."); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java index 596b223fe..d60518efc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java @@ -40,7 +40,7 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; @@ -184,8 +184,8 @@ public class ViewCertActivity extends BaseActivity Intent viewIntent = new Intent(ViewCertActivity.this, ViewKeyActivity.class); try { - ProviderHelper providerHelper = new ProviderHelper(ViewCertActivity.this); - long signerMasterKeyId = providerHelper.getCachedPublicKeyRing( + DatabaseInteractor databaseInteractor = new DatabaseInteractor(ViewCertActivity.this); + long signerMasterKeyId = databaseInteractor.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId(); viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId)); startActivity(viewIntent); 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 2785b620d..593d6597c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -74,8 +74,8 @@ 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.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -125,7 +125,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements public static final String EXTRA_DISPLAY_RESULT = "display_result"; public static final String EXTRA_LINKED_TRANSITION = "linked_transition"; - ProviderHelper mProviderHelper; + DatabaseInteractor mDatabaseInteractor; protected Uri mDataUri; @@ -185,7 +185,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mProviderHelper = new ProviderHelper(this); + mDatabaseInteractor = new DatabaseInteractor(this); mImportOpHelper = new CryptoOperationHelper<>(1, this, this, null); setTitle(null); @@ -318,7 +318,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements // or start new ones. getSupportLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this); - mNfcHelper = new NfcHelper(this, mProviderHelper); + mNfcHelper = new NfcHelper(this, mDatabaseInteractor); mNfcHelper.initNfc(mDataUri); if (savedInstanceState == null && getIntent().hasExtra(EXTRA_DISPLAY_RESULT)) { @@ -399,8 +399,8 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements } case R.id.menu_key_view_refresh: { try { - updateFromKeyserver(mDataUri, mProviderHelper); - } catch (ProviderHelper.NotFoundException e) { + updateFromKeyserver(mDataUri, mDatabaseInteractor); + } catch (DatabaseInteractor.NotFoundException e) { Notify.create(this, R.string.error_key_not_found, Notify.Style.ERROR).show(); } return true; @@ -550,7 +550,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements private boolean keyHasPassphrase() { try { SecretKeyType secretKeyType = - mProviderHelper.getCachedPublicKeyRing(mMasterKeyId).getSecretKeyType(mMasterKeyId); + mDatabaseInteractor.getCachedPublicKeyRing(mMasterKeyId).getSecretKeyType(mMasterKeyId); switch (secretKeyType) { // all of these make no sense to ask case PASSPHRASE_EMPTY: @@ -666,7 +666,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements try { // if the security token matches a subkey in any key - CachedPublicKeyRing ring = mProviderHelper.getCachedPublicKeyRing( + CachedPublicKeyRing ring = mDatabaseInteractor.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(tokenId)); byte[] candidateFp = ring.getFingerprint(); @@ -741,7 +741,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements return; } try { - long keyId = new ProviderHelper(this) + long keyId = new DatabaseInteractor(this) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); long[] encryptionKeyIds = new long[]{keyId}; @@ -765,7 +765,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements private void startSafeSlinger(Uri dataUri) { long keyId = 0; try { - keyId = new ProviderHelper(this) + keyId = new DatabaseInteractor(this) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { @@ -1118,17 +1118,17 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements // CryptoOperationHelper.Callback functions - private void updateFromKeyserver(Uri dataUri, ProviderHelper providerHelper) - throws ProviderHelper.NotFoundException { + private void updateFromKeyserver(Uri dataUri, DatabaseInteractor databaseInteractor) + throws DatabaseInteractor.NotFoundException { mIsRefreshing = true; mRefreshItem.setEnabled(false); mRefreshItem.setActionView(mRefresh); mRefresh.startAnimation(mRotate); - byte[] blob = (byte[]) providerHelper.getGenericData( + byte[] blob = (byte[]) databaseInteractor.getGenericData( KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri), - KeychainContract.Keys.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB); + KeychainContract.Keys.FINGERPRINT, DatabaseInteractor.FIELD_TYPE_BLOB); String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob); ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null, null); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java index faa8743da..b84c2498b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java @@ -41,13 +41,11 @@ import android.widget.Toast; import com.astuetz.PagerSlidingTabStrip; -import org.openintents.openpgp.util.OpenPgpUtils; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.operations.results.OperationResult; -import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -57,7 +55,7 @@ import org.sufficientlysecure.keychain.util.Log; public class ViewKeyAdvActivity extends BaseActivity implements LoaderCallbacks, OnPageChangeListener { - ProviderHelper mProviderHelper; + DatabaseInteractor mDatabaseInteractor; protected Uri mDataUri; @@ -90,7 +88,7 @@ public class ViewKeyAdvActivity extends BaseActivity implements } }); - mProviderHelper = new ProviderHelper(this); + mDatabaseInteractor = new DatabaseInteractor(this); mViewPager = (ViewPager) findViewById(R.id.pager); mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tab_layout); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index 1ec82b907..046d96805 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -58,7 +58,7 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.ui.base.LoaderFragment; import org.sufficientlysecure.keychain.ui.util.FormattingUtils; @@ -93,8 +93,8 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements View root = super.onCreateView(inflater, superContainer, savedInstanceState); View view = inflater.inflate(R.layout.view_key_adv_share_fragment, getContainer()); - ProviderHelper providerHelper = new ProviderHelper(ViewKeyAdvShareFragment.this.getActivity()); - mNfcHelper = new NfcHelper(getActivity(), providerHelper); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(ViewKeyAdvShareFragment.this.getActivity()); + mNfcHelper = new NfcHelper(getActivity(), databaseInteractor); mFingerprintView = (TextView) view.findViewById(R.id.view_key_fingerprint); mQrCode = (ImageView) view.findViewById(R.id.view_key_qr_code); @@ -200,7 +200,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements private void startSafeSlinger(Uri dataUri) { long keyId = 0; try { - keyId = new ProviderHelper(getActivity()) + keyId = new DatabaseInteractor(getActivity()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { @@ -216,10 +216,10 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements if (activity == null || mFingerprint == null) { return; } - ProviderHelper providerHelper = new ProviderHelper(activity); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(activity); try { - String content = providerHelper.getKeyRingAsArmoredString( + String content = databaseInteractor.getKeyRingAsArmoredString( KeychainContract.KeyRingData.buildPublicKeyRingUri(mDataUri)); if (toClipboard) { @@ -273,7 +273,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements } catch (PgpGeneralException | IOException e) { Log.e(Constants.TAG, "error processing key!", e); Notify.create(activity, R.string.error_key_processing, Notify.Style.ERROR).show(); - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); Notify.create(activity, R.string.error_key_not_found, Notify.Style.ERROR).show(); } @@ -457,7 +457,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements private void uploadToKeyserver() { long keyId; try { - keyId = new ProviderHelper(getActivity()) + keyId = new DatabaseInteractor(getActivity()) .getCachedPublicKeyRing(mDataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index 7b22d48ae..13c981746 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.ViewKeyActivity; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; @@ -65,7 +65,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter mData; private KeyState[] mKeyStates; - private ProviderHelper mProviderHelper; + private DatabaseInteractor mDatabaseInteractor; public ImportKeysAdapter(FragmentActivity activity, ImportKeysListener listener, boolean nonInteractive) { @@ -74,7 +74,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter data) { @@ -89,13 +89,13 @@ public class ImportKeysAdapter extends RecyclerView.Adapter 0; - } catch (ProviderHelper.NotFoundException | PgpKeyNotFoundException ignored) { + } catch (DatabaseInteractor.NotFoundException | PgpKeyNotFoundException ignored) { } mKeyStates[i] = keyState; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java index 17fe8f395..f8db70a95 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java @@ -38,7 +38,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -105,7 +105,7 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity final long subKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mSecurityTokenFingerprints); try { - CachedPublicKeyRing ring = new ProviderHelper(this).getCachedPublicKeyRing( + CachedPublicKeyRing ring = new DatabaseInteractor(this).getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); long masterKeyId = ring.getMasterKeyId(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java index 39e781c6d..b9ea3a7f7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java @@ -36,7 +36,7 @@ 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.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.util.Log; @@ -58,7 +58,7 @@ public class LinkedIdWizard extends BaseActivity { try { Uri uri = getIntent().getData(); uri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(uri); - CachedPublicKeyRing ring = new ProviderHelper(this).getCachedPublicKeyRing(uri); + CachedPublicKeyRing ring = new DatabaseInteractor(this).getCachedPublicKeyRing(uri); if (!ring.hasAnySecret()) { Log.e(Constants.TAG, "Linked Identities can only be added to secret keys!"); finish(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java index 7c2d1aa3f..3aef420bd 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java @@ -36,9 +36,8 @@ import android.provider.Settings; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.util.Notify; -import org.sufficientlysecure.keychain.util.Log; import java.lang.ref.WeakReference; @@ -49,7 +48,7 @@ import java.lang.ref.WeakReference; public class NfcHelper { private Activity mActivity; - private ProviderHelper mProviderHelper; + private DatabaseInteractor mDatabaseInteractor; /** * NFC: This handler receives a message from onNdefPushComplete @@ -65,9 +64,9 @@ public class NfcHelper { /** * Initializes the NfcHelper. */ - public NfcHelper(final Activity activity, final ProviderHelper providerHelper) { + public NfcHelper(final Activity activity, final DatabaseInteractor databaseInteractor) { mActivity = activity; - mProviderHelper = providerHelper; + mDatabaseInteractor = databaseInteractor; mNfcHandler = new NfcHandler(mActivity); } @@ -129,11 +128,11 @@ public class NfcHelper { try { Uri blobUri = KeychainContract.KeyRingData.buildPublicKeyRingUri(dataUri); - mNfcKeyringBytes = (byte[]) mProviderHelper.getGenericData( + mNfcKeyringBytes = (byte[]) mDatabaseInteractor.getGenericData( blobUri, KeychainContract.KeyRingData.KEY_RING_DATA, - ProviderHelper.FIELD_TYPE_BLOB); - } catch (ProviderHelper.NotFoundException e) { + DatabaseInteractor.FIELD_TYPE_BLOB); + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java index 16345333d..31bd6571c 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java @@ -44,7 +44,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow; import org.sufficientlysecure.keychain.pgp.WrappedSignature; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.BackupKeyringParcel; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; @@ -135,13 +135,13 @@ public class BackupOperationTest { @Before public void setUp() { - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; - providerHelper.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); - providerHelper.saveSecretKeyRing(mStaticRing2, new ProgressScaler()); + databaseInteractor.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); + databaseInteractor.saveSecretKeyRing(mStaticRing2, new ProgressScaler()); // ok NOW log verbosely! ShadowLog.stream = System.out; @@ -150,7 +150,7 @@ public class BackupOperationTest { @Test public void testExportAllLocalStripped() throws Exception { BackupOperation op = new BackupOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); // make sure there is a local cert (so the later checks that there are none are meaningful) assertTrue("second keyring has local certification", checkForLocal(mStaticRing2)); @@ -249,7 +249,7 @@ public class BackupOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); BackupOperation op = new BackupOperation(spyApplication, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); BackupKeyringParcel parcel = new BackupKeyringParcel( new long[] { mStaticRing1.getMasterKeyId() }, false, false, true, fakeOutputUri); @@ -306,7 +306,7 @@ public class BackupOperationTest { { // export encrypted BackupOperation op = new BackupOperation(spyApplication, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); BackupKeyringParcel parcel = new BackupKeyringParcel( new long[] { mStaticRing1.getMasterKeyId() }, false, true, true, fakeOutputUri); @@ -324,7 +324,7 @@ public class BackupOperationTest { { PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(outStream.toByteArray()); input.setAllowSymmetricDecryption(true); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java index d5c55cf07..5dec61169 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java @@ -25,7 +25,7 @@ import org.junit.runner.RunWith; import org.robolectric.RuntimeEnvironment; import org.robolectric.shadows.ShadowLog; import org.sufficientlysecure.keychain.KeychainTestRunner; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.BenchmarkInputParcel; import java.io.PrintStream; @@ -47,7 +47,7 @@ public class BenchmarkOperationTest { @Test public void testBenchmark() throws Exception { BenchmarkOperation op = new BenchmarkOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); op.execute(new BenchmarkInputParcel(), null); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java index 8d6c94bba..398831920 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java @@ -35,7 +35,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; @@ -117,13 +117,13 @@ public class CertifyOperationTest { @Before public void setUp() throws Exception { - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; - providerHelper.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); - providerHelper.savePublicKeyRing(mStaticRing2.extractPublicKeyRing(), new ProgressScaler(), null); + databaseInteractor.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); + databaseInteractor.savePublicKeyRing(mStaticRing2.extractPublicKeyRing(), new ProgressScaler(), null); // ok NOW log verbosely! ShadowLog.stream = System.out; @@ -132,7 +132,7 @@ public class CertifyOperationTest { @Test public void testSelfCertifyFlag() throws Exception { - CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing1.getMasterKeyId()); Assert.assertEquals("secret key must be marked self-certified in database", // TODO this should be more correctly be VERIFIED_SELF at some point! @@ -143,10 +143,10 @@ public class CertifyOperationTest { @Test public void testCertifyId() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); { - CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("public key must not be marked verified prior to certification", Certs.UNVERIFIED, ring.getVerified()); @@ -160,7 +160,7 @@ public class CertifyOperationTest { Assert.assertTrue("certification must succeed", result.success()); { - CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("new key must be verified now", Certs.VERIFIED_SECRET, ring.getVerified()); @@ -171,10 +171,10 @@ public class CertifyOperationTest { @Test public void testCertifyAttribute() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); { - CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("public key must not be marked verified prior to certification", Certs.UNVERIFIED, ring.getVerified()); @@ -188,7 +188,7 @@ public class CertifyOperationTest { Assert.assertTrue("certification must succeed", result.success()); { - CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("new key must be verified now", Certs.VERIFIED_SECRET, ring.getVerified()); @@ -200,7 +200,7 @@ public class CertifyOperationTest { @Test public void testCertifySelf() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(), @@ -217,7 +217,7 @@ public class CertifyOperationTest { public void testCertifyNonexistent() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); { CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java index b8c3e2860..5cb914448 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java @@ -38,7 +38,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.PromoteKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; @@ -90,12 +90,12 @@ public class PromoteKeyOperationTest { @Before public void setUp() throws Exception { - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; - providerHelper.savePublicKeyRing(mStaticRing.extractPublicKeyRing(), new ProgressScaler(), null); + databaseInteractor.savePublicKeyRing(mStaticRing.extractPublicKeyRing(), new ProgressScaler(), null); // ok NOW log verbosely! ShadowLog.stream = System.out; @@ -104,14 +104,14 @@ public class PromoteKeyOperationTest { @Test public void testPromote() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); PromoteKeyResult result = op.execute(new PromoteKeyringParcel(mStaticRing.getMasterKeyId(), null, null), null); Assert.assertTrue("promotion must succeed", result.success()); { - CachedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CachedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCachedPublicKeyRing(mStaticRing.getMasterKeyId()); Assert.assertTrue("key must have a secret now", ring.hasAnySecret()); @@ -128,7 +128,7 @@ public class PromoteKeyOperationTest { @Test public void testPromoteDivert() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); byte[] aid = Hex.decode("D2760001240102000000012345670000"); @@ -137,7 +137,7 @@ public class PromoteKeyOperationTest { Assert.assertTrue("promotion must succeed", result.success()); { - CanonicalizedSecretKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedSecretKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { @@ -153,7 +153,7 @@ public class PromoteKeyOperationTest { @Test public void testPromoteDivertSpecific() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); byte[] aid = Hex.decode("D2760001240102000000012345670000"); @@ -167,7 +167,7 @@ public class PromoteKeyOperationTest { Assert.assertTrue("promotion must succeed", result.success()); { - CanonicalizedSecretKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedSecretKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java index 2d518eaa6..19033606d 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java @@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.KeychainTestRunner; import org.sufficientlysecure.keychain.operations.InputDataOperation; import org.sufficientlysecure.keychain.operations.results.InputDataResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.InputDataParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -126,7 +126,7 @@ public class InputDataOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); InputDataOperation op = new InputDataOperation(spyApplication, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputDataParcel input = new InputDataParcel(fakeInputUri, null); @@ -306,7 +306,7 @@ public class InputDataOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); InputDataOperation op = new InputDataOperation(spyApplication, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputDataParcel input = new InputDataParcel(FAKE_CONTENT_INPUT_URI_1, null); return op.execute(input, new CryptoInputParcel()); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java index 575cc33cc..4cab67f5d 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java @@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.LogTyp import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; @@ -149,13 +149,13 @@ public class PgpEncryptDecryptTest { @Before public void setUp() { - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; - providerHelper.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); - providerHelper.saveSecretKeyRing(mStaticRing2, new ProgressScaler()); + databaseInteractor.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); + databaseInteractor.saveSecretKeyRing(mStaticRing2, new ProgressScaler()); // ok NOW log verbosely! ShadowLog.stream = System.out; @@ -172,7 +172,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -197,7 +197,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute( @@ -227,7 +227,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute(input, @@ -249,7 +249,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute(input, @@ -270,7 +270,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(false); DecryptVerifyResult result = op.execute(input, @@ -297,7 +297,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -353,7 +353,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -415,7 +415,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -472,7 +472,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -575,7 +575,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -626,11 +626,11 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); - providerHelper.saveSecretKeyRing(modified, new ProgressScaler()); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1)); @@ -648,11 +648,11 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); - providerHelper.saveSecretKeyRing(modified, new ProgressScaler()); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1)); @@ -675,8 +675,8 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); - providerHelper.saveSecretKeyRing(modified, new ProgressScaler()); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); } { // encrypt to this keyring, make sure it's not encrypted to the revoked subkey @@ -685,7 +685,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -730,7 +730,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -824,7 +824,7 @@ public class PgpEncryptDecryptTest { { // decryption with passphrase cached should succeed for the other key if first is gone // delete first key from database - new ProviderHelper(RuntimeEnvironment.application).getContentResolver().delete( + new DatabaseInteractor(RuntimeEnvironment.application).getContentResolver().delete( KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null ); @@ -859,7 +859,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -907,7 +907,7 @@ public class PgpEncryptDecryptTest { { // decryption with passphrase cached should succeed for the other key if first is gone // delete first key from database - new ProviderHelper(RuntimeEnvironment.application).getContentResolver().delete( + new DatabaseInteractor(RuntimeEnvironment.application).getContentResolver().delete( KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null ); @@ -946,7 +946,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaindata); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -1018,7 +1018,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -1069,7 +1069,7 @@ public class PgpEncryptDecryptTest { final Passphrase passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) { return new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null) { + new DatabaseInteractor(RuntimeEnvironment.application), null) { @Override public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId) throws NoSecretKeyException { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperKeyringTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorKeyringTest.java similarity index 98% rename from OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperKeyringTest.java rename to OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorKeyringTest.java index 62358d848..608ecd950 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperKeyringTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorKeyringTest.java @@ -30,7 +30,7 @@ import java.util.Collection; import java.util.Collections; @RunWith(KeychainTestRunner.class) -public class ProviderHelperKeyringTest { +public class DatabaseInteractorKeyringTest { @Test public void testSavePublicKeyring() throws Exception { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java similarity index 83% rename from OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java rename to OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java index f22464185..a4f31581e 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java @@ -41,9 +41,9 @@ import java.util.Arrays; import java.util.Iterator; @RunWith(KeychainTestRunner.class) -public class ProviderHelperSaveTest { +public class DatabaseInteractorSaveTest { - ProviderHelper mProviderHelper = new ProviderHelper(RuntimeEnvironment.application); + DatabaseInteractor mDatabaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); @BeforeClass public static void setUpOnce() throws Exception { @@ -61,17 +61,17 @@ public class ProviderHelperSaveTest { SaveKeyringResult result; // insert both keys, second should fail - result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(first); + result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); Assert.assertTrue("first keyring import should succeed", result.success()); - result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(second); + result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); Assert.assertFalse("second keyring import should fail", result.success()); new KeychainDatabase(RuntimeEnvironment.application).clearDatabase(); // and the other way around - result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(second); + result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); Assert.assertTrue("first keyring import should succeed", result.success()); - result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(first); + result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); Assert.assertFalse("second keyring import should fail", result.success()); } @@ -90,13 +90,13 @@ public class ProviderHelperSaveTest { SaveKeyringResult result; // insert secret, this should fail because of missing self-cert - result = new ProviderHelper(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); + result = new DatabaseInteractor(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); Assert.assertFalse("secret keyring import before pubring import should fail", result.success()); // insert pubkey, then seckey - both should succeed - result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(pubkey); + result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(pubkey); Assert.assertTrue("public keyring import should succeed", result.success()); - result = new ProviderHelper(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); + result = new DatabaseInteractor(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); Assert.assertTrue("secret keyring import after pubring import should succeed", result.success()); } @@ -108,10 +108,10 @@ public class ProviderHelperSaveTest { Assert.assertEquals("key flags should be zero", 0, (long) pub.canonicalize(new OperationLog(), 0).getPublicKey().getKeyUsage()); - mProviderHelper.savePublicKeyRing(pub); + mDatabaseInteractor.savePublicKeyRing(pub); - CachedPublicKeyRing cachedRing = mProviderHelper.getCachedPublicKeyRing(keyId); - CanonicalizedPublicKeyRing pubRing = mProviderHelper.getCanonicalizedPublicKeyRing(keyId); + CachedPublicKeyRing cachedRing = mDatabaseInteractor.getCachedPublicKeyRing(keyId); + CanonicalizedPublicKeyRing pubRing = mDatabaseInteractor.getCanonicalizedPublicKeyRing(keyId); Assert.assertEquals("master key should be encryption key", keyId, pubRing.getEncryptId()); Assert.assertEquals("master key should be encryption key (cached)", keyId, cachedRing.getEncryptId()); @@ -131,13 +131,13 @@ public class ProviderHelperSaveTest { SaveKeyringResult result; - result = mProviderHelper.saveSecretKeyRing(sec, new ProgressScaler()); + result = mDatabaseInteractor.saveSecretKeyRing(sec, new ProgressScaler()); Assert.assertTrue("import of secret keyring should succeed", result.success()); // make sure both the CanonicalizedSecretKeyRing as well as the CachedPublicKeyRing correctly // indicate the secret key type - CachedPublicKeyRing cachedRing = mProviderHelper.getCachedPublicKeyRing(keyId); - CanonicalizedSecretKeyRing secRing = mProviderHelper.getCanonicalizedSecretKeyRing(keyId); + CachedPublicKeyRing cachedRing = mDatabaseInteractor.getCachedPublicKeyRing(keyId); + CanonicalizedSecretKeyRing secRing = mDatabaseInteractor.getCanonicalizedSecretKeyRing(keyId); Iterator it = secRing.secretKeyIterator().iterator(); @@ -195,10 +195,10 @@ public class ProviderHelperSaveTest { SaveKeyringResult result; - result = mProviderHelper.savePublicKeyRing(key, new ProgressScaler(), null); + result = mDatabaseInteractor.savePublicKeyRing(key, new ProgressScaler(), null); Assert.assertTrue("import of keyring should succeed", result.success()); - CanonicalizedPublicKeyRing ring = mProviderHelper.getCanonicalizedPublicKeyRing(keyId); + CanonicalizedPublicKeyRing ring = mDatabaseInteractor.getCanonicalizedPublicKeyRing(keyId); boolean found = false; byte[] badUserId = Hex.decode("436c61757320467261656e6b656c203c436c6175732e4672e46e6b656c4068616c696661782e727774682d61616368656e2e64653e"); for (byte[] rawUserId : new IterableIterator( @@ -222,29 +222,29 @@ public class ProviderHelperSaveTest { SaveKeyringResult result; - result = mProviderHelper.saveSecretKeyRing(key, new ProgressScaler()); + result = mDatabaseInteractor.saveSecretKeyRing(key, new ProgressScaler()); Assert.assertTrue("import of keyring should succeed", result.success()); long signId; { - CanonicalizedSecretKeyRing ring = mProviderHelper.getCanonicalizedSecretKeyRing(masterKeyId); + CanonicalizedSecretKeyRing ring = mDatabaseInteractor.getCanonicalizedSecretKeyRing(masterKeyId); Assert.assertTrue("master key should have sign flag", ring.getPublicKey().canSign()); Assert.assertTrue("master key should have encrypt flag", ring.getPublicKey().canEncrypt()); - signId = mProviderHelper.getCachedPublicKeyRing(masterKeyId).getSecretSignId(); + signId = mDatabaseInteractor.getCachedPublicKeyRing(masterKeyId).getSecretSignId(); Assert.assertNotEquals("encrypt id should not be 0", 0, signId); Assert.assertNotEquals("encrypt key should be different from master key", masterKeyId, signId); } { - CachedPublicKeyRing ring = mProviderHelper.getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing ring = mDatabaseInteractor.getCachedPublicKeyRing(masterKeyId); Assert.assertEquals("signing key should be same id cached as uncached", signId, ring.getSecretSignId()); } } UncachedKeyRing readRingFromResource(String name) throws Exception { - return UncachedKeyRing.fromStream(ProviderHelperSaveTest.class.getResourceAsStream(name)).next(); + return UncachedKeyRing.fromStream(DatabaseInteractorSaveTest.class.getResourceAsStream(name)).next(); } } \ No newline at end of file diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java index f0bd955e1..a8a03d390 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java @@ -243,7 +243,7 @@ public class InteropTest { final Uri verifyUri = verify != null ? KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(verify.getMasterKeyId()) : null; - ProviderHelper helper = new ProviderHelper(RuntimeEnvironment.application) { + DatabaseInteractor helper = new DatabaseInteractor(RuntimeEnvironment.application) { @Override public CachedPublicKeyRing getCachedPublicKeyRing(Uri queryUri) throws PgpKeyNotFoundException { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java index 7628c22c1..d72102005 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java @@ -21,8 +21,8 @@ import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; import org.sufficientlysecure.keychain.provider.KeychainExternalContract.EmailStatus; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelperSaveTest; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractorSaveTest; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -45,7 +45,7 @@ public class KeychainExternalProviderTest { static final long KEY_ID_PUBLIC = 0x9A282CE2AB44A382L; - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver(); ApiPermissionHelper apiPermissionHelper; ApiDataAccessObject apiDao; @@ -187,7 +187,7 @@ public class KeychainExternalProviderTest { CertifyActionsParcel certifyActionsParcel = new CertifyActionsParcel(secretMasterKeyId); certifyActionsParcel.add(new CertifyAction(publicMasterKeyId, Collections.singletonList(userId), null)); CertifyOperation op = new CertifyOperation( - RuntimeEnvironment.application, providerHelper, new ProgressScaler(), null); + RuntimeEnvironment.application, databaseInteractor, new ProgressScaler(), null); CertifyResult certifyResult = op.execute(certifyActionsParcel, new CryptoInputParcel()); assertTrue(certifyResult.success()); @@ -195,17 +195,17 @@ public class KeychainExternalProviderTest { private void insertPublicKeyringFrom(String filename) throws Exception { UncachedKeyRing ring = readRingFromResource(filename); - SaveKeyringResult saveKeyringResult = providerHelper.savePublicKeyRing(ring); + SaveKeyringResult saveKeyringResult = databaseInteractor.savePublicKeyRing(ring); assertTrue(saveKeyringResult.success()); } private void insertSecretKeyringFrom(String filename) throws Exception { UncachedKeyRing ring = readRingFromResource(filename); - SaveKeyringResult saveKeyringResult = providerHelper.saveSecretKeyRing(ring, new ProgressScaler()); + SaveKeyringResult saveKeyringResult = databaseInteractor.saveSecretKeyRing(ring, new ProgressScaler()); assertTrue(saveKeyringResult.success()); } UncachedKeyRing readRingFromResource(String name) throws Exception { - return UncachedKeyRing.fromStream(ProviderHelperSaveTest.class.getResourceAsStream(name)).next(); + return UncachedKeyRing.fromStream(DatabaseInteractorSaveTest.class.getResourceAsStream(name)).next(); } } \ No newline at end of file diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/ProviderHelperStub.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/DatabaseInteractorStub.java similarity index 86% rename from OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/ProviderHelperStub.java rename to OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/DatabaseInteractorStub.java index 0573f07fb..f2ea24281 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/ProviderHelperStub.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/DatabaseInteractorStub.java @@ -21,10 +21,10 @@ import android.content.Context; import android.net.Uri; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -class ProviderHelperStub extends ProviderHelper { - public ProviderHelperStub(Context context) { +class DatabaseInteractorStub extends DatabaseInteractor { + public DatabaseInteractorStub(Context context) { super(context); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java index d6e8112ca..e2756747f 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java @@ -23,7 +23,7 @@ import android.content.Context; import org.bouncycastle.util.Arrays; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; import org.sufficientlysecure.keychain.util.ProgressScaler; @@ -50,24 +50,24 @@ public class KeyringTestingHelper { public boolean addKeyring(Collection blobFiles) throws Exception { - ProviderHelper providerHelper = new ProviderHelper(context); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(context); byte[] data = TestDataUtil.readAllFully(blobFiles); UncachedKeyRing ring = UncachedKeyRing.decodeFromData(data); long masterKeyId = ring.getMasterKeyId(); // Should throw an exception; key is not yet saved - retrieveKeyAndExpectNotFound(providerHelper, masterKeyId); + retrieveKeyAndExpectNotFound(databaseInteractor, masterKeyId); - SaveKeyringResult saveKeyringResult = providerHelper.savePublicKeyRing(ring, new ProgressScaler(), null); + SaveKeyringResult saveKeyringResult = databaseInteractor.savePublicKeyRing(ring, new ProgressScaler(), null); boolean saveSuccess = saveKeyringResult.success(); // Now re-retrieve the saved key. Should not throw an exception. - providerHelper.getCanonicalizedPublicKeyRing(masterKeyId); + databaseInteractor.getCanonicalizedPublicKeyRing(masterKeyId); // A different ID should still fail - retrieveKeyAndExpectNotFound(providerHelper, masterKeyId - 1); + retrieveKeyAndExpectNotFound(databaseInteractor, masterKeyId - 1); return saveSuccess; } @@ -345,11 +345,11 @@ public class KeyringTestingHelper { return getNth(ring.getPublicKeys(), position).getKeyId(); } - private void retrieveKeyAndExpectNotFound(ProviderHelper providerHelper, long masterKeyId) { + private void retrieveKeyAndExpectNotFound(DatabaseInteractor databaseInteractor, long masterKeyId) { try { - providerHelper.getCanonicalizedPublicKeyRing(masterKeyId); + databaseInteractor.getCanonicalizedPublicKeyRing(masterKeyId); throw new AssertionError("Was expecting the previous call to fail!"); - } catch (ProviderHelper.NotFoundException expectedException) { + } catch (DatabaseInteractor.NotFoundException expectedException) { // good } } From aef6e6614e19983732216c2c968a1faa4023109f Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 20 Feb 2017 16:28:30 +0100 Subject: [PATCH 02/11] extract DatabaseReadWriteInteractor --- .../keychain/TestHelpers.java | 4 +- .../keychain/actions/CustomActions.java | 4 +- .../keychain/operations/BackupOperation.java | 2 +- .../keychain/operations/BaseOperation.java | 9 +- .../operations/BaseReadWriteOperation.java | 30 + .../operations/BenchmarkOperation.java | 4 +- .../keychain/operations/CertifyOperation.java | 8 +- .../operations/ChangeUnlockOperation.java | 10 +- .../operations/ConsolidateOperation.java | 10 +- .../keychain/operations/DeleteOperation.java | 8 +- .../keychain/operations/EditKeyOperation.java | 8 +- .../keychain/operations/ImportOperation.java | 16 +- .../KeybaseVerificationOperation.java | 4 +- .../operations/PromoteKeyOperation.java | 9 +- .../keychain/operations/RevokeOperation.java | 10 +- .../operations/SignEncryptOperation.java | 10 +- .../keychain/operations/UploadOperation.java | 5 +- .../keychain/pgp/CanonicalizedSecretKey.java | 4 +- .../pgp/PgpDecryptVerifyOperation.java | 5 +- .../keychain/pgp/PgpSignEncryptOperation.java | 7 +- .../keychain/pgp/PgpSignatureChecker.java | 5 +- .../provider/CachedPublicKeyRing.java | 24 +- .../keychain/provider/DatabaseInteractor.java | 1371 +---------------- .../provider/DatabaseReadWriteInteractor.java | 1345 ++++++++++++++++ .../keychain/remote/OpenPgpService.java | 6 +- .../ui/RequestKeyPermissionPresenter.java | 3 +- .../keychain/service/KeychainService.java | 33 +- .../service/KeyserverSyncAdapterService.java | 6 +- .../service/PassphraseCacheService.java | 12 +- .../ui/CertifyFingerprintFragment.java | 4 +- .../keychain/ui/CertifyKeyFragment.java | 4 +- .../keychain/ui/CreateKeyActivity.java | 4 +- .../keychain/ui/CreateKeyFinalFragment.java | 4 +- .../keychain/ui/DecryptFragment.java | 4 +- .../keychain/ui/DeleteKeyDialogActivity.java | 9 +- .../keychain/ui/EditIdentitiesFragment.java | 4 +- .../keychain/ui/EditKeyFragment.java | 4 +- .../ui/EncryptModeAsymmetricFragment.java | 3 +- .../keychain/ui/KeyListFragment.java | 3 +- .../keychain/ui/PassphraseDialogActivity.java | 9 +- .../keychain/ui/QrCodeViewActivity.java | 5 +- .../keychain/ui/SafeSlingerActivity.java | 5 +- .../ui/SecurityTokenOperationActivity.java | 9 +- .../keychain/ui/ViewCertActivity.java | 3 +- .../keychain/ui/ViewKeyActivity.java | 11 +- .../keychain/ui/ViewKeyAdvActivity.java | 3 +- .../keychain/ui/ViewKeyAdvShareFragment.java | 11 +- .../ui/adapter/ImportKeysAdapter.java | 5 +- .../ui/base/BaseSecurityTokenActivity.java | 4 +- .../keychain/ui/linked/LinkedIdWizard.java | 4 +- .../keychain/util/NfcHelper.java | 3 +- .../operations/BackupOperationTest.java | 12 +- .../operations/BenchmarkOperationTest.java | 4 +- .../operations/CertifyOperationTest.java | 22 +- .../operations/PromoteKeyOperationTest.java | 16 +- .../keychain/pgp/InputDataOperationTest.java | 6 +- .../keychain/pgp/PgpEncryptDecryptTest.java | 50 +- .../provider/DatabaseInteractorSaveTest.java | 16 +- .../keychain/provider/InteropTest.java | 2 +- .../remote/KeychainExternalProviderTest.java | 4 +- .../support/DatabaseInteractorStub.java | 5 +- .../support/KeyringTestingHelper.java | 5 +- 62 files changed, 1658 insertions(+), 1571 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseReadWriteOperation.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java index 6d957e6fc..b538dc3dd 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java @@ -38,8 +38,8 @@ import com.nispok.snackbar.Snackbar; import org.hamcrest.Matcher; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainDatabase; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.util.ProgressScaler; @@ -97,7 +97,7 @@ public class TestHelpers { IteratorWithIOThrow stream = UncachedKeyRing.fromStream( getInstrumentation().getContext().getAssets().open(name)); - DatabaseInteractor helper = new DatabaseInteractor(context); + DatabaseReadWriteInteractor helper = new DatabaseReadWriteInteractor(context); while(stream.hasNext()) { UncachedKeyRing ring = stream.next(); if (ring.isSecret()) { diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java index ee532ab92..78d9477f6 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java @@ -27,7 +27,7 @@ import android.view.View; import com.tokenautocomplete.TokenCompleteTextView; import org.hamcrest.Matcher; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter; import static android.support.test.InstrumentationRegistry.getTargetContext; @@ -37,7 +37,7 @@ public abstract class CustomActions { public static ViewAction tokenEncryptViewAddToken(long keyId) throws Exception { CanonicalizedPublicKeyRing ring = - new DatabaseInteractor(getTargetContext()).getCanonicalizedPublicKeyRing(keyId); + new DatabaseReadWriteInteractor(getTargetContext()).getCanonicalizedPublicKeyRing(keyId); final Object item = new KeyAdapter.KeyItem(ring); return new ViewAction() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java index f8568ee3c..7534ee2bf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java @@ -51,9 +51,9 @@ import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.BackupKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java index ee21eb007..cc0e43a98 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java @@ -17,6 +17,9 @@ package org.sufficientlysecure.keychain.operations; + +import java.util.concurrent.atomic.AtomicBoolean; + import android.content.Context; import android.os.Parcelable; import android.support.annotation.NonNull; @@ -32,9 +35,7 @@ import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Passphrase; -import java.util.concurrent.atomic.AtomicBoolean; - -public abstract class BaseOperation implements PassphraseCacheInterface { +public abstract class BaseOperation implements PassphraseCacheInterface { final public Context mContext; final public Progressable mProgressable; @@ -72,7 +73,7 @@ public abstract class BaseOperation implements Passphrase } public BaseOperation(Context context, DatabaseInteractor databaseInteractor, - Progressable progressable, AtomicBoolean cancelled) { + Progressable progressable, AtomicBoolean cancelled) { mContext = context; mProgressable = progressable; mDatabaseInteractor = databaseInteractor; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseReadWriteOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseReadWriteOperation.java new file mode 100644 index 000000000..2b4524a72 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseReadWriteOperation.java @@ -0,0 +1,30 @@ +package org.sufficientlysecure.keychain.operations; + + +import java.util.concurrent.atomic.AtomicBoolean; + +import android.content.Context; +import android.os.Parcelable; + +import org.sufficientlysecure.keychain.pgp.Progressable; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; + + +abstract class BaseReadWriteOperation extends BaseOperation { + final DatabaseReadWriteInteractor mDatabaseReadWriteInteractor; + + BaseReadWriteOperation(Context context, + DatabaseReadWriteInteractor databaseInteractor, + Progressable progressable) { + super(context, databaseInteractor, progressable); + + mDatabaseReadWriteInteractor = databaseInteractor; + } + + BaseReadWriteOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, + Progressable progressable, AtomicBoolean cancelled) { + super(context, databaseInteractor, progressable, cancelled); + + mDatabaseReadWriteInteractor = databaseInteractor; + } +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java index ece2d5487..35a036c3c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java @@ -45,7 +45,7 @@ import org.sufficientlysecure.keychain.pgp.PgpSecurityConstants.OpenKeychainSymm import org.sufficientlysecure.keychain.pgp.PgpSignEncryptData; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.BenchmarkInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Log; @@ -55,7 +55,7 @@ import org.sufficientlysecure.keychain.util.ProgressScaler; public class BenchmarkOperation extends BaseOperation { - public BenchmarkOperation(Context context, DatabaseInteractor databaseInteractor, Progressable + public BenchmarkOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } 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 17d30f75f..a3fb6aca4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java @@ -39,8 +39,8 @@ import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; @@ -60,9 +60,9 @@ import org.sufficientlysecure.keychain.util.Passphrase; * * @see CertifyActionsParcel */ -public class CertifyOperation extends BaseOperation { +public class CertifyOperation extends BaseReadWriteOperation { - public CertifyOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean + public CertifyOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { super(context, databaseInteractor, progressable, cancelled); } @@ -223,7 +223,7 @@ public class CertifyOperation extends BaseOperation { KeyFormattingUtils.convertKeyIdToHex(certifiedKey.getMasterKeyId())); // store the signed key in our local cache mDatabaseInteractor.clearLog(); - SaveKeyringResult result = mDatabaseInteractor.savePublicKeyRing(certifiedKey); + SaveKeyringResult result = mDatabaseReadWriteInteractor.savePublicKeyRing(certifiedKey); if (uploadOperation != null) { UploadKeyringParcel uploadInput = diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ChangeUnlockOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ChangeUnlockOperation.java index 4cf76e5a3..bf6ef7923 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ChangeUnlockOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ChangeUnlockOperation.java @@ -29,16 +29,16 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.ProgressScaler; -public class ChangeUnlockOperation extends BaseOperation { +public class ChangeUnlockOperation extends BaseReadWriteOperation { - public ChangeUnlockOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { + public ChangeUnlockOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } @@ -71,7 +71,7 @@ public class ChangeUnlockOperation extends BaseOperation { log.add(modifyResult, 1); return new EditKeyResult(log, modifyResult); } - } catch (DatabaseInteractor.NotFoundException e) { + } catch (DatabaseReadWriteInteractor.NotFoundException e) { log.add(OperationResult.LogType.MSG_ED_ERROR_KEY_NOT_FOUND, 2); return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null); } @@ -90,7 +90,7 @@ public class ChangeUnlockOperation extends BaseOperation { // It's a success, so this must be non-null now UncachedKeyRing ring = modifyResult.getRing(); - SaveKeyringResult saveResult = mDatabaseInteractor + SaveKeyringResult saveResult = mDatabaseReadWriteInteractor .saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 70, 95, 100)); log.add(saveResult, 1); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ConsolidateOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ConsolidateOperation.java index 1142b085e..63fda571c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ConsolidateOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ConsolidateOperation.java @@ -24,13 +24,13 @@ import android.support.annotation.NonNull; import org.sufficientlysecure.keychain.operations.results.ConsolidateResult; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.ConsolidateInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; -public class ConsolidateOperation extends BaseOperation { +public class ConsolidateOperation extends BaseReadWriteOperation { - public ConsolidateOperation(Context context, DatabaseInteractor databaseInteractor, Progressable + public ConsolidateOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } @@ -40,9 +40,9 @@ public class ConsolidateOperation extends BaseOperation public ConsolidateResult execute(ConsolidateInputParcel consolidateInputParcel, CryptoInputParcel cryptoInputParcel) { if (consolidateInputParcel.mConsolidateRecovery) { - return mDatabaseInteractor.consolidateDatabaseStep2(mProgressable); + return mDatabaseReadWriteInteractor.consolidateDatabaseStep2(mProgressable); } else { - return mDatabaseInteractor.consolidateDatabaseStep1(mProgressable); + return mDatabaseReadWriteInteractor.consolidateDatabaseStep1(mProgressable); } } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java index e86591d6b..33184823e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java @@ -26,8 +26,8 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.pgp.Progressable; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.DeleteKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -41,9 +41,9 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; * a list. * */ -public class DeleteOperation extends BaseOperation { +public class DeleteOperation extends BaseReadWriteOperation { - public DeleteOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { + public DeleteOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } @@ -95,7 +95,7 @@ public class DeleteOperation extends BaseOperation { if (isSecret && success > 0) { log.add(LogType.MSG_DEL_CONSOLIDATE, 1); - ConsolidateResult sub = mDatabaseInteractor.consolidateDatabaseStep1(mProgressable); + ConsolidateResult sub = mDatabaseReadWriteInteractor.consolidateDatabaseStep1(mProgressable); log.add(sub, 2); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java index ab4e95fcc..09469cd40 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java @@ -35,8 +35,8 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; @@ -55,9 +55,9 @@ import org.sufficientlysecure.keychain.util.ProgressScaler; * @see SaveKeyringParcel * */ -public class EditKeyOperation extends BaseOperation { +public class EditKeyOperation extends BaseReadWriteOperation { - public EditKeyOperation(Context context, DatabaseInteractor databaseInteractor, + public EditKeyOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { super(context, databaseInteractor, progressable, cancelled); } @@ -161,7 +161,7 @@ public class EditKeyOperation extends BaseOperation { } // Save the new keyring. - SaveKeyringResult saveResult = mDatabaseInteractor + SaveKeyringResult saveResult = mDatabaseReadWriteInteractor .saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 60, 95, 100)); log.add(saveResult, 1); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java index 4757d7874..668392111 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java @@ -39,7 +39,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -80,18 +80,18 @@ import java.util.concurrent.atomic.AtomicBoolean; * method here will generally import keyrings in the order given by the * iterator, so this should be ensured beforehand. */ -public class ImportOperation extends BaseOperation { +public class ImportOperation extends BaseReadWriteOperation { private static final int MAX_THREADS = 10; public static final String CACHE_FILE_NAME = "key_import.pcl"; - public ImportOperation(Context context, DatabaseInteractor databaseInteractor, Progressable + public ImportOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } - public ImportOperation(Context context, DatabaseInteractor databaseInteractor, + public ImportOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { super(context, databaseInteractor, progressable, cancelled); } @@ -319,10 +319,10 @@ public class ImportOperation extends BaseOperation { ProgressScaler progressScaler = new ProgressScaler(progressable, (int) (position * progSteps), (int) ((position + 1) * progSteps), 100); if (key.isSecret()) { - result = mDatabaseInteractor.saveSecretKeyRing(key, progressScaler, + result = mDatabaseReadWriteInteractor.saveSecretKeyRing(key, progressScaler, canKeyRings, skipSave); } else { - result = mDatabaseInteractor.savePublicKeyRing(key, progressScaler, + result = mDatabaseReadWriteInteractor.savePublicKeyRing(key, progressScaler, entry.mExpectedFingerprint, canKeyRings, skipSave); } } @@ -343,7 +343,7 @@ public class ImportOperation extends BaseOperation { // synonymous to isDownloadFromKeyserver. // If no byte data was supplied, import from keyserver took place // this prevents file imports being noted as keyserver imports - mDatabaseInteractor.renewKeyLastUpdatedTime(key.getMasterKeyId(), + mDatabaseReadWriteInteractor.renewKeyLastUpdatedTime(key.getMasterKeyId(), GregorianCalendar.getInstance().getTimeInMillis(), TimeUnit.MILLISECONDS); } @@ -366,7 +366,7 @@ public class ImportOperation extends BaseOperation { setPreventCancel(); ConsolidateResult result; synchronized (mDatabaseInteractor) { - result = mDatabaseInteractor.consolidateDatabaseStep1(progressable); + result = mDatabaseReadWriteInteractor.consolidateDatabaseStep1(progressable); } log.add(result, 1); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java index 4f4a8b0db..8eabfc9f7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java @@ -36,7 +36,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.KeybaseVerificationParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -59,7 +59,7 @@ import de.measite.minidns.record.TXT; public class KeybaseVerificationOperation extends BaseOperation { - public KeybaseVerificationOperation(Context context, DatabaseInteractor databaseInteractor, + public KeybaseVerificationOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperation.java index 13141b403..55d243a0c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperation.java @@ -33,8 +33,8 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.PromoteKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -47,9 +47,8 @@ import org.sufficientlysecure.keychain.util.ProgressScaler; * without secret key material, using a GNU_DUMMY s2k type. * */ -public class PromoteKeyOperation extends BaseOperation { - - public PromoteKeyOperation(Context context, DatabaseInteractor databaseInteractor, +public class PromoteKeyOperation extends BaseReadWriteOperation { + public PromoteKeyOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { super(context, databaseInteractor, progressable, cancelled); } @@ -114,7 +113,7 @@ public class PromoteKeyOperation extends BaseOperation { setPreventCancel(); // Save the new keyring. - SaveKeyringResult saveResult = mDatabaseInteractor + SaveKeyringResult saveResult = mDatabaseReadWriteInteractor .saveSecretKeyRing(promotedRing, new ProgressScaler(mProgressable, 60, 95, 100)); log.add(saveResult, 1); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/RevokeOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/RevokeOperation.java index 920efb1ef..33b6cb478 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/RevokeOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/RevokeOperation.java @@ -31,17 +31,17 @@ import org.sufficientlysecure.keychain.operations.results.RevokeResult; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.RevokeKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; -public class RevokeOperation extends BaseOperation { +public class RevokeOperation extends BaseReadWriteOperation { - public RevokeOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { + public RevokeOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } @@ -81,7 +81,7 @@ public class RevokeOperation extends BaseOperation { saveKeyringParcel.mRevokeSubKeys.add(masterKeyId); EditKeyResult revokeAndUploadResult = new EditKeyOperation(mContext, - mDatabaseInteractor, mProgressable, mCancelled).execute(saveKeyringParcel, cryptoInputParcel); + mDatabaseReadWriteInteractor, mProgressable, mCancelled).execute(saveKeyringParcel, cryptoInputParcel); if (revokeAndUploadResult.isPending()) { return revokeAndUploadResult; @@ -97,7 +97,7 @@ public class RevokeOperation extends BaseOperation { return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId); } - } catch (PgpKeyNotFoundException | DatabaseInteractor.NotFoundException e) { + } catch (PgpKeyNotFoundException | DatabaseReadWriteInteractor.NotFoundException e) { Log.e(Constants.TAG, "could not find key to revoke", e); log.add(OperationResult.LogType.MSG_REVOKE_ERROR_KEY_FAIL, 1); return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java index fb5c941fb..4a992dc0a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java @@ -18,6 +18,10 @@ package org.sufficientlysecure.keychain.operations; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicBoolean; + import android.content.Context; import android.net.Uri; import android.support.annotation.NonNull; @@ -36,15 +40,11 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; -import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.SecurityTokenSignOperationsBuilder; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.RequiredInputType; +import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.SecurityTokenSignOperationsBuilder; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ProgressScaler; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.concurrent.atomic.AtomicBoolean; - /** * This is a high-level operation, which encapsulates one or more sign/encrypt diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java index bc75d0ae7..f5c39d3da 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java @@ -38,6 +38,7 @@ import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -59,7 +60,7 @@ import java.util.concurrent.atomic.AtomicBoolean; public class UploadOperation extends BaseOperation { public UploadOperation(Context context, DatabaseInteractor databaseInteractor, - Progressable progressable, AtomicBoolean cancelled) { + Progressable progressable, AtomicBoolean cancelled) { super(context, databaseInteractor, progressable, cancelled); } @@ -132,7 +133,7 @@ public class UploadOperation extends BaseOperation { log.add(LogType.MSG_UPLOAD_KEY, 0, KeyFormattingUtils.convertKeyIdToHex(canonicalizedRing.getMasterKeyId())); return (CanonicalizedPublicKeyRing) canonicalizedRing; - } catch (DatabaseInteractor.NotFoundException e) { + } catch (DatabaseReadWriteInteractor.NotFoundException e) { log.add(LogType.MSG_UPLOAD_ERROR_NOT_FOUND, 1); return null; } catch (IOException | PgpGeneralException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java index ee8a2b050..06a9e8bbe 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java @@ -47,7 +47,7 @@ import org.bouncycastle.openpgp.operator.jcajce.SessionKeySecretKeyDecryptorBuil import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Passphrase; @@ -127,7 +127,7 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey { * passphrase in the process. * * This method can potentially take a LONG time (i.e. seconds), so it should only - * ever be called by {@link DatabaseInteractor} for the purpose of caching its output + * ever be called by {@link DatabaseReadWriteInteractor} for the purpose of caching its output * in the database. */ public SecretKeyType getSecretKeyTypeSuperExpensive() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java index b7662b44e..953c7d695 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java @@ -71,8 +71,9 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -668,7 +669,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation 0; - } catch(DatabaseInteractor.NotFoundException e) { + } catch(DatabaseReadWriteInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -162,7 +162,7 @@ public class CachedPublicKeyRing extends KeyRing { KeychainContract.KeyRings.HAS_CERTIFY, DatabaseInteractor.FIELD_TYPE_NULL); return !((Boolean) data); - } catch(DatabaseInteractor.NotFoundException e) { + } catch(DatabaseReadWriteInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -174,7 +174,7 @@ public class CachedPublicKeyRing extends KeyRing { KeyRings.HAS_ENCRYPT, DatabaseInteractor.FIELD_TYPE_INTEGER); return (Long) data; - } catch(DatabaseInteractor.NotFoundException e) { + } catch(DatabaseReadWriteInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -196,7 +196,7 @@ public class CachedPublicKeyRing extends KeyRing { KeyRings.HAS_SIGN, DatabaseInteractor.FIELD_TYPE_INTEGER); return (Long) data; - } catch(DatabaseInteractor.NotFoundException e) { + } catch(DatabaseReadWriteInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -208,7 +208,7 @@ public class CachedPublicKeyRing extends KeyRing { KeychainContract.KeyRings.VERIFIED, DatabaseInteractor.FIELD_TYPE_INTEGER); return ((Long) data).intValue(); - } catch(DatabaseInteractor.NotFoundException e) { + } catch(DatabaseReadWriteInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -219,7 +219,7 @@ public class CachedPublicKeyRing extends KeyRing { KeychainContract.KeyRings.HAS_ANY_SECRET, DatabaseInteractor.FIELD_TYPE_INTEGER); return (Long) data > 0; - } catch(DatabaseInteractor.NotFoundException e) { + } catch(DatabaseReadWriteInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java index 1d1b93d93..31b0eb090 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java @@ -1,130 +1,58 @@ -/* - * Copyright (C) 2012-2014 Dominik Schürmann - * Copyright (C) 2014 Vincent Breitmoser - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - package org.sufficientlysecure.keychain.provider; -import android.content.ContentProviderOperation; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; + import android.content.ContentResolver; -import android.content.ContentValues; -import android.content.Context; -import android.content.OperationApplicationException; import android.database.Cursor; import android.net.Uri; -import android.os.RemoteException; -import android.support.annotation.NonNull; -import android.support.v4.util.LongSparseArray; -import org.openintents.openpgp.util.OpenPgpUtils; import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; -import org.sufficientlysecure.keychain.operations.ImportOperation; -import org.sufficientlysecure.keychain.operations.results.ConsolidateResult; -import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; -import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; -import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; -import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKey; 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.KeyRing; -import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; -import org.sufficientlysecure.keychain.pgp.WrappedSignature; -import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; -import org.sufficientlysecure.keychain.provider.KeychainContract.UpdatedKeys; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; -import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; -import org.sufficientlysecure.keychain.util.IterableIterator; -import org.sufficientlysecure.keychain.util.IteratorWithSize; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.ParcelableFileCache; -import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.util.ProgressFixedScaler; -import org.sufficientlysecure.keychain.util.ProgressScaler; -import org.sufficientlysecure.keychain.util.Utf8Util; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.TimeUnit; -/** - * This class contains high level methods for database access. Despite its - * name, it is not only a helper but actually the main interface for all - * synchronous database operations. - *

- * Operations in this class write logs. These can be obtained from the - * OperationResultParcel return values directly, but are also accumulated over - * the lifetime of the executing ProviderHelper object unless the resetLog() - * method is called to start a new one specifically. - */ public class DatabaseInteractor { - private final Context mContext; - private final ContentResolver mContentResolver; - private OperationLog mLog; - private int mIndent; + // If we ever switch to api level 11, we can ditch this whole mess! + public static final int FIELD_TYPE_NULL = 1; + // this is called integer to stay coherent with the constants in Cursor (api level 11) + public static final int FIELD_TYPE_INTEGER = 2; + public static final int FIELD_TYPE_FLOAT = 3; + public static final int FIELD_TYPE_STRING = 4; + public static final int FIELD_TYPE_BLOB = 5; - public DatabaseInteractor(Context context) { - this(context, new OperationLog(), 0); + final ContentResolver mContentResolver; + OperationLog mLog; + int mIndent; + + public DatabaseInteractor(ContentResolver contentResolver) { + this(contentResolver, new OperationLog(), 0); } - public DatabaseInteractor(Context context, OperationLog log) { - this(context, log, 0); - } - - public DatabaseInteractor(Context context, OperationLog log, int indent) { - mContext = context; - mContentResolver = context.getContentResolver(); - mLog = log; + public DatabaseInteractor(ContentResolver contentResolver, OperationLog log, int indent) { + mContentResolver = contentResolver; mIndent = indent; + mLog = log; } public OperationLog getLog() { return mLog; } - public static class NotFoundException extends Exception { - public NotFoundException() { - } - - public NotFoundException(String name) { - super(name); - } - } - public void log(LogType type) { if (mLog != null) { mLog.add(type, mIndent); @@ -141,14 +69,6 @@ public class DatabaseInteractor { mLog = new OperationLog(); } - // If we ever switch to api level 11, we can ditch this whole mess! - public static final int FIELD_TYPE_NULL = 1; - // this is called integer to stay coherent with the constants in Cursor (api level 11) - public static final int FIELD_TYPE_INTEGER = 2; - public static final int FIELD_TYPE_FLOAT = 3; - public static final int FIELD_TYPE_STRING = 4; - public static final int FIELD_TYPE_BLOB = 5; - public Object getGenericData(Uri uri, String column, int type) throws NotFoundException { Object result = getGenericData(uri, new String[]{column}, new int[]{type}, null).get(column); if (result == null) { @@ -213,38 +133,6 @@ public class DatabaseInteractor { return getGenericData(KeyRings.buildUnifiedKeyRingUri(masterKeyId), proj, types); } - private LongSparseArray getTrustedMasterKeys() { - Cursor cursor = mContentResolver.query(KeyRings.buildUnifiedKeyRingsUri(), new String[]{ - KeyRings.MASTER_KEY_ID, - // we pick from cache only information that is not easily available from keyrings - KeyRings.HAS_ANY_SECRET, KeyRings.VERIFIED, - // and of course, ring data - KeyRings.PUBKEY_DATA - }, KeyRings.HAS_ANY_SECRET + " = 1", null, null); - - try { - LongSparseArray result = new LongSparseArray<>(); - - if (cursor != null && cursor.moveToFirst()) do { - long masterKeyId = cursor.getLong(0); - int verified = cursor.getInt(2); - byte[] blob = cursor.getBlob(3); - if (blob != null) { - result.put(masterKeyId, - new CanonicalizedPublicKeyRing(blob, verified).getPublicKey()); - } - } while (cursor.moveToNext()); - - return result; - - } finally { - if (cursor != null) { - cursor.close(); - } - } - - } - public long getMasterKeyId(long subKeyId) throws NotFoundException { return (Long) getGenericData(KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId), KeyRings.MASTER_KEY_ID, FIELD_TYPE_INTEGER); @@ -327,1204 +215,6 @@ public class DatabaseInteractor { } } - // bits, in order: CESA. make SURE these are correct, we will get bad log entries otherwise!! - static final LogType LOG_TYPES_FLAG_MASTER[] = new LogType[]{ - LogType.MSG_IP_MASTER_FLAGS_XXXX, LogType.MSG_IP_MASTER_FLAGS_CXXX, - LogType.MSG_IP_MASTER_FLAGS_XEXX, LogType.MSG_IP_MASTER_FLAGS_CEXX, - LogType.MSG_IP_MASTER_FLAGS_XXSX, LogType.MSG_IP_MASTER_FLAGS_CXSX, - LogType.MSG_IP_MASTER_FLAGS_XESX, LogType.MSG_IP_MASTER_FLAGS_CESX, - LogType.MSG_IP_MASTER_FLAGS_XXXA, LogType.MSG_IP_MASTER_FLAGS_CXXA, - LogType.MSG_IP_MASTER_FLAGS_XEXA, LogType.MSG_IP_MASTER_FLAGS_CEXA, - LogType.MSG_IP_MASTER_FLAGS_XXSA, LogType.MSG_IP_MASTER_FLAGS_CXSA, - LogType.MSG_IP_MASTER_FLAGS_XESA, LogType.MSG_IP_MASTER_FLAGS_CESA - }; - - // same as above, but for subkeys - static final LogType LOG_TYPES_FLAG_SUBKEY[] = new LogType[]{ - LogType.MSG_IP_SUBKEY_FLAGS_XXXX, LogType.MSG_IP_SUBKEY_FLAGS_CXXX, - LogType.MSG_IP_SUBKEY_FLAGS_XEXX, LogType.MSG_IP_SUBKEY_FLAGS_CEXX, - LogType.MSG_IP_SUBKEY_FLAGS_XXSX, LogType.MSG_IP_SUBKEY_FLAGS_CXSX, - LogType.MSG_IP_SUBKEY_FLAGS_XESX, LogType.MSG_IP_SUBKEY_FLAGS_CESX, - LogType.MSG_IP_SUBKEY_FLAGS_XXXA, LogType.MSG_IP_SUBKEY_FLAGS_CXXA, - LogType.MSG_IP_SUBKEY_FLAGS_XEXA, LogType.MSG_IP_SUBKEY_FLAGS_CEXA, - LogType.MSG_IP_SUBKEY_FLAGS_XXSA, LogType.MSG_IP_SUBKEY_FLAGS_CXSA, - LogType.MSG_IP_SUBKEY_FLAGS_XESA, LogType.MSG_IP_SUBKEY_FLAGS_CESA - }; - - /** - * Saves an UncachedKeyRing of the public variant into the db. - *

- * This method will not delete all previous data for this masterKeyId from the database prior - * to inserting. All public data is effectively re-inserted, secret keyrings are left deleted - * and need to be saved externally to be preserved past the operation. - */ - @SuppressWarnings("unchecked") - private int saveCanonicalizedPublicKeyRing(CanonicalizedPublicKeyRing keyRing, - Progressable progress, boolean selfCertsAreTrusted) { - - // start with ok result - int result = SaveKeyringResult.SAVED_PUBLIC; - - long masterKeyId = keyRing.getMasterKeyId(); - UncachedPublicKey masterKey = keyRing.getPublicKey(); - - ArrayList operations; - try { - - log(LogType.MSG_IP_PREPARE); - mIndent += 1; - - // save all keys and userIds included in keyRing object in database - operations = new ArrayList<>(); - - log(LogType.MSG_IP_INSERT_KEYRING); - { // insert keyring - ContentValues values = new ContentValues(); - values.put(KeyRingData.MASTER_KEY_ID, masterKeyId); - try { - values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded()); - } catch (IOException e) { - log(LogType.MSG_IP_ENCODE_FAIL); - return SaveKeyringResult.RESULT_ERROR; - } - - Uri uri = KeyRingData.buildPublicKeyRingUri(masterKeyId); - operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build()); - } - - log(LogType.MSG_IP_INSERT_SUBKEYS); - progress.setProgress(LogType.MSG_IP_INSERT_SUBKEYS.getMsgId(), 40, 100); - mIndent += 1; - { // insert subkeys - Uri uri = Keys.buildKeysUri(masterKeyId); - int rank = 0; - for (CanonicalizedPublicKey key : keyRing.publicKeyIterator()) { - long keyId = key.getKeyId(); - log(keyId == masterKeyId ? LogType.MSG_IP_MASTER : LogType.MSG_IP_SUBKEY, - KeyFormattingUtils.convertKeyIdToHex(keyId) - ); - mIndent += 1; - - ContentValues values = new ContentValues(); - values.put(Keys.MASTER_KEY_ID, masterKeyId); - values.put(Keys.RANK, rank); - - values.put(Keys.KEY_ID, key.getKeyId()); - values.put(Keys.KEY_SIZE, key.getBitStrength()); - values.put(Keys.KEY_CURVE_OID, key.getCurveOid()); - values.put(Keys.ALGORITHM, key.getAlgorithm()); - values.put(Keys.FINGERPRINT, key.getFingerprint()); - - boolean c = key.canCertify(), e = key.canEncrypt(), s = key.canSign(), a = key.canAuthenticate(); - values.put(Keys.CAN_CERTIFY, c); - values.put(Keys.CAN_ENCRYPT, e); - values.put(Keys.CAN_SIGN, s); - values.put(Keys.CAN_AUTHENTICATE, a); - values.put(Keys.IS_REVOKED, key.isRevoked()); - values.put(Keys.IS_SECURE, key.isSecure()); - - // see above - if (masterKeyId == keyId) { - if (key.getKeyUsage() == null) { - log(LogType.MSG_IP_MASTER_FLAGS_UNSPECIFIED); - } else { - log(LOG_TYPES_FLAG_MASTER[(c ? 1 : 0) + (e ? 2 : 0) + (s ? 4 : 0) + (a ? 8 : 0)]); - } - } else { - if (key.getKeyUsage() == null) { - log(LogType.MSG_IP_SUBKEY_FLAGS_UNSPECIFIED); - } else { - log(LOG_TYPES_FLAG_SUBKEY[(c ? 1 : 0) + (e ? 2 : 0) + (s ? 4 : 0) + (a ? 8 : 0)]); - } - } - - Date creation = key.getCreationTime(); - values.put(Keys.CREATION, creation.getTime() / 1000); - Date expiryDate = key.getExpiryTime(); - if (expiryDate != null) { - values.put(Keys.EXPIRY, expiryDate.getTime() / 1000); - if (key.isExpired()) { - log(keyId == masterKeyId ? - LogType.MSG_IP_MASTER_EXPIRED : LogType.MSG_IP_SUBKEY_EXPIRED, - expiryDate.toString()); - } else { - log(keyId == masterKeyId ? - LogType.MSG_IP_MASTER_EXPIRES : LogType.MSG_IP_SUBKEY_EXPIRES, - expiryDate.toString()); - } - } - - operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build()); - ++rank; - mIndent -= 1; - } - } - mIndent -= 1; - - // get a list of owned secret keys, for verification filtering - LongSparseArray trustedKeys = getTrustedMasterKeys(); - - // classify and order user ids. primary are moved to the front, revoked to the back, - // otherwise the order in the keyfile is preserved. - List uids = new ArrayList<>(); - - if (trustedKeys.size() == 0) { - log(LogType.MSG_IP_UID_CLASSIFYING_ZERO); - } else { - log(LogType.MSG_IP_UID_CLASSIFYING, trustedKeys.size()); - } - mIndent += 1; - for (byte[] rawUserId : masterKey.getUnorderedRawUserIds()) { - String userId = Utf8Util.fromUTF8ByteArrayReplaceBadEncoding(rawUserId); - UserPacketItem item = new UserPacketItem(); - uids.add(item); - OpenPgpUtils.UserId splitUserId = KeyRing.splitUserId(userId); - item.userId = userId; - item.name = splitUserId.name; - item.email = splitUserId.email; - item.comment = splitUserId.comment; - int unknownCerts = 0; - - log(LogType.MSG_IP_UID_PROCESSING, userId); - mIndent += 1; - // look through signatures for this specific key - for (WrappedSignature cert : new IterableIterator<>( - masterKey.getSignaturesForRawId(rawUserId))) { - long certId = cert.getKeyId(); - // self signature - if (certId == masterKeyId) { - - // NOTE self-certificates are already verified during canonicalization, - // AND we know there is at most one cert plus at most one revocation - if (!cert.isRevocation()) { - item.selfCert = cert; - item.isPrimary = cert.isPrimaryUserId(); - } else { - item.selfRevocation = cert; - log(LogType.MSG_IP_UID_REVOKED); - } - continue; - - } - - // do we have a trusted key for this? - if (trustedKeys.indexOfKey(certId) < 0) { - unknownCerts += 1; - continue; - } - - // verify signatures from known private keys - CanonicalizedPublicKey trustedKey = trustedKeys.get(certId); - - try { - cert.init(trustedKey); - // if it doesn't certify, leave a note and skip - if (!cert.verifySignature(masterKey, rawUserId)) { - log(LogType.MSG_IP_UID_CERT_BAD); - continue; - } - - log(cert.isRevocation() - ? LogType.MSG_IP_UID_CERT_GOOD_REVOKE - : LogType.MSG_IP_UID_CERT_GOOD, - KeyFormattingUtils.convertKeyIdToHexShort(trustedKey.getKeyId()) - ); - - // check if there is a previous certificate - WrappedSignature prev = item.trustedCerts.get(cert.getKeyId()); - if (prev != null) { - // if it's newer, skip this one - if (prev.getCreationTime().after(cert.getCreationTime())) { - log(LogType.MSG_IP_UID_CERT_OLD); - continue; - } - // if the previous one was a non-revokable certification, no need to look further - if (!prev.isRevocation() && !prev.isRevokable()) { - log(LogType.MSG_IP_UID_CERT_NONREVOKE); - continue; - } - log(LogType.MSG_IP_UID_CERT_NEW); - } - item.trustedCerts.put(cert.getKeyId(), cert); - - } catch (PgpGeneralException e) { - log(LogType.MSG_IP_UID_CERT_ERROR, - KeyFormattingUtils.convertKeyIdToHex(cert.getKeyId())); - } - - } - - if (unknownCerts > 0) { - log(LogType.MSG_IP_UID_CERTS_UNKNOWN, unknownCerts); - } - mIndent -= 1; - - } - mIndent -= 1; - - ArrayList userAttributes = masterKey.getUnorderedUserAttributes(); - // Don't spam the log if there aren't even any attributes - if (!userAttributes.isEmpty()) { - log(LogType.MSG_IP_UAT_CLASSIFYING); - } - - mIndent += 1; - for (WrappedUserAttribute userAttribute : userAttributes) { - - UserPacketItem item = new UserPacketItem(); - uids.add(item); - item.type = userAttribute.getType(); - item.attributeData = userAttribute.getEncoded(); - - int unknownCerts = 0; - - switch (item.type) { - case WrappedUserAttribute.UAT_IMAGE: - log(LogType.MSG_IP_UAT_PROCESSING_IMAGE); - break; - default: - log(LogType.MSG_IP_UAT_PROCESSING_UNKNOWN); - break; - } - mIndent += 1; - // look through signatures for this specific key - for (WrappedSignature cert : new IterableIterator<>( - masterKey.getSignaturesForUserAttribute(userAttribute))) { - long certId = cert.getKeyId(); - // self signature - if (certId == masterKeyId) { - - // NOTE self-certificates are already verified during canonicalization, - // AND we know there is at most one cert plus at most one revocation - // AND the revocation only exists if there is no newer certification - if (!cert.isRevocation()) { - item.selfCert = cert; - } else { - item.selfRevocation = cert; - log(LogType.MSG_IP_UAT_REVOKED); - } - continue; - - } - - // do we have a trusted key for this? - if (trustedKeys.indexOfKey(certId) < 0) { - unknownCerts += 1; - continue; - } - - // verify signatures from known private keys - CanonicalizedPublicKey trustedKey = trustedKeys.get(certId); - - try { - cert.init(trustedKey); - // if it doesn't certify, leave a note and skip - if (!cert.verifySignature(masterKey, userAttribute)) { - log(LogType.MSG_IP_UAT_CERT_BAD); - continue; - } - - log(cert.isRevocation() - ? LogType.MSG_IP_UAT_CERT_GOOD_REVOKE - : LogType.MSG_IP_UAT_CERT_GOOD, - KeyFormattingUtils.convertKeyIdToHexShort(trustedKey.getKeyId()) - ); - - // check if there is a previous certificate - WrappedSignature prev = item.trustedCerts.get(cert.getKeyId()); - if (prev != null) { - // if it's newer, skip this one - if (prev.getCreationTime().after(cert.getCreationTime())) { - log(LogType.MSG_IP_UAT_CERT_OLD); - continue; - } - // if the previous one was a non-revokable certification, no need to look further - if (!prev.isRevocation() && !prev.isRevokable()) { - log(LogType.MSG_IP_UAT_CERT_NONREVOKE); - continue; - } - log(LogType.MSG_IP_UAT_CERT_NEW); - } - item.trustedCerts.put(cert.getKeyId(), cert); - - } catch (PgpGeneralException e) { - log(LogType.MSG_IP_UAT_CERT_ERROR, - KeyFormattingUtils.convertKeyIdToHex(cert.getKeyId())); - } - - } - - if (unknownCerts > 0) { - log(LogType.MSG_IP_UAT_CERTS_UNKNOWN, unknownCerts); - } - mIndent -= 1; - - } - mIndent -= 1; - - progress.setProgress(LogType.MSG_IP_UID_REORDER.getMsgId(), 65, 100); - log(LogType.MSG_IP_UID_REORDER); - // primary before regular before revoked (see UserIdItem.compareTo) - // this is a stable sort, so the order of keys is otherwise preserved. - Collections.sort(uids); - // iterate and put into db - for (int userIdRank = 0; userIdRank < uids.size(); userIdRank++) { - UserPacketItem item = uids.get(userIdRank); - operations.add(buildUserIdOperations(masterKeyId, item, userIdRank)); - - if (item.selfRevocation != null) { - operations.add(buildCertOperations(masterKeyId, userIdRank, item.selfRevocation, - Certs.VERIFIED_SELF)); - // don't bother with trusted certs if the uid is revoked, anyways - continue; - } - - if (item.selfCert == null) { - throw new AssertionError("User ids MUST be self-certified at this point!!"); - } - - operations.add(buildCertOperations(masterKeyId, userIdRank, item.selfCert, - selfCertsAreTrusted ? Certs.VERIFIED_SECRET : Certs.VERIFIED_SELF)); - - // iterate over signatures - for (int i = 0; i < item.trustedCerts.size(); i++) { - WrappedSignature sig = item.trustedCerts.valueAt(i); - // if it's a revocation - if (sig.isRevocation()) { - // don't further process it - continue; - } - // otherwise, build database operation - operations.add(buildCertOperations( - masterKeyId, userIdRank, sig, Certs.VERIFIED_SECRET)); - } - } - - } catch (IOException e) { - log(LogType.MSG_IP_ERROR_IO_EXC); - Log.e(Constants.TAG, "IOException during import", e); - return SaveKeyringResult.RESULT_ERROR; - } finally { - mIndent -= 1; - } - - // before deleting key, retrieve it's last updated time - final int INDEX_MASTER_KEY_ID = 0; - final int INDEX_LAST_UPDATED = 1; - Cursor lastUpdatedCursor = mContentResolver.query( - UpdatedKeys.CONTENT_URI, - new String[]{ - UpdatedKeys.MASTER_KEY_ID, - UpdatedKeys.LAST_UPDATED - }, - UpdatedKeys.MASTER_KEY_ID + " = ?", - new String[]{"" + masterKeyId}, - null - ); - if (lastUpdatedCursor.moveToNext()) { - // there was an entry to re-insert - // this operation must happen after the new key is inserted - ContentValues lastUpdatedEntry = new ContentValues(2); - lastUpdatedEntry.put(UpdatedKeys.MASTER_KEY_ID, - lastUpdatedCursor.getLong(INDEX_MASTER_KEY_ID)); - lastUpdatedEntry.put(UpdatedKeys.LAST_UPDATED, - lastUpdatedCursor.getLong(INDEX_LAST_UPDATED)); - operations.add( - ContentProviderOperation - .newInsert(UpdatedKeys.CONTENT_URI) - .withValues(lastUpdatedEntry) - .build() - ); - } - lastUpdatedCursor.close(); - - try { - // delete old version of this keyRing, which also deletes all keys and userIds on cascade - int deleted = mContentResolver.delete( - KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null); - if (deleted > 0) { - log(LogType.MSG_IP_DELETE_OLD_OK); - result |= SaveKeyringResult.UPDATED; - } else { - log(LogType.MSG_IP_DELETE_OLD_FAIL); - } - - log(LogType.MSG_IP_APPLY_BATCH); - progress.setProgress(LogType.MSG_IP_APPLY_BATCH.getMsgId(), 75, 100); - mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations); - - log(LogType.MSG_IP_SUCCESS); - progress.setProgress(LogType.MSG_IP_SUCCESS.getMsgId(), 90, 100); - return result; - - } catch (RemoteException e) { - log(LogType.MSG_IP_ERROR_REMOTE_EX); - Log.e(Constants.TAG, "RemoteException during import", e); - return SaveKeyringResult.RESULT_ERROR; - } catch (OperationApplicationException e) { - log(LogType.MSG_IP_ERROR_OP_EXC); - Log.e(Constants.TAG, "OperationApplicationException during import", e); - return SaveKeyringResult.RESULT_ERROR; - } - - } - - private static class UserPacketItem implements Comparable { - Integer type; - String userId; - String name; - String email; - String comment; - byte[] attributeData; - boolean isPrimary = false; - WrappedSignature selfCert; - WrappedSignature selfRevocation; - LongSparseArray trustedCerts = new LongSparseArray<>(); - - @Override - public int compareTo(@NonNull UserPacketItem o) { - // revoked keys always come last! - //noinspection DoubleNegation - if ((selfRevocation != null) != (o.selfRevocation != null)) { - return selfRevocation != null ? 1 : -1; - } - // if one is a user id, but the other isn't, the user id always comes first. - // we compare for null values here, so != is the correct operator! - // noinspection NumberEquality - if (type != o.type) { - return type == null ? -1 : 1; - } - // if one is *trusted* but the other isn't, that one comes first - // this overrides the primary attribute, even! - if ((trustedCerts.size() == 0) != (o.trustedCerts.size() == 0)) { - return trustedCerts.size() > o.trustedCerts.size() ? -1 : 1; - } - // if one key is primary but the other isn't, the primary one always comes first - if (isPrimary != o.isPrimary) { - return isPrimary ? -1 : 1; - } - return 0; - } - } - - /** - * Saves an UncachedKeyRing of the secret variant into the db. - * This method will fail if no corresponding public keyring is in the database! - */ - private int saveCanonicalizedSecretKeyRing(CanonicalizedSecretKeyRing keyRing) { - - long masterKeyId = keyRing.getMasterKeyId(); - log(LogType.MSG_IS, KeyFormattingUtils.convertKeyIdToHex(masterKeyId)); - mIndent += 1; - - try { - - // IF this is successful, it's a secret key - int result = SaveKeyringResult.SAVED_SECRET; - - // save secret keyring - try { - ContentValues values = new ContentValues(); - values.put(KeyRingData.MASTER_KEY_ID, masterKeyId); - values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded()); - // insert new version of this keyRing - Uri uri = KeyRingData.buildSecretKeyRingUri(masterKeyId); - if (mContentResolver.insert(uri, values) == null) { - log(LogType.MSG_IS_DB_EXCEPTION); - return SaveKeyringResult.RESULT_ERROR; - } - } catch (IOException e) { - Log.e(Constants.TAG, "Failed to encode key!", e); - log(LogType.MSG_IS_ERROR_IO_EXC); - return SaveKeyringResult.RESULT_ERROR; - } - - { - Uri uri = Keys.buildKeysUri(masterKeyId); - - // first, mark all keys as not available - ContentValues values = new ContentValues(); - values.put(Keys.HAS_SECRET, SecretKeyType.GNU_DUMMY.getNum()); - mContentResolver.update(uri, values, null, null); - - // then, mark exactly the keys we have available - log(LogType.MSG_IS_IMPORTING_SUBKEYS); - mIndent += 1; - for (CanonicalizedSecretKey sub : keyRing.secretKeyIterator()) { - long id = sub.getKeyId(); - SecretKeyType mode = sub.getSecretKeyTypeSuperExpensive(); - values.put(Keys.HAS_SECRET, mode.getNum()); - int upd = mContentResolver.update(uri, values, Keys.KEY_ID + " = ?", - new String[]{Long.toString(id)}); - if (upd == 1) { - switch (mode) { - case PASSPHRASE: - log(LogType.MSG_IS_SUBKEY_OK, - KeyFormattingUtils.convertKeyIdToHex(id) - ); - break; - case PASSPHRASE_EMPTY: - log(LogType.MSG_IS_SUBKEY_EMPTY, - KeyFormattingUtils.convertKeyIdToHex(id) - ); - break; - case PIN: - log(LogType.MSG_IS_SUBKEY_PIN, - KeyFormattingUtils.convertKeyIdToHex(id) - ); - break; - case GNU_DUMMY: - log(LogType.MSG_IS_SUBKEY_STRIPPED, - KeyFormattingUtils.convertKeyIdToHex(id) - ); - break; - case DIVERT_TO_CARD: - log(LogType.MSG_IS_SUBKEY_DIVERT, - KeyFormattingUtils.convertKeyIdToHex(id) - ); - break; - } - } else { - log(LogType.MSG_IS_SUBKEY_NONEXISTENT, - KeyFormattingUtils.convertKeyIdToHex(id) - ); - } - } - mIndent -= 1; - - // this implicitly leaves all keys which were not in the secret key ring - // with has_secret = 1 - } - - log(LogType.MSG_IS_SUCCESS); - return result; - - } finally { - mIndent -= 1; - } - - } - - /** - * Save a public keyring into the database. - *

- * This is a high level method, which takes care of merging all new information into the old and - * keep public and secret keyrings in sync. - *

- * If you want to merge keys in-memory only and not save in database set skipSave=true. - */ - public SaveKeyringResult savePublicKeyRing(UncachedKeyRing publicRing, Progressable progress, - String expectedFingerprint, - ArrayList canKeyRings, - boolean skipSave) { - - try { - long masterKeyId = publicRing.getMasterKeyId(); - log(LogType.MSG_IP, KeyFormattingUtils.convertKeyIdToHex(masterKeyId)); - mIndent += 1; - - if (publicRing.isSecret()) { - log(LogType.MSG_IP_BAD_TYPE_SECRET); - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } - - CanonicalizedPublicKeyRing canPublicRing; - boolean alreadyExists = false; - - // If there is an old keyring, merge it - try { - UncachedKeyRing oldPublicRing = getCanonicalizedPublicKeyRing(masterKeyId).getUncachedKeyRing(); - alreadyExists = true; - - // Merge data from new public ring into the old one - log(LogType.MSG_IP_MERGE_PUBLIC); - publicRing = oldPublicRing.merge(publicRing, mLog, mIndent); - - // If this is null, there is an error in the log so we can just return - if (publicRing == null) { - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } - - // Canonicalize this keyring, to assert a number of assumptions made about it. - canPublicRing = (CanonicalizedPublicKeyRing) publicRing.canonicalize(mLog, mIndent); - if (canPublicRing == null) { - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } - if (canKeyRings != null) canKeyRings.add(canPublicRing); - - // Early breakout if nothing changed - if (Arrays.hashCode(publicRing.getEncoded()) - == Arrays.hashCode(oldPublicRing.getEncoded())) { - log(LogType.MSG_IP_SUCCESS_IDENTICAL); - return new SaveKeyringResult(SaveKeyringResult.UPDATED, mLog, null); - } - } catch (NotFoundException e) { - // Not an issue, just means we are dealing with a new keyring. - - // Canonicalize this keyring, to assert a number of assumptions made about it. - canPublicRing = (CanonicalizedPublicKeyRing) publicRing.canonicalize(mLog, mIndent); - if (canPublicRing == null) { - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } - if (canKeyRings != null) canKeyRings.add(canPublicRing); - } - - // If there is a secret key, merge new data (if any) and save the key for later - CanonicalizedSecretKeyRing canSecretRing; - try { - UncachedKeyRing secretRing = getCanonicalizedSecretKeyRing(publicRing.getMasterKeyId()) - .getUncachedKeyRing(); - - // Merge data from new public ring into secret one - log(LogType.MSG_IP_MERGE_SECRET); - secretRing = secretRing.merge(publicRing, mLog, mIndent); - if (secretRing == null) { - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } - // This has always been a secret key ring, this is a safe cast - canSecretRing = (CanonicalizedSecretKeyRing) secretRing.canonicalize(mLog, mIndent); - if (canSecretRing == null) { - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } - - } catch (NotFoundException e) { - // No secret key available (this is what happens most of the time) - canSecretRing = null; - } - - - // If we have an expected fingerprint, make sure it matches - if (expectedFingerprint != null) { - if (!canPublicRing.containsBoundSubkey(expectedFingerprint)) { - log(LogType.MSG_IP_FINGERPRINT_ERROR); - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } else { - log(LogType.MSG_IP_FINGERPRINT_OK); - } - } - - int result; - if (skipSave) { - // skip save method, set fixed result - result = SaveKeyringResult.SAVED_PUBLIC - | (alreadyExists ? SaveKeyringResult.UPDATED : 0); - } else { - result = saveCanonicalizedPublicKeyRing(canPublicRing, progress, canSecretRing != null); - } - - // Save the saved keyring (if any) - if (canSecretRing != null) { - progress.setProgress(LogType.MSG_IP_REINSERT_SECRET.getMsgId(), 90, 100); - - int secretResult; - if (skipSave) { - // skip save method, set fixed result - secretResult = SaveKeyringResult.SAVED_SECRET; - } else { - secretResult = saveCanonicalizedSecretKeyRing(canSecretRing); - } - - if ((secretResult & SaveKeyringResult.RESULT_ERROR) != SaveKeyringResult.RESULT_ERROR) { - result |= SaveKeyringResult.SAVED_SECRET; - } - } - - return new SaveKeyringResult(result, mLog, canSecretRing); - } catch (IOException e) { - log(LogType.MSG_IP_ERROR_IO_EXC); - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } finally { - mIndent -= 1; - } - } - - public SaveKeyringResult savePublicKeyRing(UncachedKeyRing publicRing, Progressable progress, - String expectedFingerprint) { - return savePublicKeyRing(publicRing, progress, expectedFingerprint, null, false); - } - - public SaveKeyringResult savePublicKeyRing(UncachedKeyRing keyRing) { - return savePublicKeyRing(keyRing, new ProgressScaler(), null); - } - - public SaveKeyringResult saveSecretKeyRing(UncachedKeyRing secretRing, Progressable progress, - ArrayList canKeyRings, - boolean skipSave) { - - try { - long masterKeyId = secretRing.getMasterKeyId(); - log(LogType.MSG_IS, KeyFormattingUtils.convertKeyIdToHex(masterKeyId)); - mIndent += 1; - - if (!secretRing.isSecret()) { - log(LogType.MSG_IS_BAD_TYPE_PUBLIC); - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } - - CanonicalizedSecretKeyRing canSecretRing; - boolean alreadyExists = false; - - // If there is an old secret key, merge it. - try { - UncachedKeyRing oldSecretRing = getCanonicalizedSecretKeyRing(masterKeyId).getUncachedKeyRing(); - alreadyExists = true; - - // Merge data from new secret ring into old one - log(LogType.MSG_IS_MERGE_SECRET); - secretRing = secretRing.merge(oldSecretRing, mLog, mIndent); - - // If this is null, there is an error in the log so we can just return - if (secretRing == null) { - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } - - // Canonicalize this keyring, to assert a number of assumptions made about it. - // This is a safe cast, because we made sure this is a secret ring above - canSecretRing = (CanonicalizedSecretKeyRing) secretRing.canonicalize(mLog, mIndent); - if (canSecretRing == null) { - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } - if (canKeyRings != null) canKeyRings.add(canSecretRing); - - // Early breakout if nothing changed - if (Arrays.hashCode(secretRing.getEncoded()) - == Arrays.hashCode(oldSecretRing.getEncoded())) { - log(LogType.MSG_IS_SUCCESS_IDENTICAL, - KeyFormattingUtils.convertKeyIdToHex(masterKeyId)); - return new SaveKeyringResult(SaveKeyringResult.UPDATED, mLog, null); - } - } catch (NotFoundException e) { - // Not an issue, just means we are dealing with a new keyring - - // Canonicalize this keyring, to assert a number of assumptions made about it. - // This is a safe cast, because we made sure this is a secret ring above - canSecretRing = (CanonicalizedSecretKeyRing) secretRing.canonicalize(mLog, mIndent); - if (canSecretRing == null) { - - // Special case: If keyring canonicalization failed, try again after adding - // all self-certificates from the public key. - try { - log(LogType.MSG_IS_MERGE_SPECIAL); - UncachedKeyRing oldPublicRing = getCanonicalizedPublicKeyRing(masterKeyId).getUncachedKeyRing(); - secretRing = secretRing.merge(oldPublicRing, mLog, mIndent); - canSecretRing = (CanonicalizedSecretKeyRing) secretRing.canonicalize(mLog, mIndent); - } catch (NotFoundException e2) { - // nothing, this is handled right in the next line - } - - if (canSecretRing == null) { - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } - } - if (canKeyRings != null) canKeyRings.add(canSecretRing); - } - - // Merge new data into public keyring as well, if there is any - UncachedKeyRing publicRing; - try { - UncachedKeyRing oldPublicRing = getCanonicalizedPublicKeyRing(masterKeyId).getUncachedKeyRing(); - - // Merge data from new secret ring into public one - log(LogType.MSG_IS_MERGE_PUBLIC); - publicRing = oldPublicRing.merge(secretRing, mLog, mIndent); - if (publicRing == null) { - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } - - } catch (NotFoundException e) { - log(LogType.MSG_IS_PUBRING_GENERATE); - publicRing = secretRing.extractPublicKeyRing(); - } - - CanonicalizedPublicKeyRing canPublicRing = (CanonicalizedPublicKeyRing) publicRing.canonicalize(mLog, - mIndent); - if (canPublicRing == null) { - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } - - int publicResult; - if (skipSave) { - // skip save method, set fixed result - publicResult = SaveKeyringResult.SAVED_PUBLIC; - } else { - publicResult = saveCanonicalizedPublicKeyRing(canPublicRing, progress, true); - } - - if ((publicResult & SaveKeyringResult.RESULT_ERROR) == SaveKeyringResult.RESULT_ERROR) { - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } - - progress.setProgress(LogType.MSG_IP_REINSERT_SECRET.getMsgId(), 90, 100); - - int result; - if (skipSave) { - // skip save method, set fixed result - result = SaveKeyringResult.SAVED_SECRET - | (alreadyExists ? SaveKeyringResult.UPDATED : 0); - } else { - result = saveCanonicalizedSecretKeyRing(canSecretRing); - } - - return new SaveKeyringResult(result, mLog, canSecretRing); - } catch (IOException e) { - log(LogType.MSG_IS_ERROR_IO_EXC); - return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); - } finally { - mIndent -= 1; - } - } - - public SaveKeyringResult saveSecretKeyRing(UncachedKeyRing secretRing, Progressable progress) { - return saveSecretKeyRing(secretRing, progress, null, false); - } - - @NonNull - public ConsolidateResult consolidateDatabaseStep1(Progressable progress) { - - OperationLog log = new OperationLog(); - int indent = 0; - - // 1a. fetch all secret keyrings into a cache file - log.add(LogType.MSG_CON, indent); - indent += 1; - - if (mConsolidateCritical) { - log.add(LogType.MSG_CON_RECURSIVE, indent); - return new ConsolidateResult(ConsolidateResult.RESULT_OK, log); - } - - 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); - indent += 1; - - final Cursor cursor = mContentResolver.query(KeyRingData.buildSecretKeyRingUri(), - new String[]{KeyRingData.KEY_RING_DATA}, null, null, null); - - 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() { - ParcelableKeyRing ring; - - @Override - public boolean hasNext() { - if (ring != null) { - return true; - } - if (cursor.isAfterLast()) { - return false; - } - ring = new ParcelableKeyRing(cursor.getBlob(0)); - cursor.moveToNext(); - return true; - } - - @Override - public ParcelableKeyRing next() { - try { - return ring; - } finally { - ring = null; - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - }); - cursor.close(); - - } catch (IOException e) { - Log.e(Constants.TAG, "error saving secret", e); - log.add(LogType.MSG_CON_ERROR_IO_SECRET, indent); - return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); - } finally { - indent -= 1; - } - - progress.setProgress(R.string.progress_con_saving, 3, 100); - - // 1b. fetch all public keyrings into a cache file - try { - - log.add(LogType.MSG_CON_SAVE_PUBLIC, indent); - indent += 1; - - final Cursor cursor = mContentResolver.query( - KeyRingData.buildPublicKeyRingUri(), - new String[]{KeyRingData.KEY_RING_DATA}, null, null, null); - - 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() { - ParcelableKeyRing ring; - - @Override - public boolean hasNext() { - if (ring != null) { - return true; - } - if (cursor.isAfterLast()) { - return false; - } - ring = new ParcelableKeyRing(cursor.getBlob(0)); - cursor.moveToNext(); - return true; - } - - @Override - public ParcelableKeyRing next() { - try { - return ring; - } finally { - ring = null; - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - }); - cursor.close(); - - } catch (IOException e) { - Log.e(Constants.TAG, "error saving public", e); - log.add(LogType.MSG_CON_ERROR_IO_PUBLIC, indent); - return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); - } finally { - indent -= 1; - } - - log.add(LogType.MSG_CON_CRITICAL_IN, indent); - Preferences.getPreferences(mContext).setCachedConsolidate(true); - - return consolidateDatabaseStep2(log, indent, progress, false); - } - - @NonNull - public ConsolidateResult consolidateDatabaseStep2(Progressable progress) { - return consolidateDatabaseStep2(new OperationLog(), 0, progress, true); - } - - private static boolean mConsolidateCritical = false; - - @NonNull - private ConsolidateResult consolidateDatabaseStep2( - OperationLog log, int indent, Progressable progress, boolean recovery) { - - synchronized (DatabaseInteractor.class) { - if (mConsolidateCritical) { - log.add(LogType.MSG_CON_ERROR_CONCURRENT, indent); - return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); - } - mConsolidateCritical = true; - } - - try { - Preferences prefs = Preferences.getPreferences(mContext); - - if (recovery) { - log.add(LogType.MSG_CON_RECOVER, indent); - indent += 1; - } - - if (!prefs.getCachedConsolidate()) { - log.add(LogType.MSG_CON_ERROR_BAD_STATE, indent); - return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); - } - - // 2. wipe database (IT'S DANGEROUS) - - // first, backup our list of updated key times - ArrayList updatedKeysValues = new ArrayList<>(); - final int INDEX_MASTER_KEY_ID = 0; - final int INDEX_LAST_UPDATED = 1; - Cursor lastUpdatedCursor = mContentResolver.query( - UpdatedKeys.CONTENT_URI, - new String[]{ - UpdatedKeys.MASTER_KEY_ID, - UpdatedKeys.LAST_UPDATED - }, - null, null, null); - while (lastUpdatedCursor.moveToNext()) { - ContentValues values = new ContentValues(); - values.put(UpdatedKeys.MASTER_KEY_ID, - lastUpdatedCursor.getLong(INDEX_MASTER_KEY_ID)); - values.put(UpdatedKeys.LAST_UPDATED, - lastUpdatedCursor.getLong(INDEX_LAST_UPDATED)); - updatedKeysValues.add(values); - } - lastUpdatedCursor.close(); - - log.add(LogType.MSG_CON_DB_CLEAR, indent); - mContentResolver.delete(KeyRings.buildUnifiedKeyRingsUri(), null, null); - - ParcelableFileCache cacheSecret, cachePublic; - - // Set flag that we have a cached consolidation here - try { - cacheSecret = new ParcelableFileCache<>(mContext, "consolidate_secret.pcl"); - IteratorWithSize itSecrets = cacheSecret.readCache(false); - int numSecrets = itSecrets.getSize(); - - log.add(LogType.MSG_CON_REIMPORT_SECRET, indent, numSecrets); - indent += 1; - - // 3. Re-Import secret keyrings from cache - if (numSecrets > 0) { - - ImportKeyResult result = new ImportOperation(mContext, this, - new ProgressFixedScaler(progress, 10, 25, 100, R.string.progress_con_reimport)) - .serialKeyRingImport(itSecrets, numSecrets, null, null, false); - log.add(result, indent); - } else { - log.add(LogType.MSG_CON_REIMPORT_SECRET_SKIP, indent); - } - - } catch (IOException e) { - Log.e(Constants.TAG, "error importing secret", e); - log.add(LogType.MSG_CON_ERROR_SECRET, indent); - return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); - } finally { - indent -= 1; - } - - try { - - cachePublic = new ParcelableFileCache<>(mContext, "consolidate_public.pcl"); - IteratorWithSize itPublics = cachePublic.readCache(); - int numPublics = itPublics.getSize(); - - log.add(LogType.MSG_CON_REIMPORT_PUBLIC, indent, numPublics); - indent += 1; - - // 4. Re-Import public keyrings from cache - if (numPublics > 0) { - - ImportKeyResult result = new ImportOperation(mContext, this, - new ProgressFixedScaler(progress, 25, 99, 100, R.string.progress_con_reimport)) - .serialKeyRingImport(itPublics, numPublics, null, null, false); - log.add(result, indent); - // re-insert our backed up list of updated key times - // TODO: can this cause issues in case a public key re-import failed? - mContentResolver.bulkInsert(UpdatedKeys.CONTENT_URI, - updatedKeysValues.toArray(new ContentValues[updatedKeysValues.size()])); - } else { - log.add(LogType.MSG_CON_REIMPORT_PUBLIC_SKIP, indent); - } - - } catch (IOException e) { - Log.e(Constants.TAG, "error importing public", e); - log.add(LogType.MSG_CON_ERROR_PUBLIC, indent); - return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); - } finally { - indent -= 1; - } - - log.add(LogType.MSG_CON_CRITICAL_OUT, indent); - Preferences.getPreferences(mContext).setCachedConsolidate(false); - - // 5. Delete caches - try { - log.add(LogType.MSG_CON_DELETE_SECRET, indent); - indent += 1; - cacheSecret.delete(); - } catch (IOException e) { - // doesn't /really/ matter - Log.e(Constants.TAG, "IOException during delete of secret cache", e); - log.add(LogType.MSG_CON_WARN_DELETE_SECRET, indent); - } finally { - indent -= 1; - } - - try { - log.add(LogType.MSG_CON_DELETE_PUBLIC, indent); - indent += 1; - cachePublic.delete(); - } catch (IOException e) { - // doesn't /really/ matter - Log.e(Constants.TAG, "IOException during deletion of public cache", e); - log.add(LogType.MSG_CON_WARN_DELETE_PUBLIC, indent); - } finally { - indent -= 1; - } - - progress.setProgress(100, 100); - log.add(LogType.MSG_CON_SUCCESS, indent); - - return new ConsolidateResult(ConsolidateResult.RESULT_OK, log); - - } finally { - mConsolidateCritical = false; - } - - } - - /** - * Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing - */ - private ContentProviderOperation - buildCertOperations(long masterKeyId, int rank, WrappedSignature cert, int verified) - throws IOException { - ContentValues values = new ContentValues(); - values.put(Certs.MASTER_KEY_ID, masterKeyId); - values.put(Certs.RANK, rank); - values.put(Certs.KEY_ID_CERTIFIER, cert.getKeyId()); - values.put(Certs.TYPE, cert.getSignatureType()); - values.put(Certs.CREATION, cert.getCreationTime().getTime() / 1000); - values.put(Certs.VERIFIED, verified); - values.put(Certs.DATA, cert.getEncoded()); - - Uri uri = Certs.buildCertsUri(masterKeyId); - - return ContentProviderOperation.newInsert(uri).withValues(values).build(); - } - - /** - * Build ContentProviderOperation to add PublicUserIds to database corresponding to a keyRing - */ - private ContentProviderOperation - buildUserIdOperations(long masterKeyId, UserPacketItem item, int rank) { - ContentValues values = new ContentValues(); - values.put(UserPackets.MASTER_KEY_ID, masterKeyId); - values.put(UserPackets.TYPE, item.type); - values.put(UserPackets.USER_ID, item.userId); - values.put(UserPackets.NAME, item.name); - values.put(UserPackets.EMAIL, item.email); - values.put(UserPackets.COMMENT, item.comment); - values.put(UserPackets.ATTRIBUTE_DATA, item.attributeData); - values.put(UserPackets.IS_PRIMARY, item.isPrimary); - values.put(UserPackets.IS_REVOKED, item.selfRevocation != null); - values.put(UserPackets.RANK, rank); - - Uri uri = UserPackets.buildUserIdsUri(masterKeyId); - - return ContentProviderOperation.newInsert(uri).withValues(values).build(); - } - private String getKeyRingAsArmoredString(byte[] data) throws IOException, PgpGeneralException { UncachedKeyRing keyRing = UncachedKeyRing.decodeFromData(data); @@ -1540,19 +230,20 @@ public class DatabaseInteractor { public String getKeyRingAsArmoredString(Uri uri) throws NotFoundException, IOException, PgpGeneralException { byte[] data = (byte[]) getGenericData( - uri, KeyRingData.KEY_RING_DATA, DatabaseInteractor.FIELD_TYPE_BLOB); + uri, KeyRingData.KEY_RING_DATA, FIELD_TYPE_BLOB); return getKeyRingAsArmoredString(data); } - public Uri renewKeyLastUpdatedTime(long masterKeyId, long time, TimeUnit timeUnit) { - ContentValues values = new ContentValues(); - values.put(UpdatedKeys.MASTER_KEY_ID, masterKeyId); - values.put(UpdatedKeys.LAST_UPDATED, timeUnit.toSeconds(time)); - - return mContentResolver.insert(UpdatedKeys.CONTENT_URI, values); - } - public ContentResolver getContentResolver() { return mContentResolver; } + + public static class NotFoundException extends Exception { + public NotFoundException() { + } + + public NotFoundException(String name) { + super(name); + } + } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java new file mode 100644 index 000000000..d9b0a1f3f --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java @@ -0,0 +1,1345 @@ +/* + * Copyright (C) 2012-2014 Dominik Schürmann + * Copyright (C) 2014 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.provider; + + +import android.content.ContentProviderOperation; +import android.content.ContentValues; +import android.content.Context; +import android.content.OperationApplicationException; +import android.database.Cursor; +import android.net.Uri; +import android.os.RemoteException; +import android.support.annotation.NonNull; +import android.support.v4.util.LongSparseArray; + +import org.openintents.openpgp.util.OpenPgpUtils; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; +import org.sufficientlysecure.keychain.operations.ImportOperation; +import org.sufficientlysecure.keychain.operations.results.ConsolidateResult; +import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; +import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; +import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; +import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKey; +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.KeyRing; +import org.sufficientlysecure.keychain.pgp.Progressable; +import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; +import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; +import org.sufficientlysecure.keychain.pgp.WrappedSignature; +import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; +import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; +import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; +import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; +import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; +import org.sufficientlysecure.keychain.provider.KeychainContract.UpdatedKeys; +import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; +import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; +import org.sufficientlysecure.keychain.util.IterableIterator; +import org.sufficientlysecure.keychain.util.IteratorWithSize; +import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.ParcelableFileCache; +import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.ProgressFixedScaler; +import org.sufficientlysecure.keychain.util.ProgressScaler; +import org.sufficientlysecure.keychain.util.Utf8Util; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** + * This class contains high level methods for database access. Despite its + * name, it is not only a helper but actually the main interface for all + * synchronous database operations. + *

+ * Operations in this class write logs. These can be obtained from the + * OperationResultParcel return values directly, but are also accumulated over + * the lifetime of the executing ProviderHelper object unless the resetLog() + * method is called to start a new one specifically. + */ +public class DatabaseReadWriteInteractor extends DatabaseInteractor { + private final Context mContext; + + public DatabaseReadWriteInteractor(Context context) { + this(context, new OperationLog(), 0); + } + + public DatabaseReadWriteInteractor(Context context, OperationLog log) { + this(context, log, 0); + } + + public DatabaseReadWriteInteractor(Context context, OperationLog log, int indent) { + super(context.getContentResolver(), log, indent); + + mContext = context; + } + + private LongSparseArray getTrustedMasterKeys() { + Cursor cursor = mContentResolver.query(KeyRings.buildUnifiedKeyRingsUri(), new String[]{ + KeyRings.MASTER_KEY_ID, + // we pick from cache only information that is not easily available from keyrings + KeyRings.HAS_ANY_SECRET, KeyRings.VERIFIED, + // and of course, ring data + KeyRings.PUBKEY_DATA + }, KeyRings.HAS_ANY_SECRET + " = 1", null, null); + + try { + LongSparseArray result = new LongSparseArray<>(); + + if (cursor != null && cursor.moveToFirst()) do { + long masterKeyId = cursor.getLong(0); + int verified = cursor.getInt(2); + byte[] blob = cursor.getBlob(3); + if (blob != null) { + result.put(masterKeyId, + new CanonicalizedPublicKeyRing(blob, verified).getPublicKey()); + } + } while (cursor.moveToNext()); + + return result; + + } finally { + if (cursor != null) { + cursor.close(); + } + } + + } + + // bits, in order: CESA. make SURE these are correct, we will get bad log entries otherwise!! + private static final LogType LOG_TYPES_FLAG_MASTER[] = new LogType[]{ + LogType.MSG_IP_MASTER_FLAGS_XXXX, LogType.MSG_IP_MASTER_FLAGS_CXXX, + LogType.MSG_IP_MASTER_FLAGS_XEXX, LogType.MSG_IP_MASTER_FLAGS_CEXX, + LogType.MSG_IP_MASTER_FLAGS_XXSX, LogType.MSG_IP_MASTER_FLAGS_CXSX, + LogType.MSG_IP_MASTER_FLAGS_XESX, LogType.MSG_IP_MASTER_FLAGS_CESX, + LogType.MSG_IP_MASTER_FLAGS_XXXA, LogType.MSG_IP_MASTER_FLAGS_CXXA, + LogType.MSG_IP_MASTER_FLAGS_XEXA, LogType.MSG_IP_MASTER_FLAGS_CEXA, + LogType.MSG_IP_MASTER_FLAGS_XXSA, LogType.MSG_IP_MASTER_FLAGS_CXSA, + LogType.MSG_IP_MASTER_FLAGS_XESA, LogType.MSG_IP_MASTER_FLAGS_CESA + }; + + // same as above, but for subkeys + private static final LogType LOG_TYPES_FLAG_SUBKEY[] = new LogType[]{ + LogType.MSG_IP_SUBKEY_FLAGS_XXXX, LogType.MSG_IP_SUBKEY_FLAGS_CXXX, + LogType.MSG_IP_SUBKEY_FLAGS_XEXX, LogType.MSG_IP_SUBKEY_FLAGS_CEXX, + LogType.MSG_IP_SUBKEY_FLAGS_XXSX, LogType.MSG_IP_SUBKEY_FLAGS_CXSX, + LogType.MSG_IP_SUBKEY_FLAGS_XESX, LogType.MSG_IP_SUBKEY_FLAGS_CESX, + LogType.MSG_IP_SUBKEY_FLAGS_XXXA, LogType.MSG_IP_SUBKEY_FLAGS_CXXA, + LogType.MSG_IP_SUBKEY_FLAGS_XEXA, LogType.MSG_IP_SUBKEY_FLAGS_CEXA, + LogType.MSG_IP_SUBKEY_FLAGS_XXSA, LogType.MSG_IP_SUBKEY_FLAGS_CXSA, + LogType.MSG_IP_SUBKEY_FLAGS_XESA, LogType.MSG_IP_SUBKEY_FLAGS_CESA + }; + + /** + * Saves an UncachedKeyRing of the public variant into the db. + *

+ * This method will not delete all previous data for this masterKeyId from the database prior + * to inserting. All public data is effectively re-inserted, secret keyrings are left deleted + * and need to be saved externally to be preserved past the operation. + */ + @SuppressWarnings("unchecked") + private int saveCanonicalizedPublicKeyRing(CanonicalizedPublicKeyRing keyRing, + Progressable progress, boolean selfCertsAreTrusted) { + + // start with ok result + int result = SaveKeyringResult.SAVED_PUBLIC; + + long masterKeyId = keyRing.getMasterKeyId(); + UncachedPublicKey masterKey = keyRing.getPublicKey(); + + ArrayList operations; + try { + + log(LogType.MSG_IP_PREPARE); + mIndent += 1; + + // save all keys and userIds included in keyRing object in database + operations = new ArrayList<>(); + + log(LogType.MSG_IP_INSERT_KEYRING); + { // insert keyring + ContentValues values = new ContentValues(); + values.put(KeyRingData.MASTER_KEY_ID, masterKeyId); + try { + values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded()); + } catch (IOException e) { + log(LogType.MSG_IP_ENCODE_FAIL); + return SaveKeyringResult.RESULT_ERROR; + } + + Uri uri = KeyRingData.buildPublicKeyRingUri(masterKeyId); + operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build()); + } + + log(LogType.MSG_IP_INSERT_SUBKEYS); + progress.setProgress(LogType.MSG_IP_INSERT_SUBKEYS.getMsgId(), 40, 100); + mIndent += 1; + { // insert subkeys + Uri uri = Keys.buildKeysUri(masterKeyId); + int rank = 0; + for (CanonicalizedPublicKey key : keyRing.publicKeyIterator()) { + long keyId = key.getKeyId(); + log(keyId == masterKeyId ? LogType.MSG_IP_MASTER : LogType.MSG_IP_SUBKEY, + KeyFormattingUtils.convertKeyIdToHex(keyId) + ); + mIndent += 1; + + ContentValues values = new ContentValues(); + values.put(Keys.MASTER_KEY_ID, masterKeyId); + values.put(Keys.RANK, rank); + + values.put(Keys.KEY_ID, key.getKeyId()); + values.put(Keys.KEY_SIZE, key.getBitStrength()); + values.put(Keys.KEY_CURVE_OID, key.getCurveOid()); + values.put(Keys.ALGORITHM, key.getAlgorithm()); + values.put(Keys.FINGERPRINT, key.getFingerprint()); + + boolean c = key.canCertify(), e = key.canEncrypt(), s = key.canSign(), a = key.canAuthenticate(); + values.put(Keys.CAN_CERTIFY, c); + values.put(Keys.CAN_ENCRYPT, e); + values.put(Keys.CAN_SIGN, s); + values.put(Keys.CAN_AUTHENTICATE, a); + values.put(Keys.IS_REVOKED, key.isRevoked()); + values.put(Keys.IS_SECURE, key.isSecure()); + + // see above + if (masterKeyId == keyId) { + if (key.getKeyUsage() == null) { + log(LogType.MSG_IP_MASTER_FLAGS_UNSPECIFIED); + } else { + log(LOG_TYPES_FLAG_MASTER[(c ? 1 : 0) + (e ? 2 : 0) + (s ? 4 : 0) + (a ? 8 : 0)]); + } + } else { + if (key.getKeyUsage() == null) { + log(LogType.MSG_IP_SUBKEY_FLAGS_UNSPECIFIED); + } else { + log(LOG_TYPES_FLAG_SUBKEY[(c ? 1 : 0) + (e ? 2 : 0) + (s ? 4 : 0) + (a ? 8 : 0)]); + } + } + + Date creation = key.getCreationTime(); + values.put(Keys.CREATION, creation.getTime() / 1000); + Date expiryDate = key.getExpiryTime(); + if (expiryDate != null) { + values.put(Keys.EXPIRY, expiryDate.getTime() / 1000); + if (key.isExpired()) { + log(keyId == masterKeyId ? + LogType.MSG_IP_MASTER_EXPIRED : LogType.MSG_IP_SUBKEY_EXPIRED, + expiryDate.toString()); + } else { + log(keyId == masterKeyId ? + LogType.MSG_IP_MASTER_EXPIRES : LogType.MSG_IP_SUBKEY_EXPIRES, + expiryDate.toString()); + } + } + + operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build()); + ++rank; + mIndent -= 1; + } + } + mIndent -= 1; + + // get a list of owned secret keys, for verification filtering + LongSparseArray trustedKeys = getTrustedMasterKeys(); + + // classify and order user ids. primary are moved to the front, revoked to the back, + // otherwise the order in the keyfile is preserved. + List uids = new ArrayList<>(); + + if (trustedKeys.size() == 0) { + log(LogType.MSG_IP_UID_CLASSIFYING_ZERO); + } else { + log(LogType.MSG_IP_UID_CLASSIFYING, trustedKeys.size()); + } + mIndent += 1; + for (byte[] rawUserId : masterKey.getUnorderedRawUserIds()) { + String userId = Utf8Util.fromUTF8ByteArrayReplaceBadEncoding(rawUserId); + UserPacketItem item = new UserPacketItem(); + uids.add(item); + OpenPgpUtils.UserId splitUserId = KeyRing.splitUserId(userId); + item.userId = userId; + item.name = splitUserId.name; + item.email = splitUserId.email; + item.comment = splitUserId.comment; + int unknownCerts = 0; + + log(LogType.MSG_IP_UID_PROCESSING, userId); + mIndent += 1; + // look through signatures for this specific key + for (WrappedSignature cert : new IterableIterator<>( + masterKey.getSignaturesForRawId(rawUserId))) { + long certId = cert.getKeyId(); + // self signature + if (certId == masterKeyId) { + + // NOTE self-certificates are already verified during canonicalization, + // AND we know there is at most one cert plus at most one revocation + if (!cert.isRevocation()) { + item.selfCert = cert; + item.isPrimary = cert.isPrimaryUserId(); + } else { + item.selfRevocation = cert; + log(LogType.MSG_IP_UID_REVOKED); + } + continue; + + } + + // do we have a trusted key for this? + if (trustedKeys.indexOfKey(certId) < 0) { + unknownCerts += 1; + continue; + } + + // verify signatures from known private keys + CanonicalizedPublicKey trustedKey = trustedKeys.get(certId); + + try { + cert.init(trustedKey); + // if it doesn't certify, leave a note and skip + if (!cert.verifySignature(masterKey, rawUserId)) { + log(LogType.MSG_IP_UID_CERT_BAD); + continue; + } + + log(cert.isRevocation() + ? LogType.MSG_IP_UID_CERT_GOOD_REVOKE + : LogType.MSG_IP_UID_CERT_GOOD, + KeyFormattingUtils.convertKeyIdToHexShort(trustedKey.getKeyId()) + ); + + // check if there is a previous certificate + WrappedSignature prev = item.trustedCerts.get(cert.getKeyId()); + if (prev != null) { + // if it's newer, skip this one + if (prev.getCreationTime().after(cert.getCreationTime())) { + log(LogType.MSG_IP_UID_CERT_OLD); + continue; + } + // if the previous one was a non-revokable certification, no need to look further + if (!prev.isRevocation() && !prev.isRevokable()) { + log(LogType.MSG_IP_UID_CERT_NONREVOKE); + continue; + } + log(LogType.MSG_IP_UID_CERT_NEW); + } + item.trustedCerts.put(cert.getKeyId(), cert); + + } catch (PgpGeneralException e) { + log(LogType.MSG_IP_UID_CERT_ERROR, + KeyFormattingUtils.convertKeyIdToHex(cert.getKeyId())); + } + + } + + if (unknownCerts > 0) { + log(LogType.MSG_IP_UID_CERTS_UNKNOWN, unknownCerts); + } + mIndent -= 1; + + } + mIndent -= 1; + + ArrayList userAttributes = masterKey.getUnorderedUserAttributes(); + // Don't spam the log if there aren't even any attributes + if (!userAttributes.isEmpty()) { + log(LogType.MSG_IP_UAT_CLASSIFYING); + } + + mIndent += 1; + for (WrappedUserAttribute userAttribute : userAttributes) { + + UserPacketItem item = new UserPacketItem(); + uids.add(item); + item.type = userAttribute.getType(); + item.attributeData = userAttribute.getEncoded(); + + int unknownCerts = 0; + + switch (item.type) { + case WrappedUserAttribute.UAT_IMAGE: + log(LogType.MSG_IP_UAT_PROCESSING_IMAGE); + break; + default: + log(LogType.MSG_IP_UAT_PROCESSING_UNKNOWN); + break; + } + mIndent += 1; + // look through signatures for this specific key + for (WrappedSignature cert : new IterableIterator<>( + masterKey.getSignaturesForUserAttribute(userAttribute))) { + long certId = cert.getKeyId(); + // self signature + if (certId == masterKeyId) { + + // NOTE self-certificates are already verified during canonicalization, + // AND we know there is at most one cert plus at most one revocation + // AND the revocation only exists if there is no newer certification + if (!cert.isRevocation()) { + item.selfCert = cert; + } else { + item.selfRevocation = cert; + log(LogType.MSG_IP_UAT_REVOKED); + } + continue; + + } + + // do we have a trusted key for this? + if (trustedKeys.indexOfKey(certId) < 0) { + unknownCerts += 1; + continue; + } + + // verify signatures from known private keys + CanonicalizedPublicKey trustedKey = trustedKeys.get(certId); + + try { + cert.init(trustedKey); + // if it doesn't certify, leave a note and skip + if (!cert.verifySignature(masterKey, userAttribute)) { + log(LogType.MSG_IP_UAT_CERT_BAD); + continue; + } + + log(cert.isRevocation() + ? LogType.MSG_IP_UAT_CERT_GOOD_REVOKE + : LogType.MSG_IP_UAT_CERT_GOOD, + KeyFormattingUtils.convertKeyIdToHexShort(trustedKey.getKeyId()) + ); + + // check if there is a previous certificate + WrappedSignature prev = item.trustedCerts.get(cert.getKeyId()); + if (prev != null) { + // if it's newer, skip this one + if (prev.getCreationTime().after(cert.getCreationTime())) { + log(LogType.MSG_IP_UAT_CERT_OLD); + continue; + } + // if the previous one was a non-revokable certification, no need to look further + if (!prev.isRevocation() && !prev.isRevokable()) { + log(LogType.MSG_IP_UAT_CERT_NONREVOKE); + continue; + } + log(LogType.MSG_IP_UAT_CERT_NEW); + } + item.trustedCerts.put(cert.getKeyId(), cert); + + } catch (PgpGeneralException e) { + log(LogType.MSG_IP_UAT_CERT_ERROR, + KeyFormattingUtils.convertKeyIdToHex(cert.getKeyId())); + } + + } + + if (unknownCerts > 0) { + log(LogType.MSG_IP_UAT_CERTS_UNKNOWN, unknownCerts); + } + mIndent -= 1; + + } + mIndent -= 1; + + progress.setProgress(LogType.MSG_IP_UID_REORDER.getMsgId(), 65, 100); + log(LogType.MSG_IP_UID_REORDER); + // primary before regular before revoked (see UserIdItem.compareTo) + // this is a stable sort, so the order of keys is otherwise preserved. + Collections.sort(uids); + // iterate and put into db + for (int userIdRank = 0; userIdRank < uids.size(); userIdRank++) { + UserPacketItem item = uids.get(userIdRank); + operations.add(buildUserIdOperations(masterKeyId, item, userIdRank)); + + if (item.selfRevocation != null) { + operations.add(buildCertOperations(masterKeyId, userIdRank, item.selfRevocation, + Certs.VERIFIED_SELF)); + // don't bother with trusted certs if the uid is revoked, anyways + continue; + } + + if (item.selfCert == null) { + throw new AssertionError("User ids MUST be self-certified at this point!!"); + } + + operations.add(buildCertOperations(masterKeyId, userIdRank, item.selfCert, + selfCertsAreTrusted ? Certs.VERIFIED_SECRET : Certs.VERIFIED_SELF)); + + // iterate over signatures + for (int i = 0; i < item.trustedCerts.size(); i++) { + WrappedSignature sig = item.trustedCerts.valueAt(i); + // if it's a revocation + if (sig.isRevocation()) { + // don't further process it + continue; + } + // otherwise, build database operation + operations.add(buildCertOperations( + masterKeyId, userIdRank, sig, Certs.VERIFIED_SECRET)); + } + } + + } catch (IOException e) { + log(LogType.MSG_IP_ERROR_IO_EXC); + Log.e(Constants.TAG, "IOException during import", e); + return SaveKeyringResult.RESULT_ERROR; + } finally { + mIndent -= 1; + } + + // before deleting key, retrieve it's last updated time + final int INDEX_MASTER_KEY_ID = 0; + final int INDEX_LAST_UPDATED = 1; + Cursor lastUpdatedCursor = mContentResolver.query( + UpdatedKeys.CONTENT_URI, + new String[]{ + UpdatedKeys.MASTER_KEY_ID, + UpdatedKeys.LAST_UPDATED + }, + UpdatedKeys.MASTER_KEY_ID + " = ?", + new String[]{"" + masterKeyId}, + null + ); + if (lastUpdatedCursor.moveToNext()) { + // there was an entry to re-insert + // this operation must happen after the new key is inserted + ContentValues lastUpdatedEntry = new ContentValues(2); + lastUpdatedEntry.put(UpdatedKeys.MASTER_KEY_ID, + lastUpdatedCursor.getLong(INDEX_MASTER_KEY_ID)); + lastUpdatedEntry.put(UpdatedKeys.LAST_UPDATED, + lastUpdatedCursor.getLong(INDEX_LAST_UPDATED)); + operations.add( + ContentProviderOperation + .newInsert(UpdatedKeys.CONTENT_URI) + .withValues(lastUpdatedEntry) + .build() + ); + } + lastUpdatedCursor.close(); + + try { + // delete old version of this keyRing, which also deletes all keys and userIds on cascade + int deleted = mContentResolver.delete( + KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null); + if (deleted > 0) { + log(LogType.MSG_IP_DELETE_OLD_OK); + result |= SaveKeyringResult.UPDATED; + } else { + log(LogType.MSG_IP_DELETE_OLD_FAIL); + } + + log(LogType.MSG_IP_APPLY_BATCH); + progress.setProgress(LogType.MSG_IP_APPLY_BATCH.getMsgId(), 75, 100); + mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations); + + log(LogType.MSG_IP_SUCCESS); + progress.setProgress(LogType.MSG_IP_SUCCESS.getMsgId(), 90, 100); + return result; + + } catch (RemoteException e) { + log(LogType.MSG_IP_ERROR_REMOTE_EX); + Log.e(Constants.TAG, "RemoteException during import", e); + return SaveKeyringResult.RESULT_ERROR; + } catch (OperationApplicationException e) { + log(LogType.MSG_IP_ERROR_OP_EXC); + Log.e(Constants.TAG, "OperationApplicationException during import", e); + return SaveKeyringResult.RESULT_ERROR; + } + + } + + private static class UserPacketItem implements Comparable { + Integer type; + String userId; + String name; + String email; + String comment; + byte[] attributeData; + boolean isPrimary = false; + WrappedSignature selfCert; + WrappedSignature selfRevocation; + LongSparseArray trustedCerts = new LongSparseArray<>(); + + @Override + public int compareTo(@NonNull UserPacketItem o) { + // revoked keys always come last! + //noinspection DoubleNegation + if ((selfRevocation != null) != (o.selfRevocation != null)) { + return selfRevocation != null ? 1 : -1; + } + // if one is a user id, but the other isn't, the user id always comes first. + // we compare for null values here, so != is the correct operator! + // noinspection NumberEquality + if (type != o.type) { + return type == null ? -1 : 1; + } + // if one is *trusted* but the other isn't, that one comes first + // this overrides the primary attribute, even! + if ((trustedCerts.size() == 0) != (o.trustedCerts.size() == 0)) { + return trustedCerts.size() > o.trustedCerts.size() ? -1 : 1; + } + // if one key is primary but the other isn't, the primary one always comes first + if (isPrimary != o.isPrimary) { + return isPrimary ? -1 : 1; + } + return 0; + } + } + + /** + * Saves an UncachedKeyRing of the secret variant into the db. + * This method will fail if no corresponding public keyring is in the database! + */ + private int saveCanonicalizedSecretKeyRing(CanonicalizedSecretKeyRing keyRing) { + + long masterKeyId = keyRing.getMasterKeyId(); + log(LogType.MSG_IS, KeyFormattingUtils.convertKeyIdToHex(masterKeyId)); + mIndent += 1; + + try { + + // IF this is successful, it's a secret key + int result = SaveKeyringResult.SAVED_SECRET; + + // save secret keyring + try { + ContentValues values = new ContentValues(); + values.put(KeyRingData.MASTER_KEY_ID, masterKeyId); + values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded()); + // insert new version of this keyRing + Uri uri = KeyRingData.buildSecretKeyRingUri(masterKeyId); + if (mContentResolver.insert(uri, values) == null) { + log(LogType.MSG_IS_DB_EXCEPTION); + return SaveKeyringResult.RESULT_ERROR; + } + } catch (IOException e) { + Log.e(Constants.TAG, "Failed to encode key!", e); + log(LogType.MSG_IS_ERROR_IO_EXC); + return SaveKeyringResult.RESULT_ERROR; + } + + { + Uri uri = Keys.buildKeysUri(masterKeyId); + + // first, mark all keys as not available + ContentValues values = new ContentValues(); + values.put(Keys.HAS_SECRET, SecretKeyType.GNU_DUMMY.getNum()); + mContentResolver.update(uri, values, null, null); + + // then, mark exactly the keys we have available + log(LogType.MSG_IS_IMPORTING_SUBKEYS); + mIndent += 1; + for (CanonicalizedSecretKey sub : keyRing.secretKeyIterator()) { + long id = sub.getKeyId(); + SecretKeyType mode = sub.getSecretKeyTypeSuperExpensive(); + values.put(Keys.HAS_SECRET, mode.getNum()); + int upd = mContentResolver.update(uri, values, Keys.KEY_ID + " = ?", + new String[]{Long.toString(id)}); + if (upd == 1) { + switch (mode) { + case PASSPHRASE: + log(LogType.MSG_IS_SUBKEY_OK, + KeyFormattingUtils.convertKeyIdToHex(id) + ); + break; + case PASSPHRASE_EMPTY: + log(LogType.MSG_IS_SUBKEY_EMPTY, + KeyFormattingUtils.convertKeyIdToHex(id) + ); + break; + case PIN: + log(LogType.MSG_IS_SUBKEY_PIN, + KeyFormattingUtils.convertKeyIdToHex(id) + ); + break; + case GNU_DUMMY: + log(LogType.MSG_IS_SUBKEY_STRIPPED, + KeyFormattingUtils.convertKeyIdToHex(id) + ); + break; + case DIVERT_TO_CARD: + log(LogType.MSG_IS_SUBKEY_DIVERT, + KeyFormattingUtils.convertKeyIdToHex(id) + ); + break; + } + } else { + log(LogType.MSG_IS_SUBKEY_NONEXISTENT, + KeyFormattingUtils.convertKeyIdToHex(id) + ); + } + } + mIndent -= 1; + + // this implicitly leaves all keys which were not in the secret key ring + // with has_secret = 1 + } + + log(LogType.MSG_IS_SUCCESS); + return result; + + } finally { + mIndent -= 1; + } + + } + + /** + * Save a public keyring into the database. + *

+ * This is a high level method, which takes care of merging all new information into the old and + * keep public and secret keyrings in sync. + *

+ * If you want to merge keys in-memory only and not save in database set skipSave=true. + */ + public SaveKeyringResult savePublicKeyRing(UncachedKeyRing publicRing, Progressable progress, + String expectedFingerprint, + ArrayList canKeyRings, + boolean skipSave) { + + try { + long masterKeyId = publicRing.getMasterKeyId(); + log(LogType.MSG_IP, KeyFormattingUtils.convertKeyIdToHex(masterKeyId)); + mIndent += 1; + + if (publicRing.isSecret()) { + log(LogType.MSG_IP_BAD_TYPE_SECRET); + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } + + CanonicalizedPublicKeyRing canPublicRing; + boolean alreadyExists = false; + + // If there is an old keyring, merge it + try { + UncachedKeyRing oldPublicRing = getCanonicalizedPublicKeyRing(masterKeyId).getUncachedKeyRing(); + alreadyExists = true; + + // Merge data from new public ring into the old one + log(LogType.MSG_IP_MERGE_PUBLIC); + publicRing = oldPublicRing.merge(publicRing, mLog, mIndent); + + // If this is null, there is an error in the log so we can just return + if (publicRing == null) { + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } + + // Canonicalize this keyring, to assert a number of assumptions made about it. + canPublicRing = (CanonicalizedPublicKeyRing) publicRing.canonicalize(mLog, mIndent); + if (canPublicRing == null) { + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } + if (canKeyRings != null) canKeyRings.add(canPublicRing); + + // Early breakout if nothing changed + if (Arrays.hashCode(publicRing.getEncoded()) + == Arrays.hashCode(oldPublicRing.getEncoded())) { + log(LogType.MSG_IP_SUCCESS_IDENTICAL); + return new SaveKeyringResult(SaveKeyringResult.UPDATED, mLog, null); + } + } catch (NotFoundException e) { + // Not an issue, just means we are dealing with a new keyring. + + // Canonicalize this keyring, to assert a number of assumptions made about it. + canPublicRing = (CanonicalizedPublicKeyRing) publicRing.canonicalize(mLog, mIndent); + if (canPublicRing == null) { + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } + if (canKeyRings != null) canKeyRings.add(canPublicRing); + } + + // If there is a secret key, merge new data (if any) and save the key for later + CanonicalizedSecretKeyRing canSecretRing; + try { + UncachedKeyRing secretRing = getCanonicalizedSecretKeyRing(publicRing.getMasterKeyId()) + .getUncachedKeyRing(); + + // Merge data from new public ring into secret one + log(LogType.MSG_IP_MERGE_SECRET); + secretRing = secretRing.merge(publicRing, mLog, mIndent); + if (secretRing == null) { + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } + // This has always been a secret key ring, this is a safe cast + canSecretRing = (CanonicalizedSecretKeyRing) secretRing.canonicalize(mLog, mIndent); + if (canSecretRing == null) { + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } + + } catch (NotFoundException e) { + // No secret key available (this is what happens most of the time) + canSecretRing = null; + } + + + // If we have an expected fingerprint, make sure it matches + if (expectedFingerprint != null) { + if (!canPublicRing.containsBoundSubkey(expectedFingerprint)) { + log(LogType.MSG_IP_FINGERPRINT_ERROR); + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } else { + log(LogType.MSG_IP_FINGERPRINT_OK); + } + } + + int result; + if (skipSave) { + // skip save method, set fixed result + result = SaveKeyringResult.SAVED_PUBLIC + | (alreadyExists ? SaveKeyringResult.UPDATED : 0); + } else { + result = saveCanonicalizedPublicKeyRing(canPublicRing, progress, canSecretRing != null); + } + + // Save the saved keyring (if any) + if (canSecretRing != null) { + progress.setProgress(LogType.MSG_IP_REINSERT_SECRET.getMsgId(), 90, 100); + + int secretResult; + if (skipSave) { + // skip save method, set fixed result + secretResult = SaveKeyringResult.SAVED_SECRET; + } else { + secretResult = saveCanonicalizedSecretKeyRing(canSecretRing); + } + + if ((secretResult & SaveKeyringResult.RESULT_ERROR) != SaveKeyringResult.RESULT_ERROR) { + result |= SaveKeyringResult.SAVED_SECRET; + } + } + + return new SaveKeyringResult(result, mLog, canSecretRing); + } catch (IOException e) { + log(LogType.MSG_IP_ERROR_IO_EXC); + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } finally { + mIndent -= 1; + } + } + + public SaveKeyringResult savePublicKeyRing(UncachedKeyRing publicRing, Progressable progress, + String expectedFingerprint) { + return savePublicKeyRing(publicRing, progress, expectedFingerprint, null, false); + } + + public SaveKeyringResult savePublicKeyRing(UncachedKeyRing keyRing) { + return savePublicKeyRing(keyRing, new ProgressScaler(), null); + } + + public SaveKeyringResult saveSecretKeyRing(UncachedKeyRing secretRing, Progressable progress, + ArrayList canKeyRings, + boolean skipSave) { + + try { + long masterKeyId = secretRing.getMasterKeyId(); + log(LogType.MSG_IS, KeyFormattingUtils.convertKeyIdToHex(masterKeyId)); + mIndent += 1; + + if (!secretRing.isSecret()) { + log(LogType.MSG_IS_BAD_TYPE_PUBLIC); + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } + + CanonicalizedSecretKeyRing canSecretRing; + boolean alreadyExists = false; + + // If there is an old secret key, merge it. + try { + UncachedKeyRing oldSecretRing = getCanonicalizedSecretKeyRing(masterKeyId).getUncachedKeyRing(); + alreadyExists = true; + + // Merge data from new secret ring into old one + log(LogType.MSG_IS_MERGE_SECRET); + secretRing = secretRing.merge(oldSecretRing, mLog, mIndent); + + // If this is null, there is an error in the log so we can just return + if (secretRing == null) { + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } + + // Canonicalize this keyring, to assert a number of assumptions made about it. + // This is a safe cast, because we made sure this is a secret ring above + canSecretRing = (CanonicalizedSecretKeyRing) secretRing.canonicalize(mLog, mIndent); + if (canSecretRing == null) { + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } + if (canKeyRings != null) canKeyRings.add(canSecretRing); + + // Early breakout if nothing changed + if (Arrays.hashCode(secretRing.getEncoded()) + == Arrays.hashCode(oldSecretRing.getEncoded())) { + log(LogType.MSG_IS_SUCCESS_IDENTICAL, + KeyFormattingUtils.convertKeyIdToHex(masterKeyId)); + return new SaveKeyringResult(SaveKeyringResult.UPDATED, mLog, null); + } + } catch (NotFoundException e) { + // Not an issue, just means we are dealing with a new keyring + + // Canonicalize this keyring, to assert a number of assumptions made about it. + // This is a safe cast, because we made sure this is a secret ring above + canSecretRing = (CanonicalizedSecretKeyRing) secretRing.canonicalize(mLog, mIndent); + if (canSecretRing == null) { + + // Special case: If keyring canonicalization failed, try again after adding + // all self-certificates from the public key. + try { + log(LogType.MSG_IS_MERGE_SPECIAL); + UncachedKeyRing oldPublicRing = getCanonicalizedPublicKeyRing(masterKeyId).getUncachedKeyRing(); + secretRing = secretRing.merge(oldPublicRing, mLog, mIndent); + canSecretRing = (CanonicalizedSecretKeyRing) secretRing.canonicalize(mLog, mIndent); + } catch (NotFoundException e2) { + // nothing, this is handled right in the next line + } + + if (canSecretRing == null) { + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } + } + if (canKeyRings != null) canKeyRings.add(canSecretRing); + } + + // Merge new data into public keyring as well, if there is any + UncachedKeyRing publicRing; + try { + UncachedKeyRing oldPublicRing = getCanonicalizedPublicKeyRing(masterKeyId).getUncachedKeyRing(); + + // Merge data from new secret ring into public one + log(LogType.MSG_IS_MERGE_PUBLIC); + publicRing = oldPublicRing.merge(secretRing, mLog, mIndent); + if (publicRing == null) { + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } + + } catch (NotFoundException e) { + log(LogType.MSG_IS_PUBRING_GENERATE); + publicRing = secretRing.extractPublicKeyRing(); + } + + CanonicalizedPublicKeyRing canPublicRing = (CanonicalizedPublicKeyRing) publicRing.canonicalize(mLog, + mIndent); + if (canPublicRing == null) { + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } + + int publicResult; + if (skipSave) { + // skip save method, set fixed result + publicResult = SaveKeyringResult.SAVED_PUBLIC; + } else { + publicResult = saveCanonicalizedPublicKeyRing(canPublicRing, progress, true); + } + + if ((publicResult & SaveKeyringResult.RESULT_ERROR) == SaveKeyringResult.RESULT_ERROR) { + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } + + progress.setProgress(LogType.MSG_IP_REINSERT_SECRET.getMsgId(), 90, 100); + + int result; + if (skipSave) { + // skip save method, set fixed result + result = SaveKeyringResult.SAVED_SECRET + | (alreadyExists ? SaveKeyringResult.UPDATED : 0); + } else { + result = saveCanonicalizedSecretKeyRing(canSecretRing); + } + + return new SaveKeyringResult(result, mLog, canSecretRing); + } catch (IOException e) { + log(LogType.MSG_IS_ERROR_IO_EXC); + return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); + } finally { + mIndent -= 1; + } + } + + public SaveKeyringResult saveSecretKeyRing(UncachedKeyRing secretRing, Progressable progress) { + return saveSecretKeyRing(secretRing, progress, null, false); + } + + @NonNull + public ConsolidateResult consolidateDatabaseStep1(Progressable progress) { + + OperationLog log = new OperationLog(); + int indent = 0; + + // 1a. fetch all secret keyrings into a cache file + log.add(LogType.MSG_CON, indent); + indent += 1; + + if (mConsolidateCritical) { + log.add(LogType.MSG_CON_RECURSIVE, indent); + return new ConsolidateResult(ConsolidateResult.RESULT_OK, log); + } + + 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); + indent += 1; + + final Cursor cursor = mContentResolver.query(KeyRingData.buildSecretKeyRingUri(), + new String[]{KeyRingData.KEY_RING_DATA}, null, null, null); + + 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() { + ParcelableKeyRing ring; + + @Override + public boolean hasNext() { + if (ring != null) { + return true; + } + if (cursor.isAfterLast()) { + return false; + } + ring = new ParcelableKeyRing(cursor.getBlob(0)); + cursor.moveToNext(); + return true; + } + + @Override + public ParcelableKeyRing next() { + try { + return ring; + } finally { + ring = null; + } + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + }); + cursor.close(); + + } catch (IOException e) { + Log.e(Constants.TAG, "error saving secret", e); + log.add(LogType.MSG_CON_ERROR_IO_SECRET, indent); + return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); + } finally { + indent -= 1; + } + + progress.setProgress(R.string.progress_con_saving, 3, 100); + + // 1b. fetch all public keyrings into a cache file + try { + + log.add(LogType.MSG_CON_SAVE_PUBLIC, indent); + indent += 1; + + final Cursor cursor = mContentResolver.query( + KeyRingData.buildPublicKeyRingUri(), + new String[]{KeyRingData.KEY_RING_DATA}, null, null, null); + + 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() { + ParcelableKeyRing ring; + + @Override + public boolean hasNext() { + if (ring != null) { + return true; + } + if (cursor.isAfterLast()) { + return false; + } + ring = new ParcelableKeyRing(cursor.getBlob(0)); + cursor.moveToNext(); + return true; + } + + @Override + public ParcelableKeyRing next() { + try { + return ring; + } finally { + ring = null; + } + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + }); + cursor.close(); + + } catch (IOException e) { + Log.e(Constants.TAG, "error saving public", e); + log.add(LogType.MSG_CON_ERROR_IO_PUBLIC, indent); + return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); + } finally { + indent -= 1; + } + + log.add(LogType.MSG_CON_CRITICAL_IN, indent); + Preferences.getPreferences(mContext).setCachedConsolidate(true); + + return consolidateDatabaseStep2(log, indent, progress, false); + } + + @NonNull + public ConsolidateResult consolidateDatabaseStep2(Progressable progress) { + return consolidateDatabaseStep2(new OperationLog(), 0, progress, true); + } + + private static boolean mConsolidateCritical = false; + + @NonNull + private ConsolidateResult consolidateDatabaseStep2( + OperationLog log, int indent, Progressable progress, boolean recovery) { + + synchronized (DatabaseReadWriteInteractor.class) { + if (mConsolidateCritical) { + log.add(LogType.MSG_CON_ERROR_CONCURRENT, indent); + return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); + } + mConsolidateCritical = true; + } + + try { + Preferences prefs = Preferences.getPreferences(mContext); + + if (recovery) { + log.add(LogType.MSG_CON_RECOVER, indent); + indent += 1; + } + + if (!prefs.getCachedConsolidate()) { + log.add(LogType.MSG_CON_ERROR_BAD_STATE, indent); + return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); + } + + // 2. wipe database (IT'S DANGEROUS) + + // first, backup our list of updated key times + ArrayList updatedKeysValues = new ArrayList<>(); + final int INDEX_MASTER_KEY_ID = 0; + final int INDEX_LAST_UPDATED = 1; + Cursor lastUpdatedCursor = mContentResolver.query( + UpdatedKeys.CONTENT_URI, + new String[]{ + UpdatedKeys.MASTER_KEY_ID, + UpdatedKeys.LAST_UPDATED + }, + null, null, null); + while (lastUpdatedCursor.moveToNext()) { + ContentValues values = new ContentValues(); + values.put(UpdatedKeys.MASTER_KEY_ID, + lastUpdatedCursor.getLong(INDEX_MASTER_KEY_ID)); + values.put(UpdatedKeys.LAST_UPDATED, + lastUpdatedCursor.getLong(INDEX_LAST_UPDATED)); + updatedKeysValues.add(values); + } + lastUpdatedCursor.close(); + + log.add(LogType.MSG_CON_DB_CLEAR, indent); + mContentResolver.delete(KeyRings.buildUnifiedKeyRingsUri(), null, null); + + ParcelableFileCache cacheSecret, cachePublic; + + // Set flag that we have a cached consolidation here + try { + cacheSecret = new ParcelableFileCache<>(mContext, "consolidate_secret.pcl"); + IteratorWithSize itSecrets = cacheSecret.readCache(false); + int numSecrets = itSecrets.getSize(); + + log.add(LogType.MSG_CON_REIMPORT_SECRET, indent, numSecrets); + indent += 1; + + // 3. Re-Import secret keyrings from cache + if (numSecrets > 0) { + + ImportKeyResult result = new ImportOperation(mContext, this, + new ProgressFixedScaler(progress, 10, 25, 100, R.string.progress_con_reimport)) + .serialKeyRingImport(itSecrets, numSecrets, null, null, false); + log.add(result, indent); + } else { + log.add(LogType.MSG_CON_REIMPORT_SECRET_SKIP, indent); + } + + } catch (IOException e) { + Log.e(Constants.TAG, "error importing secret", e); + log.add(LogType.MSG_CON_ERROR_SECRET, indent); + return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); + } finally { + indent -= 1; + } + + try { + + cachePublic = new ParcelableFileCache<>(mContext, "consolidate_public.pcl"); + IteratorWithSize itPublics = cachePublic.readCache(); + int numPublics = itPublics.getSize(); + + log.add(LogType.MSG_CON_REIMPORT_PUBLIC, indent, numPublics); + indent += 1; + + // 4. Re-Import public keyrings from cache + if (numPublics > 0) { + + ImportKeyResult result = new ImportOperation(mContext, this, + new ProgressFixedScaler(progress, 25, 99, 100, R.string.progress_con_reimport)) + .serialKeyRingImport(itPublics, numPublics, null, null, false); + log.add(result, indent); + // re-insert our backed up list of updated key times + // TODO: can this cause issues in case a public key re-import failed? + mContentResolver.bulkInsert(UpdatedKeys.CONTENT_URI, + updatedKeysValues.toArray(new ContentValues[updatedKeysValues.size()])); + } else { + log.add(LogType.MSG_CON_REIMPORT_PUBLIC_SKIP, indent); + } + + } catch (IOException e) { + Log.e(Constants.TAG, "error importing public", e); + log.add(LogType.MSG_CON_ERROR_PUBLIC, indent); + return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); + } finally { + indent -= 1; + } + + log.add(LogType.MSG_CON_CRITICAL_OUT, indent); + Preferences.getPreferences(mContext).setCachedConsolidate(false); + + // 5. Delete caches + try { + log.add(LogType.MSG_CON_DELETE_SECRET, indent); + indent += 1; + cacheSecret.delete(); + } catch (IOException e) { + // doesn't /really/ matter + Log.e(Constants.TAG, "IOException during delete of secret cache", e); + log.add(LogType.MSG_CON_WARN_DELETE_SECRET, indent); + } finally { + indent -= 1; + } + + try { + log.add(LogType.MSG_CON_DELETE_PUBLIC, indent); + indent += 1; + cachePublic.delete(); + } catch (IOException e) { + // doesn't /really/ matter + Log.e(Constants.TAG, "IOException during deletion of public cache", e); + log.add(LogType.MSG_CON_WARN_DELETE_PUBLIC, indent); + } finally { + indent -= 1; + } + + progress.setProgress(100, 100); + log.add(LogType.MSG_CON_SUCCESS, indent); + + return new ConsolidateResult(ConsolidateResult.RESULT_OK, log); + + } finally { + mConsolidateCritical = false; + } + + } + + /** + * Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing + */ + private ContentProviderOperation + buildCertOperations(long masterKeyId, int rank, WrappedSignature cert, int verified) + throws IOException { + ContentValues values = new ContentValues(); + values.put(Certs.MASTER_KEY_ID, masterKeyId); + values.put(Certs.RANK, rank); + values.put(Certs.KEY_ID_CERTIFIER, cert.getKeyId()); + values.put(Certs.TYPE, cert.getSignatureType()); + values.put(Certs.CREATION, cert.getCreationTime().getTime() / 1000); + values.put(Certs.VERIFIED, verified); + values.put(Certs.DATA, cert.getEncoded()); + + Uri uri = Certs.buildCertsUri(masterKeyId); + + return ContentProviderOperation.newInsert(uri).withValues(values).build(); + } + + /** + * Build ContentProviderOperation to add PublicUserIds to database corresponding to a keyRing + */ + private ContentProviderOperation + buildUserIdOperations(long masterKeyId, UserPacketItem item, int rank) { + ContentValues values = new ContentValues(); + values.put(UserPackets.MASTER_KEY_ID, masterKeyId); + values.put(UserPackets.TYPE, item.type); + values.put(UserPackets.USER_ID, item.userId); + values.put(UserPackets.NAME, item.name); + values.put(UserPackets.EMAIL, item.email); + values.put(UserPackets.COMMENT, item.comment); + values.put(UserPackets.ATTRIBUTE_DATA, item.attributeData); + values.put(UserPackets.IS_PRIMARY, item.isPrimary); + values.put(UserPackets.IS_REVOKED, item.selfRevocation != null); + values.put(UserPackets.RANK, rank); + + Uri uri = UserPackets.buildUserIdsUri(masterKeyId); + + return ContentProviderOperation.newInsert(uri).withValues(values).build(); + } + + public Uri renewKeyLastUpdatedTime(long masterKeyId, long time, TimeUnit timeUnit) { + ContentValues values = new ContentValues(); + values.put(UpdatedKeys.MASTER_KEY_ID, masterKeyId); + values.put(UpdatedKeys.LAST_UPDATED, timeUnit.toSeconds(time)); + + return mContentResolver.insert(UpdatedKeys.CONTENT_URI, values); + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index 167302440..d11dca6c7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -63,10 +63,10 @@ import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAccounts; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.remote.OpenPgpServiceKeyIdExtractor.KeyIdResult; import org.sufficientlysecure.keychain.service.BackupKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -97,7 +97,7 @@ public class OpenPgpService extends Service { public void onCreate() { super.onCreate(); mApiPermissionHelper = new ApiPermissionHelper(this, new ApiDataAccessObject(this)); - mDatabaseInteractor = new DatabaseInteractor(this); + mDatabaseInteractor = new DatabaseInteractor(getContentResolver()); mApiDao = new ApiDataAccessObject(this); mApiPendingIntentFactory = new ApiPendingIntentFactory(getBaseContext()); @@ -167,7 +167,7 @@ public class OpenPgpService extends Service { } // execute PGP operation! - PgpSignEncryptOperation pse = new PgpSignEncryptOperation(this, new DatabaseInteractor(this), null); + PgpSignEncryptOperation pse = new PgpSignEncryptOperation(this, mDatabaseInteractor, null); PgpSignEncryptResult pgpResult = pse.execute(pseInput, inputParcel, inputData, outputStream); if (pgpResult.isPending()) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java index 467d51675..3fa66fa97 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java @@ -15,6 +15,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; @@ -40,7 +41,7 @@ class RequestKeyPermissionPresenter { PackageManager packageManager = context.getPackageManager(); ApiDataAccessObject apiDataAccessObject = new ApiDataAccessObject(context); ApiPermissionHelper apiPermissionHelper = new ApiPermissionHelper(context, apiDataAccessObject); - DatabaseInteractor databaseInteractor = new DatabaseInteractor(context); + DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(context); return new RequestKeyPermissionPresenter(context, apiDataAccessObject, apiPermissionHelper, packageManager, databaseInteractor); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java index c9b8f2103..470b19ec0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java @@ -48,7 +48,7 @@ import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.ServiceProgressHandler.MessageStatus; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Log; @@ -111,36 +111,37 @@ public class KeychainService extends Service implements Progressable { // just for brevity KeychainService outerThis = KeychainService.this; + DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(outerThis); if (inputParcel instanceof SignEncryptParcel) { - op = new SignEncryptOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); + op = new SignEncryptOperation(outerThis, databaseInteractor, outerThis, mActionCanceled); } else if (inputParcel instanceof PgpDecryptVerifyInputParcel) { - op = new PgpDecryptVerifyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); + op = new PgpDecryptVerifyOperation(outerThis, databaseInteractor, outerThis); } else if (inputParcel instanceof SaveKeyringParcel) { - op = new EditKeyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); + op = new EditKeyOperation(outerThis, databaseInteractor, outerThis, mActionCanceled); } else if (inputParcel instanceof ChangeUnlockParcel) { - op = new ChangeUnlockOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); + op = new ChangeUnlockOperation(outerThis, databaseInteractor, outerThis); } else if (inputParcel instanceof RevokeKeyringParcel) { - op = new RevokeOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); + op = new RevokeOperation(outerThis, databaseInteractor, outerThis); } else if (inputParcel instanceof CertifyActionsParcel) { - op = new CertifyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); + op = new CertifyOperation(outerThis, databaseInteractor, outerThis, mActionCanceled); } else if (inputParcel instanceof DeleteKeyringParcel) { - op = new DeleteOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); + op = new DeleteOperation(outerThis, databaseInteractor, outerThis); } else if (inputParcel instanceof PromoteKeyringParcel) { - op = new PromoteKeyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); + op = new PromoteKeyOperation(outerThis, databaseInteractor, outerThis, mActionCanceled); } else if (inputParcel instanceof ImportKeyringParcel) { - op = new ImportOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); + op = new ImportOperation(outerThis, databaseInteractor, outerThis, mActionCanceled); } else if (inputParcel instanceof BackupKeyringParcel) { - op = new BackupOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); + op = new BackupOperation(outerThis, databaseInteractor, outerThis, mActionCanceled); } else if (inputParcel instanceof UploadKeyringParcel) { - op = new UploadOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); + op = new UploadOperation(outerThis, databaseInteractor, outerThis, mActionCanceled); } else if (inputParcel instanceof ConsolidateInputParcel) { - op = new ConsolidateOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); + op = new ConsolidateOperation(outerThis, databaseInteractor, outerThis); } else if (inputParcel instanceof KeybaseVerificationParcel) { - op = new KeybaseVerificationOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); + op = new KeybaseVerificationOperation(outerThis, databaseInteractor, outerThis); } else if (inputParcel instanceof InputDataParcel) { - op = new InputDataOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); + op = new InputDataOperation(outerThis, databaseInteractor, outerThis); } else if (inputParcel instanceof BenchmarkInputParcel) { - op = new BenchmarkOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); + op = new BenchmarkOperation(outerThis, databaseInteractor, outerThis); } else { throw new AssertionError("Unrecognized input parcel in KeychainService!"); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java index 30e4387ef..986f6b1e9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java @@ -35,8 +35,8 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.operations.ImportOperation; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.network.NetworkReceiver; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity; @@ -320,7 +320,7 @@ public class KeyserverSyncAdapterService extends Service { private ImportKeyResult directUpdate(Context context, ArrayList keyList, CryptoInputParcel cryptoInputParcel) { Log.d(Constants.TAG, "Starting normal update"); - ImportOperation importOp = new ImportOperation(context, new DatabaseInteractor(context), null); + ImportOperation importOp = new ImportOperation(context, new DatabaseReadWriteInteractor(context), null); return importOp.execute( new ImportKeyringParcel(keyList, Preferences.getPreferences(context).getPreferredKeyserver()), @@ -380,7 +380,7 @@ public class KeyserverSyncAdapterService extends Service { new OperationResult.OperationLog()); } ImportKeyResult result = - new ImportOperation(context, new DatabaseInteractor(context), null, mCancelled) + new ImportOperation(context, new DatabaseReadWriteInteractor(context), null, mCancelled) .execute( new ImportKeyringParcel( keyWrapper, diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index fb6f1e08b..254bee246 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.Preferences; @@ -224,7 +224,7 @@ public class PassphraseCacheService extends Service { /** * Internal implementation to get cached passphrase. */ - private Passphrase getCachedPassphraseImpl(long masterKeyId, long subKeyId) throws DatabaseInteractor.NotFoundException { + private Passphrase getCachedPassphraseImpl(long masterKeyId, long subKeyId) throws DatabaseReadWriteInteractor.NotFoundException { // on "none" key, just do nothing if (masterKeyId == Constants.key.none) { return null; @@ -245,16 +245,16 @@ public class PassphraseCacheService extends Service { + masterKeyId + ", subKeyId " + subKeyId); // get the type of key (from the database) - CachedPublicKeyRing keyRing = new DatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing keyRing = new DatabaseReadWriteInteractor(this).getCachedPublicKeyRing(masterKeyId); SecretKeyType keyType = keyRing.getSecretKeyType(subKeyId); switch (keyType) { case PASSPHRASE_EMPTY: return new Passphrase(""); case UNAVAILABLE: - throw new DatabaseInteractor.NotFoundException("secret key for this subkey is not available"); + throw new DatabaseReadWriteInteractor.NotFoundException("secret key for this subkey is not available"); case GNU_DUMMY: - throw new DatabaseInteractor.NotFoundException("secret key for stripped subkey is not available"); + throw new DatabaseReadWriteInteractor.NotFoundException("secret key for stripped subkey is not available"); } // get cached passphrase @@ -398,7 +398,7 @@ public class PassphraseCacheService extends Service { bundle.putParcelable(EXTRA_PASSPHRASE, passphrase); msg.setData(bundle); } - } catch (DatabaseInteractor.NotFoundException e) { + } catch (DatabaseReadWriteInteractor.NotFoundException e) { Log.e(Constants.TAG, "PassphraseCacheService: Passphrase for unknown key was requested!"); msg.what = MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java index ad65fde71..400edd56c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java @@ -34,8 +34,8 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.experimental.SentenceConfirm; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.base.LoaderFragment; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; @@ -213,7 +213,7 @@ public class CertifyFingerprintFragment extends LoaderFragment implements private void certify(Uri dataUri) { long keyId = 0; try { - keyId = new DatabaseInteractor(getActivity()) + keyId = new DatabaseReadWriteInteractor(getActivity()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java index b44969b7c..fa26f1721 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -35,7 +35,7 @@ import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -68,7 +68,7 @@ public class CertifyKeyFragment .getLongExtra(CertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, Constants.key.none); if (certifyKeyId != Constants.key.none) { try { - CachedPublicKeyRing key = (new DatabaseInteractor(getActivity())) + CachedPublicKeyRing key = (new DatabaseReadWriteInteractor(getActivity())) .getCachedPublicKeyRing(certifyKeyId); if (key.canCertify()) { mCertifyKeySpinner.setPreSelectedKeyId(certifyKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java index 84a39108d..fffcad7a5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java @@ -29,8 +29,8 @@ import android.support.v4.app.TaskStackBuilder; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.securitytoken.KeyFormat; import org.sufficientlysecure.keychain.ui.base.BaseSecurityTokenActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -180,7 +180,7 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity { if (containsKeys(mScannedFingerprints)) { try { long masterKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mScannedFingerprints); - CachedPublicKeyRing ring = new DatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing ring = new DatabaseReadWriteInteractor(this).getCachedPublicKeyRing(masterKeyId); ring.getMasterKeyId(); Intent intent = new Intent(this, ViewKeyActivity.class); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index a3e8c3fe2..1248c8f69 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -43,8 +43,8 @@ import org.sufficientlysecure.keychain.operations.results.UploadResult; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; @@ -411,7 +411,7 @@ public class CreateKeyFinalFragment extends Fragment { CreateKeyActivity activity = (CreateKeyActivity) getActivity(); final SaveKeyringParcel changeKeyringParcel; - CachedPublicKeyRing key = (new DatabaseInteractor(activity)) + CachedPublicKeyRing key = (new DatabaseReadWriteInteractor(activity)) .getCachedPublicKeyRing(saveKeyResult.mMasterKeyId); try { changeKeyringParcel = new SaveKeyringParcel(key.getMasterKeyId(), key.getFingerprint()); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index 2bc84687e..f065df87e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -45,9 +45,9 @@ import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -192,7 +192,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager. try { Intent viewKeyIntent = new Intent(getActivity(), ViewKeyActivity.class); - long masterKeyId = new DatabaseInteractor(getActivity()).getCachedPublicKeyRing( + long masterKeyId = new DatabaseReadWriteInteractor(getActivity()).getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId) ).getMasterKeyId(); viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId)); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java index 84d94586b..3e776d4af 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java @@ -41,6 +41,7 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver; import org.sufficientlysecure.keychain.operations.results.DeleteResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.RevokeResult; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.DeleteKeyringParcel; @@ -89,7 +90,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { if (mMasterKeyIds.length == 1 && mHasSecret) { // if mMasterKeyIds.length == 0 we let the DeleteOperation respond try { - HashMap data = new DatabaseInteractor(this).getUnifiedData( + HashMap data = new DatabaseReadWriteInteractor(this).getUnifiedData( mMasterKeyIds[0], new String[]{ KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.IS_REVOKED @@ -112,7 +113,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { } else { showRevokeDeleteDialog(name); } - } catch (DatabaseInteractor.NotFoundException e) { + } catch (DatabaseReadWriteInteractor.NotFoundException e) { Log.e(Constants.TAG, "Secret key to delete not found at DeleteKeyDialogActivity for " + mMasterKeyIds[0], e); @@ -269,7 +270,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { long masterKeyId = masterKeyIds[0]; try { - HashMap data = new DatabaseInteractor(activity).getUnifiedData( + HashMap data = new DatabaseReadWriteInteractor(activity).getUnifiedData( masterKeyId, new String[]{ KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.HAS_ANY_SECRET @@ -293,7 +294,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { } else { mMainMessage.setText(getString(R.string.public_key_deletetion_confirmation, name)); } - } catch (DatabaseInteractor.NotFoundException e) { + } catch (DatabaseReadWriteInteractor.NotFoundException e) { dismiss(); return null; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java index c34b2b994..ef998e5d4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java @@ -49,9 +49,9 @@ import org.sufficientlysecure.keychain.operations.results.UploadResult; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; @@ -170,7 +170,7 @@ public class EditIdentitiesFragment extends Fragment try { Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri); CachedPublicKeyRing keyRing = - new DatabaseInteractor(getActivity()).getCachedPublicKeyRing(secretUri); + new DatabaseReadWriteInteractor(getActivity()).getCachedPublicKeyRing(secretUri); long masterKeyId = keyRing.getMasterKeyId(); // check if this is a master secret key we can work with diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index c766472f4..902858ff6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -48,9 +48,9 @@ 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.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; @@ -203,7 +203,7 @@ public class EditKeyFragment extends QueueingCryptoOperationFragment return; } - DatabaseInteractor databaseInteractor = new DatabaseInteractor(activity); + DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(activity); Cursor cursor = databaseInteractor.getContentResolver().query( KeyRings.buildUnifiedKeyRingsUri(), new String[]{ KeyRings.FINGERPRINT diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java index e0b4b1ba6..67fdf65ce 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java @@ -57,6 +57,7 @@ import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; @@ -112,7 +113,7 @@ public class PassphraseDialogActivity extends FragmentActivity { // handle empty passphrases by directly returning an empty crypto input parcel try { CachedPublicKeyRing pubRing = - new DatabaseInteractor(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId()); + new DatabaseReadWriteInteractor(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId()); // use empty passphrase for empty passphrase if (pubRing.getSecretKeyType(requiredInput.getSubKeyId()) == SecretKeyType.PASSPHRASE_EMPTY) { // also return passphrase back to activity @@ -231,7 +232,7 @@ public class PassphraseDialogActivity extends FragmentActivity { try { long subKeyId = mRequiredInput.getSubKeyId(); - DatabaseInteractor helper = new DatabaseInteractor(activity); + DatabaseInteractor helper = new DatabaseReadWriteInteractor(activity); CachedPublicKeyRing cachedPublicKeyRing = helper.getCachedPublicKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); // yes the inner try/catch block is necessary, otherwise the final variable @@ -266,7 +267,7 @@ public class PassphraseDialogActivity extends FragmentActivity { throw new AssertionError("Unhandled SecretKeyType (should not happen)"); } - } catch (PgpKeyNotFoundException | DatabaseInteractor.NotFoundException e) { + } catch (PgpKeyNotFoundException | DatabaseReadWriteInteractor.NotFoundException e) { alert.setTitle(R.string.title_key_not_found); alert.setMessage(getString(R.string.key_not_found, mRequiredInput.getSubKeyId())); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @@ -457,7 +458,7 @@ public class PassphraseDialogActivity extends FragmentActivity { Long subKeyId = mRequiredInput.getSubKeyId(); CanonicalizedSecretKeyRing secretKeyRing = - new DatabaseInteractor(getActivity()).getCanonicalizedSecretKeyRing( + new DatabaseReadWriteInteractor(getActivity()).getCanonicalizedSecretKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); CanonicalizedSecretKey secretKeyToUnlock = secretKeyRing.getSecretKey(subKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java index 2f99a0b68..2369a7f08 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java @@ -28,6 +28,7 @@ import android.widget.ImageView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.base.BaseActivity; @@ -74,7 +75,7 @@ public class QrCodeViewActivity extends BaseActivity { } }); - DatabaseInteractor databaseInteractor = new DatabaseInteractor(this); + DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(this); try { byte[] blob = (byte[]) databaseInteractor.getGenericData( KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri), @@ -102,7 +103,7 @@ public class QrCodeViewActivity extends BaseActivity { mQrCode.setImageBitmap(scaled); } }); - } catch (DatabaseInteractor.NotFoundException e) { + } catch (DatabaseReadWriteInteractor.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); Notify.create(this, R.string.error_key_not_found, Style.ERROR).show(); ActivityCompat.finishAfterTransition(QrCodeViewActivity.this); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java index 4dec17128..91c2645d9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java @@ -33,6 +33,7 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.operations.ImportOperation; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; @@ -105,7 +106,7 @@ public class SafeSlingerActivity extends BaseActivity // retrieve public key blob and start SafeSlinger Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId); try { - byte[] keyBlob = (byte[]) new DatabaseInteractor(this).getGenericData( + byte[] keyBlob = (byte[]) new DatabaseReadWriteInteractor(this).getGenericData( uri, KeychainContract.KeyRingData.KEY_RING_DATA, DatabaseInteractor.FIELD_TYPE_BLOB); Intent slingerIntent = new Intent(this, ExchangeActivity.class); @@ -114,7 +115,7 @@ public class SafeSlingerActivity extends BaseActivity slingerIntent.putExtra(ExchangeConfig.extra.USER_DATA, keyBlob); slingerIntent.putExtra(ExchangeConfig.extra.HOST_NAME, Constants.SAFESLINGER_SERVER); startActivityForResult(slingerIntent, REQUEST_CODE_SAFE_SLINGER); - } catch (DatabaseInteractor.NotFoundException e) { + } catch (DatabaseReadWriteInteractor.NotFoundException e) { Log.e(Constants.TAG, "personal key not found", e); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java index 94415e154..adc91fe8d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java @@ -35,6 +35,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.securitytoken.KeyType; @@ -193,12 +194,12 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity { throw new IOException(getString(R.string.error_wrong_security_token)); } - DatabaseInteractor databaseInteractor = new DatabaseInteractor(this); + DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(this); CanonicalizedPublicKeyRing publicKeyRing; try { publicKeyRing = databaseInteractor.getCanonicalizedPublicKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mRequiredInput.getMasterKeyId())); - } catch (DatabaseInteractor.NotFoundException e) { + } catch (DatabaseReadWriteInteractor.NotFoundException e) { throw new IOException("Couldn't find subkey for key to token operation."); } @@ -232,13 +233,13 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity { mSecurityTokenHelper.setPin(new Passphrase("123456")); mSecurityTokenHelper.setAdminPin(new Passphrase("12345678")); - DatabaseInteractor databaseInteractor = new DatabaseInteractor(this); + DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(this); CanonicalizedSecretKeyRing secretKeyRing; try { secretKeyRing = databaseInteractor.getCanonicalizedSecretKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mRequiredInput.getMasterKeyId()) ); - } catch (DatabaseInteractor.NotFoundException e) { + } catch (DatabaseReadWriteInteractor.NotFoundException e) { throw new IOException("Couldn't find subkey for key to token operation."); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java index d60518efc..734f59b2f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java @@ -38,6 +38,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.WrappedSignature; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; @@ -184,7 +185,7 @@ public class ViewCertActivity extends BaseActivity Intent viewIntent = new Intent(ViewCertActivity.this, ViewKeyActivity.class); try { - DatabaseInteractor databaseInteractor = new DatabaseInteractor(ViewCertActivity.this); + DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(ViewCertActivity.this); long signerMasterKeyId = databaseInteractor.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId(); viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId)); 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 593d6597c..674978452 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -72,6 +72,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; @@ -185,7 +186,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mDatabaseInteractor = new DatabaseInteractor(this); + mDatabaseInteractor = new DatabaseReadWriteInteractor(this); mImportOpHelper = new CryptoOperationHelper<>(1, this, this, null); setTitle(null); @@ -400,7 +401,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements case R.id.menu_key_view_refresh: { try { updateFromKeyserver(mDataUri, mDatabaseInteractor); - } catch (DatabaseInteractor.NotFoundException e) { + } catch (DatabaseReadWriteInteractor.NotFoundException e) { Notify.create(this, R.string.error_key_not_found, Notify.Style.ERROR).show(); } return true; @@ -741,7 +742,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements return; } try { - long keyId = new DatabaseInteractor(this) + long keyId = new DatabaseReadWriteInteractor(this) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); long[] encryptionKeyIds = new long[]{keyId}; @@ -765,7 +766,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements private void startSafeSlinger(Uri dataUri) { long keyId = 0; try { - keyId = new DatabaseInteractor(this) + keyId = new DatabaseReadWriteInteractor(this) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { @@ -1119,7 +1120,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements private void updateFromKeyserver(Uri dataUri, DatabaseInteractor databaseInteractor) - throws DatabaseInteractor.NotFoundException { + throws DatabaseReadWriteInteractor.NotFoundException { mIsRefreshing = true; mRefreshItem.setEnabled(false); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java index b84c2498b..9e72e5867 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java @@ -44,6 +44,7 @@ import com.astuetz.PagerSlidingTabStrip; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.operations.results.OperationResult; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; @@ -88,7 +89,7 @@ public class ViewKeyAdvActivity extends BaseActivity implements } }); - mDatabaseInteractor = new DatabaseInteractor(this); + mDatabaseInteractor = new DatabaseReadWriteInteractor(this); mViewPager = (ViewPager) findViewById(R.id.pager); mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tab_layout); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index 046d96805..f7fb131f2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -56,6 +56,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; @@ -93,7 +94,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements View root = super.onCreateView(inflater, superContainer, savedInstanceState); View view = inflater.inflate(R.layout.view_key_adv_share_fragment, getContainer()); - DatabaseInteractor databaseInteractor = new DatabaseInteractor(ViewKeyAdvShareFragment.this.getActivity()); + DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(ViewKeyAdvShareFragment.this.getActivity()); mNfcHelper = new NfcHelper(getActivity(), databaseInteractor); mFingerprintView = (TextView) view.findViewById(R.id.view_key_fingerprint); @@ -200,7 +201,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements private void startSafeSlinger(Uri dataUri) { long keyId = 0; try { - keyId = new DatabaseInteractor(getActivity()) + keyId = new DatabaseReadWriteInteractor(getActivity()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { @@ -216,7 +217,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements if (activity == null || mFingerprint == null) { return; } - DatabaseInteractor databaseInteractor = new DatabaseInteractor(activity); + DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(activity); try { String content = databaseInteractor.getKeyRingAsArmoredString( @@ -273,7 +274,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements } catch (PgpGeneralException | IOException e) { Log.e(Constants.TAG, "error processing key!", e); Notify.create(activity, R.string.error_key_processing, Notify.Style.ERROR).show(); - } catch (DatabaseInteractor.NotFoundException e) { + } catch (DatabaseReadWriteInteractor.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); Notify.create(activity, R.string.error_key_not_found, Notify.Style.ERROR).show(); } @@ -457,7 +458,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements private void uploadToKeyserver() { long keyId; try { - keyId = new DatabaseInteractor(getActivity()) + keyId = new DatabaseReadWriteInteractor(getActivity()) .getCachedPublicKeyRing(mDataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index 13c981746..b6eb61adf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -40,6 +40,7 @@ import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; @@ -74,7 +75,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter data) { @@ -95,7 +96,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter 0; - } catch (DatabaseInteractor.NotFoundException | PgpKeyNotFoundException ignored) { + } catch (DatabaseReadWriteInteractor.NotFoundException | PgpKeyNotFoundException ignored) { } mKeyStates[i] = keyState; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java index f8db70a95..5fc22ccd0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java @@ -37,8 +37,8 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -105,7 +105,7 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity final long subKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mSecurityTokenFingerprints); try { - CachedPublicKeyRing ring = new DatabaseInteractor(this).getCachedPublicKeyRing( + CachedPublicKeyRing ring = new DatabaseReadWriteInteractor(this).getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); long masterKeyId = ring.getMasterKeyId(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java index b9ea3a7f7..a7b8558b2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java @@ -34,9 +34,9 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.util.Log; @@ -58,7 +58,7 @@ public class LinkedIdWizard extends BaseActivity { try { Uri uri = getIntent().getData(); uri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(uri); - CachedPublicKeyRing ring = new DatabaseInteractor(this).getCachedPublicKeyRing(uri); + CachedPublicKeyRing ring = new DatabaseReadWriteInteractor(this).getCachedPublicKeyRing(uri); if (!ring.hasAnySecret()) { Log.e(Constants.TAG, "Linked Identities can only be added to secret keys!"); finish(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java index 3aef420bd..908e9db3c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java @@ -35,6 +35,7 @@ import android.provider.Settings; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.util.Notify; @@ -132,7 +133,7 @@ public class NfcHelper { blobUri, KeychainContract.KeyRingData.KEY_RING_DATA, DatabaseInteractor.FIELD_TYPE_BLOB); - } catch (DatabaseInteractor.NotFoundException e) { + } catch (DatabaseReadWriteInteractor.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java index 31bd6571c..72b8c8d21 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java @@ -44,7 +44,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow; import org.sufficientlysecure.keychain.pgp.WrappedSignature; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.BackupKeyringParcel; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; @@ -135,7 +135,7 @@ public class BackupOperationTest { @Before public void setUp() { - DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; @@ -150,7 +150,7 @@ public class BackupOperationTest { @Test public void testExportAllLocalStripped() throws Exception { BackupOperation op = new BackupOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); // make sure there is a local cert (so the later checks that there are none are meaningful) assertTrue("second keyring has local certification", checkForLocal(mStaticRing2)); @@ -249,7 +249,7 @@ public class BackupOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); BackupOperation op = new BackupOperation(spyApplication, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); BackupKeyringParcel parcel = new BackupKeyringParcel( new long[] { mStaticRing1.getMasterKeyId() }, false, false, true, fakeOutputUri); @@ -306,7 +306,7 @@ public class BackupOperationTest { { // export encrypted BackupOperation op = new BackupOperation(spyApplication, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); BackupKeyringParcel parcel = new BackupKeyringParcel( new long[] { mStaticRing1.getMasterKeyId() }, false, true, true, fakeOutputUri); @@ -324,7 +324,7 @@ public class BackupOperationTest { { PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(outStream.toByteArray()); input.setAllowSymmetricDecryption(true); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java index 5dec61169..4bdff329c 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java @@ -25,7 +25,7 @@ import org.junit.runner.RunWith; import org.robolectric.RuntimeEnvironment; import org.robolectric.shadows.ShadowLog; import org.sufficientlysecure.keychain.KeychainTestRunner; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.BenchmarkInputParcel; import java.io.PrintStream; @@ -47,7 +47,7 @@ public class BenchmarkOperationTest { @Test public void testBenchmark() throws Exception { BenchmarkOperation op = new BenchmarkOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); op.execute(new BenchmarkInputParcel(), null); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java index 398831920..0e21a8c33 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java @@ -34,8 +34,8 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; @@ -117,7 +117,7 @@ public class CertifyOperationTest { @Before public void setUp() throws Exception { - DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; @@ -132,7 +132,7 @@ public class CertifyOperationTest { @Test public void testSelfCertifyFlag() throws Exception { - CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing1.getMasterKeyId()); Assert.assertEquals("secret key must be marked self-certified in database", // TODO this should be more correctly be VERIFIED_SELF at some point! @@ -143,10 +143,10 @@ public class CertifyOperationTest { @Test public void testCertifyId() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null, null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); { - CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("public key must not be marked verified prior to certification", Certs.UNVERIFIED, ring.getVerified()); @@ -160,7 +160,7 @@ public class CertifyOperationTest { Assert.assertTrue("certification must succeed", result.success()); { - CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("new key must be verified now", Certs.VERIFIED_SECRET, ring.getVerified()); @@ -171,10 +171,10 @@ public class CertifyOperationTest { @Test public void testCertifyAttribute() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null, null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); { - CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("public key must not be marked verified prior to certification", Certs.UNVERIFIED, ring.getVerified()); @@ -188,7 +188,7 @@ public class CertifyOperationTest { Assert.assertTrue("certification must succeed", result.success()); { - CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("new key must be verified now", Certs.VERIFIED_SECRET, ring.getVerified()); @@ -200,7 +200,7 @@ public class CertifyOperationTest { @Test public void testCertifySelf() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null, null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(), @@ -217,7 +217,7 @@ public class CertifyOperationTest { public void testCertifyNonexistent() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null, null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); { CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java index 5cb914448..b1c651b61 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java @@ -38,7 +38,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.PromoteKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; @@ -90,7 +90,7 @@ public class PromoteKeyOperationTest { @Before public void setUp() throws Exception { - DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; @@ -104,14 +104,14 @@ public class PromoteKeyOperationTest { @Test public void testPromote() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null, null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); PromoteKeyResult result = op.execute(new PromoteKeyringParcel(mStaticRing.getMasterKeyId(), null, null), null); Assert.assertTrue("promotion must succeed", result.success()); { - CachedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) + CachedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCachedPublicKeyRing(mStaticRing.getMasterKeyId()); Assert.assertTrue("key must have a secret now", ring.hasAnySecret()); @@ -128,7 +128,7 @@ public class PromoteKeyOperationTest { @Test public void testPromoteDivert() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null, null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); byte[] aid = Hex.decode("D2760001240102000000012345670000"); @@ -137,7 +137,7 @@ public class PromoteKeyOperationTest { Assert.assertTrue("promotion must succeed", result.success()); { - CanonicalizedSecretKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) + CanonicalizedSecretKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { @@ -153,7 +153,7 @@ public class PromoteKeyOperationTest { @Test public void testPromoteDivertSpecific() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null, null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); byte[] aid = Hex.decode("D2760001240102000000012345670000"); @@ -167,7 +167,7 @@ public class PromoteKeyOperationTest { Assert.assertTrue("promotion must succeed", result.success()); { - CanonicalizedSecretKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) + CanonicalizedSecretKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java index 19033606d..ad28dc7f6 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java @@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.KeychainTestRunner; import org.sufficientlysecure.keychain.operations.InputDataOperation; import org.sufficientlysecure.keychain.operations.results.InputDataResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.InputDataParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -126,7 +126,7 @@ public class InputDataOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); InputDataOperation op = new InputDataOperation(spyApplication, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputDataParcel input = new InputDataParcel(fakeInputUri, null); @@ -306,7 +306,7 @@ public class InputDataOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); InputDataOperation op = new InputDataOperation(spyApplication, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputDataParcel input = new InputDataParcel(FAKE_CONTENT_INPUT_URI_1, null); return op.execute(input, new CryptoInputParcel()); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java index 4cab67f5d..1a9573c3c 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java @@ -40,8 +40,8 @@ import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; @@ -149,7 +149,7 @@ public class PgpEncryptDecryptTest { @Before public void setUp() { - DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; @@ -172,7 +172,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -197,7 +197,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute( @@ -227,7 +227,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute(input, @@ -249,7 +249,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute(input, @@ -270,7 +270,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(false); DecryptVerifyResult result = op.execute(input, @@ -297,7 +297,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -353,7 +353,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -415,7 +415,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -472,7 +472,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -575,7 +575,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -626,11 +626,11 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1)); @@ -648,11 +648,11 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1)); @@ -675,7 +675,7 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); } @@ -685,7 +685,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -730,7 +730,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -824,7 +824,7 @@ public class PgpEncryptDecryptTest { { // decryption with passphrase cached should succeed for the other key if first is gone // delete first key from database - new DatabaseInteractor(RuntimeEnvironment.application).getContentResolver().delete( + new DatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete( KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null ); @@ -859,7 +859,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -907,7 +907,7 @@ public class PgpEncryptDecryptTest { { // decryption with passphrase cached should succeed for the other key if first is gone // delete first key from database - new DatabaseInteractor(RuntimeEnvironment.application).getContentResolver().delete( + new DatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete( KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null ); @@ -946,7 +946,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaindata); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -1018,7 +1018,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null); + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -1069,7 +1069,7 @@ public class PgpEncryptDecryptTest { final Passphrase passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) { return new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseInteractor(RuntimeEnvironment.application), null) { + new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null) { @Override public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId) throws NoSecretKeyException { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java index a4f31581e..695158787 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java @@ -43,7 +43,7 @@ import java.util.Iterator; @RunWith(KeychainTestRunner.class) public class DatabaseInteractorSaveTest { - DatabaseInteractor mDatabaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor mDatabaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); @BeforeClass public static void setUpOnce() throws Exception { @@ -61,17 +61,17 @@ public class DatabaseInteractorSaveTest { SaveKeyringResult result; // insert both keys, second should fail - result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); + result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); Assert.assertTrue("first keyring import should succeed", result.success()); - result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); + result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); Assert.assertFalse("second keyring import should fail", result.success()); new KeychainDatabase(RuntimeEnvironment.application).clearDatabase(); // and the other way around - result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); + result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); Assert.assertTrue("first keyring import should succeed", result.success()); - result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); + result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); Assert.assertFalse("second keyring import should fail", result.success()); } @@ -90,13 +90,13 @@ public class DatabaseInteractorSaveTest { SaveKeyringResult result; // insert secret, this should fail because of missing self-cert - result = new DatabaseInteractor(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); + result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); Assert.assertFalse("secret keyring import before pubring import should fail", result.success()); // insert pubkey, then seckey - both should succeed - result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(pubkey); + result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(pubkey); Assert.assertTrue("public keyring import should succeed", result.success()); - result = new DatabaseInteractor(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); + result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); Assert.assertTrue("secret keyring import after pubring import should succeed", result.success()); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java index a8a03d390..c1f4da4bf 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java @@ -243,7 +243,7 @@ public class InteropTest { final Uri verifyUri = verify != null ? KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(verify.getMasterKeyId()) : null; - DatabaseInteractor helper = new DatabaseInteractor(RuntimeEnvironment.application) { + DatabaseReadWriteInteractor helper = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) { @Override public CachedPublicKeyRing getCachedPublicKeyRing(Uri queryUri) throws PgpKeyNotFoundException { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java index d72102005..8188023cc 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java @@ -20,8 +20,8 @@ import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainExternalContract.EmailStatus; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseInteractorSaveTest; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; @@ -45,7 +45,7 @@ public class KeychainExternalProviderTest { static final long KEY_ID_PUBLIC = 0x9A282CE2AB44A382L; - DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver(); ApiPermissionHelper apiPermissionHelper; ApiDataAccessObject apiDao; diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/DatabaseInteractorStub.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/DatabaseInteractorStub.java index f2ea24281..4947aff30 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/DatabaseInteractorStub.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/DatabaseInteractorStub.java @@ -21,9 +21,10 @@ import android.content.Context; import android.net.Uri; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; -class DatabaseInteractorStub extends DatabaseInteractor { + +class DatabaseInteractorStub extends DatabaseReadWriteInteractor { public DatabaseInteractorStub(Context context) { super(context); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java index e2756747f..86c908dc0 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java @@ -25,6 +25,7 @@ import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; +import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.util.ProgressScaler; import java.io.ByteArrayInputStream; @@ -50,7 +51,7 @@ public class KeyringTestingHelper { public boolean addKeyring(Collection blobFiles) throws Exception { - DatabaseInteractor databaseInteractor = new DatabaseInteractor(context); + DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(context); byte[] data = TestDataUtil.readAllFully(blobFiles); UncachedKeyRing ring = UncachedKeyRing.decodeFromData(data); @@ -349,7 +350,7 @@ public class KeyringTestingHelper { try { databaseInteractor.getCanonicalizedPublicKeyRing(masterKeyId); throw new AssertionError("Was expecting the previous call to fail!"); - } catch (DatabaseInteractor.NotFoundException expectedException) { + } catch (DatabaseReadWriteInteractor.NotFoundException expectedException) { // good } } From 0277ba1afaf8cf43b46f4008579f919c468f8100 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 20 Feb 2017 17:21:16 +0100 Subject: [PATCH 03/11] replace DatabaseReadWriteInteractor with DatabaseInteractor where possible --- .../ui/RequestKeyPermissionPresenter.java | 5 ++-- .../service/KeyserverSyncAdapterService.java | 17 +++++++------ .../service/PassphraseCacheService.java | 12 ++++----- .../ui/CertifyFingerprintFragment.java | 11 ++++---- .../keychain/ui/CertifyKeyFragment.java | 13 +++++----- .../keychain/ui/CreateKeyActivity.java | 11 ++++---- .../keychain/ui/CreateKeyFinalFragment.java | 3 ++- .../keychain/ui/DecryptFragment.java | 11 ++++---- .../keychain/ui/DeleteKeyDialogActivity.java | 9 +++---- .../keychain/ui/EditIdentitiesFragment.java | 8 +++--- .../keychain/ui/EditKeyFragment.java | 3 ++- .../ui/EncryptModeAsymmetricFragment.java | 14 +++++------ .../keychain/ui/KeyListFragment.java | 3 +-- .../keychain/ui/PassphraseDialogActivity.java | 9 +++---- .../keychain/ui/QrCodeViewActivity.java | 2 +- .../keychain/ui/SafeSlingerActivity.java | 2 +- .../ui/SecurityTokenOperationActivity.java | 23 ++++++++--------- .../keychain/ui/ViewCertActivity.java | 3 +-- .../keychain/ui/ViewKeyActivity.java | 25 +++++++++---------- .../keychain/ui/ViewKeyAdvActivity.java | 6 ++--- .../keychain/ui/ViewKeyAdvShareFragment.java | 13 +++++----- .../ui/adapter/ImportKeysAdapter.java | 18 ++++++------- .../ui/base/BaseSecurityTokenActivity.java | 22 ++++++++-------- .../keychain/ui/linked/LinkedIdWizard.java | 4 +-- 24 files changed, 123 insertions(+), 124 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java index 3fa66fa97..1f6b678c4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java @@ -15,10 +15,9 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; -import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.remote.ApiPermissionHelper; import org.sufficientlysecure.keychain.remote.ApiPermissionHelper.WrongPackageCertificateException; import org.sufficientlysecure.keychain.util.Log; @@ -41,7 +40,7 @@ class RequestKeyPermissionPresenter { PackageManager packageManager = context.getPackageManager(); ApiDataAccessObject apiDataAccessObject = new ApiDataAccessObject(context); ApiPermissionHelper apiPermissionHelper = new ApiPermissionHelper(context, apiDataAccessObject); - DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(context); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(context.getContentResolver()); return new RequestKeyPermissionPresenter(context, apiDataAccessObject, apiPermissionHelper, packageManager, databaseInteractor); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java index 986f6b1e9..87f48310b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java @@ -1,5 +1,12 @@ package org.sufficientlysecure.keychain.service; + +import java.util.ArrayList; +import java.util.GregorianCalendar; +import java.util.Random; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + import android.accounts.Account; import android.app.AlarmManager; import android.app.Notification; @@ -32,25 +39,19 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.KeychainApplication; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; +import org.sufficientlysecure.keychain.network.NetworkReceiver; +import org.sufficientlysecure.keychain.network.orbot.OrbotHelper; import org.sufficientlysecure.keychain.operations.ImportOperation; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.network.NetworkReceiver; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import org.sufficientlysecure.keychain.network.orbot.OrbotHelper; - -import java.util.ArrayList; -import java.util.GregorianCalendar; -import java.util.Random; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; public class KeyserverSyncAdapterService extends Service { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index 254bee246..0a4f11ba1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.Preferences; @@ -224,7 +224,7 @@ public class PassphraseCacheService extends Service { /** * Internal implementation to get cached passphrase. */ - private Passphrase getCachedPassphraseImpl(long masterKeyId, long subKeyId) throws DatabaseReadWriteInteractor.NotFoundException { + private Passphrase getCachedPassphraseImpl(long masterKeyId, long subKeyId) throws DatabaseInteractor.NotFoundException { // on "none" key, just do nothing if (masterKeyId == Constants.key.none) { return null; @@ -245,16 +245,16 @@ public class PassphraseCacheService extends Service { + masterKeyId + ", subKeyId " + subKeyId); // get the type of key (from the database) - CachedPublicKeyRing keyRing = new DatabaseReadWriteInteractor(this).getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing keyRing = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(masterKeyId); SecretKeyType keyType = keyRing.getSecretKeyType(subKeyId); switch (keyType) { case PASSPHRASE_EMPTY: return new Passphrase(""); case UNAVAILABLE: - throw new DatabaseReadWriteInteractor.NotFoundException("secret key for this subkey is not available"); + throw new DatabaseInteractor.NotFoundException("secret key for this subkey is not available"); case GNU_DUMMY: - throw new DatabaseReadWriteInteractor.NotFoundException("secret key for stripped subkey is not available"); + throw new DatabaseInteractor.NotFoundException("secret key for stripped subkey is not available"); } // get cached passphrase @@ -398,7 +398,7 @@ public class PassphraseCacheService extends Service { bundle.putParcelable(EXTRA_PASSPHRASE, passphrase); msg.setData(bundle); } - } catch (DatabaseReadWriteInteractor.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "PassphraseCacheService: Passphrase for unknown key was requested!"); msg.what = MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java index 400edd56c..7c2b63b25 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java @@ -17,6 +17,9 @@ package org.sufficientlysecure.keychain.ui; + +import java.io.IOException; + import android.content.Intent; import android.database.Cursor; import android.graphics.Typeface; @@ -32,16 +35,14 @@ import android.widget.TextView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.experimental.SentenceConfirm; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.ui.base.LoaderFragment; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; -import java.io.IOException; - public class CertifyFingerprintFragment extends LoaderFragment implements LoaderManager.LoaderCallbacks { @@ -213,7 +214,7 @@ public class CertifyFingerprintFragment extends LoaderFragment implements private void certify(Uri dataUri) { long keyId = 0; try { - keyId = new DatabaseReadWriteInteractor(getActivity()) + keyId = new DatabaseInteractor(getActivity().getContentResolver()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java index fa26f1721..a5991fdef 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -18,6 +18,10 @@ package org.sufficientlysecure.keychain.ui; + +import java.util.ArrayList; +import java.util.Date; + import android.app.Activity; import android.content.Intent; import android.graphics.PorterDuff; @@ -35,20 +39,17 @@ import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment; -import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.FormattingUtils; +import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; -import java.util.ArrayList; -import java.util.Date; - public class CertifyKeyFragment extends CachingCryptoOperationFragment { @@ -68,7 +69,7 @@ public class CertifyKeyFragment .getLongExtra(CertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, Constants.key.none); if (certifyKeyId != Constants.key.none) { try { - CachedPublicKeyRing key = (new DatabaseReadWriteInteractor(getActivity())) + CachedPublicKeyRing key = (new DatabaseInteractor(getActivity().getContentResolver())) .getCachedPublicKeyRing(certifyKeyId); if (key.canCertify()) { mCertifyKeySpinner.setPreSelectedKeyId(certifyKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java index fffcad7a5..9693aba1a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java @@ -17,6 +17,10 @@ package org.sufficientlysecure.keychain.ui; + +import java.io.IOException; +import java.util.ArrayList; + import android.content.Intent; import android.nfc.NfcAdapter; import android.os.Bundle; @@ -29,7 +33,7 @@ import android.support.v4.app.TaskStackBuilder; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.securitytoken.KeyFormat; import org.sufficientlysecure.keychain.ui.base.BaseSecurityTokenActivity; @@ -37,9 +41,6 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.Preferences; -import java.io.IOException; -import java.util.ArrayList; - public class CreateKeyActivity extends BaseSecurityTokenActivity { public static final String EXTRA_NAME = "name"; @@ -180,7 +181,7 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity { if (containsKeys(mScannedFingerprints)) { try { long masterKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mScannedFingerprints); - CachedPublicKeyRing ring = new DatabaseReadWriteInteractor(this).getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing ring = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(masterKeyId); ring.getMasterKeyId(); Intent intent = new Intent(this, ViewKeyActivity.class); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index 1248c8f69..496e3ec75 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -43,6 +43,7 @@ import org.sufficientlysecure.keychain.operations.results.UploadResult; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; @@ -411,7 +412,7 @@ public class CreateKeyFinalFragment extends Fragment { CreateKeyActivity activity = (CreateKeyActivity) getActivity(); final SaveKeyringParcel changeKeyringParcel; - CachedPublicKeyRing key = (new DatabaseReadWriteInteractor(activity)) + CachedPublicKeyRing key = (new DatabaseInteractor(activity.getContentResolver())) .getCachedPublicKeyRing(saveKeyResult.mMasterKeyId); try { changeKeyringParcel = new SaveKeyringParcel(key.getMasterKeyId(), key.getFingerprint()); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index f065df87e..4ad66df6a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -17,6 +17,9 @@ package org.sufficientlysecure.keychain.ui; + +import java.util.ArrayList; + import android.app.Activity; import android.content.Intent; import android.database.Cursor; @@ -40,12 +43,13 @@ import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.util.OpenPgpUtils; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; @@ -54,11 +58,8 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify.Style; -import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver; import org.sufficientlysecure.keychain.util.Preferences; -import java.util.ArrayList; - public abstract class DecryptFragment extends Fragment implements LoaderManager.LoaderCallbacks { public static final int LOADER_ID_UNIFIED = 0; @@ -192,7 +193,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager. try { Intent viewKeyIntent = new Intent(getActivity(), ViewKeyActivity.class); - long masterKeyId = new DatabaseReadWriteInteractor(getActivity()).getCachedPublicKeyRing( + long masterKeyId = new DatabaseInteractor(getActivity().getContentResolver()).getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId) ).getMasterKeyId(); viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId)); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java index 3e776d4af..6a02eb0de 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java @@ -41,7 +41,6 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver; import org.sufficientlysecure.keychain.operations.results.DeleteResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.RevokeResult; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.DeleteKeyringParcel; @@ -90,7 +89,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { if (mMasterKeyIds.length == 1 && mHasSecret) { // if mMasterKeyIds.length == 0 we let the DeleteOperation respond try { - HashMap data = new DatabaseReadWriteInteractor(this).getUnifiedData( + HashMap data = new DatabaseInteractor(getContentResolver()).getUnifiedData( mMasterKeyIds[0], new String[]{ KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.IS_REVOKED @@ -113,7 +112,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { } else { showRevokeDeleteDialog(name); } - } catch (DatabaseReadWriteInteractor.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "Secret key to delete not found at DeleteKeyDialogActivity for " + mMasterKeyIds[0], e); @@ -270,7 +269,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { long masterKeyId = masterKeyIds[0]; try { - HashMap data = new DatabaseReadWriteInteractor(activity).getUnifiedData( + HashMap data = new DatabaseInteractor(activity.getContentResolver()).getUnifiedData( masterKeyId, new String[]{ KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.HAS_ANY_SECRET @@ -294,7 +293,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { } else { mMainMessage.setText(getString(R.string.public_key_deletetion_confirmation, name)); } - } catch (DatabaseReadWriteInteractor.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { dismiss(); return null; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java index ef998e5d4..6940f78c6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java @@ -41,6 +41,7 @@ import android.widget.ListView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; +import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver; import org.sufficientlysecure.keychain.operations.results.EditKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; @@ -49,10 +50,10 @@ import org.sufficientlysecure.keychain.operations.results.UploadResult; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; @@ -62,7 +63,6 @@ import org.sufficientlysecure.keychain.ui.dialog.AddUserIdDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.EditUserIdDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver; import org.sufficientlysecure.keychain.util.Preferences; public class EditIdentitiesFragment extends Fragment @@ -170,7 +170,7 @@ public class EditIdentitiesFragment extends Fragment try { Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri); CachedPublicKeyRing keyRing = - new DatabaseReadWriteInteractor(getActivity()).getCachedPublicKeyRing(secretUri); + new DatabaseInteractor(getActivity().getContentResolver()).getCachedPublicKeyRing(secretUri); long masterKeyId = keyRing.getMasterKeyId(); // check if this is a master secret key we can work with diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index 902858ff6..891330659 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -48,6 +48,7 @@ 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.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; @@ -203,7 +204,7 @@ public class EditKeyFragment extends QueueingCryptoOperationFragment return; } - DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(activity); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(activity.getContentResolver()); Cursor cursor = databaseInteractor.getContentResolver().query( KeyRings.buildUnifiedKeyRingsUri(), new String[]{ KeyRings.FINGERPRINT diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java index 67fdf65ce..b2f6dcc01 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java @@ -57,7 +57,6 @@ import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; @@ -113,7 +112,7 @@ public class PassphraseDialogActivity extends FragmentActivity { // handle empty passphrases by directly returning an empty crypto input parcel try { CachedPublicKeyRing pubRing = - new DatabaseReadWriteInteractor(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId()); + new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(requiredInput.getMasterKeyId()); // use empty passphrase for empty passphrase if (pubRing.getSecretKeyType(requiredInput.getSubKeyId()) == SecretKeyType.PASSPHRASE_EMPTY) { // also return passphrase back to activity @@ -232,7 +231,7 @@ public class PassphraseDialogActivity extends FragmentActivity { try { long subKeyId = mRequiredInput.getSubKeyId(); - DatabaseInteractor helper = new DatabaseReadWriteInteractor(activity); + DatabaseInteractor helper = new DatabaseInteractor(activity.getContentResolver()); CachedPublicKeyRing cachedPublicKeyRing = helper.getCachedPublicKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); // yes the inner try/catch block is necessary, otherwise the final variable @@ -267,7 +266,7 @@ public class PassphraseDialogActivity extends FragmentActivity { throw new AssertionError("Unhandled SecretKeyType (should not happen)"); } - } catch (PgpKeyNotFoundException | DatabaseReadWriteInteractor.NotFoundException e) { + } catch (PgpKeyNotFoundException | DatabaseInteractor.NotFoundException e) { alert.setTitle(R.string.title_key_not_found); alert.setMessage(getString(R.string.key_not_found, mRequiredInput.getSubKeyId())); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @@ -458,7 +457,7 @@ public class PassphraseDialogActivity extends FragmentActivity { Long subKeyId = mRequiredInput.getSubKeyId(); CanonicalizedSecretKeyRing secretKeyRing = - new DatabaseReadWriteInteractor(getActivity()).getCanonicalizedSecretKeyRing( + new DatabaseInteractor(getActivity().getContentResolver()).getCanonicalizedSecretKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); CanonicalizedSecretKey secretKeyToUnlock = secretKeyRing.getSecretKey(subKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java index 2369a7f08..1c10867af 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java @@ -75,7 +75,7 @@ public class QrCodeViewActivity extends BaseActivity { } }); - DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(this); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(getContentResolver()); try { byte[] blob = (byte[]) databaseInteractor.getGenericData( KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri), diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java index 91c2645d9..e2fe9db05 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java @@ -106,7 +106,7 @@ public class SafeSlingerActivity extends BaseActivity // retrieve public key blob and start SafeSlinger Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId); try { - byte[] keyBlob = (byte[]) new DatabaseReadWriteInteractor(this).getGenericData( + byte[] keyBlob = (byte[]) new DatabaseInteractor(getContentResolver()).getGenericData( uri, KeychainContract.KeyRingData.KEY_RING_DATA, DatabaseInteractor.FIELD_TYPE_BLOB); Intent slingerIntent = new Intent(this, ExchangeActivity.class); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java index adc91fe8d..e61a8b495 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java @@ -21,6 +21,11 @@ package org.sufficientlysecure.keychain.ui; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Arrays; + import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; @@ -30,14 +35,14 @@ import android.widget.Button; import android.widget.TextView; import android.widget.ViewAnimator; +import nordpol.android.NfcGuideView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; -import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.securitytoken.KeyType; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -49,12 +54,6 @@ import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.OrientationUtils; import org.sufficientlysecure.keychain.util.Passphrase; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Arrays; - -import nordpol.android.NfcGuideView; - /** * This class provides a communication interface to OpenPGP applications on ISO SmartCard compliant * NFC devices. @@ -194,12 +193,12 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity { throw new IOException(getString(R.string.error_wrong_security_token)); } - DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(this); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(getContentResolver()); CanonicalizedPublicKeyRing publicKeyRing; try { publicKeyRing = databaseInteractor.getCanonicalizedPublicKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mRequiredInput.getMasterKeyId())); - } catch (DatabaseReadWriteInteractor.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { throw new IOException("Couldn't find subkey for key to token operation."); } @@ -233,13 +232,13 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity { mSecurityTokenHelper.setPin(new Passphrase("123456")); mSecurityTokenHelper.setAdminPin(new Passphrase("12345678")); - DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(this); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(getContentResolver()); CanonicalizedSecretKeyRing secretKeyRing; try { secretKeyRing = databaseInteractor.getCanonicalizedSecretKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mRequiredInput.getMasterKeyId()) ); - } catch (DatabaseReadWriteInteractor.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { throw new IOException("Couldn't find subkey for key to token operation."); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java index 734f59b2f..3e3099dbc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java @@ -38,7 +38,6 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.WrappedSignature; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; @@ -185,7 +184,7 @@ public class ViewCertActivity extends BaseActivity Intent viewIntent = new Intent(ViewCertActivity.this, ViewKeyActivity.class); try { - DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(ViewCertActivity.this); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(ViewCertActivity.this.getContentResolver()); long signerMasterKeyId = databaseInteractor.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId(); viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId)); 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 674978452..d0cb2fe11 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -19,6 +19,11 @@ package org.sufficientlysecure.keychain.ui; +import java.io.IOException; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.util.ArrayList; + import android.animation.ArgbEvaluator; import android.animation.ObjectAnimator; import android.annotation.SuppressLint; @@ -72,11 +77,10 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; -import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeychainContract; +import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -98,11 +102,6 @@ import org.sufficientlysecure.keychain.util.NfcHelper; import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.Preferences; -import java.io.IOException; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.util.ArrayList; - public class ViewKeyActivity extends BaseSecurityTokenActivity implements LoaderManager.LoaderCallbacks, @@ -186,7 +185,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mDatabaseInteractor = new DatabaseReadWriteInteractor(this); + mDatabaseInteractor = new DatabaseInteractor(getContentResolver()); mImportOpHelper = new CryptoOperationHelper<>(1, this, this, null); setTitle(null); @@ -401,7 +400,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements case R.id.menu_key_view_refresh: { try { updateFromKeyserver(mDataUri, mDatabaseInteractor); - } catch (DatabaseReadWriteInteractor.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Notify.create(this, R.string.error_key_not_found, Notify.Style.ERROR).show(); } return true; @@ -742,7 +741,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements return; } try { - long keyId = new DatabaseReadWriteInteractor(this) + long keyId = new DatabaseInteractor(getContentResolver()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); long[] encryptionKeyIds = new long[]{keyId}; @@ -766,7 +765,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements private void startSafeSlinger(Uri dataUri) { long keyId = 0; try { - keyId = new DatabaseReadWriteInteractor(this) + keyId = new DatabaseInteractor(getContentResolver()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { @@ -1120,7 +1119,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements private void updateFromKeyserver(Uri dataUri, DatabaseInteractor databaseInteractor) - throws DatabaseReadWriteInteractor.NotFoundException { + throws DatabaseInteractor.NotFoundException { mIsRefreshing = true; mRefreshItem.setEnabled(false); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java index 9e72e5867..34cf578ed 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java @@ -40,13 +40,11 @@ import android.view.animation.OvershootInterpolator; import android.widget.Toast; import com.astuetz.PagerSlidingTabStrip; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.operations.results.OperationResult; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; -import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -89,7 +87,7 @@ public class ViewKeyAdvActivity extends BaseActivity implements } }); - mDatabaseInteractor = new DatabaseReadWriteInteractor(this); + mDatabaseInteractor = new DatabaseInteractor(getContentResolver()); mViewPager = (ViewPager) findViewById(R.id.pager); mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tab_layout); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index f7fb131f2..78ed3b30c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -26,6 +26,7 @@ import android.app.Activity; import android.app.ActivityOptions; import android.content.ClipData; import android.content.ClipboardManager; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.database.Cursor; @@ -56,7 +57,6 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; @@ -94,7 +94,8 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements View root = super.onCreateView(inflater, superContainer, savedInstanceState); View view = inflater.inflate(R.layout.view_key_adv_share_fragment, getContainer()); - DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(ViewKeyAdvShareFragment.this.getActivity()); + ContentResolver contentResolver = ViewKeyAdvShareFragment.this.getActivity().getContentResolver(); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(contentResolver); mNfcHelper = new NfcHelper(getActivity(), databaseInteractor); mFingerprintView = (TextView) view.findViewById(R.id.view_key_fingerprint); @@ -201,7 +202,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements private void startSafeSlinger(Uri dataUri) { long keyId = 0; try { - keyId = new DatabaseReadWriteInteractor(getActivity()) + keyId = new DatabaseInteractor(getActivity().getContentResolver()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { @@ -217,7 +218,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements if (activity == null || mFingerprint == null) { return; } - DatabaseInteractor databaseInteractor = new DatabaseReadWriteInteractor(activity); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(activity.getContentResolver()); try { String content = databaseInteractor.getKeyRingAsArmoredString( @@ -274,7 +275,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements } catch (PgpGeneralException | IOException e) { Log.e(Constants.TAG, "error processing key!", e); Notify.create(activity, R.string.error_key_processing, Notify.Style.ERROR).show(); - } catch (DatabaseReadWriteInteractor.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); Notify.create(activity, R.string.error_key_not_found, Notify.Style.ERROR).show(); } @@ -458,7 +459,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements private void uploadToKeyserver() { long keyId; try { - keyId = new DatabaseReadWriteInteractor(getActivity()) + keyId = new DatabaseInteractor(getActivity().getContentResolver()) .getCachedPublicKeyRing(mDataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index b6eb61adf..22808ab8d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -17,6 +17,12 @@ package org.sufficientlysecure.keychain.ui.adapter; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + import android.content.Intent; import android.databinding.DataBindingUtil; import android.support.v4.app.FragmentActivity; @@ -40,9 +46,8 @@ import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; -import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.ViewKeyActivity; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; @@ -51,11 +56,6 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableFileCache; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - public class ImportKeysAdapter extends RecyclerView.Adapter implements ImportKeysResultListener { @@ -75,7 +75,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter data) { @@ -96,7 +96,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter 0; - } catch (DatabaseReadWriteInteractor.NotFoundException | PgpKeyNotFoundException ignored) { + } catch (DatabaseInteractor.NotFoundException | PgpKeyNotFoundException ignored) { } mKeyStates[i] = keyState; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java index 5fc22ccd0..fa6dd17cd 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java @@ -21,6 +21,9 @@ package org.sufficientlysecure.keychain.ui.base; + +import java.io.IOException; + import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -33,21 +36,24 @@ import android.nfc.TagLostException; import android.os.AsyncTask; import android.os.Bundle; +import nordpol.android.OnDiscoveredTagListener; +import nordpol.android.TagDispatcher; +import nordpol.android.TagDispatcherBuilder; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.service.PassphraseCacheService; -import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; -import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.securitytoken.CardException; import org.sufficientlysecure.keychain.securitytoken.NfcTransport; import org.sufficientlysecure.keychain.securitytoken.SecurityTokenHelper; import org.sufficientlysecure.keychain.securitytoken.Transport; import org.sufficientlysecure.keychain.securitytoken.UsbConnectionDispatcher; import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransport; +import org.sufficientlysecure.keychain.service.PassphraseCacheService; +import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; +import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.ui.CreateKeyActivity; import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity; import org.sufficientlysecure.keychain.ui.ViewKeyActivity; @@ -59,12 +65,6 @@ import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Passphrase; -import java.io.IOException; - -import nordpol.android.OnDiscoveredTagListener; -import nordpol.android.TagDispatcher; -import nordpol.android.TagDispatcherBuilder; - public abstract class BaseSecurityTokenActivity extends BaseActivity implements OnDiscoveredTagListener, UsbConnectionDispatcher.OnDiscoveredUsbDeviceListener { public static final int REQUEST_CODE_PIN = 1; @@ -105,7 +105,7 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity final long subKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mSecurityTokenFingerprints); try { - CachedPublicKeyRing ring = new DatabaseReadWriteInteractor(this).getCachedPublicKeyRing( + CachedPublicKeyRing ring = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); long masterKeyId = ring.getMasterKeyId(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java index a7b8558b2..b59ec7499 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java @@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.ui.base.BaseActivity; @@ -58,7 +58,7 @@ public class LinkedIdWizard extends BaseActivity { try { Uri uri = getIntent().getData(); uri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(uri); - CachedPublicKeyRing ring = new DatabaseReadWriteInteractor(this).getCachedPublicKeyRing(uri); + CachedPublicKeyRing ring = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(uri); if (!ring.hasAnySecret()) { Log.e(Constants.TAG, "Linked Identities can only be added to secret keys!"); finish(); From c2b9af077a1dfff5617cd53b204a7d01a4745625 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 20 Feb 2017 18:17:15 +0100 Subject: [PATCH 04/11] replace calls to getGenericData with getCachedPublicKeyRing equivalents --- .../pgp/CanonicalizedSecretKeyRing.java | 6 ++--- .../provider/CachedPublicKeyRing.java | 9 ++++++++ .../keychain/provider/DatabaseInteractor.java | 8 +++---- .../keychain/ui/QrCodeViewActivity.java | 7 +++--- .../keychain/ui/SafeSlingerActivity.java | 23 +++++++++---------- .../keychain/ui/ViewKeyActivity.java | 8 +++---- .../keychain/util/NfcHelper.java | 20 ++++++++-------- 7 files changed, 42 insertions(+), 39 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKeyRing.java index 6ed225a83..3769bd83c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKeyRing.java @@ -63,15 +63,15 @@ public class CanonicalizedSecretKeyRing extends CanonicalizedKeyRing { } public CanonicalizedSecretKey getSecretKey() { - return new CanonicalizedSecretKey(this, mRing.getSecretKey()); + return new CanonicalizedSecretKey(this, getRing().getSecretKey()); } public CanonicalizedSecretKey getSecretKey(long id) { - return new CanonicalizedSecretKey(this, mRing.getSecretKey(id)); + return new CanonicalizedSecretKey(this, getRing().getSecretKey(id)); } public IterableIterator secretKeyIterator() { - final Iterator it = mRing.getSecretKeys(); + final Iterator it = getRing().getSecretKeys(); return new IterableIterator<>(new Iterator() { @Override public boolean hasNext() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java index 6bbcc932e..69431e6d6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java @@ -25,6 +25,7 @@ import org.sufficientlysecure.keychain.Constants; 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.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; @@ -237,4 +238,12 @@ public class CachedPublicKeyRing extends KeyRing { return SecretKeyType.fromNum(((Long) data).intValue()); } + public byte[] getEncoded() throws PgpKeyNotFoundException { + try { + return (byte[]) mDatabaseInteractor.getGenericData(mUri, KeyRingData.KEY_RING_DATA, + DatabaseInteractor.FIELD_TYPE_BLOB); + } catch(DatabaseReadWriteInteractor.NotFoundException e) { + throw new PgpKeyNotFoundException(e); + } + } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java index 31b0eb090..0b5fe964e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java @@ -69,7 +69,7 @@ public class DatabaseInteractor { mLog = new OperationLog(); } - public Object getGenericData(Uri uri, String column, int type) throws NotFoundException { + Object getGenericData(Uri uri, String column, int type) throws NotFoundException { Object result = getGenericData(uri, new String[]{column}, new int[]{type}, null).get(column); if (result == null) { throw new NotFoundException(); @@ -77,17 +77,17 @@ public class DatabaseInteractor { return result; } - public Object getGenericData(Uri uri, String column, int type, String selection) + Object getGenericData(Uri uri, String column, int type, String selection) throws NotFoundException { return getGenericData(uri, new String[]{column}, new int[]{type}, selection).get(column); } - public HashMap getGenericData(Uri uri, String[] proj, int[] types) + private HashMap getGenericData(Uri uri, String[] proj, int[] types) throws NotFoundException { return getGenericData(uri, proj, types, null); } - public HashMap getGenericData(Uri uri, String[] proj, int[] types, String selection) + private HashMap getGenericData(Uri uri, String[] proj, int[] types, String selection) throws NotFoundException { Cursor cursor = mContentResolver.query(uri, proj, selection, null, null); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java index 1c10867af..0592adf3d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java @@ -28,6 +28,7 @@ import android.widget.ImageView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; @@ -77,9 +78,7 @@ public class QrCodeViewActivity extends BaseActivity { DatabaseInteractor databaseInteractor = new DatabaseInteractor(getContentResolver()); try { - byte[] blob = (byte[]) databaseInteractor.getGenericData( - KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri), - KeychainContract.KeyRings.FINGERPRINT, DatabaseInteractor.FIELD_TYPE_BLOB); + byte[] blob = databaseInteractor.getCachedPublicKeyRing(dataUri).getFingerprint(); if (blob == null) { Log.e(Constants.TAG, "key not found!"); Notify.create(this, R.string.error_key_not_found, Style.ERROR).show(); @@ -103,7 +102,7 @@ public class QrCodeViewActivity extends BaseActivity { mQrCode.setImageBitmap(scaled); } }); - } catch (DatabaseReadWriteInteractor.NotFoundException e) { + } catch (PgpKeyNotFoundException e) { Log.e(Constants.TAG, "key not found!", e); Notify.create(this, R.string.error_key_not_found, Style.ERROR).show(); ActivityCompat.finishAfterTransition(QrCodeViewActivity.this); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java index e2fe9db05..dcdbc841c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java @@ -17,6 +17,10 @@ package org.sufficientlysecure.keychain.ui; + +import java.io.IOException; +import java.util.ArrayList; + import android.annotation.TargetApi; import android.content.Intent; import android.graphics.PorterDuff; @@ -27,15 +31,18 @@ import android.view.View; import android.widget.ImageView; import android.widget.NumberPicker; +import edu.cmu.cylab.starslinger.exchange.ExchangeActivity; +import edu.cmu.cylab.starslinger.exchange.ExchangeConfig; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.operations.ImportOperation; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; -import org.sufficientlysecure.keychain.provider.KeychainContract; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; @@ -43,13 +50,6 @@ import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableFileCache; -import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver; - -import java.io.IOException; -import java.util.ArrayList; - -import edu.cmu.cylab.starslinger.exchange.ExchangeActivity; -import edu.cmu.cylab.starslinger.exchange.ExchangeConfig; @TargetApi(Build.VERSION_CODES.HONEYCOMB) public class SafeSlingerActivity extends BaseActivity @@ -106,8 +106,7 @@ public class SafeSlingerActivity extends BaseActivity // retrieve public key blob and start SafeSlinger Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId); try { - byte[] keyBlob = (byte[]) new DatabaseInteractor(getContentResolver()).getGenericData( - uri, KeychainContract.KeyRingData.KEY_RING_DATA, DatabaseInteractor.FIELD_TYPE_BLOB); + byte[] keyBlob = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(uri).getEncoded(); Intent slingerIntent = new Intent(this, ExchangeActivity.class); @@ -115,7 +114,7 @@ public class SafeSlingerActivity extends BaseActivity slingerIntent.putExtra(ExchangeConfig.extra.USER_DATA, keyBlob); slingerIntent.putExtra(ExchangeConfig.extra.HOST_NAME, Constants.SAFESLINGER_SERVER); startActivityForResult(slingerIntent, REQUEST_CODE_SAFE_SLINGER); - } catch (DatabaseReadWriteInteractor.NotFoundException e) { + } catch (PgpKeyNotFoundException e) { Log.e(Constants.TAG, "personal key not found", e); } } 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 d0cb2fe11..3b6497a77 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -400,7 +400,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements case R.id.menu_key_view_refresh: { try { updateFromKeyserver(mDataUri, mDatabaseInteractor); - } catch (DatabaseInteractor.NotFoundException e) { + } catch (PgpKeyNotFoundException e) { Notify.create(this, R.string.error_key_not_found, Notify.Style.ERROR).show(); } return true; @@ -1119,16 +1119,14 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements private void updateFromKeyserver(Uri dataUri, DatabaseInteractor databaseInteractor) - throws DatabaseInteractor.NotFoundException { + throws PgpKeyNotFoundException { mIsRefreshing = true; mRefreshItem.setEnabled(false); mRefreshItem.setActionView(mRefresh); mRefresh.startAnimation(mRotate); - byte[] blob = (byte[]) databaseInteractor.getGenericData( - KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri), - KeychainContract.Keys.FINGERPRINT, DatabaseInteractor.FIELD_TYPE_BLOB); + byte[] blob = databaseInteractor.getCachedPublicKeyRing(dataUri).getFingerprint(); String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob); ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null, null); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java index 908e9db3c..9d40cb725 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java @@ -18,6 +18,9 @@ package org.sufficientlysecure.keychain.util; + +import java.lang.ref.WeakReference; + import android.annotation.TargetApi; import android.app.Activity; import android.content.Intent; @@ -35,13 +38,11 @@ import android.provider.Settings; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; -import org.sufficientlysecure.keychain.provider.KeychainContract; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.ui.util.Notify; -import java.lang.ref.WeakReference; - /** * This class contains NFC functionality that can be shared across Fragments or Activities. */ @@ -127,13 +128,10 @@ public class NfcHelper { new AsyncTask() { protected Void doInBackground(Void... unused) { try { - Uri blobUri = - KeychainContract.KeyRingData.buildPublicKeyRingUri(dataUri); - mNfcKeyringBytes = (byte[]) mDatabaseInteractor.getGenericData( - blobUri, - KeychainContract.KeyRingData.KEY_RING_DATA, - DatabaseInteractor.FIELD_TYPE_BLOB); - } catch (DatabaseReadWriteInteractor.NotFoundException e) { + long masterKeyId = mDatabaseInteractor.getCachedPublicKeyRing(dataUri) + .extractOrGetMasterKeyId(); + mNfcKeyringBytes = mDatabaseInteractor.getPublicKeyRingData(masterKeyId); + } catch (NotFoundException | PgpKeyNotFoundException e) { Log.e(Constants.TAG, "key not found!", e); } From 623964701bd6493e68d5f6a1f070ee17b27be1e3 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 20 Feb 2017 21:32:54 +0100 Subject: [PATCH 05/11] get rid of direct query for blob from backup operation --- .../keychain/operations/BackupOperation.java | 42 +++++++++---------- .../keychain/provider/DatabaseInteractor.java | 10 +++++ 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java index 7534ee2bf..dacfc427f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java @@ -45,13 +45,18 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.LogTyp import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult; import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; +import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; +import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.PgpSignEncryptData; import org.sufficientlysecure.keychain.pgp.PgpSignEncryptInputParcel; import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; @@ -77,14 +82,10 @@ public class BackupOperation extends BaseOperation { private static final String[] PROJECTION = new String[] { KeyRings.MASTER_KEY_ID, - KeyRings.PUBKEY_DATA, - KeyRings.PRIVKEY_DATA, KeyRings.HAS_ANY_SECRET }; private static final int INDEX_MASTER_KEY_ID = 0; - private static final int INDEX_PUBKEY_DATA = 1; - private static final int INDEX_SECKEY_DATA = 2; - private static final int INDEX_HAS_ANY_SECRET = 3; + private static final int INDEX_HAS_ANY_SECRET = 1; public BackupOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { @@ -230,16 +231,16 @@ public class BackupOperation extends BaseOperation { // For each public masterKey id while (!cursor.isAfterLast()) { - long keyId = cursor.getLong(INDEX_MASTER_KEY_ID); - log.add(LogType.MSG_BACKUP_PUBLIC, 1, KeyFormattingUtils.beautifyKeyId(keyId)); + long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID); + log.add(LogType.MSG_BACKUP_PUBLIC, 1, KeyFormattingUtils.beautifyKeyId(masterKeyId)); - if (writePublicKeyToStream(log, outStream, cursor)) { + if (writePublicKeyToStream(masterKeyId, log, outStream)) { okPublic += 1; boolean hasSecret = cursor.getInt(INDEX_HAS_ANY_SECRET) > 0; if (exportSecret && hasSecret) { - log.add(LogType.MSG_BACKUP_SECRET, 2, KeyFormattingUtils.beautifyKeyId(keyId)); - if (writeSecretKeyToStream(log, outStream, cursor)) { + log.add(LogType.MSG_BACKUP_SECRET, 2, KeyFormattingUtils.beautifyKeyId(masterKeyId)); + if (writeSecretKeyToStream(masterKeyId, log, outStream)) { okSecret += 1; } } @@ -267,17 +268,16 @@ public class BackupOperation extends BaseOperation { return true; } - private boolean writePublicKeyToStream(OperationLog log, OutputStream outStream, Cursor cursor) - throws IOException { + private boolean writePublicKeyToStream(long masterKeyId, OperationLog log, OutputStream outStream) throws IOException { ArmoredOutputStream arOutStream = null; try { arOutStream = new ArmoredOutputStream(outStream); - byte[] data = cursor.getBlob(INDEX_PUBKEY_DATA); - CanonicalizedKeyRing ring = UncachedKeyRing.decodeFromData(data).canonicalize(log, 2, true); + byte[] data = mDatabaseInteractor.getPublicKeyRingData(masterKeyId); + UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(data); + CanonicalizedPublicKeyRing ring = (CanonicalizedPublicKeyRing) uncachedKeyRing.canonicalize(log, 2, true); ring.encode(arOutStream); - - } catch (PgpGeneralException e) { + } catch (PgpGeneralException | NotFoundException e) { log.add(LogType.MSG_UPLOAD_ERROR_IO, 2); } finally { if (arOutStream != null) { @@ -287,17 +287,17 @@ public class BackupOperation extends BaseOperation { return true; } - private boolean writeSecretKeyToStream(OperationLog log, OutputStream outStream, Cursor cursor) + private boolean writeSecretKeyToStream(long masterKeyId, OperationLog log, OutputStream outStream) throws IOException { ArmoredOutputStream arOutStream = null; try { arOutStream = new ArmoredOutputStream(outStream); - byte[] data = cursor.getBlob(INDEX_SECKEY_DATA); - CanonicalizedKeyRing ring = UncachedKeyRing.decodeFromData(data).canonicalize(log, 2, true); + byte[] data = mDatabaseInteractor.getSecretKeyRingData(masterKeyId); + UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(data); + CanonicalizedSecretKeyRing ring = (CanonicalizedSecretKeyRing) uncachedKeyRing.canonicalize(log, 2, true); ring.encode(arOutStream); - - } catch (PgpGeneralException e) { + } catch (PgpGeneralException | NotFoundException e) { log.add(LogType.MSG_UPLOAD_ERROR_IO, 2); } finally { if (arOutStream != null) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java index 0b5fe964e..be3e9154d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java @@ -238,6 +238,16 @@ public class DatabaseInteractor { return mContentResolver; } + public byte[] getPublicKeyRingData(long masterKeyId) throws NotFoundException { + return (byte[]) getGenericData(KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId), + KeyRingData.KEY_RING_DATA, FIELD_TYPE_BLOB); + } + + public byte[] getSecretKeyRingData(long masterKeyId) throws NotFoundException { + return (byte[]) getGenericData(KeychainContract.KeyRingData.buildSecretKeyRingUri(masterKeyId), + KeyRingData.KEY_RING_DATA, FIELD_TYPE_BLOB); + } + public static class NotFoundException extends Exception { public NotFoundException() { } From 2bc05a2cd57e6001bf5b8bebc5fed6739ddb8c00 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 20 Feb 2017 21:57:38 +0100 Subject: [PATCH 06/11] focus all read access for key ring data into DatabaseInteractor methods --- .../keychain/operations/BackupOperation.java | 3 - .../pgp/CanonicalizedSecretKeyRing.java | 3 +- .../provider/CachedPublicKeyRing.java | 3 +- .../keychain/provider/DatabaseInteractor.java | 88 +++++++++---------- .../provider/DatabaseReadWriteInteractor.java | 30 ++++--- .../keychain/provider/KeychainContract.java | 2 - .../keychain/provider/KeychainDatabase.java | 11 +-- .../keychain/provider/KeychainProvider.java | 24 +---- .../keychain/ui/ViewKeyAdvShareFragment.java | 10 +-- .../keychain/pgp/PgpKeyOperationTest.java | 18 ++-- .../pgp/UncachedKeyringMergeTest.java | 10 +-- 11 files changed, 91 insertions(+), 111 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java index dacfc427f..6b4d1732b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java @@ -44,7 +44,6 @@ import org.sufficientlysecure.keychain.operations.results.ExportResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult; -import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.PgpSignEncryptData; @@ -53,10 +52,8 @@ import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; -import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKeyRing.java index 3769bd83c..3178bfb95 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKeyRing.java @@ -25,7 +25,6 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory; import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; @@ -42,7 +41,7 @@ public class CanonicalizedSecretKeyRing extends CanonicalizedKeyRing { mRing = ring; } - public CanonicalizedSecretKeyRing(byte[] blob, boolean isRevoked, int verified) + public CanonicalizedSecretKeyRing(byte[] blob, int verified) { super(verified); JcaPGPObjectFactory factory = new JcaPGPObjectFactory(blob); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java index 69431e6d6..c0336b866 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java @@ -240,8 +240,7 @@ public class CachedPublicKeyRing extends KeyRing { public byte[] getEncoded() throws PgpKeyNotFoundException { try { - return (byte[]) mDatabaseInteractor.getGenericData(mUri, KeyRingData.KEY_RING_DATA, - DatabaseInteractor.FIELD_TYPE_BLOB); + return mDatabaseInteractor.getPublicKeyRingData(getMasterKeyId()); } catch(DatabaseReadWriteInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java index be3e9154d..8b0054ed4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java @@ -10,12 +10,10 @@ import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri; -import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; -import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; @@ -23,7 +21,6 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; -import org.sufficientlysecure.keychain.util.Log; public class DatabaseInteractor { @@ -148,19 +145,55 @@ public class DatabaseInteractor { } public CanonicalizedPublicKeyRing getCanonicalizedPublicKeyRing(long id) throws NotFoundException { - return (CanonicalizedPublicKeyRing) getCanonicalizedKeyRing(KeyRings.buildUnifiedKeyRingUri(id), false); + return getCanonicalizedPublicKeyRing(KeyRings.buildUnifiedKeyRingUri(id)); } public CanonicalizedPublicKeyRing getCanonicalizedPublicKeyRing(Uri queryUri) throws NotFoundException { - return (CanonicalizedPublicKeyRing) getCanonicalizedKeyRing(queryUri, false); + Cursor cursor = mContentResolver.query(queryUri, + new String[] { KeyRings.MASTER_KEY_ID, KeyRings.VERIFIED }, null, null, null); + try { + if (cursor != null && cursor.moveToFirst()) { + long masterKeyId = cursor.getLong(0); + int verified = cursor.getInt(1); + + byte[] publicKeyData = getPublicKeyRingData(masterKeyId); + return new CanonicalizedPublicKeyRing(publicKeyData, verified); + } else { + throw new NotFoundException("Key not found!"); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } } public CanonicalizedSecretKeyRing getCanonicalizedSecretKeyRing(long id) throws NotFoundException { - return (CanonicalizedSecretKeyRing) getCanonicalizedKeyRing(KeyRings.buildUnifiedKeyRingUri(id), true); + return getCanonicalizedSecretKeyRing(KeyRings.buildUnifiedKeyRingUri(id)); } public CanonicalizedSecretKeyRing getCanonicalizedSecretKeyRing(Uri queryUri) throws NotFoundException { - return (CanonicalizedSecretKeyRing) getCanonicalizedKeyRing(queryUri, true); + Cursor cursor = mContentResolver.query(queryUri, + new String[] { KeyRings.MASTER_KEY_ID, KeyRings.VERIFIED, KeyRings.HAS_ANY_SECRET }, null, null, null); + try { + if (cursor != null && cursor.moveToFirst()) { + long masterKeyId = cursor.getLong(0); + int verified = cursor.getInt(1); + int hasAnySecret = cursor.getInt(2); + if (hasAnySecret == 0) { + throw new NotFoundException("No secret key available or unknown public key!"); + } + + byte[] secretKeyData = getSecretKeyRingData(masterKeyId); + return new CanonicalizedSecretKeyRing(secretKeyData, verified); + } else { + throw new NotFoundException("Key not found!"); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } } public ArrayList getConfirmedUserIds(long masterKeyId) throws NotFoundException { @@ -184,53 +217,18 @@ public class DatabaseInteractor { } } - private KeyRing getCanonicalizedKeyRing(Uri queryUri, boolean secret) throws NotFoundException { - Cursor cursor = mContentResolver.query(queryUri, - new String[]{ - // we pick from cache only information that is not easily available from keyrings - KeyRings.HAS_ANY_SECRET, KeyRings.VERIFIED, - // and of course, ring data - secret ? KeyRings.PRIVKEY_DATA : KeyRings.PUBKEY_DATA - }, null, null, null - ); - try { - if (cursor != null && cursor.moveToFirst()) { - - boolean hasAnySecret = cursor.getInt(0) > 0; - int verified = cursor.getInt(1); - byte[] blob = cursor.getBlob(2); - if (secret & !hasAnySecret) { - throw new NotFoundException("Secret key not available!"); - } - return secret - ? new CanonicalizedSecretKeyRing(blob, true, verified) - : new CanonicalizedPublicKeyRing(blob, verified); - } else { - throw new NotFoundException("Key not found!"); - } - } finally { - if (cursor != null) { - cursor.close(); - } - } - } - private String getKeyRingAsArmoredString(byte[] data) throws IOException, PgpGeneralException { UncachedKeyRing keyRing = UncachedKeyRing.decodeFromData(data); ByteArrayOutputStream bos = new ByteArrayOutputStream(); keyRing.encodeArmored(bos, null); - String armoredKey = bos.toString("UTF-8"); - Log.d(Constants.TAG, "armoredKey:" + armoredKey); - - return armoredKey; + return bos.toString("UTF-8"); } - public String getKeyRingAsArmoredString(Uri uri) + public String getPublicKeyRingAsArmoredString(long masterKeyId) throws NotFoundException, IOException, PgpGeneralException { - byte[] data = (byte[]) getGenericData( - uri, KeyRingData.KEY_RING_DATA, FIELD_TYPE_BLOB); + byte[] data = getPublicKeyRingData(masterKeyId); return getKeyRingAsArmoredString(data); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java index d9b0a1f3f..fb67ddbbf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java @@ -105,29 +105,33 @@ public class DatabaseReadWriteInteractor extends DatabaseInteractor { } private LongSparseArray getTrustedMasterKeys() { - Cursor cursor = mContentResolver.query(KeyRings.buildUnifiedKeyRingsUri(), new String[]{ + Cursor cursor = mContentResolver.query(KeyRings.buildUnifiedKeyRingsUri(), new String[] { KeyRings.MASTER_KEY_ID, // we pick from cache only information that is not easily available from keyrings - KeyRings.HAS_ANY_SECRET, KeyRings.VERIFIED, - // and of course, ring data - KeyRings.PUBKEY_DATA + KeyRings.HAS_ANY_SECRET, KeyRings.VERIFIED }, KeyRings.HAS_ANY_SECRET + " = 1", null, null); try { LongSparseArray result = new LongSparseArray<>(); - if (cursor != null && cursor.moveToFirst()) do { - long masterKeyId = cursor.getLong(0); - int verified = cursor.getInt(2); - byte[] blob = cursor.getBlob(3); - if (blob != null) { - result.put(masterKeyId, - new CanonicalizedPublicKeyRing(blob, verified).getPublicKey()); + if (cursor == null) { + return result; + } + + while (cursor.moveToNext()) { + try { + long masterKeyId = cursor.getLong(0); + int verified = cursor.getInt(2); + byte[] blob = getPublicKeyRingData(masterKeyId); + if (blob != null) { + result.put(masterKeyId, new CanonicalizedPublicKeyRing(blob, verified).getPublicKey()); + } + } catch (NotFoundException e) { + throw new IllegalStateException("Error reading secret key data, this should not happen!", e); } - } while (cursor.moveToNext()); + } return result; - } finally { if (cursor != null) { cursor.close(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java index 9d1948b0a..9f05cc940 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java @@ -138,8 +138,6 @@ public class KeychainContract { public static final String HAS_CERTIFY = "has_certify"; public static final String HAS_AUTHENTICATE = "has_authenticate"; public static final String HAS_DUPLICATE_USER_ID = "has_duplicate_user_id"; - public static final String PUBKEY_DATA = "pubkey_data"; - public static final String PRIVKEY_DATA = "privkey_data"; public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon() .appendPath(BASE_KEY_RINGS).build(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java index 992ee4e68..dd897c84a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java @@ -18,6 +18,12 @@ package org.sufficientlysecure.keychain.provider; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + import android.content.Context; import android.content.Intent; import android.database.sqlite.SQLiteDatabase; @@ -36,11 +42,6 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.UserPacketsColu import org.sufficientlysecure.keychain.ui.ConsolidateDialogActivity; import org.sufficientlysecure.keychain.util.Log; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; - /** * SQLite Datatypes (from http://www.sqlite.org/datatype3.html) * - NULL. The value is a NULL value. diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java index 9f1fa2976..4115cbadf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java @@ -323,16 +323,12 @@ public class KeychainProvider extends ContentProvider { + " = " + Tables.USER_PACKETS + "." + UserPackets.EMAIL + " COLLATE NOCASE" + ")) AS " + KeyRings.HAS_DUPLICATE_USER_ID); projectionMap.put(KeyRings.VERIFIED, Tables.CERTS + "." + Certs.VERIFIED); - projectionMap.put(KeyRings.PUBKEY_DATA, - Tables.KEY_RINGS_PUBLIC + "." + KeyRingData.KEY_RING_DATA - + " AS " + KeyRings.PUBKEY_DATA); - projectionMap.put(KeyRings.PRIVKEY_DATA, - Tables.KEY_RINGS_SECRET + "." + KeyRingData.KEY_RING_DATA - + " AS " + KeyRings.PRIVKEY_DATA); projectionMap.put(KeyRings.HAS_SECRET, Tables.KEYS + "." + KeyRings.HAS_SECRET); projectionMap.put(KeyRings.HAS_ANY_SECRET, - "(" + Tables.KEY_RINGS_SECRET + "." + KeyRings.MASTER_KEY_ID + " IS NOT NULL)" + - " AS " + KeyRings.HAS_ANY_SECRET); + "(EXISTS (SELECT * FROM " + Tables.KEY_RINGS_SECRET + " WHERE " + + Tables.KEYS + "." + Keys.MASTER_KEY_ID + " = " + + Tables.KEY_RINGS_SECRET + "." + KeyRingData.MASTER_KEY_ID + + ")) AS " + KeyRings.HAS_ANY_SECRET); projectionMap.put(KeyRings.HAS_ENCRYPT, "kE." + Keys.KEY_ID + " AS " + KeyRings.HAS_ENCRYPT); projectionMap.put(KeyRings.HAS_SIGN, @@ -367,18 +363,6 @@ public class KeychainProvider extends ContentProvider { + " = " + Certs.VERIFIED_SECRET + ")" // fairly expensive joins following, only do when requested - + (plist.contains(KeyRings.PUBKEY_DATA) ? - " INNER JOIN " + Tables.KEY_RINGS_PUBLIC + " ON (" - + Tables.KEYS + "." + Keys.MASTER_KEY_ID - + " = " - + Tables.KEY_RINGS_PUBLIC + "." + KeyRingData.MASTER_KEY_ID - + ")" : "") - + (plist.contains(KeyRings.PRIVKEY_DATA) || plist.contains(KeyRings.HAS_ANY_SECRET) ? - " LEFT JOIN " + Tables.KEY_RINGS_SECRET + " ON (" - + Tables.KEYS + "." + Keys.MASTER_KEY_ID - + " = " - + Tables.KEY_RINGS_SECRET + "." + KeyRingData.MASTER_KEY_ID - + ")" : "") + (plist.contains(KeyRings.HAS_ENCRYPT) ? " LEFT JOIN " + Tables.KEYS + " AS kE ON (" +"kE." + Keys.MASTER_KEY_ID diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index 78ed3b30c..b720406d4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -17,6 +17,7 @@ package org.sufficientlysecure.keychain.ui; + import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.IOException; @@ -57,9 +58,8 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.ui.base.LoaderFragment; import org.sufficientlysecure.keychain.ui.util.FormattingUtils; @@ -221,8 +221,8 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements DatabaseInteractor databaseInteractor = new DatabaseInteractor(activity.getContentResolver()); try { - String content = databaseInteractor.getKeyRingAsArmoredString( - KeychainContract.KeyRingData.buildPublicKeyRingUri(mDataUri)); + long masterKeyId = databaseInteractor.getCachedPublicKeyRing(mDataUri).extractOrGetMasterKeyId(); + String content = databaseInteractor.getPublicKeyRingAsArmoredString(masterKeyId); if (toClipboard) { ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); @@ -275,7 +275,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements } catch (PgpGeneralException | IOException e) { Log.e(Constants.TAG, "error processing key!", e); Notify.create(activity, R.string.error_key_processing, Notify.Style.ERROR).show(); - } catch (DatabaseInteractor.NotFoundException e) { + } catch (PgpKeyNotFoundException | DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); Notify.create(activity, R.string.error_key_not_found, Notify.Style.ERROR).show(); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java index 9cfc90544..7e0fa413d 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java @@ -672,7 +672,7 @@ public class PgpKeyOperationTest { parcel.reset(); parcel.mRevokeSubKeys.add(123L); - CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0); + CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), 0); UncachedKeyRing otherModified = op.modifySecretKeyRing(secretRing, cryptoInput, parcel).getRing(); Assert.assertNull("revoking a nonexistent subkey should fail", otherModified); @@ -870,7 +870,7 @@ public class PgpKeyOperationTest { parcelSecurityToken.mChangeSubKeys.add(new SubkeyChange(keyId, false, true)); CanonicalizedSecretKeyRing secretRing = - new CanonicalizedSecretKeyRing(ringSecurityToken.getEncoded(), false, 0); + new CanonicalizedSecretKeyRing(ringSecurityToken.getEncoded(), 0); PgpKeyOperation op = new PgpKeyOperation(null); PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, cryptoInput, parcelSecurityToken); Assert.assertTrue("moveKeyToSecurityToken operation should be pending", result.isPending()); @@ -904,7 +904,7 @@ public class PgpKeyOperationTest { parcelSecurityToken.mChangeSubKeys.add(new SubkeyChange(keyId, true)); CanonicalizedSecretKeyRing secretRing = - new CanonicalizedSecretKeyRing(modified.getEncoded(), false, 0); + new CanonicalizedSecretKeyRing(modified.getEncoded(), 0); PgpKeyOperation op = new PgpKeyOperation(null); PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, cryptoInput, parcelSecurityToken); Assert.assertTrue("moveKeyToSecurityToken operation should be pending", result.isPending()); @@ -1193,7 +1193,7 @@ public class PgpKeyOperationTest { // we should still be able to modify it (and change its passphrase) without errors PgpKeyOperation op = new PgpKeyOperation(null); - CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(modified.getEncoded(), false, 0); + CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(modified.getEncoded(), 0); PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, otherCryptoInput, parcel); Assert.assertTrue("key modification must succeed", result.success()); Assert.assertFalse("log must not contain a warning", @@ -1209,7 +1209,7 @@ public class PgpKeyOperationTest { modified = KeyringTestingHelper.injectPacket(modified, sKeyWithPassphrase.buf, sKeyWithPassphrase.position); PgpKeyOperation op = new PgpKeyOperation(null); - CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(modified.getEncoded(), false, 0); + CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(modified.getEncoded(), 0); PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(otherPassphrase2), parcel); Assert.assertTrue("key modification must succeed", result.success()); Assert.assertTrue("log must contain a failed passphrase change warning", @@ -1221,7 +1221,7 @@ public class PgpKeyOperationTest { @Test public void testRestricted() throws Exception { - CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0); + CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), 0); parcel.mAddUserIds.add("discord"); PgpKeyOperation op = new PgpKeyOperation(null); @@ -1256,7 +1256,7 @@ public class PgpKeyOperationTest { try { Assert.assertTrue("modified keyring must be secret", ring.isSecret()); - CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0); + CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), 0); PgpKeyOperation op = new PgpKeyOperation(null); PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, cryptoInput, parcel); @@ -1329,7 +1329,7 @@ public class PgpKeyOperationTest { SaveKeyringParcel parcel, CryptoInputParcel cryptoInput, LogType expected) throws Exception { - CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0); + CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), 0); PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, cryptoInput, parcel); Assert.assertFalse(reason, result.success()); @@ -1343,7 +1343,7 @@ public class PgpKeyOperationTest { LogType expected) throws Exception { - CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0); + CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), 0); PgpEditKeyResult result = op.modifySecretKeyRing(secretRing, cryptoInput, parcel); Assert.assertFalse(reason, result.success()); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java index 07aa18d6a..5c4a6514d 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java @@ -185,7 +185,7 @@ public class UncachedKeyringMergeTest { UncachedKeyRing modifiedA, modifiedB; { CanonicalizedSecretKeyRing secretRing = - new CanonicalizedSecretKeyRing(ringA.getEncoded(), false, 0); + new CanonicalizedSecretKeyRing(ringA.getEncoded(), 0); parcel.reset(); parcel.mAddUserIds.add("flim"); @@ -225,7 +225,7 @@ public class UncachedKeyringMergeTest { UncachedKeyRing modifiedA, modifiedB; long subKeyIdA, subKeyIdB; { - CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ringA.getEncoded(), false, 0); + CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ringA.getEncoded(), 0); parcel.reset(); parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd( @@ -271,7 +271,7 @@ public class UncachedKeyringMergeTest { parcel.reset(); parcel.mRevokeSubKeys.add(KeyringTestingHelper.getSubkeyId(ringA, 1)); CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing( - ringA.getEncoded(), false, 0); + ringA.getEncoded(), 0); modified = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing(); } @@ -296,7 +296,7 @@ public class UncachedKeyringMergeTest { pubRing.getEncoded(), 0); CanonicalizedSecretKey secretKey = new CanonicalizedSecretKeyRing( - ringB.getEncoded(), false, 0).getSecretKey(); + ringB.getEncoded(), 0).getSecretKey(); secretKey.unlock(new Passphrase()); PgpCertifyOperation op = new PgpCertifyOperation(); CertifyAction action = new CertifyAction(pubRing.getMasterKeyId(), publicRing.getPublicKey().getUnorderedUserIds(), null); @@ -370,7 +370,7 @@ public class UncachedKeyringMergeTest { parcel.mAddUserAttribute.add(uat); CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing( - ringA.getEncoded(), false, 0); + ringA.getEncoded(), 0); modified = op.modifySecretKeyRing(secretRing, new CryptoInputParcel(new Date(), new Passphrase()), parcel).getRing(); } From c7e01926e1320f5af1a4897d4b9b0525dfe473dd Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 24 Feb 2017 17:25:32 +0100 Subject: [PATCH 07/11] add LocalKeyStorage, don't store public keys larger than 50kb in database --- .../keychain/TestHelpers.java | 2 +- .../keychain/actions/CustomActions.java | 2 +- .../keychain/operations/BackupOperation.java | 4 +- .../provider/CachedPublicKeyRing.java | 3 +- .../keychain/provider/DatabaseInteractor.java | 58 ++++++++++-- .../provider/DatabaseReadWriteInteractor.java | 94 ++++++++++++------- .../provider/LocalPublicKeyStorage.java | 78 +++++++++++++++ .../keychain/remote/OpenPgpService.java | 2 +- .../ui/RequestKeyPermissionPresenter.java | 3 +- .../keychain/service/KeychainService.java | 3 +- .../service/KeyserverSyncAdapterService.java | 5 +- .../service/PassphraseCacheService.java | 2 +- .../ui/CertifyFingerprintFragment.java | 2 +- .../keychain/ui/CertifyKeyFragment.java | 3 +- .../keychain/ui/CreateKeyActivity.java | 2 +- .../keychain/ui/CreateKeyFinalFragment.java | 3 +- .../keychain/ui/DecryptFragment.java | 2 +- .../keychain/ui/DeleteKeyDialogActivity.java | 5 +- .../keychain/ui/EditIdentitiesFragment.java | 2 +- .../keychain/ui/EditKeyFragment.java | 3 +- .../ui/EncryptModeAsymmetricFragment.java | 2 +- .../keychain/ui/KeyListFragment.java | 3 +- .../keychain/ui/PassphraseDialogActivity.java | 7 +- .../keychain/ui/QrCodeViewActivity.java | 4 +- .../keychain/ui/SafeSlingerActivity.java | 2 +- .../ui/SecurityTokenOperationActivity.java | 6 +- .../keychain/ui/ViewCertActivity.java | 3 +- .../keychain/ui/ViewKeyActivity.java | 6 +- .../keychain/ui/ViewKeyAdvActivity.java | 2 +- .../keychain/ui/ViewKeyAdvShareFragment.java | 9 +- .../ui/adapter/ImportKeysAdapter.java | 2 +- .../ui/base/BaseSecurityTokenActivity.java | 2 +- .../keychain/ui/linked/LinkedIdWizard.java | 2 +- .../keychain/util/NfcHelper.java | 2 +- .../keychain/util/ParcelableFileCache.java | 4 + .../operations/BackupOperationTest.java | 11 ++- .../operations/BenchmarkOperationTest.java | 2 +- .../operations/CertifyOperationTest.java | 21 +++-- .../operations/PromoteKeyOperationTest.java | 15 +-- .../keychain/pgp/InputDataOperationTest.java | 4 +- .../keychain/pgp/PgpEncryptDecryptTest.java | 52 +++++----- .../provider/DatabaseInteractorSaveTest.java | 19 ++-- .../remote/KeychainExternalProviderTest.java | 3 +- .../support/KeyringTestingHelper.java | 3 +- 44 files changed, 314 insertions(+), 150 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/LocalPublicKeyStorage.java diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java index b538dc3dd..0d9248dda 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java @@ -97,7 +97,7 @@ public class TestHelpers { IteratorWithIOThrow stream = UncachedKeyRing.fromStream( getInstrumentation().getContext().getAssets().open(name)); - DatabaseReadWriteInteractor helper = new DatabaseReadWriteInteractor(context); + DatabaseReadWriteInteractor helper = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context); while(stream.hasNext()) { UncachedKeyRing ring = stream.next(); if (ring.isSecret()) { diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java index 78d9477f6..5def4d793 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java @@ -37,7 +37,7 @@ public abstract class CustomActions { public static ViewAction tokenEncryptViewAddToken(long keyId) throws Exception { CanonicalizedPublicKeyRing ring = - new DatabaseReadWriteInteractor(getTargetContext()).getCanonicalizedPublicKeyRing(keyId); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(getTargetContext()).getCanonicalizedPublicKeyRing(keyId); final Object item = new KeyAdapter.KeyItem(ring); return new ViewAction() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java index 6b4d1732b..f895b286a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java @@ -270,7 +270,7 @@ public class BackupOperation extends BaseOperation { try { arOutStream = new ArmoredOutputStream(outStream); - byte[] data = mDatabaseInteractor.getPublicKeyRingData(masterKeyId); + byte[] data = mDatabaseInteractor.loadPublicKeyRingData(masterKeyId); UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(data); CanonicalizedPublicKeyRing ring = (CanonicalizedPublicKeyRing) uncachedKeyRing.canonicalize(log, 2, true); ring.encode(arOutStream); @@ -290,7 +290,7 @@ public class BackupOperation extends BaseOperation { try { arOutStream = new ArmoredOutputStream(outStream); - byte[] data = mDatabaseInteractor.getSecretKeyRingData(masterKeyId); + byte[] data = mDatabaseInteractor.loadSecretKeyRingData(masterKeyId); UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(data); CanonicalizedSecretKeyRing ring = (CanonicalizedSecretKeyRing) uncachedKeyRing.canonicalize(log, 2, true); ring.encode(arOutStream); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java index c0336b866..f347a5220 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java @@ -25,7 +25,6 @@ import org.sufficientlysecure.keychain.Constants; 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.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; @@ -240,7 +239,7 @@ public class CachedPublicKeyRing extends KeyRing { public byte[] getEncoded() throws PgpKeyNotFoundException { try { - return mDatabaseInteractor.getPublicKeyRingData(getMasterKeyId()); + return mDatabaseInteractor.loadPublicKeyRingData(getMasterKeyId()); } catch(DatabaseReadWriteInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java index 8b0054ed4..48bc27132 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java @@ -7,9 +7,12 @@ import java.util.ArrayList; import java.util.HashMap; import android.content.ContentResolver; +import android.content.Context; import android.database.Cursor; import android.net.Uri; +import android.util.Log; +import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; @@ -33,15 +36,25 @@ public class DatabaseInteractor { public static final int FIELD_TYPE_BLOB = 5; final ContentResolver mContentResolver; + final LocalPublicKeyStorage mLocalPublicKeyStorage; OperationLog mLog; int mIndent; - public DatabaseInteractor(ContentResolver contentResolver) { - this(contentResolver, new OperationLog(), 0); + public static DatabaseInteractor createDatabaseInteractor(Context context) { + ContentResolver contentResolver = context.getContentResolver(); + LocalPublicKeyStorage localPublicKeyStorage = LocalPublicKeyStorage.getInstance(context); + + return new DatabaseInteractor(contentResolver, localPublicKeyStorage); } - public DatabaseInteractor(ContentResolver contentResolver, OperationLog log, int indent) { + private DatabaseInteractor(ContentResolver contentResolver, LocalPublicKeyStorage localPublicKeyStorage) { + this(contentResolver, localPublicKeyStorage, new OperationLog(), 0); + } + + DatabaseInteractor(ContentResolver contentResolver, LocalPublicKeyStorage localPublicKeyStorage, + OperationLog log, int indent) { mContentResolver = contentResolver; + mLocalPublicKeyStorage = localPublicKeyStorage; mIndent = indent; mLog = log; } @@ -74,6 +87,10 @@ public class DatabaseInteractor { return result; } + Object getGenericDataOrNull(Uri uri, String column, int type) throws NotFoundException { + return getGenericData(uri, new String[]{column}, new int[]{type}, null).get(column); + } + Object getGenericData(Uri uri, String column, int type, String selection) throws NotFoundException { return getGenericData(uri, new String[]{column}, new int[]{type}, selection).get(column); @@ -156,7 +173,7 @@ public class DatabaseInteractor { long masterKeyId = cursor.getLong(0); int verified = cursor.getInt(1); - byte[] publicKeyData = getPublicKeyRingData(masterKeyId); + byte[] publicKeyData = loadPublicKeyRingData(masterKeyId); return new CanonicalizedPublicKeyRing(publicKeyData, verified); } else { throw new NotFoundException("Key not found!"); @@ -184,7 +201,7 @@ public class DatabaseInteractor { throw new NotFoundException("No secret key available or unknown public key!"); } - byte[] secretKeyData = getSecretKeyRingData(masterKeyId); + byte[] secretKeyData = loadSecretKeyRingData(masterKeyId); return new CanonicalizedSecretKeyRing(secretKeyData, verified); } else { throw new NotFoundException("Key not found!"); @@ -228,7 +245,7 @@ public class DatabaseInteractor { public String getPublicKeyRingAsArmoredString(long masterKeyId) throws NotFoundException, IOException, PgpGeneralException { - byte[] data = getPublicKeyRingData(masterKeyId); + byte[] data = loadPublicKeyRingData(masterKeyId); return getKeyRingAsArmoredString(data); } @@ -236,14 +253,35 @@ public class DatabaseInteractor { return mContentResolver; } - public byte[] getPublicKeyRingData(long masterKeyId) throws NotFoundException { - return (byte[]) getGenericData(KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId), + public final byte[] loadPublicKeyRingData(long masterKeyId) throws NotFoundException { + byte[] data = (byte[]) getGenericDataOrNull(KeyRingData.buildPublicKeyRingUri(masterKeyId), KeyRingData.KEY_RING_DATA, FIELD_TYPE_BLOB); + + if (data == null) { + try { + data = mLocalPublicKeyStorage.readPublicKey(masterKeyId); + } catch (IOException e) { + Log.e(Constants.TAG, "Error reading public key from storage!", e); + throw new NotFoundException(); + } + } + + if (data == null) { + throw new NotFoundException(); + } + + return data; } - public byte[] getSecretKeyRingData(long masterKeyId) throws NotFoundException { - return (byte[]) getGenericData(KeychainContract.KeyRingData.buildSecretKeyRingUri(masterKeyId), + public final byte[] loadSecretKeyRingData(long masterKeyId) throws NotFoundException { + byte[] data = (byte[]) getGenericDataOrNull(KeychainContract.KeyRingData.buildSecretKeyRingUri(masterKeyId), KeyRingData.KEY_RING_DATA, FIELD_TYPE_BLOB); + + if (data == null) { + throw new NotFoundException(); + } + + return data; } public static class NotFoundException extends Exception { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java index fb67ddbbf..df2c6b257 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java @@ -19,6 +19,15 @@ package org.sufficientlysecure.keychain.provider; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.TimeUnit; + import android.content.ContentProviderOperation; import android.content.ContentValues; import android.content.Context; @@ -68,15 +77,6 @@ import org.sufficientlysecure.keychain.util.ProgressFixedScaler; import org.sufficientlysecure.keychain.util.ProgressScaler; import org.sufficientlysecure.keychain.util.Utf8Util; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.TimeUnit; - /** * This class contains high level methods for database access. Despite its * name, it is not only a helper but actually the main interface for all @@ -88,18 +88,26 @@ import java.util.concurrent.TimeUnit; * method is called to start a new one specifically. */ public class DatabaseReadWriteInteractor extends DatabaseInteractor { + private static final int MAX_CACHED_KEY_SIZE = 1024 * 50; + private final Context mContext; - public DatabaseReadWriteInteractor(Context context) { - this(context, new OperationLog(), 0); + public static DatabaseReadWriteInteractor createDatabaseReadWriteInteractor(Context context) { + LocalPublicKeyStorage localPublicKeyStorage = LocalPublicKeyStorage.getInstance(context); + + return new DatabaseReadWriteInteractor(context, localPublicKeyStorage); } - public DatabaseReadWriteInteractor(Context context, OperationLog log) { - this(context, log, 0); + private DatabaseReadWriteInteractor(Context context, LocalPublicKeyStorage localPublicKeyStorage) { + this(context, localPublicKeyStorage, new OperationLog(), 0); } - public DatabaseReadWriteInteractor(Context context, OperationLog log, int indent) { - super(context.getContentResolver(), log, indent); + private DatabaseReadWriteInteractor(Context context, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log) { + this(context, localPublicKeyStorage, log, 0); + } + + private DatabaseReadWriteInteractor(Context context, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log, int indent) { + super(context.getContentResolver(), localPublicKeyStorage, log, indent); mContext = context; } @@ -122,7 +130,7 @@ public class DatabaseReadWriteInteractor extends DatabaseInteractor { try { long masterKeyId = cursor.getLong(0); int verified = cursor.getInt(2); - byte[] blob = getPublicKeyRingData(masterKeyId); + byte[] blob = loadPublicKeyRingData(masterKeyId); if (blob != null) { result.put(masterKeyId, new CanonicalizedPublicKeyRing(blob, verified).getPublicKey()); } @@ -191,18 +199,11 @@ public class DatabaseReadWriteInteractor extends DatabaseInteractor { operations = new ArrayList<>(); log(LogType.MSG_IP_INSERT_KEYRING); - { // insert keyring - ContentValues values = new ContentValues(); - values.put(KeyRingData.MASTER_KEY_ID, masterKeyId); - try { - values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded()); - } catch (IOException e) { - log(LogType.MSG_IP_ENCODE_FAIL); - return SaveKeyringResult.RESULT_ERROR; - } - - Uri uri = KeyRingData.buildPublicKeyRingUri(masterKeyId); - operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build()); + try { + writePublicKeyRing(keyRing, masterKeyId, operations); + } catch (IOException e) { + log(LogType.MSG_IP_ENCODE_FAIL); + return SaveKeyringResult.RESULT_ERROR; } log(LogType.MSG_IP_INSERT_SUBKEYS); @@ -582,6 +583,35 @@ public class DatabaseReadWriteInteractor extends DatabaseInteractor { } + private void writePublicKeyRing(CanonicalizedPublicKeyRing keyRing, long masterKeyId, + ArrayList operations) throws IOException { + byte[] encodedKey = keyRing.getEncoded(); + mLocalPublicKeyStorage.writePublicKey(masterKeyId, encodedKey); + + ContentValues values = new ContentValues(); + values.put(KeyRingData.MASTER_KEY_ID, masterKeyId); + if (encodedKey.length < MAX_CACHED_KEY_SIZE) { + values.put(KeyRingData.KEY_RING_DATA, encodedKey); + } else { + values.put(KeyRingData.KEY_RING_DATA, (byte[]) null); + } + + Uri uri = KeyRingData.buildPublicKeyRingUri(masterKeyId); + operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build()); + } + + private Uri writeSecretKeyRing(CanonicalizedSecretKeyRing keyRing, long masterKeyId) throws IOException { + byte[] encodedKey = keyRing.getEncoded(); + + ContentValues values = new ContentValues(); + values.put(KeyRingData.MASTER_KEY_ID, masterKeyId); + values.put(KeyRingData.KEY_RING_DATA, encodedKey); + + // insert new version of this keyRing + Uri uri = KeyRingData.buildSecretKeyRingUri(masterKeyId); + return mContentResolver.insert(uri, values); + } + private static class UserPacketItem implements Comparable { Integer type; String userId; @@ -637,12 +667,8 @@ public class DatabaseReadWriteInteractor extends DatabaseInteractor { // save secret keyring try { - ContentValues values = new ContentValues(); - values.put(KeyRingData.MASTER_KEY_ID, masterKeyId); - values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded()); - // insert new version of this keyRing - Uri uri = KeyRingData.buildSecretKeyRingUri(masterKeyId); - if (mContentResolver.insert(uri, values) == null) { + Uri insertedUri = writeSecretKeyRing(keyRing, masterKeyId); + if (insertedUri == null) { log(LogType.MSG_IS_DB_EXCEPTION); return SaveKeyringResult.RESULT_ERROR; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/LocalPublicKeyStorage.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/LocalPublicKeyStorage.java new file mode 100644 index 000000000..ff369d49e --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/LocalPublicKeyStorage.java @@ -0,0 +1,78 @@ +package org.sufficientlysecure.keychain.provider; + + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +import android.content.Context; + +import okhttp3.internal.Util; + + +class LocalPublicKeyStorage { + private static final String FORMAT_STR_PUBLIC_KEY = "0x%016x.pub"; + private static final String PUBLIC_KEYS_DIR_NAME = "public_keys"; + + + private final File localPublicKeysDir; + + + public static LocalPublicKeyStorage getInstance(Context context) { + File localPublicKeysDir = new File(context.getFilesDir(), PUBLIC_KEYS_DIR_NAME); + return new LocalPublicKeyStorage(localPublicKeysDir); + } + + private LocalPublicKeyStorage(File localPublicKeysDir) { + this.localPublicKeysDir = localPublicKeysDir; + } + + private File getPublicKeyFile(long masterKeyId) throws IOException { + if (!localPublicKeysDir.exists()) { + localPublicKeysDir.mkdir(); + } + if (!localPublicKeysDir.isDirectory()) { + throw new IOException("Failed creating public key directory!"); + } + + String keyFilename = String.format(FORMAT_STR_PUBLIC_KEY, masterKeyId); + return new File(localPublicKeysDir, keyFilename); + } + + void writePublicKey(long masterKeyId, byte[] encoded) throws IOException { + File publicKeyFile = getPublicKeyFile(masterKeyId); + + FileOutputStream fileOutputStream = new FileOutputStream(publicKeyFile); + try { + fileOutputStream.write(encoded); + } finally { + Util.closeQuietly(fileOutputStream); + } + } + + byte[] readPublicKey(long masterKeyId) throws IOException { + File publicKeyFile = getPublicKeyFile(masterKeyId); + + try { + FileInputStream fileInputStream = new FileInputStream(publicKeyFile); + return readIntoByteArray(fileInputStream); + } catch (FileNotFoundException e) { + return null; + } + } + + private static byte[] readIntoByteArray(FileInputStream fileInputStream) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + byte[] buf = new byte[128]; + int bytesRead; + while ((bytesRead = fileInputStream.read(buf)) != -1) { + baos.write(buf, 0, bytesRead); + } + + return baos.toByteArray(); + } +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index d11dca6c7..7e2c8a08d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -97,7 +97,7 @@ public class OpenPgpService extends Service { public void onCreate() { super.onCreate(); mApiPermissionHelper = new ApiPermissionHelper(this, new ApiDataAccessObject(this)); - mDatabaseInteractor = new DatabaseInteractor(getContentResolver()); + mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(this); mApiDao = new ApiDataAccessObject(this); mApiPendingIntentFactory = new ApiPendingIntentFactory(getBaseContext()); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java index 1f6b678c4..6455b8fc0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java @@ -40,7 +40,8 @@ class RequestKeyPermissionPresenter { PackageManager packageManager = context.getPackageManager(); ApiDataAccessObject apiDataAccessObject = new ApiDataAccessObject(context); ApiPermissionHelper apiPermissionHelper = new ApiPermissionHelper(context, apiDataAccessObject); - DatabaseInteractor databaseInteractor = new DatabaseInteractor(context.getContentResolver()); + DatabaseInteractor databaseInteractor = + DatabaseInteractor.createDatabaseInteractor(context); return new RequestKeyPermissionPresenter(context, apiDataAccessObject, apiPermissionHelper, packageManager, databaseInteractor); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java index 470b19ec0..9b4da90f0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java @@ -111,7 +111,8 @@ public class KeychainService extends Service implements Progressable { // just for brevity KeychainService outerThis = KeychainService.this; - DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(outerThis); + DatabaseReadWriteInteractor databaseInteractor = + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(outerThis); if (inputParcel instanceof SignEncryptParcel) { op = new SignEncryptOperation(outerThis, databaseInteractor, outerThis, mActionCanceled); } else if (inputParcel instanceof PgpDecryptVerifyInputParcel) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java index 87f48310b..fbf0cbe96 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java @@ -321,7 +321,8 @@ public class KeyserverSyncAdapterService extends Service { private ImportKeyResult directUpdate(Context context, ArrayList keyList, CryptoInputParcel cryptoInputParcel) { Log.d(Constants.TAG, "Starting normal update"); - ImportOperation importOp = new ImportOperation(context, new DatabaseReadWriteInteractor(context), null); + ImportOperation importOp = new ImportOperation(context, + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context), null); return importOp.execute( new ImportKeyringParcel(keyList, Preferences.getPreferences(context).getPreferredKeyserver()), @@ -381,7 +382,7 @@ public class KeyserverSyncAdapterService extends Service { new OperationResult.OperationLog()); } ImportKeyResult result = - new ImportOperation(context, new DatabaseReadWriteInteractor(context), null, mCancelled) + new ImportOperation(context, DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context), null, mCancelled) .execute( new ImportKeyringParcel( keyWrapper, diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index 0a4f11ba1..f5f8c87e0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -245,7 +245,7 @@ public class PassphraseCacheService extends Service { + masterKeyId + ", subKeyId " + subKeyId); // get the type of key (from the database) - CachedPublicKeyRing keyRing = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing keyRing = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId); SecretKeyType keyType = keyRing.getSecretKeyType(subKeyId); switch (keyType) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java index 7c2b63b25..82f36737d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java @@ -214,7 +214,7 @@ public class CertifyFingerprintFragment extends LoaderFragment implements private void certify(Uri dataUri) { long keyId = 0; try { - keyId = new DatabaseInteractor(getActivity().getContentResolver()) + keyId = DatabaseInteractor.createDatabaseInteractor(getContext()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java index a5991fdef..4c56e4616 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -69,7 +69,8 @@ public class CertifyKeyFragment .getLongExtra(CertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, Constants.key.none); if (certifyKeyId != Constants.key.none) { try { - CachedPublicKeyRing key = (new DatabaseInteractor(getActivity().getContentResolver())) + CachedPublicKeyRing key = (DatabaseInteractor + .createDatabaseInteractor(getContext())) .getCachedPublicKeyRing(certifyKeyId); if (key.canCertify()) { mCertifyKeySpinner.setPreSelectedKeyId(certifyKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java index 9693aba1a..b8cc7ce2c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java @@ -181,7 +181,7 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity { if (containsKeys(mScannedFingerprints)) { try { long masterKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mScannedFingerprints); - CachedPublicKeyRing ring = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing ring = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId); ring.getMasterKeyId(); Intent intent = new Intent(this, ViewKeyActivity.class); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index 496e3ec75..a9fd76d47 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -44,7 +44,6 @@ import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; @@ -412,7 +411,7 @@ public class CreateKeyFinalFragment extends Fragment { CreateKeyActivity activity = (CreateKeyActivity) getActivity(); final SaveKeyringParcel changeKeyringParcel; - CachedPublicKeyRing key = (new DatabaseInteractor(activity.getContentResolver())) + CachedPublicKeyRing key = (DatabaseInteractor.createDatabaseInteractor(getContext())) .getCachedPublicKeyRing(saveKeyResult.mMasterKeyId); try { changeKeyringParcel = new SaveKeyringParcel(key.getMasterKeyId(), key.getFingerprint()); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index 4ad66df6a..ed389584c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -193,7 +193,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager. try { Intent viewKeyIntent = new Intent(getActivity(), ViewKeyActivity.class); - long masterKeyId = new DatabaseInteractor(getActivity().getContentResolver()).getCachedPublicKeyRing( + long masterKeyId = DatabaseInteractor.createDatabaseInteractor(getContext()).getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId) ).getMasterKeyId(); viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId)); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java index 6a02eb0de..b12a061c7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java @@ -89,7 +89,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { if (mMasterKeyIds.length == 1 && mHasSecret) { // if mMasterKeyIds.length == 0 we let the DeleteOperation respond try { - HashMap data = new DatabaseInteractor(getContentResolver()).getUnifiedData( + HashMap data = DatabaseInteractor.createDatabaseInteractor(this).getUnifiedData( mMasterKeyIds[0], new String[]{ KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.IS_REVOKED @@ -269,7 +269,8 @@ public class DeleteKeyDialogActivity extends FragmentActivity { long masterKeyId = masterKeyIds[0]; try { - HashMap data = new DatabaseInteractor(activity.getContentResolver()).getUnifiedData( + HashMap data = DatabaseInteractor.createDatabaseInteractor(getContext()) + .getUnifiedData( masterKeyId, new String[]{ KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.HAS_ANY_SECRET diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java index 6940f78c6..ed269e17a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java @@ -170,7 +170,7 @@ public class EditIdentitiesFragment extends Fragment try { Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri); CachedPublicKeyRing keyRing = - new DatabaseInteractor(getActivity().getContentResolver()).getCachedPublicKeyRing(secretUri); + DatabaseInteractor.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(secretUri); long masterKeyId = keyRing.getMasterKeyId(); // check if this is a master secret key we can work with diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index 891330659..216789b41 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -49,7 +49,6 @@ import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; @@ -204,7 +203,7 @@ public class EditKeyFragment extends QueueingCryptoOperationFragment return; } - DatabaseInteractor databaseInteractor = new DatabaseInteractor(activity.getContentResolver()); + DatabaseInteractor databaseInteractor = + DatabaseInteractor.createDatabaseInteractor(getContext()); Cursor cursor = databaseInteractor.getContentResolver().query( KeyRings.buildUnifiedKeyRingsUri(), new String[]{ KeyRings.FINGERPRINT diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java index b2f6dcc01..4b2c8ee2a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java @@ -112,7 +112,7 @@ public class PassphraseDialogActivity extends FragmentActivity { // handle empty passphrases by directly returning an empty crypto input parcel try { CachedPublicKeyRing pubRing = - new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(requiredInput.getMasterKeyId()); + DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId()); // use empty passphrase for empty passphrase if (pubRing.getSecretKeyType(requiredInput.getSubKeyId()) == SecretKeyType.PASSPHRASE_EMPTY) { // also return passphrase back to activity @@ -231,7 +231,8 @@ public class PassphraseDialogActivity extends FragmentActivity { try { long subKeyId = mRequiredInput.getSubKeyId(); - DatabaseInteractor helper = new DatabaseInteractor(activity.getContentResolver()); + DatabaseInteractor helper = + DatabaseInteractor.createDatabaseInteractor(getContext()); CachedPublicKeyRing cachedPublicKeyRing = helper.getCachedPublicKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); // yes the inner try/catch block is necessary, otherwise the final variable @@ -457,7 +458,7 @@ public class PassphraseDialogActivity extends FragmentActivity { Long subKeyId = mRequiredInput.getSubKeyId(); CanonicalizedSecretKeyRing secretKeyRing = - new DatabaseInteractor(getActivity().getContentResolver()).getCanonicalizedSecretKeyRing( + DatabaseInteractor.createDatabaseInteractor(getContext()).getCanonicalizedSecretKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); CanonicalizedSecretKey secretKeyToUnlock = secretKeyRing.getSecretKey(subKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java index 0592adf3d..19f9ad964 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java @@ -29,8 +29,6 @@ import android.widget.ImageView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; -import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -76,7 +74,7 @@ public class QrCodeViewActivity extends BaseActivity { } }); - DatabaseInteractor databaseInteractor = new DatabaseInteractor(getContentResolver()); + DatabaseInteractor databaseInteractor = DatabaseInteractor.createDatabaseInteractor(this); try { byte[] blob = databaseInteractor.getCachedPublicKeyRing(dataUri).getFingerprint(); if (blob == null) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java index dcdbc841c..7f7a2978e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java @@ -106,7 +106,7 @@ public class SafeSlingerActivity extends BaseActivity // retrieve public key blob and start SafeSlinger Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId); try { - byte[] keyBlob = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(uri).getEncoded(); + byte[] keyBlob = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(uri).getEncoded(); Intent slingerIntent = new Intent(this, ExchangeActivity.class); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java index e61a8b495..453c7f649 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java @@ -193,7 +193,8 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity { throw new IOException(getString(R.string.error_wrong_security_token)); } - DatabaseInteractor databaseInteractor = new DatabaseInteractor(getContentResolver()); + DatabaseInteractor databaseInteractor = + DatabaseInteractor.createDatabaseInteractor(this); CanonicalizedPublicKeyRing publicKeyRing; try { publicKeyRing = databaseInteractor.getCanonicalizedPublicKeyRing( @@ -232,7 +233,8 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity { mSecurityTokenHelper.setPin(new Passphrase("123456")); mSecurityTokenHelper.setAdminPin(new Passphrase("12345678")); - DatabaseInteractor databaseInteractor = new DatabaseInteractor(getContentResolver()); + DatabaseInteractor databaseInteractor = + DatabaseInteractor.createDatabaseInteractor(this); CanonicalizedSecretKeyRing secretKeyRing; try { secretKeyRing = databaseInteractor.getCanonicalizedSecretKeyRing( diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java index 3e3099dbc..3167c85c1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java @@ -184,7 +184,8 @@ public class ViewCertActivity extends BaseActivity Intent viewIntent = new Intent(ViewCertActivity.this, ViewKeyActivity.class); try { - DatabaseInteractor databaseInteractor = new DatabaseInteractor(ViewCertActivity.this.getContentResolver()); + DatabaseInteractor databaseInteractor = + DatabaseInteractor.createDatabaseInteractor(ViewCertActivity.this); long signerMasterKeyId = databaseInteractor.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId(); viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId)); 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 3b6497a77..6a0d02676 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -185,7 +185,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mDatabaseInteractor = new DatabaseInteractor(getContentResolver()); + mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(this); mImportOpHelper = new CryptoOperationHelper<>(1, this, this, null); setTitle(null); @@ -741,7 +741,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements return; } try { - long keyId = new DatabaseInteractor(getContentResolver()) + long keyId = DatabaseInteractor.createDatabaseInteractor(this) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); long[] encryptionKeyIds = new long[]{keyId}; @@ -765,7 +765,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements private void startSafeSlinger(Uri dataUri) { long keyId = 0; try { - keyId = new DatabaseInteractor(getContentResolver()) + keyId = DatabaseInteractor.createDatabaseInteractor(this) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java index 34cf578ed..a87c9a13f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java @@ -87,7 +87,7 @@ public class ViewKeyAdvActivity extends BaseActivity implements } }); - mDatabaseInteractor = new DatabaseInteractor(getContentResolver()); + mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(this); mViewPager = (ViewPager) findViewById(R.id.pager); mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tab_layout); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index b720406d4..20ecc640d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -95,7 +95,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements View view = inflater.inflate(R.layout.view_key_adv_share_fragment, getContainer()); ContentResolver contentResolver = ViewKeyAdvShareFragment.this.getActivity().getContentResolver(); - DatabaseInteractor databaseInteractor = new DatabaseInteractor(contentResolver); + DatabaseInteractor databaseInteractor = DatabaseInteractor.createDatabaseInteractor(getContext()); mNfcHelper = new NfcHelper(getActivity(), databaseInteractor); mFingerprintView = (TextView) view.findViewById(R.id.view_key_fingerprint); @@ -202,7 +202,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements private void startSafeSlinger(Uri dataUri) { long keyId = 0; try { - keyId = new DatabaseInteractor(getActivity().getContentResolver()) + keyId = DatabaseInteractor.createDatabaseInteractor(getContext()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { @@ -218,7 +218,8 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements if (activity == null || mFingerprint == null) { return; } - DatabaseInteractor databaseInteractor = new DatabaseInteractor(activity.getContentResolver()); + DatabaseInteractor databaseInteractor = + DatabaseInteractor.createDatabaseInteractor(getContext()); try { long masterKeyId = databaseInteractor.getCachedPublicKeyRing(mDataUri).extractOrGetMasterKeyId(); @@ -459,7 +460,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements private void uploadToKeyserver() { long keyId; try { - keyId = new DatabaseInteractor(getActivity().getContentResolver()) + keyId = DatabaseInteractor.createDatabaseInteractor(getContext()) .getCachedPublicKeyRing(mDataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index 22808ab8d..af61873ad 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -75,7 +75,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter data) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java index fa6dd17cd..4087b88d7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java @@ -105,7 +105,7 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity final long subKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mSecurityTokenFingerprints); try { - CachedPublicKeyRing ring = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing( + CachedPublicKeyRing ring = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); long masterKeyId = ring.getMasterKeyId(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java index b59ec7499..a7c5f11ed 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java @@ -58,7 +58,7 @@ public class LinkedIdWizard extends BaseActivity { try { Uri uri = getIntent().getData(); uri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(uri); - CachedPublicKeyRing ring = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(uri); + CachedPublicKeyRing ring = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(uri); if (!ring.hasAnySecret()) { Log.e(Constants.TAG, "Linked Identities can only be added to secret keys!"); finish(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java index 9d40cb725..66ff29059 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java @@ -130,7 +130,7 @@ public class NfcHelper { try { long masterKeyId = mDatabaseInteractor.getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); - mNfcKeyringBytes = mDatabaseInteractor.getPublicKeyRingData(masterKeyId); + mNfcKeyringBytes = mDatabaseInteractor.loadPublicKeyRingData(masterKeyId); } catch (NotFoundException | PgpKeyNotFoundException e) { Log.e(Constants.TAG, "key not found!", e); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableFileCache.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableFileCache.java index d16b2c9c9..95427ff34 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableFileCache.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableFileCache.java @@ -52,6 +52,10 @@ public class ParcelableFileCache { mFilename = filename; } + public static boolean cacheFileExists(Context context, String filename) { + return new File(context.getCacheDir(), filename).exists(); + } + public void writeCache(int numEntries, Iterator it) throws IOException { DataOutputStream oos = getOutputStream(); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java index 72b8c8d21..9f3e3c7e2 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java @@ -135,7 +135,8 @@ public class BackupOperationTest { @Before public void setUp() { - DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; @@ -150,7 +151,7 @@ public class BackupOperationTest { @Test public void testExportAllLocalStripped() throws Exception { BackupOperation op = new BackupOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); // make sure there is a local cert (so the later checks that there are none are meaningful) assertTrue("second keyring has local certification", checkForLocal(mStaticRing2)); @@ -249,7 +250,7 @@ public class BackupOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); BackupOperation op = new BackupOperation(spyApplication, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); BackupKeyringParcel parcel = new BackupKeyringParcel( new long[] { mStaticRing1.getMasterKeyId() }, false, false, true, fakeOutputUri); @@ -306,7 +307,7 @@ public class BackupOperationTest { { // export encrypted BackupOperation op = new BackupOperation(spyApplication, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); BackupKeyringParcel parcel = new BackupKeyringParcel( new long[] { mStaticRing1.getMasterKeyId() }, false, true, true, fakeOutputUri); @@ -324,7 +325,7 @@ public class BackupOperationTest { { PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(outStream.toByteArray()); input.setAllowSymmetricDecryption(true); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java index 4bdff329c..6f84da91e 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java @@ -47,7 +47,7 @@ public class BenchmarkOperationTest { @Test public void testBenchmark() throws Exception { BenchmarkOperation op = new BenchmarkOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); op.execute(new BenchmarkInputParcel(), null); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java index 0e21a8c33..e77055ef5 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java @@ -117,7 +117,8 @@ public class CertifyOperationTest { @Before public void setUp() throws Exception { - DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; @@ -132,7 +133,7 @@ public class CertifyOperationTest { @Test public void testSelfCertifyFlag() throws Exception { - CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing1.getMasterKeyId()); Assert.assertEquals("secret key must be marked self-certified in database", // TODO this should be more correctly be VERIFIED_SELF at some point! @@ -143,10 +144,10 @@ public class CertifyOperationTest { @Test public void testCertifyId() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); { - CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("public key must not be marked verified prior to certification", Certs.UNVERIFIED, ring.getVerified()); @@ -160,7 +161,7 @@ public class CertifyOperationTest { Assert.assertTrue("certification must succeed", result.success()); { - CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("new key must be verified now", Certs.VERIFIED_SECRET, ring.getVerified()); @@ -171,10 +172,10 @@ public class CertifyOperationTest { @Test public void testCertifyAttribute() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); { - CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("public key must not be marked verified prior to certification", Certs.UNVERIFIED, ring.getVerified()); @@ -188,7 +189,7 @@ public class CertifyOperationTest { Assert.assertTrue("certification must succeed", result.success()); { - CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("new key must be verified now", Certs.VERIFIED_SECRET, ring.getVerified()); @@ -200,7 +201,7 @@ public class CertifyOperationTest { @Test public void testCertifySelf() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(), @@ -217,7 +218,7 @@ public class CertifyOperationTest { public void testCertifyNonexistent() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); { CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java index b1c651b61..6c4cfe270 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java @@ -90,7 +90,8 @@ public class PromoteKeyOperationTest { @Before public void setUp() throws Exception { - DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; @@ -104,14 +105,14 @@ public class PromoteKeyOperationTest { @Test public void testPromote() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); PromoteKeyResult result = op.execute(new PromoteKeyringParcel(mStaticRing.getMasterKeyId(), null, null), null); Assert.assertTrue("promotion must succeed", result.success()); { - CachedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) + CachedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCachedPublicKeyRing(mStaticRing.getMasterKeyId()); Assert.assertTrue("key must have a secret now", ring.hasAnySecret()); @@ -128,7 +129,7 @@ public class PromoteKeyOperationTest { @Test public void testPromoteDivert() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); byte[] aid = Hex.decode("D2760001240102000000012345670000"); @@ -137,7 +138,7 @@ public class PromoteKeyOperationTest { Assert.assertTrue("promotion must succeed", result.success()); { - CanonicalizedSecretKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedSecretKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { @@ -153,7 +154,7 @@ public class PromoteKeyOperationTest { @Test public void testPromoteDivertSpecific() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); byte[] aid = Hex.decode("D2760001240102000000012345670000"); @@ -167,7 +168,7 @@ public class PromoteKeyOperationTest { Assert.assertTrue("promotion must succeed", result.success()); { - CanonicalizedSecretKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedSecretKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java index ad28dc7f6..91b5fac0b 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java @@ -126,7 +126,7 @@ public class InputDataOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); InputDataOperation op = new InputDataOperation(spyApplication, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputDataParcel input = new InputDataParcel(fakeInputUri, null); @@ -306,7 +306,7 @@ public class InputDataOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); InputDataOperation op = new InputDataOperation(spyApplication, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputDataParcel input = new InputDataParcel(FAKE_CONTENT_INPUT_URI_1, null); return op.execute(input, new CryptoInputParcel()); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java index 1a9573c3c..4288d2b89 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java @@ -149,7 +149,8 @@ public class PgpEncryptDecryptTest { @Before public void setUp() { - DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; @@ -172,7 +173,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -197,7 +198,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute( @@ -227,7 +228,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute(input, @@ -249,7 +250,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute(input, @@ -270,7 +271,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(false); DecryptVerifyResult result = op.execute(input, @@ -297,7 +298,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -353,7 +354,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -415,7 +416,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -472,7 +473,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -575,7 +576,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -626,11 +627,12 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1)); @@ -648,11 +650,12 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1)); @@ -675,7 +678,8 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); } @@ -685,7 +689,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -730,7 +734,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -824,7 +828,7 @@ public class PgpEncryptDecryptTest { { // decryption with passphrase cached should succeed for the other key if first is gone // delete first key from database - new DatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete( + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete( KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null ); @@ -859,7 +863,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -907,7 +911,7 @@ public class PgpEncryptDecryptTest { { // decryption with passphrase cached should succeed for the other key if first is gone // delete first key from database - new DatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete( + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete( KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null ); @@ -946,7 +950,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaindata); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -1018,7 +1022,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -1069,7 +1073,7 @@ public class PgpEncryptDecryptTest { final Passphrase passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) { return new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null) { + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null) { @Override public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId) throws NoSecretKeyException { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java index 695158787..84d3bc644 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java @@ -43,7 +43,8 @@ import java.util.Iterator; @RunWith(KeychainTestRunner.class) public class DatabaseInteractorSaveTest { - DatabaseReadWriteInteractor mDatabaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor mDatabaseInteractor = + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); @BeforeClass public static void setUpOnce() throws Exception { @@ -61,17 +62,17 @@ public class DatabaseInteractorSaveTest { SaveKeyringResult result; // insert both keys, second should fail - result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); + result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); Assert.assertTrue("first keyring import should succeed", result.success()); - result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); + result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); Assert.assertFalse("second keyring import should fail", result.success()); new KeychainDatabase(RuntimeEnvironment.application).clearDatabase(); // and the other way around - result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); + result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); Assert.assertTrue("first keyring import should succeed", result.success()); - result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); + result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); Assert.assertFalse("second keyring import should fail", result.success()); } @@ -90,13 +91,15 @@ public class DatabaseInteractorSaveTest { SaveKeyringResult result; // insert secret, this should fail because of missing self-cert - result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); + result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) + .saveSecretKeyRing(seckey, new ProgressScaler()); Assert.assertFalse("secret keyring import before pubring import should fail", result.success()); // insert pubkey, then seckey - both should succeed - result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(pubkey); + result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(pubkey); Assert.assertTrue("public keyring import should succeed", result.success()); - result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); + result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) + .saveSecretKeyRing(seckey, new ProgressScaler()); Assert.assertTrue("secret keyring import after pubring import should succeed", result.success()); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java index 8188023cc..4a972461c 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java @@ -45,7 +45,8 @@ public class KeychainExternalProviderTest { static final long KEY_ID_PUBLIC = 0x9A282CE2AB44A382L; - DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application); + DatabaseReadWriteInteractor databaseInteractor = + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver(); ApiPermissionHelper apiPermissionHelper; ApiDataAccessObject apiDao; diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java index 86c908dc0..9c549468a 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java @@ -51,7 +51,8 @@ public class KeyringTestingHelper { public boolean addKeyring(Collection blobFiles) throws Exception { - DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(context); + DatabaseReadWriteInteractor databaseInteractor = + DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context); byte[] data = TestDataUtil.readAllFully(blobFiles); UncachedKeyRing ring = UncachedKeyRing.decodeFromData(data); From 2124a4598a4cb205d585f3c426c3ebb5827122ef Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 24 Feb 2017 18:24:11 +0100 Subject: [PATCH 08/11] DatabaseInteractor -> KeyRepository --- .../keychain/TestHelpers.java | 4 +- .../keychain/actions/CustomActions.java | 4 +- .../keychain/operations/BackupOperation.java | 20 ++--- .../keychain/operations/BaseOperation.java | 16 ++-- .../operations/BaseReadWriteOperation.java | 12 +-- .../operations/BenchmarkOperation.java | 8 +- .../keychain/operations/CertifyOperation.java | 18 ++-- .../operations/ChangeUnlockOperation.java | 10 +-- .../operations/ConsolidateOperation.java | 8 +- .../keychain/operations/DeleteOperation.java | 8 +- .../keychain/operations/EditKeyOperation.java | 12 +-- .../keychain/operations/ImportOperation.java | 20 ++--- .../operations/InputDataOperation.java | 10 +-- .../KeybaseVerificationOperation.java | 6 +- .../operations/PromoteKeyOperation.java | 10 +-- .../keychain/operations/RevokeOperation.java | 10 +-- .../operations/SignEncryptOperation.java | 10 +-- .../keychain/operations/UploadOperation.java | 12 +-- .../keychain/pgp/CanonicalizedSecretKey.java | 4 +- .../pgp/OpenPgpSignatureResultBuilder.java | 12 +-- .../pgp/PgpDecryptVerifyOperation.java | 20 ++--- .../keychain/pgp/PgpSignEncryptOperation.java | 22 ++--- .../keychain/pgp/PgpSignatureChecker.java | 20 ++--- .../provider/CachedPublicKeyRing.java | 90 +++++++++---------- ...baseInteractor.java => KeyRepository.java} | 10 +-- ...ractor.java => KeyWritableRepository.java} | 14 +-- .../keychain/remote/OpenPgpService.java | 22 ++--- .../ui/RequestKeyPermissionPresenter.java | 18 ++-- .../keychain/service/KeychainService.java | 6 +- .../service/KeyserverSyncAdapterService.java | 6 +- .../service/PassphraseCacheService.java | 12 +-- .../ui/CertifyFingerprintFragment.java | 4 +- .../keychain/ui/CertifyKeyFragment.java | 4 +- .../keychain/ui/CreateKeyActivity.java | 4 +- .../keychain/ui/CreateKeyFinalFragment.java | 4 +- .../keychain/ui/DecryptFragment.java | 4 +- .../keychain/ui/DeleteKeyDialogActivity.java | 18 ++-- .../keychain/ui/EditIdentitiesFragment.java | 6 +- .../keychain/ui/EditKeyFragment.java | 6 +- .../ui/EncryptModeAsymmetricFragment.java | 12 +-- .../keychain/ui/KeyListFragment.java | 8 +- .../keychain/ui/PassphraseDialogActivity.java | 14 +-- .../keychain/ui/QrCodeViewActivity.java | 6 +- .../keychain/ui/SafeSlingerActivity.java | 4 +- .../ui/SecurityTokenOperationActivity.java | 18 ++-- .../keychain/ui/ViewCertActivity.java | 8 +- .../keychain/ui/ViewKeyActivity.java | 24 ++--- .../keychain/ui/ViewKeyAdvActivity.java | 6 +- .../keychain/ui/ViewKeyAdvShareFragment.java | 20 ++--- .../ui/adapter/ImportKeysAdapter.java | 12 +-- .../ui/base/BaseSecurityTokenActivity.java | 4 +- .../keychain/ui/linked/LinkedIdWizard.java | 4 +- .../keychain/util/NfcHelper.java | 14 +-- .../operations/BackupOperationTest.java | 14 +-- .../operations/BenchmarkOperationTest.java | 4 +- .../operations/CertifyOperationTest.java | 24 ++--- .../operations/PromoteKeyOperationTest.java | 18 ++-- .../keychain/pgp/InputDataOperationTest.java | 6 +- .../keychain/pgp/PgpEncryptDecryptTest.java | 58 ++++++------ .../keychain/provider/InteropTest.java | 2 +- ...est.java => KeyRepositoryKeyringTest.java} | 2 +- ...veTest.java => KeyRepositorySaveTest.java} | 22 ++--- .../remote/KeychainExternalProviderTest.java | 10 +-- ...ractorStub.java => KeyRepositoryStub.java} | 6 +- .../support/KeyringTestingHelper.java | 14 +-- 65 files changed, 419 insertions(+), 419 deletions(-) rename OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/{DatabaseInteractor.java => KeyRepository.java} (96%) rename OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/{DatabaseReadWriteInteractor.java => KeyWritableRepository.java} (98%) rename OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/{DatabaseInteractorKeyringTest.java => KeyRepositoryKeyringTest.java} (98%) rename OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/{DatabaseInteractorSaveTest.java => KeyRepositorySaveTest.java} (90%) rename OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/{DatabaseInteractorStub.java => KeyRepositoryStub.java} (85%) diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java index 0d9248dda..15bdb52b4 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java @@ -38,7 +38,7 @@ import com.nispok.snackbar.Snackbar; import org.hamcrest.Matcher; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.ui.util.Notify.Style; @@ -97,7 +97,7 @@ public class TestHelpers { IteratorWithIOThrow stream = UncachedKeyRing.fromStream( getInstrumentation().getContext().getAssets().open(name)); - DatabaseReadWriteInteractor helper = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context); + KeyWritableRepository helper = KeyWritableRepository.createDatabaseReadWriteInteractor(context); while(stream.hasNext()) { UncachedKeyRing ring = stream.next(); if (ring.isSecret()) { diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java index 5def4d793..c985e65a4 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java @@ -27,7 +27,7 @@ import android.view.View; import com.tokenautocomplete.TokenCompleteTextView; import org.hamcrest.Matcher; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter; import static android.support.test.InstrumentationRegistry.getTargetContext; @@ -37,7 +37,7 @@ public abstract class CustomActions { public static ViewAction tokenEncryptViewAddToken(long keyId) throws Exception { CanonicalizedPublicKeyRing ring = - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(getTargetContext()).getCanonicalizedPublicKeyRing(keyId); + KeyWritableRepository.createDatabaseReadWriteInteractor(getTargetContext()).getCanonicalizedPublicKeyRing(keyId); final Object item = new KeyAdapter.KeyItem(ring); return new ViewAction() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java index f895b286a..ab8a4fee8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java @@ -52,8 +52,8 @@ import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeyRepository; +import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; @@ -84,14 +84,14 @@ public class BackupOperation extends BaseOperation { private static final int INDEX_MASTER_KEY_ID = 0; private static final int INDEX_HAS_ANY_SECRET = 1; - public BackupOperation(Context context, DatabaseInteractor databaseInteractor, Progressable + public BackupOperation(Context context, KeyRepository keyRepository, Progressable progressable) { - super(context, databaseInteractor, progressable); + super(context, keyRepository, progressable); } - public BackupOperation(Context context, DatabaseInteractor databaseInteractor, + public BackupOperation(Context context, KeyRepository keyRepository, Progressable progressable, AtomicBoolean cancelled) { - super(context, databaseInteractor, progressable, cancelled); + super(context, keyRepository, progressable, cancelled); } @NonNull @@ -168,7 +168,7 @@ public class BackupOperation extends BaseOperation { private PgpSignEncryptResult encryptBackupData(@NonNull BackupKeyringParcel backupInput, @NonNull CryptoInputParcel cryptoInput, @Nullable OutputStream outputStream, Uri plainUri, long exportedDataSize) throws FileNotFoundException { - PgpSignEncryptOperation signEncryptOperation = new PgpSignEncryptOperation(mContext, mDatabaseInteractor, mProgressable, mCancelled); + PgpSignEncryptOperation signEncryptOperation = new PgpSignEncryptOperation(mContext, mKeyRepository, mProgressable, mCancelled); PgpSignEncryptData data = new PgpSignEncryptData(); data.setSymmetricPassphrase(cryptoInput.getPassphrase()); @@ -270,7 +270,7 @@ public class BackupOperation extends BaseOperation { try { arOutStream = new ArmoredOutputStream(outStream); - byte[] data = mDatabaseInteractor.loadPublicKeyRingData(masterKeyId); + byte[] data = mKeyRepository.loadPublicKeyRingData(masterKeyId); UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(data); CanonicalizedPublicKeyRing ring = (CanonicalizedPublicKeyRing) uncachedKeyRing.canonicalize(log, 2, true); ring.encode(arOutStream); @@ -290,7 +290,7 @@ public class BackupOperation extends BaseOperation { try { arOutStream = new ArmoredOutputStream(outStream); - byte[] data = mDatabaseInteractor.loadSecretKeyRingData(masterKeyId); + byte[] data = mKeyRepository.loadSecretKeyRingData(masterKeyId); UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(data); CanonicalizedSecretKeyRing ring = (CanonicalizedSecretKeyRing) uncachedKeyRing.canonicalize(log, 2, true); ring.encode(arOutStream); @@ -323,7 +323,7 @@ public class BackupOperation extends BaseOperation { + " IN (" + placeholders + ")"; } - return mDatabaseInteractor.getContentResolver().query( + return mKeyRepository.getContentResolver().query( KeyRings.buildUnifiedKeyRingsUri(), PROJECTION, selection, selectionArgs, Tables.KEYS + "." + KeyRings.MASTER_KEY_ID ); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java index cc0e43a98..d43ac02ef 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java @@ -29,8 +29,8 @@ import org.sufficientlysecure.keychain.Constants.key; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.PassphraseCacheInterface; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeyRepository; +import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Passphrase; @@ -41,7 +41,7 @@ public abstract class BaseOperation implements PassphraseC final public Progressable mProgressable; final public AtomicBoolean mCancelled; - final public DatabaseInteractor mDatabaseInteractor; + final public KeyRepository mKeyRepository; /** An abstract base class for all *Operation classes. It provides a number * of common methods for progress, cancellation and passphrase cache handling. @@ -65,18 +65,18 @@ public abstract class BaseOperation implements PassphraseC * if there is no prefix it is considered Android-related. * */ - public BaseOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { + public BaseOperation(Context context, KeyRepository keyRepository, Progressable progressable) { this.mContext = context; this.mProgressable = progressable; - this.mDatabaseInteractor = databaseInteractor; + this.mKeyRepository = keyRepository; mCancelled = null; } - public BaseOperation(Context context, DatabaseInteractor databaseInteractor, + public BaseOperation(Context context, KeyRepository keyRepository, Progressable progressable, AtomicBoolean cancelled) { mContext = context; mProgressable = progressable; - mDatabaseInteractor = databaseInteractor; + mKeyRepository = keyRepository; mCancelled = cancelled; } @@ -115,7 +115,7 @@ public abstract class BaseOperation implements PassphraseC public Passphrase getCachedPassphrase(long subKeyId) throws NoSecretKeyException { try { if (subKeyId != key.symmetric) { - long masterKeyId = mDatabaseInteractor.getMasterKeyId(subKeyId); + long masterKeyId = mKeyRepository.getMasterKeyId(subKeyId); return getCachedPassphrase(masterKeyId, subKeyId); } return getCachedPassphrase(key.symmetric, key.symmetric); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseReadWriteOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseReadWriteOperation.java index 2b4524a72..a9c70a169 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseReadWriteOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseReadWriteOperation.java @@ -7,24 +7,24 @@ import android.content.Context; import android.os.Parcelable; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; abstract class BaseReadWriteOperation extends BaseOperation { - final DatabaseReadWriteInteractor mDatabaseReadWriteInteractor; + final KeyWritableRepository mKeyWritableRepository; BaseReadWriteOperation(Context context, - DatabaseReadWriteInteractor databaseInteractor, + KeyWritableRepository databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); - mDatabaseReadWriteInteractor = databaseInteractor; + mKeyWritableRepository = databaseInteractor; } - BaseReadWriteOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, + BaseReadWriteOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { super(context, databaseInteractor, progressable, cancelled); - mDatabaseReadWriteInteractor = databaseInteractor; + mKeyWritableRepository = databaseInteractor; } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java index 35a036c3c..1b857bb2a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java @@ -45,7 +45,7 @@ import org.sufficientlysecure.keychain.pgp.PgpSecurityConstants.OpenKeychainSymm import org.sufficientlysecure.keychain.pgp.PgpSignEncryptData; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.service.BenchmarkInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Log; @@ -55,7 +55,7 @@ import org.sufficientlysecure.keychain.util.ProgressScaler; public class BenchmarkOperation extends BaseOperation { - public BenchmarkOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable + public BenchmarkOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } @@ -81,7 +81,7 @@ public class BenchmarkOperation extends BaseOperation { int i = 0; do { SignEncryptOperation op = - new SignEncryptOperation(mContext, mDatabaseInteractor, + new SignEncryptOperation(mContext, mKeyRepository, new ProgressScaler(mProgressable, i*(50/numRepeats), (i+1)*(50/numRepeats), 100), mCancelled); PgpSignEncryptData data = new PgpSignEncryptData(); data.setSymmetricPassphrase(passphrase); @@ -103,7 +103,7 @@ public class BenchmarkOperation extends BaseOperation { do { DecryptVerifyResult decryptResult; PgpDecryptVerifyOperation op = - new PgpDecryptVerifyOperation(mContext, mDatabaseInteractor, + new PgpDecryptVerifyOperation(mContext, mKeyRepository, new ProgressScaler(mProgressable, 50 +i*(50/numRepeats), 50 +(i+1)*(50/numRepeats), 100)); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(encryptResult.getResultBytes()); input.setAllowSymmetricDecryption(true); 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 a3fb6aca4..a21e36771 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java @@ -39,8 +39,8 @@ import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; @@ -62,7 +62,7 @@ import org.sufficientlysecure.keychain.util.Passphrase; */ public class CertifyOperation extends BaseReadWriteOperation { - public CertifyOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable, AtomicBoolean + public CertifyOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { super(context, databaseInteractor, progressable, cancelled); } @@ -81,7 +81,7 @@ public class CertifyOperation extends BaseReadWriteOperation { - public ChangeUnlockOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable) { + public ChangeUnlockOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } @@ -63,7 +63,7 @@ public class ChangeUnlockOperation extends BaseReadWriteOperation { - public ConsolidateOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable + public ConsolidateOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } @@ -40,9 +40,9 @@ public class ConsolidateOperation extends BaseReadWriteOperation { - public DeleteOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable) { + public DeleteOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } @@ -81,7 +81,7 @@ public class DeleteOperation extends BaseReadWriteOperation cancelled = true; break; } - int count = mDatabaseInteractor.getContentResolver().delete( + int count = mKeyRepository.getContentResolver().delete( KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null ); if (count > 0) { @@ -95,7 +95,7 @@ public class DeleteOperation extends BaseReadWriteOperation if (isSecret && success > 0) { log.add(LogType.MSG_DEL_CONSOLIDATE, 1); - ConsolidateResult sub = mDatabaseReadWriteInteractor.consolidateDatabaseStep1(mProgressable); + ConsolidateResult sub = mKeyWritableRepository.consolidateDatabaseStep1(mProgressable); log.add(sub, 2); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java index 09469cd40..57cd2dd7c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java @@ -35,8 +35,8 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; @@ -57,7 +57,7 @@ import org.sufficientlysecure.keychain.util.ProgressScaler; */ public class EditKeyOperation extends BaseReadWriteOperation { - public EditKeyOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, + public EditKeyOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { super(context, databaseInteractor, progressable, cancelled); } @@ -94,7 +94,7 @@ public class EditKeyOperation extends BaseReadWriteOperation log.add(LogType.MSG_ED_FETCHING, 1, KeyFormattingUtils.convertKeyIdToHex(saveParcel.mMasterKeyId)); CanonicalizedSecretKeyRing secRing = - mDatabaseInteractor.getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId); + mKeyRepository.getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId); modifyResult = keyOperations.modifySecretKeyRing(secRing, cryptoInput, saveParcel); if (modifyResult.isPending()) { @@ -147,7 +147,7 @@ public class EditKeyOperation extends BaseReadWriteOperation new UploadKeyringParcel(saveParcel.getUploadKeyserver(), keyringBytes); UploadResult uploadResult = - new UploadOperation(mContext, mDatabaseInteractor, mProgressable, mCancelled) + new UploadOperation(mContext, mKeyRepository, mProgressable, mCancelled) .execute(exportKeyringParcel, cryptoInput); log.add(uploadResult, 2); @@ -161,7 +161,7 @@ public class EditKeyOperation extends BaseReadWriteOperation } // Save the new keyring. - SaveKeyringResult saveResult = mDatabaseReadWriteInteractor + SaveKeyringResult saveResult = mKeyWritableRepository .saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 60, 95, 100)); log.add(saveResult, 1); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java index 668392111..ba4910e01 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java @@ -39,7 +39,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -86,12 +86,12 @@ public class ImportOperation extends BaseReadWriteOperation public static final String CACHE_FILE_NAME = "key_import.pcl"; - public ImportOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable + public ImportOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } - public ImportOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, + public ImportOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { super(context, databaseInteractor, progressable, cancelled); } @@ -314,15 +314,15 @@ public class ImportOperation extends BaseReadWriteOperation SaveKeyringResult result; // synchronizing prevents https://github.com/open-keychain/open-keychain/issues/1221 // and https://github.com/open-keychain/open-keychain/issues/1480 - synchronized (mDatabaseInteractor) { - mDatabaseInteractor.clearLog(); + synchronized (mKeyRepository) { + mKeyRepository.clearLog(); ProgressScaler progressScaler = new ProgressScaler(progressable, (int) (position * progSteps), (int) ((position + 1) * progSteps), 100); if (key.isSecret()) { - result = mDatabaseReadWriteInteractor.saveSecretKeyRing(key, progressScaler, + result = mKeyWritableRepository.saveSecretKeyRing(key, progressScaler, canKeyRings, skipSave); } else { - result = mDatabaseReadWriteInteractor.savePublicKeyRing(key, progressScaler, + result = mKeyWritableRepository.savePublicKeyRing(key, progressScaler, entry.mExpectedFingerprint, canKeyRings, skipSave); } } @@ -343,7 +343,7 @@ public class ImportOperation extends BaseReadWriteOperation // synonymous to isDownloadFromKeyserver. // If no byte data was supplied, import from keyserver took place // this prevents file imports being noted as keyserver imports - mDatabaseReadWriteInteractor.renewKeyLastUpdatedTime(key.getMasterKeyId(), + mKeyWritableRepository.renewKeyLastUpdatedTime(key.getMasterKeyId(), GregorianCalendar.getInstance().getTimeInMillis(), TimeUnit.MILLISECONDS); } @@ -365,8 +365,8 @@ public class ImportOperation extends BaseReadWriteOperation if (!skipSave && (secret > 0)) { setPreventCancel(); ConsolidateResult result; - synchronized (mDatabaseInteractor) { - result = mDatabaseReadWriteInteractor.consolidateDatabaseStep1(progressable); + synchronized (mKeyRepository) { + result = mKeyWritableRepository.consolidateDatabaseStep1(progressable); } log.add(result, 1); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java index 2c62778b8..3ad764b74 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java @@ -50,7 +50,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.Operat import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.InputDataParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -71,8 +71,8 @@ public class InputDataOperation extends BaseOperation { private final byte[] buf = new byte[256]; - public InputDataOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { - super(context, databaseInteractor, progressable); + public InputDataOperation(Context context, KeyRepository keyRepository, Progressable progressable) { + super(context, keyRepository, progressable); } Uri mSignedDataUri; @@ -101,7 +101,7 @@ public class InputDataOperation extends BaseOperation { log.add(LogType.MSG_DATA_OPENPGP, 1); PgpDecryptVerifyOperation op = - new PgpDecryptVerifyOperation(mContext, mDatabaseInteractor, mProgressable); + new PgpDecryptVerifyOperation(mContext, mKeyRepository, mProgressable); decryptInput.setInputUri(input.getInputUri()); @@ -269,7 +269,7 @@ public class InputDataOperation extends BaseOperation { decryptInput.setDetachedSignature(detachedSig.toByteArray()); PgpDecryptVerifyOperation op = - new PgpDecryptVerifyOperation(mContext, mDatabaseInteractor, mProgressable); + new PgpDecryptVerifyOperation(mContext, mKeyRepository, mProgressable); DecryptVerifyResult verifyResult = op.execute(decryptInput, cryptoInput); log.addByMerge(verifyResult, 4); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java index 8eabfc9f7..f02014617 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java @@ -36,7 +36,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.service.KeybaseVerificationParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -59,7 +59,7 @@ import de.measite.minidns.record.TXT; public class KeybaseVerificationOperation extends BaseOperation { - public KeybaseVerificationOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, + public KeybaseVerificationOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } @@ -147,7 +147,7 @@ public class KeybaseVerificationOperation extends BaseOperation { - public PromoteKeyOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, + public PromoteKeyOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { super(context, databaseInteractor, progressable, cancelled); } @@ -69,7 +69,7 @@ public class PromoteKeyOperation extends BaseReadWriteOperation { - public RevokeOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable) { + public RevokeOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable) { super(context, databaseInteractor, progressable); } @@ -62,7 +62,7 @@ public class RevokeOperation extends BaseReadWriteOperation try { Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(masterKeyId); - CachedPublicKeyRing keyRing = mDatabaseInteractor.getCachedPublicKeyRing(secretUri); + CachedPublicKeyRing keyRing = mKeyRepository.getCachedPublicKeyRing(secretUri); // check if this is a master secret key we can work with switch (keyRing.getSecretKeyType(masterKeyId)) { @@ -81,7 +81,7 @@ public class RevokeOperation extends BaseReadWriteOperation saveKeyringParcel.mRevokeSubKeys.add(masterKeyId); EditKeyResult revokeAndUploadResult = new EditKeyOperation(mContext, - mDatabaseReadWriteInteractor, mProgressable, mCancelled).execute(saveKeyringParcel, cryptoInputParcel); + mKeyWritableRepository, mProgressable, mCancelled).execute(saveKeyringParcel, cryptoInputParcel); if (revokeAndUploadResult.isPending()) { return revokeAndUploadResult; @@ -97,7 +97,7 @@ public class RevokeOperation extends BaseReadWriteOperation return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId); } - } catch (PgpKeyNotFoundException | DatabaseReadWriteInteractor.NotFoundException e) { + } catch (PgpKeyNotFoundException | KeyWritableRepository.NotFoundException e) { Log.e(Constants.TAG, "could not find key to revoke", e); log.add(OperationResult.LogType.MSG_REVOKE_ERROR_KEY_FAIL, 1); return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java index 4a992dc0a..41118535e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java @@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.RequiredInputType; @@ -55,9 +55,9 @@ import org.sufficientlysecure.keychain.util.ProgressScaler; */ public class SignEncryptOperation extends BaseOperation { - public SignEncryptOperation(Context context, DatabaseInteractor databaseInteractor, + public SignEncryptOperation(Context context, KeyRepository keyRepository, Progressable progressable, AtomicBoolean cancelled) { - super(context, databaseInteractor, progressable, cancelled); + super(context, keyRepository, progressable, cancelled); } @@ -81,7 +81,7 @@ public class SignEncryptOperation extends BaseOperation { if (data.getSignatureMasterKeyId() != Constants.key.none && data.getSignatureSubKeyId() == null) { try { - long signKeyId = mDatabaseInteractor.getCachedPublicKeyRing( + long signKeyId = mKeyRepository.getCachedPublicKeyRing( data.getSignatureMasterKeyId()).getSecretSignId(); data.setSignatureSubKeyId(signKeyId); } catch (PgpKeyNotFoundException e) { @@ -96,7 +96,7 @@ public class SignEncryptOperation extends BaseOperation { return new SignEncryptResult(SignEncryptResult.RESULT_CANCELLED, log, results); } - PgpSignEncryptOperation op = new PgpSignEncryptOperation(mContext, mDatabaseInteractor, + PgpSignEncryptOperation op = new PgpSignEncryptOperation(mContext, mKeyRepository, new ProgressScaler(mProgressable, 100 * count / total, 100 * ++count / total, 100), mCancelled); PgpSignEncryptInputParcel inputParcel = new PgpSignEncryptInputParcel(input.getData()); if (inputBytes != null) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java index f5c39d3da..27265461b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java @@ -37,8 +37,8 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -59,9 +59,9 @@ import java.util.concurrent.atomic.AtomicBoolean; */ public class UploadOperation extends BaseOperation { - public UploadOperation(Context context, DatabaseInteractor databaseInteractor, + public UploadOperation(Context context, KeyRepository keyRepository, Progressable progressable, AtomicBoolean cancelled) { - super(context, databaseInteractor, progressable, cancelled); + super(context, keyRepository, progressable, cancelled); } @NonNull @@ -121,7 +121,7 @@ public class UploadOperation extends BaseOperation { if (hasMasterKeyId) { log.add(LogType.MSG_UPLOAD_KEY, 0, KeyFormattingUtils.convertKeyIdToHex(uploadInput.mMasterKeyId)); - return mDatabaseInteractor.getCanonicalizedPublicKeyRing(uploadInput.mMasterKeyId); + return mKeyRepository.getCanonicalizedPublicKeyRing(uploadInput.mMasterKeyId); } CanonicalizedKeyRing canonicalizedRing = @@ -133,7 +133,7 @@ public class UploadOperation extends BaseOperation { log.add(LogType.MSG_UPLOAD_KEY, 0, KeyFormattingUtils.convertKeyIdToHex(canonicalizedRing.getMasterKeyId())); return (CanonicalizedPublicKeyRing) canonicalizedRing; - } catch (DatabaseReadWriteInteractor.NotFoundException e) { + } catch (KeyWritableRepository.NotFoundException e) { log.add(LogType.MSG_UPLOAD_ERROR_NOT_FOUND, 1); return null; } catch (IOException | PgpGeneralException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java index 06a9e8bbe..921aed262 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java @@ -47,7 +47,7 @@ import org.bouncycastle.openpgp.operator.jcajce.SessionKeySecretKeyDecryptorBuil import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Passphrase; @@ -127,7 +127,7 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey { * passphrase in the process. * * This method can potentially take a LONG time (i.e. seconds), so it should only - * ever be called by {@link DatabaseReadWriteInteractor} for the purpose of caching its output + * ever be called by {@link KeyWritableRepository} for the purpose of caching its output * in the database. */ public SecretKeyType getSecretKeyTypeSuperExpensive() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java index 34fdc20c3..9c04c5394 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java @@ -27,8 +27,8 @@ import org.openintents.openpgp.util.OpenPgpUtils; import org.openintents.openpgp.util.OpenPgpUtils.UserId; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeyRepository; +import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException; import org.sufficientlysecure.keychain.util.Log; /** @@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.util.Log; */ public class OpenPgpSignatureResultBuilder { // injected - private final DatabaseInteractor mDatabaseInteractor; + private final KeyRepository mKeyRepository; // OpenPgpSignatureResult private String mPrimaryUserId; @@ -57,8 +57,8 @@ public class OpenPgpSignatureResultBuilder { private String mSenderAddress; private Date mSignatureTimestamp; - public OpenPgpSignatureResultBuilder(DatabaseInteractor databaseInteractor) { - this.mDatabaseInteractor = databaseInteractor; + public OpenPgpSignatureResultBuilder(KeyRepository keyRepository) { + this.mKeyRepository = keyRepository; } public void setPrimaryUserId(String userId) { @@ -127,7 +127,7 @@ public class OpenPgpSignatureResultBuilder { try { ArrayList allUserIds = signingRing.getUnorderedUserIds(); - ArrayList confirmedUserIds = mDatabaseInteractor.getConfirmedUserIds(signingRing.getMasterKeyId()); + ArrayList confirmedUserIds = mKeyRepository.getConfirmedUserIds(signingRing.getMasterKeyId()); setUserIds(allUserIds, confirmedUserIds); if (mSenderAddress != null) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java index 953c7d695..743295007 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java @@ -71,8 +71,8 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -88,8 +88,8 @@ public class PgpDecryptVerifyOperation extends BaseOperation encryptSubKeyIds = keyRing.getEncryptIds(); for (Long subKeyId : encryptSubKeyIds) { @@ -357,7 +357,7 @@ public class PgpSignEncryptOperation extends BaseOperation 0; - } catch(DatabaseReadWriteInteractor.NotFoundException e) { + } catch(KeyWritableRepository.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -158,11 +158,11 @@ public class CachedPublicKeyRing extends KeyRing { @Override public boolean canCertify() throws PgpKeyNotFoundException { try { - Object data = mDatabaseInteractor.getGenericData(mUri, + Object data = mKeyRepository.getGenericData(mUri, KeychainContract.KeyRings.HAS_CERTIFY, - DatabaseInteractor.FIELD_TYPE_NULL); + KeyRepository.FIELD_TYPE_NULL); return !((Boolean) data); - } catch(DatabaseReadWriteInteractor.NotFoundException e) { + } catch(KeyWritableRepository.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -170,11 +170,11 @@ public class CachedPublicKeyRing extends KeyRing { @Override public long getEncryptId() throws PgpKeyNotFoundException { try { - Object data = mDatabaseInteractor.getGenericData(mUri, + Object data = mKeyRepository.getGenericData(mUri, KeyRings.HAS_ENCRYPT, - DatabaseInteractor.FIELD_TYPE_INTEGER); + KeyRepository.FIELD_TYPE_INTEGER); return (Long) data; - } catch(DatabaseReadWriteInteractor.NotFoundException e) { + } catch(KeyWritableRepository.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -192,11 +192,11 @@ public class CachedPublicKeyRing extends KeyRing { */ public long getSecretSignId() throws PgpKeyNotFoundException { try { - Object data = mDatabaseInteractor.getGenericData(mUri, + Object data = mKeyRepository.getGenericData(mUri, KeyRings.HAS_SIGN, - DatabaseInteractor.FIELD_TYPE_INTEGER); + KeyRepository.FIELD_TYPE_INTEGER); return (Long) data; - } catch(DatabaseReadWriteInteractor.NotFoundException e) { + } catch(KeyWritableRepository.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -204,43 +204,43 @@ public class CachedPublicKeyRing extends KeyRing { @Override public int getVerified() throws PgpKeyNotFoundException { try { - Object data = mDatabaseInteractor.getGenericData(mUri, + Object data = mKeyRepository.getGenericData(mUri, KeychainContract.KeyRings.VERIFIED, - DatabaseInteractor.FIELD_TYPE_INTEGER); + KeyRepository.FIELD_TYPE_INTEGER); return ((Long) data).intValue(); - } catch(DatabaseReadWriteInteractor.NotFoundException e) { + } catch(KeyWritableRepository.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } public boolean hasAnySecret() throws PgpKeyNotFoundException { try { - Object data = mDatabaseInteractor.getGenericData(mUri, + Object data = mKeyRepository.getGenericData(mUri, KeychainContract.KeyRings.HAS_ANY_SECRET, - DatabaseInteractor.FIELD_TYPE_INTEGER); + KeyRepository.FIELD_TYPE_INTEGER); return (Long) data > 0; - } catch(DatabaseReadWriteInteractor.NotFoundException e) { + } catch(KeyWritableRepository.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } private Cursor getSubkeys() throws PgpKeyNotFoundException { Uri keysUri = KeychainContract.Keys.buildKeysUri(extractOrGetMasterKeyId()); - return mDatabaseInteractor.getContentResolver().query(keysUri, null, null, null, null); + return mKeyRepository.getContentResolver().query(keysUri, null, null, null, null); } public SecretKeyType getSecretKeyType(long keyId) throws NotFoundException { - Object data = mDatabaseInteractor.getGenericData(Keys.buildKeysUri(mUri), + Object data = mKeyRepository.getGenericData(Keys.buildKeysUri(mUri), KeyRings.HAS_SECRET, - DatabaseInteractor.FIELD_TYPE_INTEGER, + KeyRepository.FIELD_TYPE_INTEGER, KeyRings.KEY_ID + " = " + Long.toString(keyId)); return SecretKeyType.fromNum(((Long) data).intValue()); } public byte[] getEncoded() throws PgpKeyNotFoundException { try { - return mDatabaseInteractor.loadPublicKeyRingData(getMasterKeyId()); - } catch(DatabaseReadWriteInteractor.NotFoundException e) { + return mKeyRepository.loadPublicKeyRingData(getMasterKeyId()); + } catch(KeyWritableRepository.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyRepository.java similarity index 96% rename from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java rename to OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyRepository.java index 48bc27132..117caee63 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyRepository.java @@ -26,7 +26,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; -public class DatabaseInteractor { +public class KeyRepository { // If we ever switch to api level 11, we can ditch this whole mess! public static final int FIELD_TYPE_NULL = 1; // this is called integer to stay coherent with the constants in Cursor (api level 11) @@ -40,18 +40,18 @@ public class DatabaseInteractor { OperationLog mLog; int mIndent; - public static DatabaseInteractor createDatabaseInteractor(Context context) { + public static KeyRepository createDatabaseInteractor(Context context) { ContentResolver contentResolver = context.getContentResolver(); LocalPublicKeyStorage localPublicKeyStorage = LocalPublicKeyStorage.getInstance(context); - return new DatabaseInteractor(contentResolver, localPublicKeyStorage); + return new KeyRepository(contentResolver, localPublicKeyStorage); } - private DatabaseInteractor(ContentResolver contentResolver, LocalPublicKeyStorage localPublicKeyStorage) { + private KeyRepository(ContentResolver contentResolver, LocalPublicKeyStorage localPublicKeyStorage) { this(contentResolver, localPublicKeyStorage, new OperationLog(), 0); } - DatabaseInteractor(ContentResolver contentResolver, LocalPublicKeyStorage localPublicKeyStorage, + KeyRepository(ContentResolver contentResolver, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log, int indent) { mContentResolver = contentResolver; mLocalPublicKeyStorage = localPublicKeyStorage; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java similarity index 98% rename from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java rename to OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java index df2c6b257..1e536c85a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseReadWriteInteractor.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java @@ -87,26 +87,26 @@ import org.sufficientlysecure.keychain.util.Utf8Util; * the lifetime of the executing ProviderHelper object unless the resetLog() * method is called to start a new one specifically. */ -public class DatabaseReadWriteInteractor extends DatabaseInteractor { +public class KeyWritableRepository extends KeyRepository { private static final int MAX_CACHED_KEY_SIZE = 1024 * 50; private final Context mContext; - public static DatabaseReadWriteInteractor createDatabaseReadWriteInteractor(Context context) { + public static KeyWritableRepository createDatabaseReadWriteInteractor(Context context) { LocalPublicKeyStorage localPublicKeyStorage = LocalPublicKeyStorage.getInstance(context); - return new DatabaseReadWriteInteractor(context, localPublicKeyStorage); + return new KeyWritableRepository(context, localPublicKeyStorage); } - private DatabaseReadWriteInteractor(Context context, LocalPublicKeyStorage localPublicKeyStorage) { + private KeyWritableRepository(Context context, LocalPublicKeyStorage localPublicKeyStorage) { this(context, localPublicKeyStorage, new OperationLog(), 0); } - private DatabaseReadWriteInteractor(Context context, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log) { + private KeyWritableRepository(Context context, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log) { this(context, localPublicKeyStorage, log, 0); } - private DatabaseReadWriteInteractor(Context context, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log, int indent) { + private KeyWritableRepository(Context context, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log, int indent) { super(context.getContentResolver(), localPublicKeyStorage, log, indent); mContext = context; @@ -1174,7 +1174,7 @@ public class DatabaseReadWriteInteractor extends DatabaseInteractor { private ConsolidateResult consolidateDatabaseStep2( OperationLog log, int indent, Progressable progress, boolean recovery) { - synchronized (DatabaseReadWriteInteractor.class) { + synchronized (KeyWritableRepository.class) { if (mConsolidateCritical) { log.add(LogType.MSG_CON_ERROR_CONCURRENT, indent); return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index 7e2c8a08d..164794af1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -63,7 +63,7 @@ import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAccounts; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; @@ -88,7 +88,7 @@ public class OpenPgpService extends Service { Collections.unmodifiableList(Arrays.asList(3, 4, 5, 6, 7, 8, 9, 10, 11)); private ApiPermissionHelper mApiPermissionHelper; - private DatabaseInteractor mDatabaseInteractor; + private KeyRepository mKeyRepository; private ApiDataAccessObject mApiDao; private OpenPgpServiceKeyIdExtractor mKeyIdExtractor; private ApiPendingIntentFactory mApiPendingIntentFactory; @@ -97,7 +97,7 @@ public class OpenPgpService extends Service { public void onCreate() { super.onCreate(); mApiPermissionHelper = new ApiPermissionHelper(this, new ApiDataAccessObject(this)); - mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(this); + mKeyRepository = KeyRepository.createDatabaseInteractor(this); mApiDao = new ApiDataAccessObject(this); mApiPendingIntentFactory = new ApiPendingIntentFactory(getBaseContext()); @@ -135,7 +135,7 @@ public class OpenPgpService extends Service { // get first usable subkey capable of signing try { - long signSubKeyId = mDatabaseInteractor.getCachedPublicKeyRing( + long signSubKeyId = mKeyRepository.getCachedPublicKeyRing( pgpData.getSignatureMasterKeyId()).getSecretSignId(); pgpData.setSignatureSubKeyId(signSubKeyId); } catch (PgpKeyNotFoundException e) { @@ -167,7 +167,7 @@ public class OpenPgpService extends Service { } // execute PGP operation! - PgpSignEncryptOperation pse = new PgpSignEncryptOperation(this, mDatabaseInteractor, null); + PgpSignEncryptOperation pse = new PgpSignEncryptOperation(this, mKeyRepository, null); PgpSignEncryptResult pgpResult = pse.execute(pseInput, inputParcel, inputData, outputStream); if (pgpResult.isPending()) { @@ -254,7 +254,7 @@ public class OpenPgpService extends Service { // get first usable subkey capable of signing try { - long signSubKeyId = mDatabaseInteractor.getCachedPublicKeyRing( + long signSubKeyId = mKeyRepository.getCachedPublicKeyRing( pgpData.getSignatureMasterKeyId()).getSecretSignId(); pgpData.setSignatureSubKeyId(signSubKeyId); } catch (PgpKeyNotFoundException e) { @@ -294,7 +294,7 @@ public class OpenPgpService extends Service { new Passphrase(data.getCharArrayExtra(OpenPgpApi.EXTRA_PASSPHRASE)); } - PgpSignEncryptOperation op = new PgpSignEncryptOperation(this, mDatabaseInteractor, null); + PgpSignEncryptOperation op = new PgpSignEncryptOperation(this, mKeyRepository, null); // execute PGP operation! PgpSignEncryptResult pgpResult = op.execute(pseInput, inputParcel, inputData, outputStream); @@ -356,7 +356,7 @@ public class OpenPgpService extends Service { byte[] detachedSignature = data.getByteArrayExtra(OpenPgpApi.EXTRA_DETACHED_SIGNATURE); String senderAddress = data.getStringExtra(OpenPgpApi.EXTRA_SENDER_ADDRESS); - PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(this, mDatabaseInteractor, progressable); + PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(this, mKeyRepository, progressable); long inputLength = data.getLongExtra(OpenPgpApi.EXTRA_DATA_LENGTH, InputData.UNKNOWN_FILESIZE); InputData inputData = new InputData(inputStream, inputLength); @@ -526,7 +526,7 @@ public class OpenPgpService extends Service { try { // try to find key, throws NotFoundException if not in db! CanonicalizedPublicKeyRing keyRing = - mDatabaseInteractor.getCanonicalizedPublicKeyRing( + mKeyRepository.getCanonicalizedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(masterKeyId)); Intent result = new Intent(); @@ -555,7 +555,7 @@ public class OpenPgpService extends Service { mApiPendingIntentFactory.createShowKeyPendingIntent(data, masterKeyId)); return result; - } catch (DatabaseInteractor.NotFoundException e) { + } catch (KeyRepository.NotFoundException e) { // If keys are not in db we return an additional PendingIntent // to retrieve the missing key Intent result = new Intent(); @@ -630,7 +630,7 @@ public class OpenPgpService extends Service { // the backup code is cached in CryptoInputParcelCacheService, now we can proceed BackupKeyringParcel input = new BackupKeyringParcel(masterKeyIds, backupSecret, true, enableAsciiArmorOutput, null); - BackupOperation op = new BackupOperation(this, mDatabaseInteractor, null); + BackupOperation op = new BackupOperation(this, mKeyRepository, null); ExportResult pgpResult = op.execute(input, inputParcel, outputStream); if (pgpResult.success()) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java index 6455b8fc0..8b11d250e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java @@ -15,8 +15,8 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeyRepository; +import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.remote.ApiPermissionHelper; import org.sufficientlysecure.keychain.remote.ApiPermissionHelper.WrongPackageCertificateException; @@ -33,27 +33,27 @@ class RequestKeyPermissionPresenter { private String packageName; private long masterKeyId; - private DatabaseInteractor databaseInteractor; + private KeyRepository keyRepository; static RequestKeyPermissionPresenter createRequestKeyPermissionPresenter(Context context) { PackageManager packageManager = context.getPackageManager(); ApiDataAccessObject apiDataAccessObject = new ApiDataAccessObject(context); ApiPermissionHelper apiPermissionHelper = new ApiPermissionHelper(context, apiDataAccessObject); - DatabaseInteractor databaseInteractor = - DatabaseInteractor.createDatabaseInteractor(context); + KeyRepository keyRepository = + KeyRepository.createDatabaseInteractor(context); return new RequestKeyPermissionPresenter(context, apiDataAccessObject, apiPermissionHelper, packageManager, - databaseInteractor); + keyRepository); } private RequestKeyPermissionPresenter(Context context, ApiDataAccessObject apiDataAccessObject, - ApiPermissionHelper apiPermissionHelper, PackageManager packageManager, DatabaseInteractor databaseInteractor) { + ApiPermissionHelper apiPermissionHelper, PackageManager packageManager, KeyRepository keyRepository) { this.context = context; this.apiDataAccessObject = apiDataAccessObject; this.apiPermissionHelper = apiPermissionHelper; this.packageManager = packageManager; - this.databaseInteractor = databaseInteractor; + this.keyRepository = keyRepository; } void setView(RequestKeyPermissionMvpView view) { @@ -102,7 +102,7 @@ class RequestKeyPermissionPresenter { CachedPublicKeyRing publicFallbackRing = null; for (long candidateSubKeyId : subKeyIds) { try { - CachedPublicKeyRing cachedPublicKeyRing = databaseInteractor.getCachedPublicKeyRing( + CachedPublicKeyRing cachedPublicKeyRing = keyRepository.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(candidateSubKeyId) ); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java index 9b4da90f0..904075bc7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java @@ -48,7 +48,7 @@ import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.service.ServiceProgressHandler.MessageStatus; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Log; @@ -111,8 +111,8 @@ public class KeychainService extends Service implements Progressable { // just for brevity KeychainService outerThis = KeychainService.this; - DatabaseReadWriteInteractor databaseInteractor = - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(outerThis); + KeyWritableRepository databaseInteractor = + KeyWritableRepository.createDatabaseReadWriteInteractor(outerThis); if (inputParcel instanceof SignEncryptParcel) { op = new SignEncryptOperation(outerThis, databaseInteractor, outerThis, mActionCanceled); } else if (inputParcel instanceof PgpDecryptVerifyInputParcel) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java index fbf0cbe96..62a5f234f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java @@ -44,7 +44,7 @@ import org.sufficientlysecure.keychain.network.orbot.OrbotHelper; import org.sufficientlysecure.keychain.operations.ImportOperation; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity; @@ -322,7 +322,7 @@ public class KeyserverSyncAdapterService extends Service { CryptoInputParcel cryptoInputParcel) { Log.d(Constants.TAG, "Starting normal update"); ImportOperation importOp = new ImportOperation(context, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(context), null); return importOp.execute( new ImportKeyringParcel(keyList, Preferences.getPreferences(context).getPreferredKeyserver()), @@ -382,7 +382,7 @@ public class KeyserverSyncAdapterService extends Service { new OperationResult.OperationLog()); } ImportKeyResult result = - new ImportOperation(context, DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context), null, mCancelled) + new ImportOperation(context, KeyWritableRepository.createDatabaseReadWriteInteractor(context), null, mCancelled) .execute( new ImportKeyringParcel( keyWrapper, diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index f5f8c87e0..e3584af1f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.Preferences; @@ -224,7 +224,7 @@ public class PassphraseCacheService extends Service { /** * Internal implementation to get cached passphrase. */ - private Passphrase getCachedPassphraseImpl(long masterKeyId, long subKeyId) throws DatabaseInteractor.NotFoundException { + private Passphrase getCachedPassphraseImpl(long masterKeyId, long subKeyId) throws KeyRepository.NotFoundException { // on "none" key, just do nothing if (masterKeyId == Constants.key.none) { return null; @@ -245,16 +245,16 @@ public class PassphraseCacheService extends Service { + masterKeyId + ", subKeyId " + subKeyId); // get the type of key (from the database) - CachedPublicKeyRing keyRing = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing keyRing = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId); SecretKeyType keyType = keyRing.getSecretKeyType(subKeyId); switch (keyType) { case PASSPHRASE_EMPTY: return new Passphrase(""); case UNAVAILABLE: - throw new DatabaseInteractor.NotFoundException("secret key for this subkey is not available"); + throw new KeyRepository.NotFoundException("secret key for this subkey is not available"); case GNU_DUMMY: - throw new DatabaseInteractor.NotFoundException("secret key for stripped subkey is not available"); + throw new KeyRepository.NotFoundException("secret key for stripped subkey is not available"); } // get cached passphrase @@ -398,7 +398,7 @@ public class PassphraseCacheService extends Service { bundle.putParcelable(EXTRA_PASSPHRASE, passphrase); msg.setData(bundle); } - } catch (DatabaseInteractor.NotFoundException e) { + } catch (KeyRepository.NotFoundException e) { Log.e(Constants.TAG, "PassphraseCacheService: Passphrase for unknown key was requested!"); msg.what = MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java index 82f36737d..9dd7dca58 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java @@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.experimental.SentenceConfirm; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.ui.base.LoaderFragment; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -214,7 +214,7 @@ public class CertifyFingerprintFragment extends LoaderFragment implements private void certify(Uri dataUri) { long keyId = 0; try { - keyId = DatabaseInteractor.createDatabaseInteractor(getContext()) + keyId = KeyRepository.createDatabaseInteractor(getContext()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java index 4c56e4616..6f4133ad5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -39,7 +39,7 @@ import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -69,7 +69,7 @@ public class CertifyKeyFragment .getLongExtra(CertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, Constants.key.none); if (certifyKeyId != Constants.key.none) { try { - CachedPublicKeyRing key = (DatabaseInteractor + CachedPublicKeyRing key = (KeyRepository .createDatabaseInteractor(getContext())) .getCachedPublicKeyRing(certifyKeyId); if (key.canCertify()) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java index b8cc7ce2c..fd78da39c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java @@ -33,7 +33,7 @@ import android.support.v4.app.TaskStackBuilder; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.securitytoken.KeyFormat; import org.sufficientlysecure.keychain.ui.base.BaseSecurityTokenActivity; @@ -181,7 +181,7 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity { if (containsKeys(mScannedFingerprints)) { try { long masterKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mScannedFingerprints); - CachedPublicKeyRing ring = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing ring = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId); ring.getMasterKeyId(); Intent intent = new Intent(this, ViewKeyActivity.class); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index a9fd76d47..f7cdeb63a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.operations.results.UploadResult; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; @@ -411,7 +411,7 @@ public class CreateKeyFinalFragment extends Fragment { CreateKeyActivity activity = (CreateKeyActivity) getActivity(); final SaveKeyringParcel changeKeyringParcel; - CachedPublicKeyRing key = (DatabaseInteractor.createDatabaseInteractor(getContext())) + CachedPublicKeyRing key = (KeyRepository.createDatabaseInteractor(getContext())) .getCachedPublicKeyRing(saveKeyResult.mMasterKeyId); try { changeKeyringParcel = new SaveKeyringParcel(key.getMasterKeyId(), key.getFingerprint()); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index ed389584c..7ec43084b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -49,7 +49,7 @@ import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; @@ -193,7 +193,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager. try { Intent viewKeyIntent = new Intent(getActivity(), ViewKeyActivity.class); - long masterKeyId = DatabaseInteractor.createDatabaseInteractor(getContext()).getCachedPublicKeyRing( + long masterKeyId = KeyRepository.createDatabaseInteractor(getContext()).getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId) ).getMasterKeyId(); viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId)); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java index b12a061c7..21ee1f83a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java @@ -42,7 +42,7 @@ import org.sufficientlysecure.keychain.operations.results.DeleteResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.RevokeResult; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.service.DeleteKeyringParcel; import org.sufficientlysecure.keychain.service.RevokeKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -89,13 +89,13 @@ public class DeleteKeyDialogActivity extends FragmentActivity { if (mMasterKeyIds.length == 1 && mHasSecret) { // if mMasterKeyIds.length == 0 we let the DeleteOperation respond try { - HashMap data = DatabaseInteractor.createDatabaseInteractor(this).getUnifiedData( + HashMap data = KeyRepository.createDatabaseInteractor(this).getUnifiedData( mMasterKeyIds[0], new String[]{ KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.IS_REVOKED }, new int[]{ - DatabaseInteractor.FIELD_TYPE_STRING, - DatabaseInteractor.FIELD_TYPE_INTEGER + KeyRepository.FIELD_TYPE_STRING, + KeyRepository.FIELD_TYPE_INTEGER } ); @@ -112,7 +112,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { } else { showRevokeDeleteDialog(name); } - } catch (DatabaseInteractor.NotFoundException e) { + } catch (KeyRepository.NotFoundException e) { Log.e(Constants.TAG, "Secret key to delete not found at DeleteKeyDialogActivity for " + mMasterKeyIds[0], e); @@ -269,14 +269,14 @@ public class DeleteKeyDialogActivity extends FragmentActivity { long masterKeyId = masterKeyIds[0]; try { - HashMap data = DatabaseInteractor.createDatabaseInteractor(getContext()) + HashMap data = KeyRepository.createDatabaseInteractor(getContext()) .getUnifiedData( masterKeyId, new String[]{ KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.HAS_ANY_SECRET }, new int[]{ - DatabaseInteractor.FIELD_TYPE_STRING, - DatabaseInteractor.FIELD_TYPE_INTEGER + KeyRepository.FIELD_TYPE_STRING, + KeyRepository.FIELD_TYPE_INTEGER } ); String name; @@ -294,7 +294,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { } else { mMainMessage.setText(getString(R.string.public_key_deletetion_confirmation, name)); } - } catch (DatabaseInteractor.NotFoundException e) { + } catch (KeyRepository.NotFoundException e) { dismiss(); return null; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java index ed269e17a..b6a6658e9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java @@ -50,8 +50,8 @@ import org.sufficientlysecure.keychain.operations.results.UploadResult; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeyRepository; +import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; @@ -170,7 +170,7 @@ public class EditIdentitiesFragment extends Fragment try { Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri); CachedPublicKeyRing keyRing = - DatabaseInteractor.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(secretUri); + KeyRepository.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(secretUri); long masterKeyId = keyRing.getMasterKeyId(); // check if this is a master secret key we can work with diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index 216789b41..eb6f97cc0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -48,10 +48,10 @@ 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.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange; @@ -203,7 +203,7 @@ public class EditKeyFragment extends QueueingCryptoOperationFragment return; } - DatabaseInteractor databaseInteractor = - DatabaseInteractor.createDatabaseInteractor(getContext()); - Cursor cursor = databaseInteractor.getContentResolver().query( + KeyRepository keyRepository = + KeyRepository.createDatabaseInteractor(getContext()); + Cursor cursor = keyRepository.getContentResolver().query( KeyRings.buildUnifiedKeyRingsUri(), new String[]{ KeyRings.FINGERPRINT }, null, null, null diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java index 4b2c8ee2a..b6435108e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java @@ -58,8 +58,8 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeyRepository; +import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -112,7 +112,7 @@ public class PassphraseDialogActivity extends FragmentActivity { // handle empty passphrases by directly returning an empty crypto input parcel try { CachedPublicKeyRing pubRing = - DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId()); + KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId()); // use empty passphrase for empty passphrase if (pubRing.getSecretKeyType(requiredInput.getSubKeyId()) == SecretKeyType.PASSPHRASE_EMPTY) { // also return passphrase back to activity @@ -231,8 +231,8 @@ public class PassphraseDialogActivity extends FragmentActivity { try { long subKeyId = mRequiredInput.getSubKeyId(); - DatabaseInteractor helper = - DatabaseInteractor.createDatabaseInteractor(getContext()); + KeyRepository helper = + KeyRepository.createDatabaseInteractor(getContext()); CachedPublicKeyRing cachedPublicKeyRing = helper.getCachedPublicKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); // yes the inner try/catch block is necessary, otherwise the final variable @@ -267,7 +267,7 @@ public class PassphraseDialogActivity extends FragmentActivity { throw new AssertionError("Unhandled SecretKeyType (should not happen)"); } - } catch (PgpKeyNotFoundException | DatabaseInteractor.NotFoundException e) { + } catch (PgpKeyNotFoundException | KeyRepository.NotFoundException e) { alert.setTitle(R.string.title_key_not_found); alert.setMessage(getString(R.string.key_not_found, mRequiredInput.getSubKeyId())); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @@ -458,7 +458,7 @@ public class PassphraseDialogActivity extends FragmentActivity { Long subKeyId = mRequiredInput.getSubKeyId(); CanonicalizedSecretKeyRing secretKeyRing = - DatabaseInteractor.createDatabaseInteractor(getContext()).getCanonicalizedSecretKeyRing( + KeyRepository.createDatabaseInteractor(getContext()).getCanonicalizedSecretKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); CanonicalizedSecretKey secretKeyToUnlock = secretKeyRing.getSecretKey(subKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java index 19f9ad964..4b533bfcf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java @@ -29,7 +29,7 @@ import android.widget.ImageView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.Notify; @@ -74,9 +74,9 @@ public class QrCodeViewActivity extends BaseActivity { } }); - DatabaseInteractor databaseInteractor = DatabaseInteractor.createDatabaseInteractor(this); + KeyRepository keyRepository = KeyRepository.createDatabaseInteractor(this); try { - byte[] blob = databaseInteractor.getCachedPublicKeyRing(dataUri).getFingerprint(); + byte[] blob = keyRepository.getCachedPublicKeyRing(dataUri).getFingerprint(); if (blob == null) { Log.e(Constants.TAG, "key not found!"); Notify.create(this, R.string.error_key_not_found, Style.ERROR).show(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java index 7f7a2978e..5fdaefbcc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java @@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.operations.ImportOperation; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.base.BaseActivity; @@ -106,7 +106,7 @@ public class SafeSlingerActivity extends BaseActivity // retrieve public key blob and start SafeSlinger Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId); try { - byte[] keyBlob = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(uri).getEncoded(); + byte[] keyBlob = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(uri).getEncoded(); Intent slingerIntent = new Intent(this, ExchangeActivity.class); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java index 453c7f649..fcc3151b0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java @@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.securitytoken.KeyType; import org.sufficientlysecure.keychain.service.PassphraseCacheService; @@ -193,13 +193,13 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity { throw new IOException(getString(R.string.error_wrong_security_token)); } - DatabaseInteractor databaseInteractor = - DatabaseInteractor.createDatabaseInteractor(this); + KeyRepository keyRepository = + KeyRepository.createDatabaseInteractor(this); CanonicalizedPublicKeyRing publicKeyRing; try { - publicKeyRing = databaseInteractor.getCanonicalizedPublicKeyRing( + publicKeyRing = keyRepository.getCanonicalizedPublicKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mRequiredInput.getMasterKeyId())); - } catch (DatabaseInteractor.NotFoundException e) { + } catch (KeyRepository.NotFoundException e) { throw new IOException("Couldn't find subkey for key to token operation."); } @@ -233,14 +233,14 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity { mSecurityTokenHelper.setPin(new Passphrase("123456")); mSecurityTokenHelper.setAdminPin(new Passphrase("12345678")); - DatabaseInteractor databaseInteractor = - DatabaseInteractor.createDatabaseInteractor(this); + KeyRepository keyRepository = + KeyRepository.createDatabaseInteractor(this); CanonicalizedSecretKeyRing secretKeyRing; try { - secretKeyRing = databaseInteractor.getCanonicalizedSecretKeyRing( + secretKeyRing = keyRepository.getCanonicalizedSecretKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mRequiredInput.getMasterKeyId()) ); - } catch (DatabaseInteractor.NotFoundException e) { + } catch (KeyRepository.NotFoundException e) { throw new IOException("Couldn't find subkey for key to token operation."); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java index 3167c85c1..26cc77cba 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java @@ -40,7 +40,7 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; @@ -184,9 +184,9 @@ public class ViewCertActivity extends BaseActivity Intent viewIntent = new Intent(ViewCertActivity.this, ViewKeyActivity.class); try { - DatabaseInteractor databaseInteractor = - DatabaseInteractor.createDatabaseInteractor(ViewCertActivity.this); - long signerMasterKeyId = databaseInteractor.getCachedPublicKeyRing( + KeyRepository keyRepository = + KeyRepository.createDatabaseInteractor(ViewCertActivity.this); + long signerMasterKeyId = keyRepository.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId(); viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId)); startActivity(viewIntent); 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 6a0d02676..536900ba1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -77,8 +77,8 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeyRepository; +import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; @@ -125,7 +125,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements public static final String EXTRA_DISPLAY_RESULT = "display_result"; public static final String EXTRA_LINKED_TRANSITION = "linked_transition"; - DatabaseInteractor mDatabaseInteractor; + KeyRepository mKeyRepository; protected Uri mDataUri; @@ -185,7 +185,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(this); + mKeyRepository = KeyRepository.createDatabaseInteractor(this); mImportOpHelper = new CryptoOperationHelper<>(1, this, this, null); setTitle(null); @@ -318,7 +318,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements // or start new ones. getSupportLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this); - mNfcHelper = new NfcHelper(this, mDatabaseInteractor); + mNfcHelper = new NfcHelper(this, mKeyRepository); mNfcHelper.initNfc(mDataUri); if (savedInstanceState == null && getIntent().hasExtra(EXTRA_DISPLAY_RESULT)) { @@ -399,7 +399,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements } case R.id.menu_key_view_refresh: { try { - updateFromKeyserver(mDataUri, mDatabaseInteractor); + updateFromKeyserver(mDataUri, mKeyRepository); } catch (PgpKeyNotFoundException e) { Notify.create(this, R.string.error_key_not_found, Notify.Style.ERROR).show(); } @@ -550,7 +550,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements private boolean keyHasPassphrase() { try { SecretKeyType secretKeyType = - mDatabaseInteractor.getCachedPublicKeyRing(mMasterKeyId).getSecretKeyType(mMasterKeyId); + mKeyRepository.getCachedPublicKeyRing(mMasterKeyId).getSecretKeyType(mMasterKeyId); switch (secretKeyType) { // all of these make no sense to ask case PASSPHRASE_EMPTY: @@ -666,7 +666,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements try { // if the security token matches a subkey in any key - CachedPublicKeyRing ring = mDatabaseInteractor.getCachedPublicKeyRing( + CachedPublicKeyRing ring = mKeyRepository.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(tokenId)); byte[] candidateFp = ring.getFingerprint(); @@ -741,7 +741,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements return; } try { - long keyId = DatabaseInteractor.createDatabaseInteractor(this) + long keyId = KeyRepository.createDatabaseInteractor(this) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); long[] encryptionKeyIds = new long[]{keyId}; @@ -765,7 +765,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements private void startSafeSlinger(Uri dataUri) { long keyId = 0; try { - keyId = DatabaseInteractor.createDatabaseInteractor(this) + keyId = KeyRepository.createDatabaseInteractor(this) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { @@ -1118,7 +1118,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements // CryptoOperationHelper.Callback functions - private void updateFromKeyserver(Uri dataUri, DatabaseInteractor databaseInteractor) + private void updateFromKeyserver(Uri dataUri, KeyRepository keyRepository) throws PgpKeyNotFoundException { mIsRefreshing = true; @@ -1126,7 +1126,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements mRefreshItem.setActionView(mRefresh); mRefresh.startAnimation(mRotate); - byte[] blob = databaseInteractor.getCachedPublicKeyRing(dataUri).getFingerprint(); + byte[] blob = keyRepository.getCachedPublicKeyRing(dataUri).getFingerprint(); String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob); ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null, null); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java index a87c9a13f..797362c8d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java @@ -43,7 +43,7 @@ import com.astuetz.PagerSlidingTabStrip; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.operations.results.OperationResult; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.base.BaseActivity; @@ -54,7 +54,7 @@ import org.sufficientlysecure.keychain.util.Log; public class ViewKeyAdvActivity extends BaseActivity implements LoaderCallbacks, OnPageChangeListener { - DatabaseInteractor mDatabaseInteractor; + KeyRepository mKeyRepository; protected Uri mDataUri; @@ -87,7 +87,7 @@ public class ViewKeyAdvActivity extends BaseActivity implements } }); - mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(this); + mKeyRepository = KeyRepository.createDatabaseInteractor(this); mViewPager = (ViewPager) findViewById(R.id.pager); mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tab_layout); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index 20ecc640d..6c7602079 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -58,7 +58,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.ui.base.LoaderFragment; @@ -95,8 +95,8 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements View view = inflater.inflate(R.layout.view_key_adv_share_fragment, getContainer()); ContentResolver contentResolver = ViewKeyAdvShareFragment.this.getActivity().getContentResolver(); - DatabaseInteractor databaseInteractor = DatabaseInteractor.createDatabaseInteractor(getContext()); - mNfcHelper = new NfcHelper(getActivity(), databaseInteractor); + KeyRepository keyRepository = KeyRepository.createDatabaseInteractor(getContext()); + mNfcHelper = new NfcHelper(getActivity(), keyRepository); mFingerprintView = (TextView) view.findViewById(R.id.view_key_fingerprint); mQrCode = (ImageView) view.findViewById(R.id.view_key_qr_code); @@ -202,7 +202,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements private void startSafeSlinger(Uri dataUri) { long keyId = 0; try { - keyId = DatabaseInteractor.createDatabaseInteractor(getContext()) + keyId = KeyRepository.createDatabaseInteractor(getContext()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { @@ -218,12 +218,12 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements if (activity == null || mFingerprint == null) { return; } - DatabaseInteractor databaseInteractor = - DatabaseInteractor.createDatabaseInteractor(getContext()); + KeyRepository keyRepository = + KeyRepository.createDatabaseInteractor(getContext()); try { - long masterKeyId = databaseInteractor.getCachedPublicKeyRing(mDataUri).extractOrGetMasterKeyId(); - String content = databaseInteractor.getPublicKeyRingAsArmoredString(masterKeyId); + long masterKeyId = keyRepository.getCachedPublicKeyRing(mDataUri).extractOrGetMasterKeyId(); + String content = keyRepository.getPublicKeyRingAsArmoredString(masterKeyId); if (toClipboard) { ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); @@ -276,7 +276,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements } catch (PgpGeneralException | IOException e) { Log.e(Constants.TAG, "error processing key!", e); Notify.create(activity, R.string.error_key_processing, Notify.Style.ERROR).show(); - } catch (PgpKeyNotFoundException | DatabaseInteractor.NotFoundException e) { + } catch (PgpKeyNotFoundException | KeyRepository.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); Notify.create(activity, R.string.error_key_not_found, Notify.Style.ERROR).show(); } @@ -460,7 +460,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements private void uploadToKeyserver() { long keyId; try { - keyId = DatabaseInteractor.createDatabaseInteractor(getContext()) + keyId = KeyRepository.createDatabaseInteractor(getContext()) .getCachedPublicKeyRing(mDataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index af61873ad..45c54f58c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -46,7 +46,7 @@ import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.ViewKeyActivity; @@ -66,7 +66,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter mData; private KeyState[] mKeyStates; - private DatabaseInteractor mDatabaseInteractor; + private KeyRepository mKeyRepository; public ImportKeysAdapter(FragmentActivity activity, ImportKeysListener listener, boolean nonInteractive) { @@ -75,7 +75,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter data) { @@ -90,13 +90,13 @@ public class ImportKeysAdapter extends RecyclerView.Adapter 0; - } catch (DatabaseInteractor.NotFoundException | PgpKeyNotFoundException ignored) { + } catch (KeyRepository.NotFoundException | PgpKeyNotFoundException ignored) { } mKeyStates[i] = keyState; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java index 4087b88d7..fae9ddb1a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java @@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.securitytoken.CardException; import org.sufficientlysecure.keychain.securitytoken.NfcTransport; @@ -105,7 +105,7 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity final long subKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mSecurityTokenFingerprints); try { - CachedPublicKeyRing ring = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing( + CachedPublicKeyRing ring = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); long masterKeyId = ring.getMasterKeyId(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java index a7c5f11ed..d750e105e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java @@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.ui.base.BaseActivity; @@ -58,7 +58,7 @@ public class LinkedIdWizard extends BaseActivity { try { Uri uri = getIntent().getData(); uri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(uri); - CachedPublicKeyRing ring = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(uri); + CachedPublicKeyRing ring = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(uri); if (!ring.hasAnySecret()) { Log.e(Constants.TAG, "Linked Identities can only be added to secret keys!"); finish(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java index 66ff29059..f0136c37e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java @@ -39,8 +39,8 @@ import android.provider.Settings; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; +import org.sufficientlysecure.keychain.provider.KeyRepository; +import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException; import org.sufficientlysecure.keychain.ui.util.Notify; /** @@ -50,7 +50,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify; public class NfcHelper { private Activity mActivity; - private DatabaseInteractor mDatabaseInteractor; + private KeyRepository mKeyRepository; /** * NFC: This handler receives a message from onNdefPushComplete @@ -66,9 +66,9 @@ public class NfcHelper { /** * Initializes the NfcHelper. */ - public NfcHelper(final Activity activity, final DatabaseInteractor databaseInteractor) { + public NfcHelper(final Activity activity, final KeyRepository keyRepository) { mActivity = activity; - mDatabaseInteractor = databaseInteractor; + mKeyRepository = keyRepository; mNfcHandler = new NfcHandler(mActivity); } @@ -128,9 +128,9 @@ public class NfcHelper { new AsyncTask() { protected Void doInBackground(Void... unused) { try { - long masterKeyId = mDatabaseInteractor.getCachedPublicKeyRing(dataUri) + long masterKeyId = mKeyRepository.getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); - mNfcKeyringBytes = mDatabaseInteractor.loadPublicKeyRingData(masterKeyId); + mNfcKeyringBytes = mKeyRepository.loadPublicKeyRingData(masterKeyId); } catch (NotFoundException | PgpKeyNotFoundException e) { Log.e(Constants.TAG, "key not found!", e); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java index 9f3e3c7e2..3e42efb90 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java @@ -44,7 +44,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow; import org.sufficientlysecure.keychain.pgp.WrappedSignature; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.BackupKeyringParcel; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; @@ -135,8 +135,8 @@ public class BackupOperationTest { @Before public void setUp() { - DatabaseReadWriteInteractor databaseInteractor = - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); + KeyWritableRepository databaseInteractor = + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; @@ -151,7 +151,7 @@ public class BackupOperationTest { @Test public void testExportAllLocalStripped() throws Exception { BackupOperation op = new BackupOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); // make sure there is a local cert (so the later checks that there are none are meaningful) assertTrue("second keyring has local certification", checkForLocal(mStaticRing2)); @@ -250,7 +250,7 @@ public class BackupOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); BackupOperation op = new BackupOperation(spyApplication, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); BackupKeyringParcel parcel = new BackupKeyringParcel( new long[] { mStaticRing1.getMasterKeyId() }, false, false, true, fakeOutputUri); @@ -307,7 +307,7 @@ public class BackupOperationTest { { // export encrypted BackupOperation op = new BackupOperation(spyApplication, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); BackupKeyringParcel parcel = new BackupKeyringParcel( new long[] { mStaticRing1.getMasterKeyId() }, false, true, true, fakeOutputUri); @@ -325,7 +325,7 @@ public class BackupOperationTest { { PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(outStream.toByteArray()); input.setAllowSymmetricDecryption(true); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java index 6f84da91e..c3aba0289 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java @@ -25,7 +25,7 @@ import org.junit.runner.RunWith; import org.robolectric.RuntimeEnvironment; import org.robolectric.shadows.ShadowLog; import org.sufficientlysecure.keychain.KeychainTestRunner; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.service.BenchmarkInputParcel; import java.io.PrintStream; @@ -47,7 +47,7 @@ public class BenchmarkOperationTest { @Test public void testBenchmark() throws Exception { BenchmarkOperation op = new BenchmarkOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); op.execute(new BenchmarkInputParcel(), null); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java index e77055ef5..8b98456db 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java @@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; @@ -117,8 +117,8 @@ public class CertifyOperationTest { @Before public void setUp() throws Exception { - DatabaseReadWriteInteractor databaseInteractor = - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); + KeyWritableRepository databaseInteractor = + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; @@ -133,7 +133,7 @@ public class CertifyOperationTest { @Test public void testSelfCertifyFlag() throws Exception { - CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing1.getMasterKeyId()); Assert.assertEquals("secret key must be marked self-certified in database", // TODO this should be more correctly be VERIFIED_SELF at some point! @@ -144,10 +144,10 @@ public class CertifyOperationTest { @Test public void testCertifyId() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); { - CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("public key must not be marked verified prior to certification", Certs.UNVERIFIED, ring.getVerified()); @@ -161,7 +161,7 @@ public class CertifyOperationTest { Assert.assertTrue("certification must succeed", result.success()); { - CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("new key must be verified now", Certs.VERIFIED_SECRET, ring.getVerified()); @@ -172,10 +172,10 @@ public class CertifyOperationTest { @Test public void testCertifyAttribute() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); { - CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("public key must not be marked verified prior to certification", Certs.UNVERIFIED, ring.getVerified()); @@ -189,7 +189,7 @@ public class CertifyOperationTest { Assert.assertTrue("certification must succeed", result.success()); { - CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("new key must be verified now", Certs.VERIFIED_SECRET, ring.getVerified()); @@ -201,7 +201,7 @@ public class CertifyOperationTest { @Test public void testCertifySelf() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(), @@ -218,7 +218,7 @@ public class CertifyOperationTest { public void testCertifyNonexistent() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); { CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java index 6c4cfe270..5a7eaff83 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java @@ -38,7 +38,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.PromoteKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; @@ -90,8 +90,8 @@ public class PromoteKeyOperationTest { @Before public void setUp() throws Exception { - DatabaseReadWriteInteractor databaseInteractor = - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); + KeyWritableRepository databaseInteractor = + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; @@ -105,14 +105,14 @@ public class PromoteKeyOperationTest { @Test public void testPromote() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); PromoteKeyResult result = op.execute(new PromoteKeyringParcel(mStaticRing.getMasterKeyId(), null, null), null); Assert.assertTrue("promotion must succeed", result.success()); { - CachedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) + CachedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCachedPublicKeyRing(mStaticRing.getMasterKeyId()); Assert.assertTrue("key must have a secret now", ring.hasAnySecret()); @@ -129,7 +129,7 @@ public class PromoteKeyOperationTest { @Test public void testPromoteDivert() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); byte[] aid = Hex.decode("D2760001240102000000012345670000"); @@ -138,7 +138,7 @@ public class PromoteKeyOperationTest { Assert.assertTrue("promotion must succeed", result.success()); { - CanonicalizedSecretKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedSecretKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { @@ -154,7 +154,7 @@ public class PromoteKeyOperationTest { @Test public void testPromoteDivertSpecific() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); byte[] aid = Hex.decode("D2760001240102000000012345670000"); @@ -168,7 +168,7 @@ public class PromoteKeyOperationTest { Assert.assertTrue("promotion must succeed", result.success()); { - CanonicalizedSecretKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) + CanonicalizedSecretKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java index 91b5fac0b..2c1c2ba4b 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java @@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.KeychainTestRunner; import org.sufficientlysecure.keychain.operations.InputDataOperation; import org.sufficientlysecure.keychain.operations.results.InputDataResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.InputDataParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -126,7 +126,7 @@ public class InputDataOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); InputDataOperation op = new InputDataOperation(spyApplication, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputDataParcel input = new InputDataParcel(fakeInputUri, null); @@ -306,7 +306,7 @@ public class InputDataOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); InputDataOperation op = new InputDataOperation(spyApplication, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputDataParcel input = new InputDataParcel(FAKE_CONTENT_INPUT_URI_1, null); return op.execute(input, new CryptoInputParcel()); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java index 4288d2b89..c36ee3128 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java @@ -40,7 +40,7 @@ import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; @@ -149,8 +149,8 @@ public class PgpEncryptDecryptTest { @Before public void setUp() { - DatabaseReadWriteInteractor databaseInteractor = - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); + KeyWritableRepository databaseInteractor = + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; @@ -173,7 +173,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -198,7 +198,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute( @@ -228,7 +228,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute(input, @@ -250,7 +250,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute(input, @@ -271,7 +271,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(false); DecryptVerifyResult result = op.execute(input, @@ -298,7 +298,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -354,7 +354,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -416,7 +416,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -473,7 +473,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -576,7 +576,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -627,12 +627,12 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - DatabaseReadWriteInteractor databaseInteractor = - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); + KeyWritableRepository databaseInteractor = + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1)); @@ -650,12 +650,12 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - DatabaseReadWriteInteractor databaseInteractor = - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); + KeyWritableRepository databaseInteractor = + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1)); @@ -678,8 +678,8 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - DatabaseReadWriteInteractor databaseInteractor = - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); + KeyWritableRepository databaseInteractor = + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); } @@ -689,7 +689,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -734,7 +734,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -828,7 +828,7 @@ public class PgpEncryptDecryptTest { { // decryption with passphrase cached should succeed for the other key if first is gone // delete first key from database - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete( + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete( KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null ); @@ -863,7 +863,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -911,7 +911,7 @@ public class PgpEncryptDecryptTest { { // decryption with passphrase cached should succeed for the other key if first is gone // delete first key from database - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete( + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete( KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null ); @@ -950,7 +950,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaindata); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -1022,7 +1022,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -1073,7 +1073,7 @@ public class PgpEncryptDecryptTest { final Passphrase passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) { return new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null) { + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null) { @Override public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId) throws NoSecretKeyException { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java index c1f4da4bf..bd75e356b 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java @@ -243,7 +243,7 @@ public class InteropTest { final Uri verifyUri = verify != null ? KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(verify.getMasterKeyId()) : null; - DatabaseReadWriteInteractor helper = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) { + KeyWritableRepository helper = new KeyWritableRepository(RuntimeEnvironment.application) { @Override public CachedPublicKeyRing getCachedPublicKeyRing(Uri queryUri) throws PgpKeyNotFoundException { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorKeyringTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/KeyRepositoryKeyringTest.java similarity index 98% rename from OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorKeyringTest.java rename to OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/KeyRepositoryKeyringTest.java index 608ecd950..9e6cc03c4 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorKeyringTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/KeyRepositoryKeyringTest.java @@ -30,7 +30,7 @@ import java.util.Collection; import java.util.Collections; @RunWith(KeychainTestRunner.class) -public class DatabaseInteractorKeyringTest { +public class KeyRepositoryKeyringTest { @Test public void testSavePublicKeyring() throws Exception { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/KeyRepositorySaveTest.java similarity index 90% rename from OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java rename to OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/KeyRepositorySaveTest.java index 84d3bc644..b4f7f13fb 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/KeyRepositorySaveTest.java @@ -41,10 +41,10 @@ import java.util.Arrays; import java.util.Iterator; @RunWith(KeychainTestRunner.class) -public class DatabaseInteractorSaveTest { +public class KeyRepositorySaveTest { - DatabaseReadWriteInteractor mDatabaseInteractor = - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); + KeyWritableRepository mDatabaseInteractor = + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); @BeforeClass public static void setUpOnce() throws Exception { @@ -62,17 +62,17 @@ public class DatabaseInteractorSaveTest { SaveKeyringResult result; // insert both keys, second should fail - result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); + result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); Assert.assertTrue("first keyring import should succeed", result.success()); - result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); + result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); Assert.assertFalse("second keyring import should fail", result.success()); new KeychainDatabase(RuntimeEnvironment.application).clearDatabase(); // and the other way around - result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); + result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); Assert.assertTrue("first keyring import should succeed", result.success()); - result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); + result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); Assert.assertFalse("second keyring import should fail", result.success()); } @@ -91,14 +91,14 @@ public class DatabaseInteractorSaveTest { SaveKeyringResult result; // insert secret, this should fail because of missing self-cert - result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) + result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .saveSecretKeyRing(seckey, new ProgressScaler()); Assert.assertFalse("secret keyring import before pubring import should fail", result.success()); // insert pubkey, then seckey - both should succeed - result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(pubkey); + result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(pubkey); Assert.assertTrue("public keyring import should succeed", result.success()); - result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) + result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) .saveSecretKeyRing(seckey, new ProgressScaler()); Assert.assertTrue("secret keyring import after pubring import should succeed", result.success()); @@ -247,7 +247,7 @@ public class DatabaseInteractorSaveTest { } UncachedKeyRing readRingFromResource(String name) throws Exception { - return UncachedKeyRing.fromStream(DatabaseInteractorSaveTest.class.getResourceAsStream(name)).next(); + return UncachedKeyRing.fromStream(KeyRepositorySaveTest.class.getResourceAsStream(name)).next(); } } \ No newline at end of file diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java index 4a972461c..9568e33c3 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java @@ -20,9 +20,9 @@ import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.provider.KeychainExternalContract.EmailStatus; -import org.sufficientlysecure.keychain.provider.DatabaseInteractorSaveTest; +import org.sufficientlysecure.keychain.provider.KeyRepositorySaveTest; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -45,8 +45,8 @@ public class KeychainExternalProviderTest { static final long KEY_ID_PUBLIC = 0x9A282CE2AB44A382L; - DatabaseReadWriteInteractor databaseInteractor = - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); + KeyWritableRepository databaseInteractor = + KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver(); ApiPermissionHelper apiPermissionHelper; ApiDataAccessObject apiDao; @@ -207,6 +207,6 @@ public class KeychainExternalProviderTest { } UncachedKeyRing readRingFromResource(String name) throws Exception { - return UncachedKeyRing.fromStream(DatabaseInteractorSaveTest.class.getResourceAsStream(name)).next(); + return UncachedKeyRing.fromStream(KeyRepositorySaveTest.class.getResourceAsStream(name)).next(); } } \ No newline at end of file diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/DatabaseInteractorStub.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyRepositoryStub.java similarity index 85% rename from OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/DatabaseInteractorStub.java rename to OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyRepositoryStub.java index 4947aff30..d96019e0f 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/DatabaseInteractorStub.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyRepositoryStub.java @@ -21,11 +21,11 @@ import android.content.Context; import android.net.Uri; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; -class DatabaseInteractorStub extends DatabaseReadWriteInteractor { - public DatabaseInteractorStub(Context context) { +class KeyRepositoryStub extends KeyWritableRepository { + public KeyRepositoryStub(Context context) { super(context); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java index 9c549468a..34558b5bf 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java @@ -23,9 +23,9 @@ import android.content.Context; import org.bouncycastle.util.Arrays; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; -import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; +import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.util.ProgressScaler; import java.io.ByteArrayInputStream; @@ -51,8 +51,8 @@ public class KeyringTestingHelper { public boolean addKeyring(Collection blobFiles) throws Exception { - DatabaseReadWriteInteractor databaseInteractor = - DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context); + KeyWritableRepository databaseInteractor = + KeyWritableRepository.createDatabaseReadWriteInteractor(context); byte[] data = TestDataUtil.readAllFully(blobFiles); UncachedKeyRing ring = UncachedKeyRing.decodeFromData(data); @@ -347,11 +347,11 @@ public class KeyringTestingHelper { return getNth(ring.getPublicKeys(), position).getKeyId(); } - private void retrieveKeyAndExpectNotFound(DatabaseInteractor databaseInteractor, long masterKeyId) { + private void retrieveKeyAndExpectNotFound(KeyRepository keyRepository, long masterKeyId) { try { - databaseInteractor.getCanonicalizedPublicKeyRing(masterKeyId); + keyRepository.getCanonicalizedPublicKeyRing(masterKeyId); throw new AssertionError("Was expecting the previous call to fail!"); - } catch (DatabaseReadWriteInteractor.NotFoundException expectedException) { + } catch (KeyWritableRepository.NotFoundException expectedException) { // good } } From 9cf0b05202540d6a3a0b21647a9fc852255169d9 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 24 Feb 2017 18:24:51 +0100 Subject: [PATCH 09/11] fix unit tests --- .../provider/KeyWritableRepository.java | 11 +++--- .../keychain/provider/InteropTest.java | 3 +- .../keychain/support/KeyRepositoryStub.java | 37 ------------------- 3 files changed, 7 insertions(+), 44 deletions(-) delete mode 100644 OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyRepositoryStub.java diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java index 1e536c85a..7e45f1628 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java @@ -36,6 +36,7 @@ import android.database.Cursor; import android.net.Uri; import android.os.RemoteException; import android.support.annotation.NonNull; +import android.support.annotation.VisibleForTesting; import android.support.v4.util.LongSparseArray; import org.openintents.openpgp.util.OpenPgpUtils; @@ -98,15 +99,13 @@ public class KeyWritableRepository extends KeyRepository { return new KeyWritableRepository(context, localPublicKeyStorage); } - private KeyWritableRepository(Context context, LocalPublicKeyStorage localPublicKeyStorage) { + @VisibleForTesting + KeyWritableRepository(Context context, LocalPublicKeyStorage localPublicKeyStorage) { this(context, localPublicKeyStorage, new OperationLog(), 0); } - private KeyWritableRepository(Context context, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log) { - this(context, localPublicKeyStorage, log, 0); - } - - private KeyWritableRepository(Context context, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log, int indent) { + private KeyWritableRepository( + Context context, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log, int indent) { super(context.getContentResolver(), localPublicKeyStorage, log, indent); mContext = context; diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java index bd75e356b..9d5a6a919 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java @@ -243,7 +243,8 @@ public class InteropTest { final Uri verifyUri = verify != null ? KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(verify.getMasterKeyId()) : null; - KeyWritableRepository helper = new KeyWritableRepository(RuntimeEnvironment.application) { + KeyWritableRepository helper = new KeyWritableRepository(RuntimeEnvironment.application, + LocalPublicKeyStorage.getInstance(RuntimeEnvironment.application)) { @Override public CachedPublicKeyRing getCachedPublicKeyRing(Uri queryUri) throws PgpKeyNotFoundException { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyRepositoryStub.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyRepositoryStub.java deleted file mode 100644 index d96019e0f..000000000 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyRepositoryStub.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) Art O Cathain - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.support; - -import android.content.Context; -import android.net.Uri; - -import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.KeyWritableRepository; - - -class KeyRepositoryStub extends KeyWritableRepository { - public KeyRepositoryStub(Context context) { - super(context); - } - - @Override - public CanonicalizedPublicKeyRing getCanonicalizedPublicKeyRing(Uri id) throws NotFoundException { - byte[] data = TestDataUtil.readFully(getClass().getResourceAsStream("/public-key-for-sample.blob")); - return new CanonicalizedPublicKeyRing(data, 0); - } -} From 05e4cf1ab6249db17a5ab5d06b34516e253b5add Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 24 Feb 2017 18:37:30 +0100 Subject: [PATCH 10/11] focus key deletion into KeyWritableRepository --- .../keychain/operations/DeleteOperation.java | 8 +++----- .../keychain/provider/CachedPublicKeyRing.java | 9 ++------- .../keychain/provider/KeyWritableRepository.java | 13 ++++++++++++- .../keychain/provider/LocalPublicKeyStorage.java | 10 ++++++++++ 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java index 2c3c0ee92..94cf279bf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java @@ -17,6 +17,7 @@ package org.sufficientlysecure.keychain.operations; + import android.content.Context; import android.support.annotation.NonNull; @@ -27,7 +28,6 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.LogTyp import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.provider.KeyWritableRepository; -import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.DeleteKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -81,10 +81,8 @@ public class DeleteOperation extends BaseReadWriteOperation cancelled = true; break; } - int count = mKeyRepository.getContentResolver().delete( - KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null - ); - if (count > 0) { + boolean deleteSuccess = mKeyWritableRepository.deleteKeyRing(masterKeyId); + if (deleteSuccess) { log.add(LogType.MSG_DEL_KEY, 1, KeyFormattingUtils.beautifyKeyId(masterKeyId)); success += 1; } else { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java index a9e660a76..81b775b5f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java @@ -18,16 +18,16 @@ package org.sufficientlysecure.keychain.provider; -import android.database.Cursor; + import android.net.Uri; import org.sufficientlysecure.keychain.Constants; 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.KeyRepository.NotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; -import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException; import org.sufficientlysecure.keychain.util.Log; /** This implementation of KeyRing provides a cached view of PublicKeyRing @@ -224,11 +224,6 @@ public class CachedPublicKeyRing extends KeyRing { } } - private Cursor getSubkeys() throws PgpKeyNotFoundException { - Uri keysUri = KeychainContract.Keys.buildKeysUri(extractOrGetMasterKeyId()); - return mKeyRepository.getContentResolver().query(keysUri, null, null, null, null); - } - public SecretKeyType getSecretKeyType(long keyId) throws NotFoundException { Object data = mKeyRepository.getGenericData(Keys.buildKeysUri(mUri), KeyRings.HAS_SECRET, diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java index 7e45f1628..2ac840f1b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java @@ -552,7 +552,7 @@ public class KeyWritableRepository extends KeyRepository { lastUpdatedCursor.close(); try { - // delete old version of this keyRing, which also deletes all keys and userIds on cascade + // delete old version of this keyRing (from database only!), which also deletes all keys and userIds on cascade int deleted = mContentResolver.delete( KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null); if (deleted > 0) { @@ -611,6 +611,17 @@ public class KeyWritableRepository extends KeyRepository { return mContentResolver.insert(uri, values); } + public boolean deleteKeyRing(long masterKeyId) { + try { + mLocalPublicKeyStorage.deletePublicKey(masterKeyId); + } catch (IOException e) { + android.util.Log.e(Constants.TAG, "Could not delete file!", e); + return false; + } + int deletedRows = mContentResolver.delete(KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null); + return deletedRows > 0; + } + private static class UserPacketItem implements Comparable { Integer type; String userId; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/LocalPublicKeyStorage.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/LocalPublicKeyStorage.java index ff369d49e..ace8d2527 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/LocalPublicKeyStorage.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/LocalPublicKeyStorage.java @@ -75,4 +75,14 @@ class LocalPublicKeyStorage { return baos.toByteArray(); } + + void deletePublicKey(long masterKeyId) throws IOException { + File publicKeyFile = getPublicKeyFile(masterKeyId); + if (publicKeyFile.exists()) { + boolean deleteSuccess = publicKeyFile.delete(); + if (!deleteSuccess) { + throw new IOException("File exists, but could not be deleted!"); + } + } + } } From 3f674f8bbe8cf85d91b932ed312f9c565a4bcdcc Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 27 Feb 2017 15:13:15 +0100 Subject: [PATCH 11/11] nicer errors if key cannot be found in preselect --- .../keychain/ui/EncryptModeAsymmetricFragment.java | 13 +++++++++++-- OpenKeychain/src/main/res/values/strings.xml | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptModeAsymmetricFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptModeAsymmetricFragment.java index ea2e4fe46..2f4b882b0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptModeAsymmetricFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptModeAsymmetricFragment.java @@ -38,6 +38,9 @@ import org.sufficientlysecure.keychain.provider.KeyRepository; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter.KeyItem; +import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; +import org.sufficientlysecure.keychain.ui.util.Notify; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.ui.widget.EncryptKeyCompletionView; import org.sufficientlysecure.keychain.ui.widget.KeySpinner; import org.sufficientlysecure.keychain.ui.widget.KeySpinner.OnKeyChangedListener; @@ -141,7 +144,10 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment { mSignKeySpinner.setPreSelectedKeyId(signatureKeyId); } } catch (PgpKeyNotFoundException e) { - Log.e(Constants.TAG, "key not found!", e); + Log.e(Constants.TAG, "key not found for signing!", e); + Notify.create(getActivity(), getString(R.string.error_preselect_sign_key, + KeyFormattingUtils.beautifyKeyId(signatureKeyId)), + Style.ERROR).show(); } } @@ -152,7 +158,10 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment { mKeyRepository.getCanonicalizedPublicKeyRing(preselectedId); mEncryptKeyView.addObject(new KeyItem(ring)); } catch (NotFoundException e) { - Log.e(Constants.TAG, "key not found!", e); + Log.e(Constants.TAG, "key not found for encryption!", e); + Notify.create(getActivity(), getString(R.string.error_preselect_encrypt_key, + KeyFormattingUtils.beautifyKeyId(preselectedId)), + Style.ERROR).show(); } } // This is to work-around a rendering bug in TokenCompleteTextView diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index 1cd919492..77aa967a5 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -1805,4 +1805,6 @@ Allow Cancel Requested key: + Error selecting key %s for signing! + Error selecting key %s for encryption!