Browse Source

changed to using a setter for the asapKeyServer

master
Aaron van Meerten 5 years ago
parent
commit
7ce44f85ca
1 changed files with 9 additions and 15 deletions
  1. 9
    15
      resources/prosody-plugins/token/util.lib.lua

+ 9
- 15
resources/prosody-plugins/token/util.lib.lua View File

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

Loading…
Cancel
Save