clean up remnants of KeychainContract

This commit is contained in:
Vincent Breitmoser 2018-07-24 20:50:11 +02:00
parent 6f8b972f78
commit 48383211c3
5 changed files with 23 additions and 123 deletions

View File

@ -151,7 +151,7 @@ public class AndroidTestHelpers {
public static void cleanupForTests(Context context) throws Exception {
KeychainDatabase.getInstance(context).clearDatabase();
// KeychainDatabase.getInstance(context).clearDatabase();
// import these two, make sure they're there
importKeysFromResource(context, "x.sec.asc");

View File

@ -63,7 +63,7 @@ public class EditKeyTest {
public void test01Edit() throws Exception {
Activity activity = mActivity.getActivity();
KeychainDatabase.getInstance(activity).clearDatabase();
// KeychainDatabase.getInstance(activity).clearDatabase();
// import key for testing, get a stable initial state
importKeysFromResource(activity, "x.sec.asc");

View File

@ -34,9 +34,6 @@ import android.database.SQLException;
import android.database.sqlite.SQLiteException;
import org.sufficientlysecure.keychain.daos.LocalSecretKeyStorage;
import org.sufficientlysecure.keychain.provider.KeychainContract.CertsColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeysColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPacketsColumns;
import org.sufficientlysecure.keychain.util.Preferences;
import timber.log.Timber;
@ -63,20 +60,6 @@ public class KeychainDatabase {
return sInstance;
}
public static KeychainDatabase getTemporaryInstance(Context context) {
return new KeychainDatabase(context.getApplicationContext());
}
public interface Tables {
String KEY_RINGS_PUBLIC = "keyrings_public";
String KEYS = "keys";
String KEY_SIGNATURES = "key_signatures";
String USER_PACKETS = "user_packets";
String CERTS = "certs";
String API_ALLOWED_KEYS = "api_allowed_keys";
String OVERRIDDEN_WARNINGS = "overridden_warnings";
}
private KeychainDatabase(Context context) {
supportSQLiteOpenHelper =
new FrameworkSQLiteOpenHelperFactory()
@ -119,6 +102,7 @@ public class KeychainDatabase {
return supportSQLiteOpenHelper.getWritableDatabase();
}
@SuppressWarnings("deprecation") // using some sqldelight constants
private void onCreate(SupportSQLiteDatabase db, Context context) {
Timber.w("Creating database...");
@ -136,13 +120,13 @@ public class KeychainDatabase {
db.execSQL(KeysModel.VALIDKEYSVIEW);
db.execSQL(UserPacketsModel.UIDSTATUS);
db.execSQL("CREATE INDEX keys_by_rank ON keys (" + KeysColumns.RANK + ", " + KeysColumns.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX uids_by_rank ON user_packets (" + UserPacketsColumns.RANK + ", "
+ UserPacketsColumns.USER_ID + ", " + UserPacketsColumns.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX keys_by_rank ON keys (" + KeysModel.RANK + ", " + KeysModel.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX uids_by_rank ON user_packets (" + UserPacketsModel.RANK + ", "
+ UserPacketsModel.USER_ID + ", " + UserPacketsModel.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX verified_certs ON certs ("
+ CertsColumns.VERIFIED + ", " + CertsColumns.MASTER_KEY_ID + ");");
+ CertsModel.VERIFIED + ", " + CertsModel.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX uids_by_email ON user_packets ("
+ UserPacketsColumns.EMAIL + ");");
+ UserPacketsModel.EMAIL + ");");
Preferences.getPreferences(context).setKeySignaturesTableInitialized();
}
@ -243,11 +227,9 @@ public class KeychainDatabase {
case 12:
// do nothing here, just consolidate
case 13:
db.execSQL("CREATE INDEX keys_by_rank ON keys (" + KeysColumns.RANK + ");");
db.execSQL("CREATE INDEX uids_by_rank ON user_packets (" + UserPacketsColumns.RANK + ", "
+ UserPacketsColumns.USER_ID + ", " + UserPacketsColumns.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX verified_certs ON certs ("
+ CertsColumns.VERIFIED + ", " + CertsColumns.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX keys_by_rank ON keys (rank);");
db.execSQL("CREATE INDEX uids_by_rank ON user_packets (rank, user_id, master_key_id);");
db.execSQL("CREATE INDEX verified_certs ON certs (verified, master_key_id);");
case 14:
db.execSQL("ALTER TABLE user_packets ADD COLUMN name TEXT");
db.execSQL("ALTER TABLE user_packets ADD COLUMN email TEXT");
@ -477,11 +459,4 @@ public class KeychainDatabase {
copy(in, out);
}
// DANGEROUS, use in test code ONLY!
public void clearDatabase() {
getWritableDatabase().execSQL("delete from " + KeyRingsPublicModel.TABLE_NAME);
getWritableDatabase().execSQL("delete from " + ApiAllowedKeysModel.TABLE_NAME);
getWritableDatabase().execSQL("delete from api_apps");
}
}

View File

@ -1,83 +0,0 @@
/*
* Copyright (C) 2017 Schürmann & Breitmoser GbR
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.provider;
import android.provider.BaseColumns;
public class KeychainContract {
public interface KeysColumns {
String MASTER_KEY_ID = "master_key_id"; // not a database id
String RANK = "rank";
String KEY_ID = "key_id"; // not a database id
String ALGORITHM = "algorithm";
String FINGERPRINT = "fingerprint";
String KEY_SIZE = "key_size";
String KEY_CURVE_OID = "key_curve_oid";
String CAN_SIGN = "can_sign";
String CAN_ENCRYPT = "can_encrypt";
String CAN_CERTIFY = "can_certify";
String CAN_AUTHENTICATE = "can_authenticate";
String IS_REVOKED = "is_revoked";
String IS_SECURE = "is_secure";
String HAS_SECRET = "has_secret";
String CREATION = "creation";
String EXPIRY = "expiry";
}
public interface UserPacketsColumns {
String MASTER_KEY_ID = "master_key_id"; // foreign key to key_rings._ID
String TYPE = "type"; // not a database id
String USER_ID = "user_id"; // not a database id
String NAME = "name";
String EMAIL = "email";
String COMMENT = "comment";
String ATTRIBUTE_DATA = "attribute_data"; // not a database id
String RANK = "rank"; // ONLY used for sorting! no key, no nothing!
String IS_PRIMARY = "is_primary";
String IS_REVOKED = "is_revoked";
}
public interface CertsColumns {
String MASTER_KEY_ID = "master_key_id";
String RANK = "rank";
String KEY_ID_CERTIFIER = "key_id_certifier";
String TYPE = "type";
String VERIFIED = "verified";
String CREATION = "creation";
String DATA = "data";
}
public static class Keys implements KeysColumns, BaseColumns {
}
public static class UserPackets implements UserPacketsColumns, BaseColumns {
}
public static class Certs implements CertsColumns, BaseColumns {
public static final int VERIFIED_SECRET = 1;
public static final int VERIFIED_SELF = 2;
}
private KeychainContract() {
}
}

View File

@ -54,8 +54,8 @@ public class KeyRepositorySaveTest {
ShadowLog.stream = System.out;
}
@Test public void testImportCooperPair() throws Exception {
@Test
public void testImportCooperPairOne() throws Exception {
// insert two keys with same long key id, make sure the second one gets rejected either way!
UncachedKeyRing first =
readRingFromResource("/test-keys/cooperpair/9E669861368BCA0BE42DAF7DDDA252EBB8EBE1AF.asc");
@ -69,10 +69,18 @@ public class KeyRepositorySaveTest {
Assert.assertTrue("first keyring import should succeed", result.success());
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(second);
Assert.assertFalse("second keyring import should fail", result.success());
}
KeychainDatabase.getInstance(RuntimeEnvironment.application).clearDatabase();
@Test
public void testImportCooperPairTwo() throws Exception {
// insert two keys with same long key id, make sure the second one gets rejected either way!
UncachedKeyRing first =
readRingFromResource("/test-keys/cooperpair/9E669861368BCA0BE42DAF7DDDA252EBB8EBE1AF.asc");
UncachedKeyRing second =
readRingFromResource("/test-keys/cooperpair/A55120427374F3F7AA5F1166DDA252EBB8EBE1AF.asc");
SaveKeyringResult result;
// and the other way around
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(second);
Assert.assertTrue("first keyring import should succeed", result.success());
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(first);