aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo/src/file_transfer
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/omemo/src/file_transfer')
-rw-r--r--plugins/omemo/src/file_transfer/file_decryptor.vala24
-rw-r--r--plugins/omemo/src/file_transfer/file_encryptor.vala28
2 files changed, 25 insertions, 27 deletions
diff --git a/plugins/omemo/src/file_transfer/file_decryptor.vala b/plugins/omemo/src/file_transfer/file_decryptor.vala
index bc6f8592..d60ecdc8 100644
--- a/plugins/omemo/src/file_transfer/file_decryptor.vala
+++ b/plugins/omemo/src/file_transfer/file_decryptor.vala
@@ -1,5 +1,6 @@
using Dino.Entities;
+using Crypto;
using Signal;
namespace Dino.Plugins.Omemo {
@@ -56,20 +57,17 @@ public class OmemoFileDecryptor : FileDecryptor, Object {
key = iv_and_key[16:48];
}
- // Read data
- uint8[] buf = new uint8[256];
- Array<uint8> data = new Array<uint8>(false, true, 0);
- size_t len = -1;
- do {
- len = yield encrypted_stream.read_async(buf);
- data.append_vals(buf, (uint) len);
- } while(len > 0);
-
- // Decrypt
- uint8[] cleartext = Signal.aes_decrypt(Cipher.AES_GCM_NOPADDING, key, iv, data.data);
file_transfer.encryption = Encryption.OMEMO;
- return new MemoryInputStream.from_data(cleartext);
- } catch (Error e) {
+ debug("Decrypting file %s from %s", file_transfer.file_name, file_transfer.server_file_name);
+
+ SymmetricCipher cipher = new SymmetricCipher("AES-GCM");
+ cipher.set_key(key);
+ cipher.set_iv(iv);
+ return new ConverterInputStream(encrypted_stream, new SymmetricCipherDecrypter((owned) cipher));
+
+ } catch (Crypto.Error e) {
+ throw new FileReceiveError.DECRYPTION_FAILED("OMEMO file decryption error: %s".printf(e.message));
+ } catch (GLib.Error e) {
throw new FileReceiveError.DECRYPTION_FAILED("OMEMO file decryption error: %s".printf(e.message));
}
}
diff --git a/plugins/omemo/src/file_transfer/file_encryptor.vala b/plugins/omemo/src/file_transfer/file_encryptor.vala
index a5445153..5b4e4d96 100644
--- a/plugins/omemo/src/file_transfer/file_encryptor.vala
+++ b/plugins/omemo/src/file_transfer/file_encryptor.vala
@@ -1,6 +1,7 @@
using Gee;
using Gtk;
+using Crypto;
using Dino.Entities;
using Xmpp;
using Signal;
@@ -22,30 +23,29 @@ public class OmemoFileEncryptor : Dino.FileEncryptor, Object {
var omemo_http_file_meta = new OmemoHttpFileMeta();
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);
- data.append_vals(buf, (uint) len);
- } while(len > 0);
-
//Create a key and use it to encrypt the file
uint8[] iv = new uint8[16];
Plugin.get_context().randomize(iv);
uint8[] key = new uint8[32];
Plugin.get_context().randomize(key);
- uint8[] ciphertext = aes_encrypt(Cipher.AES_GCM_NOPADDING, key, iv, data.data);
+
+ SymmetricCipher cipher = new SymmetricCipher("AES-GCM");
+ cipher.set_key(key);
+ cipher.set_iv(iv);
omemo_http_file_meta.iv = iv;
omemo_http_file_meta.key = key;
- omemo_http_file_meta.size = ciphertext.length;
- omemo_http_file_meta.mime_type = "pgp";
- file_transfer.input_stream = new MemoryInputStream.from_data(ciphertext, GLib.free);
- } catch (Error error) {
- throw new FileSendError.ENCRYPTION_FAILED("HTTP upload: Error encrypting stream: %s".printf(error.message));
+ omemo_http_file_meta.size = file_transfer.size;
+ omemo_http_file_meta.mime_type = "omemo";
+ file_transfer.input_stream = new ConverterInputStream(file_transfer.input_stream, new SymmetricCipherEncrypter((owned) cipher));
+ } catch (Crypto.Error error) {
+ throw new FileSendError.ENCRYPTION_FAILED("OMEMO file encryption error: %s".printf(error.message));
+ } catch (GLib.Error error) {
+ throw new FileSendError.ENCRYPTION_FAILED("OMEMO file encryption error: %s".printf(error.message));
}
+ debug("Encrypting file %s as %s", file_transfer.file_name, file_transfer.server_file_name);
+
return omemo_http_file_meta;
}