add LocalKeyStorage, don't store public keys larger than 50kb in database
This commit is contained in:
@@ -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 = new DatabaseReadWriteInteractor(context);
|
DatabaseReadWriteInteractor helper = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context);
|
||||||
while(stream.hasNext()) {
|
while(stream.hasNext()) {
|
||||||
UncachedKeyRing ring = stream.next();
|
UncachedKeyRing ring = stream.next();
|
||||||
if (ring.isSecret()) {
|
if (ring.isSecret()) {
|
||||||
|
|||||||
@@ -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 =
|
||||||
new DatabaseReadWriteInteractor(getTargetContext()).getCanonicalizedPublicKeyRing(keyId);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(getTargetContext()).getCanonicalizedPublicKeyRing(keyId);
|
||||||
final Object item = new KeyAdapter.KeyItem(ring);
|
final Object item = new KeyAdapter.KeyItem(ring);
|
||||||
|
|
||||||
return new ViewAction() {
|
return new ViewAction() {
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ public class BackupOperation extends BaseOperation<BackupKeyringParcel> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
arOutStream = new ArmoredOutputStream(outStream);
|
arOutStream = new ArmoredOutputStream(outStream);
|
||||||
byte[] data = mDatabaseInteractor.getPublicKeyRingData(masterKeyId);
|
byte[] data = mDatabaseInteractor.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.getSecretKeyRingData(masterKeyId);
|
byte[] data = mDatabaseInteractor.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);
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import org.sufficientlysecure.keychain.Constants;
|
|||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
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.KeychainContract.KeyRingData;
|
|
||||||
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.DatabaseInteractor.NotFoundException;
|
||||||
@@ -240,7 +239,7 @@ public class CachedPublicKeyRing extends KeyRing {
|
|||||||
|
|
||||||
public byte[] getEncoded() throws PgpKeyNotFoundException {
|
public byte[] getEncoded() throws PgpKeyNotFoundException {
|
||||||
try {
|
try {
|
||||||
return mDatabaseInteractor.getPublicKeyRingData(getMasterKeyId());
|
return mDatabaseInteractor.loadPublicKeyRingData(getMasterKeyId());
|
||||||
} catch(DatabaseReadWriteInteractor.NotFoundException e) {
|
} catch(DatabaseReadWriteInteractor.NotFoundException e) {
|
||||||
throw new PgpKeyNotFoundException(e);
|
throw new PgpKeyNotFoundException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
||||||
@@ -33,15 +36,25 @@ public class DatabaseInteractor {
|
|||||||
public static final int FIELD_TYPE_BLOB = 5;
|
public static final int FIELD_TYPE_BLOB = 5;
|
||||||
|
|
||||||
final ContentResolver mContentResolver;
|
final ContentResolver mContentResolver;
|
||||||
|
final LocalPublicKeyStorage mLocalPublicKeyStorage;
|
||||||
OperationLog mLog;
|
OperationLog mLog;
|
||||||
int mIndent;
|
int mIndent;
|
||||||
|
|
||||||
public DatabaseInteractor(ContentResolver contentResolver) {
|
public static DatabaseInteractor createDatabaseInteractor(Context context) {
|
||||||
this(contentResolver, new OperationLog(), 0);
|
ContentResolver contentResolver = context.getContentResolver();
|
||||||
|
LocalPublicKeyStorage localPublicKeyStorage = LocalPublicKeyStorage.getInstance(context);
|
||||||
|
|
||||||
|
return new DatabaseInteractor(contentResolver, localPublicKeyStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatabaseInteractor(ContentResolver contentResolver, OperationLog log, int indent) {
|
private DatabaseInteractor(ContentResolver contentResolver, LocalPublicKeyStorage localPublicKeyStorage) {
|
||||||
|
this(contentResolver, localPublicKeyStorage, new OperationLog(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
DatabaseInteractor(ContentResolver contentResolver, LocalPublicKeyStorage localPublicKeyStorage,
|
||||||
|
OperationLog log, int indent) {
|
||||||
mContentResolver = contentResolver;
|
mContentResolver = contentResolver;
|
||||||
|
mLocalPublicKeyStorage = localPublicKeyStorage;
|
||||||
mIndent = indent;
|
mIndent = indent;
|
||||||
mLog = log;
|
mLog = log;
|
||||||
}
|
}
|
||||||
@@ -74,6 +87,10 @@ public class DatabaseInteractor {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object getGenericDataOrNull(Uri uri, String column, int type) throws NotFoundException {
|
||||||
|
return getGenericData(uri, new String[]{column}, new int[]{type}, null).get(column);
|
||||||
|
}
|
||||||
|
|
||||||
Object getGenericData(Uri uri, String column, int type, String selection)
|
Object getGenericData(Uri uri, String column, int type, String selection)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
return getGenericData(uri, new String[]{column}, new int[]{type}, selection).get(column);
|
return getGenericData(uri, new String[]{column}, new int[]{type}, selection).get(column);
|
||||||
@@ -156,7 +173,7 @@ public class DatabaseInteractor {
|
|||||||
long masterKeyId = cursor.getLong(0);
|
long masterKeyId = cursor.getLong(0);
|
||||||
int verified = cursor.getInt(1);
|
int verified = cursor.getInt(1);
|
||||||
|
|
||||||
byte[] publicKeyData = getPublicKeyRingData(masterKeyId);
|
byte[] publicKeyData = loadPublicKeyRingData(masterKeyId);
|
||||||
return new CanonicalizedPublicKeyRing(publicKeyData, verified);
|
return new CanonicalizedPublicKeyRing(publicKeyData, verified);
|
||||||
} else {
|
} else {
|
||||||
throw new NotFoundException("Key not found!");
|
throw new NotFoundException("Key not found!");
|
||||||
@@ -184,7 +201,7 @@ public class DatabaseInteractor {
|
|||||||
throw new NotFoundException("No secret key available or unknown public key!");
|
throw new NotFoundException("No secret key available or unknown public key!");
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] secretKeyData = getSecretKeyRingData(masterKeyId);
|
byte[] secretKeyData = loadSecretKeyRingData(masterKeyId);
|
||||||
return new CanonicalizedSecretKeyRing(secretKeyData, verified);
|
return new CanonicalizedSecretKeyRing(secretKeyData, verified);
|
||||||
} else {
|
} else {
|
||||||
throw new NotFoundException("Key not found!");
|
throw new NotFoundException("Key not found!");
|
||||||
@@ -228,7 +245,7 @@ public class DatabaseInteractor {
|
|||||||
|
|
||||||
public String getPublicKeyRingAsArmoredString(long masterKeyId)
|
public String getPublicKeyRingAsArmoredString(long masterKeyId)
|
||||||
throws NotFoundException, IOException, PgpGeneralException {
|
throws NotFoundException, IOException, PgpGeneralException {
|
||||||
byte[] data = getPublicKeyRingData(masterKeyId);
|
byte[] data = loadPublicKeyRingData(masterKeyId);
|
||||||
return getKeyRingAsArmoredString(data);
|
return getKeyRingAsArmoredString(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,14 +253,35 @@ public class DatabaseInteractor {
|
|||||||
return mContentResolver;
|
return mContentResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getPublicKeyRingData(long masterKeyId) throws NotFoundException {
|
public final byte[] loadPublicKeyRingData(long masterKeyId) throws NotFoundException {
|
||||||
return (byte[]) getGenericData(KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId),
|
byte[] data = (byte[]) getGenericDataOrNull(KeyRingData.buildPublicKeyRingUri(masterKeyId),
|
||||||
KeyRingData.KEY_RING_DATA, FIELD_TYPE_BLOB);
|
KeyRingData.KEY_RING_DATA, FIELD_TYPE_BLOB);
|
||||||
|
|
||||||
|
if (data == null) {
|
||||||
|
try {
|
||||||
|
data = mLocalPublicKeyStorage.readPublicKey(masterKeyId);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(Constants.TAG, "Error reading public key from storage!", e);
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data == null) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getSecretKeyRingData(long masterKeyId) throws NotFoundException {
|
public final byte[] loadSecretKeyRingData(long masterKeyId) throws NotFoundException {
|
||||||
return (byte[]) getGenericData(KeychainContract.KeyRingData.buildSecretKeyRingUri(masterKeyId),
|
byte[] data = (byte[]) getGenericDataOrNull(KeychainContract.KeyRingData.buildSecretKeyRingUri(masterKeyId),
|
||||||
KeyRingData.KEY_RING_DATA, FIELD_TYPE_BLOB);
|
KeyRingData.KEY_RING_DATA, FIELD_TYPE_BLOB);
|
||||||
|
|
||||||
|
if (data == null) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NotFoundException extends Exception {
|
public static class NotFoundException extends Exception {
|
||||||
|
|||||||
@@ -19,6 +19,15 @@
|
|||||||
package org.sufficientlysecure.keychain.provider;
|
package org.sufficientlysecure.keychain.provider;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import android.content.ContentProviderOperation;
|
import android.content.ContentProviderOperation;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -68,15 +77,6 @@ import org.sufficientlysecure.keychain.util.ProgressFixedScaler;
|
|||||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||||
import org.sufficientlysecure.keychain.util.Utf8Util;
|
import org.sufficientlysecure.keychain.util.Utf8Util;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains high level methods for database access. Despite its
|
* This class contains high level methods for database access. Despite its
|
||||||
* name, it is not only a helper but actually the main interface for all
|
* name, it is not only a helper but actually the main interface for all
|
||||||
@@ -88,18 +88,26 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* method is called to start a new one specifically.
|
* method is called to start a new one specifically.
|
||||||
*/
|
*/
|
||||||
public class DatabaseReadWriteInteractor extends DatabaseInteractor {
|
public class DatabaseReadWriteInteractor extends DatabaseInteractor {
|
||||||
|
private static final int MAX_CACHED_KEY_SIZE = 1024 * 50;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
public DatabaseReadWriteInteractor(Context context) {
|
public static DatabaseReadWriteInteractor createDatabaseReadWriteInteractor(Context context) {
|
||||||
this(context, new OperationLog(), 0);
|
LocalPublicKeyStorage localPublicKeyStorage = LocalPublicKeyStorage.getInstance(context);
|
||||||
|
|
||||||
|
return new DatabaseReadWriteInteractor(context, localPublicKeyStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatabaseReadWriteInteractor(Context context, OperationLog log) {
|
private DatabaseReadWriteInteractor(Context context, LocalPublicKeyStorage localPublicKeyStorage) {
|
||||||
this(context, log, 0);
|
this(context, localPublicKeyStorage, new OperationLog(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatabaseReadWriteInteractor(Context context, OperationLog log, int indent) {
|
private DatabaseReadWriteInteractor(Context context, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log) {
|
||||||
super(context.getContentResolver(), log, indent);
|
this(context, localPublicKeyStorage, log, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DatabaseReadWriteInteractor(Context context, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log, int indent) {
|
||||||
|
super(context.getContentResolver(), localPublicKeyStorage, log, indent);
|
||||||
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
}
|
}
|
||||||
@@ -122,7 +130,7 @@ public class DatabaseReadWriteInteractor extends DatabaseInteractor {
|
|||||||
try {
|
try {
|
||||||
long masterKeyId = cursor.getLong(0);
|
long masterKeyId = cursor.getLong(0);
|
||||||
int verified = cursor.getInt(2);
|
int verified = cursor.getInt(2);
|
||||||
byte[] blob = getPublicKeyRingData(masterKeyId);
|
byte[] blob = loadPublicKeyRingData(masterKeyId);
|
||||||
if (blob != null) {
|
if (blob != null) {
|
||||||
result.put(masterKeyId, new CanonicalizedPublicKeyRing(blob, verified).getPublicKey());
|
result.put(masterKeyId, new CanonicalizedPublicKeyRing(blob, verified).getPublicKey());
|
||||||
}
|
}
|
||||||
@@ -191,18 +199,11 @@ public class DatabaseReadWriteInteractor extends DatabaseInteractor {
|
|||||||
operations = new ArrayList<>();
|
operations = new ArrayList<>();
|
||||||
|
|
||||||
log(LogType.MSG_IP_INSERT_KEYRING);
|
log(LogType.MSG_IP_INSERT_KEYRING);
|
||||||
{ // insert keyring
|
try {
|
||||||
ContentValues values = new ContentValues();
|
writePublicKeyRing(keyRing, masterKeyId, operations);
|
||||||
values.put(KeyRingData.MASTER_KEY_ID, masterKeyId);
|
} catch (IOException e) {
|
||||||
try {
|
log(LogType.MSG_IP_ENCODE_FAIL);
|
||||||
values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded());
|
return SaveKeyringResult.RESULT_ERROR;
|
||||||
} catch (IOException e) {
|
|
||||||
log(LogType.MSG_IP_ENCODE_FAIL);
|
|
||||||
return SaveKeyringResult.RESULT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uri uri = KeyRingData.buildPublicKeyRingUri(masterKeyId);
|
|
||||||
operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log(LogType.MSG_IP_INSERT_SUBKEYS);
|
log(LogType.MSG_IP_INSERT_SUBKEYS);
|
||||||
@@ -582,6 +583,35 @@ public class DatabaseReadWriteInteractor extends DatabaseInteractor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void writePublicKeyRing(CanonicalizedPublicKeyRing keyRing, long masterKeyId,
|
||||||
|
ArrayList<ContentProviderOperation> operations) throws IOException {
|
||||||
|
byte[] encodedKey = keyRing.getEncoded();
|
||||||
|
mLocalPublicKeyStorage.writePublicKey(masterKeyId, encodedKey);
|
||||||
|
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(KeyRingData.MASTER_KEY_ID, masterKeyId);
|
||||||
|
if (encodedKey.length < MAX_CACHED_KEY_SIZE) {
|
||||||
|
values.put(KeyRingData.KEY_RING_DATA, encodedKey);
|
||||||
|
} else {
|
||||||
|
values.put(KeyRingData.KEY_RING_DATA, (byte[]) null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Uri uri = KeyRingData.buildPublicKeyRingUri(masterKeyId);
|
||||||
|
operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Uri writeSecretKeyRing(CanonicalizedSecretKeyRing keyRing, long masterKeyId) throws IOException {
|
||||||
|
byte[] encodedKey = keyRing.getEncoded();
|
||||||
|
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(KeyRingData.MASTER_KEY_ID, masterKeyId);
|
||||||
|
values.put(KeyRingData.KEY_RING_DATA, encodedKey);
|
||||||
|
|
||||||
|
// insert new version of this keyRing
|
||||||
|
Uri uri = KeyRingData.buildSecretKeyRingUri(masterKeyId);
|
||||||
|
return mContentResolver.insert(uri, values);
|
||||||
|
}
|
||||||
|
|
||||||
private static class UserPacketItem implements Comparable<UserPacketItem> {
|
private static class UserPacketItem implements Comparable<UserPacketItem> {
|
||||||
Integer type;
|
Integer type;
|
||||||
String userId;
|
String userId;
|
||||||
@@ -637,12 +667,8 @@ public class DatabaseReadWriteInteractor extends DatabaseInteractor {
|
|||||||
|
|
||||||
// save secret keyring
|
// save secret keyring
|
||||||
try {
|
try {
|
||||||
ContentValues values = new ContentValues();
|
Uri insertedUri = writeSecretKeyRing(keyRing, masterKeyId);
|
||||||
values.put(KeyRingData.MASTER_KEY_ID, masterKeyId);
|
if (insertedUri == null) {
|
||||||
values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded());
|
|
||||||
// insert new version of this keyRing
|
|
||||||
Uri uri = KeyRingData.buildSecretKeyRingUri(masterKeyId);
|
|
||||||
if (mContentResolver.insert(uri, values) == null) {
|
|
||||||
log(LogType.MSG_IS_DB_EXCEPTION);
|
log(LogType.MSG_IS_DB_EXCEPTION);
|
||||||
return SaveKeyringResult.RESULT_ERROR;
|
return SaveKeyringResult.RESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package org.sufficientlysecure.keychain.provider;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import okhttp3.internal.Util;
|
||||||
|
|
||||||
|
|
||||||
|
class LocalPublicKeyStorage {
|
||||||
|
private static final String FORMAT_STR_PUBLIC_KEY = "0x%016x.pub";
|
||||||
|
private static final String PUBLIC_KEYS_DIR_NAME = "public_keys";
|
||||||
|
|
||||||
|
|
||||||
|
private final File localPublicKeysDir;
|
||||||
|
|
||||||
|
|
||||||
|
public static LocalPublicKeyStorage getInstance(Context context) {
|
||||||
|
File localPublicKeysDir = new File(context.getFilesDir(), PUBLIC_KEYS_DIR_NAME);
|
||||||
|
return new LocalPublicKeyStorage(localPublicKeysDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LocalPublicKeyStorage(File localPublicKeysDir) {
|
||||||
|
this.localPublicKeysDir = localPublicKeysDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
private File getPublicKeyFile(long masterKeyId) throws IOException {
|
||||||
|
if (!localPublicKeysDir.exists()) {
|
||||||
|
localPublicKeysDir.mkdir();
|
||||||
|
}
|
||||||
|
if (!localPublicKeysDir.isDirectory()) {
|
||||||
|
throw new IOException("Failed creating public key directory!");
|
||||||
|
}
|
||||||
|
|
||||||
|
String keyFilename = String.format(FORMAT_STR_PUBLIC_KEY, masterKeyId);
|
||||||
|
return new File(localPublicKeysDir, keyFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void writePublicKey(long masterKeyId, byte[] encoded) throws IOException {
|
||||||
|
File publicKeyFile = getPublicKeyFile(masterKeyId);
|
||||||
|
|
||||||
|
FileOutputStream fileOutputStream = new FileOutputStream(publicKeyFile);
|
||||||
|
try {
|
||||||
|
fileOutputStream.write(encoded);
|
||||||
|
} finally {
|
||||||
|
Util.closeQuietly(fileOutputStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] readPublicKey(long masterKeyId) throws IOException {
|
||||||
|
File publicKeyFile = getPublicKeyFile(masterKeyId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileInputStream fileInputStream = new FileInputStream(publicKeyFile);
|
||||||
|
return readIntoByteArray(fileInputStream);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] readIntoByteArray(FileInputStream fileInputStream) throws IOException {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
byte[] buf = new byte[128];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = fileInputStream.read(buf)) != -1) {
|
||||||
|
baos.write(buf, 0, bytesRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
return baos.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 = new DatabaseInteractor(getContentResolver());
|
mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(this);
|
||||||
mApiDao = new ApiDataAccessObject(this);
|
mApiDao = new ApiDataAccessObject(this);
|
||||||
|
|
||||||
mApiPendingIntentFactory = new ApiPendingIntentFactory(getBaseContext());
|
mApiPendingIntentFactory = new ApiPendingIntentFactory(getBaseContext());
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ class RequestKeyPermissionPresenter {
|
|||||||
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 = new DatabaseInteractor(context.getContentResolver());
|
DatabaseInteractor databaseInteractor =
|
||||||
|
DatabaseInteractor.createDatabaseInteractor(context);
|
||||||
|
|
||||||
return new RequestKeyPermissionPresenter(context, apiDataAccessObject, apiPermissionHelper, packageManager,
|
return new RequestKeyPermissionPresenter(context, apiDataAccessObject, apiPermissionHelper, packageManager,
|
||||||
databaseInteractor);
|
databaseInteractor);
|
||||||
|
|||||||
@@ -111,7 +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 = new DatabaseReadWriteInteractor(outerThis);
|
DatabaseReadWriteInteractor databaseInteractor =
|
||||||
|
DatabaseReadWriteInteractor.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) {
|
||||||
|
|||||||
@@ -321,7 +321,8 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
private ImportKeyResult directUpdate(Context context, ArrayList<ParcelableKeyRing> keyList,
|
private ImportKeyResult directUpdate(Context context, ArrayList<ParcelableKeyRing> keyList,
|
||||||
CryptoInputParcel cryptoInputParcel) {
|
CryptoInputParcel cryptoInputParcel) {
|
||||||
Log.d(Constants.TAG, "Starting normal update");
|
Log.d(Constants.TAG, "Starting normal update");
|
||||||
ImportOperation importOp = new ImportOperation(context, new DatabaseReadWriteInteractor(context), null);
|
ImportOperation importOp = new ImportOperation(context,
|
||||||
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context), null);
|
||||||
return importOp.execute(
|
return importOp.execute(
|
||||||
new ImportKeyringParcel(keyList,
|
new ImportKeyringParcel(keyList,
|
||||||
Preferences.getPreferences(context).getPreferredKeyserver()),
|
Preferences.getPreferences(context).getPreferredKeyserver()),
|
||||||
@@ -381,7 +382,7 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
new OperationResult.OperationLog());
|
new OperationResult.OperationLog());
|
||||||
}
|
}
|
||||||
ImportKeyResult result =
|
ImportKeyResult result =
|
||||||
new ImportOperation(context, new DatabaseReadWriteInteractor(context), null, mCancelled)
|
new ImportOperation(context, DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context), null, mCancelled)
|
||||||
.execute(
|
.execute(
|
||||||
new ImportKeyringParcel(
|
new ImportKeyringParcel(
|
||||||
keyWrapper,
|
keyWrapper,
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ 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 = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(masterKeyId);
|
CachedPublicKeyRing keyRing = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId);
|
||||||
SecretKeyType keyType = keyRing.getSecretKeyType(subKeyId);
|
SecretKeyType keyType = keyRing.getSecretKeyType(subKeyId);
|
||||||
|
|
||||||
switch (keyType) {
|
switch (keyType) {
|
||||||
|
|||||||
@@ -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 = new DatabaseInteractor(getActivity().getContentResolver())
|
keyId = DatabaseInteractor.createDatabaseInteractor(getContext())
|
||||||
.getCachedPublicKeyRing(dataUri)
|
.getCachedPublicKeyRing(dataUri)
|
||||||
.extractOrGetMasterKeyId();
|
.extractOrGetMasterKeyId();
|
||||||
} catch (PgpKeyNotFoundException e) {
|
} catch (PgpKeyNotFoundException e) {
|
||||||
|
|||||||
@@ -69,7 +69,8 @@ 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 = (new DatabaseInteractor(getActivity().getContentResolver()))
|
CachedPublicKeyRing key = (DatabaseInteractor
|
||||||
|
.createDatabaseInteractor(getContext()))
|
||||||
.getCachedPublicKeyRing(certifyKeyId);
|
.getCachedPublicKeyRing(certifyKeyId);
|
||||||
if (key.canCertify()) {
|
if (key.canCertify()) {
|
||||||
mCertifyKeySpinner.setPreSelectedKeyId(certifyKeyId);
|
mCertifyKeySpinner.setPreSelectedKeyId(certifyKeyId);
|
||||||
|
|||||||
@@ -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 = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(masterKeyId);
|
CachedPublicKeyRing ring = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId);
|
||||||
ring.getMasterKeyId();
|
ring.getMasterKeyId();
|
||||||
|
|
||||||
Intent intent = new Intent(this, ViewKeyActivity.class);
|
Intent intent = new Intent(this, ViewKeyActivity.class);
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ 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.DatabaseInteractor;
|
||||||
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor;
|
|
||||||
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;
|
||||||
@@ -412,7 +411,7 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
CreateKeyActivity activity = (CreateKeyActivity) getActivity();
|
CreateKeyActivity activity = (CreateKeyActivity) getActivity();
|
||||||
|
|
||||||
final SaveKeyringParcel changeKeyringParcel;
|
final SaveKeyringParcel changeKeyringParcel;
|
||||||
CachedPublicKeyRing key = (new DatabaseInteractor(activity.getContentResolver()))
|
CachedPublicKeyRing key = (DatabaseInteractor.createDatabaseInteractor(getContext()))
|
||||||
.getCachedPublicKeyRing(saveKeyResult.mMasterKeyId);
|
.getCachedPublicKeyRing(saveKeyResult.mMasterKeyId);
|
||||||
try {
|
try {
|
||||||
changeKeyringParcel = new SaveKeyringParcel(key.getMasterKeyId(), key.getFingerprint());
|
changeKeyringParcel = new SaveKeyringParcel(key.getMasterKeyId(), key.getFingerprint());
|
||||||
|
|||||||
@@ -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 = new DatabaseInteractor(getActivity().getContentResolver()).getCachedPublicKeyRing(
|
long masterKeyId = DatabaseInteractor.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(
|
||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId)
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId)
|
||||||
).getMasterKeyId();
|
).getMasterKeyId();
|
||||||
viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId));
|
viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId));
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ 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 = new DatabaseInteractor(getContentResolver()).getUnifiedData(
|
HashMap<String, Object> data = DatabaseInteractor.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
|
||||||
@@ -269,7 +269,8 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
|
|||||||
long masterKeyId = masterKeyIds[0];
|
long masterKeyId = masterKeyIds[0];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HashMap<String, Object> data = new DatabaseInteractor(activity.getContentResolver()).getUnifiedData(
|
HashMap<String, Object> data = DatabaseInteractor.createDatabaseInteractor(getContext())
|
||||||
|
.getUnifiedData(
|
||||||
masterKeyId, new String[]{
|
masterKeyId, new String[]{
|
||||||
KeychainContract.KeyRings.NAME,
|
KeychainContract.KeyRings.NAME,
|
||||||
KeychainContract.KeyRings.HAS_ANY_SECRET
|
KeychainContract.KeyRings.HAS_ANY_SECRET
|
||||||
|
|||||||
@@ -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 =
|
||||||
new DatabaseInteractor(getActivity().getContentResolver()).getCachedPublicKeyRing(secretUri);
|
DatabaseInteractor.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
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ 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.DatabaseInteractor;
|
||||||
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor;
|
|
||||||
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.DatabaseInteractor.NotFoundException;
|
||||||
@@ -204,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 =
|
||||||
new DatabaseInteractor(getActivity().getContentResolver()).getCachedPublicKeyRing(secretUri);
|
DatabaseInteractor.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
|
||||||
|
|||||||
@@ -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 = new DatabaseInteractor(getActivity().getContentResolver());
|
mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(getContext());
|
||||||
|
|
||||||
// preselect keys given, from state or arguments
|
// preselect keys given, from state or arguments
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
|
|||||||
@@ -486,7 +486,8 @@ public class KeyListFragment extends RecyclerFragment<KeySectionedListAdapter>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseInteractor databaseInteractor = new DatabaseInteractor(activity.getContentResolver());
|
DatabaseInteractor databaseInteractor =
|
||||||
|
DatabaseInteractor.createDatabaseInteractor(getContext());
|
||||||
Cursor cursor = databaseInteractor.getContentResolver().query(
|
Cursor cursor = databaseInteractor.getContentResolver().query(
|
||||||
KeyRings.buildUnifiedKeyRingsUri(), new String[]{
|
KeyRings.buildUnifiedKeyRingsUri(), new String[]{
|
||||||
KeyRings.FINGERPRINT
|
KeyRings.FINGERPRINT
|
||||||
|
|||||||
@@ -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 =
|
||||||
new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(requiredInput.getMasterKeyId());
|
DatabaseInteractor.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,7 +231,8 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
try {
|
try {
|
||||||
long subKeyId = mRequiredInput.getSubKeyId();
|
long subKeyId = mRequiredInput.getSubKeyId();
|
||||||
|
|
||||||
DatabaseInteractor helper = new DatabaseInteractor(activity.getContentResolver());
|
DatabaseInteractor helper =
|
||||||
|
DatabaseInteractor.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
|
||||||
@@ -457,7 +458,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
|
|
||||||
Long subKeyId = mRequiredInput.getSubKeyId();
|
Long subKeyId = mRequiredInput.getSubKeyId();
|
||||||
CanonicalizedSecretKeyRing secretKeyRing =
|
CanonicalizedSecretKeyRing secretKeyRing =
|
||||||
new DatabaseInteractor(getActivity().getContentResolver()).getCanonicalizedSecretKeyRing(
|
DatabaseInteractor.createDatabaseInteractor(getContext()).getCanonicalizedSecretKeyRing(
|
||||||
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
|
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
|
||||||
CanonicalizedSecretKey secretKeyToUnlock =
|
CanonicalizedSecretKey secretKeyToUnlock =
|
||||||
secretKeyRing.getSecretKey(subKeyId);
|
secretKeyRing.getSecretKey(subKeyId);
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ 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.DatabaseReadWriteInteractor;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
|
||||||
import org.sufficientlysecure.keychain.provider.DatabaseInteractor;
|
import org.sufficientlysecure.keychain.provider.DatabaseInteractor;
|
||||||
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;
|
||||||
@@ -76,7 +74,7 @@ public class QrCodeViewActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
DatabaseInteractor databaseInteractor = new DatabaseInteractor(getContentResolver());
|
DatabaseInteractor databaseInteractor = DatabaseInteractor.createDatabaseInteractor(this);
|
||||||
try {
|
try {
|
||||||
byte[] blob = databaseInteractor.getCachedPublicKeyRing(dataUri).getFingerprint();
|
byte[] blob = databaseInteractor.getCachedPublicKeyRing(dataUri).getFingerprint();
|
||||||
if (blob == null) {
|
if (blob == null) {
|
||||||
|
|||||||
@@ -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 = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(uri).getEncoded();
|
byte[] keyBlob = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(uri).getEncoded();
|
||||||
|
|
||||||
Intent slingerIntent = new Intent(this, ExchangeActivity.class);
|
Intent slingerIntent = new Intent(this, ExchangeActivity.class);
|
||||||
|
|
||||||
|
|||||||
@@ -193,7 +193,8 @@ 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 = new DatabaseInteractor(getContentResolver());
|
DatabaseInteractor databaseInteractor =
|
||||||
|
DatabaseInteractor.createDatabaseInteractor(this);
|
||||||
CanonicalizedPublicKeyRing publicKeyRing;
|
CanonicalizedPublicKeyRing publicKeyRing;
|
||||||
try {
|
try {
|
||||||
publicKeyRing = databaseInteractor.getCanonicalizedPublicKeyRing(
|
publicKeyRing = databaseInteractor.getCanonicalizedPublicKeyRing(
|
||||||
@@ -232,7 +233,8 @@ 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 = new DatabaseInteractor(getContentResolver());
|
DatabaseInteractor databaseInteractor =
|
||||||
|
DatabaseInteractor.createDatabaseInteractor(this);
|
||||||
CanonicalizedSecretKeyRing secretKeyRing;
|
CanonicalizedSecretKeyRing secretKeyRing;
|
||||||
try {
|
try {
|
||||||
secretKeyRing = databaseInteractor.getCanonicalizedSecretKeyRing(
|
secretKeyRing = databaseInteractor.getCanonicalizedSecretKeyRing(
|
||||||
|
|||||||
@@ -184,7 +184,8 @@ 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 = new DatabaseInteractor(ViewCertActivity.this.getContentResolver());
|
DatabaseInteractor databaseInteractor =
|
||||||
|
DatabaseInteractor.createDatabaseInteractor(ViewCertActivity.this);
|
||||||
long signerMasterKeyId = databaseInteractor.getCachedPublicKeyRing(
|
long signerMasterKeyId = databaseInteractor.getCachedPublicKeyRing(
|
||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId();
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId();
|
||||||
viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId));
|
viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId));
|
||||||
|
|||||||
@@ -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 = new DatabaseInteractor(getContentResolver());
|
mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(this);
|
||||||
mImportOpHelper = new CryptoOperationHelper<>(1, this, this, null);
|
mImportOpHelper = new CryptoOperationHelper<>(1, this, this, null);
|
||||||
|
|
||||||
setTitle(null);
|
setTitle(null);
|
||||||
@@ -741,7 +741,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
long keyId = new DatabaseInteractor(getContentResolver())
|
long keyId = DatabaseInteractor.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 = new DatabaseInteractor(getContentResolver())
|
keyId = DatabaseInteractor.createDatabaseInteractor(this)
|
||||||
.getCachedPublicKeyRing(dataUri)
|
.getCachedPublicKeyRing(dataUri)
|
||||||
.extractOrGetMasterKeyId();
|
.extractOrGetMasterKeyId();
|
||||||
} catch (PgpKeyNotFoundException e) {
|
} catch (PgpKeyNotFoundException e) {
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public class ViewKeyAdvActivity extends BaseActivity implements
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mDatabaseInteractor = new DatabaseInteractor(getContentResolver());
|
mDatabaseInteractor = DatabaseInteractor.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);
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ 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 = new DatabaseInteractor(contentResolver);
|
DatabaseInteractor databaseInteractor = DatabaseInteractor.createDatabaseInteractor(getContext());
|
||||||
mNfcHelper = new NfcHelper(getActivity(), databaseInteractor);
|
mNfcHelper = new NfcHelper(getActivity(), databaseInteractor);
|
||||||
|
|
||||||
mFingerprintView = (TextView) view.findViewById(R.id.view_key_fingerprint);
|
mFingerprintView = (TextView) view.findViewById(R.id.view_key_fingerprint);
|
||||||
@@ -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 = new DatabaseInteractor(getActivity().getContentResolver())
|
keyId = DatabaseInteractor.createDatabaseInteractor(getContext())
|
||||||
.getCachedPublicKeyRing(dataUri)
|
.getCachedPublicKeyRing(dataUri)
|
||||||
.extractOrGetMasterKeyId();
|
.extractOrGetMasterKeyId();
|
||||||
} catch (PgpKeyNotFoundException e) {
|
} catch (PgpKeyNotFoundException e) {
|
||||||
@@ -218,7 +218,8 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
|
|||||||
if (activity == null || mFingerprint == null) {
|
if (activity == null || mFingerprint == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DatabaseInteractor databaseInteractor = new DatabaseInteractor(activity.getContentResolver());
|
DatabaseInteractor databaseInteractor =
|
||||||
|
DatabaseInteractor.createDatabaseInteractor(getContext());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
long masterKeyId = databaseInteractor.getCachedPublicKeyRing(mDataUri).extractOrGetMasterKeyId();
|
long masterKeyId = databaseInteractor.getCachedPublicKeyRing(mDataUri).extractOrGetMasterKeyId();
|
||||||
@@ -459,7 +460,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
|
|||||||
private void uploadToKeyserver() {
|
private void uploadToKeyserver() {
|
||||||
long keyId;
|
long keyId;
|
||||||
try {
|
try {
|
||||||
keyId = new DatabaseInteractor(getActivity().getContentResolver())
|
keyId = DatabaseInteractor.createDatabaseInteractor(getContext())
|
||||||
.getCachedPublicKeyRing(mDataUri)
|
.getCachedPublicKeyRing(mDataUri)
|
||||||
.extractOrGetMasterKeyId();
|
.extractOrGetMasterKeyId();
|
||||||
} catch (PgpKeyNotFoundException e) {
|
} catch (PgpKeyNotFoundException e) {
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
mListener = listener;
|
mListener = listener;
|
||||||
mNonInteractive = nonInteractive;
|
mNonInteractive = nonInteractive;
|
||||||
|
|
||||||
mDatabaseInteractor = new DatabaseInteractor(activity.getContentResolver());
|
mDatabaseInteractor = DatabaseInteractor.createDatabaseInteractor(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setData(List<ImportKeysListEntry> data) {
|
public void setData(List<ImportKeysListEntry> data) {
|
||||||
|
|||||||
@@ -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 = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(
|
CachedPublicKeyRing ring = DatabaseInteractor.createDatabaseInteractor(this).getCachedPublicKeyRing(
|
||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
|
||||||
long masterKeyId = ring.getMasterKeyId();
|
long masterKeyId = ring.getMasterKeyId();
|
||||||
|
|
||||||
|
|||||||
@@ -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 = new DatabaseInteractor(getContentResolver()).getCachedPublicKeyRing(uri);
|
CachedPublicKeyRing ring = DatabaseInteractor.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();
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ public class NfcHelper {
|
|||||||
try {
|
try {
|
||||||
long masterKeyId = mDatabaseInteractor.getCachedPublicKeyRing(dataUri)
|
long masterKeyId = mDatabaseInteractor.getCachedPublicKeyRing(dataUri)
|
||||||
.extractOrGetMasterKeyId();
|
.extractOrGetMasterKeyId();
|
||||||
mNfcKeyringBytes = mDatabaseInteractor.getPublicKeyRingData(masterKeyId);
|
mNfcKeyringBytes = mDatabaseInteractor.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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ public class ParcelableFileCache<E extends Parcelable> {
|
|||||||
mFilename = filename;
|
mFilename = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean cacheFileExists(Context context, String filename) {
|
||||||
|
return new File(context.getCacheDir(), filename).exists();
|
||||||
|
}
|
||||||
|
|
||||||
public void writeCache(int numEntries, Iterator<E> it) throws IOException {
|
public void writeCache(int numEntries, Iterator<E> it) throws IOException {
|
||||||
DataOutputStream oos = getOutputStream();
|
DataOutputStream oos = getOutputStream();
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,8 @@ public class BackupOperationTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
DatabaseReadWriteInteractor databaseInteractor =
|
||||||
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
||||||
|
|
||||||
// don't log verbosely here, we're not here to test imports
|
// don't log verbosely here, we're not here to test imports
|
||||||
ShadowLog.stream = oldShadowStream;
|
ShadowLog.stream = oldShadowStream;
|
||||||
@@ -150,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
// make sure there is a local cert (so the later checks that there are none are meaningful)
|
// 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));
|
||||||
@@ -249,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.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);
|
||||||
@@ -306,7 +307,7 @@ public class BackupOperationTest {
|
|||||||
|
|
||||||
{ // export encrypted
|
{ // export encrypted
|
||||||
BackupOperation op = new BackupOperation(spyApplication,
|
BackupOperation op = new BackupOperation(spyApplication,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.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);
|
||||||
@@ -324,7 +325,7 @@ public class BackupOperationTest {
|
|||||||
|
|
||||||
{
|
{
|
||||||
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(outStream.toByteArray());
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(outStream.toByteArray());
|
||||||
input.setAllowSymmetricDecryption(true);
|
input.setAllowSymmetricDecryption(true);
|
||||||
|
|||||||
@@ -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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
op.execute(new BenchmarkInputParcel(), null);
|
op.execute(new BenchmarkInputParcel(), null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,8 @@ public class CertifyOperationTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
DatabaseReadWriteInteractor databaseInteractor =
|
||||||
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
||||||
|
|
||||||
// don't log verbosely here, we're not here to test imports
|
// don't log verbosely here, we're not here to test imports
|
||||||
ShadowLog.stream = oldShadowStream;
|
ShadowLog.stream = oldShadowStream;
|
||||||
@@ -132,7 +133,7 @@ public class CertifyOperationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testSelfCertifyFlag() throws Exception {
|
public void testSelfCertifyFlag() throws Exception {
|
||||||
|
|
||||||
CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.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!
|
||||||
@@ -143,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
|
||||||
|
|
||||||
{
|
{
|
||||||
CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
||||||
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
|
.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());
|
||||||
@@ -160,7 +161,7 @@ public class CertifyOperationTest {
|
|||||||
Assert.assertTrue("certification must succeed", result.success());
|
Assert.assertTrue("certification must succeed", result.success());
|
||||||
|
|
||||||
{
|
{
|
||||||
CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.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());
|
||||||
@@ -171,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
|
||||||
|
|
||||||
{
|
{
|
||||||
CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
||||||
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
|
.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());
|
||||||
@@ -188,7 +189,7 @@ public class CertifyOperationTest {
|
|||||||
Assert.assertTrue("certification must succeed", result.success());
|
Assert.assertTrue("certification must succeed", result.success());
|
||||||
|
|
||||||
{
|
{
|
||||||
CanonicalizedPublicKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
CanonicalizedPublicKeyRing ring = DatabaseReadWriteInteractor.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());
|
||||||
@@ -200,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
|
DatabaseReadWriteInteractor.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(),
|
||||||
@@ -217,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
|
||||||
|
|
||||||
{
|
{
|
||||||
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ public class PromoteKeyOperationTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
DatabaseReadWriteInteractor databaseInteractor =
|
||||||
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
||||||
|
|
||||||
// don't log verbosely here, we're not here to test imports
|
// don't log verbosely here, we're not here to test imports
|
||||||
ShadowLog.stream = oldShadowStream;
|
ShadowLog.stream = oldShadowStream;
|
||||||
@@ -104,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
|
DatabaseReadWriteInteractor.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 = new DatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
CachedPublicKeyRing ring = DatabaseReadWriteInteractor.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());
|
||||||
|
|
||||||
@@ -128,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
|
||||||
|
|
||||||
byte[] aid = Hex.decode("D2760001240102000000012345670000");
|
byte[] aid = Hex.decode("D2760001240102000000012345670000");
|
||||||
|
|
||||||
@@ -137,7 +138,7 @@ public class PromoteKeyOperationTest {
|
|||||||
Assert.assertTrue("promotion must succeed", result.success());
|
Assert.assertTrue("promotion must succeed", result.success());
|
||||||
|
|
||||||
{
|
{
|
||||||
CanonicalizedSecretKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
CanonicalizedSecretKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
||||||
.getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId());
|
.getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId());
|
||||||
|
|
||||||
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
|
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
|
||||||
@@ -153,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null, null);
|
||||||
|
|
||||||
byte[] aid = Hex.decode("D2760001240102000000012345670000");
|
byte[] aid = Hex.decode("D2760001240102000000012345670000");
|
||||||
|
|
||||||
@@ -167,7 +168,7 @@ public class PromoteKeyOperationTest {
|
|||||||
Assert.assertTrue("promotion must succeed", result.success());
|
Assert.assertTrue("promotion must succeed", result.success());
|
||||||
|
|
||||||
{
|
{
|
||||||
CanonicalizedSecretKeyRing ring = new DatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
CanonicalizedSecretKeyRing ring = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
||||||
.getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId());
|
.getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId());
|
||||||
|
|
||||||
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
|
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
|
||||||
|
|||||||
@@ -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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.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());
|
||||||
|
|||||||
@@ -149,7 +149,8 @@ public class PgpEncryptDecryptTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
DatabaseReadWriteInteractor databaseInteractor =
|
||||||
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
||||||
|
|
||||||
// don't log verbosely here, we're not here to test imports
|
// don't log verbosely here, we're not here to test imports
|
||||||
ShadowLog.stream = oldShadowStream;
|
ShadowLog.stream = oldShadowStream;
|
||||||
@@ -172,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
@@ -197,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.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(
|
||||||
@@ -227,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.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,
|
||||||
@@ -249,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.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,
|
||||||
@@ -270,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.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,
|
||||||
@@ -297,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
@@ -353,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
@@ -415,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
@@ -472,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
@@ -575,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
@@ -626,11 +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 = new DatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
DatabaseReadWriteInteractor databaseInteractor =
|
||||||
|
DatabaseReadWriteInteractor.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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.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));
|
||||||
|
|
||||||
@@ -648,11 +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 = new DatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
DatabaseReadWriteInteractor databaseInteractor =
|
||||||
|
DatabaseReadWriteInteractor.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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.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));
|
||||||
|
|
||||||
@@ -675,7 +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 = new DatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
DatabaseReadWriteInteractor databaseInteractor =
|
||||||
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
||||||
databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler());
|
databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -685,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
@@ -730,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
@@ -824,7 +828,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
{ // decryption with passphrase cached should succeed for the other key if first is gone
|
{ // decryption with passphrase cached should succeed for the other key if first is gone
|
||||||
|
|
||||||
// delete first key from database
|
// delete first key from database
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete(
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete(
|
||||||
KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null
|
KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -859,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
@@ -907,7 +911,7 @@ public class PgpEncryptDecryptTest {
|
|||||||
{ // decryption with passphrase cached should succeed for the other key if first is gone
|
{ // decryption with passphrase cached should succeed for the other key if first is gone
|
||||||
|
|
||||||
// delete first key from database
|
// delete first key from database
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete(
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).getContentResolver().delete(
|
||||||
KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null
|
KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -946,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
@@ -1018,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null);
|
||||||
|
|
||||||
InputData data = new InputData(in, in.available());
|
InputData data = new InputData(in, in.available());
|
||||||
|
|
||||||
@@ -1069,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,
|
||||||
new DatabaseReadWriteInteractor(RuntimeEnvironment.application), null) {
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application), null) {
|
||||||
@Override
|
@Override
|
||||||
public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId)
|
public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId)
|
||||||
throws NoSecretKeyException {
|
throws NoSecretKeyException {
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ import java.util.Iterator;
|
|||||||
@RunWith(KeychainTestRunner.class)
|
@RunWith(KeychainTestRunner.class)
|
||||||
public class DatabaseInteractorSaveTest {
|
public class DatabaseInteractorSaveTest {
|
||||||
|
|
||||||
DatabaseReadWriteInteractor mDatabaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
DatabaseReadWriteInteractor mDatabaseInteractor =
|
||||||
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpOnce() throws Exception {
|
public static void setUpOnce() throws Exception {
|
||||||
@@ -61,17 +62,17 @@ public class DatabaseInteractorSaveTest {
|
|||||||
SaveKeyringResult result;
|
SaveKeyringResult result;
|
||||||
|
|
||||||
// insert both keys, second should fail
|
// insert both keys, second should fail
|
||||||
result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first);
|
result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first);
|
||||||
Assert.assertTrue("first keyring import should succeed", result.success());
|
Assert.assertTrue("first keyring import should succeed", result.success());
|
||||||
result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second);
|
result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second);
|
||||||
Assert.assertFalse("second keyring import should fail", result.success());
|
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 = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second);
|
result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(second);
|
||||||
Assert.assertTrue("first keyring import should succeed", result.success());
|
Assert.assertTrue("first keyring import should succeed", result.success());
|
||||||
result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first);
|
result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(first);
|
||||||
Assert.assertFalse("second keyring import should fail", result.success());
|
Assert.assertFalse("second keyring import should fail", result.success());
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -90,13 +91,15 @@ 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 = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler());
|
result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
||||||
|
.saveSecretKeyRing(seckey, new ProgressScaler());
|
||||||
Assert.assertFalse("secret keyring import before pubring import should fail", result.success());
|
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 = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(pubkey);
|
result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application).savePublicKeyRing(pubkey);
|
||||||
Assert.assertTrue("public keyring import should succeed", result.success());
|
Assert.assertTrue("public keyring import should succeed", result.success());
|
||||||
result = new DatabaseReadWriteInteractor(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler());
|
result = DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application)
|
||||||
|
.saveSecretKeyRing(seckey, new ProgressScaler());
|
||||||
Assert.assertTrue("secret keyring import after pubring import should succeed", result.success());
|
Assert.assertTrue("secret keyring import after pubring import should succeed", result.success());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ public class KeychainExternalProviderTest {
|
|||||||
static final long KEY_ID_PUBLIC = 0x9A282CE2AB44A382L;
|
static final long KEY_ID_PUBLIC = 0x9A282CE2AB44A382L;
|
||||||
|
|
||||||
|
|
||||||
DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
DatabaseReadWriteInteractor databaseInteractor =
|
||||||
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(RuntimeEnvironment.application);
|
||||||
ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver();
|
ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver();
|
||||||
ApiPermissionHelper apiPermissionHelper;
|
ApiPermissionHelper apiPermissionHelper;
|
||||||
ApiDataAccessObject apiDao;
|
ApiDataAccessObject apiDao;
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ public class KeyringTestingHelper {
|
|||||||
|
|
||||||
public boolean addKeyring(Collection<String> blobFiles) throws Exception {
|
public boolean addKeyring(Collection<String> blobFiles) throws Exception {
|
||||||
|
|
||||||
DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(context);
|
DatabaseReadWriteInteractor databaseInteractor =
|
||||||
|
DatabaseReadWriteInteractor.createDatabaseReadWriteInteractor(context);
|
||||||
|
|
||||||
byte[] data = TestDataUtil.readAllFully(blobFiles);
|
byte[] data = TestDataUtil.readAllFully(blobFiles);
|
||||||
UncachedKeyRing ring = UncachedKeyRing.decodeFromData(data);
|
UncachedKeyRing ring = UncachedKeyRing.decodeFromData(data);
|
||||||
|
|||||||
Reference in New Issue
Block a user