Handle the case when JWT key file contains JWK set

This commit is contained in:
Alexey Shchepin 2019-10-25 16:33:11 +03:00
parent 7eda35b945
commit c7470f5107
2 changed files with 11 additions and 1 deletions

View File

@ -162,6 +162,8 @@ format_error({bad_cert, Why, Path}) ->
format_error({bad_pem, Why, Path});
format_error({bad_jwt_key, Path}) ->
format("No valid JWT key found in file: ~ts", [Path]);
format_error({bad_jwt_key_set, Path}) ->
format("JWT key contains JWK set in file: ~ts", [Path]);
format_error({bad_jid, Bad}) ->
format("Invalid XMPP address: ~ts", [Bad]);
format_error({bad_user, Bad}) ->

View File

@ -407,7 +407,15 @@ opt_type(jwt_key) ->
{ok, Data} ->
try jose_jwk:from_binary(Data) of
{error, _} -> econf:fail({bad_jwt_key, Path});
Ret -> Ret
JWK ->
case jose_jwk:to_map(JWK) of
{_, #{<<"keys">> := [Key]}} ->
jose_jwk:from_map(Key);
{_, #{<<"keys">> := _}} ->
econf:fail({bad_jwt_key_set, Path});
_ ->
JWK
end
catch _:_ ->
econf:fail({bad_jwt_key, Path})
end;