Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ otp_release:
- 17.5
- 18.3
- 19.2
- 23.3
- 24.3
19 changes: 16 additions & 3 deletions src/radius_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-export([encode_response/3, encode_attributes/1]).
-export([encode_request/2]).

-compile(export_all).
%%-compile(export_all).

-include("radius.hrl").

Expand All @@ -30,7 +30,7 @@ decode_packet(Bin, Secret) ->
A1 = lists:keyreplace("Message-Authenticator", 1, A, {"Message-Authenticator", <<0:128>>}),
{ok, A2} = encode_attributes(A1),
Packet1 = [Code, Ident, <<Length:16>>, Auth, A2],
case crypto:hmac(md5, Secret, Packet1) =:= Value of
case hmac(Secret, Packet1) =:= Value of
true ->
{ok, Packet};
false ->
Expand Down Expand Up @@ -118,7 +118,7 @@ encode_response(Request, Response, Secret) ->

Length = <<(20 + byte_size(A2)):16>>,
Packet = list_to_binary([Code, Ident, Length, ReqAuth, A2]),
MA = crypto:hmac(md5, Secret, Packet),
MA = hmac(Secret, Packet),

A3 = A ++ [{"Message-Authenticator", MA}],
{ok, A4} = encode_attributes(A3),
Expand Down Expand Up @@ -292,3 +292,16 @@ lookup_value(Code, Name, Attrs) ->
false -> undefined
end
end.

-ifdef(OTP_RELEASE).
-if(?OTP_RELEASE >= 23).
hmac(Key, Str) ->
crypto:mac(hmac, md5, Key, Str).
-else.
hmac(Key, Str) ->
crypto:hmac(md5, Key, Str).
-endif.
-else.
hmac(Key, Str) ->
crypto:hmac(md5, Key, Str).
-endif.