This commit is contained in:
parent
d370717a59
commit
529b2bae97
3 changed files with 18 additions and 17 deletions
|
|
@ -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
|
||||
|
||||
(* -- *)
|
||||
|
|
|
|||
11
src/keys.ml
11
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 =
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue