fix secmod add/write; + wip test revoke
This commit is contained in:
parent
651c422cb1
commit
c04fda0f1e
8 changed files with 165 additions and 45 deletions
|
|
@ -57,11 +57,17 @@ let write_eddsa fpath priv =
|
|||
let write_key k = write_eddsa (key_fpath k) k.priv
|
||||
|
||||
let delete_file fpath =
|
||||
Log.debug (fun m -> m "(disabled) delete key file `%a`" Fpath.pp fpath);
|
||||
(* TODO just to be safe~~
|
||||
(* check fpath just to be safe *)
|
||||
let () =
|
||||
let root = Fpath.v Cfg.key_dir in
|
||||
if not @@ Fpath.is_rooted ~root fpath then
|
||||
Fmt.failwith
|
||||
"delete_file failure: file `%a` is not contained in secmod directory"
|
||||
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
|
||||
*)
|
||||
Ok ()
|
||||
()
|
||||
|
||||
let get_key_dir_contents dir =
|
||||
let* dir = Fpath.of_string dir |> unwrap_err_msg in
|
||||
|
|
@ -70,7 +76,7 @@ let get_key_dir_contents dir =
|
|||
let+ l =
|
||||
Bos.OS.Dir.contents ~dotfiles:false ~rel:false dir |> unwrap_err_msg
|
||||
in
|
||||
l
|
||||
List.map Fpath.normalize l
|
||||
|
||||
(* -- *)
|
||||
|
||||
|
|
@ -131,11 +137,7 @@ let load_key fpath =
|
|||
|
||||
let load () =
|
||||
let* l = get_key_dir_contents Cfg.key_dir in
|
||||
let l =
|
||||
l
|
||||
|> List.map Fpath.normalize
|
||||
|> List.filter (fun fpath -> not @@ Fpath.equal fpath sm_key_fpath)
|
||||
in
|
||||
let l = List.filter (fun fpath -> not @@ Fpath.equal fpath sm_key_fpath) l in
|
||||
let* keys = list_map load_key l in
|
||||
match keys with
|
||||
| [] -> Ok None
|
||||
|
|
@ -162,7 +164,7 @@ let init () =
|
|||
let now = TimeAbsolute.of_ptime (Ptime_clock.now ()) in
|
||||
let keys = List.of_seq @@ Hashtbl.to_seq_values t.ht in
|
||||
let new_keys = gen_additional_keys_until_lookahead ~now keys in
|
||||
let () = List.iter (fun k -> Hashtbl.replace t.ht k.pub k) keys in
|
||||
List.iter (fun k -> Hashtbl.replace t.ht k.pub k) new_keys;
|
||||
let+ () = list_iter write_key new_keys in
|
||||
t
|
||||
|
||||
|
|
@ -178,6 +180,7 @@ module Make () = struct
|
|||
let add t1 t2 =
|
||||
let k = gen_key t1 t2 in
|
||||
Hashtbl.replace t.ht k.pub k;
|
||||
let+ () = write_key k in
|
||||
()
|
||||
|
||||
let delete pub =
|
||||
|
|
@ -206,7 +209,8 @@ module Make () = struct
|
|||
let revoke pub =
|
||||
let* k = find pub in
|
||||
let* () = delete pub in
|
||||
add k.t1 k.t2; Ok ()
|
||||
let* () = add k.t1 k.t2 in
|
||||
Ok ()
|
||||
|
||||
let conv = fun { priv= _; pub; t1; t2 } -> (pub, (t1, t2))
|
||||
let keys () = Hashtbl.to_seq_values t.ht |> List.of_seq |> List.map conv
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue