summaryrefslogtreecommitdiff
path: root/src/v1.erl
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2015-03-23 16:04:10 +0100
committerLinus Nordberg <linus@nordberg.se>2015-03-23 16:04:10 +0100
commit0fd4141586310d7735a376bdbf4541b0d8e88169 (patch)
tree73886c42f951dbffefd52dea94af3365951c2e2b /src/v1.erl
parent056b69cc4891c5ef1ba8da7e0a9369cb069a03e0 (diff)
parent3f9f38468dd9f43a7a71768dbe84dd40723c30c5 (diff)
Merge branch 'precert2'
Conflicts: Makefile
Diffstat (limited to 'src/v1.erl')
-rw-r--r--src/v1.erl73
1 files changed, 33 insertions, 40 deletions
diff --git a/src/v1.erl b/src/v1.erl
index d9796fa..e672182 100644
--- a/src/v1.erl
+++ b/src/v1.erl
@@ -9,46 +9,14 @@
%% Public functions, i.e. part of URL.
request(post, "ct/v1/add-chain", Input) ->
- case (catch mochijson2:decode(Input)) of
- {error, E} ->
- html("add-chain: bad input:", E);
- {struct, [{<<"chain">>, ChainBase64}]} ->
- case (catch [base64:decode(X) || X <- ChainBase64]) of
- {'EXIT', _} ->
- html("add-chain: invalid base64-encoded chain: ",
- [ChainBase64]);
- [LeafCert | CertChain] ->
- Roots = catlfish:known_roots(),
- case x509:normalise_chain(Roots, [LeafCert|CertChain]) of
- {ok, [Leaf | Chain]} ->
- lager:info("adding ~p",
- [x509:cert_string(LeafCert)]),
- success(catlfish:add_chain(Leaf, Chain));
- {error, Reason} ->
- lager:info("rejecting ~p: ~p",
- [x509:cert_string(LeafCert), Reason]),
- html("add-chain: invalid chain", Reason)
- end;
- Invalid ->
- html("add-chain: chain is not a list: ", [Invalid])
- end;
- _ -> html("add-chain: missing input: chain", Input)
- end;
+ add_chain(Input, normal);
-request(post, "ct/v1/add-pre-chain", _Input) ->
- niy();
+request(post, "ct/v1/add-pre-chain", Input) ->
+ add_chain(Input, precert);
request(get, "ct/v1/get-sth", _Query) ->
- { Treesize,
- Timestamp,
- Roothash,
- Signature} = plop:sth(),
- R = [{tree_size, Treesize},
- {timestamp, Timestamp},
- {sha256_root_hash, base64:encode(Roothash)},
- {tree_head_signature, base64:encode(
- plop:serialise(Signature))}],
- success({R});
+ R = plop:sth(),
+ success(R);
request(get, "ct/v1/get-sth-consistency", Query) ->
case lists:sort(Query) of
@@ -138,8 +106,33 @@ html(Text, Input) ->
"~p~n" ++
"</body></html>~n", [Text, Input])}.
-niy() ->
- html("NIY - Not Implemented Yet|", []).
-
success(Data) ->
{200, [{"Content-Type", "text/json"}], mochijson2:encode(Data)}.
+
+-spec add_chain(any(), normal|precert) -> any().
+add_chain(Input, Type) ->
+ case (catch mochijson2:decode(Input)) of
+ {error, E} ->
+ html("add-chain: bad input:", E);
+ {struct, [{<<"chain">>, ChainBase64}]} ->
+ case (catch [base64:decode(X) || X <- ChainBase64]) of
+ {'EXIT', _} ->
+ html("add-chain: invalid base64-encoded chain: ",
+ [ChainBase64]);
+ [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]),
+ html("add-chain: invalid chain", Reason)
+ end;
+ Invalid ->
+ html("add-chain: chain is not a list: ", [Invalid])
+ end;
+ _ -> html("add-chain: missing input: chain", Input)
+ end.