Просмотр исходного кода

Merge pull request #825 from SamWhited/mod_token_improvements

Mod token improvements
j8
Paweł Domas 9 лет назад
Родитель
Сommit
9ba62c320b
1 измененных файлов: 10 добавлений и 1 удалений
  1. 10
    1
      prosody-plugins/mod_auth_token.lua

+ 10
- 1
prosody-plugins/mod_auth_token.lua Просмотреть файл

@@ -9,6 +9,7 @@ local http = require "net.http";
9 9
 local json = require "cjson";
10 10
 local new_sasl = require "util.sasl".new;
11 11
 local sasl = require "util.sasl";
12
+local sha256 = require "util.hashes".sha256;
12 13
 local timer = require "util.timer";
13 14
 local token_util = module:require "token/util";
14 15
 
@@ -93,13 +94,21 @@ function get_public_key(keyId)
93 94
 		local wait, done = async.waiter();
94 95
 		local function cb(content_, code_, response_, request_)
95 96
 			content, code = content_, code_;
97
+			if code == 200 or code == 204 then
98
+				cache:set(keyId, content);
99
+			end
96 100
 			done();
97 101
 		end
98 102
 		module:log("debug", "Fetching public key from: "..asapKeyServer..keyId);
99
-		local request = http.request(asapKeyServer..keyId, {
103
+
104
+		-- We hash the key ID to work around some legacy behavior and make
105
+		-- deployment easier. It also helps prevent directory
106
+		-- traversal attacks (although path cleaning could have done this too).
107
+		local request = http.request(asapKeyServer..sha256(keyId)..'.pem', {
100 108
 			headers = http_headers or {},
101 109
 			method = "GET"
102 110
 		}, cb);
111
+
103 112
 		-- TODO: Is the done() call racey? Can we cancel this if the request
104 113
 		--       succeedes?
105 114
 		local function cancel()

Загрузка…
Отмена
Сохранить