DatabaseInteractor -> KeyRepository
This commit is contained in:
@@ -47,7 +47,7 @@ import org.bouncycastle.openpgp.operator.jcajce.SessionKeySecretKeyDecryptorBuil
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor;
|
||||
import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
@@ -127,7 +127,7 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
|
||||
* passphrase in the process.
|
||||
*
|
||||
* This method can potentially take a LONG time (i.e. seconds), so it should only
|
||||
* ever be called by {@link DatabaseReadWriteInteractor} for the purpose of caching its output
|
||||
* ever be called by {@link KeyWritableRepository} for the purpose of caching its output
|
||||
* in the database.
|
||||
*/
|
||||
public SecretKeyType getSecretKeyTypeSuperExpensive() {
|
||||
|
||||
@@ -27,8 +27,8 @@ import org.openintents.openpgp.util.OpenPgpUtils;
|
||||
import org.openintents.openpgp.util.OpenPgpUtils.UserId;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.DatabaseInteractor;
|
||||
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
||||
*/
|
||||
public class OpenPgpSignatureResultBuilder {
|
||||
// injected
|
||||
private final DatabaseInteractor mDatabaseInteractor;
|
||||
private final KeyRepository mKeyRepository;
|
||||
|
||||
// OpenPgpSignatureResult
|
||||
private String mPrimaryUserId;
|
||||
@@ -57,8 +57,8 @@ public class OpenPgpSignatureResultBuilder {
|
||||
private String mSenderAddress;
|
||||
private Date mSignatureTimestamp;
|
||||
|
||||
public OpenPgpSignatureResultBuilder(DatabaseInteractor databaseInteractor) {
|
||||
this.mDatabaseInteractor = databaseInteractor;
|
||||
public OpenPgpSignatureResultBuilder(KeyRepository keyRepository) {
|
||||
this.mKeyRepository = keyRepository;
|
||||
}
|
||||
|
||||
public void setPrimaryUserId(String userId) {
|
||||
@@ -127,7 +127,7 @@ public class OpenPgpSignatureResultBuilder {
|
||||
|
||||
try {
|
||||
ArrayList<String> allUserIds = signingRing.getUnorderedUserIds();
|
||||
ArrayList<String> confirmedUserIds = mDatabaseInteractor.getConfirmedUserIds(signingRing.getMasterKeyId());
|
||||
ArrayList<String> confirmedUserIds = mKeyRepository.getConfirmedUserIds(signingRing.getMasterKeyId());
|
||||
setUserIds(allUserIds, confirmedUserIds);
|
||||
|
||||
if (mSenderAddress != null) {
|
||||
|
||||
@@ -71,8 +71,8 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.DatabaseInteractor;
|
||||
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
@@ -88,8 +88,8 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
||||
|
||||
public static final int PROGRESS_STRIDE_MILLISECONDS = 200;
|
||||
|
||||
public PgpDecryptVerifyOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) {
|
||||
super(context, databaseInteractor, progressable);
|
||||
public PgpDecryptVerifyOperation(Context context, KeyRepository keyRepository, Progressable progressable) {
|
||||
super(context, keyRepository, progressable);
|
||||
}
|
||||
|
||||
/** Decrypts and/or verifies data based on parameters of PgpDecryptVerifyInputParcel. */
|
||||
@@ -356,7 +356,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
||||
plainFact = fact;
|
||||
}
|
||||
|
||||
PgpSignatureChecker signatureChecker = new PgpSignatureChecker(mDatabaseInteractor, input.getSenderAddress());
|
||||
PgpSignatureChecker signatureChecker = new PgpSignatureChecker(mKeyRepository, input.getSenderAddress());
|
||||
if (signatureChecker.initializeOnePassSignature(dataChunk, log, indent +1)) {
|
||||
dataChunk = plainFact.nextObject();
|
||||
}
|
||||
@@ -595,7 +595,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
||||
CachedPublicKeyRing cachedPublicKeyRing;
|
||||
try {
|
||||
// get actual keyring object based on master key id
|
||||
cachedPublicKeyRing = mDatabaseInteractor.getCachedPublicKeyRing(
|
||||
cachedPublicKeyRing = mKeyRepository.getCachedPublicKeyRing(
|
||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)
|
||||
);
|
||||
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
|
||||
CanonicalizedSecretKeyRing canonicalizedSecretKeyRing = mDatabaseInteractor
|
||||
CanonicalizedSecretKeyRing canonicalizedSecretKeyRing = mKeyRepository
|
||||
.getCanonicalizedSecretKeyRing(masterKeyId);
|
||||
CanonicalizedSecretKey candidateDecryptionKey = canonicalizedSecretKeyRing.getSecretKey(subKeyId);
|
||||
|
||||
@@ -669,7 +669,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
||||
encryptedDataAsymmetric = encData;
|
||||
decryptionKey = candidateDecryptionKey;
|
||||
|
||||
} catch (PgpKeyNotFoundException | DatabaseReadWriteInteractor.NotFoundException e) {
|
||||
} catch (PgpKeyNotFoundException | KeyWritableRepository.NotFoundException e) {
|
||||
// continue with the next packet in the while loop
|
||||
log.add(LogType.MSG_DC_ASKIP_NO_KEY, indent + 1);
|
||||
continue;
|
||||
@@ -880,7 +880,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
||||
updateProgress(R.string.progress_processing_signature, 60, 100);
|
||||
JcaSkipMarkerPGPObjectFactory pgpFact = new JcaSkipMarkerPGPObjectFactory(aIn);
|
||||
|
||||
PgpSignatureChecker signatureChecker = new PgpSignatureChecker(mDatabaseInteractor, input.getSenderAddress());
|
||||
PgpSignatureChecker signatureChecker = new PgpSignatureChecker(mKeyRepository, input.getSenderAddress());
|
||||
|
||||
Object o = pgpFact.nextObject();
|
||||
if (!signatureChecker.initializeSignature(o, log, indent+1)) {
|
||||
@@ -935,7 +935,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
||||
o = pgpFact.nextObject();
|
||||
}
|
||||
|
||||
PgpSignatureChecker signatureChecker = new PgpSignatureChecker(mDatabaseInteractor, input.getSenderAddress());
|
||||
PgpSignatureChecker signatureChecker = new PgpSignatureChecker(mKeyRepository, input.getSenderAddress());
|
||||
|
||||
if ( ! signatureChecker.initializeSignature(o, log, indent+1)) {
|
||||
log.add(LogType.MSG_DC_ERROR_INVALID_DATA, 0);
|
||||
|
||||
@@ -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.SignEncryptResult;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.provider.DatabaseInteractor;
|
||||
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
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) {
|
||||
super(context, databaseInteractor, progressable, cancelled);
|
||||
public PgpSignEncryptOperation(Context context, KeyRepository keyRepository, Progressable progressable, AtomicBoolean cancelled) {
|
||||
super(context, keyRepository, progressable, cancelled);
|
||||
}
|
||||
|
||||
public PgpSignEncryptOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) {
|
||||
super(context, databaseInteractor, progressable);
|
||||
public PgpSignEncryptOperation(Context context, KeyRepository keyRepository, Progressable progressable) {
|
||||
super(context, keyRepository, progressable);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -224,7 +224,7 @@ public class PgpSignEncryptOperation extends BaseOperation<PgpSignEncryptInputPa
|
||||
long signingSubKeyId = data.getSignatureSubKeyId();
|
||||
|
||||
CanonicalizedSecretKeyRing signingKeyRing =
|
||||
mDatabaseInteractor.getCanonicalizedSecretKeyRing(signingMasterKeyId);
|
||||
mKeyRepository.getCanonicalizedSecretKeyRing(signingMasterKeyId);
|
||||
signingKey = signingKeyRing.getSecretKey(data.getSignatureSubKeyId());
|
||||
|
||||
if (input.getAllowedKeyIds() != null) {
|
||||
@@ -249,7 +249,7 @@ public class PgpSignEncryptOperation extends BaseOperation<PgpSignEncryptInputPa
|
||||
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);
|
||||
}
|
||||
|
||||
switch (mDatabaseInteractor.getCachedPublicKeyRing(signingMasterKeyId).getSecretKeyType(signingSubKeyId)) {
|
||||
switch (mKeyRepository.getCachedPublicKeyRing(signingMasterKeyId).getSecretKeyType(signingSubKeyId)) {
|
||||
case DIVERT_TO_CARD:
|
||||
case PASSPHRASE_EMPTY: {
|
||||
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);
|
||||
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);
|
||||
} catch (PgpGeneralException e) {
|
||||
@@ -338,7 +338,7 @@ public class PgpSignEncryptOperation extends BaseOperation<PgpSignEncryptInputPa
|
||||
// Asymmetric encryption
|
||||
for (long id : data.getEncryptionMasterKeyIds()) {
|
||||
try {
|
||||
CanonicalizedPublicKeyRing keyRing = mDatabaseInteractor.getCanonicalizedPublicKeyRing(
|
||||
CanonicalizedPublicKeyRing keyRing = mKeyRepository.getCanonicalizedPublicKeyRing(
|
||||
KeyRings.buildUnifiedKeyRingUri(id));
|
||||
Set<Long> encryptSubKeyIds = keyRing.getEncryptIds();
|
||||
for (Long subKeyId : encryptSubKeyIds) {
|
||||
@@ -357,7 +357,7 @@ public class PgpSignEncryptOperation extends BaseOperation<PgpSignEncryptInputPa
|
||||
log.add(LogType.MSG_PSE_ERROR_REVOKED_OR_EXPIRED, indent);
|
||||
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);
|
||||
}
|
||||
} catch (DatabaseReadWriteInteractor.NotFoundException e) {
|
||||
} catch (KeyWritableRepository.NotFoundException e) {
|
||||
log.add(LogType.MSG_PSE_KEY_UNKNOWN, indent + 1,
|
||||
KeyFormattingUtils.convertKeyIdToHex(id));
|
||||
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);
|
||||
|
||||
@@ -36,9 +36,9 @@ import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProv
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor;
|
||||
import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
|
||||
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;
|
||||
|
||||
|
||||
@@ -56,12 +56,12 @@ class PgpSignatureChecker {
|
||||
PGPOnePassSignature onePassSignature;
|
||||
PGPSignature signature;
|
||||
|
||||
DatabaseInteractor mDatabaseInteractor;
|
||||
KeyRepository mKeyRepository;
|
||||
|
||||
PgpSignatureChecker(DatabaseInteractor databaseInteractor, String senderAddress) {
|
||||
mDatabaseInteractor = databaseInteractor;
|
||||
PgpSignatureChecker(KeyRepository keyRepository, String senderAddress) {
|
||||
mKeyRepository = keyRepository;
|
||||
|
||||
signatureResultBuilder = new OpenPgpSignatureResultBuilder(databaseInteractor);
|
||||
signatureResultBuilder = new OpenPgpSignatureResultBuilder(keyRepository);
|
||||
signatureResultBuilder.setSenderAddress(senderAddress);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ class PgpSignatureChecker {
|
||||
for (int i = 0; i < sigList.size(); ++i) {
|
||||
try {
|
||||
long sigKeyId = sigList.get(i).getKeyID();
|
||||
CanonicalizedPublicKeyRing signingRing = mDatabaseInteractor.getCanonicalizedPublicKeyRing(
|
||||
CanonicalizedPublicKeyRing signingRing = mKeyRepository.getCanonicalizedPublicKeyRing(
|
||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(sigKeyId)
|
||||
);
|
||||
CanonicalizedPublicKey keyCandidate = signingRing.getPublicKey(sigKeyId);
|
||||
@@ -162,7 +162,7 @@ class PgpSignatureChecker {
|
||||
signingKey = keyCandidate;
|
||||
onePassSignature = sigList.get(i);
|
||||
return;
|
||||
} catch (DatabaseReadWriteInteractor.NotFoundException e) {
|
||||
} catch (KeyWritableRepository.NotFoundException e) {
|
||||
Log.d(Constants.TAG, "key not found, trying next signature...");
|
||||
}
|
||||
}
|
||||
@@ -174,7 +174,7 @@ class PgpSignatureChecker {
|
||||
for (int i = 0; i < sigList.size(); ++i) {
|
||||
try {
|
||||
long sigKeyId = sigList.get(i).getKeyID();
|
||||
CanonicalizedPublicKeyRing signingRing = mDatabaseInteractor.getCanonicalizedPublicKeyRing(
|
||||
CanonicalizedPublicKeyRing signingRing = mKeyRepository.getCanonicalizedPublicKeyRing(
|
||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(sigKeyId)
|
||||
);
|
||||
CanonicalizedPublicKey keyCandidate = signingRing.getPublicKey(sigKeyId);
|
||||
@@ -185,7 +185,7 @@ class PgpSignatureChecker {
|
||||
signingKey = keyCandidate;
|
||||
signature = sigList.get(i);
|
||||
return;
|
||||
} catch (DatabaseReadWriteInteractor.NotFoundException e) {
|
||||
} catch (KeyWritableRepository.NotFoundException e) {
|
||||
Log.d(Constants.TAG, "key not found, trying next signature...");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user