2017-10-15 22:23:51 +00:00
|
|
|
using Dino.Entities;
|
|
|
|
|
|
|
|
namespace Dino.Plugins.OpenPgp {
|
|
|
|
|
|
|
|
public class OutFileProcessor : OutgoingFileProcessor, Object {
|
|
|
|
|
|
|
|
StreamInteractor stream_interactor;
|
|
|
|
|
|
|
|
public OutFileProcessor(StreamInteractor stream_interactor) {
|
|
|
|
this.stream_interactor = stream_interactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool can_process(Conversation conversation, FileTransfer file_transfer) {
|
|
|
|
return conversation.encryption == Encryption.PGP;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void process(Conversation conversation, FileTransfer file_transfer) {
|
2018-01-28 19:56:27 +00:00
|
|
|
string path = file_transfer.get_file().get_path();
|
2017-10-29 14:15:28 +00:00
|
|
|
try {
|
|
|
|
GPG.Key[] keys = stream_interactor.get_module(Manager.IDENTITY).get_key_fprs(conversation);
|
2018-01-28 19:56:27 +00:00
|
|
|
uint8[] enc_content = GPGHelper.encrypt_file(path, keys, GPG.EncryptFlags.ALWAYS_TRUST, file_transfer.file_name);
|
2017-10-29 14:15:28 +00:00
|
|
|
file_transfer.input_stream = new MemoryInputStream.from_data(enc_content, GLib.free);
|
|
|
|
file_transfer.encryption = Encryption.PGP;
|
2017-10-30 00:43:26 +00:00
|
|
|
file_transfer.server_file_name = Xmpp.random_uuid() + ".pgp";
|
2017-10-29 14:15:28 +00:00
|
|
|
} catch (Error e) {
|
2018-11-14 17:17:10 +00:00
|
|
|
warning(@"PGP file encryption error: $(e.message)\n");
|
2017-10-29 14:15:28 +00:00
|
|
|
file_transfer.state = FileTransfer.State.FAILED;
|
|
|
|
}
|
2017-10-15 22:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|