summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/db.hrl4
-rw-r--r--src/plop.erl34
l---------src/plop.hrl2
-rw-r--r--src/plop_sup.erl3
4 files changed, 27 insertions, 16 deletions
diff --git a/src/db.hrl b/src/db.hrl
index ce6df7b..01bd63f 100644
--- a/src/db.hrl
+++ b/src/db.hrl
@@ -3,6 +3,6 @@
-record(plop, {
index :: non_neg_integer(), % Primary key.
hash :: binary(), % Hash over #plop_entry{} in mtl.
- mtl :: mtl(), % Merkle Tree Leaf, an #mtl{}.
- spt_text :: binary() % Signed Plop Timestamp, an #spt_on_wire{}.
+ mtl :: mtl(), % Merkle Tree Leaf.
+ spt :: spt_on_wire() % Signed Plop Timestamp.
}).
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, []) ->
diff --git a/src/plop.hrl b/src/plop.hrl
index 38dfcbf..3ff34e2 120000
--- a/src/plop.hrl
+++ b/src/plop.hrl
@@ -1 +1 @@
-/home/linus/usr/src/plop/include/plop.hrl \ No newline at end of file
+/home/linus/usr/src/ct/plop/include/plop.hrl \ No newline at end of file
diff --git a/src/plop_sup.erl b/src/plop_sup.erl
index 1d08d60..08ccdcb 100644
--- a/src/plop_sup.erl
+++ b/src/plop_sup.erl
@@ -2,9 +2,10 @@
-behaviour(supervisor).
-export([start_link/1, init/1]).
--export([start_in_shell/0]).
+-export([start_in_shell/1]).
start_link(Args) ->
+ io:format("plop_sup:start_link got args ~p~n", [Args]),
supervisor:start_link({local, ?MODULE}, ?MODULE, Args).
%% For testing.