Software /
code /
prosody-modules
Annotate
mod_debug_omemo/mod_debug_omemo.lua @ 4684:ffddf9b29463
mod_debug_omemo: README: Maybe fix version table
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 13 Sep 2021 19:29:03 +0100 |
parent | 4682:e4e5474420e6 |
child | 4685:07b6f444bafb |
rev | line source |
---|---|
4682
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local array = require "util.array"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local jid = require "util.jid"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local set = require "util.set"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local st = require "util.stanza"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local url_escape = require "util.http".urlencode; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local base_url = "https://"..module.host.."/"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local render_html_template = require"util.interpolation".new("%b{}", st.xml_escape, { |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 urlescape = url_escape; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 lower = string.lower; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 classname = function (s) return (s:gsub("%W+", "-")); end; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 relurl = function (s) |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 if s:match("^%w+://") then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 return s; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 return base_url.."/"..s; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 end; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 }); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local render_url = require "util.interpolation".new("%b{}", url_escape, { |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 urlescape = url_escape; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 noscheme = function (url) |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 return (url:gsub("^[^:]+:", "")); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 end; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 }); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 local mod_pep = module:depends("pep"); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 local mam = module:open_store("archive", "archive"); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 local function get_user_omemo_info(username) |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 local everything_valid = true; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 local any_device = false; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 local omemo_status = {}; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local omemo_devices; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 local pep_service = mod_pep.get_pep_service(username); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 if pep_service and pep_service.nodes then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 local ok, _, device_list = pep_service:get_last_item("eu.siacs.conversations.axolotl.devicelist", true); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 if ok and device_list then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 device_list = device_list:get_child("list", "eu.siacs.conversations.axolotl"); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 if device_list then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 omemo_devices = {}; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 for device_entry in device_list:childtags("device") do |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 any_device = true; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 local device_info = {}; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 local device_id = tonumber(device_entry.attr.id or ""); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 if device_id then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 device_info.id = device_id; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 local bundle_id = ("eu.siacs.conversations.axolotl.bundles:%d"):format(device_id); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 local have_bundle, _, bundle = pep_service:get_last_item(bundle_id, true); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 if have_bundle and bundle and bundle:get_child("bundle", "eu.siacs.conversations.axolotl") then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 device_info.have_bundle = true; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 local config_ok, bundle_config = pep_service:get_node_config(bundle_id, true); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 if config_ok and bundle_config then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 device_info.bundle_config = bundle_config; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 if bundle_config.max_items == 1 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 and bundle_config.access_model == "open" |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 and bundle_config.persist_items == true |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 and bundle_config.publish_model == "publishers" then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 device_info.valid = true; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 if device_info.valid == nil then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 device_info.valid = false; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 everything_valid = false; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 table.insert(omemo_devices, device_info); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 local config_ok, list_config = pep_service:get_node_config("eu.siacs.conversations.axolotl.devicelist", true); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 if config_ok and list_config then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 omemo_status.config = list_config; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 if list_config.max_items == 1 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 and list_config.access_model == "open" |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 and list_config.persist_items == true |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 and list_config.publish_model == "publishers" then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 omemo_status.config_valid = true; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 if omemo_status.config_valid == nil then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 omemo_status.config_valid = false; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 everything_valid = false; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 omemo_status.valid = everything_valid and any_device; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 return { |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 status = omemo_status; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 devices = omemo_devices; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 }; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 local access_model_text = { |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 open = "Public"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 whitelist = "Private"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 roster = "Contacts only"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 presence = "Contacts only"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 }; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 local function render_message(event, path) |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 local username, message_id = path:match("^([^/]+)/(.+)$"); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 if not username then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 return 400; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 local message; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 for _, result in mam:find(username, { key = message_id }) do |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 message = result; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 if not message then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 return 404; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 local user_omemo_status = get_user_omemo_info(username); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 local user_rids = set.new(array.pluck(user_omemo_status.devices or {}, "id")) / tostring; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 local message_omemo_header = message:find("{eu.siacs.conversations.axolotl}encrypted/header"); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 local message_rids = set.new(); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 local rid_info = {}; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 if message_omemo_header then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 for key_el in message_omemo_header:childtags("key") do |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 local rid = key_el.attr.rid; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 if rid then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 message_rids:add(rid); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 local prekey = key_el.attr.prekey; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 rid_info = { |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 prekey = prekey and (prekey == "1" or prekey:lower() == "true"); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 }; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 local rids = user_rids + message_rids; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 local direction = jid.bare(message.attr.to) == (username.."@"..module.host) and "incoming" or "outgoing"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 local is_encrypted = not not message_omemo_header; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 local sender_id = message_omemo_header and message_omemo_header.attr.sid or nil; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 local f = module:load_resource("view.tpl.html"); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 if not f then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 return 500; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 local tpl = f:read("*a"); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 local data = { user = username, rids = {} }; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 for rid in rids do |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 data.rids[rid] = { |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 status = message_rids:contains(rid) and "Encrypted" or user_rids:contains(rid) and "Missing" or nil; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 prekey = rid_info.prekey; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 }; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 data.message = { |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 type = message.attr.type or "normal"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 direction = direction; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 encryption = is_encrypted and "encrypted" or "unencrypted"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 }; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 data.omemo = { |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 sender_id = sender_id; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 status = user_omemo_status.status.valid and "no known issues" or "problems"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 }; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 data.omemo.devices = {}; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 for _, device_info in ipairs(user_omemo_status.devices) do |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 data.omemo.devices[("%d"):format(device_info.id)] = { |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 status = device_info.valid and "OK" or "Problem"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 bundle = device_info.have_bundle and "Published" or "Missing"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 access_model = access_model_text[device_info.bundle_config and device_info.bundle_config.access_model or nil]; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 }; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 event.response.headers.content_type = "text/html; charset=utf-8"; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 return render_html_template(tpl, data); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 local function check_omemo_fallback(event) |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 local message = event.stanza; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 local message_omemo_header = message:find("{eu.siacs.conversations.axolotl}encrypted/header"); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 if not message_omemo_header then return; end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
188 local to_bare = jid.bare(message.attr.to); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 local archive_stanza_id; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 for stanza_id_tag in message:childtags("stanza-id", "urn:xmpp:sid:0") do |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 if stanza_id_tag.attr.by == to_bare then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 archive_stanza_id = stanza_id_tag.attr.id; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 if not archive_stanza_id then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 return; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 local debug_url = render_url(module:http_url().."/view/{username}/{message_id}", { |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
201 username = jid.node(to_bare); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 message_id = archive_stanza_id; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 }); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 local body = message:get_child("body"); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 if not body then |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 body = st.stanza("body") |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 :text("This message is encrypted using OMEMO, but could not be decrypted by your device.\nFor more information see: "..debug_url); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 message:reset():add_child(body); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 else |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 body:text("\n\nOMEMO debug information: "..debug_url); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 end |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 module:hook("message/bare", check_omemo_fallback, 1); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 module:hook("message/full", check_omemo_fallback, 1); |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 module:depends("http") |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
219 module:provides("http", { |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 route = { |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 ["GET /view/*"] = render_message; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 }; |
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 }); |