mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 01:39:35 +02:00
Derive the alg field of the JWS object using a erlang-jose library function rather than hardcoding
This commit is contained in:
parent
4fc3d511ce
commit
133d2ae6d5
1 changed files with 10 additions and 8 deletions
|
@ -252,14 +252,16 @@ sign_json_jose(Key, Json, Nonce) ->
|
||||||
{_, BinaryPubKey} = jose_jwk:to_binary(PubKey),
|
{_, BinaryPubKey} = jose_jwk:to_binary(PubKey),
|
||||||
% ?INFO_MSG("Key Record: ~p", [jose_jwk:to_map(Key)]),
|
% ?INFO_MSG("Key Record: ~p", [jose_jwk:to_map(Key)]),
|
||||||
PubKeyJson = jiffy:decode(BinaryPubKey),
|
PubKeyJson = jiffy:decode(BinaryPubKey),
|
||||||
% Jws object containing the algorithm
|
%% TODO: Ensure this works for all cases
|
||||||
%% TODO: Dont hardcode the alg
|
AlgMap = jose_jwk:signer(Key),
|
||||||
JwsObj = jose_jws:from(
|
% ?INFO_MSG("Algorithm:~p~n", [AlgMap]),
|
||||||
#{ <<"alg">> => <<"ES256">>
|
JwsMap =
|
||||||
|
#{ <<"jwk">> => PubKeyJson
|
||||||
% , <<"b64">> => true
|
% , <<"b64">> => true
|
||||||
, <<"jwk">> => PubKeyJson
|
|
||||||
, <<"nonce">> => list_to_bitstring(Nonce)
|
, <<"nonce">> => list_to_bitstring(Nonce)
|
||||||
}),
|
},
|
||||||
|
JwsObj0 = maps:merge(JwsMap, AlgMap),
|
||||||
|
JwsObj = jose_jws:from(JwsObj0),
|
||||||
%% Signed Message
|
%% Signed Message
|
||||||
jose_jws:sign(Key, Json, JwsObj).
|
jose_jws:sign(Key, Json, JwsObj).
|
||||||
|
|
||||||
|
@ -388,7 +390,7 @@ generate_key() ->
|
||||||
%% Just a test
|
%% Just a test
|
||||||
scenario0(KeyFile) ->
|
scenario0(KeyFile) ->
|
||||||
PrivateKey = jose_jwk:from_file(KeyFile),
|
PrivateKey = jose_jwk:from_file(KeyFile),
|
||||||
% scenario("http://localhost:4000", "2", PrivateKey).
|
scenario("http://localhost:4000", "2", PrivateKey).
|
||||||
new_user_scenario("http://localhost:4000").
|
% new_user_scenario("http://localhost:4000").
|
||||||
|
|
||||||
% ejabberd_acme:scenario0("/home/konstantinos/Desktop/Programming/ejabberd/private_key_temporary").
|
% ejabberd_acme:scenario0("/home/konstantinos/Desktop/Programming/ejabberd/private_key_temporary").
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue