This commit is contained in:
parent
b34d644eb5
commit
e968d2767f
1 changed files with 14 additions and 19 deletions
|
|
@ -205,16 +205,13 @@ module Make (Conn : Pg.CONN) = struct
|
||||||
let database_find_sk conn pub =
|
let database_find_sk conn 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
|
||||||
| None ->
|
| None -> Fmt.error "secmod: signkey data not found in database"
|
||||||
Fmt.error "secmod failure: a signkey could not be found in database"
|
|
||||||
| Some sk_data -> Ok sk_data
|
| Some sk_data -> Ok sk_data
|
||||||
|
|
||||||
let database_find_dn conn h_pub =
|
let database_find_dn conn h_pub =
|
||||||
let* opt = Pg.find_denom conn h_pub |> unwrap_err_caqti in
|
let* opt = Pg.find_denom conn h_pub |> unwrap_err_caqti in
|
||||||
match opt with
|
match opt with
|
||||||
| None ->
|
| None -> Fmt.error "secmod: denomination data not found in database"
|
||||||
Fmt.error
|
|
||||||
"secmod failure: a denomination could not be found in database"
|
|
||||||
| Some dn_data -> Ok dn_data
|
| Some dn_data -> Ok dn_data
|
||||||
|
|
||||||
let list_to_ht l = Hashtbl.of_seq (List.to_seq l)
|
let list_to_ht l = Hashtbl.of_seq (List.to_seq l)
|
||||||
|
|
@ -311,7 +308,7 @@ module Make (Conn : Pg.CONN) = struct
|
||||||
|
|
||||||
let sign_with_signkey ~pub s =
|
let sign_with_signkey ~pub s =
|
||||||
match Hashtbl.find_opt t.sk_key_ht pub with
|
match Hashtbl.find_opt t.sk_key_ht pub with
|
||||||
| None -> Fmt.failwith "secmod failure: signkey not found."
|
| None -> Fmt.failwith "secmod sign_with_signkey failure: not found."
|
||||||
| Some priv -> EddsaSignature.sign ~key:priv s
|
| Some priv -> EddsaSignature.sign ~key:priv s
|
||||||
|
|
||||||
let verify_with_sm_key s ~msg = EddsaSignature.verify ~key:t.sm_pubkey s ~msg
|
let verify_with_sm_key s ~msg = EddsaSignature.verify ~key:t.sm_pubkey s ~msg
|
||||||
|
|
@ -320,10 +317,9 @@ module Make (Conn : Pg.CONN) = struct
|
||||||
EddsaSignature.verify ~key:Config.master_public_key
|
EddsaSignature.verify ~key:Config.master_public_key
|
||||||
|
|
||||||
let verify_with_signkey ~pub s ~msg =
|
let verify_with_signkey ~pub s ~msg =
|
||||||
(* check that [pub] is one of our own keys *)
|
|
||||||
match Hashtbl.find_opt t.sk_ht pub with
|
match Hashtbl.find_opt t.sk_ht pub with
|
||||||
| None -> Fmt.failwith "secmod failure: signkey not found."
|
| None -> Fmt.failwith "secmod verify_with_signkey failure: not found."
|
||||||
| Some _priv -> EddsaSignature.verify ~key:pub s ~msg
|
| Some _sk -> EddsaSignature.verify ~key:pub s ~msg
|
||||||
|
|
||||||
let get_signkeys () = t.sk_ht |> Hashtbl.to_seq_values |> List.of_seq
|
let get_signkeys () = t.sk_ht |> Hashtbl.to_seq_values |> List.of_seq
|
||||||
let get_denominations () = t.dn_ht |> Hashtbl.to_seq_values |> List.of_seq
|
let get_denominations () = t.dn_ht |> Hashtbl.to_seq_values |> List.of_seq
|
||||||
|
|
@ -344,11 +340,11 @@ module Make (Conn : Pg.CONN) = struct
|
||||||
( Hashtbl.find_opt t.future_sk_ht pub,
|
( Hashtbl.find_opt t.future_sk_ht pub,
|
||||||
Hashtbl.find_opt t.future_sk_key_ht pub )
|
Hashtbl.find_opt t.future_sk_key_ht pub )
|
||||||
with
|
with
|
||||||
| None, _ | _, None -> Error "secmod failure: future signkey not found."
|
| None, _ | _, None ->
|
||||||
|
Error "secmod certify_future_signkey: future signkey not found."
|
||||||
| Some future_sk, Some priv -> (
|
| Some future_sk, Some priv -> (
|
||||||
match Hashtbl.find_opt t.sk_ht pub with
|
match Hashtbl.find_opt t.sk_ht pub with
|
||||||
| Some _sk ->
|
| Some _sk -> Error "secmod certify_future_signkey: already certified"
|
||||||
Error "secmod failure: this signkey already has a master signature"
|
|
||||||
| None ->
|
| None ->
|
||||||
let Api.FutureSignKey.
|
let Api.FutureSignKey.
|
||||||
{
|
{
|
||||||
|
|
@ -385,12 +381,12 @@ module Make (Conn : Pg.CONN) = struct
|
||||||
Hashtbl.find_opt t.future_dn_key_ht h_pub )
|
Hashtbl.find_opt t.future_dn_key_ht h_pub )
|
||||||
with
|
with
|
||||||
| None, _ | _, None ->
|
| None, _ | _, None ->
|
||||||
Error "secmod failure: future denomination not found."
|
Error
|
||||||
|
"secmod certify_future_denomination: future denomination not found."
|
||||||
| Some future_dn, Some priv -> (
|
| Some future_dn, Some priv -> (
|
||||||
match Hashtbl.find_opt t.dn_ht h_pub with
|
match Hashtbl.find_opt t.dn_ht h_pub with
|
||||||
| Some _dn ->
|
| Some _dn ->
|
||||||
Error
|
Error "secmod certify_future_denomination: already certified"
|
||||||
"secmod failure: this denomination already has a master signature"
|
|
||||||
| None ->
|
| None ->
|
||||||
let Api.FutureDenom.
|
let Api.FutureDenom.
|
||||||
{
|
{
|
||||||
|
|
@ -443,7 +439,7 @@ module Make (Conn : Pg.CONN) = struct
|
||||||
|
|
||||||
let revoke_signkey pub revoked_sig =
|
let revoke_signkey pub revoked_sig =
|
||||||
match Hashtbl.find_opt t.sk_ht pub with
|
match Hashtbl.find_opt t.sk_ht pub with
|
||||||
| None -> Error "secmod failure: signkey not found."
|
| None -> Error "secmod revoke_signkey: signkey not found."
|
||||||
| Some sk ->
|
| Some sk ->
|
||||||
let sk = { sk with revoked_sig= Some revoked_sig } in
|
let sk = { sk with revoked_sig= Some revoked_sig } in
|
||||||
Hashtbl.replace t.sk_ht pub sk;
|
Hashtbl.replace t.sk_ht pub sk;
|
||||||
|
|
@ -453,7 +449,7 @@ module Make (Conn : Pg.CONN) = struct
|
||||||
|
|
||||||
let revoke_denomination pub revoked_sig =
|
let revoke_denomination pub revoked_sig =
|
||||||
match Hashtbl.find_opt t.dn_ht pub with
|
match Hashtbl.find_opt t.dn_ht pub with
|
||||||
| None -> Error "secmod failure: denomination not found."
|
| None -> Error "secmod revoke_denomination: denomination not found."
|
||||||
| Some dn ->
|
| Some dn ->
|
||||||
let dn = { dn with revoked_sig= Some revoked_sig } in
|
let dn = { dn with revoked_sig= Some revoked_sig } in
|
||||||
Hashtbl.replace t.dn_ht pub dn;
|
Hashtbl.replace t.dn_ht pub dn;
|
||||||
|
|
@ -474,8 +470,7 @@ module Make (Conn : Pg.CONN) = struct
|
||||||
|> List.of_seq
|
|> List.of_seq
|
||||||
|> list_iter (fun (h_pub, priv) ->
|
|> list_iter (fun (h_pub, priv) ->
|
||||||
match Hashtbl.find_opt t.dn_section_name_ht h_pub with
|
match Hashtbl.find_opt t.dn_section_name_ht h_pub with
|
||||||
| None ->
|
| None -> Error "secmod save: invalid state, section_name not found"
|
||||||
Fmt.failwith "secmod save: invalid state, section_name not found"
|
|
||||||
| Some section_name -> write_rsa (dn_fname section_name) priv)
|
| Some section_name -> write_rsa (dn_fname section_name) priv)
|
||||||
in
|
in
|
||||||
Logs.info (fun m -> m "saved secmod private keys data");
|
Logs.info (fun m -> m "saved secmod private keys data");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue