From 02dbe39b067bcff5ad2c2b09b254a57351a6ab84 Mon Sep 17 00:00:00 2001 From: Konstantinos Kallas Date: Tue, 9 May 2017 23:27:37 +0300 Subject: [PATCH] Examining jose functionality --- rebar.config | 1 + run_acme.sh | 7 ++++++- src/mod_acme.erl | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/rebar.config b/rebar.config index b553931e6..5d5bf98a1 100644 --- a/rebar.config +++ b/rebar.config @@ -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", diff --git a/run_acme.sh b/run_acme.sh index 400ee04ac..c07204a07 100755 --- a/run_acme.sh +++ b/run_acme.sh @@ -1,3 +1,8 @@ #!/bin/bash -erl -pa ebin deps/jiffy/ebin deps/fast_tls/ebin -noshell -s mod_acme scenario -s erlang halt \ No newline at end of file +erl -pa ebin \ +deps/jiffy/ebin \ +deps/fast_tls/ebin \ +deps/jose/ebin \ +deps/base64url/ebin \ +-noshell -s mod_acme scenario -s erlang halt \ No newline at end of file diff --git a/src/mod_acme.erl b/src/mod_acme.erl index 984744dde..292cafbcb 100644 --- a/src/mod_acme.erl +++ b/src/mod_acme.erl @@ -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]),