DatabaseInteractor -> KeyRepository

This commit is contained in:
Vincent Breitmoser
2017-02-24 18:24:11 +01:00
parent c7e01926e1
commit 2124a4598a
65 changed files with 419 additions and 419 deletions

View File

@@ -38,7 +38,7 @@ import com.nispok.snackbar.Snackbar;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow; 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.provider.KeychainDatabase;
import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.ui.util.Notify.Style;
@@ -97,7 +97,7 @@ public class TestHelpers {
IteratorWithIOThrow<UncachedKeyRing> stream = UncachedKeyRing.fromStream( IteratorWithIOThrow<UncachedKeyRing> stream = UncachedKeyRing.fromStream(
getInstrumentation().getContext().getAssets().open(name)); getInstrumentation().getContext().getAssets().open(name));
DatabaseReadWriteInteractor helper = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context); KeyWritableRepository helper = KeyWritableRepository.createDatabaseReadWriteInteractor(context);
while(stream.hasNext()) { while(stream.hasNext()) {
UncachedKeyRing ring = stream.next(); UncachedKeyRing ring = stream.next();
if (ring.isSecret()) { if (ring.isSecret()) {

View File

@@ -27,7 +27,7 @@ import android.view.View;
import com.tokenautocomplete.TokenCompleteTextView; import com.tokenautocomplete.TokenCompleteTextView;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; 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 org.sufficientlysecure.keychain.ui.adapter.KeyAdapter;
import static android.support.test.InstrumentationRegistry.getTargetContext; import static android.support.test.InstrumentationRegistry.getTargetContext;
@@ -37,7 +37,7 @@ public abstract class CustomActions {
public static ViewAction tokenEncryptViewAddToken(long keyId) throws Exception { public static ViewAction tokenEncryptViewAddToken(long keyId) throws Exception {
CanonicalizedPublicKeyRing ring = CanonicalizedPublicKeyRing ring =
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(getTargetContext()).getCanonicalizedPublicKeyRing(keyId); KeyWritableRepository.createDatabaseReadWriteInteractor(getTargetContext()).getCanonicalizedPublicKeyRing(keyId);
final Object item = new KeyAdapter.KeyItem(ring); final Object item = new KeyAdapter.KeyItem(ring);
return new ViewAction() { return new ViewAction() {

View File

@@ -52,8 +52,8 @@ import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
@@ -84,14 +84,14 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
private static final int INDEX_MASTER_KEY_ID = 0; private static final int INDEX_MASTER_KEY_ID = 0;
private static final int INDEX_HAS_ANY_SECRET = 1; private static final int INDEX_HAS_ANY_SECRET = 1;
public BackupOperation(Context context, DatabaseInteractor databaseInteractor, Progressable public BackupOperation(Context context, KeyRepository keyRepository, Progressable
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) { Progressable progressable, AtomicBoolean cancelled) {
super(context, databaseInteractor, progressable, cancelled); super(context, keyRepository, progressable, cancelled);
} }
@NonNull @NonNull
@@ -168,7 +168,7 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
private PgpSignEncryptResult encryptBackupData(@NonNull BackupKeyringParcel backupInput, private PgpSignEncryptResult encryptBackupData(@NonNull BackupKeyringParcel backupInput,
@NonNull CryptoInputParcel cryptoInput, @Nullable OutputStream outputStream, Uri plainUri, long exportedDataSize) @NonNull CryptoInputParcel cryptoInput, @Nullable OutputStream outputStream, Uri plainUri, long exportedDataSize)
throws FileNotFoundException { throws FileNotFoundException {
PgpSignEncryptOperation signEncryptOperation = new PgpSignEncryptOperation(mContext, mDatabaseInteractor, mProgressable, mCancelled); PgpSignEncryptOperation signEncryptOperation = new PgpSignEncryptOperation(mContext, mKeyRepository, mProgressable, mCancelled);
PgpSignEncryptData data = new PgpSignEncryptData(); PgpSignEncryptData data = new PgpSignEncryptData();
data.setSymmetricPassphrase(cryptoInput.getPassphrase()); data.setSymmetricPassphrase(cryptoInput.getPassphrase());
@@ -270,7 +270,7 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
try { try {
arOutStream = new ArmoredOutputStream(outStream); arOutStream = new ArmoredOutputStream(outStream);
byte[] data = mDatabaseInteractor.loadPublicKeyRingData(masterKeyId); byte[] data = mKeyRepository.loadPublicKeyRingData(masterKeyId);
UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(data); UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(data);
CanonicalizedPublicKeyRing ring = (CanonicalizedPublicKeyRing) uncachedKeyRing.canonicalize(log, 2, true); CanonicalizedPublicKeyRing ring = (CanonicalizedPublicKeyRing) uncachedKeyRing.canonicalize(log, 2, true);
ring.encode(arOutStream); ring.encode(arOutStream);
@@ -290,7 +290,7 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
try { try {
arOutStream = new ArmoredOutputStream(outStream); arOutStream = new ArmoredOutputStream(outStream);
byte[] data = mDatabaseInteractor.loadSecretKeyRingData(masterKeyId); byte[] data = mKeyRepository.loadSecretKeyRingData(masterKeyId);
UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(data); UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(data);
CanonicalizedSecretKeyRing ring = (CanonicalizedSecretKeyRing) uncachedKeyRing.canonicalize(log, 2, true); CanonicalizedSecretKeyRing ring = (CanonicalizedSecretKeyRing) uncachedKeyRing.canonicalize(log, 2, true);
ring.encode(arOutStream); ring.encode(arOutStream);
@@ -323,7 +323,7 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
+ " IN (" + placeholders + ")"; + " IN (" + placeholders + ")";
} }
return mDatabaseInteractor.getContentResolver().query( return mKeyRepository.getContentResolver().query(
KeyRings.buildUnifiedKeyRingsUri(), PROJECTION, selection, selectionArgs, KeyRings.buildUnifiedKeyRingsUri(), PROJECTION, selection, selectionArgs,
Tables.KEYS + "." + KeyRings.MASTER_KEY_ID Tables.KEYS + "." + KeyRings.MASTER_KEY_ID
); );

View File

@@ -29,8 +29,8 @@ import org.sufficientlysecure.keychain.Constants.key;
import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.pgp.PassphraseCacheInterface; import org.sufficientlysecure.keychain.pgp.PassphraseCacheInterface;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.Passphrase;
@@ -41,7 +41,7 @@ public abstract class BaseOperation<T extends Parcelable> implements PassphraseC
final public Progressable mProgressable; final public Progressable mProgressable;
final public AtomicBoolean mCancelled; final public AtomicBoolean mCancelled;
final public DatabaseInteractor mDatabaseInteractor; final public KeyRepository mKeyRepository;
/** An abstract base class for all *Operation classes. It provides a number /** An abstract base class for all *Operation classes. It provides a number
* of common methods for progress, cancellation and passphrase cache handling. * of common methods for progress, cancellation and passphrase cache handling.
@@ -65,18 +65,18 @@ public abstract class BaseOperation<T extends Parcelable> implements PassphraseC
* if there is no prefix it is considered Android-related. * 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.mContext = context;
this.mProgressable = progressable; this.mProgressable = progressable;
this.mDatabaseInteractor = databaseInteractor; this.mKeyRepository = keyRepository;
mCancelled = null; mCancelled = null;
} }
public BaseOperation(Context context, DatabaseInteractor databaseInteractor, public BaseOperation(Context context, KeyRepository keyRepository,
Progressable progressable, AtomicBoolean cancelled) { Progressable progressable, AtomicBoolean cancelled) {
mContext = context; mContext = context;
mProgressable = progressable; mProgressable = progressable;
mDatabaseInteractor = databaseInteractor; mKeyRepository = keyRepository;
mCancelled = cancelled; mCancelled = cancelled;
} }
@@ -115,7 +115,7 @@ public abstract class BaseOperation<T extends Parcelable> implements PassphraseC
public Passphrase getCachedPassphrase(long subKeyId) throws NoSecretKeyException { public Passphrase getCachedPassphrase(long subKeyId) throws NoSecretKeyException {
try { try {
if (subKeyId != key.symmetric) { if (subKeyId != key.symmetric) {
long masterKeyId = mDatabaseInteractor.getMasterKeyId(subKeyId); long masterKeyId = mKeyRepository.getMasterKeyId(subKeyId);
return getCachedPassphrase(masterKeyId, subKeyId); return getCachedPassphrase(masterKeyId, subKeyId);
} }
return getCachedPassphrase(key.symmetric, key.symmetric); return getCachedPassphrase(key.symmetric, key.symmetric);

View File

@@ -7,24 +7,24 @@ import android.content.Context;
import android.os.Parcelable; import android.os.Parcelable;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
abstract class BaseReadWriteOperation<T extends Parcelable> extends BaseOperation<T> { abstract class BaseReadWriteOperation<T extends Parcelable> extends BaseOperation<T> {
final DatabaseReadWriteInteractor mDatabaseReadWriteInteractor; final KeyWritableRepository mKeyWritableRepository;
BaseReadWriteOperation(Context context, BaseReadWriteOperation(Context context,
DatabaseReadWriteInteractor databaseInteractor, KeyWritableRepository databaseInteractor,
Progressable progressable) { Progressable progressable) {
super(context, databaseInteractor, progressable); super(context, databaseInteractor, progressable);
mDatabaseReadWriteInteractor = databaseInteractor; mKeyWritableRepository = databaseInteractor;
} }
BaseReadWriteOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, BaseReadWriteOperation(Context context, KeyWritableRepository databaseInteractor,
Progressable progressable, AtomicBoolean cancelled) { Progressable progressable, AtomicBoolean cancelled) {
super(context, databaseInteractor, progressable, cancelled); super(context, databaseInteractor, progressable, cancelled);
mDatabaseReadWriteInteractor = databaseInteractor; mKeyWritableRepository = databaseInteractor;
} }
} }

View File

@@ -45,7 +45,7 @@ import org.sufficientlysecure.keychain.pgp.PgpSecurityConstants.OpenKeychainSymm
import org.sufficientlysecure.keychain.pgp.PgpSignEncryptData; import org.sufficientlysecure.keychain.pgp.PgpSignEncryptData;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; 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.BenchmarkInputParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@@ -55,7 +55,7 @@ import org.sufficientlysecure.keychain.util.ProgressScaler;
public class BenchmarkOperation extends BaseOperation<BenchmarkInputParcel> { public class BenchmarkOperation extends BaseOperation<BenchmarkInputParcel> {
public BenchmarkOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable public BenchmarkOperation(Context context, KeyWritableRepository databaseInteractor, Progressable
progressable) { progressable) {
super(context, databaseInteractor, progressable); super(context, databaseInteractor, progressable);
} }
@@ -81,7 +81,7 @@ public class BenchmarkOperation extends BaseOperation<BenchmarkInputParcel> {
int i = 0; int i = 0;
do { do {
SignEncryptOperation op = SignEncryptOperation op =
new SignEncryptOperation(mContext, mDatabaseInteractor, new SignEncryptOperation(mContext, mKeyRepository,
new ProgressScaler(mProgressable, i*(50/numRepeats), (i+1)*(50/numRepeats), 100), mCancelled); new ProgressScaler(mProgressable, i*(50/numRepeats), (i+1)*(50/numRepeats), 100), mCancelled);
PgpSignEncryptData data = new PgpSignEncryptData(); PgpSignEncryptData data = new PgpSignEncryptData();
data.setSymmetricPassphrase(passphrase); data.setSymmetricPassphrase(passphrase);
@@ -103,7 +103,7 @@ public class BenchmarkOperation extends BaseOperation<BenchmarkInputParcel> {
do { do {
DecryptVerifyResult decryptResult; DecryptVerifyResult decryptResult;
PgpDecryptVerifyOperation op = PgpDecryptVerifyOperation op =
new PgpDecryptVerifyOperation(mContext, mDatabaseInteractor, new PgpDecryptVerifyOperation(mContext, mKeyRepository,
new ProgressScaler(mProgressable, 50 +i*(50/numRepeats), 50 +(i+1)*(50/numRepeats), 100)); new ProgressScaler(mProgressable, 50 +i*(50/numRepeats), 50 +(i+1)*(50/numRepeats), 100));
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(encryptResult.getResultBytes()); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(encryptResult.getResultBytes());
input.setAllowSymmetricDecryption(true); input.setAllowSymmetricDecryption(true);

View File

@@ -39,8 +39,8 @@ import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
@@ -62,7 +62,7 @@ import org.sufficientlysecure.keychain.util.Passphrase;
*/ */
public class CertifyOperation extends BaseReadWriteOperation<CertifyActionsParcel> { public class CertifyOperation extends BaseReadWriteOperation<CertifyActionsParcel> {
public CertifyOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable, AtomicBoolean public CertifyOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable, AtomicBoolean
cancelled) { cancelled) {
super(context, databaseInteractor, progressable, cancelled); super(context, databaseInteractor, progressable, cancelled);
} }
@@ -81,7 +81,7 @@ public class CertifyOperation extends BaseReadWriteOperation<CertifyActionsParce
log.add(LogType.MSG_CRT_MASTER_FETCH, 1); log.add(LogType.MSG_CRT_MASTER_FETCH, 1);
CachedPublicKeyRing cachedPublicKeyRing = mDatabaseInteractor.getCachedPublicKeyRing(masterKeyId); CachedPublicKeyRing cachedPublicKeyRing = mKeyRepository.getCachedPublicKeyRing(masterKeyId);
Passphrase passphrase; Passphrase passphrase;
switch (cachedPublicKeyRing.getSecretKeyType(masterKeyId)) { switch (cachedPublicKeyRing.getSecretKeyType(masterKeyId)) {
@@ -121,7 +121,7 @@ public class CertifyOperation extends BaseReadWriteOperation<CertifyActionsParce
// Get actual secret key // Get actual secret key
CanonicalizedSecretKeyRing secretKeyRing = CanonicalizedSecretKeyRing secretKeyRing =
mDatabaseInteractor.getCanonicalizedSecretKeyRing(parcel.mMasterKeyId); mKeyRepository.getCanonicalizedSecretKeyRing(parcel.mMasterKeyId);
certificationKey = secretKeyRing.getSecretKey(); certificationKey = secretKeyRing.getSecretKey();
log.add(LogType.MSG_CRT_UNLOCK, 1); log.add(LogType.MSG_CRT_UNLOCK, 1);
@@ -165,7 +165,7 @@ public class CertifyOperation extends BaseReadWriteOperation<CertifyActionsParce
} }
CanonicalizedPublicKeyRing publicRing = CanonicalizedPublicKeyRing publicRing =
mDatabaseInteractor.getCanonicalizedPublicKeyRing(action.mMasterKeyId); mKeyRepository.getCanonicalizedPublicKeyRing(action.mMasterKeyId);
PgpCertifyOperation op = new PgpCertifyOperation(); PgpCertifyOperation op = new PgpCertifyOperation();
PgpCertifyResult result = op.certify(certificationKey, publicRing, PgpCertifyResult result = op.certify(certificationKey, publicRing,
@@ -206,7 +206,7 @@ public class CertifyOperation extends BaseReadWriteOperation<CertifyActionsParce
// these variables are used inside the following loop, but they need to be created only once // these variables are used inside the following loop, but they need to be created only once
UploadOperation uploadOperation = null; UploadOperation uploadOperation = null;
if (parcel.keyServerUri != null) { if (parcel.keyServerUri != null) {
uploadOperation = new UploadOperation(mContext, mDatabaseInteractor, mProgressable, mCancelled); uploadOperation = new UploadOperation(mContext, mKeyRepository, mProgressable, mCancelled);
} }
// Write all certified keys into the database // Write all certified keys into the database
@@ -222,8 +222,8 @@ public class CertifyOperation extends BaseReadWriteOperation<CertifyActionsParce
log.add(LogType.MSG_CRT_SAVE, 2, log.add(LogType.MSG_CRT_SAVE, 2,
KeyFormattingUtils.convertKeyIdToHex(certifiedKey.getMasterKeyId())); KeyFormattingUtils.convertKeyIdToHex(certifiedKey.getMasterKeyId()));
// store the signed key in our local cache // store the signed key in our local cache
mDatabaseInteractor.clearLog(); mKeyRepository.clearLog();
SaveKeyringResult result = mDatabaseReadWriteInteractor.savePublicKeyRing(certifiedKey); SaveKeyringResult result = mKeyWritableRepository.savePublicKeyRing(certifiedKey);
if (uploadOperation != null) { if (uploadOperation != null) {
UploadKeyringParcel uploadInput = UploadKeyringParcel uploadInput =

View File

@@ -29,7 +29,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
@@ -38,7 +38,7 @@ import org.sufficientlysecure.keychain.util.ProgressScaler;
public class ChangeUnlockOperation extends BaseReadWriteOperation<ChangeUnlockParcel> { public class ChangeUnlockOperation extends BaseReadWriteOperation<ChangeUnlockParcel> {
public ChangeUnlockOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable) { public ChangeUnlockOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable) {
super(context, databaseInteractor, progressable); super(context, databaseInteractor, progressable);
} }
@@ -63,7 +63,7 @@ public class ChangeUnlockOperation extends BaseReadWriteOperation<ChangeUnlockPa
KeyFormattingUtils.convertKeyIdToHex(unlockParcel.mMasterKeyId)); KeyFormattingUtils.convertKeyIdToHex(unlockParcel.mMasterKeyId));
CanonicalizedSecretKeyRing secRing = CanonicalizedSecretKeyRing secRing =
mDatabaseInteractor.getCanonicalizedSecretKeyRing(unlockParcel.mMasterKeyId); mKeyRepository.getCanonicalizedSecretKeyRing(unlockParcel.mMasterKeyId);
modifyResult = keyOperations.modifyKeyRingPassphrase(secRing, cryptoInput, unlockParcel); modifyResult = keyOperations.modifyKeyRingPassphrase(secRing, cryptoInput, unlockParcel);
if (modifyResult.isPending()) { if (modifyResult.isPending()) {
@@ -71,7 +71,7 @@ public class ChangeUnlockOperation extends BaseReadWriteOperation<ChangeUnlockPa
log.add(modifyResult, 1); log.add(modifyResult, 1);
return new EditKeyResult(log, modifyResult); return new EditKeyResult(log, modifyResult);
} }
} catch (DatabaseReadWriteInteractor.NotFoundException e) { } catch (KeyWritableRepository.NotFoundException e) {
log.add(OperationResult.LogType.MSG_ED_ERROR_KEY_NOT_FOUND, 2); log.add(OperationResult.LogType.MSG_ED_ERROR_KEY_NOT_FOUND, 2);
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null); return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
} }
@@ -90,7 +90,7 @@ public class ChangeUnlockOperation extends BaseReadWriteOperation<ChangeUnlockPa
// It's a success, so this must be non-null now // It's a success, so this must be non-null now
UncachedKeyRing ring = modifyResult.getRing(); UncachedKeyRing ring = modifyResult.getRing();
SaveKeyringResult saveResult = mDatabaseReadWriteInteractor SaveKeyringResult saveResult = mKeyWritableRepository
.saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 70, 95, 100)); .saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 70, 95, 100));
log.add(saveResult, 1); log.add(saveResult, 1);

View File

@@ -24,13 +24,13 @@ import android.support.annotation.NonNull;
import org.sufficientlysecure.keychain.operations.results.ConsolidateResult; import org.sufficientlysecure.keychain.operations.results.ConsolidateResult;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.service.ConsolidateInputParcel; import org.sufficientlysecure.keychain.service.ConsolidateInputParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
public class ConsolidateOperation extends BaseReadWriteOperation<ConsolidateInputParcel> { public class ConsolidateOperation extends BaseReadWriteOperation<ConsolidateInputParcel> {
public ConsolidateOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable public ConsolidateOperation(Context context, KeyWritableRepository databaseInteractor, Progressable
progressable) { progressable) {
super(context, databaseInteractor, progressable); super(context, databaseInteractor, progressable);
} }
@@ -40,9 +40,9 @@ public class ConsolidateOperation extends BaseReadWriteOperation<ConsolidateInpu
public ConsolidateResult execute(ConsolidateInputParcel consolidateInputParcel, public ConsolidateResult execute(ConsolidateInputParcel consolidateInputParcel,
CryptoInputParcel cryptoInputParcel) { CryptoInputParcel cryptoInputParcel) {
if (consolidateInputParcel.mConsolidateRecovery) { if (consolidateInputParcel.mConsolidateRecovery) {
return mDatabaseReadWriteInteractor.consolidateDatabaseStep2(mProgressable); return mKeyWritableRepository.consolidateDatabaseStep2(mProgressable);
} else { } else {
return mDatabaseReadWriteInteractor.consolidateDatabaseStep1(mProgressable); return mKeyWritableRepository.consolidateDatabaseStep1(mProgressable);
} }
} }
} }

View File

@@ -26,7 +26,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
import org.sufficientlysecure.keychain.service.DeleteKeyringParcel; import org.sufficientlysecure.keychain.service.DeleteKeyringParcel;
@@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
*/ */
public class DeleteOperation extends BaseReadWriteOperation<DeleteKeyringParcel> { public class DeleteOperation extends BaseReadWriteOperation<DeleteKeyringParcel> {
public DeleteOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable) { public DeleteOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable) {
super(context, databaseInteractor, progressable); super(context, databaseInteractor, progressable);
} }
@@ -81,7 +81,7 @@ public class DeleteOperation extends BaseReadWriteOperation<DeleteKeyringParcel>
cancelled = true; cancelled = true;
break; break;
} }
int count = mDatabaseInteractor.getContentResolver().delete( int count = mKeyRepository.getContentResolver().delete(
KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null
); );
if (count > 0) { if (count > 0) {
@@ -95,7 +95,7 @@ public class DeleteOperation extends BaseReadWriteOperation<DeleteKeyringParcel>
if (isSecret && success > 0) { if (isSecret && success > 0) {
log.add(LogType.MSG_DEL_CONSOLIDATE, 1); log.add(LogType.MSG_DEL_CONSOLIDATE, 1);
ConsolidateResult sub = mDatabaseReadWriteInteractor.consolidateDatabaseStep1(mProgressable); ConsolidateResult sub = mKeyWritableRepository.consolidateDatabaseStep1(mProgressable);
log.add(sub, 2); log.add(sub, 2);
} }

View File

@@ -35,8 +35,8 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.service.UploadKeyringParcel; import org.sufficientlysecure.keychain.service.UploadKeyringParcel;
@@ -57,7 +57,7 @@ import org.sufficientlysecure.keychain.util.ProgressScaler;
*/ */
public class EditKeyOperation extends BaseReadWriteOperation<SaveKeyringParcel> { public class EditKeyOperation extends BaseReadWriteOperation<SaveKeyringParcel> {
public EditKeyOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, public EditKeyOperation(Context context, KeyWritableRepository databaseInteractor,
Progressable progressable, AtomicBoolean cancelled) { Progressable progressable, AtomicBoolean cancelled) {
super(context, databaseInteractor, progressable, cancelled); super(context, databaseInteractor, progressable, cancelled);
} }
@@ -94,7 +94,7 @@ public class EditKeyOperation extends BaseReadWriteOperation<SaveKeyringParcel>
log.add(LogType.MSG_ED_FETCHING, 1, log.add(LogType.MSG_ED_FETCHING, 1,
KeyFormattingUtils.convertKeyIdToHex(saveParcel.mMasterKeyId)); KeyFormattingUtils.convertKeyIdToHex(saveParcel.mMasterKeyId));
CanonicalizedSecretKeyRing secRing = CanonicalizedSecretKeyRing secRing =
mDatabaseInteractor.getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId); mKeyRepository.getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId);
modifyResult = keyOperations.modifySecretKeyRing(secRing, cryptoInput, saveParcel); modifyResult = keyOperations.modifySecretKeyRing(secRing, cryptoInput, saveParcel);
if (modifyResult.isPending()) { if (modifyResult.isPending()) {
@@ -147,7 +147,7 @@ public class EditKeyOperation extends BaseReadWriteOperation<SaveKeyringParcel>
new UploadKeyringParcel(saveParcel.getUploadKeyserver(), keyringBytes); new UploadKeyringParcel(saveParcel.getUploadKeyserver(), keyringBytes);
UploadResult uploadResult = UploadResult uploadResult =
new UploadOperation(mContext, mDatabaseInteractor, mProgressable, mCancelled) new UploadOperation(mContext, mKeyRepository, mProgressable, mCancelled)
.execute(exportKeyringParcel, cryptoInput); .execute(exportKeyringParcel, cryptoInput);
log.add(uploadResult, 2); log.add(uploadResult, 2);
@@ -161,7 +161,7 @@ public class EditKeyOperation extends BaseReadWriteOperation<SaveKeyringParcel>
} }
// Save the new keyring. // Save the new keyring.
SaveKeyringResult saveResult = mDatabaseReadWriteInteractor SaveKeyringResult saveResult = mKeyWritableRepository
.saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 60, 95, 100)); .saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 60, 95, 100));
log.add(saveResult, 1); log.add(saveResult, 1);

View File

@@ -39,7 +39,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; 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.ContactSyncAdapterService;
import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
@@ -86,12 +86,12 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
public static final String CACHE_FILE_NAME = "key_import.pcl"; 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) { progressable) {
super(context, databaseInteractor, progressable); super(context, databaseInteractor, progressable);
} }
public ImportOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, public ImportOperation(Context context, KeyWritableRepository databaseInteractor,
Progressable progressable, AtomicBoolean cancelled) { Progressable progressable, AtomicBoolean cancelled) {
super(context, databaseInteractor, progressable, cancelled); super(context, databaseInteractor, progressable, cancelled);
} }
@@ -314,15 +314,15 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
SaveKeyringResult result; SaveKeyringResult result;
// synchronizing prevents https://github.com/open-keychain/open-keychain/issues/1221 // synchronizing prevents https://github.com/open-keychain/open-keychain/issues/1221
// and https://github.com/open-keychain/open-keychain/issues/1480 // and https://github.com/open-keychain/open-keychain/issues/1480
synchronized (mDatabaseInteractor) { synchronized (mKeyRepository) {
mDatabaseInteractor.clearLog(); mKeyRepository.clearLog();
ProgressScaler progressScaler = new ProgressScaler(progressable, (int) (position * progSteps), ProgressScaler progressScaler = new ProgressScaler(progressable, (int) (position * progSteps),
(int) ((position + 1) * progSteps), 100); (int) ((position + 1) * progSteps), 100);
if (key.isSecret()) { if (key.isSecret()) {
result = mDatabaseReadWriteInteractor.saveSecretKeyRing(key, progressScaler, result = mKeyWritableRepository.saveSecretKeyRing(key, progressScaler,
canKeyRings, skipSave); canKeyRings, skipSave);
} else { } else {
result = mDatabaseReadWriteInteractor.savePublicKeyRing(key, progressScaler, result = mKeyWritableRepository.savePublicKeyRing(key, progressScaler,
entry.mExpectedFingerprint, canKeyRings, skipSave); entry.mExpectedFingerprint, canKeyRings, skipSave);
} }
} }
@@ -343,7 +343,7 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
// synonymous to isDownloadFromKeyserver. // synonymous to isDownloadFromKeyserver.
// If no byte data was supplied, import from keyserver took place // If no byte data was supplied, import from keyserver took place
// this prevents file imports being noted as keyserver imports // this prevents file imports being noted as keyserver imports
mDatabaseReadWriteInteractor.renewKeyLastUpdatedTime(key.getMasterKeyId(), mKeyWritableRepository.renewKeyLastUpdatedTime(key.getMasterKeyId(),
GregorianCalendar.getInstance().getTimeInMillis(), GregorianCalendar.getInstance().getTimeInMillis(),
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
} }
@@ -365,8 +365,8 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
if (!skipSave && (secret > 0)) { if (!skipSave && (secret > 0)) {
setPreventCancel(); setPreventCancel();
ConsolidateResult result; ConsolidateResult result;
synchronized (mDatabaseInteractor) { synchronized (mKeyRepository) {
result = mDatabaseReadWriteInteractor.consolidateDatabaseStep1(progressable); result = mKeyWritableRepository.consolidateDatabaseStep1(progressable);
} }
log.add(result, 1); log.add(result, 1);
} }

View File

@@ -50,7 +50,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.Operat
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation;
import org.sufficientlysecure.keychain.pgp.Progressable; 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.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.service.InputDataParcel; import org.sufficientlysecure.keychain.service.InputDataParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
@@ -71,8 +71,8 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
private final byte[] buf = new byte[256]; private final byte[] buf = new byte[256];
public InputDataOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { public InputDataOperation(Context context, KeyRepository keyRepository, Progressable progressable) {
super(context, databaseInteractor, progressable); super(context, keyRepository, progressable);
} }
Uri mSignedDataUri; Uri mSignedDataUri;
@@ -101,7 +101,7 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
log.add(LogType.MSG_DATA_OPENPGP, 1); log.add(LogType.MSG_DATA_OPENPGP, 1);
PgpDecryptVerifyOperation op = PgpDecryptVerifyOperation op =
new PgpDecryptVerifyOperation(mContext, mDatabaseInteractor, mProgressable); new PgpDecryptVerifyOperation(mContext, mKeyRepository, mProgressable);
decryptInput.setInputUri(input.getInputUri()); decryptInput.setInputUri(input.getInputUri());
@@ -269,7 +269,7 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
decryptInput.setDetachedSignature(detachedSig.toByteArray()); decryptInput.setDetachedSignature(detachedSig.toByteArray());
PgpDecryptVerifyOperation op = PgpDecryptVerifyOperation op =
new PgpDecryptVerifyOperation(mContext, mDatabaseInteractor, mProgressable); new PgpDecryptVerifyOperation(mContext, mKeyRepository, mProgressable);
DecryptVerifyResult verifyResult = op.execute(decryptInput, cryptoInput); DecryptVerifyResult verifyResult = op.execute(decryptInput, cryptoInput);
log.addByMerge(verifyResult, 4); log.addByMerge(verifyResult, 4);

View File

@@ -36,7 +36,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation;
import org.sufficientlysecure.keychain.pgp.Progressable; 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.KeybaseVerificationParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
@@ -59,7 +59,7 @@ import de.measite.minidns.record.TXT;
public class KeybaseVerificationOperation extends BaseOperation<KeybaseVerificationParcel> { public class KeybaseVerificationOperation extends BaseOperation<KeybaseVerificationParcel> {
public KeybaseVerificationOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, public KeybaseVerificationOperation(Context context, KeyWritableRepository databaseInteractor,
Progressable progressable) { Progressable progressable) {
super(context, databaseInteractor, progressable); super(context, databaseInteractor, progressable);
} }
@@ -147,7 +147,7 @@ public class KeybaseVerificationOperation extends BaseOperation<KeybaseVerificat
} }
} }
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(mContext, mDatabaseInteractor, mProgressable); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(mContext, mKeyRepository, mProgressable);
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(messageBytes) PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(messageBytes)
.setRequiredSignerFingerprint(requiredFingerprint); .setRequiredSignerFingerprint(requiredFingerprint);

View File

@@ -33,8 +33,8 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKey;
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.service.PromoteKeyringParcel; import org.sufficientlysecure.keychain.service.PromoteKeyringParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
@@ -48,7 +48,7 @@ import org.sufficientlysecure.keychain.util.ProgressScaler;
* *
*/ */
public class PromoteKeyOperation extends BaseReadWriteOperation<PromoteKeyringParcel> { public class PromoteKeyOperation extends BaseReadWriteOperation<PromoteKeyringParcel> {
public PromoteKeyOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, public PromoteKeyOperation(Context context, KeyWritableRepository databaseInteractor,
Progressable progressable, AtomicBoolean cancelled) { Progressable progressable, AtomicBoolean cancelled) {
super(context, databaseInteractor, progressable, cancelled); super(context, databaseInteractor, progressable, cancelled);
} }
@@ -69,7 +69,7 @@ public class PromoteKeyOperation extends BaseReadWriteOperation<PromoteKeyringPa
log.add(LogType.MSG_PR_FETCHING, 1, log.add(LogType.MSG_PR_FETCHING, 1,
KeyFormattingUtils.convertKeyIdToHex(promoteKeyringParcel.mKeyRingId)); KeyFormattingUtils.convertKeyIdToHex(promoteKeyringParcel.mKeyRingId));
CanonicalizedPublicKeyRing pubRing = CanonicalizedPublicKeyRing pubRing =
mDatabaseInteractor.getCanonicalizedPublicKeyRing(promoteKeyringParcel.mKeyRingId); mKeyRepository.getCanonicalizedPublicKeyRing(promoteKeyringParcel.mKeyRingId);
if (promoteKeyringParcel.mSubKeyIds == null) { if (promoteKeyringParcel.mSubKeyIds == null) {
log.add(LogType.MSG_PR_ALL, 1); log.add(LogType.MSG_PR_ALL, 1);
@@ -113,7 +113,7 @@ public class PromoteKeyOperation extends BaseReadWriteOperation<PromoteKeyringPa
setPreventCancel(); setPreventCancel();
// Save the new keyring. // Save the new keyring.
SaveKeyringResult saveResult = mDatabaseReadWriteInteractor SaveKeyringResult saveResult = mKeyWritableRepository
.saveSecretKeyRing(promotedRing, new ProgressScaler(mProgressable, 60, 95, 100)); .saveSecretKeyRing(promotedRing, new ProgressScaler(mProgressable, 60, 95, 100));
log.add(saveResult, 1); log.add(saveResult, 1);

View File

@@ -31,7 +31,7 @@ import org.sufficientlysecure.keychain.operations.results.RevokeResult;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.service.RevokeKeyringParcel; import org.sufficientlysecure.keychain.service.RevokeKeyringParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
@@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.util.Log;
public class RevokeOperation extends BaseReadWriteOperation<RevokeKeyringParcel> { public class RevokeOperation extends BaseReadWriteOperation<RevokeKeyringParcel> {
public RevokeOperation(Context context, DatabaseReadWriteInteractor databaseInteractor, Progressable progressable) { public RevokeOperation(Context context, KeyWritableRepository databaseInteractor, Progressable progressable) {
super(context, databaseInteractor, progressable); super(context, databaseInteractor, progressable);
} }
@@ -62,7 +62,7 @@ public class RevokeOperation extends BaseReadWriteOperation<RevokeKeyringParcel>
try { try {
Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(masterKeyId); 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 // check if this is a master secret key we can work with
switch (keyRing.getSecretKeyType(masterKeyId)) { switch (keyRing.getSecretKeyType(masterKeyId)) {
@@ -81,7 +81,7 @@ public class RevokeOperation extends BaseReadWriteOperation<RevokeKeyringParcel>
saveKeyringParcel.mRevokeSubKeys.add(masterKeyId); saveKeyringParcel.mRevokeSubKeys.add(masterKeyId);
EditKeyResult revokeAndUploadResult = new EditKeyOperation(mContext, EditKeyResult revokeAndUploadResult = new EditKeyOperation(mContext,
mDatabaseReadWriteInteractor, mProgressable, mCancelled).execute(saveKeyringParcel, cryptoInputParcel); mKeyWritableRepository, mProgressable, mCancelled).execute(saveKeyringParcel, cryptoInputParcel);
if (revokeAndUploadResult.isPending()) { if (revokeAndUploadResult.isPending()) {
return revokeAndUploadResult; return revokeAndUploadResult;
@@ -97,7 +97,7 @@ public class RevokeOperation extends BaseReadWriteOperation<RevokeKeyringParcel>
return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId); 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.e(Constants.TAG, "could not find key to revoke", e);
log.add(OperationResult.LogType.MSG_REVOKE_ERROR_KEY_FAIL, 1); log.add(OperationResult.LogType.MSG_REVOKE_ERROR_KEY_FAIL, 1);
return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId); return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId);

View File

@@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; 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.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.RequiredInputType; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.RequiredInputType;
@@ -55,9 +55,9 @@ import org.sufficientlysecure.keychain.util.ProgressScaler;
*/ */
public class SignEncryptOperation extends BaseOperation<SignEncryptParcel> { public class SignEncryptOperation extends BaseOperation<SignEncryptParcel> {
public SignEncryptOperation(Context context, DatabaseInteractor databaseInteractor, public SignEncryptOperation(Context context, KeyRepository keyRepository,
Progressable progressable, AtomicBoolean cancelled) { Progressable progressable, AtomicBoolean cancelled) {
super(context, databaseInteractor, progressable, cancelled); super(context, keyRepository, progressable, cancelled);
} }
@@ -81,7 +81,7 @@ public class SignEncryptOperation extends BaseOperation<SignEncryptParcel> {
if (data.getSignatureMasterKeyId() != Constants.key.none if (data.getSignatureMasterKeyId() != Constants.key.none
&& data.getSignatureSubKeyId() == null) { && data.getSignatureSubKeyId() == null) {
try { try {
long signKeyId = mDatabaseInteractor.getCachedPublicKeyRing( long signKeyId = mKeyRepository.getCachedPublicKeyRing(
data.getSignatureMasterKeyId()).getSecretSignId(); data.getSignatureMasterKeyId()).getSecretSignId();
data.setSignatureSubKeyId(signKeyId); data.setSignatureSubKeyId(signKeyId);
} catch (PgpKeyNotFoundException e) { } catch (PgpKeyNotFoundException e) {
@@ -96,7 +96,7 @@ public class SignEncryptOperation extends BaseOperation<SignEncryptParcel> {
return new SignEncryptResult(SignEncryptResult.RESULT_CANCELLED, log, results); 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); new ProgressScaler(mProgressable, 100 * count / total, 100 * ++count / total, 100), mCancelled);
PgpSignEncryptInputParcel inputParcel = new PgpSignEncryptInputParcel(input.getData()); PgpSignEncryptInputParcel inputParcel = new PgpSignEncryptInputParcel(input.getData());
if (inputBytes != null) { if (inputBytes != null) {

View File

@@ -37,8 +37,8 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.service.UploadKeyringParcel; import org.sufficientlysecure.keychain.service.UploadKeyringParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
@@ -59,9 +59,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
*/ */
public class UploadOperation extends BaseOperation<UploadKeyringParcel> { public class UploadOperation extends BaseOperation<UploadKeyringParcel> {
public UploadOperation(Context context, DatabaseInteractor databaseInteractor, public UploadOperation(Context context, KeyRepository keyRepository,
Progressable progressable, AtomicBoolean cancelled) { Progressable progressable, AtomicBoolean cancelled) {
super(context, databaseInteractor, progressable, cancelled); super(context, keyRepository, progressable, cancelled);
} }
@NonNull @NonNull
@@ -121,7 +121,7 @@ public class UploadOperation extends BaseOperation<UploadKeyringParcel> {
if (hasMasterKeyId) { if (hasMasterKeyId) {
log.add(LogType.MSG_UPLOAD_KEY, 0, KeyFormattingUtils.convertKeyIdToHex(uploadInput.mMasterKeyId)); log.add(LogType.MSG_UPLOAD_KEY, 0, KeyFormattingUtils.convertKeyIdToHex(uploadInput.mMasterKeyId));
return mDatabaseInteractor.getCanonicalizedPublicKeyRing(uploadInput.mMasterKeyId); return mKeyRepository.getCanonicalizedPublicKeyRing(uploadInput.mMasterKeyId);
} }
CanonicalizedKeyRing canonicalizedRing = CanonicalizedKeyRing canonicalizedRing =
@@ -133,7 +133,7 @@ public class UploadOperation extends BaseOperation<UploadKeyringParcel> {
log.add(LogType.MSG_UPLOAD_KEY, 0, KeyFormattingUtils.convertKeyIdToHex(canonicalizedRing.getMasterKeyId())); log.add(LogType.MSG_UPLOAD_KEY, 0, KeyFormattingUtils.convertKeyIdToHex(canonicalizedRing.getMasterKeyId()));
return (CanonicalizedPublicKeyRing) canonicalizedRing; return (CanonicalizedPublicKeyRing) canonicalizedRing;
} catch (DatabaseReadWriteInteractor.NotFoundException e) { } catch (KeyWritableRepository.NotFoundException e) {
log.add(LogType.MSG_UPLOAD_ERROR_NOT_FOUND, 1); log.add(LogType.MSG_UPLOAD_ERROR_NOT_FOUND, 1);
return null; return null;
} catch (IOException | PgpGeneralException e) { } catch (IOException | PgpGeneralException e) {

View File

@@ -47,7 +47,7 @@ import org.bouncycastle.openpgp.operator.jcajce.SessionKeySecretKeyDecryptorBuil
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; 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.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.Passphrase;
@@ -127,7 +127,7 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
* passphrase in the process. * passphrase in the process.
* *
* This method can potentially take a LONG time (i.e. seconds), so it should only * 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. * in the database.
*/ */
public SecretKeyType getSecretKeyTypeSuperExpensive() { public SecretKeyType getSecretKeyTypeSuperExpensive() {

View File

@@ -27,8 +27,8 @@ import org.openintents.openpgp.util.OpenPgpUtils;
import org.openintents.openpgp.util.OpenPgpUtils.UserId; import org.openintents.openpgp.util.OpenPgpUtils.UserId;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
/** /**
@@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.util.Log;
*/ */
public class OpenPgpSignatureResultBuilder { public class OpenPgpSignatureResultBuilder {
// injected // injected
private final DatabaseInteractor mDatabaseInteractor; private final KeyRepository mKeyRepository;
// OpenPgpSignatureResult // OpenPgpSignatureResult
private String mPrimaryUserId; private String mPrimaryUserId;
@@ -57,8 +57,8 @@ public class OpenPgpSignatureResultBuilder {
private String mSenderAddress; private String mSenderAddress;
private Date mSignatureTimestamp; private Date mSignatureTimestamp;
public OpenPgpSignatureResultBuilder(DatabaseInteractor databaseInteractor) { public OpenPgpSignatureResultBuilder(KeyRepository keyRepository) {
this.mDatabaseInteractor = databaseInteractor; this.mKeyRepository = keyRepository;
} }
public void setPrimaryUserId(String userId) { public void setPrimaryUserId(String userId) {
@@ -127,7 +127,7 @@ public class OpenPgpSignatureResultBuilder {
try { try {
ArrayList<String> allUserIds = signingRing.getUnorderedUserIds(); ArrayList<String> allUserIds = signingRing.getUnorderedUserIds();
ArrayList<String> confirmedUserIds = mDatabaseInteractor.getConfirmedUserIds(signingRing.getMasterKeyId()); ArrayList<String> confirmedUserIds = mKeyRepository.getConfirmedUserIds(signingRing.getMasterKeyId());
setUserIds(allUserIds, confirmedUserIds); setUserIds(allUserIds, confirmedUserIds);
if (mSenderAddress != null) { if (mSenderAddress != null) {

View File

@@ -71,8 +71,8 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
@@ -88,8 +88,8 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
public static final int PROGRESS_STRIDE_MILLISECONDS = 200; public static final int PROGRESS_STRIDE_MILLISECONDS = 200;
public PgpDecryptVerifyOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { public PgpDecryptVerifyOperation(Context context, KeyRepository keyRepository, Progressable progressable) {
super(context, databaseInteractor, progressable); super(context, keyRepository, progressable);
} }
/** Decrypts and/or verifies data based on parameters of PgpDecryptVerifyInputParcel. */ /** Decrypts and/or verifies data based on parameters of PgpDecryptVerifyInputParcel. */
@@ -356,7 +356,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
plainFact = fact; plainFact = fact;
} }
PgpSignatureChecker signatureChecker = new PgpSignatureChecker(mDatabaseInteractor, input.getSenderAddress()); PgpSignatureChecker signatureChecker = new PgpSignatureChecker(mKeyRepository, input.getSenderAddress());
if (signatureChecker.initializeOnePassSignature(dataChunk, log, indent +1)) { if (signatureChecker.initializeOnePassSignature(dataChunk, log, indent +1)) {
dataChunk = plainFact.nextObject(); dataChunk = plainFact.nextObject();
} }
@@ -595,7 +595,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
CachedPublicKeyRing cachedPublicKeyRing; CachedPublicKeyRing cachedPublicKeyRing;
try { try {
// get actual keyring object based on master key id // get actual keyring object based on master key id
cachedPublicKeyRing = mDatabaseInteractor.getCachedPublicKeyRing( cachedPublicKeyRing = mKeyRepository.getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId) KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)
); );
long masterKeyId = cachedPublicKeyRing.getMasterKeyId(); long masterKeyId = cachedPublicKeyRing.getMasterKeyId();
@@ -623,7 +623,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
} }
// get actual subkey which has been used for this encryption packet // get actual subkey which has been used for this encryption packet
CanonicalizedSecretKeyRing canonicalizedSecretKeyRing = mDatabaseInteractor CanonicalizedSecretKeyRing canonicalizedSecretKeyRing = mKeyRepository
.getCanonicalizedSecretKeyRing(masterKeyId); .getCanonicalizedSecretKeyRing(masterKeyId);
CanonicalizedSecretKey candidateDecryptionKey = canonicalizedSecretKeyRing.getSecretKey(subKeyId); CanonicalizedSecretKey candidateDecryptionKey = canonicalizedSecretKeyRing.getSecretKey(subKeyId);
@@ -669,7 +669,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
encryptedDataAsymmetric = encData; encryptedDataAsymmetric = encData;
decryptionKey = candidateDecryptionKey; decryptionKey = candidateDecryptionKey;
} catch (PgpKeyNotFoundException | DatabaseReadWriteInteractor.NotFoundException e) { } catch (PgpKeyNotFoundException | KeyWritableRepository.NotFoundException e) {
// continue with the next packet in the while loop // continue with the next packet in the while loop
log.add(LogType.MSG_DC_ASKIP_NO_KEY, indent + 1); log.add(LogType.MSG_DC_ASKIP_NO_KEY, indent + 1);
continue; continue;
@@ -880,7 +880,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
updateProgress(R.string.progress_processing_signature, 60, 100); updateProgress(R.string.progress_processing_signature, 60, 100);
JcaSkipMarkerPGPObjectFactory pgpFact = new JcaSkipMarkerPGPObjectFactory(aIn); JcaSkipMarkerPGPObjectFactory pgpFact = new JcaSkipMarkerPGPObjectFactory(aIn);
PgpSignatureChecker signatureChecker = new PgpSignatureChecker(mDatabaseInteractor, input.getSenderAddress()); PgpSignatureChecker signatureChecker = new PgpSignatureChecker(mKeyRepository, input.getSenderAddress());
Object o = pgpFact.nextObject(); Object o = pgpFact.nextObject();
if (!signatureChecker.initializeSignature(o, log, indent+1)) { if (!signatureChecker.initializeSignature(o, log, indent+1)) {
@@ -935,7 +935,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
o = pgpFact.nextObject(); o = pgpFact.nextObject();
} }
PgpSignatureChecker signatureChecker = new PgpSignatureChecker(mDatabaseInteractor, input.getSenderAddress()); PgpSignatureChecker signatureChecker = new PgpSignatureChecker(mKeyRepository, input.getSenderAddress());
if ( ! signatureChecker.initializeSignature(o, log, indent+1)) { if ( ! signatureChecker.initializeSignature(o, log, indent+1)) {
log.add(LogType.MSG_DC_ERROR_INVALID_DATA, 0); log.add(LogType.MSG_DC_ERROR_INVALID_DATA, 0);

View File

@@ -44,8 +44,8 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.Operat
import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult; import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult;
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult; import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
@@ -99,12 +99,12 @@ public class PgpSignEncryptOperation extends BaseOperation<PgpSignEncryptInputPa
} }
} }
public PgpSignEncryptOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { public PgpSignEncryptOperation(Context context, KeyRepository keyRepository, Progressable progressable, AtomicBoolean cancelled) {
super(context, databaseInteractor, progressable, cancelled); super(context, keyRepository, progressable, cancelled);
} }
public PgpSignEncryptOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { public PgpSignEncryptOperation(Context context, KeyRepository keyRepository, Progressable progressable) {
super(context, databaseInteractor, progressable); super(context, keyRepository, progressable);
} }
@NonNull @NonNull
@@ -224,7 +224,7 @@ public class PgpSignEncryptOperation extends BaseOperation<PgpSignEncryptInputPa
long signingSubKeyId = data.getSignatureSubKeyId(); long signingSubKeyId = data.getSignatureSubKeyId();
CanonicalizedSecretKeyRing signingKeyRing = CanonicalizedSecretKeyRing signingKeyRing =
mDatabaseInteractor.getCanonicalizedSecretKeyRing(signingMasterKeyId); mKeyRepository.getCanonicalizedSecretKeyRing(signingMasterKeyId);
signingKey = signingKeyRing.getSecretKey(data.getSignatureSubKeyId()); signingKey = signingKeyRing.getSecretKey(data.getSignatureSubKeyId());
if (input.getAllowedKeyIds() != null) { if (input.getAllowedKeyIds() != null) {
@@ -249,7 +249,7 @@ public class PgpSignEncryptOperation extends BaseOperation<PgpSignEncryptInputPa
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log); return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);
} }
switch (mDatabaseInteractor.getCachedPublicKeyRing(signingMasterKeyId).getSecretKeyType(signingSubKeyId)) { switch (mKeyRepository.getCachedPublicKeyRing(signingMasterKeyId).getSecretKeyType(signingSubKeyId)) {
case DIVERT_TO_CARD: case DIVERT_TO_CARD:
case PASSPHRASE_EMPTY: { case PASSPHRASE_EMPTY: {
if (!signingKey.unlock(new Passphrase())) { if (!signingKey.unlock(new Passphrase())) {
@@ -293,7 +293,7 @@ public class PgpSignEncryptOperation extends BaseOperation<PgpSignEncryptInputPa
} }
} catch (DatabaseReadWriteInteractor.NotFoundException e) { } catch (KeyWritableRepository.NotFoundException e) {
log.add(LogType.MSG_PSE_ERROR_SIGN_KEY, indent); log.add(LogType.MSG_PSE_ERROR_SIGN_KEY, indent);
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log); return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);
} catch (PgpGeneralException e) { } catch (PgpGeneralException e) {
@@ -338,7 +338,7 @@ public class PgpSignEncryptOperation extends BaseOperation<PgpSignEncryptInputPa
// Asymmetric encryption // Asymmetric encryption
for (long id : data.getEncryptionMasterKeyIds()) { for (long id : data.getEncryptionMasterKeyIds()) {
try { try {
CanonicalizedPublicKeyRing keyRing = mDatabaseInteractor.getCanonicalizedPublicKeyRing( CanonicalizedPublicKeyRing keyRing = mKeyRepository.getCanonicalizedPublicKeyRing(
KeyRings.buildUnifiedKeyRingUri(id)); KeyRings.buildUnifiedKeyRingUri(id));
Set<Long> encryptSubKeyIds = keyRing.getEncryptIds(); Set<Long> encryptSubKeyIds = keyRing.getEncryptIds();
for (Long subKeyId : encryptSubKeyIds) { for (Long subKeyId : encryptSubKeyIds) {
@@ -357,7 +357,7 @@ public class PgpSignEncryptOperation extends BaseOperation<PgpSignEncryptInputPa
log.add(LogType.MSG_PSE_ERROR_REVOKED_OR_EXPIRED, indent); log.add(LogType.MSG_PSE_ERROR_REVOKED_OR_EXPIRED, indent);
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log); return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);
} }
} catch (DatabaseReadWriteInteractor.NotFoundException e) { } catch (KeyWritableRepository.NotFoundException e) {
log.add(LogType.MSG_PSE_KEY_UNKNOWN, indent + 1, log.add(LogType.MSG_PSE_KEY_UNKNOWN, indent + 1,
KeyFormattingUtils.convertKeyIdToHex(id)); KeyFormattingUtils.convertKeyIdToHex(id));
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log); return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);

View File

@@ -36,9 +36,9 @@ import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProv
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@@ -56,12 +56,12 @@ class PgpSignatureChecker {
PGPOnePassSignature onePassSignature; PGPOnePassSignature onePassSignature;
PGPSignature signature; PGPSignature signature;
DatabaseInteractor mDatabaseInteractor; KeyRepository mKeyRepository;
PgpSignatureChecker(DatabaseInteractor databaseInteractor, String senderAddress) { PgpSignatureChecker(KeyRepository keyRepository, String senderAddress) {
mDatabaseInteractor = databaseInteractor; mKeyRepository = keyRepository;
signatureResultBuilder = new OpenPgpSignatureResultBuilder(databaseInteractor); signatureResultBuilder = new OpenPgpSignatureResultBuilder(keyRepository);
signatureResultBuilder.setSenderAddress(senderAddress); signatureResultBuilder.setSenderAddress(senderAddress);
} }
@@ -151,7 +151,7 @@ class PgpSignatureChecker {
for (int i = 0; i < sigList.size(); ++i) { for (int i = 0; i < sigList.size(); ++i) {
try { try {
long sigKeyId = sigList.get(i).getKeyID(); long sigKeyId = sigList.get(i).getKeyID();
CanonicalizedPublicKeyRing signingRing = mDatabaseInteractor.getCanonicalizedPublicKeyRing( CanonicalizedPublicKeyRing signingRing = mKeyRepository.getCanonicalizedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(sigKeyId) KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(sigKeyId)
); );
CanonicalizedPublicKey keyCandidate = signingRing.getPublicKey(sigKeyId); CanonicalizedPublicKey keyCandidate = signingRing.getPublicKey(sigKeyId);
@@ -162,7 +162,7 @@ class PgpSignatureChecker {
signingKey = keyCandidate; signingKey = keyCandidate;
onePassSignature = sigList.get(i); onePassSignature = sigList.get(i);
return; return;
} catch (DatabaseReadWriteInteractor.NotFoundException e) { } catch (KeyWritableRepository.NotFoundException e) {
Log.d(Constants.TAG, "key not found, trying next signature..."); Log.d(Constants.TAG, "key not found, trying next signature...");
} }
} }
@@ -174,7 +174,7 @@ class PgpSignatureChecker {
for (int i = 0; i < sigList.size(); ++i) { for (int i = 0; i < sigList.size(); ++i) {
try { try {
long sigKeyId = sigList.get(i).getKeyID(); long sigKeyId = sigList.get(i).getKeyID();
CanonicalizedPublicKeyRing signingRing = mDatabaseInteractor.getCanonicalizedPublicKeyRing( CanonicalizedPublicKeyRing signingRing = mKeyRepository.getCanonicalizedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(sigKeyId) KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(sigKeyId)
); );
CanonicalizedPublicKey keyCandidate = signingRing.getPublicKey(sigKeyId); CanonicalizedPublicKey keyCandidate = signingRing.getPublicKey(sigKeyId);
@@ -185,7 +185,7 @@ class PgpSignatureChecker {
signingKey = keyCandidate; signingKey = keyCandidate;
signature = sigList.get(i); signature = sigList.get(i);
return; return;
} catch (DatabaseReadWriteInteractor.NotFoundException e) { } catch (KeyWritableRepository.NotFoundException e) {
Log.d(Constants.TAG, "key not found, trying next signature..."); Log.d(Constants.TAG, "key not found, trying next signature...");
} }
} }

View File

@@ -27,7 +27,7 @@ import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
/** This implementation of KeyRing provides a cached view of PublicKeyRing /** This implementation of KeyRing provides a cached view of PublicKeyRing
@@ -48,21 +48,21 @@ import org.sufficientlysecure.keychain.util.Log;
*/ */
public class CachedPublicKeyRing extends KeyRing { public class CachedPublicKeyRing extends KeyRing {
final DatabaseInteractor mDatabaseInteractor; final KeyRepository mKeyRepository;
final Uri mUri; final Uri mUri;
public CachedPublicKeyRing(DatabaseInteractor databaseInteractor, Uri uri) { public CachedPublicKeyRing(KeyRepository keyRepository, Uri uri) {
mDatabaseInteractor = databaseInteractor; mKeyRepository = keyRepository;
mUri = uri; mUri = uri;
} }
@Override @Override
public long getMasterKeyId() throws PgpKeyNotFoundException { public long getMasterKeyId() throws PgpKeyNotFoundException {
try { try {
Object data = mDatabaseInteractor.getGenericData(mUri, Object data = mKeyRepository.getGenericData(mUri,
KeychainContract.KeyRings.MASTER_KEY_ID, DatabaseInteractor.FIELD_TYPE_INTEGER); KeychainContract.KeyRings.MASTER_KEY_ID, KeyRepository.FIELD_TYPE_INTEGER);
return (Long) data; return (Long) data;
} catch (DatabaseReadWriteInteractor.NotFoundException e) { } catch (KeyWritableRepository.NotFoundException e) {
throw new PgpKeyNotFoundException(e); throw new PgpKeyNotFoundException(e);
} }
} }
@@ -85,10 +85,10 @@ public class CachedPublicKeyRing extends KeyRing {
public byte[] getFingerprint() throws PgpKeyNotFoundException { public byte[] getFingerprint() throws PgpKeyNotFoundException {
try { try {
Object data = mDatabaseInteractor.getGenericData(mUri, Object data = mKeyRepository.getGenericData(mUri,
KeychainContract.KeyRings.FINGERPRINT, DatabaseInteractor.FIELD_TYPE_BLOB); KeychainContract.KeyRings.FINGERPRINT, KeyRepository.FIELD_TYPE_BLOB);
return (byte[]) data; return (byte[]) data;
} catch (DatabaseReadWriteInteractor.NotFoundException e) { } catch (KeyWritableRepository.NotFoundException e) {
throw new PgpKeyNotFoundException(e); throw new PgpKeyNotFoundException(e);
} }
} }
@@ -96,11 +96,11 @@ public class CachedPublicKeyRing extends KeyRing {
@Override @Override
public String getPrimaryUserId() throws PgpKeyNotFoundException { public String getPrimaryUserId() throws PgpKeyNotFoundException {
try { try {
Object data = mDatabaseInteractor.getGenericData(mUri, Object data = mKeyRepository.getGenericData(mUri,
KeychainContract.KeyRings.USER_ID, KeychainContract.KeyRings.USER_ID,
DatabaseInteractor.FIELD_TYPE_STRING); KeyRepository.FIELD_TYPE_STRING);
return (String) data; return (String) data;
} catch(DatabaseReadWriteInteractor.NotFoundException e) { } catch(KeyWritableRepository.NotFoundException e) {
throw new PgpKeyNotFoundException(e); throw new PgpKeyNotFoundException(e);
} }
} }
@@ -111,22 +111,22 @@ public class CachedPublicKeyRing extends KeyRing {
public String getName() throws PgpKeyNotFoundException { public String getName() throws PgpKeyNotFoundException {
try { try {
Object data = mDatabaseInteractor.getGenericData(mUri, Object data = mKeyRepository.getGenericData(mUri,
KeyRings.NAME, KeyRings.NAME,
DatabaseInteractor.FIELD_TYPE_STRING); KeyRepository.FIELD_TYPE_STRING);
return (String) data; return (String) data;
} catch(DatabaseReadWriteInteractor.NotFoundException e) { } catch(KeyWritableRepository.NotFoundException e) {
throw new PgpKeyNotFoundException(e); throw new PgpKeyNotFoundException(e);
} }
} }
public String getEmail() throws PgpKeyNotFoundException { public String getEmail() throws PgpKeyNotFoundException {
try { try {
Object data = mDatabaseInteractor.getGenericData(mUri, Object data = mKeyRepository.getGenericData(mUri,
KeyRings.EMAIL, KeyRings.EMAIL,
DatabaseInteractor.FIELD_TYPE_STRING); KeyRepository.FIELD_TYPE_STRING);
return (String) data; return (String) data;
} catch(DatabaseReadWriteInteractor.NotFoundException e) { } catch(KeyWritableRepository.NotFoundException e) {
throw new PgpKeyNotFoundException(e); throw new PgpKeyNotFoundException(e);
} }
} }
@@ -134,11 +134,11 @@ public class CachedPublicKeyRing extends KeyRing {
public String getComment() throws PgpKeyNotFoundException { public String getComment() throws PgpKeyNotFoundException {
try { try {
Object data = mDatabaseInteractor.getGenericData(mUri, Object data = mKeyRepository.getGenericData(mUri,
KeyRings.COMMENT, KeyRings.COMMENT,
DatabaseInteractor.FIELD_TYPE_STRING); KeyRepository.FIELD_TYPE_STRING);
return (String) data; return (String) data;
} catch(DatabaseReadWriteInteractor.NotFoundException e) { } catch(KeyWritableRepository.NotFoundException e) {
throw new PgpKeyNotFoundException(e); throw new PgpKeyNotFoundException(e);
} }
} }
@@ -146,11 +146,11 @@ public class CachedPublicKeyRing extends KeyRing {
@Override @Override
public boolean isRevoked() throws PgpKeyNotFoundException { public boolean isRevoked() throws PgpKeyNotFoundException {
try { try {
Object data = mDatabaseInteractor.getGenericData(mUri, Object data = mKeyRepository.getGenericData(mUri,
KeychainContract.KeyRings.IS_REVOKED, KeychainContract.KeyRings.IS_REVOKED,
DatabaseInteractor.FIELD_TYPE_INTEGER); KeyRepository.FIELD_TYPE_INTEGER);
return (Long) data > 0; return (Long) data > 0;
} catch(DatabaseReadWriteInteractor.NotFoundException e) { } catch(KeyWritableRepository.NotFoundException e) {
throw new PgpKeyNotFoundException(e); throw new PgpKeyNotFoundException(e);
} }
} }
@@ -158,11 +158,11 @@ public class CachedPublicKeyRing extends KeyRing {
@Override @Override
public boolean canCertify() throws PgpKeyNotFoundException { public boolean canCertify() throws PgpKeyNotFoundException {
try { try {
Object data = mDatabaseInteractor.getGenericData(mUri, Object data = mKeyRepository.getGenericData(mUri,
KeychainContract.KeyRings.HAS_CERTIFY, KeychainContract.KeyRings.HAS_CERTIFY,
DatabaseInteractor.FIELD_TYPE_NULL); KeyRepository.FIELD_TYPE_NULL);
return !((Boolean) data); return !((Boolean) data);
} catch(DatabaseReadWriteInteractor.NotFoundException e) { } catch(KeyWritableRepository.NotFoundException e) {
throw new PgpKeyNotFoundException(e); throw new PgpKeyNotFoundException(e);
} }
} }
@@ -170,11 +170,11 @@ public class CachedPublicKeyRing extends KeyRing {
@Override @Override
public long getEncryptId() throws PgpKeyNotFoundException { public long getEncryptId() throws PgpKeyNotFoundException {
try { try {
Object data = mDatabaseInteractor.getGenericData(mUri, Object data = mKeyRepository.getGenericData(mUri,
KeyRings.HAS_ENCRYPT, KeyRings.HAS_ENCRYPT,
DatabaseInteractor.FIELD_TYPE_INTEGER); KeyRepository.FIELD_TYPE_INTEGER);
return (Long) data; return (Long) data;
} catch(DatabaseReadWriteInteractor.NotFoundException e) { } catch(KeyWritableRepository.NotFoundException e) {
throw new PgpKeyNotFoundException(e); throw new PgpKeyNotFoundException(e);
} }
} }
@@ -192,11 +192,11 @@ public class CachedPublicKeyRing extends KeyRing {
*/ */
public long getSecretSignId() throws PgpKeyNotFoundException { public long getSecretSignId() throws PgpKeyNotFoundException {
try { try {
Object data = mDatabaseInteractor.getGenericData(mUri, Object data = mKeyRepository.getGenericData(mUri,
KeyRings.HAS_SIGN, KeyRings.HAS_SIGN,
DatabaseInteractor.FIELD_TYPE_INTEGER); KeyRepository.FIELD_TYPE_INTEGER);
return (Long) data; return (Long) data;
} catch(DatabaseReadWriteInteractor.NotFoundException e) { } catch(KeyWritableRepository.NotFoundException e) {
throw new PgpKeyNotFoundException(e); throw new PgpKeyNotFoundException(e);
} }
} }
@@ -204,43 +204,43 @@ public class CachedPublicKeyRing extends KeyRing {
@Override @Override
public int getVerified() throws PgpKeyNotFoundException { public int getVerified() throws PgpKeyNotFoundException {
try { try {
Object data = mDatabaseInteractor.getGenericData(mUri, Object data = mKeyRepository.getGenericData(mUri,
KeychainContract.KeyRings.VERIFIED, KeychainContract.KeyRings.VERIFIED,
DatabaseInteractor.FIELD_TYPE_INTEGER); KeyRepository.FIELD_TYPE_INTEGER);
return ((Long) data).intValue(); return ((Long) data).intValue();
} catch(DatabaseReadWriteInteractor.NotFoundException e) { } catch(KeyWritableRepository.NotFoundException e) {
throw new PgpKeyNotFoundException(e); throw new PgpKeyNotFoundException(e);
} }
} }
public boolean hasAnySecret() throws PgpKeyNotFoundException { public boolean hasAnySecret() throws PgpKeyNotFoundException {
try { try {
Object data = mDatabaseInteractor.getGenericData(mUri, Object data = mKeyRepository.getGenericData(mUri,
KeychainContract.KeyRings.HAS_ANY_SECRET, KeychainContract.KeyRings.HAS_ANY_SECRET,
DatabaseInteractor.FIELD_TYPE_INTEGER); KeyRepository.FIELD_TYPE_INTEGER);
return (Long) data > 0; return (Long) data > 0;
} catch(DatabaseReadWriteInteractor.NotFoundException e) { } catch(KeyWritableRepository.NotFoundException e) {
throw new PgpKeyNotFoundException(e); throw new PgpKeyNotFoundException(e);
} }
} }
private Cursor getSubkeys() throws PgpKeyNotFoundException { private Cursor getSubkeys() throws PgpKeyNotFoundException {
Uri keysUri = KeychainContract.Keys.buildKeysUri(extractOrGetMasterKeyId()); 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 { public SecretKeyType getSecretKeyType(long keyId) throws NotFoundException {
Object data = mDatabaseInteractor.getGenericData(Keys.buildKeysUri(mUri), Object data = mKeyRepository.getGenericData(Keys.buildKeysUri(mUri),
KeyRings.HAS_SECRET, KeyRings.HAS_SECRET,
DatabaseInteractor.FIELD_TYPE_INTEGER, KeyRepository.FIELD_TYPE_INTEGER,
KeyRings.KEY_ID + " = " + Long.toString(keyId)); KeyRings.KEY_ID + " = " + Long.toString(keyId));
return SecretKeyType.fromNum(((Long) data).intValue()); return SecretKeyType.fromNum(((Long) data).intValue());
} }
public byte[] getEncoded() throws PgpKeyNotFoundException { public byte[] getEncoded() throws PgpKeyNotFoundException {
try { try {
return mDatabaseInteractor.loadPublicKeyRingData(getMasterKeyId()); return mKeyRepository.loadPublicKeyRingData(getMasterKeyId());
} catch(DatabaseReadWriteInteractor.NotFoundException e) { } catch(KeyWritableRepository.NotFoundException e) {
throw new PgpKeyNotFoundException(e); throw new PgpKeyNotFoundException(e);
} }
} }

View File

@@ -26,7 +26,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; 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! // If we ever switch to api level 11, we can ditch this whole mess!
public static final int FIELD_TYPE_NULL = 1; public static final int FIELD_TYPE_NULL = 1;
// this is called integer to stay coherent with the constants in Cursor (api level 11) // this is called integer to stay coherent with the constants in Cursor (api level 11)
@@ -40,18 +40,18 @@ public class DatabaseInteractor {
OperationLog mLog; OperationLog mLog;
int mIndent; int mIndent;
public static DatabaseInteractor createDatabaseInteractor(Context context) { public static KeyRepository createDatabaseInteractor(Context context) {
ContentResolver contentResolver = context.getContentResolver(); ContentResolver contentResolver = context.getContentResolver();
LocalPublicKeyStorage localPublicKeyStorage = LocalPublicKeyStorage.getInstance(context); 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); this(contentResolver, localPublicKeyStorage, new OperationLog(), 0);
} }
DatabaseInteractor(ContentResolver contentResolver, LocalPublicKeyStorage localPublicKeyStorage, KeyRepository(ContentResolver contentResolver, LocalPublicKeyStorage localPublicKeyStorage,
OperationLog log, int indent) { OperationLog log, int indent) {
mContentResolver = contentResolver; mContentResolver = contentResolver;
mLocalPublicKeyStorage = localPublicKeyStorage; mLocalPublicKeyStorage = localPublicKeyStorage;

View File

@@ -87,26 +87,26 @@ import org.sufficientlysecure.keychain.util.Utf8Util;
* the lifetime of the executing ProviderHelper object unless the resetLog() * the lifetime of the executing ProviderHelper object unless the resetLog()
* method is called to start a new one specifically. * 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 static final int MAX_CACHED_KEY_SIZE = 1024 * 50;
private final Context mContext; private final Context mContext;
public static DatabaseReadWriteInteractor createDatabaseReadWriteInteractor(Context context) { public static KeyWritableRepository createDatabaseReadWriteInteractor(Context context) {
LocalPublicKeyStorage localPublicKeyStorage = LocalPublicKeyStorage.getInstance(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); 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); 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); super(context.getContentResolver(), localPublicKeyStorage, log, indent);
mContext = context; mContext = context;
@@ -1174,7 +1174,7 @@ public class DatabaseReadWriteInteractor extends DatabaseInteractor {
private ConsolidateResult consolidateDatabaseStep2( private ConsolidateResult consolidateDatabaseStep2(
OperationLog log, int indent, Progressable progress, boolean recovery) { OperationLog log, int indent, Progressable progress, boolean recovery) {
synchronized (DatabaseReadWriteInteractor.class) { synchronized (KeyWritableRepository.class) {
if (mConsolidateCritical) { if (mConsolidateCritical) {
log.add(LogType.MSG_CON_ERROR_CONCURRENT, indent); log.add(LogType.MSG_CON_ERROR_CONCURRENT, indent);
return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log);

View File

@@ -63,7 +63,7 @@ import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; 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;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAccounts; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAccounts;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; 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)); Collections.unmodifiableList(Arrays.asList(3, 4, 5, 6, 7, 8, 9, 10, 11));
private ApiPermissionHelper mApiPermissionHelper; private ApiPermissionHelper mApiPermissionHelper;
private DatabaseInteractor mDatabaseInteractor; private KeyRepository mKeyRepository;
private ApiDataAccessObject mApiDao; private ApiDataAccessObject mApiDao;
private OpenPgpServiceKeyIdExtractor mKeyIdExtractor; private OpenPgpServiceKeyIdExtractor mKeyIdExtractor;
private ApiPendingIntentFactory mApiPendingIntentFactory; private ApiPendingIntentFactory mApiPendingIntentFactory;
@@ -97,7 +97,7 @@ public class OpenPgpService extends Service {
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
mApiPermissionHelper = new ApiPermissionHelper(this, new ApiDataAccessObject(this)); mApiPermissionHelper = new ApiPermissionHelper(this, new ApiDataAccessObject(this));
mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(this); mKeyRepository = KeyRepository.createDatabaseInteractor(this);
mApiDao = new ApiDataAccessObject(this); mApiDao = new ApiDataAccessObject(this);
mApiPendingIntentFactory = new ApiPendingIntentFactory(getBaseContext()); mApiPendingIntentFactory = new ApiPendingIntentFactory(getBaseContext());
@@ -135,7 +135,7 @@ public class OpenPgpService extends Service {
// get first usable subkey capable of signing // get first usable subkey capable of signing
try { try {
long signSubKeyId = mDatabaseInteractor.getCachedPublicKeyRing( long signSubKeyId = mKeyRepository.getCachedPublicKeyRing(
pgpData.getSignatureMasterKeyId()).getSecretSignId(); pgpData.getSignatureMasterKeyId()).getSecretSignId();
pgpData.setSignatureSubKeyId(signSubKeyId); pgpData.setSignatureSubKeyId(signSubKeyId);
} catch (PgpKeyNotFoundException e) { } catch (PgpKeyNotFoundException e) {
@@ -167,7 +167,7 @@ public class OpenPgpService extends Service {
} }
// execute PGP operation! // 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); PgpSignEncryptResult pgpResult = pse.execute(pseInput, inputParcel, inputData, outputStream);
if (pgpResult.isPending()) { if (pgpResult.isPending()) {
@@ -254,7 +254,7 @@ public class OpenPgpService extends Service {
// get first usable subkey capable of signing // get first usable subkey capable of signing
try { try {
long signSubKeyId = mDatabaseInteractor.getCachedPublicKeyRing( long signSubKeyId = mKeyRepository.getCachedPublicKeyRing(
pgpData.getSignatureMasterKeyId()).getSecretSignId(); pgpData.getSignatureMasterKeyId()).getSecretSignId();
pgpData.setSignatureSubKeyId(signSubKeyId); pgpData.setSignatureSubKeyId(signSubKeyId);
} catch (PgpKeyNotFoundException e) { } catch (PgpKeyNotFoundException e) {
@@ -294,7 +294,7 @@ public class OpenPgpService extends Service {
new Passphrase(data.getCharArrayExtra(OpenPgpApi.EXTRA_PASSPHRASE)); new Passphrase(data.getCharArrayExtra(OpenPgpApi.EXTRA_PASSPHRASE));
} }
PgpSignEncryptOperation op = new PgpSignEncryptOperation(this, mDatabaseInteractor, null); PgpSignEncryptOperation op = new PgpSignEncryptOperation(this, mKeyRepository, null);
// execute PGP operation! // execute PGP operation!
PgpSignEncryptResult pgpResult = op.execute(pseInput, inputParcel, inputData, outputStream); 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); byte[] detachedSignature = data.getByteArrayExtra(OpenPgpApi.EXTRA_DETACHED_SIGNATURE);
String senderAddress = data.getStringExtra(OpenPgpApi.EXTRA_SENDER_ADDRESS); 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); long inputLength = data.getLongExtra(OpenPgpApi.EXTRA_DATA_LENGTH, InputData.UNKNOWN_FILESIZE);
InputData inputData = new InputData(inputStream, inputLength); InputData inputData = new InputData(inputStream, inputLength);
@@ -526,7 +526,7 @@ public class OpenPgpService extends Service {
try { try {
// try to find key, throws NotFoundException if not in db! // try to find key, throws NotFoundException if not in db!
CanonicalizedPublicKeyRing keyRing = CanonicalizedPublicKeyRing keyRing =
mDatabaseInteractor.getCanonicalizedPublicKeyRing( mKeyRepository.getCanonicalizedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(masterKeyId)); KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(masterKeyId));
Intent result = new Intent(); Intent result = new Intent();
@@ -555,7 +555,7 @@ public class OpenPgpService extends Service {
mApiPendingIntentFactory.createShowKeyPendingIntent(data, masterKeyId)); mApiPendingIntentFactory.createShowKeyPendingIntent(data, masterKeyId));
return result; return result;
} catch (DatabaseInteractor.NotFoundException e) { } catch (KeyRepository.NotFoundException e) {
// If keys are not in db we return an additional PendingIntent // If keys are not in db we return an additional PendingIntent
// to retrieve the missing key // to retrieve the missing key
Intent result = new Intent(); Intent result = new Intent();
@@ -630,7 +630,7 @@ public class OpenPgpService extends Service {
// the backup code is cached in CryptoInputParcelCacheService, now we can proceed // the backup code is cached in CryptoInputParcelCacheService, now we can proceed
BackupKeyringParcel input = new BackupKeyringParcel(masterKeyIds, backupSecret, true, enableAsciiArmorOutput, null); 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); ExportResult pgpResult = op.execute(input, inputParcel, outputStream);
if (pgpResult.success()) { if (pgpResult.success()) {

View File

@@ -15,8 +15,8 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; import org.sufficientlysecure.keychain.provider.ApiDataAccessObject;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.remote.ApiPermissionHelper; import org.sufficientlysecure.keychain.remote.ApiPermissionHelper;
import org.sufficientlysecure.keychain.remote.ApiPermissionHelper.WrongPackageCertificateException; import org.sufficientlysecure.keychain.remote.ApiPermissionHelper.WrongPackageCertificateException;
@@ -33,27 +33,27 @@ class RequestKeyPermissionPresenter {
private String packageName; private String packageName;
private long masterKeyId; private long masterKeyId;
private DatabaseInteractor databaseInteractor; private KeyRepository keyRepository;
static RequestKeyPermissionPresenter createRequestKeyPermissionPresenter(Context context) { static RequestKeyPermissionPresenter createRequestKeyPermissionPresenter(Context context) {
PackageManager packageManager = context.getPackageManager(); PackageManager packageManager = context.getPackageManager();
ApiDataAccessObject apiDataAccessObject = new ApiDataAccessObject(context); ApiDataAccessObject apiDataAccessObject = new ApiDataAccessObject(context);
ApiPermissionHelper apiPermissionHelper = new ApiPermissionHelper(context, apiDataAccessObject); ApiPermissionHelper apiPermissionHelper = new ApiPermissionHelper(context, apiDataAccessObject);
DatabaseInteractor databaseInteractor = KeyRepository keyRepository =
DatabaseInteractor.createDatabaseInteractor(context); KeyRepository.createDatabaseInteractor(context);
return new RequestKeyPermissionPresenter(context, apiDataAccessObject, apiPermissionHelper, packageManager, return new RequestKeyPermissionPresenter(context, apiDataAccessObject, apiPermissionHelper, packageManager,
databaseInteractor); keyRepository);
} }
private RequestKeyPermissionPresenter(Context context, ApiDataAccessObject apiDataAccessObject, private RequestKeyPermissionPresenter(Context context, ApiDataAccessObject apiDataAccessObject,
ApiPermissionHelper apiPermissionHelper, PackageManager packageManager, DatabaseInteractor databaseInteractor) { ApiPermissionHelper apiPermissionHelper, PackageManager packageManager, KeyRepository keyRepository) {
this.context = context; this.context = context;
this.apiDataAccessObject = apiDataAccessObject; this.apiDataAccessObject = apiDataAccessObject;
this.apiPermissionHelper = apiPermissionHelper; this.apiPermissionHelper = apiPermissionHelper;
this.packageManager = packageManager; this.packageManager = packageManager;
this.databaseInteractor = databaseInteractor; this.keyRepository = keyRepository;
} }
void setView(RequestKeyPermissionMvpView view) { void setView(RequestKeyPermissionMvpView view) {
@@ -102,7 +102,7 @@ class RequestKeyPermissionPresenter {
CachedPublicKeyRing publicFallbackRing = null; CachedPublicKeyRing publicFallbackRing = null;
for (long candidateSubKeyId : subKeyIds) { for (long candidateSubKeyId : subKeyIds) {
try { try {
CachedPublicKeyRing cachedPublicKeyRing = databaseInteractor.getCachedPublicKeyRing( CachedPublicKeyRing cachedPublicKeyRing = keyRepository.getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(candidateSubKeyId) KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(candidateSubKeyId)
); );

View File

@@ -48,7 +48,7 @@ import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; 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.ServiceProgressHandler.MessageStatus;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@@ -111,8 +111,8 @@ public class KeychainService extends Service implements Progressable {
// just for brevity // just for brevity
KeychainService outerThis = KeychainService.this; KeychainService outerThis = KeychainService.this;
DatabaseReadWriteInteractor databaseInteractor = KeyWritableRepository databaseInteractor =
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(outerThis); KeyWritableRepository.createDatabaseReadWriteInteractor(outerThis);
if (inputParcel instanceof SignEncryptParcel) { if (inputParcel instanceof SignEncryptParcel) {
op = new SignEncryptOperation(outerThis, databaseInteractor, outerThis, mActionCanceled); op = new SignEncryptOperation(outerThis, databaseInteractor, outerThis, mActionCanceled);
} else if (inputParcel instanceof PgpDecryptVerifyInputParcel) { } else if (inputParcel instanceof PgpDecryptVerifyInputParcel) {

View File

@@ -44,7 +44,7 @@ import org.sufficientlysecure.keychain.network.orbot.OrbotHelper;
import org.sufficientlysecure.keychain.operations.ImportOperation; import org.sufficientlysecure.keychain.operations.ImportOperation;
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult; 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.provider.KeychainContract;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity; import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity;
@@ -322,7 +322,7 @@ public class KeyserverSyncAdapterService extends Service {
CryptoInputParcel cryptoInputParcel) { CryptoInputParcel cryptoInputParcel) {
Log.d(Constants.TAG, "Starting normal update"); Log.d(Constants.TAG, "Starting normal update");
ImportOperation importOp = new ImportOperation(context, ImportOperation importOp = new ImportOperation(context,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context), null); KeyWritableRepository.createDatabaseReadWriteInteractor(context), null);
return importOp.execute( return importOp.execute(
new ImportKeyringParcel(keyList, new ImportKeyringParcel(keyList,
Preferences.getPreferences(context).getPreferredKeyserver()), Preferences.getPreferences(context).getPreferredKeyserver()),
@@ -382,7 +382,7 @@ public class KeyserverSyncAdapterService extends Service {
new OperationResult.OperationLog()); new OperationResult.OperationLog());
} }
ImportKeyResult result = ImportKeyResult result =
new ImportOperation(context, DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context), null, mCancelled) new ImportOperation(context, KeyWritableRepository.createDatabaseReadWriteInteractor(context), null, mCancelled)
.execute( .execute(
new ImportKeyringParcel( new ImportKeyringParcel(
keyWrapper, keyWrapper,

View File

@@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; 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.Log;
import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.Passphrase;
import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.Preferences;
@@ -224,7 +224,7 @@ public class PassphraseCacheService extends Service {
/** /**
* Internal implementation to get cached passphrase. * 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 // on "none" key, just do nothing
if (masterKeyId == Constants.key.none) { if (masterKeyId == Constants.key.none) {
return null; return null;
@@ -245,16 +245,16 @@ public class PassphraseCacheService extends Service {
+ masterKeyId + ", subKeyId " + subKeyId); + masterKeyId + ", subKeyId " + subKeyId);
// get the type of key (from the database) // 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); SecretKeyType keyType = keyRing.getSecretKeyType(subKeyId);
switch (keyType) { switch (keyType) {
case PASSPHRASE_EMPTY: case PASSPHRASE_EMPTY:
return new Passphrase(""); return new Passphrase("");
case UNAVAILABLE: 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: 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 // get cached passphrase
@@ -398,7 +398,7 @@ public class PassphraseCacheService extends Service {
bundle.putParcelable(EXTRA_PASSPHRASE, passphrase); bundle.putParcelable(EXTRA_PASSPHRASE, passphrase);
msg.setData(bundle); msg.setData(bundle);
} }
} catch (DatabaseInteractor.NotFoundException e) { } catch (KeyRepository.NotFoundException e) {
Log.e(Constants.TAG, "PassphraseCacheService: Passphrase for unknown key was requested!"); Log.e(Constants.TAG, "PassphraseCacheService: Passphrase for unknown key was requested!");
msg.what = MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND; msg.what = MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND;
} }

View File

@@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.experimental.SentenceConfirm; import org.sufficientlysecure.keychain.experimental.SentenceConfirm;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; 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.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.ui.base.LoaderFragment; import org.sufficientlysecure.keychain.ui.base.LoaderFragment;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
@@ -214,7 +214,7 @@ public class CertifyFingerprintFragment extends LoaderFragment implements
private void certify(Uri dataUri) { private void certify(Uri dataUri) {
long keyId = 0; long keyId = 0;
try { try {
keyId = DatabaseInteractor.createDatabaseInteractor(getContext()) keyId = KeyRepository.createDatabaseInteractor(getContext())
.getCachedPublicKeyRing(dataUri) .getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId(); .extractOrGetMasterKeyId();
} catch (PgpKeyNotFoundException e) { } catch (PgpKeyNotFoundException e) {

View File

@@ -39,7 +39,7 @@ import org.sufficientlysecure.keychain.operations.results.CertifyResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; 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;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
@@ -69,7 +69,7 @@ public class CertifyKeyFragment
.getLongExtra(CertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, Constants.key.none); .getLongExtra(CertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, Constants.key.none);
if (certifyKeyId != Constants.key.none) { if (certifyKeyId != Constants.key.none) {
try { try {
CachedPublicKeyRing key = (DatabaseInteractor CachedPublicKeyRing key = (KeyRepository
.createDatabaseInteractor(getContext())) .createDatabaseInteractor(getContext()))
.getCachedPublicKeyRing(certifyKeyId); .getCachedPublicKeyRing(certifyKeyId);
if (key.canCertify()) { if (key.canCertify()) {

View File

@@ -33,7 +33,7 @@ import android.support.v4.app.TaskStackBuilder;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; 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.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.securitytoken.KeyFormat; import org.sufficientlysecure.keychain.securitytoken.KeyFormat;
import org.sufficientlysecure.keychain.ui.base.BaseSecurityTokenActivity; import org.sufficientlysecure.keychain.ui.base.BaseSecurityTokenActivity;
@@ -181,7 +181,7 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity {
if (containsKeys(mScannedFingerprints)) { if (containsKeys(mScannedFingerprints)) {
try { try {
long masterKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mScannedFingerprints); long masterKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mScannedFingerprints);
CachedPublicKeyRing ring = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId); CachedPublicKeyRing ring = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId);
ring.getMasterKeyId(); ring.getMasterKeyId();
Intent intent = new Intent(this, ViewKeyActivity.class); Intent intent = new Intent(this, ViewKeyActivity.class);

View File

@@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.operations.results.UploadResult;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; 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;
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
@@ -411,7 +411,7 @@ public class CreateKeyFinalFragment extends Fragment {
CreateKeyActivity activity = (CreateKeyActivity) getActivity(); CreateKeyActivity activity = (CreateKeyActivity) getActivity();
final SaveKeyringParcel changeKeyringParcel; final SaveKeyringParcel changeKeyringParcel;
CachedPublicKeyRing key = (DatabaseInteractor.createDatabaseInteractor(getContext())) CachedPublicKeyRing key = (KeyRepository.createDatabaseInteractor(getContext()))
.getCachedPublicKeyRing(saveKeyResult.mMasterKeyId); .getCachedPublicKeyRing(saveKeyResult.mMasterKeyId);
try { try {
changeKeyringParcel = new SaveKeyringParcel(key.getMasterKeyId(), key.getFingerprint()); changeKeyringParcel = new SaveKeyringParcel(key.getMasterKeyId(), key.getFingerprint());

View File

@@ -49,7 +49,7 @@ import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; 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;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
@@ -193,7 +193,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager.
try { try {
Intent viewKeyIntent = new Intent(getActivity(), ViewKeyActivity.class); Intent viewKeyIntent = new Intent(getActivity(), ViewKeyActivity.class);
long masterKeyId = DatabaseInteractor.createDatabaseInteractor(getContext()).getCachedPublicKeyRing( long masterKeyId = KeyRepository.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId) KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId)
).getMasterKeyId(); ).getMasterKeyId();
viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId)); viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId));

View File

@@ -42,7 +42,7 @@ import org.sufficientlysecure.keychain.operations.results.DeleteResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.operations.results.RevokeResult; import org.sufficientlysecure.keychain.operations.results.RevokeResult;
import org.sufficientlysecure.keychain.provider.KeychainContract; 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.DeleteKeyringParcel;
import org.sufficientlysecure.keychain.service.RevokeKeyringParcel; import org.sufficientlysecure.keychain.service.RevokeKeyringParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
@@ -89,13 +89,13 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
if (mMasterKeyIds.length == 1 && mHasSecret) { if (mMasterKeyIds.length == 1 && mHasSecret) {
// if mMasterKeyIds.length == 0 we let the DeleteOperation respond // if mMasterKeyIds.length == 0 we let the DeleteOperation respond
try { try {
HashMap<String, Object> data = DatabaseInteractor.createDatabaseInteractor(this).getUnifiedData( HashMap<String, Object> data = KeyRepository.createDatabaseInteractor(this).getUnifiedData(
mMasterKeyIds[0], new String[]{ mMasterKeyIds[0], new String[]{
KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.NAME,
KeychainContract.KeyRings.IS_REVOKED KeychainContract.KeyRings.IS_REVOKED
}, new int[]{ }, new int[]{
DatabaseInteractor.FIELD_TYPE_STRING, KeyRepository.FIELD_TYPE_STRING,
DatabaseInteractor.FIELD_TYPE_INTEGER KeyRepository.FIELD_TYPE_INTEGER
} }
); );
@@ -112,7 +112,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
} else { } else {
showRevokeDeleteDialog(name); showRevokeDeleteDialog(name);
} }
} catch (DatabaseInteractor.NotFoundException e) { } catch (KeyRepository.NotFoundException e) {
Log.e(Constants.TAG, Log.e(Constants.TAG,
"Secret key to delete not found at DeleteKeyDialogActivity for " "Secret key to delete not found at DeleteKeyDialogActivity for "
+ mMasterKeyIds[0], e); + mMasterKeyIds[0], e);
@@ -269,14 +269,14 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
long masterKeyId = masterKeyIds[0]; long masterKeyId = masterKeyIds[0];
try { try {
HashMap<String, Object> data = DatabaseInteractor.createDatabaseInteractor(getContext()) HashMap<String, Object> data = KeyRepository.createDatabaseInteractor(getContext())
.getUnifiedData( .getUnifiedData(
masterKeyId, new String[]{ masterKeyId, new String[]{
KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.NAME,
KeychainContract.KeyRings.HAS_ANY_SECRET KeychainContract.KeyRings.HAS_ANY_SECRET
}, new int[]{ }, new int[]{
DatabaseInteractor.FIELD_TYPE_STRING, KeyRepository.FIELD_TYPE_STRING,
DatabaseInteractor.FIELD_TYPE_INTEGER KeyRepository.FIELD_TYPE_INTEGER
} }
); );
String name; String name;
@@ -294,7 +294,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
} else { } else {
mMainMessage.setText(getString(R.string.public_key_deletetion_confirmation, name)); mMainMessage.setText(getString(R.string.public_key_deletetion_confirmation, name));
} }
} catch (DatabaseInteractor.NotFoundException e) { } catch (KeyRepository.NotFoundException e) {
dismiss(); dismiss();
return null; return null;
} }

View File

@@ -50,8 +50,8 @@ import org.sufficientlysecure.keychain.operations.results.UploadResult;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
@@ -170,7 +170,7 @@ public class EditIdentitiesFragment extends Fragment
try { try {
Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri); Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri);
CachedPublicKeyRing keyRing = CachedPublicKeyRing keyRing =
DatabaseInteractor.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(secretUri); KeyRepository.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(secretUri);
long masterKeyId = keyRing.getMasterKeyId(); long masterKeyId = keyRing.getMasterKeyId();
// check if this is a master secret key we can work with // check if this is a master secret key we can work with

View File

@@ -48,10 +48,10 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; 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;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; 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.ChangeUnlockParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange;
@@ -203,7 +203,7 @@ public class EditKeyFragment extends QueueingCryptoOperationFragment<SaveKeyring
try { try {
Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri); Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri);
CachedPublicKeyRing keyRing = CachedPublicKeyRing keyRing =
DatabaseInteractor.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(secretUri); KeyRepository.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(secretUri);
long masterKeyId = keyRing.getMasterKeyId(); long masterKeyId = keyRing.getMasterKeyId();
// check if this is a master secret key we can work with // check if this is a master secret key we can work with

View File

@@ -34,8 +34,8 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter.KeyItem; import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter.KeyItem;
import org.sufficientlysecure.keychain.ui.widget.EncryptKeyCompletionView; import org.sufficientlysecure.keychain.ui.widget.EncryptKeyCompletionView;
@@ -46,7 +46,7 @@ import org.sufficientlysecure.keychain.util.Passphrase;
public class EncryptModeAsymmetricFragment extends EncryptModeFragment { public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
DatabaseInteractor mDatabaseInteractor; KeyRepository mKeyRepository;
private KeySpinner mSignKeySpinner; private KeySpinner mSignKeySpinner;
private EncryptKeyCompletionView mEncryptKeyView; private EncryptKeyCompletionView mEncryptKeyView;
@@ -115,7 +115,7 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(getContext()); mKeyRepository = KeyRepository.createDatabaseInteractor(getContext());
// preselect keys given, from state or arguments // preselect keys given, from state or arguments
if (savedInstanceState == null) { if (savedInstanceState == null) {
@@ -135,7 +135,7 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
private void preselectKeys(Long signatureKeyId, long[] encryptionKeyIds) { private void preselectKeys(Long signatureKeyId, long[] encryptionKeyIds) {
if (signatureKeyId != null) { if (signatureKeyId != null) {
try { try {
CachedPublicKeyRing keyring = mDatabaseInteractor.getCachedPublicKeyRing( CachedPublicKeyRing keyring = mKeyRepository.getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingUri(signatureKeyId)); KeyRings.buildUnifiedKeyRingUri(signatureKeyId));
if (keyring.hasAnySecret()) { if (keyring.hasAnySecret()) {
mSignKeySpinner.setPreSelectedKeyId(signatureKeyId); mSignKeySpinner.setPreSelectedKeyId(signatureKeyId);
@@ -149,7 +149,7 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
for (long preselectedId : encryptionKeyIds) { for (long preselectedId : encryptionKeyIds) {
try { try {
CanonicalizedPublicKeyRing ring = CanonicalizedPublicKeyRing ring =
mDatabaseInteractor.getCanonicalizedPublicKeyRing(preselectedId); mKeyRepository.getCanonicalizedPublicKeyRing(preselectedId);
mEncryptKeyView.addObject(new KeyItem(ring)); mEncryptKeyView.addObject(new KeyItem(ring));
} catch (NotFoundException e) { } catch (NotFoundException e) {
Log.e(Constants.TAG, "key not found!", e); Log.e(Constants.TAG, "key not found!", e);

View File

@@ -59,7 +59,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.provider.KeychainDatabase;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.service.BenchmarkInputParcel; import org.sufficientlysecure.keychain.service.BenchmarkInputParcel;
import org.sufficientlysecure.keychain.service.ConsolidateInputParcel; import org.sufficientlysecure.keychain.service.ConsolidateInputParcel;
import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
@@ -486,9 +486,9 @@ public class KeyListFragment extends RecyclerFragment<KeySectionedListAdapter>
return; return;
} }
DatabaseInteractor databaseInteractor = KeyRepository keyRepository =
DatabaseInteractor.createDatabaseInteractor(getContext()); KeyRepository.createDatabaseInteractor(getContext());
Cursor cursor = databaseInteractor.getContentResolver().query( Cursor cursor = keyRepository.getContentResolver().query(
KeyRings.buildUnifiedKeyRingsUri(), new String[]{ KeyRings.buildUnifiedKeyRingsUri(), new String[]{
KeyRings.FINGERPRINT KeyRings.FINGERPRINT
}, null, null, null }, null, null, null

View File

@@ -58,8 +58,8 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; 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 // handle empty passphrases by directly returning an empty crypto input parcel
try { try {
CachedPublicKeyRing pubRing = CachedPublicKeyRing pubRing =
DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId()); KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId());
// use empty passphrase for empty passphrase // use empty passphrase for empty passphrase
if (pubRing.getSecretKeyType(requiredInput.getSubKeyId()) == SecretKeyType.PASSPHRASE_EMPTY) { if (pubRing.getSecretKeyType(requiredInput.getSubKeyId()) == SecretKeyType.PASSPHRASE_EMPTY) {
// also return passphrase back to activity // also return passphrase back to activity
@@ -231,8 +231,8 @@ public class PassphraseDialogActivity extends FragmentActivity {
try { try {
long subKeyId = mRequiredInput.getSubKeyId(); long subKeyId = mRequiredInput.getSubKeyId();
DatabaseInteractor helper = KeyRepository helper =
DatabaseInteractor.createDatabaseInteractor(getContext()); KeyRepository.createDatabaseInteractor(getContext());
CachedPublicKeyRing cachedPublicKeyRing = helper.getCachedPublicKeyRing( CachedPublicKeyRing cachedPublicKeyRing = helper.getCachedPublicKeyRing(
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
// yes the inner try/catch block is necessary, otherwise the final variable // 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)"); 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.setTitle(R.string.title_key_not_found);
alert.setMessage(getString(R.string.key_not_found, mRequiredInput.getSubKeyId())); alert.setMessage(getString(R.string.key_not_found, mRequiredInput.getSubKeyId()));
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@@ -458,7 +458,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
Long subKeyId = mRequiredInput.getSubKeyId(); Long subKeyId = mRequiredInput.getSubKeyId();
CanonicalizedSecretKeyRing secretKeyRing = CanonicalizedSecretKeyRing secretKeyRing =
DatabaseInteractor.createDatabaseInteractor(getContext()).getCanonicalizedSecretKeyRing( KeyRepository.createDatabaseInteractor(getContext()).getCanonicalizedSecretKeyRing(
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
CanonicalizedSecretKey secretKeyToUnlock = CanonicalizedSecretKey secretKeyToUnlock =
secretKeyRing.getSecretKey(subKeyId); secretKeyRing.getSecretKey(subKeyId);

View File

@@ -29,7 +29,7 @@ import android.widget.ImageView;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; 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.base.BaseActivity;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.ui.util.Notify; 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 { try {
byte[] blob = databaseInteractor.getCachedPublicKeyRing(dataUri).getFingerprint(); byte[] blob = keyRepository.getCachedPublicKeyRing(dataUri).getFingerprint();
if (blob == null) { if (blob == null) {
Log.e(Constants.TAG, "key not found!"); Log.e(Constants.TAG, "key not found!");
Notify.create(this, R.string.error_key_not_found, Style.ERROR).show(); Notify.create(this, R.string.error_key_not_found, Style.ERROR).show();

View File

@@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.operations.ImportOperation;
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; 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;
import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.base.BaseActivity;
@@ -106,7 +106,7 @@ public class SafeSlingerActivity extends BaseActivity
// retrieve public key blob and start SafeSlinger // retrieve public key blob and start SafeSlinger
Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId); Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId);
try { try {
byte[] keyBlob = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(uri).getEncoded(); byte[] keyBlob = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(uri).getEncoded();
Intent slingerIntent = new Intent(this, ExchangeActivity.class); Intent slingerIntent = new Intent(this, ExchangeActivity.class);

View File

@@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; 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.provider.KeychainContract;
import org.sufficientlysecure.keychain.securitytoken.KeyType; import org.sufficientlysecure.keychain.securitytoken.KeyType;
import org.sufficientlysecure.keychain.service.PassphraseCacheService; 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)); throw new IOException(getString(R.string.error_wrong_security_token));
} }
DatabaseInteractor databaseInteractor = KeyRepository keyRepository =
DatabaseInteractor.createDatabaseInteractor(this); KeyRepository.createDatabaseInteractor(this);
CanonicalizedPublicKeyRing publicKeyRing; CanonicalizedPublicKeyRing publicKeyRing;
try { try {
publicKeyRing = databaseInteractor.getCanonicalizedPublicKeyRing( publicKeyRing = keyRepository.getCanonicalizedPublicKeyRing(
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mRequiredInput.getMasterKeyId())); 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."); 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.setPin(new Passphrase("123456"));
mSecurityTokenHelper.setAdminPin(new Passphrase("12345678")); mSecurityTokenHelper.setAdminPin(new Passphrase("12345678"));
DatabaseInteractor databaseInteractor = KeyRepository keyRepository =
DatabaseInteractor.createDatabaseInteractor(this); KeyRepository.createDatabaseInteractor(this);
CanonicalizedSecretKeyRing secretKeyRing; CanonicalizedSecretKeyRing secretKeyRing;
try { try {
secretKeyRing = databaseInteractor.getCanonicalizedSecretKeyRing( secretKeyRing = keyRepository.getCanonicalizedSecretKeyRing(
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mRequiredInput.getMasterKeyId()) 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."); throw new IOException("Couldn't find subkey for key to token operation.");
} }

View File

@@ -40,7 +40,7 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; 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.base.BaseActivity;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@@ -184,9 +184,9 @@ public class ViewCertActivity extends BaseActivity
Intent viewIntent = new Intent(ViewCertActivity.this, ViewKeyActivity.class); Intent viewIntent = new Intent(ViewCertActivity.this, ViewKeyActivity.class);
try { try {
DatabaseInteractor databaseInteractor = KeyRepository keyRepository =
DatabaseInteractor.createDatabaseInteractor(ViewCertActivity.this); KeyRepository.createDatabaseInteractor(ViewCertActivity.this);
long signerMasterKeyId = databaseInteractor.getCachedPublicKeyRing( long signerMasterKeyId = keyRepository.getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId(); KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId();
viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId)); viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId));
startActivity(viewIntent); startActivity(viewIntent);

View File

@@ -77,8 +77,8 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; 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_DISPLAY_RESULT = "display_result";
public static final String EXTRA_LINKED_TRANSITION = "linked_transition"; public static final String EXTRA_LINKED_TRANSITION = "linked_transition";
DatabaseInteractor mDatabaseInteractor; KeyRepository mKeyRepository;
protected Uri mDataUri; protected Uri mDataUri;
@@ -185,7 +185,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(this); mKeyRepository = KeyRepository.createDatabaseInteractor(this);
mImportOpHelper = new CryptoOperationHelper<>(1, this, this, null); mImportOpHelper = new CryptoOperationHelper<>(1, this, this, null);
setTitle(null); setTitle(null);
@@ -318,7 +318,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
// or start new ones. // or start new ones.
getSupportLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this); getSupportLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this);
mNfcHelper = new NfcHelper(this, mDatabaseInteractor); mNfcHelper = new NfcHelper(this, mKeyRepository);
mNfcHelper.initNfc(mDataUri); mNfcHelper.initNfc(mDataUri);
if (savedInstanceState == null && getIntent().hasExtra(EXTRA_DISPLAY_RESULT)) { 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: { case R.id.menu_key_view_refresh: {
try { try {
updateFromKeyserver(mDataUri, mDatabaseInteractor); updateFromKeyserver(mDataUri, mKeyRepository);
} catch (PgpKeyNotFoundException e) { } catch (PgpKeyNotFoundException e) {
Notify.create(this, R.string.error_key_not_found, Notify.Style.ERROR).show(); 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() { private boolean keyHasPassphrase() {
try { try {
SecretKeyType secretKeyType = SecretKeyType secretKeyType =
mDatabaseInteractor.getCachedPublicKeyRing(mMasterKeyId).getSecretKeyType(mMasterKeyId); mKeyRepository.getCachedPublicKeyRing(mMasterKeyId).getSecretKeyType(mMasterKeyId);
switch (secretKeyType) { switch (secretKeyType) {
// all of these make no sense to ask // all of these make no sense to ask
case PASSPHRASE_EMPTY: case PASSPHRASE_EMPTY:
@@ -666,7 +666,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
try { try {
// if the security token matches a subkey in any key // if the security token matches a subkey in any key
CachedPublicKeyRing ring = mDatabaseInteractor.getCachedPublicKeyRing( CachedPublicKeyRing ring = mKeyRepository.getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(tokenId)); KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(tokenId));
byte[] candidateFp = ring.getFingerprint(); byte[] candidateFp = ring.getFingerprint();
@@ -741,7 +741,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
return; return;
} }
try { try {
long keyId = DatabaseInteractor.createDatabaseInteractor(this) long keyId = KeyRepository.createDatabaseInteractor(this)
.getCachedPublicKeyRing(dataUri) .getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId(); .extractOrGetMasterKeyId();
long[] encryptionKeyIds = new long[]{keyId}; long[] encryptionKeyIds = new long[]{keyId};
@@ -765,7 +765,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
private void startSafeSlinger(Uri dataUri) { private void startSafeSlinger(Uri dataUri) {
long keyId = 0; long keyId = 0;
try { try {
keyId = DatabaseInteractor.createDatabaseInteractor(this) keyId = KeyRepository.createDatabaseInteractor(this)
.getCachedPublicKeyRing(dataUri) .getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId(); .extractOrGetMasterKeyId();
} catch (PgpKeyNotFoundException e) { } catch (PgpKeyNotFoundException e) {
@@ -1118,7 +1118,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
// CryptoOperationHelper.Callback functions // CryptoOperationHelper.Callback functions
private void updateFromKeyserver(Uri dataUri, DatabaseInteractor databaseInteractor) private void updateFromKeyserver(Uri dataUri, KeyRepository keyRepository)
throws PgpKeyNotFoundException { throws PgpKeyNotFoundException {
mIsRefreshing = true; mIsRefreshing = true;
@@ -1126,7 +1126,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
mRefreshItem.setActionView(mRefresh); mRefreshItem.setActionView(mRefresh);
mRefresh.startAnimation(mRotate); mRefresh.startAnimation(mRotate);
byte[] blob = databaseInteractor.getCachedPublicKeyRing(dataUri).getFingerprint(); byte[] blob = keyRepository.getCachedPublicKeyRing(dataUri).getFingerprint();
String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob); String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob);
ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null, null); ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null, null);

View File

@@ -43,7 +43,7 @@ import com.astuetz.PagerSlidingTabStrip;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.operations.results.OperationResult; 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.provider.KeychainContract;
import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.base.BaseActivity;
@@ -54,7 +54,7 @@ import org.sufficientlysecure.keychain.util.Log;
public class ViewKeyAdvActivity extends BaseActivity implements public class ViewKeyAdvActivity extends BaseActivity implements
LoaderCallbacks<Cursor>, OnPageChangeListener { LoaderCallbacks<Cursor>, OnPageChangeListener {
DatabaseInteractor mDatabaseInteractor; KeyRepository mKeyRepository;
protected Uri mDataUri; 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); mViewPager = (ViewPager) findViewById(R.id.pager);
mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tab_layout); mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tab_layout);

View File

@@ -58,7 +58,7 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; 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.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.ui.base.LoaderFragment; 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()); View view = inflater.inflate(R.layout.view_key_adv_share_fragment, getContainer());
ContentResolver contentResolver = ViewKeyAdvShareFragment.this.getActivity().getContentResolver(); ContentResolver contentResolver = ViewKeyAdvShareFragment.this.getActivity().getContentResolver();
DatabaseInteractor databaseInteractor = DatabaseInteractor.createDatabaseInteractor(getContext()); KeyRepository keyRepository = KeyRepository.createDatabaseInteractor(getContext());
mNfcHelper = new NfcHelper(getActivity(), databaseInteractor); mNfcHelper = new NfcHelper(getActivity(), keyRepository);
mFingerprintView = (TextView) view.findViewById(R.id.view_key_fingerprint); mFingerprintView = (TextView) view.findViewById(R.id.view_key_fingerprint);
mQrCode = (ImageView) view.findViewById(R.id.view_key_qr_code); 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) { private void startSafeSlinger(Uri dataUri) {
long keyId = 0; long keyId = 0;
try { try {
keyId = DatabaseInteractor.createDatabaseInteractor(getContext()) keyId = KeyRepository.createDatabaseInteractor(getContext())
.getCachedPublicKeyRing(dataUri) .getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId(); .extractOrGetMasterKeyId();
} catch (PgpKeyNotFoundException e) { } catch (PgpKeyNotFoundException e) {
@@ -218,12 +218,12 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
if (activity == null || mFingerprint == null) { if (activity == null || mFingerprint == null) {
return; return;
} }
DatabaseInteractor databaseInteractor = KeyRepository keyRepository =
DatabaseInteractor.createDatabaseInteractor(getContext()); KeyRepository.createDatabaseInteractor(getContext());
try { try {
long masterKeyId = databaseInteractor.getCachedPublicKeyRing(mDataUri).extractOrGetMasterKeyId(); long masterKeyId = keyRepository.getCachedPublicKeyRing(mDataUri).extractOrGetMasterKeyId();
String content = databaseInteractor.getPublicKeyRingAsArmoredString(masterKeyId); String content = keyRepository.getPublicKeyRingAsArmoredString(masterKeyId);
if (toClipboard) { if (toClipboard) {
ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
@@ -276,7 +276,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
} catch (PgpGeneralException | IOException e) { } catch (PgpGeneralException | IOException e) {
Log.e(Constants.TAG, "error processing key!", e); Log.e(Constants.TAG, "error processing key!", e);
Notify.create(activity, R.string.error_key_processing, Notify.Style.ERROR).show(); 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); Log.e(Constants.TAG, "key not found!", e);
Notify.create(activity, R.string.error_key_not_found, Notify.Style.ERROR).show(); 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() { private void uploadToKeyserver() {
long keyId; long keyId;
try { try {
keyId = DatabaseInteractor.createDatabaseInteractor(getContext()) keyId = KeyRepository.createDatabaseInteractor(getContext())
.getCachedPublicKeyRing(mDataUri) .getCachedPublicKeyRing(mDataUri)
.extractOrGetMasterKeyId(); .extractOrGetMasterKeyId();
} catch (PgpKeyNotFoundException e) { } catch (PgpKeyNotFoundException e) {

View File

@@ -46,7 +46,7 @@ import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; 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.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
import org.sufficientlysecure.keychain.ui.ViewKeyActivity; import org.sufficientlysecure.keychain.ui.ViewKeyActivity;
@@ -66,7 +66,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
private List<ImportKeysListEntry> mData; private List<ImportKeysListEntry> mData;
private KeyState[] mKeyStates; private KeyState[] mKeyStates;
private DatabaseInteractor mDatabaseInteractor; private KeyRepository mKeyRepository;
public ImportKeysAdapter(FragmentActivity activity, ImportKeysListener listener, public ImportKeysAdapter(FragmentActivity activity, ImportKeysListener listener,
boolean nonInteractive) { boolean nonInteractive) {
@@ -75,7 +75,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
mListener = listener; mListener = listener;
mNonInteractive = nonInteractive; mNonInteractive = nonInteractive;
mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(activity); mKeyRepository = KeyRepository.createDatabaseInteractor(activity);
} }
public void setData(List<ImportKeysListEntry> data) { public void setData(List<ImportKeysListEntry> data) {
@@ -90,13 +90,13 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
try { try {
KeyRing keyRing; KeyRing keyRing;
if (entry.isSecretKey()) { if (entry.isSecretKey()) {
keyRing = mDatabaseInteractor.getCanonicalizedSecretKeyRing(keyId); keyRing = mKeyRepository.getCanonicalizedSecretKeyRing(keyId);
} else { } else {
keyRing = mDatabaseInteractor.getCachedPublicKeyRing(keyId); keyRing = mKeyRepository.getCachedPublicKeyRing(keyId);
} }
keyState.mAlreadyPresent = true; keyState.mAlreadyPresent = true;
keyState.mVerified = keyRing.getVerified() > 0; keyState.mVerified = keyRing.getVerified() > 0;
} catch (DatabaseInteractor.NotFoundException | PgpKeyNotFoundException ignored) { } catch (KeyRepository.NotFoundException | PgpKeyNotFoundException ignored) {
} }
mKeyStates[i] = keyState; mKeyStates[i] = keyState;

View File

@@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; 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.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.securitytoken.CardException; import org.sufficientlysecure.keychain.securitytoken.CardException;
import org.sufficientlysecure.keychain.securitytoken.NfcTransport; import org.sufficientlysecure.keychain.securitytoken.NfcTransport;
@@ -105,7 +105,7 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity
final long subKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mSecurityTokenFingerprints); final long subKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mSecurityTokenFingerprints);
try { try {
CachedPublicKeyRing ring = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing( CachedPublicKeyRing ring = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
long masterKeyId = ring.getMasterKeyId(); long masterKeyId = ring.getMasterKeyId();

View File

@@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; 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;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.base.BaseActivity;
@@ -58,7 +58,7 @@ public class LinkedIdWizard extends BaseActivity {
try { try {
Uri uri = getIntent().getData(); Uri uri = getIntent().getData();
uri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(uri); uri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(uri);
CachedPublicKeyRing ring = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(uri); CachedPublicKeyRing ring = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(uri);
if (!ring.hasAnySecret()) { if (!ring.hasAnySecret()) {
Log.e(Constants.TAG, "Linked Identities can only be added to secret keys!"); Log.e(Constants.TAG, "Linked Identities can only be added to secret keys!");
finish(); finish();

View File

@@ -39,8 +39,8 @@ import android.provider.Settings;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify;
/** /**
@@ -50,7 +50,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
public class NfcHelper { public class NfcHelper {
private Activity mActivity; private Activity mActivity;
private DatabaseInteractor mDatabaseInteractor; private KeyRepository mKeyRepository;
/** /**
* NFC: This handler receives a message from onNdefPushComplete * NFC: This handler receives a message from onNdefPushComplete
@@ -66,9 +66,9 @@ public class NfcHelper {
/** /**
* Initializes the NfcHelper. * Initializes the NfcHelper.
*/ */
public NfcHelper(final Activity activity, final DatabaseInteractor databaseInteractor) { public NfcHelper(final Activity activity, final KeyRepository keyRepository) {
mActivity = activity; mActivity = activity;
mDatabaseInteractor = databaseInteractor; mKeyRepository = keyRepository;
mNfcHandler = new NfcHandler(mActivity); mNfcHandler = new NfcHandler(mActivity);
} }
@@ -128,9 +128,9 @@ public class NfcHelper {
new AsyncTask<Void, Void, Void>() { new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... unused) { protected Void doInBackground(Void... unused) {
try { try {
long masterKeyId = mDatabaseInteractor.getCachedPublicKeyRing(dataUri) long masterKeyId = mKeyRepository.getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId(); .extractOrGetMasterKeyId();
mNfcKeyringBytes = mDatabaseInteractor.loadPublicKeyRingData(masterKeyId); mNfcKeyringBytes = mKeyRepository.loadPublicKeyRingData(masterKeyId);
} catch (NotFoundException | PgpKeyNotFoundException e) { } catch (NotFoundException | PgpKeyNotFoundException e) {
Log.e(Constants.TAG, "key not found!", e); Log.e(Constants.TAG, "key not found!", e);
} }

View File

@@ -44,7 +44,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;
import org.sufficientlysecure.keychain.pgp.WrappedSignature; 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.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.service.BackupKeyringParcel; import org.sufficientlysecure.keychain.service.BackupKeyringParcel;
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
@@ -135,8 +135,8 @@ public class BackupOperationTest {
@Before @Before
public void setUp() { public void setUp() {
DatabaseReadWriteInteractor databaseInteractor = KeyWritableRepository databaseInteractor =
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
// don't log verbosely here, we're not here to test imports // don't log verbosely here, we're not here to test imports
ShadowLog.stream = oldShadowStream; ShadowLog.stream = oldShadowStream;
@@ -151,7 +151,7 @@ public class BackupOperationTest {
@Test @Test
public void testExportAllLocalStripped() throws Exception { public void testExportAllLocalStripped() throws Exception {
BackupOperation op = new BackupOperation(RuntimeEnvironment.application, 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) // 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)); assertTrue("second keyring has local certification", checkForLocal(mStaticRing2));
@@ -250,7 +250,7 @@ public class BackupOperationTest {
when(spyApplication.getContentResolver()).thenReturn(mockResolver); when(spyApplication.getContentResolver()).thenReturn(mockResolver);
BackupOperation op = new BackupOperation(spyApplication, BackupOperation op = new BackupOperation(spyApplication,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
BackupKeyringParcel parcel = new BackupKeyringParcel( BackupKeyringParcel parcel = new BackupKeyringParcel(
new long[] { mStaticRing1.getMasterKeyId() }, false, false, true, fakeOutputUri); new long[] { mStaticRing1.getMasterKeyId() }, false, false, true, fakeOutputUri);
@@ -307,7 +307,7 @@ public class BackupOperationTest {
{ // export encrypted { // export encrypted
BackupOperation op = new BackupOperation(spyApplication, BackupOperation op = new BackupOperation(spyApplication,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
BackupKeyringParcel parcel = new BackupKeyringParcel( BackupKeyringParcel parcel = new BackupKeyringParcel(
new long[] { mStaticRing1.getMasterKeyId() }, false, true, true, fakeOutputUri); new long[] { mStaticRing1.getMasterKeyId() }, false, true, true, fakeOutputUri);
@@ -325,7 +325,7 @@ public class BackupOperationTest {
{ {
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(outStream.toByteArray()); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(outStream.toByteArray());
input.setAllowSymmetricDecryption(true); input.setAllowSymmetricDecryption(true);

View File

@@ -25,7 +25,7 @@ import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLog;
import org.sufficientlysecure.keychain.KeychainTestRunner; import org.sufficientlysecure.keychain.KeychainTestRunner;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.service.BenchmarkInputParcel; import org.sufficientlysecure.keychain.service.BenchmarkInputParcel;
import java.io.PrintStream; import java.io.PrintStream;
@@ -47,7 +47,7 @@ public class BenchmarkOperationTest {
@Test @Test
public void testBenchmark() throws Exception { public void testBenchmark() throws Exception {
BenchmarkOperation op = new BenchmarkOperation(RuntimeEnvironment.application, BenchmarkOperation op = new BenchmarkOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
op.execute(new BenchmarkInputParcel(), null); op.execute(new BenchmarkInputParcel(), null);
} }

View File

@@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; 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.provider.KeychainContract.Certs;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
@@ -117,8 +117,8 @@ public class CertifyOperationTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
DatabaseReadWriteInteractor databaseInteractor = KeyWritableRepository databaseInteractor =
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
// don't log verbosely here, we're not here to test imports // don't log verbosely here, we're not here to test imports
ShadowLog.stream = oldShadowStream; ShadowLog.stream = oldShadowStream;
@@ -133,7 +133,7 @@ public class CertifyOperationTest {
@Test @Test
public void testSelfCertifyFlag() throws Exception { public void testSelfCertifyFlag() throws Exception {
CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) CanonicalizedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
.getCanonicalizedPublicKeyRing(mStaticRing1.getMasterKeyId()); .getCanonicalizedPublicKeyRing(mStaticRing1.getMasterKeyId());
Assert.assertEquals("secret key must be marked self-certified in database", Assert.assertEquals("secret key must be marked self-certified in database",
// TODO this should be more correctly be VERIFIED_SELF at some point! // TODO this should be more correctly be VERIFIED_SELF at some point!
@@ -144,10 +144,10 @@ public class CertifyOperationTest {
@Test @Test
public void testCertifyId() throws Exception { public void testCertifyId() throws Exception {
CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, 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()); .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
Assert.assertEquals("public key must not be marked verified prior to certification", Assert.assertEquals("public key must not be marked verified prior to certification",
Certs.UNVERIFIED, ring.getVerified()); Certs.UNVERIFIED, ring.getVerified());
@@ -161,7 +161,7 @@ public class CertifyOperationTest {
Assert.assertTrue("certification must succeed", result.success()); Assert.assertTrue("certification must succeed", result.success());
{ {
CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) CanonicalizedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
Assert.assertEquals("new key must be verified now", Assert.assertEquals("new key must be verified now",
Certs.VERIFIED_SECRET, ring.getVerified()); Certs.VERIFIED_SECRET, ring.getVerified());
@@ -172,10 +172,10 @@ public class CertifyOperationTest {
@Test @Test
public void testCertifyAttribute() throws Exception { public void testCertifyAttribute() throws Exception {
CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, 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()); .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
Assert.assertEquals("public key must not be marked verified prior to certification", Assert.assertEquals("public key must not be marked verified prior to certification",
Certs.UNVERIFIED, ring.getVerified()); Certs.UNVERIFIED, ring.getVerified());
@@ -189,7 +189,7 @@ public class CertifyOperationTest {
Assert.assertTrue("certification must succeed", result.success()); Assert.assertTrue("certification must succeed", result.success());
{ {
CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) CanonicalizedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
Assert.assertEquals("new key must be verified now", Assert.assertEquals("new key must be verified now",
Certs.VERIFIED_SECRET, ring.getVerified()); Certs.VERIFIED_SECRET, ring.getVerified());
@@ -201,7 +201,7 @@ public class CertifyOperationTest {
@Test @Test
public void testCertifySelf() throws Exception { public void testCertifySelf() throws Exception {
CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(), actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
@@ -218,7 +218,7 @@ public class CertifyOperationTest {
public void testCertifyNonexistent() throws Exception { public void testCertifyNonexistent() throws Exception {
CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
{ {
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());

View File

@@ -38,7 +38,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; import org.sufficientlysecure.keychain.pgp.UncachedPublicKey;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; 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.ChangeUnlockParcel;
import org.sufficientlysecure.keychain.service.PromoteKeyringParcel; import org.sufficientlysecure.keychain.service.PromoteKeyringParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
@@ -90,8 +90,8 @@ public class PromoteKeyOperationTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
DatabaseReadWriteInteractor databaseInteractor = KeyWritableRepository databaseInteractor =
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
// don't log verbosely here, we're not here to test imports // don't log verbosely here, we're not here to test imports
ShadowLog.stream = oldShadowStream; ShadowLog.stream = oldShadowStream;
@@ -105,14 +105,14 @@ public class PromoteKeyOperationTest {
@Test @Test
public void testPromote() throws Exception { public void testPromote() throws Exception {
PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, 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); PromoteKeyResult result = op.execute(new PromoteKeyringParcel(mStaticRing.getMasterKeyId(), null, null), null);
Assert.assertTrue("promotion must succeed", result.success()); Assert.assertTrue("promotion must succeed", result.success());
{ {
CachedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) CachedPublicKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
.getCachedPublicKeyRing(mStaticRing.getMasterKeyId()); .getCachedPublicKeyRing(mStaticRing.getMasterKeyId());
Assert.assertTrue("key must have a secret now", ring.hasAnySecret()); Assert.assertTrue("key must have a secret now", ring.hasAnySecret());
@@ -129,7 +129,7 @@ public class PromoteKeyOperationTest {
@Test @Test
public void testPromoteDivert() throws Exception { public void testPromoteDivert() throws Exception {
PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
byte[] aid = Hex.decode("D2760001240102000000012345670000"); byte[] aid = Hex.decode("D2760001240102000000012345670000");
@@ -138,7 +138,7 @@ public class PromoteKeyOperationTest {
Assert.assertTrue("promotion must succeed", result.success()); Assert.assertTrue("promotion must succeed", result.success());
{ {
CanonicalizedSecretKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) CanonicalizedSecretKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
.getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId());
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
@@ -154,7 +154,7 @@ public class PromoteKeyOperationTest {
@Test @Test
public void testPromoteDivertSpecific() throws Exception { public void testPromoteDivertSpecific() throws Exception {
PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
byte[] aid = Hex.decode("D2760001240102000000012345670000"); byte[] aid = Hex.decode("D2760001240102000000012345670000");
@@ -168,7 +168,7 @@ public class PromoteKeyOperationTest {
Assert.assertTrue("promotion must succeed", result.success()); Assert.assertTrue("promotion must succeed", result.success());
{ {
CanonicalizedSecretKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) CanonicalizedSecretKeyRing ring = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
.getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId());
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {

View File

@@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.KeychainTestRunner;
import org.sufficientlysecure.keychain.operations.InputDataOperation; import org.sufficientlysecure.keychain.operations.InputDataOperation;
import org.sufficientlysecure.keychain.operations.results.InputDataResult; import org.sufficientlysecure.keychain.operations.results.InputDataResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; 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.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.service.InputDataParcel; import org.sufficientlysecure.keychain.service.InputDataParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
@@ -126,7 +126,7 @@ public class InputDataOperationTest {
when(spyApplication.getContentResolver()).thenReturn(mockResolver); when(spyApplication.getContentResolver()).thenReturn(mockResolver);
InputDataOperation op = new InputDataOperation(spyApplication, InputDataOperation op = new InputDataOperation(spyApplication,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
InputDataParcel input = new InputDataParcel(fakeInputUri, null); InputDataParcel input = new InputDataParcel(fakeInputUri, null);
@@ -306,7 +306,7 @@ public class InputDataOperationTest {
when(spyApplication.getContentResolver()).thenReturn(mockResolver); when(spyApplication.getContentResolver()).thenReturn(mockResolver);
InputDataOperation op = new InputDataOperation(spyApplication, 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); InputDataParcel input = new InputDataParcel(FAKE_CONTENT_INPUT_URI_1, null);
return op.execute(input, new CryptoInputParcel()); return op.execute(input, new CryptoInputParcel());

View File

@@ -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.OperationResult.LogType;
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult; 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.provider.KeychainContract.KeyRingData;
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
@@ -149,8 +149,8 @@ public class PgpEncryptDecryptTest {
@Before @Before
public void setUp() { public void setUp() {
DatabaseReadWriteInteractor databaseInteractor = KeyWritableRepository databaseInteractor =
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
// don't log verbosely here, we're not here to test imports // don't log verbosely here, we're not here to test imports
ShadowLog.stream = oldShadowStream; ShadowLog.stream = oldShadowStream;
@@ -173,7 +173,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
@@ -198,7 +198,7 @@ public class PgpEncryptDecryptTest {
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
input.setAllowSymmetricDecryption(true); input.setAllowSymmetricDecryption(true);
DecryptVerifyResult result = op.execute( DecryptVerifyResult result = op.execute(
@@ -228,7 +228,7 @@ public class PgpEncryptDecryptTest {
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
input.setAllowSymmetricDecryption(true); input.setAllowSymmetricDecryption(true);
DecryptVerifyResult result = op.execute(input, DecryptVerifyResult result = op.execute(input,
@@ -250,7 +250,7 @@ public class PgpEncryptDecryptTest {
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
input.setAllowSymmetricDecryption(true); input.setAllowSymmetricDecryption(true);
DecryptVerifyResult result = op.execute(input, DecryptVerifyResult result = op.execute(input,
@@ -271,7 +271,7 @@ public class PgpEncryptDecryptTest {
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
input.setAllowSymmetricDecryption(false); input.setAllowSymmetricDecryption(false);
DecryptVerifyResult result = op.execute(input, DecryptVerifyResult result = op.execute(input,
@@ -298,7 +298,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
@@ -354,7 +354,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
@@ -416,7 +416,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
@@ -473,7 +473,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
@@ -576,7 +576,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
@@ -627,12 +627,12 @@ public class PgpEncryptDecryptTest {
new ArrayList<RawPacket>(), new ArrayList<RawPacket>(), new ArrayList<RawPacket>(), new ArrayList<RawPacket>(),
new CryptoInputParcel(new Date(), mKeyPhrase1)); new CryptoInputParcel(new Date(), mKeyPhrase1));
DatabaseReadWriteInteractor databaseInteractor = KeyWritableRepository databaseInteractor =
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler());
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext);
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1)); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1));
@@ -650,12 +650,12 @@ public class PgpEncryptDecryptTest {
new ArrayList<RawPacket>(), new ArrayList<RawPacket>(), new ArrayList<RawPacket>(), new ArrayList<RawPacket>(),
new CryptoInputParcel(new Date(), mKeyPhrase1)); new CryptoInputParcel(new Date(), mKeyPhrase1));
DatabaseReadWriteInteractor databaseInteractor = KeyWritableRepository databaseInteractor =
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler());
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext);
DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1)); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1));
@@ -678,8 +678,8 @@ public class PgpEncryptDecryptTest {
new ArrayList<RawPacket>(), new ArrayList<RawPacket>(), new ArrayList<RawPacket>(), new ArrayList<RawPacket>(),
new CryptoInputParcel(new Date(), mKeyPhrase1)); new CryptoInputParcel(new Date(), mKeyPhrase1));
DatabaseReadWriteInteractor databaseInteractor = KeyWritableRepository databaseInteractor =
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler());
} }
@@ -689,7 +689,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
@@ -734,7 +734,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); 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 { // decryption with passphrase cached should succeed for the other key if first is gone
// delete first key from database // delete first key from database
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete( KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete(
KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null
); );
@@ -863,7 +863,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); 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 { // decryption with passphrase cached should succeed for the other key if first is gone
// delete first key from database // delete first key from database
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete( KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete(
KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null
); );
@@ -950,7 +950,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaindata); ByteArrayInputStream in = new ByteArrayInputStream(plaindata);
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
@@ -1022,7 +1022,7 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
@@ -1073,7 +1073,7 @@ public class PgpEncryptDecryptTest {
final Passphrase passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) { final Passphrase passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) {
return new PgpDecryptVerifyOperation(RuntimeEnvironment.application, return new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null) { KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null) {
@Override @Override
public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId) public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId)
throws NoSecretKeyException { throws NoSecretKeyException {

View File

@@ -243,7 +243,7 @@ public class InteropTest {
final Uri verifyUri = verify != null ? final Uri verifyUri = verify != null ?
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(verify.getMasterKeyId()) : null; KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(verify.getMasterKeyId()) : null;
DatabaseReadWriteInteractor helper = new DatabaseReadWriteInteractor(RuntimeEnvironment.application) { KeyWritableRepository helper = new KeyWritableRepository(RuntimeEnvironment.application) {
@Override @Override
public CachedPublicKeyRing getCachedPublicKeyRing(Uri queryUri) throws PgpKeyNotFoundException { public CachedPublicKeyRing getCachedPublicKeyRing(Uri queryUri) throws PgpKeyNotFoundException {

View File

@@ -30,7 +30,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@RunWith(KeychainTestRunner.class) @RunWith(KeychainTestRunner.class)
public class DatabaseInteractorKeyringTest { public class KeyRepositoryKeyringTest {
@Test @Test
public void testSavePublicKeyring() throws Exception { public void testSavePublicKeyring() throws Exception {

View File

@@ -41,10 +41,10 @@ import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
@RunWith(KeychainTestRunner.class) @RunWith(KeychainTestRunner.class)
public class DatabaseInteractorSaveTest { public class KeyRepositorySaveTest {
DatabaseReadWriteInteractor mDatabaseInteractor = KeyWritableRepository mDatabaseInteractor =
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
@BeforeClass @BeforeClass
public static void setUpOnce() throws Exception { public static void setUpOnce() throws Exception {
@@ -62,17 +62,17 @@ public class DatabaseInteractorSaveTest {
SaveKeyringResult result; SaveKeyringResult result;
// insert both keys, second should fail // 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()); 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()); Assert.assertFalse("second keyring import should fail", result.success());
new KeychainDatabase(RuntimeEnvironment.application).clearDatabase(); new KeychainDatabase(RuntimeEnvironment.application).clearDatabase();
// and the other way around // 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()); 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()); Assert.assertFalse("second keyring import should fail", result.success());
} }
@@ -91,14 +91,14 @@ public class DatabaseInteractorSaveTest {
SaveKeyringResult result; SaveKeyringResult result;
// insert secret, this should fail because of missing self-cert // insert secret, this should fail because of missing self-cert
result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
.saveSecretKeyRing(seckey, new ProgressScaler()); .saveSecretKeyRing(seckey, new ProgressScaler());
Assert.assertFalse("secret keyring import before pubring import should fail", result.success()); Assert.assertFalse("secret keyring import before pubring import should fail", result.success());
// insert pubkey, then seckey - both should succeed // 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()); Assert.assertTrue("public keyring import should succeed", result.success());
result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application) result = KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
.saveSecretKeyRing(seckey, new ProgressScaler()); .saveSecretKeyRing(seckey, new ProgressScaler());
Assert.assertTrue("secret keyring import after pubring import should succeed", result.success()); 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 { UncachedKeyRing readRingFromResource(String name) throws Exception {
return UncachedKeyRing.fromStream(DatabaseInteractorSaveTest.class.getResourceAsStream(name)).next(); return UncachedKeyRing.fromStream(KeyRepositorySaveTest.class.getResourceAsStream(name)).next();
} }
} }

View File

@@ -20,9 +20,9 @@ import org.sufficientlysecure.keychain.operations.results.CertifyResult;
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; 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.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;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
@@ -45,8 +45,8 @@ public class KeychainExternalProviderTest {
static final long KEY_ID_PUBLIC = 0x9A282CE2AB44A382L; static final long KEY_ID_PUBLIC = 0x9A282CE2AB44A382L;
DatabaseReadWriteInteractor databaseInteractor = KeyWritableRepository databaseInteractor =
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application); KeyWritableRepository.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver(); ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver();
ApiPermissionHelper apiPermissionHelper; ApiPermissionHelper apiPermissionHelper;
ApiDataAccessObject apiDao; ApiDataAccessObject apiDao;
@@ -207,6 +207,6 @@ public class KeychainExternalProviderTest {
} }
UncachedKeyRing readRingFromResource(String name) throws Exception { UncachedKeyRing readRingFromResource(String name) throws Exception {
return UncachedKeyRing.fromStream(DatabaseInteractorSaveTest.class.getResourceAsStream(name)).next(); return UncachedKeyRing.fromStream(KeyRepositorySaveTest.class.getResourceAsStream(name)).next();
} }
} }

View File

@@ -21,11 +21,11 @@ import android.content.Context;
import android.net.Uri; import android.net.Uri;
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
class DatabaseInteractorStub extends DatabaseReadWriteInteractor { class KeyRepositoryStub extends KeyWritableRepository {
public DatabaseInteractorStub(Context context) { public KeyRepositoryStub(Context context) {
super(context); super(context);
} }

View File

@@ -23,9 +23,9 @@ import android.content.Context;
import org.bouncycastle.util.Arrays; import org.bouncycastle.util.Arrays;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; 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.operations.results.SaveKeyringResult;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.util.ProgressScaler; import org.sufficientlysecure.keychain.util.ProgressScaler;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@@ -51,8 +51,8 @@ public class KeyringTestingHelper {
public boolean addKeyring(Collection<String> blobFiles) throws Exception { public boolean addKeyring(Collection<String> blobFiles) throws Exception {
DatabaseReadWriteInteractor databaseInteractor = KeyWritableRepository databaseInteractor =
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context); KeyWritableRepository.createDatabaseReadWriteInteractor(context);
byte[] data = TestDataUtil.readAllFully(blobFiles); byte[] data = TestDataUtil.readAllFully(blobFiles);
UncachedKeyRing ring = UncachedKeyRing.decodeFromData(data); UncachedKeyRing ring = UncachedKeyRing.decodeFromData(data);
@@ -347,11 +347,11 @@ public class KeyringTestingHelper {
return getNth(ring.getPublicKeys(), position).getKeyId(); return getNth(ring.getPublicKeys(), position).getKeyId();
} }
private void retrieveKeyAndExpectNotFound(DatabaseInteractor databaseInteractor, long masterKeyId) { private void retrieveKeyAndExpectNotFound(KeyRepository keyRepository, long masterKeyId) {
try { try {
databaseInteractor.getCanonicalizedPublicKeyRing(masterKeyId); keyRepository.getCanonicalizedPublicKeyRing(masterKeyId);
throw new AssertionError("Was expecting the previous call to fail!"); throw new AssertionError("Was expecting the previous call to fail!");
} catch (DatabaseReadWriteInteractor.NotFoundException expectedException) { } catch (KeyWritableRepository.NotFoundException expectedException) {
// good // good
} }
} }