diff options
author | Magnus Ahltorp <map@kth.se> | 2015-03-26 23:59:30 +0100 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2015-03-27 00:00:14 +0100 |
commit | db1c5cf0eeba9b47a3f89bebc1abd9985ee9fef7 (patch) | |
tree | 13bb97720c65e0ff0c0a518c480410f94f5a40e6 | |
parent | f38b28bfe90ac9c35c8b2edcf296720e189f7083 (diff) |
Provide function for calculating entryhash from entryentryhash-merge
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/catlfish.erl | 25 | ||||
-rwxr-xr-x | tools/compileconfig.py | 2 |
3 files changed, 28 insertions, 1 deletions
@@ -1,5 +1,5 @@ build all: - erl -pa ../lager/ebin -make + ./make.erl clean: -rm ebin/*.beam release: all diff --git a/src/catlfish.erl b/src/catlfish.erl index 2e5ffd4..ed75495 100644 --- a/src/catlfish.erl +++ b/src/catlfish.erl @@ -5,6 +5,7 @@ -export([add_chain/3, entries/2, entry_and_proof/2]). -export([known_roots/0, update_known_roots/0]). -export([init_cache_table/0]). +-export([entryhash_from_entry/1]). -include_lib("eunit/include/eunit.hrl"). -define(PROTOCOL_VERSION, 0). @@ -243,6 +244,30 @@ init_cache_table() -> end, ets:new(?CACHE_TABLE, [set, public, named_table]). +deserialise_extra_data(ExtraData) -> + case decode_tls_vector(ExtraData, 3) of + {E, <<>>} -> + [E]; + {E, Rest} -> + [E | deserialise_extra_data(Rest)] + end. + +entryhash_from_entry(Entry) -> + {MTLText, ExtraDataPacked} = unpack_entry(Entry), + {ExtraData, <<>>} = decode_tls_vector(ExtraDataPacked, 3), + MTL = deserialise_mtl(MTLText), + TimestampedEntry = MTL#mtl.entry, + Chain = deserialise_extra_data(ExtraData), + Data = + case TimestampedEntry#timestamped_entry.entry_type of + x509_entry -> + SignedEntry = TimestampedEntry#timestamped_entry.signed_entry, + [SignedEntry#signed_x509_entry.asn1_cert | Chain]; + precert_entry -> + Chain + end, + crypto:hash(sha256, Data). + %% Private functions. -spec unpack_entry(binary()) -> {binary(), binary()}. unpack_entry(Entry) -> diff --git a/tools/compileconfig.py b/tools/compileconfig.py index 30424c5..e3d9ee0 100755 --- a/tools/compileconfig.py +++ b/tools/compileconfig.py @@ -188,6 +188,8 @@ def gen_config(nodename, config, localconfig): if nodetype == "frontendnodes": plopconfig += [ (Symbol("sth_path"), paths["db"] + "sth"), + (Symbol("entryhash_from_entry"), + (Symbol("catlfish"), Symbol("entryhash_from_entry"))), ] signingnode = config["signingnodes"][0] |