Bläddra i källkod

allows override of asap key server in token utility

master
Aaron van Meerten 5 år sedan
förälder
incheckning
41e0d782ce
1 ändrade filer med 14 tillägg och 5 borttagningar
  1. 14
    5
      resources/prosody-plugins/token/util.lib.lua

+ 14
- 5
resources/prosody-plugins/token/util.lib.lua Visa fil

@@ -103,7 +103,10 @@ end
103 103
 --- Returns the public key by keyID
104 104
 -- @param keyId the key ID to request
105 105
 -- @return the public key (the content of requested resource) or nil
106
-function Util:get_public_key(keyId)
106
+function Util:get_public_key(keyId,asapKeyServer)
107
+    if asapKeyServer == "" then
108
+        asapKeyServer = self.asapKeyServer)
109
+    end
107 110
     local content = cache:get(keyId);
108 111
     if content == nil then
109 112
         -- If the key is not found in the cache.
@@ -117,7 +120,7 @@ function Util:get_public_key(keyId)
117 120
             end
118 121
             done();
119 122
         end
120
-        local keyurl = path.join(self.asapKeyServer, hex.to(sha256(keyId))..'.pem');
123
+        local keyurl = path.join(asapKeyServer, hex.to(sha256(keyId))..'.pem');
121 124
         module:log("debug", "Fetching public key from: "..keyurl);
122 125
 
123 126
         -- We hash the key ID to work around some legacy behavior and make
@@ -239,6 +242,12 @@ end
239 242
 -- @param session the current session
240 243
 -- @return false and error
241 244
 function Util:process_and_verify_token(session)
245
+    return self:process_and_verify_token_with_keyserver(session,"")
246
+end
247
+function Util:process_and_verify_token_with_keyserver(session,asapKeyServer)
248
+    if asapKeyServer == "" then
249
+        asapKeyServer = self.asapKeyServer
250
+    end
242 251
 
243 252
     if session.auth_token == nil then
244 253
         if self.allowEmptyToken then
@@ -249,7 +258,7 @@ function Util:process_and_verify_token(session)
249 258
     end
250 259
 
251 260
     local pubKey;
252
-    if self.asapKeyServer and session.auth_token ~= nil then
261
+    if asapKeyServer and session.auth_token ~= nil then
253 262
         local dotFirst = session.auth_token:find("%.");
254 263
         if not dotFirst then return nil, "Invalid token" end
255 264
         local header = json.decode(basexx.from_url64(session.auth_token:sub(1,dotFirst-1)));
@@ -257,7 +266,7 @@ function Util:process_and_verify_token(session)
257 266
         if kid == nil then
258 267
             return false, "not-allowed", "'kid' claim is missing";
259 268
         end
260
-        pubKey = self:get_public_key(kid);
269
+        pubKey = self:get_public_key(kid,asapKeyServer);
261 270
         if pubKey == nil then
262 271
             return false, "not-allowed", "could not obtain public key";
263 272
         end
@@ -265,7 +274,7 @@ function Util:process_and_verify_token(session)
265 274
 
266 275
     -- now verify the whole token
267 276
     local claims, msg;
268
-    if self.asapKeyServer then
277
+    if asapKeyServer then
269 278
         claims, msg = self:verify_token(session.auth_token, pubKey);
270 279
     else
271 280
         claims, msg = self:verify_token(session.auth_token, self.appSecret);

Laddar…
Avbryt
Spara