Annotate

mod_jid_prep/mod_jid_prep.lua @ 5193:2bb29ece216b

mod_http_oauth2: Implement stateless dynamic client registration Replaces previous explicit registration that required either the additional module mod_adhoc_oauth2_client or manually editing the database. That method was enough to have something to test with, but would not probably not scale easily. Dynamic client registration allows creating clients on the fly, which may be even easier in theory. In order to not allow basically unauthenticated writes to the database, we implement a stateless model here. per_host_key := HMAC(config -> oauth2_registration_key, hostname) client_id := JWT { client metadata } signed with per_host_key client_secret := HMAC(per_host_key, client_id) This should ensure everything we need to know is part of the client_id, allowing redirects etc to be validated, and the client_secret can be validated with only the client_id and the per_host_key. A nonce injected into the client_id JWT should ensure nobody can submit the same client metadata and retrieve the same client_secret
author Kim Alvefur <zash@zash.se>
date Fri, 03 Mar 2023 21:14:19 +0100
parent 1404:99cb06b31ae8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1003
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- Run JIDs through stringprep processing on behalf of clients
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 -- http://xmpp.org/extensions/inbox/jidprep.html
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local jid_prep = require "util.jid".prep;
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local st = require "util.stanza";
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6
1404
99cb06b31ae8 mod_jid_prep: Update to version 0.1; advertise feature and change :tmp to :0 in namespace
Kim Alvefur <zash@zash.se>
parents: 1003
diff changeset
7 local xmlns_prep = "urn:xmpp:jidprep:0";
99cb06b31ae8 mod_jid_prep: Update to version 0.1; advertise feature and change :tmp to :0 in namespace
Kim Alvefur <zash@zash.se>
parents: 1003
diff changeset
8
99cb06b31ae8 mod_jid_prep: Update to version 0.1; advertise feature and change :tmp to :0 in namespace
Kim Alvefur <zash@zash.se>
parents: 1003
diff changeset
9 module:add_feature(xmlns_prep);
1003
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 function prep_jid(event)
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local stanza = event.stanza;
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local jid = jid_prep(stanza:get_child_text("jid", xmlns_prep));
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 if not jid then
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 return event.origin.send(st.error_reply(stanza, "modify", "jid-malformed"));
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 end
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 return event.origin.send(st.reply(stanza):tag("jid", { xmlns = xmlns_prep }):text(jid));
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 end
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 module:hook("iq/host/"..xmlns_prep..":jid", prep_jid);
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 module:depends("http");
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 module:provides("http", {
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 route = {
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 ["GET /*"] = function (event, jid)
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 return jid_prep(jid) or 400;
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 end;
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 }
767999c39f0a mod_jid_prep: Implement the JID prep protocol in the XEP submitted 5 minutes ago...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 });