summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plop.erl77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/plop.erl b/src/plop.erl
new file mode 100644
index 0000000..4af3f25
--- /dev/null
+++ b/src/plop.erl
@@ -0,0 +1,77 @@
+%%% @doc Server holding log entries in a database and hashes in a Merkle tree.
+%%%
+%%% When you submit data for insertion in the log, the data and a hash
+%%% of it is stored in a way that [mumble FIXME and FIXME]. In return
+%%% you will get a proof of your entry being included in the log. This
+%%% proof can later, together with the public key of the log, be used
+%%% to prove that your entry is indeed present in the log.
+
+-module('plop').
+-export([start/0, loop/2]).
+
+-record(plop, {pubkey :: crypto:rsa_public(),
+ privkey :: crypt:rsa_private()}).
+
+start(PlopKey) ->
+ Tree = ht:create(),
+ register(plop, spawn(plop, loop, [PlopKey, Tree])).
+
+log(Format, Data) ->
+ io:format(Format, Data).
+
+loop(PlopKey, Tree) ->
+ receive
+ {From, quit} ->
+ From ! {quit, ok};
+ {From, Data} ->
+ handle_req(From, Tree, Data),
+ loop(Tree);
+ Unknown ->
+ log("DEBUG: Received malformed command: ~p~n", [Unknown]),
+ loop(Tree)
+ end.
+
+handle_req(From, Tree, Arg) ->
+ case Arg of
+ {add, Data} ->
+ From ! spt(ht:append(Tree, Data));
+ %% {diff, Tree2} ->
+ %% From ! ht:diff(Tree, Tree2);
+ {sth} -> % Signed tree head.
+ sth(Tree);
+ Unknown ->
+ From ! {error, Unknown}
+ end.
+
+%% @doc Signed Plop Timestamp.
+ %% Signed Timestamp
+ %% struct {
+ %% Version sct_version;
+ %% LogID id;
+ %% uint64 timestamp;
+ %% CtExtensions extensions;
+ %% digitally-signed struct {
+ %% Version sct_version;
+ %% SignatureType signature_type = certificate_timestamp;
+ %% uint64 timestamp;
+ %% LogEntryType entry_type;
+ %% select(entry_type) {
+ %% case x509_entry: ASN.1Cert;
+ %% case precert_entry: PreCert;
+ %% } signed_entry;
+ %% CtExtensions extensions;
+ %% };
+ %% } SignedCertificateTimestamp;
+spt(LogID, Data) ->
+ "FIXME: a signed timestamp for " ++ Data.
+
+%% @doc Signed Tree Head
+ %% digitally-signed struct {
+ %% Version version;
+ %% SignatureType signature_type = tree_hash;
+ %% uint64 timestamp;
+ %% uint64 tree_size;
+ %% opaque sha256_root_hash[32];
+ %% } TreeHeadSignature;
+sth(Tree) ->
+ "FIXME: signed tree head for " ++ Tree.