This commit is contained in:
parent
38b42406e4
commit
937a8b759f
1 changed files with 27 additions and 17 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
open Syntax
|
open Syntax
|
||||||
open Crypto
|
open Crypto
|
||||||
open Mirage_crypto_ec
|
|
||||||
open Config.Exchange_secmod_eddsa
|
|
||||||
open Time
|
open Time
|
||||||
|
open Mirage_crypto_ec
|
||||||
|
module Cfg = Config.Exchange_secmod_eddsa
|
||||||
|
|
||||||
type priv = Ed25519.priv
|
type priv = Ed25519.priv
|
||||||
type pub = Ed25519.pub
|
type pub = Ed25519.pub
|
||||||
|
|
@ -36,12 +36,12 @@ let time_abs_to_string abs =
|
||||||
|> string_of_int
|
|> string_of_int
|
||||||
|
|
||||||
let read_key fname =
|
let read_key fname =
|
||||||
let fpath = Fpath.(v key_dir / fname) in
|
let fpath = Fpath.(v Cfg.key_dir / fname) in
|
||||||
let* data = Bos.OS.File.read fpath |> unwrap_err_msg in
|
let* data = Bos.OS.File.read fpath |> unwrap_err_msg in
|
||||||
EddsaPrivateKey.of_octets data
|
EddsaPrivateKey.of_octets data
|
||||||
|
|
||||||
let write_eddsa fname priv =
|
let write_eddsa fname priv =
|
||||||
let fpath = Fpath.(v key_dir / fname) in
|
let fpath = Fpath.(v Cfg.key_dir / fname) in
|
||||||
let data = EddsaPrivateKey.to_octets priv in
|
let data = EddsaPrivateKey.to_octets priv in
|
||||||
Bos.OS.File.write fpath data |> unwrap_err_msg
|
Bos.OS.File.write fpath data |> unwrap_err_msg
|
||||||
|
|
||||||
|
|
@ -55,12 +55,12 @@ let split_in_periodes ~start ~end_ =
|
||||||
(* no overlap on first periode
|
(* no overlap on first periode
|
||||||
this is to not generate a key valid in the past *)
|
this is to not generate a key valid in the past *)
|
||||||
let t1 = start in
|
let t1 = start in
|
||||||
let t2 = Absolute.add start duration in
|
let t2 = Absolute.add start Cfg.duration in
|
||||||
let acc = [ (t1, t2) ] in
|
let acc = [ (t1, t2) ] in
|
||||||
let start = t2 in
|
let start = t2 in
|
||||||
let rec go acc start end_ =
|
let rec go acc start end_ =
|
||||||
let t1 = Absolute.sub start overlap_duration in
|
let t1 = Absolute.sub start Cfg.overlap_duration in
|
||||||
let t2 = Absolute.add start duration in
|
let t2 = Absolute.add start Cfg.duration in
|
||||||
if t2 > end_ then acc else go ((t1, t2) :: acc) t2 end_
|
if t2 > end_ then acc else go ((t1, t2) :: acc) t2 end_
|
||||||
in
|
in
|
||||||
go acc start end_
|
go acc start end_
|
||||||
|
|
@ -73,9 +73,9 @@ let gen_additional_keys_until_lookahead ~now l =
|
||||||
let l_rev = List.rev l in
|
let l_rev = List.rev l in
|
||||||
match l_rev with
|
match l_rev with
|
||||||
| [] -> now
|
| [] -> now
|
||||||
| hd :: _ -> Absolute.sub hd.t2 overlap_duration
|
| hd :: _ -> Absolute.sub hd.t2 Cfg.overlap_duration
|
||||||
in
|
in
|
||||||
let end_ = Absolute.add now lookahead_sign in
|
let end_ = Absolute.add now Cfg.lookahead_sign in
|
||||||
let periodes = split_in_periodes ~start ~end_ in
|
let periodes = split_in_periodes ~start ~end_ in
|
||||||
let new_keys =
|
let new_keys =
|
||||||
List.map
|
List.map
|
||||||
|
|
@ -108,7 +108,7 @@ let purge_outdated ~now l =
|
||||||
|
|
||||||
let load_key fpath =
|
let load_key fpath =
|
||||||
let fname = Fpath.filename fpath in
|
let fname = Fpath.filename fpath in
|
||||||
if fname = sm_priv_key then Ok None
|
if fname = Cfg.sm_priv_key then Ok None
|
||||||
else
|
else
|
||||||
match String.split_on_char '-' fname with
|
match String.split_on_char '-' fname with
|
||||||
| [] -> Fmt.failwith "not possible"
|
| [] -> Fmt.failwith "not possible"
|
||||||
|
|
@ -122,7 +122,7 @@ let load_key fpath =
|
||||||
| _ -> Ok None
|
| _ -> Ok None
|
||||||
|
|
||||||
let load () =
|
let load () =
|
||||||
let dir = Fpath.v key_dir in
|
let dir = Fpath.v Cfg.key_dir in
|
||||||
let* b = Bos.OS.Dir.create ~mode:0o700 dir |> unwrap_err_msg in
|
let* b = Bos.OS.Dir.create ~mode:0o700 dir |> unwrap_err_msg in
|
||||||
if b then
|
if b then
|
||||||
Logs.info (fun m -> m "secmod_eddsa: created directory `%a`" Fpath.pp dir);
|
Logs.info (fun m -> m "secmod_eddsa: created directory `%a`" Fpath.pp dir);
|
||||||
|
|
@ -134,7 +134,7 @@ let load () =
|
||||||
match keys with
|
match keys with
|
||||||
| [] -> Ok None
|
| [] -> Ok None
|
||||||
| _l ->
|
| _l ->
|
||||||
let* sm_key_priv = read_key sm_priv_key in
|
let* sm_key_priv = read_key Cfg.sm_priv_key in
|
||||||
let sm_key_pub = EddsaPrivateKey.pub_of_priv sm_key_priv in
|
let sm_key_pub = EddsaPrivateKey.pub_of_priv sm_key_priv in
|
||||||
Ok (Some { sm_key_priv; sm_key_pub; keys })
|
Ok (Some { sm_key_priv; sm_key_pub; keys })
|
||||||
|
|
||||||
|
|
@ -145,7 +145,7 @@ let init () =
|
||||||
| Some t -> Ok t
|
| Some t -> Ok t
|
||||||
| None ->
|
| None ->
|
||||||
let sm_key_priv, sm_key_pub = Mirage_crypto_ec.Ed25519.generate () in
|
let sm_key_priv, sm_key_pub = Mirage_crypto_ec.Ed25519.generate () in
|
||||||
let* () = write_eddsa sm_priv_key sm_key_priv in
|
let* () = write_eddsa Cfg.sm_priv_key sm_key_priv in
|
||||||
Ok { sm_key_priv; sm_key_pub; keys= [] }
|
Ok { sm_key_priv; sm_key_pub; keys= [] }
|
||||||
in
|
in
|
||||||
let now = Absolute.of_ptime (Ptime_clock.now ()) in
|
let now = Absolute.of_ptime (Ptime_clock.now ()) in
|
||||||
|
|
@ -163,15 +163,25 @@ let t =
|
||||||
| Error e -> Fmt.failwith "secmod_eddsa initialization failure: %s." e
|
| Error e -> Fmt.failwith "secmod_eddsa initialization failure: %s." e
|
||||||
| Ok t -> t
|
| Ok t -> t
|
||||||
|
|
||||||
(*
|
let sm_key_pub = t.sm_key_pub
|
||||||
- sign
|
let keys () = List.map (fun { priv= _; pub; t1; t2 } -> (pub, t1, t2)) t.keys
|
||||||
- expose future_sk list
|
let sign_with_sm_key s = EddsaSignature.sign ~key:t.sm_key_priv s
|
||||||
|
|
||||||
|
let sign ~pub s =
|
||||||
|
match List.find_opt (fun k -> k.pub = pub) t.keys with
|
||||||
|
| None -> Error "key not found"
|
||||||
|
| Some k ->
|
||||||
|
let data = EddsaSignature.sign ~key:k.priv s in
|
||||||
|
Ok data
|
||||||
|
|
||||||
|
(* TODO
|
||||||
|
- sign: check time
|
||||||
- purge
|
- purge
|
||||||
- revoke
|
- revoke
|
||||||
- schedule tasks
|
- schedule tasks
|
||||||
- !lock
|
- !lock
|
||||||
|
|
||||||
todo taler doc/config is confusing
|
taler doc/config is confusing
|
||||||
how is computed stamp_expire stamp_end
|
how is computed stamp_expire stamp_end
|
||||||
what to do of 'Exchange.signkey_legal_duration'
|
what to do of 'Exchange.signkey_legal_duration'
|
||||||
=> (??)
|
=> (??)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue