summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plop.erl37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/plop.erl b/src/plop.erl
index 008d15d..9907c35 100644
--- a/src/plop.erl
+++ b/src/plop.erl
@@ -1,26 +1,29 @@
%%% @doc Server holding log entries in a database and hashes in a
%%% Merkle tree. A backend for things like Certificate Transparency
%%% (RFC 6962).
-
+%%%
%%% When you submit data for insertion in the log, it's stored in an
%%% append only database with an accompanying Merkle tree. The leaves
%%% of the tree hold hashes of submitted data and makes it possible
%%% for anyone to verify wether a given piece of data is or is not
%%% present in the log.
-
+%%%
%%% In return you will get a signed timestamp which is a promise that
%%% your entry will be present in the log within a certain time period
%%% (the MMD). This signed timestamp can later, together with the
%%% public key of the log, be used to ensure that your entry is indeed
%%% present in the log.
+%%% TODO
+%%% - get rid of CT-specific stuff that has creeped in
+
-module(plop).
-behaviour(gen_server).
%% API.
-export([start_link/2, stop/0]).
-export([get_logid/0, serialise/1]).
--export([add/1, sth/0]).
+-export([add/1, sth/0, get/2]).
%% API for tests.
-export([read_keyfile_rsa/2, read_keyfiles_ec/2]).
-export([testing_get_pubkey/0]).
@@ -71,7 +74,6 @@ stop() ->
%%%%%%%%%%%%%%%%%%%%
init([PrivKeyfile, PubKeyfile]) ->
- io:format("plop starting~n"),
%% Read RSA keypair.
%% {Private_key, Public_key} = read_keyfile_rsa(Keyfile, Passphrase),
%% LogID = crypto:hash(sha256,
@@ -109,6 +111,9 @@ add(Data) when is_record(Data, timestamped_entry) ->
sth() ->
gen_server:call(?MODULE, {sth, []}).
+get(Start, End) ->
+ gen_server:call(?MODULE, {get, {Start, End}}).
+
get_logid() ->
gen_server:call(?MODULE, {get, logid}).
@@ -121,11 +126,12 @@ handle_call(stop, _From, State) ->
%% FIXME: What's the right interface for add()? Need to be able to set
%% version and signature type, at least. That's missing from
%% #timestamped_entry, so add it somehow.
-handle_call({add, #timestamped_entry{timestamp = Timestamp_in,
- entry = Entry}},
- _From, State = #state{privkey = Privkey,
- logid = LogID,
- hashtree = Tree}) ->
+handle_call({add, #timestamped_entry{
+ timestamp = Timestamp_in, entry = Entry}},
+ _From,
+ State = #state{privkey = Privkey,
+ logid = LogID,
+ hashtree = Tree}) ->
TimestampedEntry = #timestamped_entry{
timestamp = timestamp(Timestamp_in),
entry = Entry},
@@ -137,6 +143,9 @@ handle_call({sth, Data}, _From,
hashtree = Tree}) ->
{reply, sth(PrivKey, Tree, Data), Plop};
+handle_call({get, {Start, End}}, _From, Plop) ->
+ {reply, db:get_by_index(Start, End), Plop};
+
handle_call({get, logid}, _From,
Plop = #state{logid = LogID}) ->
{reply, LogID, Plop};
@@ -168,8 +177,8 @@ do_add(TimestampedEntry = #timestamped_entry{entry = PlopEntry},
DB_hash = crypto:hash(sha256, serialise(PlopEntry)),
Record = db:find(DB_hash),
case Record of
- #plop{index = I, mtl = #mtl{entry = E}, spt = SPT} ->
- io:format("Found entry: index=~p~n", [I]),
+ #plop{index = _I, mtl = #mtl{entry = E}, spt = SPT} ->
+ %%io:format("Found entry: index=~p~n", [I]),
%% Database consistency checking. FIXME: Remove.
Record = Record#plop{
hash = DB_hash,
@@ -181,7 +190,7 @@ do_add(TimestampedEntry = #timestamped_entry{entry = PlopEntry},
[] ->
NewSPT = spt(LogID, Privkey, TimestampedEntry),
MTL = #mtl{entry = TimestampedEntry},
- io:format("Creating new entry: index=~p~n", [ht:size(Tree)]),
+ %%io:format("Creating new entry: index=~p~n", [ht:size(Tree)]),
DB_data = #plop{index = ht:size(Tree),
hash = DB_hash,
mtl = MTL,
@@ -241,8 +250,8 @@ sth(PrivKey, Tree, #sth_signed{version = Version, timestamp = Timestamp_in}) ->
timestamp = Timestamp,
roothash = Roothash,
signature = Signature},
- io:format("STH: ~p~nBinToSign: ~p~nSignature: ~p~nTimestamp: ~p~n",
- [STH, BinToSign, Signature, Timestamp]),
+ %%io:format("STH: ~p~nBinToSign: ~p~nSignature: ~p~nTimestamp: ~p~n",
+ %% [STH, BinToSign, Signature, Timestamp]),
STH.
%% TODO: Merge the keyfile reading functions.