summaryrefslogtreecommitdiff
path: root/src/signing.erl
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2015-03-02 19:15:09 +0100
committerMagnus Ahltorp <map@kth.se>2015-03-02 19:15:31 +0100
commit9eaa1ef1b558043b809fd7c7f869128c186ec0e9 (patch)
treece2e59b845248e016e709ed01ca5ce1f3e1a4b27 /src/signing.erl
parent35a43b7b1951fdb45e2367122a3928ddba49c894 (diff)
Implement external signing
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)}.