From db1c5cf0eeba9b47a3f89bebc1abd9985ee9fef7 Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Thu, 26 Mar 2015 23:59:30 +0100 Subject: Provide function for calculating entryhash from entry --- Makefile | 2 +- src/catlfish.erl | 25 +++++++++++++++++++++++++ tools/compileconfig.py | 2 ++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cd445e3..58a1160 100644 --- a/Makefile +++ b/Makefile @@ -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] -- cgit v1.1