Software /
code /
prosody-modules
Diff
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 |
line wrap: on
line diff
--- a/mod_sasl2_bind2/mod_sasl2_bind2.lua Thu Sep 22 16:37:59 2022 +0100 +++ b/mod_sasl2_bind2/mod_sasl2_bind2.lua Thu Sep 22 16:43:51 2022 +0100 @@ -1,4 +1,5 @@ local base64 = require "util.encodings".base64; +local id = require "util.id"; local sha1 = require "util.hashes".sha1; local st = require "util.stanza"; @@ -23,11 +24,11 @@ local function do_bind(session, bind_request) local resource; - local client_id_tag = bind_request:get_child("client-id"); - local client_id = client_id_tag and client_id_tag:get_text() or session.client_id; - if client_id and client_id ~= "" then - local tag = client_id_tag and client_id_tag.attr.tag or "client"; - resource = ("%s~%s"):format(tag, base64.encode(sha1(client_id):sub(1, 9))); + local client_name_tag = bind_request:get_child_text("tag"); + if client_name_tag then + local client_id = session.client_id; + local tag_suffix = client_id and base64.encode(sha1(client_id):sub(1, 9)) or id.medium(); + resource = ("%s~%s"):format(client_name_tag, tag_suffix); end local success, err_type, err, err_msg = sm_bind_resource(session, resource);