Mercurial > prosody-modules
changeset 3393:8d1141025b43
mod_s2s_auth_monkeysphere: Remove blocking mode (simplifes code) (not tested)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 01 Dec 2018 16:04:35 +0100 |
parents | c8c9c940ec2d |
children | 4fe7eee926ce |
files | mod_s2s_auth_monkeysphere/README.markdown mod_s2s_auth_monkeysphere/mod_s2s_auth_monkeysphere.lua |
diffstat | 2 files changed, 19 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_s2s_auth_monkeysphere/README.markdown Sat Dec 01 16:04:24 2018 +0100 +++ b/mod_s2s_auth_monkeysphere/README.markdown Sat Dec 01 16:04:35 2018 +0100 @@ -18,8 +18,9 @@ ## Compatibility - ------- ------- - trunk Works - 0.10 Works - 0.9 Works - ------- ------- + ------- ----------------------------- + trunk Works (not tested recently) + 0.11 Works (not tested) + 0.10 Does not work + 0.9 Does not work + ------- -----------------------------
--- a/mod_s2s_auth_monkeysphere/mod_s2s_auth_monkeysphere.lua Sat Dec 01 16:04:24 2018 +0100 +++ b/mod_s2s_auth_monkeysphere/mod_s2s_auth_monkeysphere.lua Sat Dec 01 16:04:35 2018 +0100 @@ -1,33 +1,17 @@ module:set_global(); -local http_request = require"socket.http".request; -local ltn12 = require"ltn12"; local json = require"util.json"; local json_encode, json_decode = json.encode, json.decode; local gettime = require"socket".gettime; local serialize = require"util.serialization".serialize; -local have_async, async = pcall(require, "util.async"); +local async = require"util.async"; +local http_request = require "net.http".request; local msva_url = assert(os.getenv"MONKEYSPHERE_VALIDATION_AGENT_SOCKET", "MONKEYSPHERE_VALIDATION_AGENT_SOCKET is unset, please set it").."/reviewcert"; -if have_async then - local _http_request = require "net.http".request; - function http_request(url, ex) - local wait, done = async.waiter(); - local content, code, request, response; - _http_request(url, ex, function (_content, _code, _request, _response) - content, code, request, response = _content, _code, _request, _response; - done(); - end); - wait(); - return content, code, request, response; - end -end - local function check_with_monkeysphere(event) local session, host, cert = event.session, event.host, event.cert; - local result = {}; local post_body = json_encode { peer = { name = host; @@ -42,23 +26,26 @@ } local req = { method = "POST"; - url = msva_url; headers = { ["Content-Type"] = "application/json"; - ["Content-Length"] = tostring(#post_body); }; - sink = ltn12.sink.table(result); - source = ltn12.source.string(post_body); + body = post_body; }; session.log("debug", "Asking what Monkeysphere thinks about this certificate"); local starttime = gettime(); - local ok, code = http_request(req); + local wait, done = async.waiter(); + local body, code; + http_request(msva_url, req, function (_, _code) + body, code = body, _code; + done(); + end); + wait(); module:log("debug", "Request took %fs", gettime() - starttime); - local body = table.concat(result); - if ok and code == 200 and body then + if code == 200 and body then body = json_decode(body); if body then - session.log(body.valid and "info" or "warn", "Monkeysphere thinks the cert is %salid: %s", body.valid and "V" or "Inv", body.message); + session.log(body.valid and "info" or "warn", + "Monkeysphere thinks the cert is %salid: %s", body.valid and "V" or "Inv", body.message); if body.valid then session.cert_chain_status = "valid"; session.cert_identity_status = "valid";