summaryrefslogtreecommitdiff
path: root/src/signing.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/signing.erl')
-rw-r--r--src/signing.erl42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/signing.erl b/src/signing.erl
new file mode 100644
index 0000000..707b18e
--- /dev/null
+++ b/src/signing.erl
@@ -0,0 +1,42 @@
+%%% Copyright (c) 2014, NORDUnet A/S.
+%%% See LICENSE for licensing information.
+
+%%% @doc Signing node API
+
+-module(signing).
+%% API (URL)
+-export([request/3]).
+
+request(post, "ct/signing/sct", Input) ->
+ case (catch mochijson2:decode(Input)) of
+ {error, E} ->
+ html("sendentry: bad input:", E);
+ {struct, PropList} ->
+ Data = base64:decode(proplists:get_value(<<"data">>, PropList)),
+
+ Result = sign:sign_sct(Data),
+ success({[{result, base64:encode(Result)}]})
+ end;
+request(post, "ct/signing/sth", Input) ->
+ case (catch mochijson2:decode(Input)) of
+ {error, E} ->
+ html("sendentry: bad input:", E);
+ {struct, PropList} ->
+ Data = base64:decode(proplists:get_value(<<"data">>, PropList)),
+
+ Result = sign:sign_sth(Data),
+ success({[{result, base64:encode(Result)}]})
+ end.
+
+%% Private functions.
+html(Text, Input) ->
+ {400, [{"Content-Type", "text/html"}],
+ io_lib:format(
+ "<html><body><p>~n" ++
+ "~s~n" ++
+ "~p~n" ++
+ "</body></html>~n", [Text, Input])}.
+
+success(Data) ->
+ lager:debug("returning ~p", [Data]),
+ {200, [{"Content-Type", "text/json"}], mochijson2:encode(Data)}.