25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Examining jose functionality

This commit is contained in:
Konstantinos Kallas 2017-05-09 23:27:37 +03:00
parent 67a00939db
commit 02dbe39b06
3 changed files with 35 additions and 1 deletions

View File

@ -31,6 +31,7 @@
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.1"}}},
{luerl, ".*", {git, "https://github.com/rvirding/luerl", {tag, "v0.2"}}},
{jose, ".*", {git, "git://github.com/potatosalad/erlang-jose.git", {branch, "master"}}},
{if_var_true, mysql, {p1_mysql, ".*", {git, "https://github.com/processone/p1_mysql",
"31e035b"}}},
{if_var_true, pgsql, {p1_pgsql, ".*", {git, "https://github.com/processone/p1_pgsql",

View File

@ -1,3 +1,8 @@
#!/bin/bash
erl -pa ebin deps/jiffy/ebin deps/fast_tls/ebin -noshell -s mod_acme scenario -s erlang halt
erl -pa ebin \
deps/jiffy/ebin \
deps/fast_tls/ebin \
deps/jose/ebin \
deps/base64url/ebin \
-noshell -s mod_acme scenario -s erlang halt

View File

@ -108,6 +108,10 @@ init([]) ->
ok = application:start(asn1),
ok = application:start(public_key),
ok = application:start(ssl),
ok = application:start(base64url),
ok = application:start(jose),
{ok, #state{}}.
handle_call(directory, _From, S = #state{dir_url=Url, dirs=Dirs}) ->
@ -139,6 +143,9 @@ handle_call(new_account, _From, S = #state{ca_url = Ca, dirs=Dirs}) ->
%% Make the request body
ReqBody = jiffy:encode({[]}),
%% Jose
% SignedBody = sign_a_json_object_using_jose(ReqBody),
{ok, {Status, Head, Body}} =
httpc:request(post, {Url, [], "application/jose+json", ReqBody}, [], []),
{reply, {ok, {Status, Head, Body}}, S};
@ -168,6 +175,27 @@ final_url(Urls) ->
%% Test
sign_a_json_object_using_jose(Json) ->
% Generate a key for now
Key = jose_jwk:generate_key({okp, 'Ed448'}),
io:format("Key: ~p~n", [Key]),
% Jws object containing the algorithm
JwsObj = jose_jws:from(#{<<"alg">> => <<"Ed448">>}),
io:format("Jws: ~p~n", [JwsObj]),
%% Signed Message
Signed = jose_jws:sign(Key, Json, JwsObj),
io:format("Signed: ~p~n", [Signed]),
%% Compact Message
Compact = jose_jws:compact(Signed),
io:format("Compact: ~p~n", [Compact]),
%% Verify
io:format("Verify: ~p~n", [jose_jws:verify(Key, Signed)]),
Signed.
scenario() ->
{ok, Pid} = start(),
io:format("Server started: ~p~n", [Pid]),