|
@@ -19,7 +19,6 @@ local http_headers = {
|
19
|
19
|
|
20
|
20
|
-- TODO: Figure out a less arbitrary default cache size.
|
21
|
21
|
local cacheSize = module:get_option_number("jwt_pubkey_cache_size", 128);
|
22
|
|
-local cache = require"util.cache".new(cacheSize);
|
23
|
22
|
|
24
|
23
|
local Util = {}
|
25
|
24
|
Util.__index = Util
|
|
@@ -38,6 +37,8 @@ function Util.new(module)
|
38
|
37
|
self.asapKeyServer = module:get_option_string("asap_key_server");
|
39
|
38
|
self.allowEmptyToken = module:get_option_boolean("allow_empty_token");
|
40
|
39
|
|
|
40
|
+ self.cache = require"util.cache".new(cacheSize);
|
|
41
|
+
|
41
|
42
|
--[[
|
42
|
43
|
Multidomain can be supported in some deployments. In these deployments
|
43
|
44
|
there is a virtual conference muc, which address contains the subdomain
|
|
@@ -108,7 +109,7 @@ end
|
108
|
109
|
-- @param keyId the key ID to request
|
109
|
110
|
-- @return the public key (the content of requested resource) or nil
|
110
|
111
|
function Util:get_public_key(keyId)
|
111
|
|
- local content = cache:get(keyId);
|
|
112
|
+ local content = self.cache:get(keyId);
|
112
|
113
|
if content == nil then
|
113
|
114
|
-- If the key is not found in the cache.
|
114
|
115
|
module:log("debug", "Cache miss for key: "..keyId);
|
|
@@ -117,7 +118,10 @@ function Util:get_public_key(keyId)
|
117
|
118
|
local function cb(content_, code_, response_, request_)
|
118
|
119
|
content, code = content_, code_;
|
119
|
120
|
if code == 200 or code == 204 then
|
120
|
|
- cache:set(keyId, content);
|
|
121
|
+ self.cache:set(keyId, content);
|
|
122
|
+ else
|
|
123
|
+ module:log("warn", "Error on public key request: Code %s, Content %s",
|
|
124
|
+ code_, content_);
|
121
|
125
|
end
|
122
|
126
|
done();
|
123
|
127
|
end
|
|
@@ -138,7 +142,9 @@ function Util:get_public_key(keyId)
|
138
|
142
|
-- TODO: This check is racey. Not likely to be a problem, but we should
|
139
|
143
|
-- still stick a mutex on content / code at some point.
|
140
|
144
|
if code == nil then
|
141
|
|
- http.destroy_request(request);
|
|
145
|
+ -- no longer works in prosody 0.11
|
|
146
|
+ -- @TODO: work with prosody devs to determine better timeout mechanism for timing out active http requests
|
|
147
|
+ -- http.destroy_request(request);
|
142
|
148
|
done();
|
143
|
149
|
end
|
144
|
150
|
end
|