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;
mXmppConnectionService.getFileBackend().updateFileParams(message, url);
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
mXmppConnectionService.updateMessage(message);
if (!inputFile.delete()) {
Log.w(Config.LOGTAG,"unable to delete pgp encrypted source file "+inputFile.getAbsolutePath());
}
mXmppConnectionService.updateMessage(message);
skipNotificationPush = true;
mXmppConnectionService.getFileBackend().updateMediaScanner(outputFile, () -> notifyIfPending(message));
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) {
synchronized (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) {
boolean deleted = false;
final PgpDecryptionService pgpDecryptionService = account.getPgpDecryptionService();
synchronized (this.messages) {
for(Message message : this.messages) {
if (uuids.contains(message.getUuid())) {
message.setDeleted(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_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_TYPE_INDEX = "create INDEX message_type_index ON " + Message.TABLENAME + "(" + Message.TYPE + ")";
@ -196,7 +196,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
@Override
public void onConfigure(SQLiteDatabase db) {
db.execSQL("PRAGMA foreign_keys=ON");
db.rawQuery("PRAGMA secure_delete=ON",null);
db.rawQuery("PRAGMA secure_delete=ON", null);
}
@Override
@ -682,8 +682,8 @@ public class DatabaseBackend extends SQLiteOpenHelper {
if (cursor.moveToFirst()) {
result = Resolver.Result.fromCursor(cursor);
}
} catch (Exception e ) {
Log.d(Config.LOGTAG,"unable to find cached resolver result in database "+e.getMessage());
} catch (Exception e) {
Log.d(Config.LOGTAG, "unable to find cached resolver result in database " + e.getMessage());
return null;
} finally {
cursor.close();
@ -766,7 +766,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public Cursor getMessageSearchCursor(List<String> term) {
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));
return db.rawQuery(SQL, new String[]{FtsUtils.toMatchString(term)});
}
@ -810,15 +810,21 @@ public class DatabaseBackend extends SQLiteOpenHelper {
String selection;
String[] selectionArgs;
if (internal) {
selection = Message.RELATIVE_FILE_PATH+" IN(?,?) and type in (1,2)";
selectionArgs = new String[]{file.getAbsolutePath(),file.getName()};
final String name = 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 {
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()};
}
final List<String> uuids = new ArrayList<>();
Cursor cursor = db.query(Message.TABLENAME,new String[]{Message.UUID},selection,selectionArgs,null,null,null);
while(cursor != null && cursor.moveToNext()) {
Cursor cursor = db.query(Message.TABLENAME, new String[]{Message.UUID}, selection, selectionArgs, null, null, null);
while (cursor != null && cursor.moveToNext()) {
uuids.add(cursor.getString(0));
}
if (cursor != null) {
@ -831,10 +837,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public void markFileAsDeleted(List<String> uuids) {
SQLiteDatabase db = this.getReadableDatabase();
final ContentValues contentValues = new ContentValues();
final String where = Message.UUID+"=?";
contentValues.put(Message.DELETED,1);
final String where = Message.UUID + "=?";
contentValues.put(Message.DELETED, 1);
db.beginTransaction();
for(String uuid : uuids) {
for (String uuid : uuids) {
db.update(Message.TABLENAME, contentValues, where, new String[]{uuid});
}
db.setTransactionSuccessful();
@ -843,10 +849,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public List<FilePath> getAllNonDeletedFilePath() {
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<>();
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) {
cursor.close();
@ -857,11 +863,11 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public List<FilePath> getRelativeFilePaths(String account, Jid jid, int limit) {
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[] args = {account, jid.toEscapedString(), jid.toEscapedString()+"/%"};
Cursor cursor = db.rawQuery(SQL+(limit > 0 ? " limit "+String.valueOf(limit) : ""), args);
final String[] args = {account, jid.toEscapedString(), jid.toEscapedString() + "/%"};
Cursor cursor = db.rawQuery(SQL + (limit > 0 ? " limit " + String.valueOf(limit) : ""), args);
List<FilePath> filesPaths = new ArrayList<>();
while(cursor.moveToNext()) {
filesPaths.add(new FilePath(cursor.getString(0),cursor.getString(1)));
while (cursor.moveToNext()) {
filesPaths.add(new FilePath(cursor.getString(0), cursor.getString(1)));
}
cursor.close();
return filesPaths;
@ -870,6 +876,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public static class FilePath {
public final UUID uuid;
public final String path;
private FilePath(String uuid, String path) {
this.uuid = UUID.fromString(uuid);
this.path = path;

View file

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