clean up
This commit is contained in:
parent
d0ddee257e
commit
bcc940100a
20 changed files with 112 additions and 130 deletions
|
|
@ -1,3 +1,12 @@
|
|||
(* TODO
|
||||
! use lock
|
||||
schedule tasks
|
||||
sign: check timestamps before signing
|
||||
|
||||
list_issue_date: save timestamp of key generation
|
||||
key validity period:
|
||||
more checks + do not exceed lookahead
|
||||
refacto common parts with secmod_eddsa *)
|
||||
let src = Logs.Src.create "mte.secmod_eddsa"
|
||||
|
||||
module Log = (val Logs.src_log src : Logs.LOG)
|
||||
|
|
@ -46,13 +55,13 @@ let key_fpath k =
|
|||
|
||||
let read_key fpath =
|
||||
Log.debug (fun m -> m "reading key file `%a`" Fpath.pp fpath);
|
||||
let* data = Bos.OS.File.read fpath |> unwrap_err_msg in
|
||||
let* data = Bos.OS.File.read fpath |> unwrap_msg in
|
||||
EddsaPrivateKey.of_octets data
|
||||
|
||||
let write_eddsa fpath priv =
|
||||
Log.debug (fun m -> m "writing key file `%a`" Fpath.pp fpath);
|
||||
let data = EddsaPrivateKey.to_octets priv in
|
||||
Bos.OS.File.write fpath data |> unwrap_err_msg
|
||||
Bos.OS.File.write fpath data |> unwrap_msg
|
||||
|
||||
let write_key k = write_eddsa (key_fpath k) k.priv
|
||||
|
||||
|
|
@ -66,16 +75,14 @@ let delete_file fpath =
|
|||
Fpath.pp fpath
|
||||
in
|
||||
Log.debug (fun m -> m "delete key file `%a`" Fpath.pp fpath);
|
||||
let+ () = Bos.OS.File.delete ~must_exist:true fpath |> unwrap_err_msg in
|
||||
let+ () = Bos.OS.File.delete ~must_exist:true fpath |> unwrap_msg in
|
||||
()
|
||||
|
||||
let get_key_dir_contents dir =
|
||||
let* dir = Fpath.of_string dir |> unwrap_err_msg in
|
||||
let* b = Bos.OS.Dir.create ~mode:0o700 dir |> unwrap_err_msg in
|
||||
let* dir = Fpath.of_string dir |> unwrap_msg in
|
||||
let* b = Bos.OS.Dir.create ~mode:0o700 dir |> unwrap_msg in
|
||||
if b then Log.info (fun m -> m "created directory `%a`" Fpath.pp dir);
|
||||
let+ l =
|
||||
Bos.OS.Dir.contents ~dotfiles:false ~rel:false dir |> unwrap_err_msg
|
||||
in
|
||||
let+ l = Bos.OS.Dir.contents ~dotfiles:false ~rel:false dir |> unwrap_msg in
|
||||
List.map Fpath.normalize l
|
||||
|
||||
(* -- *)
|
||||
|
|
@ -103,7 +110,6 @@ let split_in_periodes ~start ~end_ =
|
|||
in
|
||||
go acc start end_
|
||||
|
||||
(* TODO do not exceed lookahead (probably more important...) *)
|
||||
(* try to not generate keys with validity start in the past *)
|
||||
let gen_additional_keys_until_lookahead ~now l =
|
||||
let start =
|
||||
|
|
@ -118,11 +124,10 @@ let gen_additional_keys_until_lookahead ~now l =
|
|||
let new_keys = List.map (fun (t1, t2) -> gen_key t1 t2) periodes in
|
||||
new_keys
|
||||
|
||||
(* TODO config *)
|
||||
let sm_key_fpath =
|
||||
Result.get_ok
|
||||
@@
|
||||
let+ fpath = Fpath.of_string Cfg.sm_priv_key |> unwrap_err_msg in
|
||||
let+ fpath = Fpath.of_string Cfg.sm_priv_key |> unwrap_msg in
|
||||
Fpath.normalize fpath
|
||||
|
||||
(* we load sm_key separately
|
||||
|
|
@ -216,10 +221,3 @@ module Make () = struct
|
|||
let keys () = Hashtbl.to_seq_values t.ht |> List.of_seq |> List.map conv
|
||||
let find_key pub = Hashtbl.find_opt t.ht pub |> Option.map conv
|
||||
end
|
||||
|
||||
(* TODO
|
||||
- more checks
|
||||
- sign: check timestamps before signing
|
||||
- schedule tasks
|
||||
- !lock
|
||||
*)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue