aboutsummaryrefslogtreecommitdiffstats
path: root/org_apg/src/org/thialfihar/android/apg/provider
diff options
context:
space:
mode:
Diffstat (limited to 'org_apg/src/org/thialfihar/android/apg/provider')
-rw-r--r--org_apg/src/org/thialfihar/android/apg/provider/ApgContract.java16
-rw-r--r--org_apg/src/org/thialfihar/android/apg/provider/ApgProvider.java110
-rw-r--r--org_apg/src/org/thialfihar/android/apg/provider/ApgProviderExternal.java32
-rw-r--r--org_apg/src/org/thialfihar/android/apg/provider/ApgProviderInternal.java30
-rw-r--r--org_apg/src/org/thialfihar/android/apg/provider/ProviderHelper.java4
5 files changed, 154 insertions, 38 deletions
diff --git a/org_apg/src/org/thialfihar/android/apg/provider/ApgContract.java b/org_apg/src/org/thialfihar/android/apg/provider/ApgContract.java
index 235d2d8ca..c68eec750 100644
--- a/org_apg/src/org/thialfihar/android/apg/provider/ApgContract.java
+++ b/org_apg/src/org/thialfihar/android/apg/provider/ApgContract.java
@@ -57,9 +57,11 @@ public class ApgContract {
public static final int SECRET = 1;
}
- public static final String CONTENT_AUTHORITY = Constants.PACKAGE_NAME;
+ public static final String CONTENT_AUTHORITY_EXTERNAL = Constants.PACKAGE_NAME;
+ public static final String CONTENT_AUTHORITY_INTERNAL = Constants.PACKAGE_NAME + ".internal";
- private static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
+ private static final Uri BASE_CONTENT_URI_INTERNAL = Uri.parse("content://"
+ + CONTENT_AUTHORITY_INTERNAL);
public static final String BASE_KEY_RINGS = "key_rings";
public static final String BASE_DATA = "data";
@@ -75,7 +77,7 @@ public class ApgContract {
public static final String PATH_KEYS = "keys";
public static class KeyRings implements KeyRingsColumns, BaseColumns {
- public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
+ public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
.appendPath(BASE_KEY_RINGS).build();
/** Use if multiple items get returned */
@@ -132,7 +134,7 @@ public class ApgContract {
}
public static class Keys implements KeysColumns, BaseColumns {
- public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
+ public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
.appendPath(BASE_KEY_RINGS).build();
/** Use if multiple items get returned */
@@ -163,7 +165,7 @@ public class ApgContract {
}
public static class UserIds implements UserIdsColumns, BaseColumns {
- public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
+ public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
.appendPath(BASE_KEY_RINGS).build();
/** Use if multiple items get returned */
@@ -194,8 +196,8 @@ public class ApgContract {
}
public static class DataStream {
- public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(BASE_DATA)
- .build();
+ public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
+ .appendPath(BASE_DATA).build();
public static Uri buildDataStreamUri(String streamFilename) {
return CONTENT_URI.buildUpon().appendPath(streamFilename).build();
diff --git a/org_apg/src/org/thialfihar/android/apg/provider/ApgProvider.java b/org_apg/src/org/thialfihar/android/apg/provider/ApgProvider.java
index 8e93365b7..10bc3cee5 100644
--- a/org_apg/src/org/thialfihar/android/apg/provider/ApgProvider.java
+++ b/org_apg/src/org/thialfihar/android/apg/provider/ApgProvider.java
@@ -47,8 +47,6 @@ import android.provider.BaseColumns;
import android.text.TextUtils;
public class ApgProvider extends ContentProvider {
- private static final UriMatcher sUriMatcher = buildUriMatcher();
-
private static final int PUBLIC_KEY_RING = 101;
private static final int PUBLIC_KEY_RING_BY_ROW_ID = 102;
private static final int PUBLIC_KEY_RING_BY_MASTER_KEY_ID = 103;
@@ -75,13 +73,22 @@ public class ApgProvider extends ContentProvider {
private static final int DATA_STREAM = 301;
+ protected static boolean sInternalProvider;
+ protected static UriMatcher sUriMatcher;
+
/**
* Build and return a {@link UriMatcher} that catches all {@link Uri} variations supported by
* this {@link ContentProvider}.
*/
- private static UriMatcher buildUriMatcher() {
+ protected static UriMatcher buildUriMatcher(boolean internalProvider) {
final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
- final String authority = ApgContract.CONTENT_AUTHORITY;
+
+ String authority;
+ if (internalProvider) {
+ authority = ApgContract.CONTENT_AUTHORITY_INTERNAL;
+ } else {
+ authority = ApgContract.CONTENT_AUTHORITY_EXTERNAL;
+ }
/**
* public key rings
@@ -283,8 +290,66 @@ public class ApgProvider extends ContentProvider {
return type;
}
- private SQLiteQueryBuilder buildKeyRingQuery(SQLiteQueryBuilder qb,
- HashMap<String, String> projectionMap, int match, boolean isMasterKey, String sortOrder) {
+ /**
+ * Set result of query to specific columns, don't show blob column for external content provider
+ *
+ * @return
+ */
+ private HashMap<String, String> getProjectionMapForKeyRings() {
+ HashMap<String, String> projectionMap = new HashMap<String, String>();
+
+ projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
+ projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
+ + KeyRingsColumns.MASTER_KEY_ID);
+ // only give out keyRing blob when we are using the internal content provider
+ if (sInternalProvider) {
+ projectionMap.put(KeyRingsColumns.KEY_RING_DATA, Tables.KEY_RINGS + "."
+ + KeyRingsColumns.KEY_RING_DATA);
+ }
+ projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "." + UserIdsColumns.USER_ID);
+
+ return projectionMap;
+ }
+
+ /**
+ * Set result of query to specific columns, don't show blob column for external content provider
+ *
+ * @return
+ */
+ private HashMap<String, String> getProjectionMapForKeys() {
+ HashMap<String, String> projectionMap = new HashMap<String, String>();
+
+ projectionMap.put(BaseColumns._ID, BaseColumns._ID);
+ projectionMap.put(KeysColumns.KEY_ID, KeysColumns.KEY_ID);
+ projectionMap.put(KeysColumns.IS_MASTER_KEY, KeysColumns.IS_MASTER_KEY);
+ projectionMap.put(KeysColumns.ALGORITHM, KeysColumns.ALGORITHM);
+ projectionMap.put(KeysColumns.KEY_SIZE, KeysColumns.KEY_SIZE);
+ projectionMap.put(KeysColumns.CAN_SIGN, KeysColumns.CAN_SIGN);
+ projectionMap.put(KeysColumns.CAN_ENCRYPT, KeysColumns.CAN_ENCRYPT);
+ projectionMap.put(KeysColumns.IS_REVOKED, KeysColumns.IS_REVOKED);
+ projectionMap.put(KeysColumns.CREATION, KeysColumns.CREATION);
+ projectionMap.put(KeysColumns.EXPIRY, KeysColumns.EXPIRY);
+ projectionMap.put(KeysColumns.KEY_RING_ROW_ID, KeysColumns.KEY_RING_ROW_ID);
+ // only give out keyRing blob when we are using the internal content provider
+ if (sInternalProvider) {
+ projectionMap.put(KeysColumns.KEY_DATA, KeysColumns.KEY_DATA);
+ }
+ projectionMap.put(KeysColumns.RANK, KeysColumns.RANK);
+
+ return projectionMap;
+ }
+
+ /**
+ * Builds default query for keyRings: KeyRings table is joined with Keys and UserIds
+ *
+ * @param qb
+ * @param match
+ * @param isMasterKey
+ * @param sortOrder
+ * @return
+ */
+ private SQLiteQueryBuilder buildKeyRingQuery(SQLiteQueryBuilder qb, int match,
+ boolean isMasterKey, String sortOrder) {
qb.appendWhere(Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + " = ");
qb.appendWhereEscapeString(Integer.toString(getKeyType(match)));
@@ -300,14 +365,7 @@ public class ApgProvider extends ContentProvider {
+ Tables.USER_IDS + "." + UserIdsColumns.KEY_RING_ROW_ID + " AND "
+ Tables.USER_IDS + "." + UserIdsColumns.RANK + " = '0')");
- projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
- projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
- + KeyRingsColumns.MASTER_KEY_ID);
- projectionMap.put(KeyRingsColumns.KEY_RING_DATA, Tables.KEY_RINGS + "."
- + KeyRingsColumns.KEY_RING_DATA);
- projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "." + UserIdsColumns.USER_ID);
-
- qb.setProjectionMap(projectionMap);
+ qb.setProjectionMap(getProjectionMapForKeyRings());
return qb;
}
@@ -322,14 +380,12 @@ public class ApgProvider extends ContentProvider {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
SQLiteDatabase db = mApgDatabase.getReadableDatabase();
- HashMap<String, String> projectionMap = new HashMap<String, String>();
-
int match = sUriMatcher.match(uri);
switch (match) {
case PUBLIC_KEY_RING:
case SECRET_KEY_RING:
- qb = buildKeyRingQuery(qb, projectionMap, match, true, sortOrder);
+ qb = buildKeyRingQuery(qb, match, true, sortOrder);
if (TextUtils.isEmpty(sortOrder)) {
sortOrder = Tables.USER_IDS + "." + UserIdsColumns.USER_ID + " ASC";
@@ -339,7 +395,7 @@ public class ApgProvider extends ContentProvider {
case PUBLIC_KEY_RING_BY_ROW_ID:
case SECRET_KEY_RING_BY_ROW_ID:
- qb = buildKeyRingQuery(qb, projectionMap, match, true, sortOrder);
+ qb = buildKeyRingQuery(qb, match, true, sortOrder);
qb.appendWhere(" AND " + Tables.KEY_RINGS + "." + BaseColumns._ID + " = ");
qb.appendWhereEscapeString(uri.getLastPathSegment());
@@ -352,7 +408,7 @@ public class ApgProvider extends ContentProvider {
case PUBLIC_KEY_RING_BY_MASTER_KEY_ID:
case SECRET_KEY_RING_BY_MASTER_KEY_ID:
- qb = buildKeyRingQuery(qb, projectionMap, match, true, sortOrder);
+ qb = buildKeyRingQuery(qb, match, true, sortOrder);
qb.appendWhere(" AND " + Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID + " = ");
qb.appendWhereEscapeString(uri.getLastPathSegment());
@@ -365,7 +421,7 @@ public class ApgProvider extends ContentProvider {
case SECRET_KEY_RING_BY_KEY_ID:
case PUBLIC_KEY_RING_BY_KEY_ID:
- qb = buildKeyRingQuery(qb, projectionMap, match, false, sortOrder);
+ qb = buildKeyRingQuery(qb, match, false, sortOrder);
qb.appendWhere(" AND " + Tables.KEYS + "." + KeysColumns.KEY_ID + " = ");
qb.appendWhereEscapeString(uri.getLastPathSegment());
@@ -389,15 +445,7 @@ public class ApgProvider extends ContentProvider {
+ Tables.USER_IDS + "." + UserIdsColumns.KEY_RING_ROW_ID + " AND "
+ Tables.USER_IDS + "." + UserIdsColumns.RANK + " = '0')");
- projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
- projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
- + KeyRingsColumns.MASTER_KEY_ID);
- projectionMap.put(KeyRingsColumns.KEY_RING_DATA, Tables.KEY_RINGS + "."
- + KeyRingsColumns.KEY_RING_DATA);
- projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "."
- + UserIdsColumns.USER_ID);
-
- qb.setProjectionMap(projectionMap);
+ qb.setProjectionMap(getProjectionMapForKeyRings());
String emails = uri.getLastPathSegment();
String chunks[] = emails.split(" *, *");
@@ -434,6 +482,8 @@ public class ApgProvider extends ContentProvider {
qb.appendWhere(" AND " + KeysColumns.KEY_RING_ROW_ID + " = ");
qb.appendWhereEscapeString(uri.getPathSegments().get(2));
+ qb.setProjectionMap(getProjectionMapForKeys());
+
break;
case PUBLIC_KEY_RING_KEY_BY_ROW_ID:
@@ -448,6 +498,8 @@ public class ApgProvider extends ContentProvider {
qb.appendWhere(" AND " + BaseColumns._ID + " = ");
qb.appendWhereEscapeString(uri.getLastPathSegment());
+ qb.setProjectionMap(getProjectionMapForKeys());
+
break;
case PUBLIC_KEY_RING_USER_ID:
diff --git a/org_apg/src/org/thialfihar/android/apg/provider/ApgProviderExternal.java b/org_apg/src/org/thialfihar/android/apg/provider/ApgProviderExternal.java
new file mode 100644
index 000000000..61cca8bed
--- /dev/null
+++ b/org_apg/src/org/thialfihar/android/apg/provider/ApgProviderExternal.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.thialfihar.android.apg.provider;
+
+/**
+ * The same content provider as ApgProviderInternal except that it does not give out keyRing and key
+ * blob data when querying.
+ *
+ * This provider is exported with a readPermission in AndroidManifest.xml
+ */
+public class ApgProviderExternal extends ApgProvider {
+
+ static {
+ sInternalProvider = false;
+ sUriMatcher = buildUriMatcher(sInternalProvider);
+ }
+
+}
diff --git a/org_apg/src/org/thialfihar/android/apg/provider/ApgProviderInternal.java b/org_apg/src/org/thialfihar/android/apg/provider/ApgProviderInternal.java
new file mode 100644
index 000000000..e2226a0fa
--- /dev/null
+++ b/org_apg/src/org/thialfihar/android/apg/provider/ApgProviderInternal.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.thialfihar.android.apg.provider;
+
+/**
+ * This provider is NOT exported in AndroidManifest.xml as it also return the actual secret keys
+ * from the database
+ */
+public class ApgProviderInternal extends ApgProvider {
+
+ static {
+ sInternalProvider = true;
+ sUriMatcher = buildUriMatcher(sInternalProvider);
+ }
+
+}
diff --git a/org_apg/src/org/thialfihar/android/apg/provider/ProviderHelper.java b/org_apg/src/org/thialfihar/android/apg/provider/ProviderHelper.java
index 6b3e94938..915c0aea5 100644
--- a/org_apg/src/org/thialfihar/android/apg/provider/ProviderHelper.java
+++ b/org_apg/src/org/thialfihar/android/apg/provider/ProviderHelper.java
@@ -232,7 +232,7 @@ public class ProviderHelper {
}
try {
- context.getContentResolver().applyBatch(ApgContract.CONTENT_AUTHORITY, operations);
+ context.getContentResolver().applyBatch(ApgContract.CONTENT_AUTHORITY_INTERNAL, operations);
} catch (RemoteException e) {
Log.e(Constants.TAG, "applyBatch failed!", e);
} catch (OperationApplicationException e) {
@@ -288,7 +288,7 @@ public class ProviderHelper {
}
try {
- context.getContentResolver().applyBatch(ApgContract.CONTENT_AUTHORITY, operations);
+ context.getContentResolver().applyBatch(ApgContract.CONTENT_AUTHORITY_INTERNAL, operations);
} catch (RemoteException e) {
Log.e(Constants.TAG, "applyBatch failed!", e);
} catch (OperationApplicationException e) {