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"
|
let config_filename = "mte.conf"
|
||||||
|
|
||||||
(* TODO config : rm *)
|
(* TODO config
|
||||||
let secrets_dir = Fpath.v "secrets"
|
read Fpath.t *)
|
||||||
let secmod_dir = Fpath.(secrets_dir / "secmod")
|
|
||||||
let secmod_eddsa_dir = Fpath.(secrets_dir / "secmod_eddsa")
|
|
||||||
|
|
||||||
let config_data =
|
let config_data =
|
||||||
match Assets_crunch.read config_filename with
|
match Assets_crunch.read config_filename with
|
||||||
|
|
@ -203,8 +201,8 @@ module Exchange_secmod_eddsa = struct
|
||||||
let lookahead_sign = get "lookahead_sign" |> duration
|
let lookahead_sign = get "lookahead_sign" |> duration
|
||||||
let overlap_duration = get "overlap_duration" |> duration
|
let overlap_duration = get "overlap_duration" |> duration
|
||||||
let duration = get "duration" |> duration
|
let duration = get "duration" |> duration
|
||||||
let sm_priv_key = get "sm_priv_key"
|
|
||||||
let key_dir = get "key_dir"
|
let key_dir = get "key_dir"
|
||||||
|
let sm_priv_key = get "sm_priv_key"
|
||||||
end
|
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 conn = (module Conn : Pg.CONN)
|
||||||
let sm_key_fname = Fpath.(Config.secmod_dir / "sm_key")
|
let sm_key_fname = Fpath.(v Config.Exchange_secmod_eddsa.sm_priv_key)
|
||||||
let sk_fname i = Fpath.(Config.secmod_dir / Fmt.str "sk_%d" i)
|
|
||||||
|
let sk_fname i =
|
||||||
|
Fpath.(v Config.Exchange_secmod_eddsa.key_dir / Fmt.str "sk_%d" i)
|
||||||
|
|
||||||
let dn_fname section_name =
|
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
|
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
|
Ok t
|
||||||
|
|
||||||
let init () =
|
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
|
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);
|
if b then Logs.info (fun m -> m "Keys: created directory `%a`" Fpath.pp dir);
|
||||||
let* l =
|
let* l =
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,7 @@ type t = {
|
||||||
(* -- util -- *)
|
(* -- util -- *)
|
||||||
|
|
||||||
let time_abs_of_string s =
|
let time_abs_of_string s =
|
||||||
match int_of_string_opt s with
|
int_of_string_opt s |> Option.map (fun n -> Absolute.of_s (Int64.of_int n))
|
||||||
| None -> None
|
|
||||||
| Some n ->
|
|
||||||
let ts = Absolute.of_s (Int64.of_int n) in
|
|
||||||
Some ts
|
|
||||||
|
|
||||||
let t1_t2_of_fpath fpath =
|
let t1_t2_of_fpath fpath =
|
||||||
let fname = Fpath.filename fpath in
|
let fname = Fpath.filename fpath in
|
||||||
|
|
@ -122,10 +118,16 @@ let check_periodes _l =
|
||||||
(* TODO *)
|
(* TODO *)
|
||||||
Ok ()
|
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 load sm_key separately
|
||||||
we don't accept non-key files in key_dir *)
|
we don't accept non-key files in key_dir *)
|
||||||
let load_key fpath =
|
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
|
| true -> Ok None
|
||||||
| false -> (
|
| false -> (
|
||||||
match t1_t2_of_fpath fpath with
|
match t1_t2_of_fpath fpath with
|
||||||
|
|
@ -135,8 +137,6 @@ let load_key fpath =
|
||||||
let pub = EddsaPrivateKey.pub_of_priv priv in
|
let pub = EddsaPrivateKey.pub_of_priv priv in
|
||||||
Ok (Some { priv; pub; t1; t2 }))
|
Ok (Some { priv; pub; t1; t2 }))
|
||||||
|
|
||||||
let sm_key_fpath = Fpath.(v Cfg.key_dir / Cfg.sm_priv_key)
|
|
||||||
|
|
||||||
let load () =
|
let load () =
|
||||||
let* l = get_key_dir_contents Cfg.key_dir in
|
let* l = get_key_dir_contents Cfg.key_dir in
|
||||||
let* l = list_map load_key l in
|
let* l = list_map load_key l in
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue