Deprecate encrypted storage DB types

pull/1/head
Moxie Marlinspike 7 years ago
parent f36b296e2e
commit 5496f5baac

@ -289,11 +289,6 @@ public class MmsDatabase extends MessagingDatabase {
return readerFor(rawQuery(where, null));
}
public Reader getDecryptInProgressMessages() {
String where = MESSAGE_BOX + " & " + (Types.ENCRYPTION_ASYMMETRIC_BIT) + " != 0";
return readerFor(rawQuery(where, null));
}
private void updateMailboxBitmask(long id, long maskOff, long maskOn, Optional<Long> threadId) {
SQLiteDatabase db = databaseHelper.getWritableDatabase();
db.execSQL("UPDATE " + TABLE_NAME +
@ -583,7 +578,7 @@ public class MmsDatabase extends MessagingDatabase {
ContentValues contentValues = new ContentValues();
contentValues.put(ADDRESS, request.getRecipient().getAddress().serialize());
contentValues.put(DATE_SENT, request.getSentTimeMillis());
contentValues.put(MESSAGE_BOX, Types.BASE_INBOX_TYPE | Types.SECURE_MESSAGE_BIT | Types.ENCRYPTION_SYMMETRIC_BIT);
contentValues.put(MESSAGE_BOX, Types.BASE_INBOX_TYPE | Types.SECURE_MESSAGE_BIT);
contentValues.put(THREAD_ID, getThreadIdForMessage(messageId));
contentValues.put(READ, 1);
contentValues.put(DATE_RECEIVED, contentValues.getAsLong(DATE_SENT));

@ -73,8 +73,8 @@ public interface MmsSmsColumns {
// Encrypted Storage Information XXX
public static final long ENCRYPTION_MASK = 0xFF000000;
public static final long ENCRYPTION_SYMMETRIC_BIT = 0x80000000;
protected static final long ENCRYPTION_ASYMMETRIC_BIT = 0x40000000;
// public static final long ENCRYPTION_SYMMETRIC_BIT = 0x80000000; Deprecated
// protected static final long ENCRYPTION_ASYMMETRIC_BIT = 0x40000000; Deprecated
protected static final long ENCRYPTION_REMOTE_BIT = 0x20000000;
protected static final long ENCRYPTION_REMOTE_FAILED_BIT = 0x10000000;
protected static final long ENCRYPTION_REMOTE_NO_SESSION_BIT = 0x08000000;
@ -209,14 +209,6 @@ public interface MmsSmsColumns {
return (type & GROUP_QUIT_BIT) != 0;
}
public static boolean isSymmetricEncryption(long type) {
return (type & ENCRYPTION_SYMMETRIC_BIT) != 0;
}
public static boolean isAsymmetricEncryption(long type) {
return (type & ENCRYPTION_ASYMMETRIC_BIT) != 0;
}
public static boolean isFailedDecryptType(long type) {
return (type & ENCRYPTION_REMOTE_FAILED_BIT) != 0;
}
@ -226,7 +218,7 @@ public interface MmsSmsColumns {
}
public static boolean isDecryptInProgressType(long type) {
return (type & ENCRYPTION_ASYMMETRIC_BIT) != 0;
return (type & 0x40000000) != 0; // Inline deprecated asymmetric encryption type
}
public static boolean isNoRemoteSessionType(long type) {

@ -80,7 +80,7 @@ public class PlaintextBackupImporter {
@SuppressWarnings("SameParameterValue")
private static void addTranslatedTypeToStatement(SQLiteStatement statement, int index, int type) {
statement.bindLong(index, SmsDatabase.Types.translateFromSystemBaseType(type) | SmsDatabase.Types.ENCRYPTION_SYMMETRIC_BIT);
statement.bindLong(index, SmsDatabase.Types.translateFromSystemBaseType(type));
}
private static void addStringToStatement(SQLiteStatement statement, int index, String value) {

@ -664,20 +664,6 @@ public class SmsDatabase extends MessagingDatabase {
return db.query(TABLE_NAME, MESSAGE_PROJECTION, outgoingSelection, null, null, null, null);
}
public Cursor getDecryptInProgressMessages() {
String where = TYPE + " & " + (Types.ENCRYPTION_ASYMMETRIC_BIT) + " != 0";
SQLiteDatabase db = databaseHelper.getReadableDatabase();
return db.query(TABLE_NAME, MESSAGE_PROJECTION, where, null, null, null, null);
}
// public Cursor getEncryptedRogueMessages(Recipient recipient) {
// String selection = TYPE + " & " + Types.ENCRYPTION_REMOTE_NO_SESSION_BIT + " != 0" +
// " AND PHONE_NUMBERS_EQUAL(" + ADDRESS + ", ?)";
// String[] args = {recipient.getNumber()};
// SQLiteDatabase db = databaseHelper.getReadableDatabase();
// return db.query(TABLE_NAME, MESSAGE_PROJECTION, selection, args, null, null, null);
// }
public Cursor getExpirationStartedMessages() {
String where = EXPIRE_STARTED + " > 0";
SQLiteDatabase db = databaseHelper.getReadableDatabase();
@ -895,14 +881,7 @@ public class SmsDatabase extends MessagingDatabase {
}
protected DisplayRecord.Body getBody(Cursor cursor) {
long type = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.TYPE));
String body = cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.BODY));
if (Types.isSymmetricEncryption(type)) {
return new DisplayRecord.Body(body, false);
} else {
return new DisplayRecord.Body(body, true);
}
return new DisplayRecord.Body(cursor.getString(cursor.getColumnIndexOrThrow(BODY)), true);
}
public void close() {

@ -69,10 +69,10 @@ public class SmsMigrator {
int columnIndex = cursor.getColumnIndexOrThrow(key);
if (cursor.isNull(columnIndex)) {
statement.bindLong(index, SmsDatabase.Types.BASE_INBOX_TYPE | SmsDatabase.Types.ENCRYPTION_SYMMETRIC_BIT);
statement.bindLong(index, SmsDatabase.Types.BASE_INBOX_TYPE);
} else {
long theirType = cursor.getLong(columnIndex);
statement.bindLong(index, SmsDatabase.Types.translateFromSystemBaseType(theirType) | SmsDatabase.Types.ENCRYPTION_SYMMETRIC_BIT);
statement.bindLong(index, SmsDatabase.Types.translateFromSystemBaseType(theirType));
}
}

@ -416,7 +416,7 @@ public class ClassicOpenHelper extends SQLiteOpenHelper {
ContentValues update = new ContentValues();
update.put(SmsDatabase.BODY, encryptedBody);
update.put(SmsDatabase.TYPE, type | SmsDatabase.Types.ENCRYPTION_SYMMETRIC_BIT);
update.put(SmsDatabase.TYPE, type | 0x80000000); // Inline now deprecated symmetric encryption type
db.update(SmsDatabase.TABLE_NAME, update, SmsDatabase.ID + " = ?",
new String[] {String.valueOf(id)});

@ -73,9 +73,7 @@ public class MediaMmsMessageRecord extends MmsMessageRecord {
@Override
public SpannableString getDisplayBody() {
if (MmsDatabase.Types.isDecryptInProgressType(type)) {
return emphasisAdded(context.getString(R.string.MmsMessageRecord_decrypting_mms_please_wait));
} else if (MmsDatabase.Types.isFailedDecryptType(type)) {
if (MmsDatabase.Types.isFailedDecryptType(type)) {
return emphasisAdded(context.getString(R.string.MmsMessageRecord_bad_encrypted_mms_message));
} else if (MmsDatabase.Types.isDuplicateMessageType(type)) {
return emphasisAdded(context.getString(R.string.SmsMessageRecord_duplicate_message));

@ -86,10 +86,6 @@ public abstract class MessageRecord extends DisplayRecord {
return MmsSmsColumns.Types.isLegacyType(type);
}
public boolean isAsymmetricEncryption() {
return MmsSmsColumns.Types.isAsymmetricEncryption(type);
}
@Override
public SpannableString getDisplayBody() {
if (isGroupUpdate() && isOutgoing()) {

@ -78,8 +78,6 @@ public class SmsMessageRecord extends MessageRecord {
return emphasisAdded(context.getString(R.string.ConversationItem_received_key_exchange_message_tap_to_process));
} else if (SmsDatabase.Types.isDuplicateMessageType(type)) {
return emphasisAdded(context.getString(R.string.SmsMessageRecord_duplicate_message));
} else if (SmsDatabase.Types.isDecryptInProgressType(type)) {
return emphasisAdded(context.getString(R.string.MessageDisplayHelper_decrypting_please_wait));
} else if (SmsDatabase.Types.isNoRemoteSessionType(type)) {
return emphasisAdded(context.getString(R.string.MessageDisplayHelper_message_encrypted_for_non_existing_session));
} else if (!getBody().isPlaintext()) {

@ -72,9 +72,7 @@ public class ThreadRecord extends DisplayRecord {
@Override
public SpannableString getDisplayBody() {
if (SmsDatabase.Types.isDecryptInProgressType(type)) {
return emphasisAdded(context.getString(R.string.MessageDisplayHelper_decrypting_please_wait));
} else if (isGroupUpdate()) {
if (isGroupUpdate()) {
return emphasisAdded(context.getString(R.string.ThreadRecord_group_updated));
} else if (isGroupQuit()) {
return emphasisAdded(context.getString(R.string.ThreadRecord_left_the_group));

Loading…
Cancel
Save