diff options
| author | Magnus Ahltorp <map@kth.se> | 2014-11-18 17:06:53 +0100 |
|---|---|---|
| committer | Magnus Ahltorp <map@kth.se> | 2014-11-18 17:06:53 +0100 |
| commit | 6f94f976570318f792e473b4d569cbcfcf787659 (patch) | |
| tree | 7ad4b7ec8039f0206916d56f50d73c4e91faf071 /src/frontend.erl | |
| parent | 9e0ce61de75745ac4f1cab7440c86dc3d18b731e (diff) | |
Make ht load tree and verify root hash before updating tree size
Diffstat (limited to 'src/frontend.erl')
| -rw-r--r-- | src/frontend.erl | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/frontend.erl b/src/frontend.erl index 9c69517..6fc2fd5 100644 --- a/src/frontend.erl +++ b/src/frontend.erl @@ -41,6 +41,7 @@ request(post, "ct/frontend/sendsth", Input) -> {struct, PropList} -> OldSize = db:size(), Treesize = proplists:get_value(<<"tree_size">>, PropList), + RootHash = base64:decode(proplists:get_value(<<"sha256_root_hash">>, PropList)), Indexsize = db:indexsize(), if @@ -59,9 +60,15 @@ request(post, "ct/frontend/sendsth", Input) -> case Errors of [] -> - ok = db:set_treesize(Treesize), - ht:reset_tree([db:size() - 1]), - success({[{result, <<"ok">>}]}); + ht:load_tree(Treesize - 1), + OwnRootHash = ht:root(Treesize - 1), + case OwnRootHash of + RootHash -> + ok = db:set_treesize(Treesize), + success({[{result, <<"ok">>}]}); + _ -> + html("Root hash not the same", hex:bin_to_hexstr(OwnRootHash)) + end; _ -> html("Database not complete", Errors) end |
