From ed8bb6d1e454b9ddc793f74f682bd80b1c728904 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Sun, 4 May 2014 19:52:13 +0200 Subject: Get going, first cut. add-chain looks like it might work properly. Not verified! --- src/v1.erl | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/v1.erl (limited to 'src/v1.erl') diff --git a/src/v1.erl b/src/v1.erl new file mode 100644 index 0000000..99cf55b --- /dev/null +++ b/src/v1.erl @@ -0,0 +1,45 @@ +-module(v1). +-export([add_chain/3]). +-export([hello/3]). +-include("/home/linus/usr/src/ct/plop/include/plop.hrl"). +-define(PROTOCOL_VERSION, 1). + +%% Public functions. +add_chain(SessionID, _Env, Input) -> + Res = case (catch jiffy:decode(Input)) of + {error, E} -> html("add-chain: bad input; see RFC 6962", E); + {[{<<"chain">>, Chain}]} -> + Entry = #plop_entry{type = x509, + data = list_to_binary(Chain)}, + SPT = plop:add(#timestamped_entry{entry = Entry}), + Timestamp = SPT#spt_on_wire.timestamp, + R = [{sct_version, ?PROTOCOL_VERSION}, + {id, base64:encode(plop:get_logid())}, + {timestamp, Timestamp}, + {extensions, []}, + {signature, base64:encode(list_to_binary(plop:serialise(SPT)))}], + binary_to_list(jiffy:encode({R})); + _ -> html("add-chain: missing input: chain; see RFC 6962", Input) + end, + mod_esi:deliver(SessionID, Res). + +%% For testing. FIXME: Remove. +hello(SessionID, Env, Input) -> + Query = httpd:parse_query(Input), + mod_esi:deliver(SessionID, io_lib:format( + "Content-Type: text/html\r\n\r\n" ++ + "hello again, erlang world" ++ + "

SessionID: ~p~n" ++ + "

Env: ~p~n" ++ + "

Input, raw: ~p~n" ++ + "

Input, parsed: ~p~n" ++ + "", [SessionID, Env, Input, Query])). + +%% Private functions. +html(Text, Input) -> + io_lib:format( + "Content-Type: text/html\r\n\r\n" ++ + "

~n" ++ + "~s~n" ++ + "~p~n" ++ + "~n", [Text, Input]). -- cgit v1.1