Software /
code /
prosody-modules
Comparison
mod_sasl2_bind2/mod_sasl2_bind2.lua @ 5047:023f21bfcc08
mod_sasl2_bind2: Generate resource from client tag if provided
This follows the updated advice in the latest XEP-0386 proposal.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 22 Sep 2022 16:43:51 +0100 |
parent | 5046:904dde7be981 |
child | 5060:bc491065c221 |
comparison
equal
deleted
inserted
replaced
5046:904dde7be981 | 5047:023f21bfcc08 |
---|---|
1 local base64 = require "util.encodings".base64; | 1 local base64 = require "util.encodings".base64; |
2 local id = require "util.id"; | |
2 local sha1 = require "util.hashes".sha1; | 3 local sha1 = require "util.hashes".sha1; |
3 local st = require "util.stanza"; | 4 local st = require "util.stanza"; |
4 | 5 |
5 local sm_bind_resource = require "core.sessionmanager".bind_resource; | 6 local sm_bind_resource = require "core.sessionmanager".bind_resource; |
6 | 7 |
21 -- Helper to actually bind a resource to a session | 22 -- Helper to actually bind a resource to a session |
22 | 23 |
23 local function do_bind(session, bind_request) | 24 local function do_bind(session, bind_request) |
24 local resource; | 25 local resource; |
25 | 26 |
26 local client_id_tag = bind_request:get_child("client-id"); | 27 local client_name_tag = bind_request:get_child_text("tag"); |
27 local client_id = client_id_tag and client_id_tag:get_text() or session.client_id; | 28 if client_name_tag then |
28 if client_id and client_id ~= "" then | 29 local client_id = session.client_id; |
29 local tag = client_id_tag and client_id_tag.attr.tag or "client"; | 30 local tag_suffix = client_id and base64.encode(sha1(client_id):sub(1, 9)) or id.medium(); |
30 resource = ("%s~%s"):format(tag, base64.encode(sha1(client_id):sub(1, 9))); | 31 resource = ("%s~%s"):format(client_name_tag, tag_suffix); |
31 end | 32 end |
32 | 33 |
33 local success, err_type, err, err_msg = sm_bind_resource(session, resource); | 34 local success, err_type, err, err_msg = sm_bind_resource(session, resource); |
34 if not success then | 35 if not success then |
35 session.log("debug", "Resource bind failed: %s", err_msg or err); | 36 session.log("debug", "Resource bind failed: %s", err_msg or err); |