This commit is contained in:
swrup 2026-02-10 11:59:51 +01:00
parent 0a45e7fe95
commit 201ea095bb
11 changed files with 20 additions and 13 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
_build _build
assets
data/secmod/* data/secmod/*
!data/secmod/.gitkeep !data/secmod/.gitkeep

View file

@ -1,9 +1,11 @@
open Parse_config open Parse_config
let config_filename = "mte.conf"
let secrets_dir = Fpath.v "secrets"
let config_data = let config_data =
let path = Fpath.to_string (Fpath.v "default.config") in match Assets_crunch.read config_filename with
match Assets_crunch.read path with | None -> fail "static file not found: `%s`" config_filename
| None -> fail "static file not found: `%s`" path
| Some data -> | Some data ->
let v = Config_section.parse data in let v = Config_section.parse data in
v v

View file

@ -37,8 +37,8 @@
(rule (rule
(target assets_crunch.ml) (target assets_crunch.ml)
(deps (deps
(source_tree ../data/assets/)) (source_tree ../assets))
(action (action
(with-stdout-to (with-stdout-to
%{null} %{null}
(run ocaml-crunch -m plain ../data/assets -o %{target})))) (run ocaml-crunch -m plain ../assets -o %{target}))))

View file

@ -74,8 +74,6 @@ module Make (Conn : Pg.CONN) = struct
dn_section_name_ht: (denomination_hash, string) Hashtbl.t; dn_section_name_ht: (denomination_hash, string) Hashtbl.t;
} }
let dir = Fpath.(v "data" / "secmod")
let db_lookup_signkey_data conn fname pub = let db_lookup_signkey_data conn fname pub =
let* opt = Pg.find_signkey conn pub |> unwrap_err_caqti in let* opt = Pg.find_signkey conn pub |> unwrap_err_caqti in
match opt with match opt with
@ -112,9 +110,13 @@ module Make (Conn : Pg.CONN) = struct
let error_invalid_state = let error_invalid_state =
Fmt.error "secmod load error: invalid store state." Fmt.error "secmod load error: invalid store state."
in in
let* sm_key_priv = Data_file.read_eddsa Fpath.(dir / "sk_sm") in let* sm_key_priv =
Data_file.read_eddsa Fpath.(Config.secrets_dir / "sk_sm")
in
let* signkeys = let* signkeys =
let l = List.init 1 (fun i -> Fpath.(dir / Fmt.str "sk_%d" i)) in let l =
List.init 1 (fun i -> Fpath.(Config.secrets_dir / Fmt.str "sk_%d" i))
in
let* l = list_map (fun fname -> load_signkey conn fname) l in let* l = list_map (fun fname -> load_signkey conn fname) l in
match opt_list l with Error () -> error_invalid_state | Ok opt -> Ok opt match opt_list l with Error () -> error_invalid_state | Ok opt -> Ok opt
in in
@ -125,7 +127,7 @@ module Make (Conn : Pg.CONN) = struct
list_map list_map
(fun coin -> (fun coin ->
let section_name = coin.section_name in let section_name = coin.section_name in
let fname = Fpath.(dir / section_name) in let fname = Fpath.(Config.secrets_dir / section_name) in
let* opt = Data_file.read_rsa fname in let* opt = Data_file.read_rsa fname in
match opt with match opt with
| None -> Ok None | None -> Ok None
@ -378,12 +380,14 @@ module Make (Conn : Pg.CONN) = struct
let store () = let store () =
Miou.Mutex.protect t.lock @@ fun () -> Miou.Mutex.protect t.lock @@ fun () ->
let* () = Data_file.write_eddsa Fpath.(dir / "sk_sm") t.sm_key_priv in let* () =
Data_file.write_eddsa Fpath.(Config.secrets_dir / "sk_sm") t.sm_key_priv
in
let* () = let* () =
Hashtbl.to_seq_values t.sk_ht Hashtbl.to_seq_values t.sk_ht
|> List.of_seq |> List.of_seq
|> List.mapi (fun i (key : signkey) -> |> List.mapi (fun i (key : signkey) ->
let fname = Fpath.(dir / Fmt.str "sk_%d" i) in let fname = Fpath.(Config.secrets_dir / Fmt.str "sk_%d" i) in
(fname, key.priv)) (fname, key.priv))
|> list_iter (fun (fname, key) -> Data_file.write_eddsa fname key) |> list_iter (fun (fname, key) -> Data_file.write_eddsa fname key)
in in
@ -397,7 +401,7 @@ module Make (Conn : Pg.CONN) = struct
| None -> Error "invalid state, section_name not found" | None -> Error "invalid state, section_name not found"
| Some s -> Ok s | Some s -> Ok s
in in
let fname = Fpath.(dir / section_name) in let fname = Fpath.(Config.secrets_dir / section_name) in
(fname, key.priv)) (fname, key.priv))
in in
list_iter (fun (fname, key) -> Data_file.write_rsa fname key) l list_iter (fun (fname, key) -> Data_file.write_rsa fname key) l