Mercurial > prosody-hg
annotate plugins/mod_http_altconnect.lua @ 14218:926f25af2ffe 13.0
util.tlsref: New util library to encapsulate the Mozilla/TLSRef recommendations
Previously we embedded this data directly into core.certmanager. This splits
it out, for various benefits:
- Removes data from the business logic (the config parsing is complex enough
as it is)
- Allows easier testing and tracking of the data (this commit adds various
consistency checks, so that we can have more confidence in future updates
to the data not breaking stuff)
This library also supports multiple versions of the recommendations.
Previously we picked a single version, and put that into certmanager. But this
meant we had to make choices for our users, and one of the choices is between
advancing security standards and ensuring we don't break connectivity for
people doing minor upgrades (deterring people from performing minor upgrades
would have a security impact too).
This library supports the concept of a "default" and a "latest" version, so we
are now free to add new versions into stable releases, and admins can pick
between compatibility and security.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 12 Jun 2026 13:01:56 +0100 |
| parents | 569fae28a2f3 |
| children |
| rev | line source |
|---|---|
|
13718
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- mod_http_altconnect |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- XEP-0156: Discovering Alternative XMPP Connection Methods |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 module:depends"http"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local mm = require "prosody.core.modulemanager"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local json = require"prosody.util.json"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local st = require"prosody.util.stanza"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local array = require"prosody.util.array"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local advertise_bosh = module:get_option_boolean("advertise_bosh", true); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local advertise_websocket = module:get_option_boolean("advertise_websocket", true); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local function get_supported() |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local uris = array(); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 if advertise_bosh and (mm.is_loaded(module.host, "bosh") or mm.is_loaded("*", "bosh")) then |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 uris:push({ rel = "urn:xmpp:alt-connections:xbosh", href = module:http_url("bosh", "/http-bind") }); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 end |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 if advertise_websocket and (mm.is_loaded(module.host, "websocket") or mm.is_loaded("*", "websocket")) then |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 uris:push({ rel = "urn:xmpp:alt-connections:websocket", href = module:http_url("websocket", "xmpp-websocket"):gsub("^http", "ws") }); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 end |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 return uris; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 end |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 local function GET_xml(event) |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 local response = event.response; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 local xrd = st.stanza("XRD", { xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0' }); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 local uris = get_supported(); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 for _, method in ipairs(uris) do |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 xrd:tag("Link", method):up(); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 end |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 response.headers.content_type = "application/xrd+xml" |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 response.headers.access_control_allow_origin = "*"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 return '<?xml version="1.0" encoding="UTF-8"?>' .. tostring(xrd); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 end |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 local function GET_json(event) |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 local response = event.response; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 local jrd = { links = get_supported() }; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 response.headers.content_type = "application/json" |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 response.headers.access_control_allow_origin = "*"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 return json.encode(jrd); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 module:provides("http", { |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 default_path = "/.well-known"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 route = { |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 ["GET /host-meta"] = GET_xml; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 ["GET /host-meta.json"] = GET_json; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 }; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 }); |
