trust id -> autocrypt peer

This commit is contained in:
Vincent Breitmoser
2017-06-13 18:33:21 +02:00
parent 4e4912bd6d
commit 1e620e01aa
11 changed files with 193 additions and 199 deletions

View File

@@ -1,6 +1,5 @@
/* /*
* Copyright (C) 2012-2014 Dominik Schürmann <dominik@dominikschuermann.de> * Copyright (C) 2017 Vincent Breitmoser <v.breitmoser@mugenguild.com>
* Copyright (C) 2014-2016 Vincent Breitmoser <v.breitmoser@mugenguild.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -27,15 +26,15 @@ import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiTrustIdentity; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAutocryptPeer;
public class TrustIdentityDataAccessObject { public class AutocryptPeerDataAccessObject {
private final SimpleContentResolverInterface mQueryInterface; private final SimpleContentResolverInterface mQueryInterface;
private final String packageName; private final String packageName;
public TrustIdentityDataAccessObject(Context context, String packageName) { public AutocryptPeerDataAccessObject(Context context, String packageName) {
this.packageName = packageName; this.packageName = packageName;
final ContentResolver contentResolver = context.getContentResolver(); final ContentResolver contentResolver = context.getContentResolver();
@@ -63,18 +62,18 @@ public class TrustIdentityDataAccessObject {
}; };
} }
public TrustIdentityDataAccessObject(SimpleContentResolverInterface queryInterface, String packageName) { public AutocryptPeerDataAccessObject(SimpleContentResolverInterface queryInterface, String packageName) {
mQueryInterface = queryInterface; mQueryInterface = queryInterface;
this.packageName = packageName; this.packageName = packageName;
} }
public Long getMasterKeyIdForTrustId(String trustId) { public Long getMasterKeyIdForAutocryptPeer(String autocryptId) {
Cursor cursor = mQueryInterface.query( Cursor cursor = mQueryInterface.query(
ApiTrustIdentity.buildByPackageNameAndTrustId(packageName, trustId), null, null, null, null); ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId), null, null, null, null);
try { try {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
int masterKeyIdColumn = cursor.getColumnIndex(ApiTrustIdentity.MASTER_KEY_ID); int masterKeyIdColumn = cursor.getColumnIndex(ApiAutocryptPeer.MASTER_KEY_ID);
return cursor.getLong(masterKeyIdColumn); return cursor.getLong(masterKeyIdColumn);
} }
} finally { } finally {
@@ -86,13 +85,13 @@ public class TrustIdentityDataAccessObject {
return null; return null;
} }
public Date getLastUpdateForTrustId(String trustId) { public Date getLastUpdateForAutocryptPeer(String autocryptId) {
Cursor cursor = mQueryInterface.query(ApiTrustIdentity.buildByPackageNameAndTrustId(packageName, trustId), Cursor cursor = mQueryInterface.query(ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId),
null, null, null, null); null, null, null, null);
try { try {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
long lastUpdated = cursor.getColumnIndex(ApiTrustIdentity.LAST_UPDATED); long lastUpdated = cursor.getColumnIndex(ApiAutocryptPeer.LAST_UPDATED);
return new Date(lastUpdated); return new Date(lastUpdated);
} }
} finally { } finally {
@@ -103,15 +102,15 @@ public class TrustIdentityDataAccessObject {
return null; return null;
} }
public void setMasterKeyIdForTrustId(String trustId, long masterKeyId, Date date) { public void setMasterKeyIdForAutocryptPeer(String autocryptId, long masterKeyId, Date date) {
Date lastUpdated = getLastUpdateForTrustId(trustId); Date lastUpdated = getLastUpdateForAutocryptPeer(autocryptId);
if (lastUpdated != null && lastUpdated.after(date)) { if (lastUpdated != null && lastUpdated.after(date)) {
throw new IllegalArgumentException("Database entry was newer than the one to be inserted! Cannot backdate"); throw new IllegalArgumentException("Database entry was newer than the one to be inserted! Cannot backdate");
} }
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
cv.put(ApiTrustIdentity.MASTER_KEY_ID, masterKeyId); cv.put(ApiAutocryptPeer.MASTER_KEY_ID, masterKeyId);
cv.put(ApiTrustIdentity.LAST_UPDATED, date.getTime()); cv.put(ApiAutocryptPeer.LAST_UPDATED, date.getTime());
mQueryInterface.update(ApiTrustIdentity.buildByPackageNameAndTrustId(packageName, trustId), cv, null, null); mQueryInterface.update(ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId), cv, null, null);
} }
} }

View File

@@ -62,7 +62,7 @@ import org.sufficientlysecure.keychain.pgp.UncachedPublicKey;
import org.sufficientlysecure.keychain.pgp.WrappedSignature; import org.sufficientlysecure.keychain.pgp.WrappedSignature;
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiTrustIdentity; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAutocryptPeer;
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
@@ -603,7 +603,7 @@ public class KeyWritableRepository extends KeyRepository {
android.util.Log.e(Constants.TAG, "Could not delete file!", e); android.util.Log.e(Constants.TAG, "Could not delete file!", e);
return false; return false;
} }
mContentResolver.delete(ApiTrustIdentity.buildByMasterKeyId(masterKeyId),null, null); mContentResolver.delete(ApiAutocryptPeer.buildByMasterKeyId(masterKeyId),null, null);
int deletedRows = mContentResolver.delete(KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null); int deletedRows = mContentResolver.delete(KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null);
return deletedRows > 0; return deletedRows > 0;
} }

View File

@@ -95,7 +95,7 @@ public class KeychainContract {
String IDENTIFIER = "identifier"; String IDENTIFIER = "identifier";
} }
interface ApiTrustIdentityColumns { interface ApiAutocryptPeerColumns {
String PACKAGE_NAME = "package_name"; String PACKAGE_NAME = "package_name";
String IDENTIFIER = "identifier"; String IDENTIFIER = "identifier";
String LAST_UPDATED = "last_updated"; String LAST_UPDATED = "last_updated";
@@ -131,7 +131,7 @@ public class KeychainContract {
public static final String PATH_BY_PACKAGE_NAME = "by_package_name"; public static final String PATH_BY_PACKAGE_NAME = "by_package_name";
public static final String PATH_BY_KEY_ID = "by_key_id"; public static final String PATH_BY_KEY_ID = "by_key_id";
public static final String BASE_TRUST_IDENTITIES = "trust_ids"; public static final String BASE_AUTOCRYPT_PEERS = "autocrypt_peers";
public static class KeyRings implements BaseColumns, KeysColumns, UserPacketsColumns { public static class KeyRings implements BaseColumns, KeysColumns, UserPacketsColumns {
public static final String MASTER_KEY_ID = KeysColumns.MASTER_KEY_ID; public static final String MASTER_KEY_ID = KeysColumns.MASTER_KEY_ID;
@@ -345,16 +345,16 @@ public class KeychainContract {
} }
} }
public static class ApiTrustIdentity implements ApiTrustIdentityColumns, BaseColumns { public static class ApiAutocryptPeer implements ApiAutocryptPeerColumns, BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon() public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
.appendPath(BASE_TRUST_IDENTITIES).build(); .appendPath(BASE_AUTOCRYPT_PEERS).build();
public static Uri buildByKeyUri(Uri uri) { public static Uri buildByKeyUri(Uri uri) {
return CONTENT_URI.buildUpon().appendPath(PATH_BY_KEY_ID).appendPath(uri.getPathSegments().get(1)).build(); return CONTENT_URI.buildUpon().appendPath(PATH_BY_KEY_ID).appendPath(uri.getPathSegments().get(1)).build();
} }
public static Uri buildByPackageNameAndTrustId(String packageName, String trustId) { public static Uri buildByPackageNameAndAutocryptId(String packageName, String autocryptPeer) {
return CONTENT_URI.buildUpon().appendPath(PATH_BY_PACKAGE_NAME).appendPath(packageName).appendPath(trustId).build(); return CONTENT_URI.buildUpon().appendPath(PATH_BY_PACKAGE_NAME).appendPath(packageName).appendPath(autocryptPeer).build();
} }
public static Uri buildByMasterKeyId(long masterKeyId) { public static Uri buildByMasterKeyId(long masterKeyId) {

View File

@@ -33,7 +33,7 @@ import android.provider.BaseColumns;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAppsAllowedKeysColumns; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAppsAllowedKeysColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAppsColumns; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAppsColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiTrustIdentityColumns; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAutocryptPeerColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.CertsColumns; import org.sufficientlysecure.keychain.provider.KeychainContract.CertsColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingsColumns; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingsColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeysColumns; import org.sufficientlysecure.keychain.provider.KeychainContract.KeysColumns;
@@ -66,7 +66,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
String API_APPS = "api_apps"; String API_APPS = "api_apps";
String API_ALLOWED_KEYS = "api_allowed_keys"; String API_ALLOWED_KEYS = "api_allowed_keys";
String OVERRIDDEN_WARNINGS = "overridden_warnings"; String OVERRIDDEN_WARNINGS = "overridden_warnings";
String API_TRUST_IDENTITIES = "api_trust_identities"; String API_AUTOCRYPT_PEERS = "api_autocrypt_peers";
} }
private static final String CREATE_KEYRINGS_PUBLIC = private static final String CREATE_KEYRINGS_PUBLIC =
@@ -158,15 +158,15 @@ public class KeychainDatabase extends SQLiteOpenHelper {
+ Tables.KEY_RINGS_PUBLIC + "(" + KeyRingsColumns.MASTER_KEY_ID + ") ON DELETE CASCADE" + Tables.KEY_RINGS_PUBLIC + "(" + KeyRingsColumns.MASTER_KEY_ID + ") ON DELETE CASCADE"
+ ")"; + ")";
private static final String CREATE_API_TRUST_IDENTITIES = private static final String CREATE_API_AUTOCRYPT_PEERS =
"CREATE TABLE IF NOT EXISTS " + Tables.API_TRUST_IDENTITIES + " (" "CREATE TABLE IF NOT EXISTS " + Tables.API_AUTOCRYPT_PEERS + " ("
+ ApiTrustIdentityColumns.PACKAGE_NAME + " TEXT NOT NULL, " + ApiAutocryptPeerColumns.PACKAGE_NAME + " TEXT NOT NULL, "
+ ApiTrustIdentityColumns.IDENTIFIER + " TEXT NOT NULL, " + ApiAutocryptPeerColumns.IDENTIFIER + " TEXT NOT NULL, "
+ ApiTrustIdentityColumns.LAST_UPDATED + " INTEGER NOT NULL, " + ApiAutocryptPeerColumns.LAST_UPDATED + " INTEGER NOT NULL, "
+ ApiTrustIdentityColumns.MASTER_KEY_ID + " INTEGER NOT NULL, " + ApiAutocryptPeerColumns.MASTER_KEY_ID + " INTEGER NOT NULL, "
+ "PRIMARY KEY(" + ApiTrustIdentityColumns.PACKAGE_NAME + ", " + "PRIMARY KEY(" + ApiAutocryptPeerColumns.PACKAGE_NAME + ", "
+ ApiTrustIdentityColumns.IDENTIFIER + "), " + ApiAutocryptPeerColumns.IDENTIFIER + "), "
+ "FOREIGN KEY(" + ApiTrustIdentityColumns.PACKAGE_NAME + ") REFERENCES " + "FOREIGN KEY(" + ApiAutocryptPeerColumns.PACKAGE_NAME + ") REFERENCES "
+ Tables.API_APPS + "(" + ApiAppsColumns.PACKAGE_NAME + ") ON DELETE CASCADE" + Tables.API_APPS + "(" + ApiAppsColumns.PACKAGE_NAME + ") ON DELETE CASCADE"
+ ")"; + ")";
@@ -213,7 +213,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
db.execSQL(CREATE_API_APPS); db.execSQL(CREATE_API_APPS);
db.execSQL(CREATE_API_APPS_ALLOWED_KEYS); db.execSQL(CREATE_API_APPS_ALLOWED_KEYS);
db.execSQL(CREATE_OVERRIDDEN_WARNINGS); db.execSQL(CREATE_OVERRIDDEN_WARNINGS);
db.execSQL(CREATE_API_TRUST_IDENTITIES); db.execSQL(CREATE_API_AUTOCRYPT_PEERS);
db.execSQL("CREATE INDEX keys_by_rank ON keys (" + KeysColumns.RANK + ");"); db.execSQL("CREATE INDEX keys_by_rank ON keys (" + KeysColumns.RANK + ");");
db.execSQL("CREATE INDEX uids_by_rank ON user_packets (" + UserPacketsColumns.RANK + ", " db.execSQL("CREATE INDEX uids_by_rank ON user_packets (" + UserPacketsColumns.RANK + ", "
@@ -334,21 +334,16 @@ public class KeychainDatabase extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE updated_keys ADD COLUMN seen_on_keyservers INTEGER;"); db.execSQL("ALTER TABLE updated_keys ADD COLUMN seen_on_keyservers INTEGER;");
case 22: case 22:
db.execSQL("CREATE TABLE IF NOT EXISTS " + Tables.API_TRUST_IDENTITIES + " (" db.execSQL("CREATE TABLE IF NOT EXISTS api_autocrypt_peers ("
+ ApiTrustIdentityColumns.PACKAGE_NAME + " TEXT NOT NULL, " + "package_name TEXT NOT NULL, "
+ ApiTrustIdentityColumns.IDENTIFIER + " TEXT NOT NULL, " + "identifier TEXT NOT NULL, "
+ ApiTrustIdentityColumns.LAST_UPDATED + " INTEGER NOT NULL, " + "last_updated INTEGER NOT NULL, "
+ ApiTrustIdentityColumns.MASTER_KEY_ID + " INTEGER NOT NULL, " + "master_key_id INTEGER NOT NULL, "
+ "PRIMARY KEY(" + ApiTrustIdentityColumns.PACKAGE_NAME + ", " + "PRIMARY KEY(package_name, identifier), "
+ ApiTrustIdentityColumns.IDENTIFIER + "), " + "FOREIGN KEY(package_name) REFERENCES api_apps(package_name) ON DELETE CASCADE"
+ "FOREIGN KEY(" + ApiTrustIdentityColumns.MASTER_KEY_ID + ") REFERENCES "
+ Tables.KEY_RINGS_PUBLIC + "(" + KeyRingsColumns.MASTER_KEY_ID + ") ON DELETE CASCADE, "
+ "FOREIGN KEY(" + ApiTrustIdentityColumns.PACKAGE_NAME + ") REFERENCES "
+ Tables.API_APPS + "(" + ApiAppsColumns.PACKAGE_NAME + ") ON DELETE CASCADE"
+ ")"); + ")");
if (oldVersion == 18 || oldVersion == 19 || oldVersion == 20 || oldVersion == 21 || oldVersion == 22) { if (oldVersion == 18 || oldVersion == 19 || oldVersion == 20 || oldVersion == 21 || oldVersion == 22) {
// no consolidate for now, often crashes!
return; return;
} }
} }

View File

@@ -22,7 +22,7 @@ import android.net.Uri;
import android.provider.BaseColumns; import android.provider.BaseColumns;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiTrustIdentityColumns; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAutocryptPeerColumns;
public class KeychainExternalContract { public class KeychainExternalContract {
@@ -35,7 +35,7 @@ public class KeychainExternalContract {
private static final Uri BASE_CONTENT_URI_EXTERNAL = Uri private static final Uri BASE_CONTENT_URI_EXTERNAL = Uri
.parse("content://" + CONTENT_AUTHORITY_EXTERNAL); .parse("content://" + CONTENT_AUTHORITY_EXTERNAL);
public static final String BASE_EMAIL_STATUS = "email_status"; public static final String BASE_EMAIL_STATUS = "email_status";
public static final String BASE_TRUST_IDENTITIES = "trust_ids"; public static final String BASE_AUTOCRYPT_PEERS = "autocrypt_peers";
public static class EmailStatus implements BaseColumns { public static class EmailStatus implements BaseColumns {
@@ -43,8 +43,8 @@ public class KeychainExternalContract {
public static final String USER_ID = "user_id"; public static final String USER_ID = "user_id";
public static final String USER_ID_STATUS = "email_status"; public static final String USER_ID_STATUS = "email_status";
public static final String MASTER_KEY_ID = "master_key_id"; public static final String MASTER_KEY_ID = "master_key_id";
public static final String TRUST_ID_LAST_UPDATE = "trust_id_last_update"; public static final String AUTOCRYPT_PEER_LAST_SEEN = "autocrypt_peer_last_seen";
public static final String TRUST_ID_STATUS = "trust_id_status"; public static final String AUTOCRYPT_PEER_STATE = "autocrypt_peer_state";
public static final Uri CONTENT_URI = BASE_CONTENT_URI_EXTERNAL.buildUpon() public static final Uri CONTENT_URI = BASE_CONTENT_URI_EXTERNAL.buildUpon()
.appendPath(BASE_EMAIL_STATUS).build(); .appendPath(BASE_EMAIL_STATUS).build();
@@ -53,16 +53,16 @@ public class KeychainExternalContract {
"vnd.android.cursor.dir/vnd.org.sufficientlysecure.keychain.provider.email_status"; "vnd.android.cursor.dir/vnd.org.sufficientlysecure.keychain.provider.email_status";
} }
public static class ApiTrustIdentity implements ApiTrustIdentityColumns, BaseColumns { public static class ApiAutocryptPeer implements ApiAutocryptPeerColumns, BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI_EXTERNAL.buildUpon() public static final Uri CONTENT_URI = BASE_CONTENT_URI_EXTERNAL.buildUpon()
.appendPath(BASE_TRUST_IDENTITIES).build(); .appendPath(BASE_AUTOCRYPT_PEERS).build();
public static Uri buildByPackageNameUri(String packageName) { public static Uri buildByPackageNameUri(String packageName) {
return CONTENT_URI.buildUpon().appendEncodedPath(packageName).build(); return CONTENT_URI.buildUpon().appendEncodedPath(packageName).build();
} }
public static Uri buildByPackageNameAndTrustIdUri(String packageName, String trustId) { public static Uri buildByPackageNameAndTrustIdUri(String packageName, String autocryptPeer) {
return CONTENT_URI.buildUpon().appendEncodedPath(packageName).appendEncodedPath(trustId).build(); return CONTENT_URI.buildUpon().appendEncodedPath(packageName).appendEncodedPath(autocryptPeer).build();
} }
} }

View File

@@ -35,7 +35,7 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAllowedKeys; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAllowedKeys;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiTrustIdentity; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAutocryptPeer;
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
@@ -203,11 +203,11 @@ public class KeychainProvider extends ContentProvider {
* *
* </pre> * </pre>
*/ */
matcher.addURI(authority, KeychainContract.BASE_TRUST_IDENTITIES + "/" + matcher.addURI(authority, KeychainContract.BASE_AUTOCRYPT_PEERS + "/" +
KeychainContract.PATH_BY_KEY_ID + "/*", TRUST_IDS_BY_MASTER_KEY_ID); KeychainContract.PATH_BY_KEY_ID + "/*", TRUST_IDS_BY_MASTER_KEY_ID);
matcher.addURI(authority, KeychainContract.BASE_TRUST_IDENTITIES + "/" + matcher.addURI(authority, KeychainContract.BASE_AUTOCRYPT_PEERS + "/" +
KeychainContract.PATH_BY_PACKAGE_NAME + "/*", TRUST_IDS_BY_PACKAGE_NAME); KeychainContract.PATH_BY_PACKAGE_NAME + "/*", TRUST_IDS_BY_PACKAGE_NAME);
matcher.addURI(authority, KeychainContract.BASE_TRUST_IDENTITIES + "/" + matcher.addURI(authority, KeychainContract.BASE_AUTOCRYPT_PEERS + "/" +
KeychainContract.PATH_BY_PACKAGE_NAME + "/*/*", TRUST_IDS_BY_PACKAGE_NAME_AND_TRUST_ID); KeychainContract.PATH_BY_PACKAGE_NAME + "/*/*", TRUST_IDS_BY_PACKAGE_NAME_AND_TRUST_ID);
@@ -343,7 +343,7 @@ public class KeychainProvider extends ContentProvider {
"(" + Tables.KEYS + "." + Keys.EXPIRY + " IS NOT NULL AND " + Tables.KEYS + "." + Keys.EXPIRY "(" + Tables.KEYS + "." + Keys.EXPIRY + " IS NOT NULL AND " + Tables.KEYS + "." + Keys.EXPIRY
+ " < " + new Date().getTime() / 1000 + ") AS " + KeyRings.IS_EXPIRED); + " < " + new Date().getTime() / 1000 + ") AS " + KeyRings.IS_EXPIRED);
projectionMap.put(KeyRings.API_KNOWN_TO_PACKAGE_NAMES, projectionMap.put(KeyRings.API_KNOWN_TO_PACKAGE_NAMES,
"GROUP_CONCAT(aTI." + ApiTrustIdentity.PACKAGE_NAME + ") AS " "GROUP_CONCAT(aTI." + ApiAutocryptPeer.PACKAGE_NAME + ") AS "
+ KeyRings.API_KNOWN_TO_PACKAGE_NAMES); + KeyRings.API_KNOWN_TO_PACKAGE_NAMES);
qb.setProjectionMap(projectionMap); qb.setProjectionMap(projectionMap);
@@ -414,7 +414,7 @@ public class KeychainProvider extends ContentProvider {
+ " >= " + new Date().getTime() / 1000 + " )" + " >= " + new Date().getTime() / 1000 + " )"
+ ")" : "") + ")" : "")
+ (plist.contains(KeyRings.API_KNOWN_TO_PACKAGE_NAMES) ? + (plist.contains(KeyRings.API_KNOWN_TO_PACKAGE_NAMES) ?
" LEFT JOIN " + Tables.API_TRUST_IDENTITIES + " AS aTI ON (" " LEFT JOIN " + Tables.API_AUTOCRYPT_PEERS + " AS aTI ON ("
+"aTI." + Keys.MASTER_KEY_ID +"aTI." + Keys.MASTER_KEY_ID
+ " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID + " = " + Tables.KEYS + "." + Keys.MASTER_KEY_ID
+ ")" : "") + ")" : "")
@@ -672,32 +672,32 @@ public class KeychainProvider extends ContentProvider {
} }
HashMap<String, String> projectionMap = new HashMap<>(); HashMap<String, String> projectionMap = new HashMap<>();
projectionMap.put(ApiTrustIdentity._ID, "oid AS " + ApiTrustIdentity._ID); projectionMap.put(ApiAutocryptPeer._ID, "oid AS " + ApiAutocryptPeer._ID);
projectionMap.put(ApiTrustIdentity.PACKAGE_NAME, ApiTrustIdentity.PACKAGE_NAME); projectionMap.put(ApiAutocryptPeer.PACKAGE_NAME, ApiAutocryptPeer.PACKAGE_NAME);
projectionMap.put(ApiTrustIdentity.IDENTIFIER, ApiTrustIdentity.IDENTIFIER); projectionMap.put(ApiAutocryptPeer.IDENTIFIER, ApiAutocryptPeer.IDENTIFIER);
projectionMap.put(ApiTrustIdentity.MASTER_KEY_ID, ApiTrustIdentity.MASTER_KEY_ID); projectionMap.put(ApiAutocryptPeer.MASTER_KEY_ID, ApiAutocryptPeer.MASTER_KEY_ID);
projectionMap.put(ApiTrustIdentity.LAST_UPDATED, ApiTrustIdentity.LAST_UPDATED); projectionMap.put(ApiAutocryptPeer.LAST_UPDATED, ApiAutocryptPeer.LAST_UPDATED);
qb.setProjectionMap(projectionMap); qb.setProjectionMap(projectionMap);
qb.setTables(Tables.API_TRUST_IDENTITIES); qb.setTables(Tables.API_AUTOCRYPT_PEERS);
if (match == TRUST_IDS_BY_MASTER_KEY_ID) { if (match == TRUST_IDS_BY_MASTER_KEY_ID) {
long masterKeyId = Long.parseLong(uri.getLastPathSegment()); long masterKeyId = Long.parseLong(uri.getLastPathSegment());
selection = Tables.API_TRUST_IDENTITIES + "." + ApiTrustIdentity.MASTER_KEY_ID + " = ?"; selection = Tables.API_AUTOCRYPT_PEERS + "." + ApiAutocryptPeer.MASTER_KEY_ID + " = ?";
selectionArgs = new String[] { Long.toString(masterKeyId) }; selectionArgs = new String[] { Long.toString(masterKeyId) };
} else if (match == TRUST_IDS_BY_PACKAGE_NAME) { } else if (match == TRUST_IDS_BY_PACKAGE_NAME) {
String packageName = uri.getPathSegments().get(2); String packageName = uri.getPathSegments().get(2);
selection = Tables.API_TRUST_IDENTITIES + "." + ApiTrustIdentity.PACKAGE_NAME + " = ?"; selection = Tables.API_AUTOCRYPT_PEERS + "." + ApiAutocryptPeer.PACKAGE_NAME + " = ?";
selectionArgs = new String[] { packageName }; selectionArgs = new String[] { packageName };
} else { // TRUST_IDS_BY_PACKAGE_NAME_AND_TRUST_ID } else { // TRUST_IDS_BY_PACKAGE_NAME_AND_TRUST_ID
String packageName = uri.getPathSegments().get(2); String packageName = uri.getPathSegments().get(2);
String trustId = uri.getPathSegments().get(3); String autocryptPeer = uri.getPathSegments().get(3);
selection = Tables.API_TRUST_IDENTITIES + "." + ApiTrustIdentity.PACKAGE_NAME + " = ? AND " + selection = Tables.API_AUTOCRYPT_PEERS + "." + ApiAutocryptPeer.PACKAGE_NAME + " = ? AND " +
Tables.API_TRUST_IDENTITIES + "." + ApiTrustIdentity.IDENTIFIER + " = ?"; Tables.API_AUTOCRYPT_PEERS + "." + ApiAutocryptPeer.IDENTIFIER + " = ?";
selectionArgs = new String[] { packageName, trustId }; selectionArgs = new String[] { packageName, autocryptPeer };
} }
break; break;
@@ -998,21 +998,21 @@ public class KeychainProvider extends ContentProvider {
break; break;
} }
case TRUST_IDS_BY_PACKAGE_NAME_AND_TRUST_ID: { case TRUST_IDS_BY_PACKAGE_NAME_AND_TRUST_ID: {
Long masterKeyId = values.getAsLong(ApiTrustIdentity.MASTER_KEY_ID); Long masterKeyId = values.getAsLong(ApiAutocryptPeer.MASTER_KEY_ID);
long updateTime = values.getAsLong(KeychainContract.ApiTrustIdentity.LAST_UPDATED); long updateTime = values.getAsLong(ApiAutocryptPeer.LAST_UPDATED);
if (masterKeyId == null) { if (masterKeyId == null) {
throw new IllegalArgumentException("master_key_id must be a non-null value!"); throw new IllegalArgumentException("master_key_id must be a non-null value!");
} }
ContentValues actualValues = new ContentValues(); ContentValues actualValues = new ContentValues();
String packageName = uri.getPathSegments().get(2); String packageName = uri.getPathSegments().get(2);
actualValues.put(ApiTrustIdentity.PACKAGE_NAME, packageName); actualValues.put(ApiAutocryptPeer.PACKAGE_NAME, packageName);
actualValues.put(ApiTrustIdentity.IDENTIFIER, uri.getLastPathSegment()); actualValues.put(ApiAutocryptPeer.IDENTIFIER, uri.getLastPathSegment());
actualValues.put(ApiTrustIdentity.MASTER_KEY_ID, masterKeyId); actualValues.put(ApiAutocryptPeer.MASTER_KEY_ID, masterKeyId);
actualValues.put(ApiTrustIdentity.LAST_UPDATED, updateTime); actualValues.put(ApiAutocryptPeer.LAST_UPDATED, updateTime);
try { try {
db.replace(Tables.API_TRUST_IDENTITIES, null, actualValues); db.replace(Tables.API_AUTOCRYPT_PEERS, null, actualValues);
} finally { } finally {
db.close(); db.close();
} }

View File

@@ -47,7 +47,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.provider.KeychainDatabase;
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
import org.sufficientlysecure.keychain.provider.KeychainExternalContract; import org.sufficientlysecure.keychain.provider.KeychainExternalContract;
import org.sufficientlysecure.keychain.provider.KeychainExternalContract.ApiTrustIdentity; import org.sufficientlysecure.keychain.provider.KeychainExternalContract.ApiAutocryptPeer;
import org.sufficientlysecure.keychain.provider.KeychainExternalContract.EmailStatus; import org.sufficientlysecure.keychain.provider.KeychainExternalContract.EmailStatus;
import org.sufficientlysecure.keychain.provider.SimpleContentResolverInterface; import org.sufficientlysecure.keychain.provider.SimpleContentResolverInterface;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@@ -55,7 +55,7 @@ import org.sufficientlysecure.keychain.util.Log;
public class KeychainExternalProvider extends ContentProvider implements SimpleContentResolverInterface { public class KeychainExternalProvider extends ContentProvider implements SimpleContentResolverInterface {
private static final int EMAIL_STATUS = 101; private static final int EMAIL_STATUS = 101;
private static final int EMAIL_STATUS_INTERNAL = 102; private static final int EMAIL_STATUS_INTERNAL = 102;
private static final int TRUST_IDENTITY = 201; private static final int AUTOCRYPT_PEER = 201;
private static final int API_APPS = 301; private static final int API_APPS = 301;
private static final int API_APPS_BY_PACKAGE_NAME = 302; private static final int API_APPS_BY_PACKAGE_NAME = 302;
@@ -86,7 +86,7 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
matcher.addURI(authority, KeychainExternalContract.BASE_EMAIL_STATUS, EMAIL_STATUS); matcher.addURI(authority, KeychainExternalContract.BASE_EMAIL_STATUS, EMAIL_STATUS);
matcher.addURI(authority, KeychainExternalContract.BASE_EMAIL_STATUS + "/*", EMAIL_STATUS_INTERNAL); matcher.addURI(authority, KeychainExternalContract.BASE_EMAIL_STATUS + "/*", EMAIL_STATUS_INTERNAL);
matcher.addURI(authority, KeychainExternalContract.BASE_TRUST_IDENTITIES + "/*", TRUST_IDENTITY); matcher.addURI(authority, KeychainExternalContract.BASE_AUTOCRYPT_PEERS + "/*", AUTOCRYPT_PEER);
// can only query status of calling app - for internal use only! // can only query status of calling app - for internal use only!
matcher.addURI(KeychainContract.CONTENT_AUTHORITY, KeychainContract.BASE_API_APPS + "/*", API_APPS_BY_PACKAGE_NAME); matcher.addURI(KeychainContract.CONTENT_AUTHORITY, KeychainContract.BASE_API_APPS + "/*", API_APPS_BY_PACKAGE_NAME);
@@ -180,18 +180,18 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
+ " WHEN " + Certs.VERIFIED_SECRET + " THEN " + KeychainExternalContract.KEY_STATUS_VERIFIED + " WHEN " + Certs.VERIFIED_SECRET + " THEN " + KeychainExternalContract.KEY_STATUS_VERIFIED
+ " WHEN NULL THEN NULL" + " WHEN NULL THEN NULL"
+ " END AS " + EmailStatus.USER_ID_STATUS); + " END AS " + EmailStatus.USER_ID_STATUS);
projectionMap.put(EmailStatus.TRUST_ID_STATUS, "CASE ( MIN (certs_trust_id." + Certs.VERIFIED + " ) ) " projectionMap.put(EmailStatus.AUTOCRYPT_PEER_STATE, "CASE ( MIN (certs_autocrypt_peer." + Certs.VERIFIED + " ) ) "
// remap to keep this provider contract independent from our internal representation // remap to keep this provider contract independent from our internal representation
+ " WHEN " + Certs.VERIFIED_SELF + " THEN " + KeychainExternalContract.KEY_STATUS_UNVERIFIED + " WHEN " + Certs.VERIFIED_SELF + " THEN " + KeychainExternalContract.KEY_STATUS_UNVERIFIED
+ " WHEN " + Certs.VERIFIED_SECRET + " THEN " + KeychainExternalContract.KEY_STATUS_VERIFIED + " WHEN " + Certs.VERIFIED_SECRET + " THEN " + KeychainExternalContract.KEY_STATUS_VERIFIED
+ " WHEN NULL THEN NULL" + " WHEN NULL THEN NULL"
+ " END AS " + EmailStatus.TRUST_ID_STATUS); + " END AS " + EmailStatus.AUTOCRYPT_PEER_STATE);
projectionMap.put(EmailStatus.MASTER_KEY_ID, projectionMap.put(EmailStatus.MASTER_KEY_ID,
Tables.USER_PACKETS + "." + UserPackets.MASTER_KEY_ID + " AS " + EmailStatus.MASTER_KEY_ID); Tables.USER_PACKETS + "." + UserPackets.MASTER_KEY_ID + " AS " + EmailStatus.MASTER_KEY_ID);
projectionMap.put(EmailStatus.USER_ID, projectionMap.put(EmailStatus.USER_ID,
Tables.USER_PACKETS + "." + UserPackets.USER_ID + " AS " + EmailStatus.USER_ID); Tables.USER_PACKETS + "." + UserPackets.USER_ID + " AS " + EmailStatus.USER_ID);
projectionMap.put(EmailStatus.TRUST_ID_LAST_UPDATE, Tables.API_TRUST_IDENTITIES + "." + projectionMap.put(EmailStatus.AUTOCRYPT_PEER_LAST_SEEN, Tables.API_AUTOCRYPT_PEERS + "." +
ApiTrustIdentity.LAST_UPDATED + " AS " + EmailStatus.TRUST_ID_LAST_UPDATE); ApiAutocryptPeer.LAST_UPDATED + " AS " + EmailStatus.AUTOCRYPT_PEER_LAST_SEEN);
qb.setProjectionMap(projectionMap); qb.setProjectionMap(projectionMap);
if (projection == null) { if (projection == null) {
@@ -208,12 +208,12 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
+ Tables.USER_PACKETS + "." + UserPackets.MASTER_KEY_ID + " = certs_user_id." + Certs.MASTER_KEY_ID + Tables.USER_PACKETS + "." + UserPackets.MASTER_KEY_ID + " = certs_user_id." + Certs.MASTER_KEY_ID
+ " AND " + Tables.USER_PACKETS + "." + UserPackets.RANK + " = certs_user_id." + Certs.RANK + " AND " + Tables.USER_PACKETS + "." + UserPackets.RANK + " = certs_user_id." + Certs.RANK
+ ")" + ")"
+ " LEFT JOIN " + Tables.API_TRUST_IDENTITIES + " ON (" + " LEFT JOIN " + Tables.API_AUTOCRYPT_PEERS + " ON ("
+ Tables.API_TRUST_IDENTITIES + "." + ApiTrustIdentity.IDENTIFIER + " LIKE queried_addresses.address" + Tables.API_AUTOCRYPT_PEERS + "." + ApiAutocryptPeer.IDENTIFIER + " LIKE queried_addresses.address"
+ " AND " + Tables.API_TRUST_IDENTITIES + "." + ApiTrustIdentity.PACKAGE_NAME + " = \"" + callingPackageName + "\"" + " AND " + Tables.API_AUTOCRYPT_PEERS + "." + ApiAutocryptPeer.PACKAGE_NAME + " = \"" + callingPackageName + "\""
+ ")" + ")"
+ " LEFT JOIN " + Tables.CERTS + " AS certs_trust_id ON (" + " LEFT JOIN " + Tables.CERTS + " AS certs_autocrypt_peer ON ("
+ Tables.API_TRUST_IDENTITIES + "." + ApiTrustIdentity.MASTER_KEY_ID + " = certs_trust_id." + Certs.MASTER_KEY_ID + Tables.API_AUTOCRYPT_PEERS + "." + ApiAutocryptPeer.MASTER_KEY_ID + " = certs_autocrypt_peer." + Certs.MASTER_KEY_ID
+ ")" + ")"
); );
// in case there are multiple verifying certificates // in case there are multiple verifying certificates
@@ -232,7 +232,7 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
break; break;
} }
case TRUST_IDENTITY: { case AUTOCRYPT_PEER: {
boolean callerIsAllowed = mApiPermissionHelper.isAllowedIgnoreErrors(); boolean callerIsAllowed = mApiPermissionHelper.isAllowedIgnoreErrors();
if (!callerIsAllowed) { if (!callerIsAllowed) {
throw new AccessControlException("An application must register before use of KeychainExternalProvider!"); throw new AccessControlException("An application must register before use of KeychainExternalProvider!");
@@ -243,19 +243,19 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
} }
HashMap<String, String> projectionMap = new HashMap<>(); HashMap<String, String> projectionMap = new HashMap<>();
projectionMap.put(ApiTrustIdentity._ID, "oid AS " + ApiTrustIdentity._ID); projectionMap.put(ApiAutocryptPeer._ID, "oid AS " + ApiAutocryptPeer._ID);
projectionMap.put(ApiTrustIdentity.IDENTIFIER, ApiTrustIdentity.IDENTIFIER); projectionMap.put(ApiAutocryptPeer.IDENTIFIER, ApiAutocryptPeer.IDENTIFIER);
projectionMap.put(ApiTrustIdentity.MASTER_KEY_ID, ApiTrustIdentity.MASTER_KEY_ID); projectionMap.put(ApiAutocryptPeer.MASTER_KEY_ID, ApiAutocryptPeer.MASTER_KEY_ID);
projectionMap.put(ApiTrustIdentity.LAST_UPDATED, ApiTrustIdentity.LAST_UPDATED); projectionMap.put(ApiAutocryptPeer.LAST_UPDATED, ApiAutocryptPeer.LAST_UPDATED);
qb.setProjectionMap(projectionMap); qb.setProjectionMap(projectionMap);
qb.setTables(Tables.API_TRUST_IDENTITIES); qb.setTables(Tables.API_AUTOCRYPT_PEERS);
// allow access to columns of the calling package exclusively! // allow access to columns of the calling package exclusively!
qb.appendWhere(Tables.API_TRUST_IDENTITIES + "." + ApiTrustIdentity.PACKAGE_NAME + qb.appendWhere(Tables.API_AUTOCRYPT_PEERS + "." + ApiAutocryptPeer.PACKAGE_NAME +
" = " + mApiPermissionHelper.getCurrentCallingPackage()); " = " + mApiPermissionHelper.getCurrentCallingPackage());
qb.appendWhere(Tables.API_TRUST_IDENTITIES + "." + ApiTrustIdentity.IDENTIFIER + " = "); qb.appendWhere(Tables.API_AUTOCRYPT_PEERS + "." + ApiAutocryptPeer.IDENTIFIER + " = ");
qb.appendWhereEscapeString(uri.getLastPathSegment()); qb.appendWhereEscapeString(uri.getLastPathSegment());
break; break;
@@ -325,7 +325,7 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
Log.v(Constants.TAG, "insert(uri=" + uri + ")"); Log.v(Constants.TAG, "insert(uri=" + uri + ")");
int match = mUriMatcher.match(uri); int match = mUriMatcher.match(uri);
if (match != TRUST_IDENTITY) { if (match != AUTOCRYPT_PEER) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@@ -334,20 +334,20 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
throw new AccessControlException("An application must register before use of KeychainExternalProvider!"); throw new AccessControlException("An application must register before use of KeychainExternalProvider!");
} }
Long masterKeyId = values.getAsLong(ApiTrustIdentity.MASTER_KEY_ID); Long masterKeyId = values.getAsLong(ApiAutocryptPeer.MASTER_KEY_ID);
if (masterKeyId == null) { if (masterKeyId == null) {
throw new IllegalArgumentException("master_key_id must be a non-null value!"); throw new IllegalArgumentException("master_key_id must be a non-null value!");
} }
ContentValues actualValues = new ContentValues(); ContentValues actualValues = new ContentValues();
actualValues.put(ApiTrustIdentity.PACKAGE_NAME, mApiPermissionHelper.getCurrentCallingPackage()); actualValues.put(ApiAutocryptPeer.PACKAGE_NAME, mApiPermissionHelper.getCurrentCallingPackage());
actualValues.put(ApiTrustIdentity.IDENTIFIER, uri.getLastPathSegment()); actualValues.put(ApiAutocryptPeer.IDENTIFIER, uri.getLastPathSegment());
actualValues.put(ApiTrustIdentity.MASTER_KEY_ID, masterKeyId); actualValues.put(ApiAutocryptPeer.MASTER_KEY_ID, masterKeyId);
actualValues.put(ApiTrustIdentity.LAST_UPDATED, new Date().getTime() / 1000); actualValues.put(ApiAutocryptPeer.LAST_UPDATED, new Date().getTime() / 1000);
SQLiteDatabase db = getDb().getWritableDatabase(); SQLiteDatabase db = getDb().getWritableDatabase();
try { try {
db.insert(Tables.API_TRUST_IDENTITIES, null, actualValues); db.insert(Tables.API_AUTOCRYPT_PEERS, null, actualValues);
return uri; return uri;
} finally { } finally {
db.close(); db.close();
@@ -359,7 +359,7 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
Log.v(Constants.TAG, "delete(uri=" + uri + ")"); Log.v(Constants.TAG, "delete(uri=" + uri + ")");
int match = mUriMatcher.match(uri); int match = mUriMatcher.match(uri);
if (match != TRUST_IDENTITY || selection != null || selectionArgs != null) { if (match != AUTOCRYPT_PEER || selection != null || selectionArgs != null) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@@ -368,7 +368,7 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
throw new AccessControlException("An application must register before use of KeychainExternalProvider!"); throw new AccessControlException("An application must register before use of KeychainExternalProvider!");
} }
String actualSelection = ApiTrustIdentity.PACKAGE_NAME + " = ? AND " + ApiTrustIdentity.IDENTIFIER + " = ?"; String actualSelection = ApiAutocryptPeer.PACKAGE_NAME + " = ? AND " + ApiAutocryptPeer.IDENTIFIER + " = ?";
String[] actualSelectionArgs = new String[] { String[] actualSelectionArgs = new String[] {
mApiPermissionHelper.getCurrentCallingPackage(), mApiPermissionHelper.getCurrentCallingPackage(),
uri.getLastPathSegment() uri.getLastPathSegment()
@@ -376,7 +376,7 @@ public class KeychainExternalProvider extends ContentProvider implements SimpleC
SQLiteDatabase db = getDb().getWritableDatabase(); SQLiteDatabase db = getDb().getWritableDatabase();
try { try {
return db.delete(Tables.API_TRUST_IDENTITIES, actualSelection, actualSelectionArgs); return db.delete(Tables.API_AUTOCRYPT_PEERS, actualSelection, actualSelectionArgs);
} finally { } finally {
db.close(); db.close();
} }

View File

@@ -44,10 +44,10 @@ import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.openintents.openpgp.IOpenPgpService; import org.openintents.openpgp.IOpenPgpService;
import org.openintents.openpgp.OpenPgpDecryptionResult; import org.openintents.openpgp.OpenPgpDecryptionResult;
import org.openintents.openpgp.OpenPgpError; import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.OpenPgpInlineKeyUpdate; import org.openintents.openpgp.AutocryptPeerUpdate;
import org.openintents.openpgp.OpenPgpMetadata; import org.openintents.openpgp.OpenPgpMetadata;
import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.OpenPgpSignatureResult;
import org.openintents.openpgp.OpenPgpSignatureResult.TrustIdentityResult; import org.openintents.openpgp.OpenPgpSignatureResult.AutocryptPeerResult;
import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpApi;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.operations.BackupOperation; import org.sufficientlysecure.keychain.operations.BackupOperation;
@@ -73,7 +73,7 @@ import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.OverriddenWarningsRepository; import org.sufficientlysecure.keychain.provider.OverriddenWarningsRepository;
import org.sufficientlysecure.keychain.provider.TrustIdentityDataAccessObject; import org.sufficientlysecure.keychain.provider.AutocryptPeerDataAccessObject;
import org.sufficientlysecure.keychain.remote.OpenPgpServiceKeyIdExtractor.KeyIdResult; import org.sufficientlysecure.keychain.remote.OpenPgpServiceKeyIdExtractor.KeyIdResult;
import org.sufficientlysecure.keychain.remote.OpenPgpServiceKeyIdExtractor.KeyIdResultStatus; import org.sufficientlysecure.keychain.remote.OpenPgpServiceKeyIdExtractor.KeyIdResultStatus;
import org.sufficientlysecure.keychain.service.BackupKeyringParcel; import org.sufficientlysecure.keychain.service.BackupKeyringParcel;
@@ -88,7 +88,7 @@ public class OpenPgpService extends Service {
public static final int API_VERSION_WITHOUT_SIGNATURE_ONLY_FLAG = 8; public static final int API_VERSION_WITHOUT_SIGNATURE_ONLY_FLAG = 8;
public static final int API_VERSION_WITH_DECRYPTION_RESULT = 8; public static final int API_VERSION_WITH_DECRYPTION_RESULT = 8;
public static final int API_VERSION_WITH_RESULT_NO_SIGNATURE = 8; public static final int API_VERSION_WITH_RESULT_NO_SIGNATURE = 8;
public static final int API_VERSION_WITH_TRUST_IDENTITIES = 12; public static final int API_VERSION_WITH_AUTOCRYPT = 12;
public static final List<Integer> SUPPORTED_VERSIONS = public static final List<Integer> SUPPORTED_VERSIONS =
Collections.unmodifiableList(Arrays.asList(7, 8, 9, 10, 11, 12)); Collections.unmodifiableList(Arrays.asList(7, 8, 9, 10, 11, 12));
@@ -360,9 +360,9 @@ public class OpenPgpService extends Service {
byte[] detachedSignature = data.getByteArrayExtra(OpenPgpApi.EXTRA_DETACHED_SIGNATURE); byte[] detachedSignature = data.getByteArrayExtra(OpenPgpApi.EXTRA_DETACHED_SIGNATURE);
String senderAddress = data.getStringExtra(OpenPgpApi.EXTRA_SENDER_ADDRESS); String senderAddress = data.getStringExtra(OpenPgpApi.EXTRA_SENDER_ADDRESS);
TrustIdentityDataAccessObject trustIdentityDao = new TrustIdentityDataAccessObject( AutocryptPeerDataAccessObject autocryptPeerentityDao = new AutocryptPeerDataAccessObject(
getBaseContext(), mApiPermissionHelper.getCurrentCallingPackage()); getBaseContext(), mApiPermissionHelper.getCurrentCallingPackage());
String senderTrustId = updateTrustIdStateFromIntent(data, trustIdentityDao); updateAutocryptPeerStateFromIntent(data, autocryptPeerentityDao);
PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(this, mKeyRepository, progressable); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(this, mKeyRepository, progressable);
@@ -449,41 +449,41 @@ public class OpenPgpService extends Service {
mApiPendingIntentFactory.createSecurityProblemIntent(packageName, securityProblem, supportOverride)); mApiPendingIntentFactory.createSecurityProblemIntent(packageName, securityProblem, supportOverride));
} }
private String updateTrustIdStateFromIntent(Intent data, TrustIdentityDataAccessObject trustIdentityDao) private String updateAutocryptPeerStateFromIntent(Intent data, AutocryptPeerDataAccessObject autocryptPeerDao)
throws PgpGeneralException, IOException { throws PgpGeneralException, IOException {
String trustId = data.getStringExtra(OpenPgpApi.EXTRA_TRUST_IDENTITY); String autocryptPeerId = data.getStringExtra(OpenPgpApi.EXTRA_AUTOCRYPT_PEER_ID);
OpenPgpInlineKeyUpdate inlineKeyUpdate = data.getParcelableExtra(OpenPgpApi.EXTRA_INLINE_KEY_DATA); AutocryptPeerUpdate inlineKeyUpdate = data.getParcelableExtra(OpenPgpApi.EXTRA_INLINE_KEY_DATA);
if (inlineKeyUpdate == null) { if (inlineKeyUpdate == null) {
return null; return null;
} }
UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(inlineKeyUpdate.getKeyData()); UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(inlineKeyUpdate.getKeyData());
if (uncachedKeyRing.isSecret()) { if (uncachedKeyRing.isSecret()) {
Log.e(Constants.TAG, "Found secret key in trust id! - Ignoring"); Log.e(Constants.TAG, "Found secret key in autocrypt id! - Ignoring");
return null; return null;
} }
// this will merge if the key already exists - no worries! // this will merge if the key already exists - no worries!
KeyWritableRepository.createDatabaseReadWriteInteractor(this).savePublicKeyRing(uncachedKeyRing); KeyWritableRepository.createDatabaseReadWriteInteractor(this).savePublicKeyRing(uncachedKeyRing);
long inlineMasterKeyId = uncachedKeyRing.getMasterKeyId(); long inlineMasterKeyId = uncachedKeyRing.getMasterKeyId();
Date lastUpdate = trustIdentityDao.getLastUpdateForTrustId(trustId); Date lastUpdate = autocryptPeerDao.getLastUpdateForAutocryptPeer(autocryptPeerId);
Date updateTimestamp = inlineKeyUpdate.getTimestamp(); Date updateTimestamp = inlineKeyUpdate.getTimestamp();
Long trustedMasterKeyId = trustIdentityDao.getMasterKeyIdForTrustId(trustId); Long autocryptMasterKeyId = autocryptPeerDao.getMasterKeyIdForAutocryptPeer(autocryptPeerId);
if (lastUpdate != null && lastUpdate.after(updateTimestamp)) { if (lastUpdate != null && lastUpdate.after(updateTimestamp)) {
Log.d(Constants.TAG, "Key for trust id is newer, ignoring other"); Log.d(Constants.TAG, "Key for autocrypt peer is newer, ignoring other");
return trustId; return autocryptPeerId;
} else if (trustedMasterKeyId == null) { } else if (autocryptMasterKeyId == null) {
Log.d(Constants.TAG, "No binding for trust id, pinning key"); Log.d(Constants.TAG, "No binding for autocrypt peer, pinning key");
trustIdentityDao.setMasterKeyIdForTrustId(trustId, inlineMasterKeyId, updateTimestamp); autocryptPeerDao.setMasterKeyIdForAutocryptPeer(autocryptPeerId, inlineMasterKeyId, updateTimestamp);
} else if (inlineMasterKeyId == trustedMasterKeyId) { } else if (inlineMasterKeyId == autocryptMasterKeyId) {
Log.d(Constants.TAG, "Key id is the same - doing nothing"); Log.d(Constants.TAG, "Key id is the same - doing nothing");
} else { } else {
// TODO danger in result intent! // TODO danger in result intent!
trustIdentityDao.setMasterKeyIdForTrustId(trustId, inlineMasterKeyId, updateTimestamp); autocryptPeerDao.setMasterKeyIdForAutocryptPeer(autocryptPeerId, inlineMasterKeyId, updateTimestamp);
} }
return trustId; return autocryptPeerId;
} }
private void processDecryptionResultForResultIntent(int targetApiVersion, Intent result, private void processDecryptionResultForResultIntent(int targetApiVersion, Intent result,
@@ -568,19 +568,19 @@ public class OpenPgpService extends Service {
} }
} }
String trustIdentity = data.getStringExtra(OpenPgpApi.EXTRA_TRUST_IDENTITY); String autocryptPeerentity = data.getStringExtra(OpenPgpApi.EXTRA_AUTOCRYPT_PEER_ID);
if (trustIdentity != null) { if (autocryptPeerentity != null) {
if (targetApiVersion < API_VERSION_WITH_TRUST_IDENTITIES) { if (targetApiVersion < API_VERSION_WITH_AUTOCRYPT) {
throw new IllegalStateException("API version conflict, trust identities are supported v12 and up!"); throw new IllegalStateException("API version conflict, autocrypt is supported v12 and up!");
} }
signatureResult = processTrustIdentityInfoToSignatureResult(signatureResult, trustIdentity); signatureResult = processAutocryptPeerInfoToSignatureResult(signatureResult, autocryptPeerentity);
} }
result.putExtra(OpenPgpApi.RESULT_SIGNATURE, signatureResult); result.putExtra(OpenPgpApi.RESULT_SIGNATURE, signatureResult);
} }
private OpenPgpSignatureResult processTrustIdentityInfoToSignatureResult(OpenPgpSignatureResult signatureResult, private OpenPgpSignatureResult processAutocryptPeerInfoToSignatureResult(OpenPgpSignatureResult signatureResult,
String trustIdentity) { String autocryptPeerentity) {
boolean hasValidSignature = boolean hasValidSignature =
signatureResult.getResult() == OpenPgpSignatureResult.RESULT_VALID_KEY_CONFIRMED || signatureResult.getResult() == OpenPgpSignatureResult.RESULT_VALID_KEY_CONFIRMED ||
signatureResult.getResult() == OpenPgpSignatureResult.RESULT_VALID_KEY_UNCONFIRMED; signatureResult.getResult() == OpenPgpSignatureResult.RESULT_VALID_KEY_UNCONFIRMED;
@@ -588,18 +588,18 @@ public class OpenPgpService extends Service {
return signatureResult; return signatureResult;
} }
TrustIdentityDataAccessObject trustIdentityDao = new TrustIdentityDataAccessObject(getBaseContext(), AutocryptPeerDataAccessObject autocryptPeerentityDao = new AutocryptPeerDataAccessObject(getBaseContext(),
mApiPermissionHelper.getCurrentCallingPackage()); mApiPermissionHelper.getCurrentCallingPackage());
Long tofuTrustedMasterKeyId = trustIdentityDao.getMasterKeyIdForTrustId(trustIdentity); Long autocryptPeerMasterKeyId = autocryptPeerentityDao.getMasterKeyIdForAutocryptPeer(autocryptPeerentity);
long masterKeyId = signatureResult.getKeyId(); long masterKeyId = signatureResult.getKeyId();
if (tofuTrustedMasterKeyId == null) { if (autocryptPeerMasterKeyId == null) {
trustIdentityDao.setMasterKeyIdForTrustId(trustIdentity, masterKeyId, new Date()); autocryptPeerentityDao.setMasterKeyIdForAutocryptPeer(autocryptPeerentity, masterKeyId, new Date());
return signatureResult.withTrustIdentityResult(TrustIdentityResult.NEW); return signatureResult.withAutocryptPeerResult(AutocryptPeerResult.NEW);
} else if (masterKeyId == tofuTrustedMasterKeyId) { } else if (masterKeyId == autocryptPeerMasterKeyId) {
return signatureResult.withTrustIdentityResult(TrustIdentityResult.OK); return signatureResult.withAutocryptPeerResult(AutocryptPeerResult.OK);
} else { } else {
return signatureResult.withTrustIdentityResult(TrustIdentityResult.MISMATCH); return signatureResult.withAutocryptPeerResult(AutocryptPeerResult.MISMATCH);
} }
} }
@@ -746,14 +746,14 @@ public class OpenPgpService extends Service {
} }
} }
private Intent updateTrustIdKeyImpl(Intent data) { private Intent updateAutocryptPeerImpl(Intent data) {
try { try {
Intent result = new Intent(); Intent result = new Intent();
String trustId = data.getStringExtra(OpenPgpApi.EXTRA_TRUST_IDENTITY); String autocryptPeer = data.getStringExtra(OpenPgpApi.EXTRA_AUTOCRYPT_PEER_ID);
OpenPgpInlineKeyUpdate inlineKeyUpdate = data.getParcelableExtra(OpenPgpApi.EXTRA_INLINE_KEY_DATA); AutocryptPeerUpdate inlineKeyUpdate = data.getParcelableExtra(OpenPgpApi.EXTRA_INLINE_KEY_DATA);
if (inlineKeyUpdate == null || trustId == null) { if (inlineKeyUpdate == null || autocryptPeer == null) {
throw new IllegalArgumentException("need to specify both trust_id and inline_key_data!"); throw new IllegalArgumentException("need to specify both autocrypt_peer_id and inline_key_data!");
} }
UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(inlineKeyUpdate.getKeyData()); UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(inlineKeyUpdate.getKeyData());
@@ -761,10 +761,10 @@ public class OpenPgpService extends Service {
// this will merge if the key already exists - no worries! // this will merge if the key already exists - no worries!
KeyWritableRepository.createDatabaseReadWriteInteractor(this).savePublicKeyRing(uncachedKeyRing); KeyWritableRepository.createDatabaseReadWriteInteractor(this).savePublicKeyRing(uncachedKeyRing);
TrustIdentityDataAccessObject trustIdentityDao = new TrustIdentityDataAccessObject(getBaseContext(), AutocryptPeerDataAccessObject autocryptPeerentityDao = new AutocryptPeerDataAccessObject(getBaseContext(),
mApiPermissionHelper.getCurrentCallingPackage()); mApiPermissionHelper.getCurrentCallingPackage());
Date lastUpdate = trustIdentityDao.getLastUpdateForTrustId(trustId); Date lastUpdate = autocryptPeerentityDao.getLastUpdateForAutocryptPeer(autocryptPeer);
Date updateTimestamp = inlineKeyUpdate.getTimestamp(); Date updateTimestamp = inlineKeyUpdate.getTimestamp();
boolean updateIsNewerThanLastUpdate = lastUpdate == null || lastUpdate.before(updateTimestamp); boolean updateIsNewerThanLastUpdate = lastUpdate == null || lastUpdate.before(updateTimestamp);
@@ -772,23 +772,23 @@ public class OpenPgpService extends Service {
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
return result; return result;
} }
Log.d(Constants.TAG, "Key for trust id is newer"); Log.d(Constants.TAG, "Key for autocrypt peer is newer");
Long trustedMasterKeyId = trustIdentityDao.getMasterKeyIdForTrustId(trustId); Long autocryptPeerMasterKeyId = autocryptPeerentityDao.getMasterKeyIdForAutocryptPeer(autocryptPeer);
if (trustedMasterKeyId == null) { if (autocryptPeerMasterKeyId == null) {
Log.d(Constants.TAG, "No binding for trust id, pinning key"); Log.d(Constants.TAG, "No binding for autocrypt peer, pinning key");
trustIdentityDao.setMasterKeyIdForTrustId(trustId, inlineMasterKeyId, updateTimestamp); autocryptPeerentityDao.setMasterKeyIdForAutocryptPeer(autocryptPeer, inlineMasterKeyId, updateTimestamp);
} else if (inlineMasterKeyId == trustedMasterKeyId) { } else if (inlineMasterKeyId == autocryptPeerMasterKeyId) {
Log.d(Constants.TAG, "Key id is the same - doing nothing"); Log.d(Constants.TAG, "Key id is the same - doing nothing");
} else { } else {
// TODO danger in result intent! // TODO danger in result intent!
trustIdentityDao.setMasterKeyIdForTrustId(trustId, inlineMasterKeyId, updateTimestamp); autocryptPeerentityDao.setMasterKeyIdForAutocryptPeer(autocryptPeer, inlineMasterKeyId, updateTimestamp);
} }
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
return result; return result;
} catch (Exception e) { } catch (Exception e) {
Log.d(Constants.TAG, "exception in updateTrustIdKeyImpl", e); Log.d(Constants.TAG, "exception in updateAutocryptPeerImpl", e);
return createErrorResultIntent(OpenPgpError.GENERIC_ERROR, e.getMessage()); return createErrorResultIntent(OpenPgpError.GENERIC_ERROR, e.getMessage());
} }
} }
@@ -964,8 +964,8 @@ public class OpenPgpService extends Service {
case OpenPgpApi.ACTION_BACKUP: { case OpenPgpApi.ACTION_BACKUP: {
return backupImpl(data, outputStream); return backupImpl(data, outputStream);
} }
case OpenPgpApi.ACTION_UPDATE_TRUST_ID: { case OpenPgpApi.ACTION_UPDATE_AUTOCRYPT_PEER: {
return updateTrustIdKeyImpl(data); return updateAutocryptPeerImpl(data);
} }
default: { default: {
return null; return null;

View File

@@ -39,7 +39,7 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.linked.LinkedAttribute; import org.sufficientlysecure.keychain.linked.LinkedAttribute;
import org.sufficientlysecure.keychain.linked.UriAttribute; import org.sufficientlysecure.keychain.linked.UriAttribute;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiTrustIdentity; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAutocryptPeer;
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.IdentityInfo; import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.IdentityInfo;
@@ -108,15 +108,15 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
} }
private static final String[] TRUST_IDS_PROJECTION = new String[] { private static final String[] TRUST_IDS_PROJECTION = new String[] {
ApiTrustIdentity._ID, ApiAutocryptPeer._ID,
ApiTrustIdentity.PACKAGE_NAME, ApiAutocryptPeer.PACKAGE_NAME,
ApiTrustIdentity.IDENTIFIER, ApiAutocryptPeer.IDENTIFIER,
}; };
private static final int INDEX_PACKAGE_NAME = 1; private static final int INDEX_PACKAGE_NAME = 1;
private static final int INDEX_TRUST_ID = 2; private static final int INDEX_TRUST_ID = 2;
private void correlateOrAddTrustIds(ArrayList<IdentityInfo> identities) { private void correlateOrAddTrustIds(ArrayList<IdentityInfo> identities) {
Cursor cursor = contentResolver.query(ApiTrustIdentity.buildByMasterKeyId(masterKeyId), Cursor cursor = contentResolver.query(ApiAutocryptPeer.buildByMasterKeyId(masterKeyId),
TRUST_IDS_PROJECTION, null, null, null); TRUST_IDS_PROJECTION, null, null, null);
if (cursor == null) { if (cursor == null) {
Log.e(Constants.TAG, "Error loading trust ids!"); Log.e(Constants.TAG, "Error loading trust ids!");
@@ -126,19 +126,19 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
try { try {
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
String packageName = cursor.getString(INDEX_PACKAGE_NAME); String packageName = cursor.getString(INDEX_PACKAGE_NAME);
String trustId = cursor.getString(INDEX_TRUST_ID); String autocryptPeer = cursor.getString(INDEX_TRUST_ID);
Drawable drawable = packageIconGetter.getDrawableForPackageName(packageName); Drawable drawable = packageIconGetter.getDrawableForPackageName(packageName);
Intent trustIdIntent = getTrustIdActivityIntentIfResolvable(packageName, trustId); Intent autocryptPeerIntent = getTrustIdActivityIntentIfResolvable(packageName, autocryptPeer);
UserIdInfo associatedUserIdInfo = findUserIdMatchingTrustId(identities, trustId); UserIdInfo associatedUserIdInfo = findUserIdMatchingTrustId(identities, autocryptPeer);
if (associatedUserIdInfo != null) { if (associatedUserIdInfo != null) {
int position = identities.indexOf(associatedUserIdInfo); int position = identities.indexOf(associatedUserIdInfo);
TrustIdInfo trustIdInfo = TrustIdInfo.create(associatedUserIdInfo, trustId, drawable, trustIdIntent); TrustIdInfo autocryptPeerInfo = TrustIdInfo.create(associatedUserIdInfo, autocryptPeer, drawable, autocryptPeerIntent);
identities.set(position, trustIdInfo); identities.set(position, autocryptPeerInfo);
} else { } else {
TrustIdInfo trustIdInfo = TrustIdInfo.create(trustId, drawable, trustIdIntent); TrustIdInfo autocryptPeerInfo = TrustIdInfo.create(autocryptPeer, drawable, autocryptPeerIntent);
identities.add(trustIdInfo); identities.add(autocryptPeerInfo);
} }
} }
} finally { } finally {
@@ -146,11 +146,11 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
} }
} }
private Intent getTrustIdActivityIntentIfResolvable(String packageName, String trustId) { private Intent getTrustIdActivityIntentIfResolvable(String packageName, String autocryptPeer) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(packageName + ".AUTOCRYPT_PEER_ACTION"); intent.setAction(packageName + ".AUTOCRYPT_PEER_ACTION");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(OpenPgpApi.EXTRA_TRUST_IDENTITY, trustId); intent.putExtra(OpenPgpApi.EXTRA_AUTOCRYPT_PEER_ID, autocryptPeer);
List<ResolveInfo> resolveInfos = getContext().getPackageManager().queryIntentActivities(intent, 0); List<ResolveInfo> resolveInfos = getContext().getPackageManager().queryIntentActivities(intent, 0);
if (resolveInfos != null && !resolveInfos.isEmpty()) { if (resolveInfos != null && !resolveInfos.isEmpty()) {
@@ -160,11 +160,11 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
} }
} }
private static UserIdInfo findUserIdMatchingTrustId(List<IdentityInfo> identities, String trustId) { private static UserIdInfo findUserIdMatchingTrustId(List<IdentityInfo> identities, String autocryptPeer) {
for (IdentityInfo identityInfo : identities) { for (IdentityInfo identityInfo : identities) {
if (identityInfo instanceof UserIdInfo) { if (identityInfo instanceof UserIdInfo) {
UserIdInfo userIdInfo = (UserIdInfo) identityInfo; UserIdInfo userIdInfo = (UserIdInfo) identityInfo;
if (trustId.equals(userIdInfo.getEmail())) { if (autocryptPeer.equals(userIdInfo.getEmail())) {
return userIdInfo; return userIdInfo;
} }
} }
@@ -312,14 +312,14 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
@Nullable @Nullable
public abstract Intent getTrustIdIntent(); public abstract Intent getTrustIdIntent();
static TrustIdInfo create(UserIdInfo userIdInfo, String trustId, Drawable appIcon, Intent trustIdIntent) { static TrustIdInfo create(UserIdInfo userIdInfo, String autocryptPeer, Drawable appIcon, Intent autocryptPeerIntent) {
return new AutoValue_IdentityLoader_TrustIdInfo(userIdInfo.getRank(), userIdInfo.getVerified(), return new AutoValue_IdentityLoader_TrustIdInfo(userIdInfo.getRank(), userIdInfo.getVerified(),
userIdInfo.isPrimary(), trustId, appIcon, userIdInfo, trustIdIntent); userIdInfo.isPrimary(), autocryptPeer, appIcon, userIdInfo, autocryptPeerIntent);
} }
static TrustIdInfo create(String trustId, Drawable appIcon, Intent trustIdIntent) { static TrustIdInfo create(String autocryptPeer, Drawable appIcon, Intent autocryptPeerIntent) {
return new AutoValue_IdentityLoader_TrustIdInfo( return new AutoValue_IdentityLoader_TrustIdInfo(
0, Certs.VERIFIED_SELF, false, trustId, appIcon, null, trustIdIntent); 0, Certs.VERIFIED_SELF, false, autocryptPeer, appIcon, null, autocryptPeerIntent);
} }
} }

View File

@@ -119,8 +119,8 @@ public class IdentitiesPresenter implements LoaderCallbacks<List<IdentityInfo>>
} else if (info instanceof UserIdInfo) { } else if (info instanceof UserIdInfo) {
showUserIdInfo((UserIdInfo) info); showUserIdInfo((UserIdInfo) info);
} else if (info instanceof TrustIdInfo) { } else if (info instanceof TrustIdInfo) {
Intent trustIdIntent = ((TrustIdInfo) info).getTrustIdIntent(); Intent autocryptPeerIntent = ((TrustIdInfo) info).getTrustIdIntent();
viewKeyMvpView.startActivity(trustIdIntent); viewKeyMvpView.startActivity(autocryptPeerIntent);
} }
} }

View File

@@ -24,7 +24,7 @@ import org.sufficientlysecure.keychain.provider.ApiDataAccessObject;
import org.sufficientlysecure.keychain.provider.KeyWritableRepository; import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.provider.KeychainExternalContract.EmailStatus; import org.sufficientlysecure.keychain.provider.KeychainExternalContract.EmailStatus;
import org.sufficientlysecure.keychain.provider.KeyRepositorySaveTest; import org.sufficientlysecure.keychain.provider.KeyRepositorySaveTest;
import org.sufficientlysecure.keychain.provider.TrustIdentityDataAccessObject; import org.sufficientlysecure.keychain.provider.AutocryptPeerDataAccessObject;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
@@ -45,7 +45,7 @@ public class KeychainExternalProviderTest {
static final String USER_ID_SEC_1 = "twi <twi-sec@openkeychain.org>"; static final String USER_ID_SEC_1 = "twi <twi-sec@openkeychain.org>";
static final long KEY_ID_SECRET = 0x5D4DA4423C39122FL; static final long KEY_ID_SECRET = 0x5D4DA4423C39122FL;
static final long KEY_ID_PUBLIC = 0x9A282CE2AB44A382L; static final long KEY_ID_PUBLIC = 0x9A282CE2AB44A382L;
public static final String TRUST_ID = "tid"; public static final String AUTOCRYPT_PEER = "tid";
KeyWritableRepository databaseInteractor = KeyWritableRepository databaseInteractor =
@@ -53,7 +53,7 @@ public class KeychainExternalProviderTest {
ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver(); ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver();
ApiPermissionHelper apiPermissionHelper; ApiPermissionHelper apiPermissionHelper;
ApiDataAccessObject apiDao; ApiDataAccessObject apiDao;
private TrustIdentityDataAccessObject trustIdDao; AutocryptPeerDataAccessObject autocryptPeerDao;
@Before @Before
@@ -67,7 +67,7 @@ public class KeychainExternalProviderTest {
apiDao = new ApiDataAccessObject(RuntimeEnvironment.application); apiDao = new ApiDataAccessObject(RuntimeEnvironment.application);
apiPermissionHelper = new ApiPermissionHelper(RuntimeEnvironment.application, apiDao); apiPermissionHelper = new ApiPermissionHelper(RuntimeEnvironment.application, apiDao);
trustIdDao = new TrustIdentityDataAccessObject(RuntimeEnvironment.application, PACKAGE_NAME); autocryptPeerDao = new AutocryptPeerDataAccessObject(RuntimeEnvironment.application, PACKAGE_NAME);
apiDao.insertApiApp(new AppSettings(PACKAGE_NAME, PACKAGE_SIGNATURE)); apiDao.insertApiApp(new AppSettings(PACKAGE_NAME, PACKAGE_SIGNATURE));
} }
@@ -178,17 +178,17 @@ public class KeychainExternalProviderTest {
} }
@Test @Test
public void testQuery__trustId__withUnconfirmedKey() throws Exception { public void testQuery__autocryptPeer__withUnconfirmedKey() throws Exception {
insertSecretKeyringFrom("/test-keys/testring.sec"); insertSecretKeyringFrom("/test-keys/testring.sec");
insertPublicKeyringFrom("/test-keys/testring.pub"); insertPublicKeyringFrom("/test-keys/testring.pub");
trustIdDao.setMasterKeyIdForTrustId("tid", KEY_ID_PUBLIC, new Date()); autocryptPeerDao.setMasterKeyIdForAutocryptPeer("tid", KEY_ID_PUBLIC, new Date());
Cursor cursor = contentResolver.query( Cursor cursor = contentResolver.query(
EmailStatus.CONTENT_URI, new String[] { EmailStatus.CONTENT_URI, new String[] {
EmailStatus.EMAIL_ADDRESS, EmailStatus.USER_ID_STATUS, EmailStatus.USER_ID, EmailStatus.EMAIL_ADDRESS, EmailStatus.USER_ID_STATUS, EmailStatus.USER_ID,
EmailStatus.TRUST_ID_STATUS }, EmailStatus.AUTOCRYPT_PEER_STATE },
null, new String [] { TRUST_ID }, null null, new String [] { AUTOCRYPT_PEER }, null
); );
assertNotNull(cursor); assertNotNull(cursor);
@@ -201,18 +201,18 @@ public class KeychainExternalProviderTest {
} }
@Test @Test
public void testQuery__trustId__withConfirmedKey() throws Exception { public void testQuery__withAutocryptPeer__withConfirmedKey() throws Exception {
insertSecretKeyringFrom("/test-keys/testring.sec"); insertSecretKeyringFrom("/test-keys/testring.sec");
insertPublicKeyringFrom("/test-keys/testring.pub"); insertPublicKeyringFrom("/test-keys/testring.pub");
trustIdDao.setMasterKeyIdForTrustId("tid", KEY_ID_PUBLIC, new Date()); autocryptPeerDao.setMasterKeyIdForAutocryptPeer("tid", KEY_ID_PUBLIC, new Date());
certifyKey(KEY_ID_SECRET, KEY_ID_PUBLIC, USER_ID_1); certifyKey(KEY_ID_SECRET, KEY_ID_PUBLIC, USER_ID_1);
Cursor cursor = contentResolver.query( Cursor cursor = contentResolver.query(
EmailStatus.CONTENT_URI, new String[] { EmailStatus.CONTENT_URI, new String[] {
EmailStatus.EMAIL_ADDRESS, EmailStatus.USER_ID_STATUS, EmailStatus.USER_ID, EmailStatus.EMAIL_ADDRESS, EmailStatus.USER_ID_STATUS, EmailStatus.USER_ID,
EmailStatus.TRUST_ID_STATUS }, EmailStatus.AUTOCRYPT_PEER_STATE },
null, new String [] { TRUST_ID }, null null, new String [] { AUTOCRYPT_PEER }, null
); );
assertNotNull(cursor); assertNotNull(cursor);
@@ -225,7 +225,7 @@ public class KeychainExternalProviderTest {
} }
@Test @Test
public void testQuery__withTrustId() throws Exception { public void testQuery__withAutocryptPeer() throws Exception {
insertSecretKeyringFrom("/test-keys/testring.sec"); insertSecretKeyringFrom("/test-keys/testring.sec");
insertPublicKeyringFrom("/test-keys/testring.pub"); insertPublicKeyringFrom("/test-keys/testring.pub");