diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/omemo/src/file_transfer/file_decryptor.vala | 62 | ||||
-rw-r--r-- | plugins/omemo/src/logic/manager.vala | 12 | ||||
-rw-r--r-- | plugins/omemo/src/ui/util.vala | 6 | ||||
-rw-r--r-- | plugins/openpgp/src/file_transfer/file_decryptor.vala | 2 | ||||
-rw-r--r-- | plugins/openpgp/src/util.vala | 3 | ||||
-rw-r--r-- | plugins/signal-protocol/src/simple_iks.vala | 6 | ||||
-rw-r--r-- | plugins/signal-protocol/src/store.vala | 8 | ||||
-rw-r--r-- | plugins/signal-protocol/tests/common.vala | 4 | ||||
-rw-r--r-- | plugins/signal-protocol/vapi/signal-protocol-public.vapi | 16 |
9 files changed, 68 insertions, 51 deletions
diff --git a/plugins/omemo/src/file_transfer/file_decryptor.vala b/plugins/omemo/src/file_transfer/file_decryptor.vala index 6998fef2..bc6f8592 100644 --- a/plugins/omemo/src/file_transfer/file_decryptor.vala +++ b/plugins/omemo/src/file_transfer/file_decryptor.vala @@ -38,36 +38,40 @@ public class OmemoFileDecryptor : FileDecryptor, Object { return this.url_regex.match(http_file_receive.url) || (receive_data as OmemoHttpFileReceiveData) != null; } - public async InputStream decrypt_file(InputStream encrypted_stream, Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data) { - OmemoHttpFileReceiveData? omemo_http_receive_data = receive_data as OmemoHttpFileReceiveData; - if (omemo_http_receive_data == null) assert(false); - - // Decode IV and key - MatchInfo match_info; - this.url_regex.match(omemo_http_receive_data.original_url, 0, out match_info); - uint8[] iv_and_key = hex_to_bin(match_info.fetch(2).up()); - uint8[] iv, key; - if (iv_and_key.length == 44) { - iv = iv_and_key[0:12]; - key = iv_and_key[12:44]; - } else { - iv = iv_and_key[0:16]; - key = iv_and_key[16:48]; + public async InputStream decrypt_file(InputStream encrypted_stream, Conversation conversation, FileTransfer file_transfer, FileReceiveData receive_data) throws FileReceiveError { + try { + OmemoHttpFileReceiveData? omemo_http_receive_data = receive_data as OmemoHttpFileReceiveData; + if (omemo_http_receive_data == null) assert(false); + + // Decode IV and key + MatchInfo match_info; + this.url_regex.match(omemo_http_receive_data.original_url, 0, out match_info); + uint8[] iv_and_key = hex_to_bin(match_info.fetch(2).up()); + uint8[] iv, key; + if (iv_and_key.length == 44) { + iv = iv_and_key[0:12]; + key = iv_and_key[12:44]; + } else { + iv = iv_and_key[0:16]; + 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) { + throw new FileReceiveError.DECRYPTION_FAILED("OMEMO file decryption error: %s".printf(e.message)); } - - // 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); } private uint8[] hex_to_bin(string hex) { diff --git a/plugins/omemo/src/logic/manager.vala b/plugins/omemo/src/logic/manager.vala index a71dfd9d..53e02e37 100644 --- a/plugins/omemo/src/logic/manager.vala +++ b/plugins/omemo/src/logic/manager.vala @@ -326,22 +326,22 @@ public class Manager : StreamInteractionModule, Object { store.identity_key_store.local_registration_id = Random.int_range(1, int32.MAX); Signal.ECKeyPair key_pair = Plugin.get_context().generate_key_pair(); - store.identity_key_store.identity_key_private = key_pair.private.serialize(); - store.identity_key_store.identity_key_public = key_pair.public.serialize(); + store.identity_key_store.identity_key_private = new Bytes(key_pair.private.serialize()); + store.identity_key_store.identity_key_public = new Bytes(key_pair.public.serialize()); identity_id = (int) db.identity.insert().or("REPLACE") .value(db.identity.account_id, account.id) .value(db.identity.device_id, (int) store.local_registration_id) - .value(db.identity.identity_key_private_base64, Base64.encode(store.identity_key_store.identity_key_private)) - .value(db.identity.identity_key_public_base64, Base64.encode(store.identity_key_store.identity_key_public)) + .value(db.identity.identity_key_private_base64, Base64.encode(store.identity_key_store.identity_key_private.get_data())) + .value(db.identity.identity_key_public_base64, Base64.encode(store.identity_key_store.identity_key_public.get_data())) .perform(); } catch (Error e) { // Ignore error } } else { store.identity_key_store.local_registration_id = ((!)row)[db.identity.device_id]; - store.identity_key_store.identity_key_private = Base64.decode(((!)row)[db.identity.identity_key_private_base64]); - store.identity_key_store.identity_key_public = Base64.decode(((!)row)[db.identity.identity_key_public_base64]); + store.identity_key_store.identity_key_private = new Bytes(Base64.decode(((!)row)[db.identity.identity_key_private_base64])); + store.identity_key_store.identity_key_public = new Bytes(Base64.decode(((!)row)[db.identity.identity_key_public_base64])); identity_id = ((!)row)[db.identity.id]; } diff --git a/plugins/omemo/src/ui/util.vala b/plugins/omemo/src/ui/util.vala index 88d30b3b..cf61ed82 100644 --- a/plugins/omemo/src/ui/util.vala +++ b/plugins/omemo/src/ui/util.vala @@ -1,3 +1,5 @@ +using Xmpp.Util; + namespace Dino.Plugins.Omemo { public static string fingerprint_from_base64(string b64) { @@ -19,7 +21,7 @@ public static string fingerprint_markup(string s) { for (int i = 0; i < s.length; i += 4) { string four_chars = s.substring(i, 4).down(); - int raw = (int) four_chars.to_long(null, 16); + int raw = (int) from_hex(four_chars); uint8[] bytes = {(uint8) ((raw >> 8) & 0xff - 128), (uint8) (raw & 0xff - 128)}; Checksum checksum = new Checksum(ChecksumType.SHA1); @@ -57,4 +59,4 @@ public static string fingerprint_markup(string s) { return "<span font_family='monospace' font='8'>" + markup + "</span>"; } -}
\ No newline at end of file +} diff --git a/plugins/openpgp/src/file_transfer/file_decryptor.vala b/plugins/openpgp/src/file_transfer/file_decryptor.vala index 7668023e..97eb9f43 100644 --- a/plugins/openpgp/src/file_transfer/file_decryptor.vala +++ b/plugins/openpgp/src/file_transfer/file_decryptor.vala @@ -35,7 +35,7 @@ public class PgpFileDecryptor : FileDecryptor, Object { } return new MemoryInputStream.from_data(clear_data.data, GLib.free); } catch (Error e) { - throw new FileReceiveError.DECRYPTION_FAILED("PGP file decrypt error: %s".printf(e.message)); + throw new FileReceiveError.DECRYPTION_FAILED("PGP file decryption error: %s".printf(e.message)); } } } diff --git a/plugins/openpgp/src/util.vala b/plugins/openpgp/src/util.vala index 7c42b578..d40cf6ef 100644 --- a/plugins/openpgp/src/util.vala +++ b/plugins/openpgp/src/util.vala @@ -1,6 +1,7 @@ using Gtk; using Dino.Entities; +using Xmpp.Util; namespace Dino.Plugins.OpenPgp { @@ -10,7 +11,7 @@ public static string markup_colorize_id(string s, bool is_fingerprint) { for (int i = 0; i < s.length; i += 4) { string four_chars = s.substring(i, 4).down(); - int raw = (int) four_chars.to_long(null, 16); + int raw = (int) from_hex(four_chars); uint8[] bytes = {(uint8) ((raw >> 8) & 0xff - 128), (uint8) (raw & 0xff - 128)}; Checksum checksum = new Checksum(ChecksumType.SHA1); diff --git a/plugins/signal-protocol/src/simple_iks.vala b/plugins/signal-protocol/src/simple_iks.vala index 1e575515..5247c455 100644 --- a/plugins/signal-protocol/src/simple_iks.vala +++ b/plugins/signal-protocol/src/simple_iks.vala @@ -3,8 +3,8 @@ using Gee; namespace Signal { public class SimpleIdentityKeyStore : IdentityKeyStore { - public override uint8[] identity_key_private { get; set; } - public override uint8[] identity_key_public { get; set; } + public override Bytes identity_key_private { get; set; } + public override Bytes identity_key_public { get; set; } public override uint32 local_registration_id { get; set; } private Map<string, Map<int, IdentityKeyStore.TrustedIdentity>> trusted_identities = new HashMap<string, Map<int, IdentityKeyStore.TrustedIdentity>>(); @@ -37,4 +37,4 @@ public class SimpleIdentityKeyStore : IdentityKeyStore { } } -}
\ No newline at end of file +} diff --git a/plugins/signal-protocol/src/store.vala b/plugins/signal-protocol/src/store.vala index 2e277478..632ff8cc 100644 --- a/plugins/signal-protocol/src/store.vala +++ b/plugins/signal-protocol/src/store.vala @@ -1,8 +1,8 @@ namespace Signal { public abstract class IdentityKeyStore : Object { - public abstract uint8[] identity_key_private { get; set; } - public abstract uint8[] identity_key_public { get; set; } + public abstract Bytes identity_key_private { get; set; } + public abstract Bytes identity_key_public { get; set; } public abstract uint32 local_registration_id { get; set; } public signal void trusted_identity_added(TrustedIdentity id); @@ -112,8 +112,8 @@ public class Store : Object { static int iks_get_identity_key_pair(out Buffer public_data, out Buffer private_data, void* user_data) { Store store = (Store) user_data; - public_data = new Buffer.from(store.identity_key_store.identity_key_public); - private_data = new Buffer.from(store.identity_key_store.identity_key_private); + public_data = new Buffer.from(store.identity_key_store.identity_key_public.get_data()); + private_data = new Buffer.from(store.identity_key_store.identity_key_private.get_data()); return 0; } diff --git a/plugins/signal-protocol/tests/common.vala b/plugins/signal-protocol/tests/common.vala index 26e90185..9bb9b1dc 100644 --- a/plugins/signal-protocol/tests/common.vala +++ b/plugins/signal-protocol/tests/common.vala @@ -15,8 +15,8 @@ Store setup_test_store_context(Context global_context) { store.identity_key_store.local_registration_id = (Random.next_int() % 16380) + 1; ECKeyPair key_pair = global_context.generate_key_pair(); - store.identity_key_store.identity_key_private = key_pair.private.serialize(); - store.identity_key_store.identity_key_public = key_pair.public.serialize(); + store.identity_key_store.identity_key_private = new Bytes(key_pair.private.serialize()); + store.identity_key_store.identity_key_public = new Bytes(key_pair.public.serialize()); } catch (Error e) { fail_if_reached(); } diff --git a/plugins/signal-protocol/vapi/signal-protocol-public.vapi b/plugins/signal-protocol/vapi/signal-protocol-public.vapi index 0a4456ad..1952beb1 100644 --- a/plugins/signal-protocol/vapi/signal-protocol-public.vapi +++ b/plugins/signal-protocol/vapi/signal-protocol-public.vapi @@ -218,9 +218,14 @@ namespace Signal { [CCode (instance_pos = 1, cname = "ec_public_key_serialize")] private int serialize_([CCode (pos = 0)] out Buffer buffer); [CCode (cname = "ec_public_key_serialize_")] - public uint8[] serialize() throws GLib.Error { + public uint8[] serialize() { Buffer buffer; - throw_by_code(serialize_(out buffer)); + try { + throw_by_code(serialize_(out buffer)); + } catch (GLib.Error e) { + // Can only throw for invalid arguments or out of memory. + GLib.assert_not_reached(); + } return buffer.data; } public int compare(ECPublicKey other); @@ -235,7 +240,12 @@ namespace Signal { [CCode (cname = "ec_private_key_serialize_")] public uint8[] serialize() throws GLib.Error { Buffer buffer; - throw_by_code(serialize_(out buffer)); + try { + throw_by_code(serialize_(out buffer)); + } catch (GLib.Error e) { + // Can only throw for invalid arguments or out of memory. + GLib.assert_not_reached(); + } return buffer.data; } public int compare(ECPublicKey other); |