27
27
-include (" scram.hrl" ).
28
28
29
29
-type password () :: binary () | # scram {}.
30
- -type get_password_fun () :: fun ((binary ()) -> {false | {false , atom (), binary ()} | password (), module ()}).
30
+ -type get_password_fun () :: fun ((binary ()) -> {false | {false , atom (), binary ()} | password () | [ password ()] , module ()}).
31
31
32
32
-record (state ,
33
33
{step = 2 :: 2 | 4 ,
@@ -124,10 +124,21 @@ mech_step(#state{step = 2, algo = Algo, ssdp = Ssdp} = State, ClientIn) ->
124
124
case parse_attribute (ClientNonceAttribute ) of
125
125
{$r , ClientNonce } ->
126
126
{Pass , AuthModule } = (State # state .get_password )(UserName ),
127
- LPass = if is_binary (Pass ) -> jid :resourceprep (Pass );
128
- true -> Pass
127
+ Pass2 = case Pass of
128
+ Bin when is_binary (Bin ) -> Bin ;
129
+ List when is_list (List ) ->
130
+ lists :foldl (
131
+ fun (# scram {hash = Hash } = S , _ ) when Algo == Hash ->
132
+ S ;
133
+ (Bin2 , false ) when is_binary (Bin2 ) -> Bin2 ;
134
+ (_ , Acc ) -> Acc
135
+ end , false , List );
136
+ Other -> Other
129
137
end ,
130
- case Pass of
138
+ LPass = if is_binary (Pass2 ) -> jid :resourceprep (Pass2 );
139
+ true -> Pass2
140
+ end ,
141
+ case Pass2 of
131
142
{false , Condition , Text } ->
132
143
{error , {Condition , Text }, UserName };
133
144
false ->
@@ -138,7 +149,7 @@ mech_step(#state{step = 2, algo = Algo, ssdp = Ssdp} = State, ClientIn) ->
138
149
{error , saslprep_failed , UserName };
139
150
_ ->
140
151
{StoredKey , ServerKey , Salt , IterationCount } =
141
- case Pass of
152
+ case Pass2 of
142
153
# scram {storedkey = STK , serverkey = SEK , salt = Slt ,
143
154
iterationcount = IC } ->
144
155
{base64 :decode (STK ),
@@ -148,7 +159,7 @@ mech_step(#state{step = 2, algo = Algo, ssdp = Ssdp} = State, ClientIn) ->
148
159
TempSalt =
149
160
p1_rand :bytes (? SALT_LENGTH ),
150
161
SaltedPassword =
151
- scram :salted_password (Algo , Pass ,
162
+ scram :salted_password (Algo , Pass2 ,
152
163
TempSalt ,
153
164
? SCRAM_DEFAULT_ITERATION_COUNT ),
154
165
{scram :stored_key (Algo , scram :client_key (Algo , SaltedPassword )),
0 commit comments