Software /
code /
prosody-modules
Comparison
mod_s2s_auth_posh/mod_s2s_auth_posh.lua @ 3205:7bfb25111ea6
mod_s2s_auth_posh: Normalize code formatting
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 28 Jan 2018 13:57:02 +0100 |
parent | 3204:13f381f0c03f |
child | 3225:517c7f0333e3 |
comparison
equal
deleted
inserted
replaced
3204:13f381f0c03f | 3205:7bfb25111ea6 |
---|---|
3 -- | 3 -- |
4 -- Implements authentication via POSH (PKIX over Secure HTTP) | 4 -- Implements authentication via POSH (PKIX over Secure HTTP) |
5 -- http://tools.ietf.org/html/draft-miller-posh-03 | 5 -- http://tools.ietf.org/html/draft-miller-posh-03 |
6 -- | 6 -- |
7 module:set_global(); | 7 module:set_global(); |
8 local json = require 'util.json' | 8 local json = require "util.json"; |
9 | 9 |
10 local base64 = require"util.encodings".base64; | 10 local base64 = require "util.encodings".base64; |
11 local pem2der = require "util.x509".pem2der; | 11 local pem2der = require "util.x509".pem2der; |
12 local hashes = require"util.hashes"; | 12 local hashes = require "util.hashes"; |
13 local build_url = require"socket.url".build; | 13 local build_url = require "socket.url".build; |
14 local async = require "util.async"; | 14 local async = require "util.async"; |
15 local http = require"net.http"; | 15 local http = require "net.http"; |
16 | 16 |
17 local cache = require "util.cache".new(100); | 17 local cache = require "util.cache".new(100); |
18 | 18 |
19 local hash_order = { "sha-512", "sha-384", "sha-256", "sha-224", "sha-1" }; | 19 local hash_order = { "sha-512", "sha-384", "sha-256", "sha-224", "sha-1" }; |
20 local hash_funcs = { hashes.sha512, hashes.sha384, hashes.sha256, hashes.sha224, hashes.sha1 }; | 20 local hash_funcs = { hashes.sha512, hashes.sha384, hashes.sha256, hashes.sha224, hashes.sha1 }; |
44 log("debug", "Session direction: %s", tostring(host_session.direction)); | 44 log("debug", "Session direction: %s", tostring(host_session.direction)); |
45 | 45 |
46 local url = build_url { scheme = "https", host = target_host, path = "/.well-known/posh/xmpp-server.json" }; | 46 local url = build_url { scheme = "https", host = target_host, path = "/.well-known/posh/xmpp-server.json" }; |
47 | 47 |
48 log("debug", "Request POSH information for %s", tostring(target_host)); | 48 log("debug", "Request POSH information for %s", tostring(target_host)); |
49 http.request(url, nil, function(response, code) | 49 http.request(url, nil, function (response, code) |
50 if code ~= 200 then | 50 if code ~= 200 then |
51 log("debug", "No or invalid POSH response received"); | 51 log("debug", "No or invalid POSH response received"); |
52 resume(); | 52 resume(); |
53 return; | 53 return; |
54 end | 54 end |
67 end) | 67 end) |
68 return true; | 68 return true; |
69 end | 69 end |
70 | 70 |
71 -- Do POSH authentication | 71 -- Do POSH authentication |
72 module:hook("s2s-check-certificate", function(event) | 72 module:hook("s2s-check-certificate", function (event) |
73 local session, cert = event.session, event.cert; | 73 local session, cert = event.session, event.cert; |
74 local log = session.log or module._log; | 74 local log = session.log or module._log; |
75 if session.cert_identity_status == "valid" then | 75 if session.cert_identity_status == "valid" then |
76 log("debug", "Not trying POSH because certificate is already valid"); | 76 log("debug", "Not trying POSH because certificate is already valid"); |
77 return; | 77 return; |