From 29c438dade7c2cb06a9bdc790ce80741c71e3ca7 Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Fri, 29 May 2015 18:16:29 +0200 Subject: Add verification of entry contents in frontend/sendsth --- src/frontend.erl | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/frontend.erl') diff --git a/src/frontend.erl b/src/frontend.erl index 172cc23..27b3c6c 100644 --- a/src/frontend.erl +++ b/src/frontend.erl @@ -121,15 +121,33 @@ check_entries(Entries, Start, End) -> end end, [], lists:zip(Entries, lists:seq(Start, End))). +entryhash_from_entry(Entry) -> + {ok, {Module, Function}} = application:get_env(plop, entryhash_from_entry), + Module:Function(Entry). + +verify_entry(Entry) -> + {ok, {Module, Function}} = application:get_env(plop, verify_entry), + Module:Function(Entry). + check_entry(LeafHash, Index) -> case db:get_by_leaf_hash(LeafHash) of notfound -> {notfound, Index}; {Index, LeafHash, Entry} -> - {ok, {Module, Function}} = application:get_env(plop, entryhash_from_entry), - EntryHash = Module:Function(Entry), - db:add_entryhash(LeafHash, EntryHash), - ok + case verify_entry(Entry) of + {ok, LeafHash} -> + EntryHash = entryhash_from_entry(Entry), + db:add_entryhash(LeafHash, EntryHash), + ok; + {ok, DifferentLeafHash} -> + lager:error("leaf hash not correct: filename is ~p " ++ + "and contents are ~p", + [hex:bin_to_hexstr(LeafHash), + hex:bin_to_hexstr(DifferentLeafHash)]), + {error, differentleafhash}; + {error, Reason} -> + lager:error("verification failed: ~p", [Reason]) + end end. -spec fetchmissingentries(non_neg_integer()) -> [binary() | noentry]. -- cgit v1.1