summaryrefslogtreecommitdiff
path: root/src/v1.erl
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2015-07-16 11:52:27 +0200
committerLinus Nordberg <linus@nordu.net>2015-09-26 21:23:03 +0200
commiteabf3612c5efe3b344366802db9f4de36871bacf (patch)
tree9df075d6c460abbb9d6be667140d2625debb4745 /src/v1.erl
parent68ce3c508c16ce1cdfbfa928ae0494cca1bdc0ce (diff)
Accept any kind of submitted data, not only X.509 certificate chains.
Have add_chain() take a blob instead of a cert leaf and a chain. Rename ct/v1/add-chain -> add-blob. Remove ct/v1/add-pre-chain. Remove chain checking code. Generate allowed_client config matching new HTTP API.
Diffstat (limited to 'src/v1.erl')
-rw-r--r--src/v1.erl42
1 files changed, 8 insertions, 34 deletions
diff --git a/src/v1.erl b/src/v1.erl
index e066cdd..d89b521 100644
--- a/src/v1.erl
+++ b/src/v1.erl
@@ -28,13 +28,9 @@ check_valid_sth() ->
end.
%% Public functions, i.e. part of URL.
-request(post, "ct/v1/add-chain", Input) ->
+request(post, "ct/v1/add-blob", Input) ->
check_valid_sth(),
- add_chain(Input, normal);
-
-request(post, "ct/v1/add-pre-chain", Input) ->
- check_valid_sth(),
- add_chain(Input, precert);
+ add_blob(Input);
request(get, "ct/v1/get-sth", _Query) ->
check_valid_sth(),
@@ -149,34 +145,12 @@ internalerror(Text) ->
"~s~n" ++
"</body></html>~n", [Text])}.
--spec add_chain(any(), normal|precert) -> any().
-add_chain(Input, Type) ->
+-spec add_blob(any()) -> any().
+add_blob(Input) ->
case (catch mochijson2:decode(Input)) of
{error, E} ->
- err400("add-chain: bad input:", E);
- {struct, [{<<"chain">>, ChainB64List}]} ->
- case decode_chain(ChainB64List) of
- [LeafCert | CertChain] ->
- case x509:normalise_chain(catlfish:known_roots(),
- [LeafCert|CertChain]) of
- {ok, [Leaf | Chain]} ->
- lager:info("adding ~p cert ~p",
- [Type, x509:cert_string(LeafCert)]),
- success(catlfish:add_chain(Leaf, Chain, Type));
- {error, Reason} ->
- lager:info("rejecting ~p: ~p",
- [x509:cert_string(LeafCert), Reason]),
- err400("add-chain: invalid chain", Reason)
- end;
- {invalid, ErrText} ->
- err400(io:format("add-chain: ~p", [ErrText]), [ChainB64List])
- end;
- _ -> err400("add-chain: missing input: chain", Input)
- end.
-
--spec decode_chain(string()) -> {invalid, string()} | [binary()].
-decode_chain(B64List) ->
- case (catch [base64:decode(X) || X <- B64List]) of
- {'EXIT', _} -> {invalid, "invalid base64-encoded chain"};
- L -> L
+ err400("add-blob: bad input:", E);
+ {struct, [{<<"blob">>, Blob}]} ->
+ success(catlfish:add_chain(Blob, normal));
+ _ -> err400("add-blob: missing input: blob", Input)
end.