summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2015-05-29 18:16:29 +0200
committerMagnus Ahltorp <map@kth.se>2015-05-29 18:16:29 +0200
commit29c438dade7c2cb06a9bdc790ce80741c71e3ca7 (patch)
tree4bd38e5917df19c094d98eb735ee34658e42022c
parent1d8feb02887225a6cc5dc89bb0486424cb02e318 (diff)
Add verification of entry contents in frontend/sendsthfrontendverify
-rw-r--r--src/frontend.erl26
1 files changed, 22 insertions, 4 deletions
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].