From e899668213ee8f7d3566bb5754b488d8633c30c7 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Tue, 10 Sep 2019 20:56:00 +0200 Subject: Add JET support --- .../omemo/src/file_transfer/file_decryptor.vala | 24 +++++++++---------- .../omemo/src/file_transfer/file_encryptor.vala | 28 +++++++++++----------- 2 files changed, 25 insertions(+), 27 deletions(-) (limited to 'plugins/omemo/src') 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 data = new Array(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 data = new Array(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; } -- cgit v1.2.3-70-g09d2