parent
e327a88898
commit
49bcbdaa51
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -92,6 +92,10 @@ public class FileProvider : Dino.FileProvider, Object {
|
|||
return file_meta;
|
||||
}
|
||||
|
||||
public Encryption get_encryption(FileTransfer file_transfer, FileReceiveData receive_data, FileMeta file_meta) {
|
||||
return Encryption.NONE;
|
||||
}
|
||||
|
||||
public async InputStream download(FileTransfer file_transfer, FileReceiveData receive_data, FileMeta file_meta) throws FileReceiveError {
|
||||
HttpFileReceiveData? http_receive_data = receive_data as HttpFileReceiveData;
|
||||
if (http_receive_data == null) assert(false);
|
||||
|
|
|
@ -13,6 +13,10 @@ public class OmemoFileDecryptor : FileDecryptor, Object {
|
|||
|
||||
private Regex url_regex = /^aesgcm:\/\/(.*)#(([A-Fa-f0-9]{2}){48}|([A-Fa-f0-9]{2}){44})$/;
|
||||
|
||||
public Encryption get_encryption() {
|
||||
return Encryption.OMEMO;
|
||||
}
|
||||
|
||||
public FileReceiveData prepare_get_meta_info(Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data) {
|
||||
HttpFileReceiveData? http_receive_data = receive_data as HttpFileReceiveData;
|
||||
if (http_receive_data == null) assert(false);
|
||||
|
|
|
@ -42,12 +42,12 @@ public class EncryptionHelper : JingleFileEncryptionHelper, Object {
|
|||
return new Xep.Jet.Options(Omemo.NS_URI, AES_128_GCM_URI);
|
||||
}
|
||||
|
||||
public FileMeta complete_meta(FileTransfer file_transfer, FileReceiveData receive_data, FileMeta file_meta, Xmpp.Xep.JingleFileTransfer.FileTransfer jingle_transfer) {
|
||||
public Encryption get_encryption(Xmpp.Xep.JingleFileTransfer.FileTransfer jingle_transfer) {
|
||||
Xep.Jet.SecurityParameters? security = jingle_transfer.security as Xep.Jet.SecurityParameters;
|
||||
if (security != null && security.encoding.get_type_uri() == Omemo.NS_URI) {
|
||||
file_transfer.encryption = Encryption.OMEMO;
|
||||
return Encryption.OMEMO;
|
||||
}
|
||||
return file_meta;
|
||||
return Encryption.NONE;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,6 +4,10 @@ namespace Dino.Plugins.OpenPgp {
|
|||
|
||||
public class PgpFileDecryptor : FileDecryptor, Object {
|
||||
|
||||
public Encryption get_encryption() {
|
||||
return Encryption.PGP;
|
||||
}
|
||||
|
||||
public FileReceiveData prepare_get_meta_info(Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data) {
|
||||
return receive_data;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue