Fix tracking of created_at in SenderKeyDatabase.

fork-5.53.8
Greyson Parrelli 2021-11-06 00:18:42 -04:00
rodzic f5af964286
commit 100796b3b9
4 zmienionych plików z 27 dodań i 10 usunięć

Wyświetl plik

@ -735,7 +735,7 @@ private static final String[] GROUP_PROJECTION = {
List<UUID> removed = DecryptedGroupUtil.removedMembersUuidList(change);
if (removed.size() > 0) {
Log.i(TAG, removed.size() + " members were removed from group " + groupId + ". Rotating the sender key.");
Log.i(TAG, removed.size() + " members were removed from group " + groupId + ". Rotating the DistributionId " + distributionId);
SenderKeyUtil.rotateOurKey(context, distributionId);
}
}

Wyświetl plik

@ -54,14 +54,31 @@ public class SenderKeyDatabase extends Database {
public void store(@NonNull SignalProtocolAddress address, @NonNull DistributionId distributionId, @NonNull SenderKeyRecord record) {
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
ContentValues values = new ContentValues();
values.put(ADDRESS, address.getName());
values.put(DEVICE, address.getDeviceId());
values.put(DISTRIBUTION_ID, distributionId.toString());
values.put(RECORD, record.serialize());
values.put(CREATED_AT, System.currentTimeMillis());
db.beginTransaction();
try {
ContentValues updateValues = new ContentValues();
updateValues.put(RECORD, record.serialize());
db.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE);
String query = ADDRESS + " = ? AND " + DEVICE + " = ? AND " + DISTRIBUTION_ID + " = ?";
String[] args = SqlUtil.buildArgs(address.getName(), address.getDeviceId(), distributionId);
int updateCount = db.update(TABLE_NAME, updateValues, query, args);
if (updateCount <= 0) {
Log.d(TAG, "New sender key " + distributionId + " from " + address);
ContentValues insertValues = new ContentValues();
insertValues.put(ADDRESS, address.getName());
insertValues.put(DEVICE, address.getDeviceId());
insertValues.put(DISTRIBUTION_ID, distributionId.toString());
insertValues.put(RECORD, record.serialize());
insertValues.put(CREATED_AT, System.currentTimeMillis());
db.insertWithOnConflict(TABLE_NAME, null, insertValues, SQLiteDatabase.CONFLICT_REPLACE);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
public @Nullable SenderKeyRecord load(@NonNull SignalProtocolAddress address, @NonNull DistributionId distributionId) {

Wyświetl plik

@ -28,7 +28,7 @@ public class LogSectionSenderKey implements LogSection {
public @NonNull CharSequence getContent(@NonNull Context context) {
StringBuilder builder = new StringBuilder();
builder.append("--- Sender Keys").append("\n\n");
builder.append("--- Sender Keys Created By This Device").append("\n\n");
try (Cursor cursor = DatabaseFactory.getSenderKeyDatabase(context).getAllCreatedBySelf()) {
builder.append(AsciiArt.tableFor(cursor)).append("\n\n");
}

Wyświetl plik

@ -216,7 +216,7 @@ public final class GroupSendUtil {
long keyAge = System.currentTimeMillis() - keyCreateTime;
if (keyCreateTime != -1 && keyAge > FeatureFlags.senderKeyMaxAge()) {
Log.w(TAG, "Key is " + (keyAge) + " ms old (~" + TimeUnit.MILLISECONDS.toDays(keyAge) + " days). Rotating.");
Log.w(TAG, "DistributionId " + distributionId + " was created at " + keyCreateTime + " and is " + (keyAge) + " ms old (~" + TimeUnit.MILLISECONDS.toDays(keyAge) + " days). Rotating.");
SenderKeyUtil.rotateOurKey(context, distributionId);
}