diff options
Diffstat (limited to 'OpenKeychain/src/main')
6 files changed, 79 insertions, 28 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java index 2e9551826..65bc6381b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java @@ -20,6 +20,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; +import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; @@ -191,6 +192,9 @@ public class CertifyOperation extends BaseOperation { } log.add(LogType.MSG_CRT_SUCCESS, 0); + //since only verified keys are synced to contacts, we need to initiate a sync now + ContactSyncAdapterService.requestSync(); + return new CertifyResult(CertifyResult.RESULT_OK, log, certifyOk, certifyError, uploadOk, uploadError); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedUserAttribute.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedUserAttribute.java index 8e23d36d9..2c7f0187a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedUserAttribute.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedUserAttribute.java @@ -109,6 +109,15 @@ public class WrappedUserAttribute implements Serializable { } + public byte[][] getSubpackets() { + UserAttributeSubpacket[] subpackets = mVector.toSubpacketArray(); + byte[][] ret = new byte[subpackets.length][]; + for (int i = 0; i < subpackets.length; i++) { + ret[i] = subpackets[i].getData(); + } + return ret; + } + private void readObjectNoData() throws ObjectStreamException { } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java index b88cd6006..4a162989f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java @@ -53,7 +53,7 @@ import java.io.IOException; */ public class KeychainDatabase extends SQLiteOpenHelper { private static final String DATABASE_NAME = "openkeychain.db"; - private static final int DATABASE_VERSION = 8; + private static final int DATABASE_VERSION = 9; static Boolean apgHack = false; private Context mContext; @@ -61,7 +61,7 @@ public class KeychainDatabase extends SQLiteOpenHelper { String KEY_RINGS_PUBLIC = "keyrings_public"; String KEY_RINGS_SECRET = "keyrings_secret"; String KEYS = "keys"; - String USER_PACKETS = "user_ids"; + String USER_PACKETS = "user_packets"; String CERTS = "certs"; String API_APPS = "api_apps"; String API_ACCOUNTS = "api_accounts"; @@ -119,8 +119,7 @@ public class KeychainDatabase extends SQLiteOpenHelper { + UserPacketsColumns.IS_REVOKED + " INTEGER, " + UserPacketsColumns.RANK+ " INTEGER, " - + "PRIMARY KEY(" + UserPacketsColumns.MASTER_KEY_ID + ", " + UserPacketsColumns.USER_ID + "), " - + "UNIQUE (" + UserPacketsColumns.MASTER_KEY_ID + ", " + UserPacketsColumns.RANK + "), " + + "PRIMARY KEY(" + UserPacketsColumns.MASTER_KEY_ID + ", " + UserPacketsColumns.RANK + "), " + "FOREIGN KEY(" + UserPacketsColumns.MASTER_KEY_ID + ") REFERENCES " + Tables.KEY_RINGS_PUBLIC + "(" + KeyRingsColumns.MASTER_KEY_ID + ") ON DELETE CASCADE" + ")"; @@ -267,6 +266,13 @@ public class KeychainDatabase extends SQLiteOpenHelper { } catch (Exception e) { // never mind, the column probably already existed } + case 9: + // tbale name for user_ids changed to user_packets + db.execSQL("DROP TABLE IF EXISTS certs"); + db.execSQL("DROP TABLE IF EXISTS user_ids"); + db.execSQL(CREATE_USER_PACKETS); + db.execSQL(CREATE_CERTS); + } // always do consolidate after upgrade 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 6cd251be5..1d3934620 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -1082,9 +1082,8 @@ public class ProviderHelper { log.add(LogType.MSG_CON_SAVE_SECRET, indent); indent += 1; - final Cursor cursor = mContentResolver.query(KeyRings.buildUnifiedKeyRingsUri(), new String[]{ - KeyRings.PRIVKEY_DATA, KeyRings.FINGERPRINT, KeyRings.HAS_ANY_SECRET - }, KeyRings.HAS_ANY_SECRET + " = 1", null, null); + final Cursor cursor = mContentResolver.query(KeyRingData.buildSecretKeyRingUri(), + new String[]{ KeyRingData.KEY_RING_DATA }, null, null, null); if (cursor == null) { log.add(LogType.MSG_CON_ERROR_DB, indent); @@ -1106,8 +1105,7 @@ public class ProviderHelper { if (cursor.isAfterLast()) { return false; } - ring = new ParcelableKeyRing(KeyFormattingUtils.convertFingerprintToHex(cursor.getBlob(1)), cursor.getBlob(0) - ); + ring = new ParcelableKeyRing(cursor.getBlob(0)); cursor.moveToNext(); return true; } @@ -1144,9 +1142,9 @@ public class ProviderHelper { log.add(LogType.MSG_CON_SAVE_PUBLIC, indent); indent += 1; - final Cursor cursor = mContentResolver.query(KeyRings.buildUnifiedKeyRingsUri(), new String[]{ - KeyRings.PUBKEY_DATA, KeyRings.FINGERPRINT - }, null, null, null); + final Cursor cursor = mContentResolver.query( + KeyRingData.buildPublicKeyRingUri(), + new String[]{ KeyRingData.KEY_RING_DATA }, null, null, null); if (cursor == null) { log.add(LogType.MSG_CON_ERROR_DB, indent); @@ -1168,8 +1166,7 @@ public class ProviderHelper { if (cursor.isAfterLast()) { return false; } - ring = new ParcelableKeyRing(KeyFormattingUtils.convertFingerprintToHex(cursor.getBlob(1)), cursor.getBlob(0) - ); + ring = new ParcelableKeyRing(cursor.getBlob(0)); cursor.moveToNext(); return true; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java index bb3df2541..eae283269 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java @@ -53,7 +53,7 @@ public class ViewKeyFragment extends LoaderFragment implements //private ListView mLinkedSystemContact; boolean mIsSecret = false; - private String mName; + boolean mSystemContactLoaded = false; LinearLayout mSystemContactLayout; ImageView mSystemContactPicture; @@ -120,17 +120,17 @@ public class ViewKeyFragment extends LoaderFragment implements * Checks if a system contact exists for given masterKeyId, and if it does, sets name, picture * and onClickListener for the linked system contact's layout * - * @param name * @param masterKeyId */ - private void loadLinkedSystemContact(String name, final long masterKeyId) { + private void loadLinkedSystemContact(final long masterKeyId) { final Context context = mSystemContactName.getContext(); final ContentResolver resolver = context.getContentResolver(); final long contactId = ContactHelper.findContactId(resolver, masterKeyId); + final String contactName = ContactHelper.getContactName(resolver, contactId); - if (contactId != -1) {//contact exists for given master key - mSystemContactName.setText(name); + if (contactName != null) {//contact name exists for given master key + mSystemContactName.setText(contactName); Bitmap picture = ContactHelper.loadPhotoByMasterKeyId(resolver, masterKeyId, true); if (picture != null) mSystemContactPicture.setImageBitmap(picture); @@ -141,6 +141,7 @@ public class ViewKeyFragment extends LoaderFragment implements launchContactActivity(contactId, context); } }); + mSystemContactLoaded = true; } } @@ -238,14 +239,14 @@ public class ViewKeyFragment extends LoaderFragment implements switch (loader.getId()) { case LOADER_ID_UNIFIED: { if (data.moveToFirst()) { - - mIsSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0; - if (mName == null) {//to ensure we load the linked system contact only once - String[] mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID)); - mName = mainUserId[0]; + //TODO system to allow immediate refreshing of system contact on verification + if (!mSystemContactLoaded) {//ensure we load linked system contact only once long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID); - loadLinkedSystemContact(mName, masterKeyId); + loadLinkedSystemContact(masterKeyId); } + + mIsSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0; + // load user ids after we know if it's a secret key mUserIdsAdapter = new UserIdsAdapter(getActivity(), null, 0, !mIsSecret, null); mUserIds.setAdapter(mUserIdsAdapter); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java index 1413273e8..b3eb36157 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java @@ -296,6 +296,34 @@ public class ContactHelper { return contactId; } + /** + * Returns the display name of the system contact associated with contactId, null if the + * contact does not exist + * + * @param resolver + * @param contactId + * @return primary display name of system contact associated with contactId, null if it does + * not exist + */ + public static String getContactName(ContentResolver resolver, long contactId) { + String contactName = null; + Cursor raw = resolver.query(ContactsContract.Contacts.CONTENT_URI, + new String[]{ + ContactsContract.Contacts.DISPLAY_NAME_PRIMARY + }, + ContactsContract.Contacts._ID + "=?", + new String[]{//"0" for "not deleted" + Long.toString(contactId) + }, null); + if (raw != null) { + if (raw.moveToNext()) { + contactName = raw.getString(0); + } + raw.close(); + } + return contactName; + } + public static Bitmap getCachedPhotoByMasterKeyId(ContentResolver contentResolver, long masterKeyId) { if (masterKeyId == -1) { return null; @@ -333,12 +361,16 @@ public class ContactHelper { KeychainContract.KeyRings.MASTER_KEY_ID, KeychainContract.KeyRings.USER_ID, KeychainContract.KeyRings.IS_EXPIRED, - KeychainContract.KeyRings.IS_REVOKED}; + KeychainContract.KeyRings.IS_REVOKED, + KeychainContract.KeyRings.VERIFIED, + KeychainContract.KeyRings.HAS_SECRET}; public static final int INDEX_MASTER_KEY_ID = 0; public static final int INDEX_USER_ID = 1; public static final int INDEX_IS_EXPIRED = 2; public static final int INDEX_IS_REVOKED = 3; + public static final int INDEX_VERIFIED = 4; + public static final int INDEX_HAS_SECRET = 5; /** * Write/Update the current OpenKeychain keys to the contact db @@ -373,6 +405,8 @@ public class ContactHelper { String keyIdShort = KeyFormattingUtils.convertKeyIdToHexShort(cursor.getLong(INDEX_MASTER_KEY_ID)); boolean isExpired = cursor.getInt(INDEX_IS_EXPIRED) != 0; boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0; + boolean isVerified = cursor.getInt(INDEX_VERIFIED) > 0; + boolean isSecret = cursor.getInt(INDEX_HAS_SECRET) != 0; Log.d(Constants.TAG, "masterKeyId: " + masterKeyId); @@ -385,8 +419,8 @@ public class ContactHelper { ArrayList<ContentProviderOperation> ops = new ArrayList<>(); // Do not store expired or revoked keys in contact db - and remove them if they already exist - if (isExpired || isRevoked) { - Log.d(Constants.TAG, "Expired or revoked: Deleting rawContactId " + rawContactId); + if (isExpired || isRevoked || !isVerified&&!isSecret) { + Log.d(Constants.TAG, "Expired or revoked or unverified: Deleting rawContactId " + rawContactId); if (rawContactId != -1) { deleteRawContactById(resolver, rawContactId); } |