aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo
diff options
context:
space:
mode:
authorhrxi <hrrrxi@gmail.com>2019-09-01 18:18:25 +0200
committerfiaxh <fiaxh@users.noreply.github.com>2019-09-10 19:36:11 +0200
commitd5d305193ce527f1cc3022c406de35d9a85d4ccb (patch)
treed12efc741319a7d71c13f7bf6c2c7579d25fdabe /plugins/omemo
parent9950742bf1903291c271619aea101b0e2f81d19c (diff)
downloaddino-d5d305193ce527f1cc3022c406de35d9a85d4ccb.tar.gz
dino-d5d305193ce527f1cc3022c406de35d9a85d4ccb.zip
Fix some warnings
Instances of `RegexError` are just asserted as `assert_not_reached` as they cannot really fail except for allocation failure if the given regex is valid.
Diffstat (limited to 'plugins/omemo')
-rw-r--r--plugins/omemo/src/file_transfer/file_decryptor.vala62
-rw-r--r--plugins/omemo/src/logic/manager.vala12
-rw-r--r--plugins/omemo/src/ui/util.vala6
3 files changed, 43 insertions, 37 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
+}