summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2014-09-20 00:28:46 +0200
committerLinus Nordberg <linus@nordberg.se>2014-09-20 00:28:46 +0200
commit5c7a5be8f161684ae2d9d0868c35d623e127a327 (patch)
tree886965dc3ee00f29c2c97ae6b9572419823cf0ff
parent610c025a58053446b48b4b3b884b113375533231 (diff)
Decode chain in 'add-chain' properly.
-rw-r--r--src/v1.erl27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/v1.erl b/src/v1.erl
index d6b833b..0f9a7bc 100644
--- a/src/v1.erl
+++ b/src/v1.erl
@@ -18,17 +18,22 @@
'add-chain'(SessionID, _Env, Input) ->
Res = case (catch jiffy:decode(Input)) of
{error, E} -> html("add-chain: bad input:", E);
- {[{<<"chain">>, Chain}]} ->
- Entry = #plop_entry{type = x509,
- data = list_to_binary(Chain)},
- SPT = plop:add(#timestamped_entry{entry = Entry}),
- R = [{sct_version, ?PROTOCOL_VERSION},
- {id, base64:encode(SPT#spt.logid)},
- {timestamp, SPT#spt.timestamp},
- {extensions, base64:encode("")},
- {signature, base64:encode(
- plop:serialise(SPT#spt.signature))}],
- binary_to_list(jiffy:encode({R}));
+ {[{<<"chain">>, ChainBase64}]} ->
+ case (catch base64:decode(ChainBase64)) of
+ {'EXIT', _} ->
+ html("add-chain: invalid base64-encoded chain: ",
+ [ChainBase64]);
+ Chain ->
+ Entry = #plop_entry{type = x509, data = Chain},
+ SPT = plop:add(#timestamped_entry{entry = Entry}),
+ R = [{sct_version, ?PROTOCOL_VERSION},
+ {id, base64:encode(SPT#spt.logid)},
+ {timestamp, SPT#spt.timestamp},
+ {extensions, base64:encode("")},
+ {signature, base64:encode(
+ plop:serialise(SPT#spt.signature))}],
+ binary_to_list(jiffy:encode({R}))
+ end;
_ -> html("add-chain: missing input: chain", Input)
end,
deliver(SessionID, Res).