check if encrypted pgp file get deleted

This commit is contained in:
Daniel Gultsch 2019-01-10 21:24:24 +01:00
parent 8ab4ca7138
commit 7cabb2c377
5 changed files with 1474 additions and 1477 deletions

View file

@ -209,10 +209,10 @@ public class PgpDecryptionService {
URL url = message.getFileParams().url; URL url = message.getFileParams().url;
mXmppConnectionService.getFileBackend().updateFileParams(message, url); mXmppConnectionService.getFileBackend().updateFileParams(message, url);
message.setEncryption(Message.ENCRYPTION_DECRYPTED); message.setEncryption(Message.ENCRYPTION_DECRYPTED);
mXmppConnectionService.updateMessage(message);
if (!inputFile.delete()) { if (!inputFile.delete()) {
Log.w(Config.LOGTAG,"unable to delete pgp encrypted source file "+inputFile.getAbsolutePath()); Log.w(Config.LOGTAG,"unable to delete pgp encrypted source file "+inputFile.getAbsolutePath());
} }
mXmppConnectionService.updateMessage(message);
skipNotificationPush = true; skipNotificationPush = true;
mXmppConnectionService.getFileBackend().updateMediaScanner(outputFile, () -> notifyIfPending(message)); mXmppConnectionService.getFileBackend().updateMediaScanner(outputFile, () -> notifyIfPending(message));
break; break;

View file

@ -179,20 +179,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
} }
} }
public void findMessagesWithFiles(final OnMessageFound onMessageFound) {
final ArrayList<Message> results = new ArrayList<>();
synchronized (this.messages) {
for (final Message m : this.messages) {
if (m.isFileOrImage() && m.getEncryption() != Message.ENCRYPTION_PGP) {
results.add(m);
}
}
}
for(Message result : results) {
onMessageFound.onMessageFound(result);
}
}
public Message findMessageWithFileAndUuid(final String uuid) { public Message findMessageWithFileAndUuid(final String uuid) {
synchronized (this.messages) { synchronized (this.messages) {
for (final Message message : this.messages) { for (final Message message : this.messages) {
@ -208,11 +194,15 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
public boolean markAsDeleted(final List<String> uuids) { public boolean markAsDeleted(final List<String> uuids) {
boolean deleted = false; boolean deleted = false;
final PgpDecryptionService pgpDecryptionService = account.getPgpDecryptionService();
synchronized (this.messages) { synchronized (this.messages) {
for(Message message : this.messages) { for(Message message : this.messages) {
if (uuids.contains(message.getUuid())) { if (uuids.contains(message.getUuid())) {
message.setDeleted(true); message.setDeleted(true);
deleted = true; deleted = true;
if (message.getEncryption() == Message.ENCRYPTION_PGP && pgpDecryptionService != null) {
pgpDecryptionService.discard(message);
}
} }
} }
} }

View file

@ -166,7 +166,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static String CREATE_MESSAGE_TIME_INDEX = "create INDEX message_time_index ON " + Message.TABLENAME + "(" + Message.TIME_SENT + ")"; private static String CREATE_MESSAGE_TIME_INDEX = "create INDEX message_time_index ON " + Message.TABLENAME + "(" + Message.TIME_SENT + ")";
private static String CREATE_MESSAGE_CONVERSATION_INDEX = "create INDEX message_conversation_index ON " + Message.TABLENAME + "(" + Message.CONVERSATION + ")"; private static String CREATE_MESSAGE_CONVERSATION_INDEX = "create INDEX message_conversation_index ON " + Message.TABLENAME + "(" + Message.CONVERSATION + ")";
private static String CREATE_MESSAGE_DELETED_INDEX = "create index message_deleted_index ON "+ Message.TABLENAME + "(" + Message.DELETED + ")"; private static String CREATE_MESSAGE_DELETED_INDEX = "create index message_deleted_index ON " + Message.TABLENAME + "(" + Message.DELETED + ")";
private static String CREATE_MESSAGE_RELATIVE_FILE_PATH_INDEX = "create INDEX message_file_path_index ON " + Message.TABLENAME + "(" + Message.RELATIVE_FILE_PATH + ")"; private static String CREATE_MESSAGE_RELATIVE_FILE_PATH_INDEX = "create INDEX message_file_path_index ON " + Message.TABLENAME + "(" + Message.RELATIVE_FILE_PATH + ")";
private static String CREATE_MESSAGE_TYPE_INDEX = "create INDEX message_type_index ON " + Message.TABLENAME + "(" + Message.TYPE + ")"; private static String CREATE_MESSAGE_TYPE_INDEX = "create INDEX message_type_index ON " + Message.TABLENAME + "(" + Message.TYPE + ")";
@ -196,7 +196,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
@Override @Override
public void onConfigure(SQLiteDatabase db) { public void onConfigure(SQLiteDatabase db) {
db.execSQL("PRAGMA foreign_keys=ON"); db.execSQL("PRAGMA foreign_keys=ON");
db.rawQuery("PRAGMA secure_delete=ON",null); db.rawQuery("PRAGMA secure_delete=ON", null);
} }
@Override @Override
@ -682,8 +682,8 @@ public class DatabaseBackend extends SQLiteOpenHelper {
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
result = Resolver.Result.fromCursor(cursor); result = Resolver.Result.fromCursor(cursor);
} }
} catch (Exception e ) { } catch (Exception e) {
Log.d(Config.LOGTAG,"unable to find cached resolver result in database "+e.getMessage()); Log.d(Config.LOGTAG, "unable to find cached resolver result in database " + e.getMessage());
return null; return null;
} finally { } finally {
cursor.close(); cursor.close();
@ -766,7 +766,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public Cursor getMessageSearchCursor(List<String> term) { public Cursor getMessageSearchCursor(List<String> term) {
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
String SQL = "SELECT " + Message.TABLENAME + ".*," + Conversation.TABLENAME + '.' + Conversation.CONTACTJID + ',' + Conversation.TABLENAME + '.' + Conversation.ACCOUNT + ',' + Conversation.TABLENAME + '.' + Conversation.MODE + " FROM " + Message.TABLENAME + " join " + Conversation.TABLENAME + " on " + Message.TABLENAME + '.' + Message.CONVERSATION + '=' + Conversation.TABLENAME + '.' + Conversation.UUID + " join messages_index ON messages_index.uuid=messages.uuid where " + Message.ENCRYPTION + " NOT IN(" + Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE + ',' + Message.ENCRYPTION_PGP + ',' + Message.ENCRYPTION_DECRYPTION_FAILED + ','+Message.ENCRYPTION_AXOLOTL_FAILED+") AND " + Message.TYPE + " IN(" + Message.TYPE_TEXT + ',' + Message.TYPE_PRIVATE + ") AND messages_index.body MATCH ? ORDER BY " + Message.TIME_SENT + " DESC limit " + Config.MAX_SEARCH_RESULTS; String SQL = "SELECT " + Message.TABLENAME + ".*," + Conversation.TABLENAME + '.' + Conversation.CONTACTJID + ',' + Conversation.TABLENAME + '.' + Conversation.ACCOUNT + ',' + Conversation.TABLENAME + '.' + Conversation.MODE + " FROM " + Message.TABLENAME + " join " + Conversation.TABLENAME + " on " + Message.TABLENAME + '.' + Message.CONVERSATION + '=' + Conversation.TABLENAME + '.' + Conversation.UUID + " join messages_index ON messages_index.uuid=messages.uuid where " + Message.ENCRYPTION + " NOT IN(" + Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE + ',' + Message.ENCRYPTION_PGP + ',' + Message.ENCRYPTION_DECRYPTION_FAILED + ',' + Message.ENCRYPTION_AXOLOTL_FAILED + ") AND " + Message.TYPE + " IN(" + Message.TYPE_TEXT + ',' + Message.TYPE_PRIVATE + ") AND messages_index.body MATCH ? ORDER BY " + Message.TIME_SENT + " DESC limit " + Config.MAX_SEARCH_RESULTS;
Log.d(Config.LOGTAG, "search term: " + FtsUtils.toMatchString(term)); Log.d(Config.LOGTAG, "search term: " + FtsUtils.toMatchString(term));
return db.rawQuery(SQL, new String[]{FtsUtils.toMatchString(term)}); return db.rawQuery(SQL, new String[]{FtsUtils.toMatchString(term)});
} }
@ -810,15 +810,21 @@ public class DatabaseBackend extends SQLiteOpenHelper {
String selection; String selection;
String[] selectionArgs; String[] selectionArgs;
if (internal) { if (internal) {
selection = Message.RELATIVE_FILE_PATH+" IN(?,?) and type in (1,2)"; final String name = file.getName();
selectionArgs = new String[]{file.getAbsolutePath(),file.getName()}; if (name.endsWith(".pgp")) {
selection = "(" + Message.RELATIVE_FILE_PATH + " IN(?,?) OR (" + Message.RELATIVE_FILE_PATH + "=? and encryption in(1,4))) and type in (1,2)";
selectionArgs = new String[]{file.getAbsolutePath(), name, name.substring(0, name.length() - 4)};
} else { } else {
selection = Message.RELATIVE_FILE_PATH+"=? and type in (1,2)"; selection = Message.RELATIVE_FILE_PATH + " IN(?,?) and type in (1,2)";
selectionArgs = new String[]{file.getAbsolutePath(), name};
}
} else {
selection = Message.RELATIVE_FILE_PATH + "=? and type in (1,2)";
selectionArgs = new String[]{file.getAbsolutePath()}; selectionArgs = new String[]{file.getAbsolutePath()};
} }
final List<String> uuids = new ArrayList<>(); final List<String> uuids = new ArrayList<>();
Cursor cursor = db.query(Message.TABLENAME,new String[]{Message.UUID},selection,selectionArgs,null,null,null); Cursor cursor = db.query(Message.TABLENAME, new String[]{Message.UUID}, selection, selectionArgs, null, null, null);
while(cursor != null && cursor.moveToNext()) { while (cursor != null && cursor.moveToNext()) {
uuids.add(cursor.getString(0)); uuids.add(cursor.getString(0));
} }
if (cursor != null) { if (cursor != null) {
@ -831,10 +837,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public void markFileAsDeleted(List<String> uuids) { public void markFileAsDeleted(List<String> uuids) {
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
final ContentValues contentValues = new ContentValues(); final ContentValues contentValues = new ContentValues();
final String where = Message.UUID+"=?"; final String where = Message.UUID + "=?";
contentValues.put(Message.DELETED,1); contentValues.put(Message.DELETED, 1);
db.beginTransaction(); db.beginTransaction();
for(String uuid : uuids) { for (String uuid : uuids) {
db.update(Message.TABLENAME, contentValues, where, new String[]{uuid}); db.update(Message.TABLENAME, contentValues, where, new String[]{uuid});
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
@ -843,10 +849,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public List<FilePath> getAllNonDeletedFilePath() { public List<FilePath> getAllNonDeletedFilePath() {
final SQLiteDatabase db = this.getReadableDatabase(); final SQLiteDatabase db = this.getReadableDatabase();
final Cursor cursor = db.query(Message.TABLENAME,new String[]{Message.UUID,Message.RELATIVE_FILE_PATH},"type in (1,2) and deleted=0",null,null,null,null); final Cursor cursor = db.query(Message.TABLENAME, new String[]{Message.UUID, Message.RELATIVE_FILE_PATH}, "type in (1,2) and deleted=0", null, null, null, null);
final List<FilePath> list = new ArrayList<>(); final List<FilePath> list = new ArrayList<>();
while (cursor != null && cursor.moveToNext()) { while (cursor != null && cursor.moveToNext()) {
list.add(new FilePath(cursor.getString(0),cursor.getString(1))); list.add(new FilePath(cursor.getString(0), cursor.getString(1)));
} }
if (cursor != null) { if (cursor != null) {
cursor.close(); cursor.close();
@ -857,11 +863,11 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public List<FilePath> getRelativeFilePaths(String account, Jid jid, int limit) { public List<FilePath> getRelativeFilePaths(String account, Jid jid, int limit) {
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
final String SQL = "select uuid,relativeFilePath from messages where type in (1,2) and deleted=0 and conversationUuid=(select uuid from conversations where accountUuid=? and (contactJid=? or contactJid like ?)) order by timeSent desc"; final String SQL = "select uuid,relativeFilePath from messages where type in (1,2) and deleted=0 and conversationUuid=(select uuid from conversations where accountUuid=? and (contactJid=? or contactJid like ?)) order by timeSent desc";
final String[] args = {account, jid.toEscapedString(), jid.toEscapedString()+"/%"}; final String[] args = {account, jid.toEscapedString(), jid.toEscapedString() + "/%"};
Cursor cursor = db.rawQuery(SQL+(limit > 0 ? " limit "+String.valueOf(limit) : ""), args); Cursor cursor = db.rawQuery(SQL + (limit > 0 ? " limit " + String.valueOf(limit) : ""), args);
List<FilePath> filesPaths = new ArrayList<>(); List<FilePath> filesPaths = new ArrayList<>();
while(cursor.moveToNext()) { while (cursor.moveToNext()) {
filesPaths.add(new FilePath(cursor.getString(0),cursor.getString(1))); filesPaths.add(new FilePath(cursor.getString(0), cursor.getString(1)));
} }
cursor.close(); cursor.close();
return filesPaths; return filesPaths;
@ -870,6 +876,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public static class FilePath { public static class FilePath {
public final UUID uuid; public final UUID uuid;
public final String path; public final String path;
private FilePath(String uuid, String path) { private FilePath(String uuid, String path) {
this.uuid = UUID.fromString(uuid); this.uuid = UUID.fromString(uuid);
this.path = path; this.path = path;

View file

@ -1089,7 +1089,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
copyLink.setVisible(true); copyLink.setVisible(true);
} }
} }
if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) { if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED && !deleted) {
retryDecryption.setVisible(true); retryDecryption.setVisible(true);
} }
if (!showError if (!showError