aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java145
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java22
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java80
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java126
4 files changed, 288 insertions, 85 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java
new file mode 100644
index 000000000..ed1988336
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java
@@ -0,0 +1,145 @@
+package org.sufficientlysecure.keychain.provider;
+
+import android.net.Uri;
+
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.pgp.KeyRing;
+import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
+import org.sufficientlysecure.keychain.util.Log;
+
+public class CachedPublicKeyRing extends KeyRing {
+
+ final ProviderHelper mProviderHelper;
+ final Uri mUri;
+
+ public CachedPublicKeyRing(ProviderHelper providerHelper, Uri uri) {
+ mProviderHelper = providerHelper;
+ mUri = uri;
+ }
+
+ public long getMasterKeyId() throws PgpGeneralException {
+ try {
+ Object data = mProviderHelper.getGenericData(mUri,
+ KeychainContract.KeyRings.MASTER_KEY_ID, ProviderHelper.FIELD_TYPE_INTEGER);
+ return (Long) data;
+ } catch (ProviderHelper.NotFoundException e) {
+ throw new PgpGeneralException(e);
+ }
+ }
+
+ /**
+ * Find the master key id related to a given query. The id will either be extracted from the
+ * query, which should work for all specific /key_rings/ queries, or will be queried if it can't.
+ */
+ public long extractOrGetMasterKeyId() throws PgpGeneralException {
+ // try extracting from the uri first
+ String firstSegment = mUri.getPathSegments().get(1);
+ if (!firstSegment.equals("find")) try {
+ return Long.parseLong(firstSegment);
+ } catch (NumberFormatException e) {
+ // didn't work? oh well.
+ Log.d(Constants.TAG, "Couldn't get masterKeyId from URI, querying...");
+ }
+ return getMasterKeyId();
+ }
+
+ public String getPrimaryUserId() throws PgpGeneralException {
+ try {
+ Object data = mProviderHelper.getGenericData(mUri,
+ KeychainContract.KeyRings.MASTER_KEY_ID,
+ ProviderHelper.FIELD_TYPE_STRING);
+ return (String) data;
+ } catch(ProviderHelper.NotFoundException e) {
+ throw new PgpGeneralException(e);
+ }
+ }
+
+ public boolean isRevoked() throws PgpGeneralException {
+ try {
+ Object data = mProviderHelper.getGenericData(mUri,
+ KeychainContract.KeyRings.MASTER_KEY_ID,
+ ProviderHelper.FIELD_TYPE_INTEGER);
+ return (Long) data > 0;
+ } catch(ProviderHelper.NotFoundException e) {
+ throw new PgpGeneralException(e);
+ }
+ }
+
+ public boolean canCertify() throws PgpGeneralException {
+ try {
+ Object data = mProviderHelper.getGenericData(mUri,
+ KeychainContract.KeyRings.MASTER_KEY_ID,
+ ProviderHelper.FIELD_TYPE_INTEGER);
+ return (Long) data > 0;
+ } catch(ProviderHelper.NotFoundException e) {
+ throw new PgpGeneralException(e);
+ }
+ }
+
+ public long getEncryptId() throws PgpGeneralException {
+ try {
+ Object data = mProviderHelper.getGenericData(mUri,
+ KeychainContract.KeyRings.MASTER_KEY_ID,
+ ProviderHelper.FIELD_TYPE_INTEGER);
+ return (Long) data;
+ } catch(ProviderHelper.NotFoundException e) {
+ throw new PgpGeneralException(e);
+ }
+ }
+
+ public boolean hasEncrypt() throws PgpGeneralException {
+ try {
+ Object data = mProviderHelper.getGenericData(mUri,
+ KeychainContract.KeyRings.MASTER_KEY_ID,
+ ProviderHelper.FIELD_TYPE_INTEGER);
+ return (Long) data > 0;
+ } catch(ProviderHelper.NotFoundException e) {
+ throw new PgpGeneralException(e);
+ }
+ }
+
+ public long getSignId() throws PgpGeneralException {
+ try {
+ Object data = mProviderHelper.getGenericData(mUri,
+ KeychainContract.KeyRings.MASTER_KEY_ID,
+ ProviderHelper.FIELD_TYPE_INTEGER);
+ return (Long) data;
+ } catch(ProviderHelper.NotFoundException e) {
+ throw new PgpGeneralException(e);
+ }
+ }
+
+ public boolean hasSign() throws PgpGeneralException {
+ try {
+ Object data = mProviderHelper.getGenericData(mUri,
+ KeychainContract.KeyRings.MASTER_KEY_ID,
+ ProviderHelper.FIELD_TYPE_INTEGER);
+ return (Long) data > 0;
+ } catch(ProviderHelper.NotFoundException e) {
+ throw new PgpGeneralException(e);
+ }
+ }
+
+ public int getVerified() throws PgpGeneralException {
+ try {
+ Object data = mProviderHelper.getGenericData(mUri,
+ KeychainContract.KeyRings.MASTER_KEY_ID,
+ ProviderHelper.FIELD_TYPE_INTEGER);
+ return (Integer) data;
+ } catch(ProviderHelper.NotFoundException e) {
+ throw new PgpGeneralException(e);
+ }
+ }
+
+ public boolean hasAnySecret() throws PgpGeneralException {
+ try {
+ Object data = mProviderHelper.getGenericData(mUri,
+ KeychainContract.KeyRings.MASTER_KEY_ID,
+ ProviderHelper.FIELD_TYPE_INTEGER);
+ return (Long) data > 0;
+ } catch(ProviderHelper.NotFoundException e) {
+ throw new PgpGeneralException(e);
+ }
+
+ }
+}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java
index a4fa3dac9..483f762f7 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java
@@ -110,6 +110,8 @@ public class KeychainContract {
public static final String HAS_ANY_SECRET = "has_any_secret";
public static final String HAS_ENCRYPT = "has_encrypt";
public static final String HAS_SIGN = "has_sign";
+ public static final String PUBKEY_DATA = "pubkey_data";
+ public static final String PRIVKEY_DATA = "privkey_data";
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
.appendPath(BASE_KEY_RINGS).build();
@@ -123,6 +125,10 @@ public class KeychainContract {
return CONTENT_URI.buildUpon().appendPath(PATH_UNIFIED).build();
}
+ public static Uri buildGenericKeyRingUri(long masterKeyId) {
+ return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId)).build();
+ }
+
public static Uri buildGenericKeyRingUri(String masterKeyId) {
return CONTENT_URI.buildUpon().appendPath(masterKeyId).build();
}
@@ -131,20 +137,24 @@ public class KeychainContract {
return CONTENT_URI.buildUpon().appendPath(uri.getPathSegments().get(1)).build();
}
- public static Uri buildUnifiedKeyRingUri(String masterKeyId) {
- return CONTENT_URI.buildUpon().appendPath(masterKeyId).appendPath(PATH_UNIFIED).build();
+ public static Uri buildUnifiedKeyRingUri(long masterKeyId) {
+ return CONTENT_URI.buildUpon().appendPath(Long.toString(masterKeyId))
+ .appendPath(PATH_UNIFIED).build();
}
public static Uri buildUnifiedKeyRingUri(Uri uri) {
- return CONTENT_URI.buildUpon().appendPath(uri.getPathSegments().get(1)).appendPath(PATH_UNIFIED).build();
+ return CONTENT_URI.buildUpon().appendPath(uri.getPathSegments().get(1))
+ .appendPath(PATH_UNIFIED).build();
}
public static Uri buildUnifiedKeyRingsFindByEmailUri(String email) {
- return CONTENT_URI.buildUpon().appendPath(PATH_FIND).appendPath(PATH_BY_EMAIL).appendPath(email).build();
+ return CONTENT_URI.buildUpon().appendPath(PATH_FIND)
+ .appendPath(PATH_BY_EMAIL).appendPath(email).build();
}
- public static Uri buildUnifiedKeyRingsFindBySubkeyUri(String subkey) {
- return CONTENT_URI.buildUpon().appendPath(PATH_FIND).appendPath(PATH_BY_SUBKEY).appendPath(subkey).build();
+ public static Uri buildUnifiedKeyRingsFindBySubkeyUri(long subkey) {
+ return CONTENT_URI.buildUpon().appendPath(PATH_FIND)
+ .appendPath(PATH_BY_SUBKEY).appendPath(Long.toString(subkey)).build();
}
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java
index ec7bf58d9..2f6cded91 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java
@@ -43,6 +43,7 @@ import org.sufficientlysecure.keychain.util.Log;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
+import java.util.List;
public class KeychainProvider extends ContentProvider {
@@ -242,45 +243,39 @@ public class KeychainProvider extends ContentProvider {
HashMap<String, String> projectionMap = new HashMap<String, String>();
projectionMap.put(KeyRings._ID, Tables.KEYS + ".oid AS _id");
projectionMap.put(KeyRings.MASTER_KEY_ID, Tables.KEYS + "." + Keys.MASTER_KEY_ID);
- projectionMap.put(KeyRings.KEY_ID, Keys.KEY_ID);
- projectionMap.put(KeyRings.KEY_SIZE, Keys.KEY_SIZE);
+ projectionMap.put(KeyRings.KEY_ID, Tables.KEYS + "." + Keys.KEY_ID);
+ projectionMap.put(KeyRings.KEY_SIZE, Tables.KEYS + "." + Keys.KEY_SIZE);
projectionMap.put(KeyRings.IS_REVOKED, Tables.KEYS + "." + Keys.IS_REVOKED);
- projectionMap.put(KeyRings.CAN_CERTIFY, Keys.CAN_CERTIFY);
- projectionMap.put(KeyRings.CAN_ENCRYPT, Keys.CAN_ENCRYPT);
- projectionMap.put(KeyRings.CAN_SIGN, Keys.CAN_SIGN);
+ projectionMap.put(KeyRings.CAN_CERTIFY, Tables.KEYS + "." + Keys.CAN_CERTIFY);
+ projectionMap.put(KeyRings.CAN_ENCRYPT, Tables.KEYS + "." + Keys.CAN_ENCRYPT);
+ projectionMap.put(KeyRings.CAN_SIGN, Tables.KEYS + "." + Keys.CAN_SIGN);
projectionMap.put(KeyRings.CREATION, Tables.KEYS + "." + Keys.CREATION);
- projectionMap.put(KeyRings.EXPIRY, Keys.EXPIRY);
- projectionMap.put(KeyRings.ALGORITHM, Keys.ALGORITHM);
- projectionMap.put(KeyRings.FINGERPRINT, Keys.FINGERPRINT);
+ projectionMap.put(KeyRings.EXPIRY, Tables.KEYS + "." + Keys.EXPIRY);
+ projectionMap.put(KeyRings.ALGORITHM, Tables.KEYS + "." + Keys.ALGORITHM);
+ projectionMap.put(KeyRings.FINGERPRINT, Tables.KEYS + "." + Keys.FINGERPRINT);
projectionMap.put(KeyRings.USER_ID, UserIds.USER_ID);
projectionMap.put(KeyRings.VERIFIED, KeyRings.VERIFIED);
- projectionMap.put(KeyRings.HAS_SECRET, KeyRings.HAS_SECRET);
+ projectionMap.put(KeyRings.PUBKEY_DATA,
+ Tables.KEY_RINGS_PUBLIC + "." + KeyRingData.KEY_RING_DATA
+ + " AS " + KeyRings.PUBKEY_DATA);
+ projectionMap.put(KeyRings.PRIVKEY_DATA,
+ Tables.KEY_RINGS_SECRET + "." + KeyRingData.KEY_RING_DATA
+ + " AS " + KeyRings.PRIVKEY_DATA);
+ projectionMap.put(KeyRings.HAS_SECRET, Tables.KEYS + "." + KeyRings.HAS_SECRET);
projectionMap.put(KeyRings.HAS_ANY_SECRET,
"(EXISTS (SELECT * FROM " + Tables.KEY_RINGS_SECRET
+ " WHERE " + Tables.KEY_RINGS_SECRET + "." + KeyRingData.MASTER_KEY_ID
+ " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID
+ ")) AS " + KeyRings.HAS_ANY_SECRET);
projectionMap.put(KeyRings.HAS_ENCRYPT,
- "(EXISTS (SELECT * FROM " + Tables.KEYS + " AS k"
- +" WHERE k." + Keys.MASTER_KEY_ID
- + " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID
- + " AND k." + Keys.IS_REVOKED + " = 0"
- + " AND k." + Keys.CAN_ENCRYPT + " = 1"
- + " AND ( k." + Keys.EXPIRY + " IS NULL OR k." + Keys.EXPIRY
- + " >= " + new Date().getTime() / 1000 + " )"
- + ")) AS " + KeyRings.HAS_ENCRYPT);
+ "kE." + Keys.KEY_ID + " AS " + KeyRings.HAS_ENCRYPT);
projectionMap.put(KeyRings.HAS_SIGN,
- "(EXISTS (SELECT * FROM " + Tables.KEYS + " AS k"
- +" WHERE k." + Keys.MASTER_KEY_ID
- + " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID
- + " AND k." + Keys.IS_REVOKED + " = 0"
- + " AND k." + Keys.HAS_SECRET + " = 1"
- + " AND k." + Keys.CAN_SIGN + " = 1"
- + " AND ( k." + Keys.EXPIRY + " IS NULL OR k." + Keys.EXPIRY
- + " >= " + new Date().getTime() / 1000 + " )"
- + ")) AS " + KeyRings.HAS_SIGN);
+ "kS." + Keys.KEY_ID + " AS " + KeyRings.HAS_SIGN);
qb.setProjectionMap(projectionMap);
+ // Need this as list so we can search in it
+ List<String> plist = Arrays.asList(projection);
+
qb.setTables(
Tables.KEYS
+ " INNER JOIN " + Tables.USER_IDS + " ON ("
@@ -295,6 +290,37 @@ public class KeychainProvider extends ContentProvider {
+ " AND " + Tables.CERTS + "." + Certs.VERIFIED
+ " = " + Certs.VERIFIED_SECRET
+ ")"
+ // fairly expensive joins following, only do when requested
+ + (plist.contains(KeyRings.PUBKEY_DATA) ?
+ " INNER JOIN " + Tables.KEY_RINGS_PUBLIC + " ON ("
+ + Tables.KEYS + "." + Keys.MASTER_KEY_ID
+ + " = "
+ + Tables.KEY_RINGS_PUBLIC + "." + KeyRingData.MASTER_KEY_ID
+ + ")" : "")
+ + (plist.contains(KeyRings.PRIVKEY_DATA) ?
+ " LEFT JOIN " + Tables.KEY_RINGS_SECRET + " ON ("
+ + Tables.KEYS + "." + Keys.MASTER_KEY_ID
+ + " = "
+ + Tables.KEY_RINGS_SECRET + "." + KeyRingData.MASTER_KEY_ID
+ + ")" : "")
+ + (plist.contains(KeyRings.HAS_ENCRYPT) ?
+ " LEFT JOIN " + Tables.KEYS + " AS kE ON ("
+ +"kE." + Keys.MASTER_KEY_ID
+ + " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID
+ + " AND kE." + Keys.IS_REVOKED + " = 0"
+ + " AND kE." + Keys.CAN_ENCRYPT + " = 1"
+ + " AND ( kE." + Keys.EXPIRY + " IS NULL OR kE." + Keys.EXPIRY
+ + " >= " + new Date().getTime() / 1000 + " )"
+ + ")" : "")
+ + (plist.contains(KeyRings.HAS_SIGN) ?
+ " LEFT JOIN " + Tables.KEYS + " AS kS ON ("
+ +"kS." + Keys.MASTER_KEY_ID
+ + " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID
+ + " AND kS." + Keys.IS_REVOKED + " = 0"
+ + " AND kS." + Keys.CAN_SIGN + " = 1"
+ + " AND ( kS." + Keys.EXPIRY + " IS NULL OR kS." + Keys.EXPIRY
+ + " >= " + new Date().getTime() / 1000 + " )"
+ + ")" : "")
);
qb.appendWhere(Tables.KEYS + "." + Keys.RANK + " = 0");
// in case there are multiple verifying certificates
@@ -618,7 +644,7 @@ public class KeychainProvider extends ContentProvider {
}
if(keyId != null) {
- uri = KeyRings.buildGenericKeyRingUri(keyId.toString());
+ uri = KeyRings.buildGenericKeyRingUri(keyId);
rowUri = uri;
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java
index ab00db13a..4df86ee9b 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java
@@ -37,12 +37,16 @@ import org.spongycastle.openpgp.PGPPublicKeyRing;
import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.spongycastle.openpgp.PGPSignature;
-import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.spongycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.pgp.KeyRing;
+import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing;
+import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
+import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
+import org.sufficientlysecure.keychain.pgp.UncachedSecretKeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps;
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
@@ -63,7 +67,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
public class ProviderHelper {
@@ -141,35 +144,10 @@ public class ProviderHelper {
public HashMap<String, Object> getUnifiedData(long masterKeyId, String[] proj, int[] types)
throws NotFoundException {
- return getGenericData(KeyRings.buildUnifiedKeyRingUri(Long.toString(masterKeyId)), proj, types);
- }
-
- /**
- * Find the master key id related to a given query. The id will either be extracted from the
- * query, which should work for all specific /key_rings/ queries, or will be queried if it can't.
- */
- public long extractOrGetMasterKeyId(Uri queryUri)
- throws NotFoundException {
- // try extracting from the uri first
- String firstSegment = queryUri.getPathSegments().get(1);
- if (!firstSegment.equals("find")) try {
- return Long.parseLong(firstSegment);
- } catch (NumberFormatException e) {
- // didn't work? oh well.
- Log.d(Constants.TAG, "Couldn't get masterKeyId from URI, querying...");
- }
- return getMasterKeyId(queryUri);
- }
-
- public long getMasterKeyId(Uri queryUri) throws NotFoundException {
- Object data = getGenericData(queryUri, KeyRings.MASTER_KEY_ID, FIELD_TYPE_INTEGER);
- if (data != null) {
- return (Long) data;
- } else {
- throw new NotFoundException();
- }
+ return getGenericData(KeyRings.buildUnifiedKeyRingUri(masterKeyId), proj, types);
}
+ @Deprecated
public LongSparseArray<PGPKeyRing> getPGPKeyRings(Uri queryUri) {
Cursor cursor = mContentResolver.query(queryUri,
new String[]{KeyRingData.MASTER_KEY_ID, KeyRingData.KEY_RING_DATA},
@@ -193,6 +171,55 @@ public class ProviderHelper {
return result;
}
+ public CachedPublicKeyRing getCachedPublicKeyRing(Uri queryUri) {
+ return new CachedPublicKeyRing(this, queryUri);
+ }
+
+ public WrappedPublicKeyRing getWrappedPublicKeyRing(long id) throws NotFoundException {
+ return (WrappedPublicKeyRing) getWrappedKeyRing(KeyRings.buildUnifiedKeyRingUri(id), false);
+ }
+
+ public WrappedPublicKeyRing getWrappedPublicKeyRing(Uri queryUri) throws NotFoundException {
+ return (WrappedPublicKeyRing) getWrappedKeyRing(queryUri, false);
+ }
+
+ public WrappedSecretKeyRing getWrappedSecretKeyRing(long id) throws NotFoundException {
+ return (WrappedSecretKeyRing) getWrappedKeyRing(KeyRings.buildUnifiedKeyRingUri(id), true);
+ }
+
+ public WrappedSecretKeyRing getWrappedSecretKeyRing(Uri queryUri) throws NotFoundException {
+ return (WrappedSecretKeyRing) getWrappedKeyRing(queryUri, true);
+ }
+
+
+ private KeyRing getWrappedKeyRing(Uri queryUri, boolean secret) throws NotFoundException {
+ Cursor cursor = mContentResolver.query(queryUri,
+ new String[] {
+ // we pick from cache only information that is not easily available from keyrings
+ KeyRings.HAS_ANY_SECRET, KeyRings.VERIFIED,
+ // and of course, ring data
+ secret ? KeyRings.PRIVKEY_DATA : KeyRings.PUBKEY_DATA
+ }, null, null, null);
+ try {
+ if (cursor != null && cursor.moveToFirst()) {
+
+ boolean hasAnySecret = cursor.getInt(0) > 0;
+ int verified = cursor.getInt(1);
+ byte[] blob = cursor.getBlob(2);
+ return secret
+ ? new WrappedSecretKeyRing(blob, hasAnySecret, verified)
+ : new WrappedPublicKeyRing(blob, hasAnySecret, verified);
+ } else {
+ throw new NotFoundException("Key not found!");
+ }
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ }
+ }
+
+ @Deprecated
public PGPKeyRing getPGPKeyRing(Uri queryUri) throws NotFoundException {
LongSparseArray<PGPKeyRing> result = getPGPKeyRings(queryUri);
if (result.size() == 0) {
@@ -202,31 +229,10 @@ public class ProviderHelper {
}
}
- public PGPPublicKeyRing getPGPPublicKeyRingWithKeyId(long keyId)
- throws NotFoundException {
- Uri uri = KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId));
- long masterKeyId = getMasterKeyId(uri);
- return getPGPPublicKeyRing(masterKeyId);
- }
-
- public PGPSecretKeyRing getPGPSecretKeyRingWithKeyId(long keyId)
- throws NotFoundException {
- Uri uri = KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId));
- long masterKeyId = getMasterKeyId(uri);
- return getPGPSecretKeyRing(masterKeyId);
- }
-
- /**
- * Retrieves the actual PGPPublicKeyRing object from the database blob based on the masterKeyId
- */
- public PGPPublicKeyRing getPGPPublicKeyRing(long masterKeyId) throws NotFoundException {
- Uri queryUri = KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId));
- return (PGPPublicKeyRing) getPGPKeyRing(queryUri);
- }
-
/**
* Retrieves the actual PGPSecretKeyRing object from the database blob based on the maserKeyId
*/
+ @Deprecated
public PGPSecretKeyRing getPGPSecretKeyRing(long masterKeyId) throws NotFoundException {
Uri queryUri = KeyRingData.buildSecretKeyRingUri(Long.toString(masterKeyId));
return (PGPSecretKeyRing) getPGPKeyRing(queryUri);
@@ -395,8 +401,18 @@ public class ProviderHelper {
* Saves a PGPSecretKeyRing in the DB. This will only work if a corresponding public keyring
* is already in the database!
*/
+ public void saveKeyRing(UncachedSecretKeyRing wrappedRing) throws IOException {
+ // TODO split up getters
+ PGPSecretKeyRing keyRing = wrappedRing.getSecretKeyRing();
+ saveKeyRing(keyRing);
+ }
+
+ /**
+ * Saves a PGPSecretKeyRing in the DB. This will only work if a corresponding public keyring
+ * is already in the database!
+ */
public void saveKeyRing(PGPSecretKeyRing keyRing) throws IOException {
- long masterKeyId = keyRing.getPublicKey().getKeyID();
+ long masterKeyId = keyRing.getSecretKey().getKeyID();
{
Uri uri = Keys.buildKeysUri(Long.toString(masterKeyId));
@@ -433,6 +449,12 @@ public class ProviderHelper {
}
+ public void saveKeyRing(UncachedKeyRing wrappedRing) throws IOException {
+ PGPPublicKeyRing pubRing = wrappedRing.getPublicRing();
+ PGPSecretKeyRing secRing = wrappedRing.getSecretRing();
+ saveKeyRing(pubRing, secRing);
+ }
+
/**
* Saves (or updates) a pair of public and secret KeyRings in the database
*/