Fix SASL auth error conditions

This commit is contained in:
Badlop 2011-09-05 16:29:30 +02:00
parent fed00a0c17
commit d6d3190b47
3 changed files with 15 additions and 15 deletions

View File

@ -91,7 +91,7 @@ mech_step(#state{step = 1, nonce = Nonce} = State, _) ->
mech_step(#state{step = 3, nonce = Nonce} = State, ClientIn) -> mech_step(#state{step = 3, nonce = Nonce} = State, ClientIn) ->
case parse(ClientIn) of case parse(ClientIn) of
bad -> bad ->
{error, 'bad-protocol'}; {error, 'malformed-request'};
KeyVals -> KeyVals ->
DigestURI = proplists:get_value("digest-uri", KeyVals, ""), DigestURI = proplists:get_value("digest-uri", KeyVals, ""),
UserName = proplists:get_value("username", KeyVals, ""), UserName = proplists:get_value("username", KeyVals, ""),
@ -136,7 +136,7 @@ mech_step(#state{step = 5,
{auth_module, AuthModule}]}; {auth_module, AuthModule}]};
mech_step(A, B) -> mech_step(A, B) ->
?DEBUG("SASL DIGEST: A ~p B ~p", [A,B]), ?DEBUG("SASL DIGEST: A ~p B ~p", [A,B]),
{error, 'bad-protocol'}. {error, 'malformed-request'}.
%% @spec (S) -> [{Key, Value}] | bad %% @spec (S) -> [{Key, Value}] | bad
%% S = string() %% S = string()

View File

@ -77,7 +77,7 @@ mech_step(State, ClientIn) ->
{error, 'not-authorized', "", User} {error, 'not-authorized', "", User}
end; end;
_ -> _ ->
{error, 'bad-protocol'} {error, 'malformed-request'}
end. end.
prepare(ClientIn) -> prepare(ClientIn) ->

View File

@ -61,7 +61,7 @@ mech_step(#state{step = 2} = State, ClientIn) ->
{_, EscapedUserName} -> {_, EscapedUserName} ->
case unescape_username(EscapedUserName) of case unescape_username(EscapedUserName) of
error -> error ->
{error, 'protocol-error-bad-username'}; {error, 'malformed-request', "Error in username encoding", EscapedUserName};
UserName -> UserName ->
case parse_attribute(ClientNonceAttribute) of case parse_attribute(ClientNonceAttribute) of
{$r, ClientNonce} -> {$r, ClientNonce} ->
@ -90,12 +90,12 @@ mech_step(#state{step = 2} = State, ClientIn) ->
client_nonce = ClientNonce, server_nonce = ServerNonce, username = UserName}} client_nonce = ClientNonce, server_nonce = ServerNonce, username = UserName}}
end; end;
_Else -> _Else ->
{error, 'not-supported'} {error, 'malformed-request'}
end end
end end
end; end;
_Else -> _Else ->
{error, 'bad-protocol'} {error, 'malformed-request'}
end; end;
mech_step(#state{step = 4} = State, ClientIn) -> mech_step(#state{step = 4} = State, ClientIn) ->
case string:tokens(ClientIn, ",") of case string:tokens(ClientIn, ",") of
@ -118,21 +118,21 @@ mech_step(#state{step = 4} = State, ClientIn) ->
ServerSignature = scram:server_signature(State#state.server_key, AuthMessage), ServerSignature = scram:server_signature(State#state.server_key, AuthMessage),
{ok, [{username, State#state.username}], "v=" ++ base64:encode_to_string(ServerSignature)}; {ok, [{username, State#state.username}], "v=" ++ base64:encode_to_string(ServerSignature)};
true -> true ->
{error, 'bad-auth'} {error, 'not-authorized', "", State#state.username}
end; end;
_Else -> _Else ->
{error, 'bad-protocol'} {error, 'malformed-request', "Bad protocol", State#state.username}
end; end;
{$r, _} -> {$r, _} ->
{error, 'bad-nonce'}; {error, 'malformed-request', "Bad nonce", State#state.username};
_Else -> _Else ->
{error, 'bad-protocol'} {error, 'malformed-request', "Bad protocol", State#state.username}
end; end;
_Else -> _Else ->
{error, 'bad-protocol'} {error, 'malformed-request', "Bad protocol", State#state.username}
end; end;
_Else -> _Else ->
{error, 'bad-protocol'} {error, 'malformed-request', "Bad protocol", State#state.username}
end. end.
parse_attribute(Attribute) -> parse_attribute(Attribute) ->
@ -147,13 +147,13 @@ parse_attribute(Attribute) ->
String = string:substr(Attribute, 3), String = string:substr(Attribute, 3),
{lists:nth(1, Attribute), String}; {lists:nth(1, Attribute), String};
true -> true ->
{error, 'bad-format second char not equal sign'} {error, 'malformed-request', "Second char not equal sign", ""}
end; end;
_Else -> _Else ->
{error, 'bad-format first char not a letter'} {error, 'malformed-request', "First char not a letter", ""}
end; end;
true -> true ->
{error, 'bad-format attribute too short'} {error, 'malformed-request', "Attribute too short", ""}
end. end.
unescape_username("") -> unescape_username("") ->