aboutsummaryrefslogtreecommitdiff
path: root/plugins/openpgp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/openpgp')
-rw-r--r--plugins/openpgp/CMakeLists.txt5
-rw-r--r--plugins/openpgp/src/file_transfer/file_decryptor.vala (renamed from plugins/openpgp/src/in_file_processor.vala)21
-rw-r--r--plugins/openpgp/src/file_transfer/file_encryptor.vala41
-rw-r--r--plugins/openpgp/src/out_file_processor.vala32
-rw-r--r--plugins/openpgp/src/plugin.vala4
5 files changed, 61 insertions, 42 deletions
diff --git a/plugins/openpgp/CMakeLists.txt b/plugins/openpgp/CMakeLists.txt
index ab406123..eb50dc71 100644
--- a/plugins/openpgp/CMakeLists.txt
+++ b/plugins/openpgp/CMakeLists.txt
@@ -28,14 +28,15 @@ compile_gresources(
vala_precompile(OPENPGP_VALA_C
SOURCES
+ src/file_transfer/file_decryptor.vala
+ src/file_transfer/file_encryptor.vala
+
src/account_settings_entry.vala
src/account_settings_widget.vala
src/contact_details_provider.vala
src/database.vala
src/encryption_list_entry.vala
- src/in_file_processor.vala
src/manager.vala
- src/out_file_processor.vala
src/plugin.vala
src/register_plugin.vala
src/stream_flag.vala
diff --git a/plugins/openpgp/src/in_file_processor.vala b/plugins/openpgp/src/file_transfer/file_decryptor.vala
index 918f824a..7668023e 100644
--- a/plugins/openpgp/src/in_file_processor.vala
+++ b/plugins/openpgp/src/file_transfer/file_decryptor.vala
@@ -2,31 +2,40 @@ using Dino.Entities;
namespace Dino.Plugins.OpenPgp {
-public class InFileProcessor : IncomingFileProcessor, Object {
- public bool can_process(FileTransfer file_transfer) {
+public class PgpFileDecryptor : FileDecryptor, Object {
+
+ public FileReceiveData prepare_get_meta_info(Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data) {
+ return receive_data;
+ }
+
+ public FileMeta prepare_download_file(Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data, FileMeta file_meta) {
+ return file_meta;
+ }
+
+ public bool can_decrypt_file(Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data) {
return file_transfer.file_name.has_suffix("pgp") || file_transfer.mime_type == "application/pgp-encrypted";
}
- public void process(FileTransfer file_transfer) {
+ public async InputStream decrypt_file(InputStream encrypted_stream, Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data) throws FileReceiveError {
try {
uint8[] buf = new uint8[256];
Array<uint8> data = new Array<uint8>(false, true, 0);
size_t len = -1;
do {
- len = file_transfer.input_stream.read(buf);
+ len = encrypted_stream.read(buf);
data.append_vals(buf, (uint) len);
} while(len > 0);
GPGHelper.DecryptedData clear_data = GPGHelper.decrypt_data(data.data);
- file_transfer.input_stream = new MemoryInputStream.from_data(clear_data.data, GLib.free);
file_transfer.encryption = Encryption.PGP;
if (clear_data.filename != null && clear_data.filename != "") {
file_transfer.file_name = clear_data.filename;
} else if (file_transfer.file_name.has_suffix(".pgp")) {
file_transfer.file_name = file_transfer.file_name.substring(0, file_transfer.file_name.length - 4);
}
+ return new MemoryInputStream.from_data(clear_data.data, GLib.free);
} catch (Error e) {
- file_transfer.state = FileTransfer.State.FAILED;
+ throw new FileReceiveError.DECRYPTION_FAILED("PGP file decrypt error: %s".printf(e.message));
}
}
}
diff --git a/plugins/openpgp/src/file_transfer/file_encryptor.vala b/plugins/openpgp/src/file_transfer/file_encryptor.vala
new file mode 100644
index 00000000..7d51be60
--- /dev/null
+++ b/plugins/openpgp/src/file_transfer/file_encryptor.vala
@@ -0,0 +1,41 @@
+using Dino.Entities;
+
+namespace Dino.Plugins.OpenPgp {
+
+public class PgpFileEncryptor : Dino.FileEncryptor, Object {
+
+ StreamInteractor stream_interactor;
+
+ public PgpFileEncryptor(StreamInteractor stream_interactor) {
+ this.stream_interactor = stream_interactor;
+ }
+
+ public bool can_encrypt_file(Conversation conversation, FileTransfer file_transfer) {
+ return conversation.encryption == Encryption.PGP;
+ }
+
+ public FileMeta encrypt_file(Conversation conversation, FileTransfer file_transfer) throws FileSendError {
+ try {
+ GPG.Key[] keys = stream_interactor.get_module(Manager.IDENTITY).get_key_fprs(conversation);
+ uint8[] enc_content = GPGHelper.encrypt_file(file_transfer.get_file().get_path(), keys, GPG.EncryptFlags.ALWAYS_TRUST, file_transfer.file_name);
+ file_transfer.input_stream = new MemoryInputStream.from_data(enc_content, GLib.free);
+ file_transfer.encryption = Encryption.PGP;
+ file_transfer.server_file_name = Xmpp.random_uuid() + ".pgp";
+ } catch (Error e) {
+ throw new FileSendError.ENCRYPTION_FAILED("PGP file encryption error: %s".printf(e.message));
+ }
+
+ return new FileMeta();
+ }
+
+ public FileSendData? preprocess_send_file(Conversation conversation, FileTransfer file_transfer, FileSendData file_send_data, FileMeta file_meta) {
+ HttpFileSendData? send_data = file_send_data as HttpFileSendData;
+ if (send_data == null) return null;
+
+ send_data.encrypt_message = false;
+
+ return file_send_data;
+ }
+}
+
+}
diff --git a/plugins/openpgp/src/out_file_processor.vala b/plugins/openpgp/src/out_file_processor.vala
deleted file mode 100644
index 40eef7f5..00000000
--- a/plugins/openpgp/src/out_file_processor.vala
+++ /dev/null
@@ -1,32 +0,0 @@
-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) {
- string path = file_transfer.get_file().get_path();
- try {
- GPG.Key[] keys = stream_interactor.get_module(Manager.IDENTITY).get_key_fprs(conversation);
- uint8[] enc_content = GPGHelper.encrypt_file(path, keys, GPG.EncryptFlags.ALWAYS_TRUST, file_transfer.file_name);
- file_transfer.input_stream = new MemoryInputStream.from_data(enc_content, GLib.free);
- file_transfer.encryption = Encryption.PGP;
- file_transfer.server_file_name = Xmpp.random_uuid() + ".pgp";
- } catch (Error e) {
- warning(@"PGP file encryption error: $(e.message)\n");
- file_transfer.state = FileTransfer.State.FAILED;
- }
- }
-}
-
-}
diff --git a/plugins/openpgp/src/plugin.vala b/plugins/openpgp/src/plugin.vala
index 1d4f5203..35ede01e 100644
--- a/plugins/openpgp/src/plugin.vala
+++ b/plugins/openpgp/src/plugin.vala
@@ -29,8 +29,8 @@ public class Plugin : Plugins.RootInterface, Object {
app.stream_interactor.module_manager.initialize_account_modules.connect(on_initialize_account_modules);
Manager.start(app.stream_interactor, db);
- app.stream_interactor.get_module(FileManager.IDENTITY).add_outgoing_processor(new OutFileProcessor(app.stream_interactor));
- app.stream_interactor.get_module(FileManager.IDENTITY).add_incoming_processor(new InFileProcessor());
+ app.stream_interactor.get_module(FileManager.IDENTITY).add_file_encryptor(new PgpFileEncryptor(app.stream_interactor));
+ app.stream_interactor.get_module(FileManager.IDENTITY).add_file_decryptor(new PgpFileDecryptor());
internationalize(GETTEXT_PACKAGE, app.search_path_generator.get_locale_path(GETTEXT_PACKAGE, LOCALE_INSTALL_DIR));
}