【问题标题】:Why cyrsasl_scram mechanism is not allowing base64 GUID?为什么 cyrsasl_scram 机制不允许 base64 GUID?
【发布时间】:2021-01-04 07:20:32
【问题描述】:

我正在编写一个聊天通讯应用程序。 如果用户的唯一 id 以 Base 64 GUID 格式给出,则会抛出 bad_username 错误。

在这个文件中:https://pow.gs/mirror/ejabberd/-/blob/fd8e07af4789be362a61755ea47f216baeb64989/src/cyrsasl_scram.erl,有一种方法可以从用户名中删除==

unescape_username(<<"">>) -> <<"">>;
unescape_username(EscapedUsername) ->
    Pos = str:str(EscapedUsername, <<"=">>),
    if Pos == 0 -> EscapedUsername;
       true ->
       Start = str:substr(EscapedUsername, 1, Pos - 1),
       End = str:substr(EscapedUsername, Pos),
       EndLen = byte_size(End),
       if EndLen < 3 -> error;
          true ->
          case str:substr(End, 1, 3) of
            <<"=2C">> ->
            <<Start/binary, ",",
              (unescape_username(str:substr(End, 4)))/binary>>;
            <<"=3D">> ->
            <<Start/binary, "=",
              (unescape_username(str:substr(End, 4)))/binary>>;
            _Else -> error
          end
       end
    end.

我不知道为什么要写这个。如果我删除此特定代码,则连接工作正常。请告诉我为什么它被限制。

【问题讨论】:

    标签: erlang ejabberd sasl ejabberd-saas


    【解决方案1】:

    如果用户的唯一 ID 以 Base 64 GUID 格式给出,则会抛出 bad_username 错误。

    对:

     call xmpp_sasl_scram:unescape_username(<<"user1">>)
     returned from xmpp_sasl_scram:unescape_username/1 -> <<"user1">>
    
     call xmpp_sasl_scram:unescape_username(<<"user3==ABC">>)
     returned from xmpp_sasl_scram:unescape_username/1 -> error
    
     call xmpp_sasl_scram:unescape_username(<<"user4=DEF">>)
     returned from xmpp_sasl_scram:unescape_username/1 -> error
    
     call xmpp_sasl_scram:unescape_username(<<"user5=">>)
     returned from xmpp_sasl_scram:unescape_username/1 -> error
    

    我不知道为什么要写这个。如果我删除此特定代码,则连接工作正常。请告诉我为什么它被限制。

    我也不知道。但该代码自九年前就存在: https://github.com/processone/ejabberd/commit/e80b92b48148505b44c6a378db36badfe60fce79#diff-5c51943c1268ffe26fe3b041b20675c6R136

    不管有什么理由,这显然是一个很好的理由。

    【讨论】:

    • 解决方案是什么?我们应该限制它吗?
    • tools.ietf.org/html/rfc5802#section-5.1 说:用户名中的字符 ',' 或 '=' 分别作为 '=2C' 和 '=3D' 发送....但是用户名在 XMPP 中是小写的,所以大写字母将变为小写。
    猜你喜欢
    • 2019-01-21
    • 2020-11-24
    • 2021-07-18
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多