From 9840774a87b9d15523ecc04ee4c157270e9abfe5 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sat, 13 May 2017 17:48:13 +0200 Subject: omemo: store and display identity keys of all devices --- plugins/omemo/src/stream_module.vala | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'plugins/omemo/src/stream_module.vala') diff --git a/plugins/omemo/src/stream_module.vala b/plugins/omemo/src/stream_module.vala index 00cddd0a..46bc0ecf 100644 --- a/plugins/omemo/src/stream_module.vala +++ b/plugins/omemo/src/stream_module.vala @@ -24,6 +24,7 @@ public class StreamModule : XmppStreamModule { public signal void store_created(Store store); public signal void device_list_loaded(string jid); + public signal void bundle_fetched(string jid, int device_id, Bundle bundle); public signal void session_started(string jid, int device_id); public signal void session_start_failed(string jid, int device_id); @@ -183,11 +184,11 @@ public class StreamModule : XmppStreamModule { public void request_user_devicelist(XmppStream stream, string jid) { if (active_devicelist_requests.add(jid)) { if (Plugin.DEBUG) print(@"OMEMO: requesting device list for $jid\n"); - stream.get_module(Pubsub.Module.IDENTITY).request(stream, jid, NODE_DEVICELIST, (stream, jid, id, node) => on_devicelist(stream, jid, id ?? "", node)); + stream.get_module(Pubsub.Module.IDENTITY).request(stream, jid, NODE_DEVICELIST, (stream, jid, id, node) => on_devicelist(stream, jid, id, node)); } } - public void on_devicelist(XmppStream stream, string jid, string id, StanzaNode? node_) { + public void on_devicelist(XmppStream stream, string jid, string? id, StanzaNode? node_) { StanzaNode node = node_ ?? new StanzaNode.build("list", NS_URI).add_self_xmlns(); string? my_jid = stream.get_flag(Bind.Flag.IDENTITY).my_jid; if (my_jid == null) return; @@ -219,7 +220,6 @@ public class StreamModule : XmppStreamModule { public void start_sessions_with(XmppStream stream, string bare_jid) { if (!device_lists.has_key(bare_jid)) { - // TODO: manually request a device list return; } Address address = new Address(bare_jid, 0); @@ -247,6 +247,23 @@ public class StreamModule : XmppStreamModule { } } + public void fetch_bundle(XmppStream stream, string bare_jid, int device_id) { + if (active_bundle_requests.add(bare_jid + @":$device_id")) { + if (Plugin.DEBUG) print(@"OMEMO: Asking for bundle from $bare_jid:$device_id\n"); + stream.get_module(Pubsub.Module.IDENTITY).request(stream, bare_jid, @"$NODE_BUNDLES:$device_id", (stream, jid, id, node) => { + bundle_fetched(jid, device_id, new Bundle(node)); + }); + } + } + + public ArrayList get_device_list(string jid) { + if (is_known_address(jid)) { + return device_lists[jid]; + } else { + return new ArrayList(); + } + } + public bool is_known_address(string name) { return device_lists.has_key(name); } @@ -276,6 +293,7 @@ public class StreamModule : XmppStreamModule { fail = true; } else { Bundle bundle = new Bundle(node); + bundle_fetched(jid, device_id, bundle); int32 signed_pre_key_id = bundle.signed_pre_key_id; ECPublicKey? signed_pre_key = bundle.signed_pre_key; uint8[] signed_pre_key_signature = bundle.signed_pre_key_signature; -- cgit v1.2.3-54-g00ecf