diff options
author | Linus Nordberg <linus@nordberg.se> | 2014-09-20 00:28:46 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2014-09-20 00:28:46 +0200 |
commit | 5c7a5be8f161684ae2d9d0868c35d623e127a327 (patch) | |
tree | 886965dc3ee00f29c2c97ae6b9572419823cf0ff /src/v1.erl | |
parent | 610c025a58053446b48b4b3b884b113375533231 (diff) |
Decode chain in 'add-chain' properly.
Diffstat (limited to 'src/v1.erl')
-rw-r--r-- | src/v1.erl | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -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). |