summaryrefslogtreecommitdiff
path: root/src/v1.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/v1.erl')
-rw-r--r--src/v1.erl18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/v1.erl b/src/v1.erl
index 29ccd41..2581804 100644
--- a/src/v1.erl
+++ b/src/v1.erl
@@ -126,11 +126,8 @@ 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]);
+ {struct, [{<<"chain">>, ChainB64List}]} ->
+ case decode_chain(ChainB64List) of
[LeafCert | CertChain] ->
case x509:normalise_chain(catlfish:known_roots(),
[LeafCert|CertChain]) of
@@ -143,8 +140,15 @@ add_chain(Input, Type) ->
[x509:cert_string(LeafCert), Reason]),
html("add-chain: invalid chain", Reason)
end;
- Invalid ->
- html("add-chain: chain is not a list: ", [Invalid])
+ {invalid, ErrText} ->
+ html(io:format("add-chain: ~p", [ErrText]), [ChainB64List])
end;
_ -> html("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
+ end.