diff options
author | fiaxh <git@lightrise.org> | 2020-09-02 16:47:41 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2020-09-07 15:14:29 +0200 |
commit | 49bcbdaa517e5d6f8d4860db70ae0a9960e2c519 (patch) | |
tree | 7275f69dc7ef36022eace7cfbc0bb7f66be60824 /libdino/src | |
parent | e327a88898a90543f1de851274274139642c9a21 (diff) | |
download | dino-49bcbdaa517e5d6f8d4860db70ae0a9960e2c519.tar.gz dino-49bcbdaa517e5d6f8d4860db70ae0a9960e2c519.zip |
Fix initial file encryption displaying
fixes #831
Diffstat (limited to 'libdino/src')
-rw-r--r-- | libdino/src/service/file_manager.vala | 11 | ||||
-rw-r--r-- | libdino/src/service/jingle_file_transfers.vala | 19 |
2 files changed, 21 insertions, 9 deletions
diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala index fe9cba73..192dc8a8 100644 --- a/libdino/src/service/file_manager.vala +++ b/libdino/src/service/file_manager.vala @@ -313,6 +313,15 @@ public class FileManager : StreamInteractionModule, Object { file_transfer.size = (int)file_meta.size; file_transfer.info = info; + var encryption = file_provider.get_encryption(file_transfer, receive_data, file_meta); + if (encryption != Encryption.NONE) file_transfer.encryption = encryption; + + foreach (FileDecryptor decryptor in file_decryptors) { + if (decryptor.can_decrypt_file(conversation, file_transfer, receive_data)) { + file_transfer.encryption = decryptor.get_encryption(); + } + } + file_transfer.persist(db); if (is_sender_trustworthy(file_transfer, conversation)) { @@ -389,6 +398,7 @@ public class HttpFileReceiveData : FileReceiveData { public interface FileProvider : Object { public signal void file_incoming(string info, Jid from, DateTime time, DateTime local_time, Conversation conversation, FileReceiveData receive_data, FileMeta file_meta); + public abstract Encryption get_encryption(FileTransfer file_transfer, FileReceiveData receive_data, FileMeta file_meta); public abstract FileMeta get_file_meta(FileTransfer file_transfer) throws FileReceiveError; public abstract FileReceiveData? get_file_receive_data(FileTransfer file_transfer); @@ -419,6 +429,7 @@ public interface FileEncryptor : Object { } public interface FileDecryptor : Object { + public abstract Encryption get_encryption(); public abstract FileReceiveData prepare_get_meta_info(Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data); public abstract FileMeta prepare_download_file(Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data, FileMeta file_meta); public abstract bool can_decrypt_file(Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data); diff --git a/libdino/src/service/jingle_file_transfers.vala b/libdino/src/service/jingle_file_transfers.vala index 6482e2e7..016939bf 100644 --- a/libdino/src/service/jingle_file_transfers.vala +++ b/libdino/src/service/jingle_file_transfers.vala @@ -11,7 +11,7 @@ public interface JingleFileEncryptionHelper : Object { public abstract async bool can_encrypt(Conversation conversation, FileTransfer file_transfer, Jid? full_jid = null); public abstract string? get_precondition_name(Conversation conversation, FileTransfer file_transfer); public abstract Object? get_precondition_options(Conversation conversation, FileTransfer file_transfer); - public abstract FileMeta complete_meta(FileTransfer file_transfer, FileReceiveData receive_data, FileMeta file_meta, Xmpp.Xep.JingleFileTransfer.FileTransfer jingle_transfer); + public abstract Encryption get_encryption(Xmpp.Xep.JingleFileTransfer.FileTransfer jingle_transfer); } public class JingleFileEncryptionHelperTransferOnly : JingleFileEncryptionHelper, Object { @@ -27,8 +27,8 @@ public class JingleFileEncryptionHelperTransferOnly : JingleFileEncryptionHelper public Object? get_precondition_options(Conversation conversation, FileTransfer file_transfer) { return null; } - public FileMeta complete_meta(FileTransfer file_transfer, FileReceiveData receive_data, FileMeta file_meta, Xmpp.Xep.JingleFileTransfer.FileTransfer jingle_transfer) { - return file_meta; + public Encryption get_encryption(Xmpp.Xep.JingleFileTransfer.FileTransfer jingle_transfer) { + return Encryption.NONE; } } @@ -79,15 +79,19 @@ public class JingleFileProvider : FileProvider, Object { } public async FileMeta get_meta_info(FileTransfer file_transfer, FileReceiveData receive_data, FileMeta file_meta) throws FileReceiveError { + return file_meta; + } + + public Encryption get_encryption(FileTransfer file_transfer, FileReceiveData receive_data, FileMeta file_meta) { Xmpp.Xep.JingleFileTransfer.FileTransfer? jingle_file_transfer = file_transfers[file_transfer.info]; if (jingle_file_transfer == null) { throw new FileReceiveError.DOWNLOAD_FAILED("Transfer data not available anymore"); } - FileMeta meta = file_meta; foreach (JingleFileEncryptionHelper helper in JingleFileHelperRegistry.instance.encryption_helpers.values) { - meta = helper.complete_meta(file_transfer, receive_data, meta, jingle_file_transfer); + var encryption = helper.get_encryption(jingle_file_transfer); + if (encryption != Encryption.NONE) return encryption; } - return meta; + return Encryption.NONE; } public async InputStream download(FileTransfer file_transfer, FileReceiveData receive_data, FileMeta file_meta) throws FileReceiveError { @@ -97,9 +101,6 @@ public class JingleFileProvider : FileProvider, Object { if (jingle_file_transfer == null) { throw new FileReceiveError.DOWNLOAD_FAILED("Transfer data not available anymore"); } - foreach (JingleFileEncryptionHelper helper in JingleFileHelperRegistry.instance.encryption_helpers.values) { - helper.complete_meta(file_transfer, receive_data, file_meta, jingle_file_transfer); - } try { jingle_file_transfer.accept(stream); } catch (IOError e) { |