omemo: handle broken incoming key bundles

fixes #137
This commit is contained in:
Marvin W 2017-08-24 15:55:24 +02:00
parent 51b4f9b204
commit 7b395263c1
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A

View file

@ -282,11 +282,13 @@ public class StreamModule : XmppStreamModule {
ECPublicKey? identity_key = bundle.identity_key; ECPublicKey? identity_key = bundle.identity_key;
ArrayList<Bundle.PreKey> pre_keys = bundle.pre_keys; ArrayList<Bundle.PreKey> pre_keys = bundle.pre_keys;
if (signed_pre_key_id < 0 || signed_pre_key == null || identity_key == null || pre_keys.size == 0) {
fail = true;
} else {
int pre_key_idx = Random.int_range(0, pre_keys.size); int pre_key_idx = Random.int_range(0, pre_keys.size);
int32 pre_key_id = pre_keys[pre_key_idx].key_id; int32 pre_key_id = pre_keys[pre_key_idx].key_id;
ECPublicKey? pre_key = pre_keys[pre_key_idx].key; ECPublicKey? pre_key = pre_keys[pre_key_idx].key;
if (pre_key_id < 0 || pre_key == null) {
if (signed_pre_key_id < 0 || signed_pre_key == null || identity_key == null || pre_key_id < 0 || pre_key == null) {
fail = true; fail = true;
} else { } else {
Address address = new Address(jid, device_id); Address address = new Address(jid, device_id);
@ -303,6 +305,7 @@ public class StreamModule : XmppStreamModule {
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) { if (fail) {
stream.get_module(IDENTITY).ignore_device(jid, device_id); stream.get_module(IDENTITY).ignore_device(jid, device_id);
} }