-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathkiwiirc-jitsi-meet-tokens.patch
292 lines (280 loc) · 10.8 KB
/
kiwiirc-jitsi-meet-tokens.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
diff --git a/mod_muc_role_from_jwt.lua b/mod_muc_role_from_jwt.lua
new file mode 100644
index 000000000..f807b39db
--- /dev/null
+++ b/mod_muc_role_from_jwt.lua
@@ -0,0 +1,90 @@
+module:log("info", "kiwiirc patch active: prosody-plugins/mod_muc_role_from_jwt.lua");
+
+local muc_service = module:depends("muc");
+local room_mt = muc_service.room_mt;
+
+--local occupant = muc_service.occupant_mt;
+module:set_global();
+--module:depends("c2s");
+--local sessions = module:shared("c2s/sessions");
+local sessions = module:shared("sessions");
+
+local muc_util = module:require "muc/util";
+local valid_affiliations = muc_util.valid_affiliations;
+
+local jid_bare = require "util.jid".bare;
+local jid_split = require "util.jid".split;
+
+-- package.path = '?.lua;' .. package.path
+-- local inspect = require('/usr/share/jitsi-meet/prosody-plugins/inspect');
+
+function len(t)
+ local n = 0;
+ for _ in pairs(t) do
+ n = n + 1
+ end
+ return n
+end
+
+local seen={}
+
+function dump(t,i)
+ module:log("debug", "dump table size: " .. len(t));
+ seen[t]=true
+ local s={}
+ local n=0
+ for k in pairs(t) do
+ n=n+1 s[n]=k
+ end
+ if pcall(function () table.sort(s); end) then
+ table.sort(s)
+ end
+ for k,v in ipairs(s) do
+ module:log("debug", "dump: " .. tostring(i) .. tostring(v))
+ v=t[v]
+ if type(v)=="table" and not seen[v] then
+ dump(v,i.."\t")
+ end
+ end
+end
+
+local jitsi_meet_focus_hostname = module:get_option("jitsi_meet_focus_hostname");
+
+room_mt.get_affiliation = function(room, jid)
+ --module:log("debug", "--- entered get_affiliation: jid=" .. jid);
+ --module:log("debug", debug.traceback());
+-- dump(_G,"");
+ -- dump(_G.full_sessions, "");
+ --module:log("debug", "sessions - " .. inspect(prosody.full_sessions));
+ local bare_jid = jid_bare(jid);
+-- module:log("debug", "jid : " .. session);
+ --local sess = occupant:get_presence(jid);
+ --module.log("debug", "sess - " .. sess);
+ local affiliation = nil;
+
+ -- TODO: don't allow earlier sessions to override affiliation claim from later ones
+ for conn, session in pairs(prosody.full_sessions) do
+ --module:log("debug", "test session: " .. jid .. " - " .. session.full_jid);
+ if jid_bare(session.full_jid) == bare_jid then
+ --module:log("debug", "found session - " .. inspect(session));
+ --module:log("debug", "found session - " .. session.full_jid);
+ if valid_affiliations[session.jitsi_meet_room_affiliation] ~= nil then
+ affiliation = session.jitsi_meet_room_affiliation;
+ -- module:log("debug", "setting affil - " .. affiliation);
+ end
+ end
+ end
+ local default_focus_affil = "owner";
+ local node, host, resource = jid_split(jid);
+ if host == jitsi_meet_focus_hostname then
+ module:log("debug", "affil (focus): " .. default_focus_affil .. " jid: " .. jid);
+ return default_focus_affil;
+ end
+ local default_affil = "member";
+ if affiliation == nil then
+ module:log("debug", "affil (default): " .. default_affil .. " jid: " .. jid);
+ return default_affil;
+ end
+ module:log("debug", "affil: " .. affiliation .. " jid: " .. jid);
+ return affiliation;
+end
diff --git a/mod_presence_identity.lua b/mod_presence_identity.lua
index 4db397e84..8de8af21e 100644
--- a/mod_presence_identity.lua
+++ b/mod_presence_identity.lua
@@ -1,6 +1,8 @@
local stanza = require "util.stanza";
local update_presence_identity = module:require "util".update_presence_identity;
+module:log("info", "kiwiirc patch active: prosody-plugins/mod_presence_identity.lua");
+
-- For all received presence messages, if the jitsi_meet_context_(user|group)
-- values are set in the session, then insert them into the presence messages
-- for that session.
@@ -20,3 +22,4 @@ end
module:hook("pre-presence/bare", on_message);
module:hook("pre-presence/full", on_message);
+module:hook("presence/full", on_message); -- this is the only one that fires now?
diff --git a/token/util.lib.lua b/token/util.lib.lua
index f12f173e9..8bd722254 100644
--- a/token/util.lib.lua
+++ b/token/util.lib.lua
@@ -18,6 +18,9 @@ local nr_retries = 3;
-- TODO: Figure out a less arbitrary default cache size.
local cacheSize = module:get_option_number("jwt_pubkey_cache_size", 128);
+local jitsi_meet_domain = module:get_option("jitsi_meet_domain");
+module:log("info", "kiwiirc patch active: prosody-plugins/token/util.lib.lua");
+
local Util = {}
Util.__index = Util
@@ -196,6 +199,8 @@ function Util:verify_token(token, secret, acceptedIssuers)
return nil, err;
end
+ claims["context"] = nil;
+
local alg = claims["alg"];
if alg ~= nil and (alg == "none" or alg == "") then
return nil, "'alg' claim must not be empty";
@@ -205,22 +210,33 @@ function Util:verify_token(token, secret, acceptedIssuers)
if issClaim == nil then
return nil, "'iss' claim is missing";
end
+
--check the issuer against the accepted list
- local issCheck, issCheckErr = self:verify_issuer(issClaim, acceptedIssuers);
- if issCheck == nil then
- return nil, issCheckErr;
+ local subClaim = claims["sub"];
+ if subClaim == nil then
+ claims["sub"] = jitsi_meet_domain;
end
if self.requireRoomClaim then
- local roomClaim = claims["room"];
+ local roomClaim = claims["channel"];
if roomClaim == nil then
- return nil, "'room' claim is missing";
+ return nil, "'channel' claim is missing";
end
+
+ local encRoom = issClaim .. "/" .. roomClaim;
+ claims["room"] = encRoom:gsub('.', function (c) return string.format('%02X', string.byte(c)) end):lower();
+ module:log("debug", "room encoded from " .. encRoom .. " as " .. claims.room);
+ end
+
+ local nickClaim = claims["nick"];
+ if nickClaim == nil then
+ return nil, "'nick' claim is missing";
end
local audClaim = claims["aud"];
if audClaim == nil then
- return nil, "'aud' claim is missing";
+ audClaim = "kiwiClientID";
+ claims["aud"] = audClaim;
end
--check the audience against the accepted list
local audCheck, audCheckErr = self:verify_audience(audClaim);
@@ -286,8 +302,40 @@ function Util:process_and_verify_token(session, acceptedIssuers)
if claims ~= nil then
-- Binds room name to the session which is later checked on MUC join
session.jitsi_meet_room = claims["room"];
+ session.jitsi_meet_joined = claims["joined"];
-- Binds domain name to the session
session.jitsi_meet_domain = claims["sub"];
+ session.jitsi_meet_issuer = claims["iss"];
+
+ affil = {};
+ affil.owner = false;
+ affil.admin = false;
+ affil.member = false;
+ affil.none = true;
+ affil.outcast = false;
+
+ if (claims.modes ~= nil and type(claims.modes) == "table") then
+ for i, mode in ipairs(claims.modes) do
+ if mode == "o" then affil.owner = true
+ -- elseif mode == "%" then affil.member = true
+ -- elseif mode == "+" then affil.member = true
+ end
+ end
+ end
+
+ if affil.owner then affil.final = "owner"
+ elseif affil.admin then affil.final = "admin"
+ elseif affil.member then affil.final = "member"
+ elseif affil.none then affil.final = "none"
+ else affil.final = "outcast"
+ end
+ --module:log("error", "---- Benz log msg - " .. affil.final .. " from " .. inspect(claims));
+ --module:log("error", debug.traceback());
+ session.jitsi_meet_room_affiliation = affil.final;
+
+ local contextUser = {};
+ contextUser["name"] = claims["nick"];
+ session.jitsi_meet_context_user = contextUser;
-- Binds the user details to the session if available
if claims["context"] ~= nil then
@@ -337,11 +385,38 @@ function Util:verify_room(session, room_address)
return true;
end
+ -- allow anonymous users because apparently that's how jicofo works. hopefully something else actually enforces access control elsewhere???
+ if not session.jitsi_meet_issuer then
+ module:log("debug", "allowing anonymous session");
+ return true
+ end
+
+ -- handle auth for one-on-one query conversations
+ local decoded_room_name = hex.from(room);
+ module:log("debug", "decoded room name: " .. decoded_room_name);
+ local server_address, first_query_partner, second_query_partner = decoded_room_name:match("^([^/]+)/query[-]([^#]+)#([^#]+)$");
+ local query_auth = first_query_partner ~= nil;
+ if query_auth then
+ local client_nick = session.jitsi_meet_context_user ~= nil and session.jitsi_meet_context_user.name;
+ local participant = client_nick == first_query_partner or client_nick == second_query_partner;
+ local same_server = server_address == session.jitsi_meet_issuer;
+ -- return participant and same_server;
+ if participant and same_server then
+ return true;
+ else
+ module:log("debug", "query auth failed. continuing...");
+ end
+ end
+
local auth_room = session.jitsi_meet_room;
+ if auth_room and not session.jitsi_meet_joined then
+ module:log("debug", "ignoring room claim without joined claim");
+ auth_room = nil
+ end
if not self.enableDomainVerification then
-- if auth_room is missing, this means user is anonymous (no token for
-- its domain) we let it through, jicofo is verifying creation domain
- if auth_room and room ~= string.lower(auth_room) and auth_room ~= '*' then
+ if auth_room and room ~= string.lower(auth_room) and auth_room ~= '*' or query_auth then
return false;
end
diff --git a/util.lib.lua b/util.lib.lua
index c517eabef..be438973f 100644
--- a/util.lib.lua
+++ b/util.lib.lua
@@ -2,6 +2,8 @@ local jid = require "util.jid";
local timer = require "util.timer";
local http = require "net.http";
+module:log("info", "kiwiirc patch active: prosody-plugins/util.lib.lua");
+
local http_timeout = 30;
local have_async, async = pcall(require, "util.async");
local http_headers = {
@@ -182,6 +184,10 @@ function update_presence_identity(
if k == "name" and v == "identity" then
return nil
end
+ -- Also remove the nick element
+ if k == "name" and v == "nick" then
+ return nil
+ end
end
return tag
end
@@ -189,6 +195,9 @@ function update_presence_identity(
module:log("debug",
"Presence after previous identity stripped: %s", tostring(stanza));
+ -- Override nick
+ stanza:tag("nick", {xmlns='http://jabber.org/protocol/nick'}):text(user.name):up();
+
stanza:tag("identity"):tag("user");
for k, v in pairs(user) do
v = tostring(v)