问题描述
我有一个聊天交流应用程序。 如果用户的唯一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,3) of
<<"=2C">> ->
<<Start/binary,",(unescape_username(str:substr(End,4)))/binary>>;
<<"=3D">> ->
<<Start/binary,"=",4)))/binary>>;
_Else -> error
end
end
end.
我不知道为什么要这样写。如果删除此特定代码,则连接工作正常。请让我知道为什么要限制它。
解决方法
如果用户的唯一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
无论出于什么原因,这显然都是一个很好的理由。