mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-19 20:31:52 -05:00
final code style changes
This commit is contained in:
parent
b1476a7429
commit
2d0817bd74
@ -37,8 +37,9 @@ import android.os.Handler;
|
|||||||
* </code>
|
* </code>
|
||||||
*/
|
*/
|
||||||
public class DialogFragmentWorkaround {
|
public class DialogFragmentWorkaround {
|
||||||
public static final SDKLevel17Interface INTERFACE = ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) ? new SDKLevel17Impl()
|
public static final SDKLevel17Interface INTERFACE =
|
||||||
: new SDKLevelPriorLevel17Impl());
|
((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) ? new SDKLevel17Impl()
|
||||||
|
: new SDKLevelPriorLevel17Impl());
|
||||||
|
|
||||||
private static final int RUNNABLE_DELAY = 300;
|
private static final int RUNNABLE_DELAY = 300;
|
||||||
|
|
||||||
|
@ -288,9 +288,11 @@ public class PgpDecryptVerify {
|
|||||||
// if no passphrase was explicitly set try to get it from the cache service
|
// if no passphrase was explicitly set try to get it from the cache service
|
||||||
if (mPassphrase == null) {
|
if (mPassphrase == null) {
|
||||||
// returns "" if key has no passphrase
|
// returns "" if key has no passphrase
|
||||||
mPassphrase = PassphraseCacheService.getCachedPassphrase(mContext, encData.getKeyID());
|
mPassphrase =
|
||||||
|
PassphraseCacheService.getCachedPassphrase(mContext, encData.getKeyID());
|
||||||
|
|
||||||
// if passphrase was not cached, return here indicating that a passphrase is missing!
|
// if passphrase was not cached, return here
|
||||||
|
// indicating that a passphrase is missing!
|
||||||
if (mPassphrase == null) {
|
if (mPassphrase == null) {
|
||||||
returnData.setKeyPassphraseNeeded(true);
|
returnData.setKeyPassphraseNeeded(true);
|
||||||
return returnData;
|
return returnData;
|
||||||
@ -384,7 +386,8 @@ public class PgpDecryptVerify {
|
|||||||
signatureResult.setKeyId(signatureKeyId);
|
signatureResult.setKeyId(signatureKeyId);
|
||||||
|
|
||||||
if (signature != null) {
|
if (signature != null) {
|
||||||
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider = new JcaPGPContentVerifierBuilderProvider()
|
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider =
|
||||||
|
new JcaPGPContentVerifierBuilderProvider()
|
||||||
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
|
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
|
||||||
|
|
||||||
signature.init(contentVerifierBuilderProvider, signatureKey);
|
signature.init(contentVerifierBuilderProvider, signatureKey);
|
||||||
@ -613,7 +616,8 @@ public class PgpDecryptVerify {
|
|||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean verifyKeyBinding(Context context, PGPSignature signature, PGPPublicKey signatureKey) {
|
private static boolean verifyKeyBinding(Context context,
|
||||||
|
PGPSignature signature, PGPPublicKey signatureKey) {
|
||||||
long signatureKeyId = signature.getKeyID();
|
long signatureKeyId = signature.getKeyID();
|
||||||
boolean validKeyBinding = false;
|
boolean validKeyBinding = false;
|
||||||
|
|
||||||
@ -648,7 +652,8 @@ public class PgpDecryptVerify {
|
|||||||
//about keys without subkey signing. Can't get it to import a slightly broken one
|
//about keys without subkey signing. Can't get it to import a slightly broken one
|
||||||
//either, so we will err on bad subkey binding here.
|
//either, so we will err on bad subkey binding here.
|
||||||
PGPSignature sig = itr.next();
|
PGPSignature sig = itr.next();
|
||||||
if (sig.getKeyID() == masterPublicKey.getKeyID() && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING) {
|
if (sig.getKeyID() == masterPublicKey.getKeyID() &&
|
||||||
|
sig.getSignatureType() == PGPSignature.SUBKEY_BINDING) {
|
||||||
//check and if ok, check primary key binding.
|
//check and if ok, check primary key binding.
|
||||||
try {
|
try {
|
||||||
sig.init(contentVerifierBuilderProvider, masterPublicKey);
|
sig.init(contentVerifierBuilderProvider, masterPublicKey);
|
||||||
@ -680,7 +685,7 @@ public class PgpDecryptVerify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean verifyPrimaryKeyBinding(PGPSignatureSubpacketVector pkts,
|
private static boolean verifyPrimaryKeyBinding(PGPSignatureSubpacketVector pkts,
|
||||||
PGPPublicKey masterPublicKey, PGPPublicKey signingPublicKey) {
|
PGPPublicKey masterPublicKey, PGPPublicKey signingPublicKey) {
|
||||||
boolean validPrimaryKeyBinding = false;
|
boolean validPrimaryKeyBinding = false;
|
||||||
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider =
|
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider =
|
||||||
new JcaPGPContentVerifierBuilderProvider()
|
new JcaPGPContentVerifierBuilderProvider()
|
||||||
|
@ -52,7 +52,8 @@ public class PgpImportExport {
|
|||||||
this.mProgress = progress;
|
this.mProgress = progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PgpImportExport(Context context, ProgressDialogUpdater progress, KeychainServiceListener keychainListener) {
|
public PgpImportExport(Context context,
|
||||||
|
ProgressDialogUpdater progress, KeychainServiceListener keychainListener) {
|
||||||
super();
|
super();
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
this.mProgress = progress;
|
this.mProgress = progress;
|
||||||
@ -252,8 +253,9 @@ public class PgpImportExport {
|
|||||||
}
|
}
|
||||||
newPubRing = PGPPublicKeyRing.insertPublicKey(newPubRing, key);
|
newPubRing = PGPPublicKeyRing.insertPublicKey(newPubRing, key);
|
||||||
}
|
}
|
||||||
if (newPubRing != null)
|
if (newPubRing != null) {
|
||||||
ProviderHelper.saveKeyRing(mContext, newPubRing);
|
ProviderHelper.saveKeyRing(mContext, newPubRing);
|
||||||
|
}
|
||||||
// TODO: remove status returns, use exceptions!
|
// TODO: remove status returns, use exceptions!
|
||||||
status = Id.return_value.ok;
|
status = Id.return_value.ok;
|
||||||
}
|
}
|
||||||
|
@ -287,7 +287,8 @@ public class PgpKeyOperation {
|
|||||||
long numDays =
|
long numDays =
|
||||||
(expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000);
|
(expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000);
|
||||||
if (numDays <= 0) {
|
if (numDays <= 0) {
|
||||||
throw new PgpGeneralException(mContext.getString(R.string.error_expiry_must_come_after_creation));
|
throw new PgpGeneralException(
|
||||||
|
mContext.getString(R.string.error_expiry_must_come_after_creation));
|
||||||
}
|
}
|
||||||
hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400);
|
hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400);
|
||||||
} else {
|
} else {
|
||||||
@ -336,8 +337,10 @@ public class PgpKeyOperation {
|
|||||||
keyFlags = 0;
|
keyFlags = 0;
|
||||||
|
|
||||||
usageId = keysUsages.get(i);
|
usageId = keysUsages.get(i);
|
||||||
canSign = (usageId == Id.choice.usage.sign_only || usageId == Id.choice.usage.sign_and_encrypt);
|
canSign =
|
||||||
canEncrypt = (usageId == Id.choice.usage.encrypt_only || usageId == Id.choice.usage.sign_and_encrypt);
|
(usageId == Id.choice.usage.sign_only || usageId == Id.choice.usage.sign_and_encrypt);
|
||||||
|
canEncrypt =
|
||||||
|
(usageId == Id.choice.usage.encrypt_only || usageId == Id.choice.usage.sign_and_encrypt);
|
||||||
if (canSign) {
|
if (canSign) {
|
||||||
Date todayDate = new Date(); //both sig times the same
|
Date todayDate = new Date(); //both sig times the same
|
||||||
keyFlags |= KeyFlags.SIGN_DATA;
|
keyFlags |= KeyFlags.SIGN_DATA;
|
||||||
|
@ -258,10 +258,10 @@ public class PgpToX509 {
|
|||||||
*
|
*
|
||||||
* @author Bruno Harbulot.
|
* @author Bruno Harbulot.
|
||||||
*/
|
*/
|
||||||
public final static class PredefinedPasswordCallbackHandler implements CallbackHandler {
|
public static final class PredefinedPasswordCallbackHandler implements CallbackHandler {
|
||||||
|
|
||||||
private char[] password;
|
private char[] mPassword;
|
||||||
private String prompt;
|
private String mPrompt;
|
||||||
|
|
||||||
public PredefinedPasswordCallbackHandler(String password) {
|
public PredefinedPasswordCallbackHandler(String password) {
|
||||||
this(password == null ? null : password.toCharArray(), null);
|
this(password == null ? null : password.toCharArray(), null);
|
||||||
@ -276,16 +276,16 @@ public class PgpToX509 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PredefinedPasswordCallbackHandler(char[] password, String prompt) {
|
public PredefinedPasswordCallbackHandler(char[] password, String prompt) {
|
||||||
this.password = password;
|
this.mPassword = password;
|
||||||
this.prompt = prompt;
|
this.mPrompt = prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
|
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
|
||||||
for (Callback callback : callbacks) {
|
for (Callback callback : callbacks) {
|
||||||
if (callback instanceof PasswordCallback) {
|
if (callback instanceof PasswordCallback) {
|
||||||
PasswordCallback pwCallback = (PasswordCallback) callback;
|
PasswordCallback pwCallback = (PasswordCallback) callback;
|
||||||
if ((this.prompt == null) || (this.prompt.equals(pwCallback.getPrompt()))) {
|
if ((this.mPrompt == null) || (this.mPrompt.equals(pwCallback.getPrompt()))) {
|
||||||
pwCallback.setPassword(this.password);
|
pwCallback.setPassword(this.mPassword);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedCallbackException(callback, "Unrecognised callback.");
|
throw new UnsupportedCallbackException(callback, "Unrecognised callback.");
|
||||||
|
@ -17,10 +17,9 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.provider;
|
package org.sufficientlysecure.keychain.provider;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
|
||||||
public class KeychainContract {
|
public class KeychainContract {
|
||||||
|
|
||||||
@ -94,10 +93,14 @@ public class KeychainContract {
|
|||||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
|
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
|
||||||
.appendPath(BASE_KEY_RINGS).build();
|
.appendPath(BASE_KEY_RINGS).build();
|
||||||
|
|
||||||
/** Use if multiple items get returned */
|
/**
|
||||||
|
* Use if multiple items get returned
|
||||||
|
*/
|
||||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.key_ring";
|
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.key_ring";
|
||||||
|
|
||||||
/** Use if a single item is returned */
|
/**
|
||||||
|
* Use if a single item is returned
|
||||||
|
*/
|
||||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.key_ring";
|
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.key_ring";
|
||||||
|
|
||||||
public static Uri buildUnifiedKeyRingsUri() {
|
public static Uri buildUnifiedKeyRingsUri() {
|
||||||
@ -165,10 +168,14 @@ public class KeychainContract {
|
|||||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
|
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
|
||||||
.appendPath(BASE_KEY_RINGS).build();
|
.appendPath(BASE_KEY_RINGS).build();
|
||||||
|
|
||||||
/** Use if multiple items get returned */
|
/**
|
||||||
|
* Use if multiple items get returned
|
||||||
|
*/
|
||||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.key";
|
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.key";
|
||||||
|
|
||||||
/** Use if a single item is returned */
|
/**
|
||||||
|
* Use if a single item is returned
|
||||||
|
*/
|
||||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.key";
|
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.key";
|
||||||
|
|
||||||
public static Uri buildPublicKeysUri(String keyRingRowId) {
|
public static Uri buildPublicKeysUri(String keyRingRowId) {
|
||||||
@ -204,10 +211,14 @@ public class KeychainContract {
|
|||||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
|
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
|
||||||
.appendPath(BASE_KEY_RINGS).build();
|
.appendPath(BASE_KEY_RINGS).build();
|
||||||
|
|
||||||
/** Use if multiple items get returned */
|
/**
|
||||||
|
* Use if multiple items get returned
|
||||||
|
*/
|
||||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.user_id";
|
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.user_id";
|
||||||
|
|
||||||
/** Use if a single item is returned */
|
/**
|
||||||
|
* Use if a single item is returned
|
||||||
|
*/
|
||||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.user_id";
|
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.user_id";
|
||||||
|
|
||||||
public static Uri buildPublicUserIdsUri(String keyRingRowId) {
|
public static Uri buildPublicUserIdsUri(String keyRingRowId) {
|
||||||
@ -243,10 +254,14 @@ public class KeychainContract {
|
|||||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
|
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
|
||||||
.appendPath(BASE_API_APPS).build();
|
.appendPath(BASE_API_APPS).build();
|
||||||
|
|
||||||
/** Use if multiple items get returned */
|
/**
|
||||||
|
* Use if multiple items get returned
|
||||||
|
*/
|
||||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.api_apps";
|
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.api_apps";
|
||||||
|
|
||||||
/** Use if a single item is returned */
|
/**
|
||||||
|
* Use if a single item is returned
|
||||||
|
*/
|
||||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.api_apps";
|
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.api_apps";
|
||||||
|
|
||||||
public static Uri buildIdUri(String rowId) {
|
public static Uri buildIdUri(String rowId) {
|
||||||
|
@ -17,6 +17,10 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.provider;
|
package org.sufficientlysecure.keychain.provider;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.provider.BaseColumns;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAppsColumns;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAppsColumns;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingsColumns;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingsColumns;
|
||||||
@ -24,11 +28,6 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeysColumns;
|
|||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIdsColumns;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIdsColumns;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
|
||||||
import android.provider.BaseColumns;
|
|
||||||
|
|
||||||
public class KeychainDatabase extends SQLiteOpenHelper {
|
public class KeychainDatabase extends SQLiteOpenHelper {
|
||||||
private static final String DATABASE_NAME = "apg.db";
|
private static final String DATABASE_NAME = "apg.db";
|
||||||
private static final int DATABASE_VERSION = 7;
|
private static final int DATABASE_VERSION = 7;
|
||||||
|
@ -17,21 +17,6 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.provider;
|
package org.sufficientlysecure.keychain.provider;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingsColumns;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyTypes;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeysColumns;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIdsColumns;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
|
||||||
|
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.UriMatcher;
|
import android.content.UriMatcher;
|
||||||
@ -43,6 +28,13 @@ import android.database.sqlite.SQLiteQueryBuilder;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainContract.*;
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class KeychainProvider extends ContentProvider {
|
public class KeychainProvider extends ContentProvider {
|
||||||
// public static final String ACTION_BROADCAST_DATABASE_CHANGE = Constants.PACKAGE_NAME
|
// public static final String ACTION_BROADCAST_DATABASE_CHANGE = Constants.PACKAGE_NAME
|
||||||
@ -367,7 +359,8 @@ public class KeychainProvider extends ContentProvider {
|
|||||||
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
|
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
|
||||||
projectionMap.put(KeyRingsColumns.KEY_RING_DATA, Tables.KEY_RINGS + "."
|
projectionMap.put(KeyRingsColumns.KEY_RING_DATA, Tables.KEY_RINGS + "."
|
||||||
+ KeyRingsColumns.KEY_RING_DATA);
|
+ KeyRingsColumns.KEY_RING_DATA);
|
||||||
projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID);
|
projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
|
||||||
|
+ KeyRingsColumns.MASTER_KEY_ID);
|
||||||
// TODO: deprecated master key id
|
// TODO: deprecated master key id
|
||||||
//projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEYS + "." + KeysColumns.KEY_ID);
|
//projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEYS + "." + KeysColumns.KEY_ID);
|
||||||
|
|
||||||
@ -483,7 +476,8 @@ public class KeychainProvider extends ContentProvider {
|
|||||||
groupBy = Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID;
|
groupBy = Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID;
|
||||||
|
|
||||||
if (TextUtils.isEmpty(sortOrder)) {
|
if (TextUtils.isEmpty(sortOrder)) {
|
||||||
sortOrder = KeyRings.TYPE + " DESC, " + Tables.USER_IDS + "." + UserIdsColumns.USER_ID + " ASC";
|
sortOrder = KeyRings.TYPE + " DESC, " +
|
||||||
|
Tables.USER_IDS + "." + UserIdsColumns.USER_ID + " ASC";
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -17,10 +17,9 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.provider;
|
package org.sufficientlysecure.keychain.provider;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
|
||||||
public class KeychainServiceBlobContract {
|
public class KeychainServiceBlobContract {
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ import android.content.Context;
|
|||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainServiceBlobContract.BlobsColumns;
|
import org.sufficientlysecure.keychain.provider.KeychainServiceBlobContract.BlobsColumns;
|
||||||
|
|
||||||
public class KeychainServiceBlobDatabase extends SQLiteOpenHelper {
|
public class KeychainServiceBlobDatabase extends SQLiteOpenHelper {
|
||||||
|
@ -18,11 +18,6 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.provider;
|
package org.sufficientlysecure.keychain.provider;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainServiceBlobContract.Blobs;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainServiceBlobContract.BlobsColumns;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
|
||||||
|
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
@ -31,7 +26,10 @@ import android.database.sqlite.SQLiteDatabase;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainServiceBlobContract.Blobs;
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainServiceBlobContract.BlobsColumns;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -55,7 +53,9 @@ public class KeychainServiceBlobProvider extends ContentProvider {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Uri insert(Uri uri, ContentValues ignored) {
|
public Uri insert(Uri uri, ContentValues ignored) {
|
||||||
// ContentValues are actually ignored, because we want to store a blob with no more
|
// ContentValues are actually ignored, because we want to store a blob with no more
|
||||||
@ -74,7 +74,9 @@ public class KeychainServiceBlobProvider extends ContentProvider {
|
|||||||
return Uri.withAppendedPath(insertedUri, password);
|
return Uri.withAppendedPath(insertedUri, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ParcelFileDescriptor openFile(Uri uri, String mode) throws SecurityException,
|
public ParcelFileDescriptor openFile(Uri uri, String mode) throws SecurityException,
|
||||||
FileNotFoundException {
|
FileNotFoundException {
|
||||||
@ -91,9 +93,9 @@ public class KeychainServiceBlobProvider extends ContentProvider {
|
|||||||
|
|
||||||
// get the data
|
// get the data
|
||||||
SQLiteDatabase db = mBlobDatabase.getReadableDatabase();
|
SQLiteDatabase db = mBlobDatabase.getReadableDatabase();
|
||||||
Cursor result = db.query(KeychainServiceBlobDatabase.TABLE, new String[] { BaseColumns._ID },
|
Cursor result = db.query(KeychainServiceBlobDatabase.TABLE, new String[]{BaseColumns._ID},
|
||||||
BaseColumns._ID + " = ? and " + BlobsColumns.KEY + " = ?",
|
BaseColumns._ID + " = ? and " + BlobsColumns.KEY + " = ?",
|
||||||
new String[] { id, key }, null, null, null);
|
new String[]{id, key}, null, null, null);
|
||||||
|
|
||||||
if (result.getCount() == 0) {
|
if (result.getCount() == 0) {
|
||||||
// either the key is wrong or no id exists
|
// either the key is wrong or no id exists
|
||||||
@ -124,26 +126,34 @@ public class KeychainServiceBlobProvider extends ContentProvider {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getType(Uri uri) {
|
public String getType(Uri uri) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
||||||
String sortOrder) {
|
String sortOrder) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -17,18 +17,13 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.provider;
|
package org.sufficientlysecure.keychain.provider;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import android.content.*;
|
||||||
import java.io.IOException;
|
import android.database.Cursor;
|
||||||
import java.util.ArrayList;
|
import android.database.DatabaseUtils;
|
||||||
import java.util.Date;
|
import android.net.Uri;
|
||||||
|
import android.os.RemoteException;
|
||||||
import org.spongycastle.bcpg.ArmoredOutputStream;
|
import org.spongycastle.bcpg.ArmoredOutputStream;
|
||||||
import org.spongycastle.openpgp.PGPKeyRing;
|
import org.spongycastle.openpgp.*;
|
||||||
import org.spongycastle.openpgp.PGPPublicKey;
|
|
||||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
|
||||||
import org.spongycastle.openpgp.PGPSecretKey;
|
|
||||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
|
||||||
import org.spongycastle.openpgp.PGPSignature;
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpHelper;
|
||||||
@ -42,15 +37,10 @@ import org.sufficientlysecure.keychain.service.remote.AppSettings;
|
|||||||
import org.sufficientlysecure.keychain.util.IterableIterator;
|
import org.sufficientlysecure.keychain.util.IterableIterator;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import android.content.ContentProviderOperation;
|
import java.io.ByteArrayOutputStream;
|
||||||
import android.content.ContentResolver;
|
import java.io.IOException;
|
||||||
import android.content.ContentValues;
|
import java.util.ArrayList;
|
||||||
import android.content.Context;
|
import java.util.Date;
|
||||||
import android.content.OperationApplicationException;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.database.DatabaseUtils;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.RemoteException;
|
|
||||||
|
|
||||||
public class ProviderHelper {
|
public class ProviderHelper {
|
||||||
|
|
||||||
@ -111,7 +101,7 @@ public class ProviderHelper {
|
|||||||
public static PGPPublicKey getPGPPublicKeyByKeyId(Context context, long keyId) {
|
public static PGPPublicKey getPGPPublicKeyByKeyId(Context context, long keyId) {
|
||||||
PGPPublicKeyRing keyRing = getPGPPublicKeyRingByKeyId(context, keyId);
|
PGPPublicKeyRing keyRing = getPGPPublicKeyRingByKeyId(context, keyId);
|
||||||
|
|
||||||
return (keyRing == null)? null : keyRing.getPublicKey(keyId);
|
return (keyRing == null) ? null : keyRing.getPublicKey(keyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -162,7 +152,8 @@ public class ProviderHelper {
|
|||||||
|
|
||||||
// get current _ID of key
|
// get current _ID of key
|
||||||
long currentRowId = -1;
|
long currentRowId = -1;
|
||||||
Cursor oldQuery = context.getContentResolver().query(deleteUri, new String[]{KeyRings._ID}, null, null, null);
|
Cursor oldQuery = context.getContentResolver()
|
||||||
|
.query(deleteUri, new String[]{KeyRings._ID}, null, null, null);
|
||||||
if (oldQuery != null && oldQuery.moveToFirst()) {
|
if (oldQuery != null && oldQuery.moveToFirst()) {
|
||||||
currentRowId = oldQuery.getLong(0);
|
currentRowId = oldQuery.getLong(0);
|
||||||
} else {
|
} else {
|
||||||
@ -178,10 +169,12 @@ public class ProviderHelper {
|
|||||||
|
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
// use exactly the same _ID again to replace key in-place.
|
// use exactly the same _ID again to replace key in-place.
|
||||||
// NOTE: If we would not use the same _ID again, getting back to the ViewKeyActivity would result in Nullpointer,
|
// NOTE: If we would not use the same _ID again,
|
||||||
|
// getting back to the ViewKeyActivity would result in Nullpointer,
|
||||||
// because the currently loaded key would be gone from the database
|
// because the currently loaded key would be gone from the database
|
||||||
if (currentRowId != -1)
|
if (currentRowId != -1) {
|
||||||
values.put(KeyRings._ID, currentRowId);
|
values.put(KeyRings._ID, currentRowId);
|
||||||
|
}
|
||||||
values.put(KeyRings.MASTER_KEY_ID, masterKeyId);
|
values.put(KeyRings.MASTER_KEY_ID, masterKeyId);
|
||||||
values.put(KeyRings.KEY_RING_DATA, keyRing.getEncoded());
|
values.put(KeyRings.KEY_RING_DATA, keyRing.getEncoded());
|
||||||
|
|
||||||
@ -205,8 +198,11 @@ public class ProviderHelper {
|
|||||||
++userIdRank;
|
++userIdRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PGPSignature certification : new IterableIterator<PGPSignature>(masterKey.getSignaturesOfType(PGPSignature.POSITIVE_CERTIFICATION))) {
|
for (PGPSignature certification :
|
||||||
//TODO: how to do this?? we need to verify the signatures again and again when they are displayed...
|
new IterableIterator<PGPSignature>(
|
||||||
|
masterKey.getSignaturesOfType(PGPSignature.POSITIVE_CERTIFICATION))) {
|
||||||
|
// TODO: how to do this??
|
||||||
|
// we need to verify the signatures again and again when they are displayed...
|
||||||
// if (certification.verify
|
// if (certification.verify
|
||||||
// operations.add(buildPublicKeyOperations(context, keyRingRowId, key, rank));
|
// operations.add(buildPublicKeyOperations(context, keyRingRowId, key, rank));
|
||||||
}
|
}
|
||||||
@ -233,7 +229,8 @@ public class ProviderHelper {
|
|||||||
|
|
||||||
// get current _ID of key
|
// get current _ID of key
|
||||||
long currentRowId = -1;
|
long currentRowId = -1;
|
||||||
Cursor oldQuery = context.getContentResolver().query(deleteUri, new String[]{KeyRings._ID}, null, null, null);
|
Cursor oldQuery = context.getContentResolver()
|
||||||
|
.query(deleteUri, new String[]{KeyRings._ID}, null, null, null);
|
||||||
if (oldQuery != null && oldQuery.moveToFirst()) {
|
if (oldQuery != null && oldQuery.moveToFirst()) {
|
||||||
currentRowId = oldQuery.getLong(0);
|
currentRowId = oldQuery.getLong(0);
|
||||||
} else {
|
} else {
|
||||||
@ -249,10 +246,12 @@ public class ProviderHelper {
|
|||||||
|
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
// use exactly the same _ID again to replace key in-place.
|
// use exactly the same _ID again to replace key in-place.
|
||||||
// NOTE: If we would not use the same _ID again, getting back to the ViewKeyActivity would result in Nullpointer,
|
// NOTE: If we would not use the same _ID again,
|
||||||
|
// getting back to the ViewKeyActivity would result in Nullpointer,
|
||||||
// because the currently loaded key would be gone from the database
|
// because the currently loaded key would be gone from the database
|
||||||
if (currentRowId != -1)
|
if (currentRowId != -1) {
|
||||||
values.put(KeyRings._ID, currentRowId);
|
values.put(KeyRings._ID, currentRowId);
|
||||||
|
}
|
||||||
values.put(KeyRings.MASTER_KEY_ID, masterKeyId);
|
values.put(KeyRings.MASTER_KEY_ID, masterKeyId);
|
||||||
values.put(KeyRings.KEY_RING_DATA, keyRing.getEncoded());
|
values.put(KeyRings.KEY_RING_DATA, keyRing.getEncoded());
|
||||||
|
|
||||||
@ -289,7 +288,7 @@ public class ProviderHelper {
|
|||||||
* Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing
|
* Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing
|
||||||
*/
|
*/
|
||||||
private static ContentProviderOperation buildPublicKeyOperations(Context context,
|
private static ContentProviderOperation buildPublicKeyOperations(Context context,
|
||||||
long keyRingRowId, PGPPublicKey key, int rank) throws IOException {
|
long keyRingRowId, PGPPublicKey key, int rank) throws IOException {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(Keys.KEY_ID, key.getKeyID());
|
values.put(Keys.KEY_ID, key.getKeyID());
|
||||||
values.put(Keys.IS_MASTER_KEY, key.isMasterKey());
|
values.put(Keys.IS_MASTER_KEY, key.isMasterKey());
|
||||||
@ -317,7 +316,7 @@ public class ProviderHelper {
|
|||||||
* Build ContentProviderOperation to add PublicUserIds to database corresponding to a keyRing
|
* Build ContentProviderOperation to add PublicUserIds to database corresponding to a keyRing
|
||||||
*/
|
*/
|
||||||
private static ContentProviderOperation buildPublicUserIdOperations(Context context,
|
private static ContentProviderOperation buildPublicUserIdOperations(Context context,
|
||||||
long keyRingRowId, String userId, int rank) {
|
long keyRingRowId, String userId, int rank) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(UserIds.KEY_RING_ROW_ID, keyRingRowId);
|
values.put(UserIds.KEY_RING_ROW_ID, keyRingRowId);
|
||||||
values.put(UserIds.USER_ID, userId);
|
values.put(UserIds.USER_ID, userId);
|
||||||
@ -332,7 +331,7 @@ public class ProviderHelper {
|
|||||||
* Build ContentProviderOperation to add PGPSecretKey to database corresponding to a keyRing
|
* Build ContentProviderOperation to add PGPSecretKey to database corresponding to a keyRing
|
||||||
*/
|
*/
|
||||||
private static ContentProviderOperation buildSecretKeyOperations(Context context,
|
private static ContentProviderOperation buildSecretKeyOperations(Context context,
|
||||||
long keyRingRowId, PGPSecretKey key, int rank) throws IOException {
|
long keyRingRowId, PGPSecretKey key, int rank) throws IOException {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
|
|
||||||
boolean hasPrivate = true;
|
boolean hasPrivate = true;
|
||||||
@ -369,7 +368,7 @@ public class ProviderHelper {
|
|||||||
* Build ContentProviderOperation to add SecretUserIds to database corresponding to a keyRing
|
* Build ContentProviderOperation to add SecretUserIds to database corresponding to a keyRing
|
||||||
*/
|
*/
|
||||||
private static ContentProviderOperation buildSecretUserIdOperations(Context context,
|
private static ContentProviderOperation buildSecretUserIdOperations(Context context,
|
||||||
long keyRingRowId, String userId, int rank) {
|
long keyRingRowId, String userId, int rank) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(UserIds.KEY_RING_ROW_ID, keyRingRowId);
|
values.put(UserIds.KEY_RING_ROW_ID, keyRingRowId);
|
||||||
values.put(UserIds.USER_ID, userId);
|
values.put(UserIds.USER_ID, userId);
|
||||||
@ -413,10 +412,10 @@ public class ProviderHelper {
|
|||||||
|
|
||||||
ArrayList<Long> rowIds = new ArrayList<Long>();
|
ArrayList<Long> rowIds = new ArrayList<Long>();
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
int IdCol = cursor.getColumnIndex(KeyRings._ID);
|
int idCol = cursor.getColumnIndex(KeyRings._ID);
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
rowIds.add(cursor.getLong(IdCol));
|
rowIds.add(cursor.getLong(idCol));
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -496,7 +495,7 @@ public class ProviderHelper {
|
|||||||
+ " AS sign_keys WHERE sign_keys." + Keys.KEY_RING_ROW_ID + " = "
|
+ " AS sign_keys WHERE sign_keys." + Keys.KEY_RING_ROW_ID + " = "
|
||||||
+ KeychainDatabase.Tables.KEY_RINGS + "." + KeyRings._ID
|
+ KeychainDatabase.Tables.KEY_RINGS + "." + KeyRings._ID
|
||||||
+ " AND sign_keys." + Keys.CAN_SIGN + " = '1' AND " + Keys.IS_MASTER_KEY
|
+ " AND sign_keys." + Keys.CAN_SIGN + " = '1' AND " + Keys.IS_MASTER_KEY
|
||||||
+ " = 1) AS sign",};
|
+ " = 1) AS sign", };
|
||||||
|
|
||||||
ContentResolver cr = context.getContentResolver();
|
ContentResolver cr = context.getContentResolver();
|
||||||
Cursor cursor = cr.query(queryUri, projection, null, null, null);
|
Cursor cursor = cr.query(queryUri, projection, null, null, null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user