diff options
author | Linus Nordberg <linus@nordu.net> | 2014-05-04 19:56:38 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2014-05-04 19:56:44 +0200 |
commit | 87757c2219744426a1d5c9c698e109c47ea892da (patch) | |
tree | c935b209f566a175994a797a910ba45da3243adf /src/plop.erl | |
parent | b95fac93ba4bcdfcff7a18718eb587593660bb6c (diff) |
Adopt to first user -- ctls.
Return #spt_on_wire instead of serialised version of it -- user wants
the timestamp in there.
Store that in db too.
Export serialise/1 for user to do it themselves.
Add get_logid/1 -- user needs that for the CST.
Make sure 'now' is turned into a proper timestamp at all levels.
Debug printout in plop start_link.
Diffstat (limited to 'src/plop.erl')
-rw-r--r-- | src/plop.erl | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/plop.erl b/src/plop.erl index 14d39b1..98e62af 100644 --- a/src/plop.erl +++ b/src/plop.erl @@ -13,6 +13,7 @@ %% API. -export([start_link/2, stop/0]). +-export([get_logid/0, serialise/1]). -export([add/1, sth/0]). %% API for tests. -export([sth/1]). @@ -80,6 +81,9 @@ sth() -> sth(Data) -> gen_server:call(?MODULE, {sth, Data}). +get_logid() -> + gen_server:call(?MODULE, {get, logid}). + testing_get_pubkey() -> gen_server:call(?MODULE, {test, pubkey}). %%%%%%%%%%%%%%%%%%%% @@ -89,10 +93,14 @@ handle_call(stop, _From, State) -> %% FIXME: What's the right interface for add()? Need to be able to set %% version and signature type, at least. That's missing from %% #timestamped_entry, so add it somehow. -handle_call({add, #timestamped_entry{} = TimestampedEntry}, +handle_call({add, #timestamped_entry{timestamp = Timestamp_in, + entry = Entry}}, _From, State = #state{privkey = Privkey, logid = LogID, hashtree = Tree}) -> + TimestampedEntry = #timestamped_entry{ + timestamp = timestamp(Timestamp_in), + entry = Entry}, {NewTree, SPT} = do_add(TimestampedEntry, Privkey, LogID, Tree), {reply, SPT, State#state{hashtree = NewTree}}; @@ -101,6 +109,10 @@ handle_call({sth, Data}, _From, hashtree = Tree}) -> {reply, sth(PrivKey, Tree, Data), Plop}; +handle_call({get, logid}, _From, + Plop = #state{logid = LogID}) -> + {reply, LogID, Plop}; + handle_call({test, pubkey}, _From, Plop = #state{pubkey = PK}) -> {reply, PK, Plop}. @@ -113,7 +125,7 @@ do_add(TimestampedEntry = #timestamped_entry{entry = PlopEntry}, DB_hash = crypto:hash(sha256, serialise(PlopEntry)), Record = db:find(DB_hash), case Record of - #plop{index = I, mtl = M = #mtl{entry = E}, spt_text = SPT} -> + #plop{index = I, mtl = M = #mtl{entry = E}, spt = SPT} -> io:format("Found entry: index=~p~nMTL: ~p~nSPT: ~p~n", [I, M, SPT]), Record = Record#plop{ % DB consistency checking. hash = DB_hash, @@ -131,7 +143,7 @@ do_add(TimestampedEntry = #timestamped_entry{entry = PlopEntry}, DB_data = #plop{index = ht:size(Tree) + 1, hash = DB_hash, mtl = MTL, - spt_text = NewSPT}, + spt = NewSPT}, db:add(DB_data), {ht:append(Tree, serialise(MTL)), % New tree. NewSPT} % New SPT. @@ -139,12 +151,11 @@ do_add(TimestampedEntry = #timestamped_entry{entry = PlopEntry}, %% @doc Signed Plop Timestamp, conformant to an SCT in RFC6962 3.2 and %% RFC5246 4.7. --spec spt(binary(), public_key:rsa_private_key(), timestamped_entry()) -> binary(). +-spec spt(binary(), public_key:rsa_private_key(), timestamped_entry()) -> spt_on_wire(). spt(LogID, PrivKey, #timestamped_entry{ - timestamp = Timestamp_in, + timestamp = Timestamp, entry = #plop_entry{type = EntryType, data = EntryData} }) -> - Timestamp = timestamp(Timestamp_in), BinToSign = list_to_binary(serialise(#spt_signed{ version = 1, @@ -153,12 +164,11 @@ spt(LogID, PrivKey, #timestamped_entry{ entry_type = EntryType, signed_entry = EntryData})), Signature = signhash(BinToSign, PrivKey), - SPT = serialise(#spt_on_wire{ - version = ?PLOPVERSION, - logid = LogID, - timestamp = Timestamp, - signature = Signature}), - list_to_binary(SPT). + #spt_on_wire{ + version = ?PLOPVERSION, + logid = LogID, + timestamp = Timestamp, + signature = Signature}. %% @doc Signed Tree Head as specified in RFC6962 section 3.2. sth(PrivKey, Tree, []) -> |