diff options
author | Marvin W <git@larma.de> | 2017-08-24 15:55:24 +0200 |
---|---|---|
committer | Marvin W <git@larma.de> | 2017-08-24 15:58:32 +0200 |
commit | 7b395263c1ec0e6b057f7c3bb1d0525f6f38964d (patch) | |
tree | 3f0417c05fc06d6f22a2f9f91195ad2da5939c84 /plugins/omemo | |
parent | 51b4f9b204d4555d354b7324ba918dbfff151c59 (diff) | |
download | dino-7b395263c1ec0e6b057f7c3bb1d0525f6f38964d.tar.gz dino-7b395263c1ec0e6b057f7c3bb1d0525f6f38964d.zip |
omemo: handle broken incoming key bundles
fixes #137
Diffstat (limited to 'plugins/omemo')
-rw-r--r-- | plugins/omemo/src/stream_module.vala | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/plugins/omemo/src/stream_module.vala b/plugins/omemo/src/stream_module.vala index 4fdf85a7..00cddd0a 100644 --- a/plugins/omemo/src/stream_module.vala +++ b/plugins/omemo/src/stream_module.vala @@ -282,25 +282,28 @@ public class StreamModule : XmppStreamModule { ECPublicKey? identity_key = bundle.identity_key; ArrayList<Bundle.PreKey> pre_keys = bundle.pre_keys; - int pre_key_idx = Random.int_range(0, pre_keys.size); - int32 pre_key_id = pre_keys[pre_key_idx].key_id; - ECPublicKey? pre_key = pre_keys[pre_key_idx].key; - - if (signed_pre_key_id < 0 || signed_pre_key == null || identity_key == null || pre_key_id < 0 || pre_key == null) { + if (signed_pre_key_id < 0 || signed_pre_key == null || identity_key == null || pre_keys.size == 0) { fail = true; } else { - Address address = new Address(jid, device_id); - try { - if (store.contains_session(address)) { - return; - } - SessionBuilder builder = store.create_session_builder(address); - builder.process_pre_key_bundle(create_pre_key_bundle(device_id, device_id, pre_key_id, pre_key, signed_pre_key_id, signed_pre_key, signed_pre_key_signature, identity_key)); - stream.get_module(IDENTITY).session_started(jid, device_id); - } catch (Error e) { + int pre_key_idx = Random.int_range(0, pre_keys.size); + int32 pre_key_id = pre_keys[pre_key_idx].key_id; + ECPublicKey? pre_key = pre_keys[pre_key_idx].key; + if (pre_key_id < 0 || pre_key == null) { fail = true; + } else { + Address address = new Address(jid, device_id); + try { + if (store.contains_session(address)) { + return; + } + SessionBuilder builder = store.create_session_builder(address); + builder.process_pre_key_bundle(create_pre_key_bundle(device_id, device_id, pre_key_id, pre_key, signed_pre_key_id, signed_pre_key, signed_pre_key_signature, identity_key)); + stream.get_module(IDENTITY).session_started(jid, device_id); + } catch (Error e) { + fail = true; + } + address.device_id = 0; // TODO: Hack to have address obj live longer } - address.device_id = 0; // TODO: Hack to have address obj live longer } } if (fail) { |