diff --git a/default/assets/mte.conf b/default/assets/mte.conf index a6c89c52..c401d5f3 100644 --- a/default/assets/mte.conf +++ b/default/assets/mte.conf @@ -41,11 +41,17 @@ config = "pgx://mte:hunter2@localhost:5432/taler-exchange" [taler-exchange-secmod-rsa] lookahead_sign = "1 year" -overlap_duration = "1 year" +overlap_duration = "1 hour" +duration = "3 weeks" +key_dir = "secrets/secmod_rsa" +sm_priv_key = "secrets/secmod_rsa/sm_key" [taler-exchange-secmod-eddsa] lookahead_sign = "1 year" -overlap_duration = "1 year" +overlap_duration = "1 hour" +duration = "3 weeks" +key_dir = "secrets/secmod_eddsa" +sm_priv_key = "secrets/secmod_eddsa/sm_key" [coin_kudo_1] value= EUR:0.01 diff --git a/src/config.ml b/src/config.ml index eb7973b5..7f74db6c 100644 --- a/src/config.ml +++ b/src/config.ml @@ -2,10 +2,8 @@ open Parse_config let config_filename = "mte.conf" -(* TODO config : rm *) -let secrets_dir = Fpath.v "secrets" -let secmod_dir = Fpath.(secrets_dir / "secmod") -let secmod_eddsa_dir = Fpath.(secrets_dir / "secmod_eddsa") +(* TODO config + read Fpath.t *) let config_data = match Assets_crunch.read config_filename with @@ -203,8 +201,8 @@ module Exchange_secmod_eddsa = struct let lookahead_sign = get "lookahead_sign" |> duration let overlap_duration = get "overlap_duration" |> duration let duration = get "duration" |> duration - let sm_priv_key = get "sm_priv_key" let key_dir = get "key_dir" + let sm_priv_key = get "sm_priv_key" end (* -- *) diff --git a/src/keys.ml b/src/keys.ml index ea18dba0..cbfc4234 100644 --- a/src/keys.ml +++ b/src/keys.ml @@ -40,11 +40,14 @@ module Make (Conn : Pg.CONN) = struct } let conn = (module Conn : Pg.CONN) - let sm_key_fname = Fpath.(Config.secmod_dir / "sm_key") - let sk_fname i = Fpath.(Config.secmod_dir / Fmt.str "sk_%d" i) + let sm_key_fname = Fpath.(v Config.Exchange_secmod_eddsa.sm_priv_key) + + let sk_fname i = + Fpath.(v Config.Exchange_secmod_eddsa.key_dir / Fmt.str "sk_%d" i) let dn_fname section_name = - Fpath.(Config.secmod_dir / Fmt.str "dn_%s" section_name) + Fpath.( + v Config.Exchange_secmod_eddsa.key_dir / Fmt.str "dn_%s" section_name) let sign_with_sm_key t s = EddsaSignature.sign ~key:t.sm_key s @@ -238,7 +241,7 @@ module Make (Conn : Pg.CONN) = struct Ok t let init () = - let dir = Config.secmod_dir in + let dir = Fpath.v Config.Exchange_secmod_eddsa.key_dir in let* b = Bos.OS.Dir.create ~mode:0o700 dir |> unwrap_err_msg in if b then Logs.info (fun m -> m "Keys: created directory `%a`" Fpath.pp dir); let* l = diff --git a/src/secmod_eddsa.ml b/src/secmod_eddsa.ml index 5bdd9ca6..ee787cdf 100644 --- a/src/secmod_eddsa.ml +++ b/src/secmod_eddsa.ml @@ -23,11 +23,7 @@ type t = { (* -- util -- *) let time_abs_of_string s = - match int_of_string_opt s with - | None -> None - | Some n -> - let ts = Absolute.of_s (Int64.of_int n) in - Some ts + int_of_string_opt s |> Option.map (fun n -> Absolute.of_s (Int64.of_int n)) let t1_t2_of_fpath fpath = let fname = Fpath.filename fpath in @@ -122,10 +118,16 @@ let check_periodes _l = (* TODO *) Ok () +let sm_key_fpath = + Result.get_ok + @@ + let+ fpath = Fpath.of_string Cfg.sm_priv_key |> unwrap_err_msg in + Fpath.normalize fpath + (* we load sm_key separately we don't accept non-key files in key_dir *) let load_key fpath = - match Fpath.filename fpath = Cfg.sm_priv_key with + match Fpath.equal (Fpath.normalize fpath) sm_key_fpath with | true -> Ok None | false -> ( match t1_t2_of_fpath fpath with @@ -135,8 +137,6 @@ let load_key fpath = let pub = EddsaPrivateKey.pub_of_priv priv in Ok (Some { priv; pub; t1; t2 })) -let sm_key_fpath = Fpath.(v Cfg.key_dir / Cfg.sm_priv_key) - let load () = let* l = get_key_dir_contents Cfg.key_dir in let* l = list_map load_key l in