Commit 476a256c authored by Moxie Marlinspike's avatar Moxie Marlinspike Committed by Bastien Le Querrec

Support for attachment digests

// FREEBIE

Upstream commit: https://github.com/signalapp/Signal-Android/commit/79e925051ac3f0f1dacfd96a4c18fd9253c30018
parent eabf1422
Pipeline #178 passed with stages
in 7 minutes and 44 seconds
......@@ -22,8 +22,12 @@ public abstract class Attachment {
@Nullable
private final String relay;
@Nullable
private final byte[] digest;
public Attachment(@NonNull String contentType, int transferState, long size,
@Nullable String location, @Nullable String key, @Nullable String relay)
@Nullable String location, @Nullable String key, @Nullable String relay,
@Nullable byte[] digest)
{
this.contentType = contentType;
this.transferState = transferState;
......@@ -31,6 +35,7 @@ public abstract class Attachment {
this.location = location;
this.key = key;
this.relay = relay;
this.digest = digest;
}
@Nullable
......@@ -71,4 +76,9 @@ public abstract class Attachment {
public String getRelay() {
return relay;
}
@Nullable
public byte[] getDigest() {
return digest;
}
}
......@@ -15,9 +15,9 @@ public class DatabaseAttachment extends Attachment {
public DatabaseAttachment(AttachmentId attachmentId, long mmsId,
boolean hasData, boolean hasThumbnail,
String contentType, int transferProgress, long size,
String location, String key, String relay)
String location, String key, String relay, byte[] digest)
{
super(contentType, transferProgress, size, location, key, relay);
super(contentType, transferProgress, size, location, key, relay, digest);
this.attachmentId = attachmentId;
this.hasData = hasData;
this.hasThumbnail = hasThumbnail;
......
......@@ -10,7 +10,7 @@ import org.smssecure.smssecure.database.MmsDatabase;
public class MmsNotificationAttachment extends Attachment {
public MmsNotificationAttachment(int status, long size) {
super("application/mms", getTransferStateFromStatus(status), size, null, null, null);
super("application/mms", getTransferStateFromStatus(status), size, null, null, null, null);
}
@Nullable
......
......@@ -16,7 +16,7 @@ public class UriAttachment extends Attachment {
public UriAttachment(@NonNull Uri dataUri, @Nullable Uri thumbnailUri,
@NonNull String contentType, int transferState, long size)
{
super(contentType, transferState, size, null, null, null);
super(contentType, transferState, size, null, null, null, null);
this.dataUri = dataUri;
this.thumbnailUri = thumbnailUri;
}
......
......@@ -76,6 +76,7 @@ public class AttachmentDatabase extends Database {
static final String THUMBNAIL = "thumbnail";
static final String THUMBNAIL_ASPECT_RATIO = "aspect_ratio";
static final String UNIQUE_ID = "unique_id";
static final String DIGEST = "digest";
public static final int TRANSFER_PROGRESS_DONE = 0;
public static final int TRANSFER_PROGRESS_STARTED = 1;
......@@ -88,7 +89,7 @@ public class AttachmentDatabase extends Database {
MMS_ID, CONTENT_TYPE, NAME, CONTENT_DISPOSITION,
CONTENT_LOCATION, DATA, THUMBNAIL, TRANSFER_STATE,
SIZE, THUMBNAIL, THUMBNAIL_ASPECT_RATIO,
UNIQUE_ID};
UNIQUE_ID, DIGEST};
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ROW_ID + " INTEGER PRIMARY KEY, " +
MMS_ID + " INTEGER, " + "seq" + " INTEGER DEFAULT 0, " +
......@@ -97,7 +98,8 @@ public class AttachmentDatabase extends Database {
CONTENT_LOCATION + " TEXT, " + "ctt_s" + " INTEGER, " +
"ctt_t" + " TEXT, " + "encrypted" + " INTEGER, " +
TRANSFER_STATE + " INTEGER, "+ DATA + " TEXT, " + SIZE + " INTEGER, " +
THUMBNAIL + " TEXT, " + THUMBNAIL_ASPECT_RATIO + " REAL, " + UNIQUE_ID + " INTEGER NOT NULL);";
THUMBNAIL + " TEXT, " + THUMBNAIL_ASPECT_RATIO + " REAL, " + UNIQUE_ID + " INTEGER NOT NULL, " +
DIGEST + " BLOB);";
public static final String[] CREATE_INDEXS = {
"CREATE INDEX IF NOT EXISTS part_mms_id_index ON " + TABLE_NAME + " (" + MMS_ID + ");",
......@@ -263,6 +265,7 @@ public class AttachmentDatabase extends Database {
values.put(TRANSFER_STATE, TRANSFER_PROGRESS_DONE);
values.put(CONTENT_LOCATION, (String)null);
values.put(CONTENT_DISPOSITION, (String)null);
values.put(DIGEST, (byte[])null);
values.put(NAME, (String) null);
if (database.update(TABLE_NAME, values, PART_ID_WHERE, attachmentId.toStrings()) == 0) {
......@@ -321,7 +324,8 @@ public class AttachmentDatabase extends Database {
dataSize,
databaseAttachment.getLocation(),
databaseAttachment.getKey(),
databaseAttachment.getRelay());
databaseAttachment.getRelay(),
databaseAttachment.getDigest());
}
......@@ -443,7 +447,8 @@ public class AttachmentDatabase extends Database {
cursor.getLong(cursor.getColumnIndexOrThrow(SIZE)),
cursor.getString(cursor.getColumnIndexOrThrow(CONTENT_LOCATION)),
cursor.getString(cursor.getColumnIndexOrThrow(CONTENT_DISPOSITION)),
cursor.getString(cursor.getColumnIndexOrThrow(NAME)));
cursor.getString(cursor.getColumnIndexOrThrow(NAME)),
cursor.getBlob(cursor.getColumnIndexOrThrow(DIGEST)));
}
......@@ -467,6 +472,7 @@ public class AttachmentDatabase extends Database {
contentValues.put(TRANSFER_STATE, attachment.getTransferState());
contentValues.put(UNIQUE_ID, uniqueId);
contentValues.put(CONTENT_LOCATION, attachment.getLocation());
contentValues.put(DIGEST, attachment.getDigest());
contentValues.put(CONTENT_DISPOSITION, attachment.getKey());
contentValues.put(NAME, attachment.getRelay());
......
......@@ -74,13 +74,14 @@ public class DatabaseFactory {
private static final int INTRODUCED_SUBSCRIPTION_ID_VERSION = 28;
private static final int INTRODUCED_LAST_SEEN = 29;
private static final int INTRODUCED_NOTIFIED = 30;
private static final int INTRODUCED_DIGEST = 31;
/*
* Yes, INTRODUCED_XMPP_TRANSPORT > DATABASE_VERSION to allow database
* downgrade when XMPP transport will be included in unstable branch.
*/
private static final int INTRODUCED_XMPP_TRANSPORT = 31;
private static final int DATABASE_VERSION = 30;
private static final int INTRODUCED_XMPP_TRANSPORT = 32;
private static final int DATABASE_VERSION = 31;
private static final String DATABASE_NAME = "messages.db";
private static final Object lock = new Object();
......@@ -566,6 +567,10 @@ public class DatabaseFactory {
db.execSQL("CREATE INDEX IF NOT EXISTS mms_read_and_notified_and_thread_id_index ON mms(read,notified,thread_id)");
}
if (oldVersion < INTRODUCED_DIGEST) {
db.execSQL("ALTER TABLE part ADD COLUMN digest BLOB");
}
db.setTransactionSuccessful();
db.endTransaction();
}
......
......@@ -86,7 +86,7 @@ public class MediaDatabase extends Database {
}
public Attachment getAttachment() {
return new DatabaseAttachment(attachmentId, mmsId, hasData, hasThumbnail, contentType, transferState, size, null, null, null);
return new DatabaseAttachment(attachmentId, mmsId, hasData, hasThumbnail, contentType, transferState, size, null, null, null, null);
}
public String getContentType() {
......
......@@ -137,6 +137,7 @@ public class MmsDatabase extends MessagingDatabase {
AttachmentDatabase.THUMBNAIL,
AttachmentDatabase.CONTENT_TYPE,
AttachmentDatabase.CONTENT_LOCATION,
AttachmentDatabase.DIGEST,
AttachmentDatabase.CONTENT_DISPOSITION,
AttachmentDatabase.NAME,
AttachmentDatabase.TRANSFER_STATE
......@@ -487,7 +488,8 @@ public class MmsDatabase extends MessagingDatabase {
databaseAttachment.getSize(),
databaseAttachment.getLocation(),
databaseAttachment.getKey(),
databaseAttachment.getRelay()));
databaseAttachment.getRelay(),
databaseAttachment.getDigest()));
}
return insertMediaMessage(masterSecret,
......
......@@ -59,6 +59,7 @@ public class MmsSmsDatabase extends Database {
AttachmentDatabase.THUMBNAIL,
AttachmentDatabase.CONTENT_TYPE,
AttachmentDatabase.CONTENT_LOCATION,
AttachmentDatabase.DIGEST,
AttachmentDatabase.CONTENT_DISPOSITION,
AttachmentDatabase.NAME,
AttachmentDatabase.TRANSFER_STATE};
......@@ -136,6 +137,7 @@ public class MmsSmsDatabase extends Database {
AttachmentDatabase.THUMBNAIL,
AttachmentDatabase.CONTENT_TYPE,
AttachmentDatabase.CONTENT_LOCATION,
AttachmentDatabase.DIGEST,
AttachmentDatabase.CONTENT_DISPOSITION,
AttachmentDatabase.NAME,
AttachmentDatabase.TRANSFER_STATE};
......@@ -163,6 +165,7 @@ public class MmsSmsDatabase extends Database {
AttachmentDatabase.THUMBNAIL,
AttachmentDatabase.CONTENT_TYPE,
AttachmentDatabase.CONTENT_LOCATION,
AttachmentDatabase.DIGEST,
AttachmentDatabase.CONTENT_DISPOSITION,
AttachmentDatabase.NAME,
AttachmentDatabase.TRANSFER_STATE};
......@@ -214,6 +217,7 @@ public class MmsSmsDatabase extends Database {
mmsColumnsPresent.add(AttachmentDatabase.THUMBNAIL);
mmsColumnsPresent.add(AttachmentDatabase.CONTENT_TYPE);
mmsColumnsPresent.add(AttachmentDatabase.CONTENT_LOCATION);
mmsColumnsPresent.add(AttachmentDatabase.DIGEST);
mmsColumnsPresent.add(AttachmentDatabase.CONTENT_DISPOSITION);
mmsColumnsPresent.add(AttachmentDatabase.NAME);
mmsColumnsPresent.add(AttachmentDatabase.TRANSFER_STATE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment