From c2d7fcc2e1274c148f0ac94436c138022390ffc4 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Fri, 19 Sep 2014 14:33:25 +0200 Subject: Hash over the MerkleTreeLeaf. Hash over correct timestamp when adding submitted entries. Hash over the full #mtl{} when adding entries from db. --- src/plop.erl | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/plop.erl') diff --git a/src/plop.erl b/src/plop.erl index 92ada3a..8277175 100644 --- a/src/plop.erl +++ b/src/plop.erl @@ -104,7 +104,8 @@ terminate(_Reason, _State) -> ok. %%%%%%%%%%%%%%%%%%%% -add(Data) when is_record(Data, timestamped_entry) -> +-spec add(timestamped_entry()) -> spt(). +add(Data) -> gen_server:call(?MODULE, {add, Data}). sth() -> gen_server:call(?MODULE, {sth, []}). @@ -171,22 +172,17 @@ handle_call({test, pubkey}, _From, -spec do_add(timestamped_entry(), public_key:rsa_private_key(), binary()) -> {ok|error, binary()}. -do_add(TimestampedEntry = #timestamped_entry{entry = PlopEntry}, - Privkey, - LogID) -> - DB_hash = crypto:hash(sha256, serialise(PlopEntry)), +do_add(TimestampedEntry, Privkey, LogID) -> + DB_hash = crypto:hash(sha256, + serialise(TimestampedEntry#timestamped_entry.entry)), Record = db:find(entryhash, DB_hash), case Record of #plop{index = _I, mtl = MTL, spt = SPT} -> %% Costly database consistency checking. FIXME: Remove. - E = MTL#mtl.entry, Record = Record#plop{ entryhash = DB_hash, mtlhash = ht:leaf_hash(serialise(MTL)), - mtl = #mtl{entry = - #timestamped_entry{ - timestamp = E#timestamped_entry.timestamp, - entry = PlopEntry}}}, + mtl = MTL}, {ok, SPT}; [] -> NewSPT = spt(LogID, Privkey, TimestampedEntry), -- cgit v1.1