summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2014-05-01 18:04:45 +0200
committerLinus Nordberg <linus@nordu.net>2014-05-01 18:04:45 +0200
commit1ff857dfc7b70c7fe544afb27ab26500237d633f (patch)
treeb4f5d3c2ce53113ed055869431c5dd37798e71a6
parentc44d085b74c541d1e07db03a0372a5350bcc7577 (diff)
Store MTL in database -- we need the meat.
-rw-r--r--src/plop.erl48
1 files changed, 23 insertions, 25 deletions
diff --git a/src/plop.erl b/src/plop.erl
index e5432bc..b55eaff 100644
--- a/src/plop.erl
+++ b/src/plop.erl
@@ -93,29 +93,27 @@ handle_call({sth, Data}, _From,
%%%%%%%%%%%%%%%%%%%%
+-spec do_add(timestamped_entry(), public_key:rsa_private_key(), binary(), any()) -> {any(), binary()}.
do_add(TimestampedEntry, Privkey, LogID, Tree) ->
- H = crypto:hash(sha256, serialise(TimestampedEntry)),
- Record = db:find(H),
- TmpFixm = case Record of
- #plop{index = I, spt = S} ->
- io:format("Found entry w/ index=~p, SPT: ~p~n", [I, S]),
- %% DB consistency check:
- %%Record = #plop{hash = H, spt = serialise(Data)}, % FIXME: Remove.
- {Tree, % State not changed.
- S}; % Cached SPT.
- _ ->
- NewSPT = spt(LogID, Privkey, TimestampedEntry),
- DbData = #plop{index = ht:size(Tree) + 1,
- hash = H,
- spt = NewSPT},
- db:add(DbData),
- LeafData = #mtl{version = 1,
- leaf_type = timestamped_entry,
- entry = TimestampedEntry},
- {ht:append(Tree, serialise(LeafData)), % New tree.
- NewSPT} % New SPT.
- end,
- TmpFixm.
+ MTL = #mtl{entry = TimestampedEntry},
+ MTL_text = serialise(MTL),
+ DB_hash = crypto:hash(sha256, MTL_text),
+ case db:find(DB_hash) of
+ #plop{index = I, mtl = M, spt_text = SPT} ->
+ io:format("Found entry: index=~p, MTL: ~p, SPT: ~p~n", [I, M, SPT]),
+ %% DB consistency check:
+ %%Record = #plop{hash = H, spt = serialise(Data)}, % FIXME: Remove.
+ {Tree, SPT}; % State not changed, cached SPT.
+ _ ->
+ NewSPT = spt(LogID, Privkey, TimestampedEntry),
+ DB_data = #plop{index = ht:size(Tree) + 1,
+ hash = DB_hash,
+ mtl = MTL,
+ spt_text = NewSPT},
+ db:add(DB_data),
+ {ht:append(Tree, MTL_text), % New tree.
+ NewSPT} % New SPT.
+ end.
%% @doc Signed Plop Timestamp, conformant to an SCT in RFC6962 3.2 and
%% RFC5246 4.7.
@@ -286,12 +284,12 @@ serialise_test_() ->
signed_entry = <<"foo">>})))].
add_test_() ->
{ok, S} = init(["test/rsakey.pem", "sikrit"]),
- [?_assertEqual(
- <<"fixme">>,
+ {_Tree, SPT} =
do_add(#timestamped_entry{
timestamp = 4711,
entry_type = test,
entry = <<"some data">>},
S#state.privkey,
S#state.logid,
- S#state.hashtree))].
+ S#state.hashtree),
+ [?_assertEqual(<<"fixme:SPT">>, SPT)].