summaryrefslogtreecommitdiff
path: root/src/v1.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/v1.erl')
-rw-r--r--src/v1.erl52
1 files changed, 21 insertions, 31 deletions
diff --git a/src/v1.erl b/src/v1.erl
index ef9aadd..72d0112 100644
--- a/src/v1.erl
+++ b/src/v1.erl
@@ -30,9 +30,9 @@ check_valid_sth() ->
end.
%% Public functions, i.e. part of URL.
-request(post, ?APPURL_CT_V1, "add-ds-rr", Input) ->
+request(post, ?APPURL_CT_V1, "add-rr-chain", Input) ->
check_valid_sth(),
- add_ds(Input);
+ add_rr_chain(Input);
request(get, ?APPURL_CT_V1, "get-sth", _Query) ->
check_valid_sth(),
@@ -147,37 +147,27 @@ internalerror(Text) ->
"~s~n" ++
"</body></html>~n", [Text])}.
--spec add_ds(any()) -> any().
-add_ds(Input) ->
+-spec add_rr_chain(any()) -> any().
+add_rr_chain(Input) ->
case (catch mochijson2:decode(Input)) of
{error, E} ->
- err400("add-ds-rr: bad input:", E);
- {struct, [{<<"chain">>, List}]} ->
- case decode_chain(List) of
- {invalid, ErrText} ->
- err400(io:format("add-ds-rr: ~p", [ErrText]), List);
- Data when is_list(Data) ->
- add_ds_helper(Data);
- _ ->
- err400("add-ds-rr: missing one or more entries", List)
+ err400("add-rr-chain: bad input:", E);
+ {struct, [{<<"chain">>, B64}]} ->
+ case (catch base64:decode(B64)) of
+ {'EXIT', _} ->
+ err400("add-rr-chain: invalid base64-encoding:", B64);
+ Data ->
+ case dnssecport:validate(Data) of
+ {ok, [DS | Chain]} ->
+ lager:debug("succesful DNSSEC validation"),
+ success(catlfish:add_chain(DS, Chain, normal));
+ {error, ErrorCode} ->
+ err400(io_lib:format(
+ "add-rr-chain: invalid DS record: ~p",
+ [ErrorCode]),
+ Data)
+ end
end;
_ ->
- err400("add-ds-rr: missing input: chain", Input)
- end.
-
-decode_chain(List) ->
- case (catch [base64:decode(X) || X <- List]) of
- {'EXIT', _} ->
- {invalid, "invalid base64-encoding"};
- L ->
- L
- end.
-
-add_ds_helper(Data) ->
- case dnssecport:validate(Data) of
- {ok, [DS | Chain]} ->
- success(catlfish:add_chain(DS, Chain, normal));
- {error, ErrorCode} ->
- err400(io:format("add-ds-rr: invalid DS record: ~p", [ErrorCode]),
- Data)
+ err400("add-rr-chain: missing input: chain", Input)
end.