Procházet zdrojové kódy

feat: Adds an option to validate a recording token.

master
damencho před 4 roky
rodič
revize
6d3d15a64b

+ 32
- 7
resources/prosody-plugins/mod_filter_iq_jibri.lua Zobrazit soubor

@@ -1,5 +1,8 @@
1 1
 local st = require "util.stanza";
2 2
 local is_feature_allowed = module:require "util".is_feature_allowed;
3
+local token_util = module:require "token/util".new(module);
4
+
5
+local accepted_rayo_iq_token_issuers = module:get_option_array("accepted_rayo_iq_token_issuers");
3 6
 
4 7
 -- filters jibri iq in case of requested from jwt authenticated session that
5 8
 -- has features in the user context, but without feature for recording
@@ -11,15 +14,37 @@ module:hook("pre-iq/full", function(event)
11 14
             local session = event.origin;
12 15
             local token = session.auth_token;
13 16
 
14
-            if jibri.attr.action == 'start'
15
-                and (token == nil
17
+            if jibri.attr.action == 'start' then
18
+                local errorReason;
19
+                if accepted_rayo_iq_token_issuers then
20
+                    local iq_token = jibri.attr.token;
21
+                    if iq_token then
22
+                        local session = {};
23
+                        session.auth_token = iq_token;
24
+                        local verified, reason = token_util:process_and_verify_token(
25
+                            session, accepted_rayo_iq_token_issuers);
26
+                        if verified then
27
+                            return nil; -- this will proceed with dispatching the stanza
28
+                        end
29
+                        errorReason = reason;
30
+                    else
31
+                        errorReason = 'No recording token provided';
32
+                    end
33
+
34
+                    module:log("warn", "not a valid token %s", tostring(errorReason));
35
+                    session.send(st.error_reply(stanza, "auth", "forbidden"));
36
+                    return true;
37
+                end
38
+
39
+                if token == nil
16 40
                     or not is_feature_allowed(session,
17
-                        (jibri.attr.recording_mode == 'file' and 'recording' or 'livestreaming'))
41
+                    (jibri.attr.recording_mode == 'file' and 'recording' or 'livestreaming')
18 42
                 ) then
19
-                module:log("info",
20
-                    "Filtering jibri start recording, stanza:%s", tostring(stanza));
21
-                session.send(st.error_reply(stanza, "auth", "forbidden"));
22
-                return true;
43
+                    module:log("info",
44
+                        "Filtering jibri start recording, stanza:%s", tostring(stanza));
45
+                    session.send(st.error_reply(stanza, "auth", "forbidden"));
46
+                    return true;
47
+                end
23 48
             end
24 49
         end
25 50
     end

+ 15
- 8
resources/prosody-plugins/token/util.lib.lua Zobrazit soubor

@@ -159,9 +159,10 @@ end
159 159
 
160 160
 --- Verifies issuer part of token
161 161
 -- @param 'iss' claim from the token to verify
162
+-- @param 'acceptedIssuers' list of issuers to check
162 163
 -- @return nil and error string or true for accepted claim
163
-function Util:verify_issuer(issClaim)
164
-    for i, iss in ipairs(self.acceptedIssuers) do
164
+function Util:verify_issuer(issClaim, acceptedIssuers)
165
+    for i, iss in ipairs(acceptedIssuers) do
165 166
         if issClaim == iss then
166 167
             --claim matches an accepted issuer so return success
167 168
             return true;
@@ -192,8 +193,9 @@ end
192 193
 --- Verifies token
193 194
 -- @param token the token to verify
194 195
 -- @param secret the secret to use to verify token
196
+-- @param acceptedIssuers the list of accepted issuers to check
195 197
 -- @return nil and error or the extracted claims from the token
196
-function Util:verify_token(token, secret)
198
+function Util:verify_token(token, secret, acceptedIssuers)
197 199
     local claims, err = jwt.decode(token, secret, true);
198 200
     if claims == nil then
199 201
         return nil, err;
@@ -209,7 +211,7 @@ function Util:verify_token(token, secret)
209 211
         return nil, "'iss' claim is missing";
210 212
     end
211 213
     --check the issuer against the accepted list
212
-    local issCheck, issCheckErr = self:verify_issuer(issClaim);
214
+    local issCheck, issCheckErr = self:verify_issuer(issClaim, acceptedIssuers);
213 215
     if issCheck == nil then
214 216
         return nil, issCheckErr;
215 217
     end
@@ -241,8 +243,13 @@ end
241 243
 -- session.jitsi_meet_context_group - the group value from the token
242 244
 -- session.jitsi_meet_context_features - the features value from the token
243 245
 -- @param session the current session
246
+-- @param acceptedIssuers optional list of accepted issuers to check
244 247
 -- @return false and error
245
-function Util:process_and_verify_token(session)
248
+function Util:process_and_verify_token(session, acceptedIssuers)
249
+    if not acceptedIssuers then
250
+        acceptedIssuers = self.acceptedIssuers;
251
+    end
252
+
246 253
     if session.auth_token == nil then
247 254
         if self.allowEmptyToken then
248 255
             return true;
@@ -272,9 +279,9 @@ function Util:process_and_verify_token(session)
272 279
     -- now verify the whole token
273 280
     local claims, msg;
274 281
     if self.asapKeyServer then
275
-        claims, msg = self:verify_token(session.auth_token, pubKey);
282
+        claims, msg = self:verify_token(session.auth_token, pubKey, acceptedIssuers);
276 283
     else
277
-        claims, msg = self:verify_token(session.auth_token, self.appSecret);
284
+        claims, msg = self:verify_token(session.auth_token, self.appSecret, acceptedIssuers);
278 285
     end
279 286
     if claims ~= nil then
280 287
         -- Binds room name to the session which is later checked on MUC join
@@ -401,4 +408,4 @@ function Util:verify_room(session, room_address)
401 408
     end
402 409
 end
403 410
 
404
-return Util;
411
+return Util;

Načítá se…
Zrušit
Uložit