25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-10-09 15:06:54 +02:00

Added support for all hash functions required by XEP-0115

This commit is contained in:
Evgeniy Khramtsov 2010-06-22 03:10:41 +10:00
parent 49dd83e731
commit f66f049ef3

View File

@ -277,10 +277,20 @@ feature_response(#iq{type = result,
Host, From, Caps, [SubNode | SubNodes]) ->
BinaryNode = node_to_binary(Caps#caps.node, SubNode),
IsValid = case Caps#caps.hash of
"sha-1" ->
Caps#caps.version == make_disco_hash(Els, sha1);
"md2" ->
Caps#caps.version == make_disco_hash(Els, md2);
"md5" ->
Caps#caps.version == make_disco_hash(Els, md5);
"sha-1" ->
Caps#caps.version == make_disco_hash(Els, sha1);
"sha-224" ->
Caps#caps.version == make_disco_hash(Els, sha224);
"sha-256" ->
Caps#caps.version == make_disco_hash(Els, sha256);
"sha-384" ->
Caps#caps.version == make_disco_hash(Els, sha384);
"sha-512" ->
Caps#caps.version == make_disco_hash(Els, sha512);
_ ->
true
end,
@ -339,15 +349,25 @@ make_my_disco_hash(Host) ->
""
end.
make_disco_hash(DiscoEls, Algo) when Algo == sha1; Algo == md5 ->
make_disco_hash(DiscoEls, Algo) ->
Concat = [concat_identities(DiscoEls),
concat_features(DiscoEls),
concat_info(DiscoEls)],
base64:encode_to_string(
if Algo == sha1 ->
crypto:sha(Concat);
if Algo == md2 ->
sha:md2(Concat);
Algo == md5 ->
crypto:md5(Concat)
crypto:md5(Concat);
Algo == sha1 ->
crypto:sha(Concat);
Algo == sha224 ->
sha:sha224(Concat);
Algo == sha256 ->
sha:sha256(Concat);
Algo == sha384 ->
sha:sha384(Concat);
Algo == sha512 ->
sha:sha512(Concat)
end).
concat_features(Els) ->