From 968300d19b07be2749cb602e400a97167151e0ba Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Fri, 25 Apr 2014 16:32:56 +0200 Subject: Formatting and comments. --- src/plop.erl | 63 +++++++++++++++++++++--------------------------------------- 1 file changed, 22 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/plop.erl b/src/plop.erl index 3cc3205..0565a29 100644 --- a/src/plop.erl +++ b/src/plop.erl @@ -13,6 +13,8 @@ -export([start/2, loop/1]). +-define(PLOPVERSION, 1). + -record(plop, {pubkey :: public_key:rsa_public_key(), privkey :: public_key:rsa_private_key(), logid :: binary(), @@ -21,7 +23,8 @@ -spec start(string(), string()) -> pid(). start(Keyfile, Passphrase) -> {Private_key, Public_key} = read_keyfile(Keyfile, Passphrase), - LogID = crypto:hash(sha256, public_key:der_encode('RSAPublicKey', Public_key)), + LogID = crypto:hash(sha256, + public_key:der_encode('RSAPublicKey', Public_key)), Plop = #plop{pubkey = Public_key, privkey = Private_key, logid = LogID, @@ -60,7 +63,8 @@ handle_req(From, hashtree = Tree}, Arg) -> case Arg of - {add, PlopData = #plop_data{entry = Entry}} when is_record(Entry, plop_entry) -> + {add, PlopData = #plop_data{entry = Entry}} + when is_record(Entry, plop_entry) -> %% fixme: add Entry to db, ht:append(Tree, serialise(Entry)), SPT = spt(LogID, Privkey, PlopData), @@ -72,45 +76,22 @@ handle_req(From, From ! {error, Unknown} end. -%% RFC6962 - %% 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; -%% RRC 5246 - %% A digitally-signed element is encoded as a struct DigitallySigned: - %% struct { - %% SignatureAndHashAlgorithm algorithm; - %% opaque signature<0..2^16-1>; - %% } DigitallySigned; - --define(PLOPVERSION, 1). - -%% @doc Signed Plop Timestamp. -spt(LogID, PrivKey, #plop_data{version = Version, % >= 1 - signature_type = Sigtype, % >= 0 - timestamp = Timestamp_in, - entry = Entry = #plop_entry{}}) when is_binary(LogID) -> - Timestamp = case Timestamp_in of - now -> - {NowMegaSec, NowSec, NowMicroSec} = now(), - trunc(NowMegaSec * 1.0e9 + NowSec * 1.0e3 + NowMicroSec / 1.0e3); - _ -> Timestamp_in - end, +%% @doc Signed Plop Timestamp according to RFC6962 3.2 and RFC5246 4.7. +spt(LogID, + PrivKey, + #plop_data{version = Version, % >= 1 + signature_type = Sigtype, % >= 0 + timestamp = Timestamp_in, + entry = Entry = #plop_entry{}}) when is_binary(LogID) -> + Timestamp = + case Timestamp_in of + now -> + {NowMegaSec, NowSec, NowMicroSec} = now(), + trunc(NowMegaSec * 1.0e9 + + NowSec * 1.0e3 + + NowMicroSec / 1.0e3); + _ -> Timestamp_in + end, BinToSign = list_to_binary( serialise(#plop_data{version = Version, signature_type = Sigtype, -- cgit v1.1