certs: more fixes, almost working now

This commit is contained in:
Vincent Breitmoser 2014-04-05 21:38:03 +02:00
parent aa6f5118f5
commit 2802718efb
5 changed files with 52 additions and 38 deletions

View File

@ -369,19 +369,29 @@ public class KeychainProvider extends ContentProvider {
case KEY_RING_USER_IDS: { case KEY_RING_USER_IDS: {
HashMap<String, String> projectionMap = new HashMap<String, String>(); HashMap<String, String> projectionMap = new HashMap<String, String>();
projectionMap.put(UserIds._ID, Tables.USER_IDS + ".oid AS _id"); projectionMap.put(UserIds._ID, Tables.USER_IDS + ".oid AS _id");
projectionMap.put(UserIds.MASTER_KEY_ID, UserIds.MASTER_KEY_ID); projectionMap.put(UserIds.MASTER_KEY_ID, Tables.USER_IDS + "." + UserIds.MASTER_KEY_ID);
projectionMap.put(UserIds.USER_ID, UserIds.USER_ID); projectionMap.put(UserIds.USER_ID, Tables.USER_IDS + "." + UserIds.USER_ID);
projectionMap.put(UserIds.RANK, UserIds.RANK); projectionMap.put(UserIds.RANK, Tables.USER_IDS + "." + UserIds.RANK);
projectionMap.put(UserIds.IS_PRIMARY, UserIds.IS_PRIMARY); projectionMap.put(UserIds.IS_PRIMARY, Tables.USER_IDS + "." + UserIds.IS_PRIMARY);
projectionMap.put(UserIds.VERIFIED, "0 AS " + UserIds.VERIFIED); // we take the minimum (>0) here, where "1" is "verified by known secret key"
projectionMap.put(UserIds.VERIFIED, "MIN(" + Certs.VERIFIED + ") AS " + UserIds.VERIFIED);
qb.setProjectionMap(projectionMap); qb.setProjectionMap(projectionMap);
qb.setTables(Tables.USER_IDS); qb.setTables(Tables.USER_IDS
qb.appendWhere(UserIds.MASTER_KEY_ID + " = "); + " LEFT JOIN " + Tables.CERTS + " ON ("
+ Tables.USER_IDS + "." + UserIds.MASTER_KEY_ID + " = "
+ Tables.CERTS + "." + Certs.MASTER_KEY_ID
+ " AND " + Tables.USER_IDS + "." + UserIds.RANK + " = "
+ Tables.CERTS + "." + Certs.RANK
+ " AND " + Tables.CERTS + "." + Certs.VERIFIED + " > 0"
+ ")");
groupBy = Tables.USER_IDS + "." + UserIds.RANK;
qb.appendWhere(Tables.USER_IDS + "." + UserIds.MASTER_KEY_ID + " = ");
qb.appendWhereEscapeString(uri.getPathSegments().get(1)); qb.appendWhereEscapeString(uri.getPathSegments().get(1));
if (TextUtils.isEmpty(sortOrder)) { if (TextUtils.isEmpty(sortOrder)) {
sortOrder = UserIds.RANK + " ASC"; sortOrder = Tables.USER_IDS + "." + UserIds.RANK + " ASC";
} }
break; break;
@ -433,9 +443,7 @@ public class KeychainProvider extends ContentProvider {
projectionMap.put(Certs.KEY_ID_CERTIFIER, Tables.CERTS + "." + Certs.KEY_ID_CERTIFIER); projectionMap.put(Certs.KEY_ID_CERTIFIER, Tables.CERTS + "." + Certs.KEY_ID_CERTIFIER);
projectionMap.put(Certs.VERIFIED, Tables.CERTS + "." + Certs.VERIFIED); projectionMap.put(Certs.VERIFIED, Tables.CERTS + "." + Certs.VERIFIED);
projectionMap.put(Certs.KEY_DATA, Tables.CERTS + "." + Certs.KEY_DATA); projectionMap.put(Certs.KEY_DATA, Tables.CERTS + "." + Certs.KEY_DATA);
// verified key data
projectionMap.put(Certs.USER_ID, Tables.USER_IDS + "." + UserIds.USER_ID); projectionMap.put(Certs.USER_ID, Tables.USER_IDS + "." + UserIds.USER_ID);
// verifying key data
projectionMap.put(Certs.SIGNER_UID, "signer." + UserIds.USER_ID + " AS " + Certs.SIGNER_UID); projectionMap.put(Certs.SIGNER_UID, "signer." + UserIds.USER_ID + " AS " + Certs.SIGNER_UID);
qb.setProjectionMap(projectionMap); qb.setProjectionMap(projectionMap);
@ -447,7 +455,7 @@ public class KeychainProvider extends ContentProvider {
+ Tables.CERTS + "." + Certs.RANK + " = " + Tables.CERTS + "." + Certs.RANK + " = "
+ Tables.USER_IDS + "." + UserIds.RANK + Tables.USER_IDS + "." + UserIds.RANK
+ ") LEFT JOIN " + Tables.USER_IDS + " AS signer ON (" + ") LEFT JOIN " + Tables.USER_IDS + " AS signer ON ("
+ Tables.CERTS + "." + Keys.MASTER_KEY_ID + " = " + Tables.CERTS + "." + Certs.KEY_ID_CERTIFIER + " = "
+ "signer." + UserIds.MASTER_KEY_ID + "signer." + UserIds.MASTER_KEY_ID
+ " AND " + " AND "
+ "signer." + Keys.RANK + " = 0" + "signer." + Keys.RANK + " = 0"
@ -553,7 +561,9 @@ public class KeychainProvider extends ContentProvider {
break; break;
case KEY_RING_CERTS: case KEY_RING_CERTS:
db.insertOrThrow(Tables.CERTS, null, values); // we replace here, keeping only the latest signature
// TODO this would be better handled in saveKeyRing directly!
db.replaceOrThrow(Tables.CERTS, null, values);
keyId = values.getAsLong(Certs.MASTER_KEY_ID); keyId = values.getAsLong(Certs.MASTER_KEY_ID);
break; break;

View File

@ -223,6 +223,9 @@ public class ProviderHelper {
// get a list of owned secret keys, for verification filtering // get a list of owned secret keys, for verification filtering
Map<Long, PGPKeyRing> allKeyRings = getPGPKeyRings(context, KeyRingData.buildSecretKeyRingUri()); Map<Long, PGPKeyRing> allKeyRings = getPGPKeyRings(context, KeyRingData.buildSecretKeyRingUri());
// special case: available secret keys verify themselves!
if(secretRing != null)
allKeyRings.put(secretRing.getSecretKey().getKeyID(), secretRing);
int userIdRank = 0; int userIdRank = 0;
for (String userId : new IterableIterator<String>(masterKey.getUserIDs())) { for (String userId : new IterableIterator<String>(masterKey.getUserIDs())) {

View File

@ -38,8 +38,8 @@ import android.widget.TextView;
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.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import se.emilsjolander.stickylistheaders.ApiLevelTooLowException; import se.emilsjolander.stickylistheaders.ApiLevelTooLowException;
@ -52,20 +52,20 @@ public class ViewKeyCertsFragment extends Fragment
// These are the rows that we will retrieve. // These are the rows that we will retrieve.
static final String[] PROJECTION = new String[] { static final String[] PROJECTION = new String[] {
KeychainContract.Certs._ID, Certs._ID,
KeychainContract.Certs.MASTER_KEY_ID, Certs.MASTER_KEY_ID,
KeychainContract.Certs.VERIFIED, Certs.VERIFIED,
KeychainContract.Certs.RANK, Certs.RANK,
KeychainContract.Certs.KEY_ID_CERTIFIER, Certs.KEY_ID_CERTIFIER,
KeychainContract.Certs.USER_ID, Certs.USER_ID,
KeychainContract.Certs.SIGNER_UID Certs.SIGNER_UID
}; };
// sort by our user id, // sort by our user id,
static final String SORT_ORDER = static final String SORT_ORDER =
KeychainDatabase.Tables.USER_IDS + "." + KeychainContract.UserIds.RANK + " ASC, " Tables.CERTS + "." + Certs.RANK + " ASC, "
+ KeychainDatabase.Tables.CERTS + "." + KeychainContract.Certs.VERIFIED + " DESC, " + Certs.VERIFIED + " DESC, "
+ KeychainContract.Certs.SIGNER_UID + " ASC"; + Certs.SIGNER_UID + " ASC";
public static final String ARG_DATA_URI = "data_uri"; public static final String ARG_DATA_URI = "data_uri";
@ -133,7 +133,7 @@ public class ViewKeyCertsFragment extends Fragment
} }
Uri uri = getArguments().getParcelable(ARG_DATA_URI); Uri uri = getArguments().getParcelable(ARG_DATA_URI);
mBaseUri = KeychainContract.Certs.buildCertsUri(uri); mBaseUri = Certs.buildCertsUri(uri);
mStickyList.setAreHeadersSticky(true); mStickyList.setAreHeadersSticky(true);
mStickyList.setDrawingListUnderStickyHeader(false); mStickyList.setDrawingListUnderStickyHeader(false);
@ -185,7 +185,7 @@ public class ViewKeyCertsFragment extends Fragment
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent viewIntent = null; Intent viewIntent = null;
viewIntent = new Intent(getActivity(), ViewCertActivity.class); viewIntent = new Intent(getActivity(), ViewCertActivity.class);
viewIntent.setData(KeychainContract.Certs.buildCertsUri(Long.toString(id))); viewIntent.setData(Certs.buildCertsUri(Long.toString(id)));
startActivity(viewIntent); startActivity(viewIntent);
} }
@ -230,12 +230,12 @@ public class ViewKeyCertsFragment extends Fragment
private void initIndex(Cursor cursor) { private void initIndex(Cursor cursor) {
if (cursor != null) { if (cursor != null) {
mIndexCertId = cursor.getColumnIndexOrThrow(KeychainContract.Certs.MASTER_KEY_ID); mIndexCertId = cursor.getColumnIndexOrThrow(Certs.MASTER_KEY_ID);
mIndexUserId = cursor.getColumnIndexOrThrow(KeychainContract.UserIds.USER_ID); mIndexUserId = cursor.getColumnIndexOrThrow(Certs.USER_ID);
mIndexRank = cursor.getColumnIndexOrThrow(KeychainContract.UserIds.RANK); mIndexRank = cursor.getColumnIndexOrThrow(Certs.RANK);
mIndexVerified = cursor.getColumnIndexOrThrow(KeychainContract.Certs.VERIFIED); mIndexVerified = cursor.getColumnIndexOrThrow(Certs.VERIFIED);
mIndexSignerKeyId = cursor.getColumnIndexOrThrow(KeychainContract.Certs.KEY_ID_CERTIFIER); mIndexSignerKeyId = cursor.getColumnIndexOrThrow(Certs.KEY_ID_CERTIFIER);
mIndexSignerUserId = cursor.getColumnIndexOrThrow(KeychainContract.Certs.SIGNER_UID); mIndexSignerUserId = cursor.getColumnIndexOrThrow(Certs.SIGNER_UID);
} }
} }

View File

@ -39,7 +39,6 @@ import com.beardedhen.androidbootstrap.BootstrapButton;
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.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
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.KeychainContract.UserIds; import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
@ -176,7 +175,7 @@ public class ViewKeyMainFragment extends Fragment implements
static final int INDEX_UNIFIED_EXPIRY = 8; static final int INDEX_UNIFIED_EXPIRY = 8;
static final String[] USER_IDS_PROJECTION = new String[] { static final String[] USER_IDS_PROJECTION = new String[] {
UserIds._ID, UserIds.USER_ID, UserIds.RANK, UserIds._ID, UserIds.USER_ID, UserIds.RANK, UserIds.VERIFIED
}; };
static final String[] KEYS_PROJECTION = new String[] { static final String[] KEYS_PROJECTION = new String[] {

View File

@ -84,7 +84,7 @@ public class ViewKeyUserIdsAdapter extends CursorAdapter {
if (cursor != null) { if (cursor != null) {
mIndexUserId = cursor.getColumnIndexOrThrow(UserIds.USER_ID); mIndexUserId = cursor.getColumnIndexOrThrow(UserIds.USER_ID);
mIndexRank = cursor.getColumnIndexOrThrow(UserIds.RANK); mIndexRank = cursor.getColumnIndexOrThrow(UserIds.RANK);
// mVerifiedId = cursor.getColumnIndexOrThrow(UserIds.VERIFIED); mVerifiedId = cursor.getColumnIndexOrThrow(UserIds.VERIFIED);
} }
} }
@ -106,10 +106,12 @@ public class ViewKeyUserIdsAdapter extends CursorAdapter {
} }
vAddress.setText(userId[1]); vAddress.setText(userId[1]);
int verified = 1; // cursor.getInt(mVerifiedId); int verified = cursor.getInt(mVerifiedId);
// TODO introduce own resource for this :) // TODO introduce own resources for this :)
if(verified > 0) if(verified == 1)
vVerified.setImageResource(android.R.drawable.presence_online); vVerified.setImageResource(android.R.drawable.presence_online);
else if(verified > 1)
vVerified.setImageResource(android.R.drawable.presence_away);
else else
vVerified.setImageResource(android.R.drawable.presence_invisible); vVerified.setImageResource(android.R.drawable.presence_invisible);