summaryrefslogtreecommitdiff
path: root/src/plop.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/plop.erl')
-rw-r--r--src/plop.erl34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/plop.erl b/src/plop.erl
index 14d39b1..98e62af 100644
--- a/src/plop.erl
+++ b/src/plop.erl
@@ -13,6 +13,7 @@
%% API.
-export([start_link/2, stop/0]).
+-export([get_logid/0, serialise/1]).
-export([add/1, sth/0]).
%% API for tests.
-export([sth/1]).
@@ -80,6 +81,9 @@ sth() ->
sth(Data) ->
gen_server:call(?MODULE, {sth, Data}).
+get_logid() ->
+ gen_server:call(?MODULE, {get, logid}).
+
testing_get_pubkey() ->
gen_server:call(?MODULE, {test, pubkey}).
%%%%%%%%%%%%%%%%%%%%
@@ -89,10 +93,14 @@ 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{} = TimestampedEntry},
+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},
{NewTree, SPT} = do_add(TimestampedEntry, Privkey, LogID, Tree),
{reply, SPT, State#state{hashtree = NewTree}};
@@ -101,6 +109,10 @@ handle_call({sth, Data}, _From,
hashtree = Tree}) ->
{reply, sth(PrivKey, Tree, Data), Plop};
+handle_call({get, logid}, _From,
+ Plop = #state{logid = LogID}) ->
+ {reply, LogID, Plop};
+
handle_call({test, pubkey}, _From,
Plop = #state{pubkey = PK}) ->
{reply, PK, Plop}.
@@ -113,7 +125,7 @@ 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 = M = #mtl{entry = E}, spt_text = SPT} ->
+ #plop{index = I, mtl = M = #mtl{entry = E}, spt = SPT} ->
io:format("Found entry: index=~p~nMTL: ~p~nSPT: ~p~n", [I, M, SPT]),
Record = Record#plop{ % DB consistency checking.
hash = DB_hash,
@@ -131,7 +143,7 @@ do_add(TimestampedEntry = #timestamped_entry{entry = PlopEntry},
DB_data = #plop{index = ht:size(Tree) + 1,
hash = DB_hash,
mtl = MTL,
- spt_text = NewSPT},
+ spt = NewSPT},
db:add(DB_data),
{ht:append(Tree, serialise(MTL)), % New tree.
NewSPT} % New SPT.
@@ -139,12 +151,11 @@ do_add(TimestampedEntry = #timestamped_entry{entry = PlopEntry},
%% @doc Signed Plop Timestamp, conformant to an SCT in RFC6962 3.2 and
%% RFC5246 4.7.
--spec spt(binary(), public_key:rsa_private_key(), timestamped_entry()) -> binary().
+-spec spt(binary(), public_key:rsa_private_key(), timestamped_entry()) -> spt_on_wire().
spt(LogID, PrivKey, #timestamped_entry{
- timestamp = Timestamp_in,
+ timestamp = Timestamp,
entry = #plop_entry{type = EntryType, data = EntryData}
}) ->
- Timestamp = timestamp(Timestamp_in),
BinToSign =
list_to_binary(serialise(#spt_signed{
version = 1,
@@ -153,12 +164,11 @@ spt(LogID, PrivKey, #timestamped_entry{
entry_type = EntryType,
signed_entry = EntryData})),
Signature = signhash(BinToSign, PrivKey),
- SPT = serialise(#spt_on_wire{
- version = ?PLOPVERSION,
- logid = LogID,
- timestamp = Timestamp,
- signature = Signature}),
- list_to_binary(SPT).
+ #spt_on_wire{
+ version = ?PLOPVERSION,
+ logid = LogID,
+ timestamp = Timestamp,
+ signature = Signature}.
%% @doc Signed Tree Head as specified in RFC6962 section 3.2.
sth(PrivKey, Tree, []) ->