ソースを参照

Add pre and post validation for users that want to use their own public keys

master
Andrei Bora 5年前
コミット
92e6cf7618
2個のファイルの変更25行の追加7行の削除
  1. 21
    6
      resources/prosody-plugins/mod_auth_token.lua
  2. 4
    1
      resources/prosody-plugins/token/util.lib.lua

+ 21
- 6
resources/prosody-plugins/mod_auth_token.lua ファイルの表示

@@ -74,18 +74,28 @@ function provider.delete_user(username)
74 74
 	return nil;
75 75
 end
76 76
 
77
+local function validate_result(session, res, error, reason)
78
+    if res == false then
79
+        log("warn",
80
+            "Error verifying token err:%s, reason:%s", error, reason);
81
+        session.auth_token = nil;
82
+        return res, error, reason;
83
+    end
84
+end
85
+
77 86
 function provider.get_sasl_handler(session)
78 87
 
79 88
 	local function get_username_from_token(self, message)
80
-        local res, error, reason = token_util:process_and_verify_token(session);
81 89
 
82
-        if (res == false) then
83
-            log("warn",
84
-                "Error verifying token err:%s, reason:%s", error, reason);
85
-            session.auth_token = nil;
86
-            return res, error, reason;
90
+        -- retrieve custom public key from server and save it on the session
91
+        local event_result = prosody.events.fire_event("pre-jitsi-authentication-fetch-key", session);
92
+        if event_result ~= nil then
93
+            validate_result(session,event_result.res, event_result.error, event_result.reason)
87 94
         end
88 95
 
96
+        local res, error, reason = token_util:process_and_verify_token(session);
97
+        validate_result(session, res, error, reason);
98
+
89 99
         local customUsername
90 100
             = prosody.events.fire_event("pre-jitsi-authentication", session);
91 101
 
@@ -102,6 +112,11 @@ function provider.get_sasl_handler(session)
102 112
             self.username = message;
103 113
         end
104 114
 
115
+        local event_result = prosody.events.fire_event("post-jitsi-authentication", session);
116
+        if event_result ~= nil then
117
+            validate_result(session,event_result.res, event_result.error, event_result.reason)
118
+        end
119
+
105 120
         return res;
106 121
 	end
107 122
 

+ 4
- 1
resources/prosody-plugins/token/util.lib.lua ファイルの表示

@@ -301,7 +301,10 @@ function Util:process_and_verify_token(session, acceptedIssuers)
301 301
     end
302 302
 
303 303
     local pubKey;
304
-    if self.asapKeyServer and session.auth_token ~= nil then
304
+    if session.public_key then
305
+        module:log("debug","Public key was found on the session");
306
+        pubKey = session.public_key;
307
+    elseif self.asapKeyServer and session.auth_token ~= nil then
305 308
         local dotFirst = session.auth_token:find("%.");
306 309
         if not dotFirst then return nil, "Invalid token" end
307 310
         local header, err = json_safe.decode(basexx.from_url64(session.auth_token:sub(1,dotFirst-1)));

読み込み中…
キャンセル
保存