This commit is contained in:
swrup 2026-02-21 16:45:59 +01:00
parent 84c3b8bec5
commit 7f440077ed
6 changed files with 101 additions and 96 deletions

View file

@ -1,28 +1,35 @@
(* TODO better error type *)
type 'a result = ('a, string) Result.t
module type S = Mod_intf.S
module type S = Mod_intf.KEYS
module Make (Conn : Pg.CONN) = struct
let conn = (module Conn : Pg.CONN)
open Syntax
open Crypto
let master_pub = Config.Exchange.master_public_key
let secmod_rsa_pub = Secmod_rsa.sm_key_pub
let secmod_eddsa_pub = Secmod_eddsa.sm_key_pub
let secmod_rsa_pub = Secmod_rsa.sm_pub
let secmod_eddsa_pub = Secmod_eddsa.sm_pub
let sign ~pub s =
Secmod_eddsa.sign ~pub s |> function
(* TODO error
should be a "key not found", either:
- we tried to sign with a key that is not ours
- key was revoked
- bad keyring state
*)
let sign pub s =
match Secmod_eddsa.sign ~pub s with
| Error e -> Fmt.failwith "sign failure: %s." e
| Ok v -> v
let sign_denom ~pub s =
Secmod_rsa.sign ~pub s |> function
let sign_denom pub s =
match Secmod_rsa.sign ~pub s with
| Error e -> Fmt.failwith "sign_denom failure: %s." e
| Ok v -> v
(* - *)
let conn = (module Conn : Pg.CONN)
let find_signkey pub = Pg.find_signkey conn pub |> unwrap_err_caqti
let find_denomination h_pub = Pg.find_denom conn h_pub |> unwrap_err_caqti
@ -42,8 +49,7 @@ module Make (Conn : Pg.CONN) = struct
let exchange_pub = pub in
let anchor_time = stamp_start in
let duration = Timestamp.diff stamp_start stamp_expire in
signf Secmod_eddsa.sign_with_sm_key
{ exchange_pub; anchor_time; duration }
signf Secmod_eddsa.sign_secmod { exchange_pub; anchor_time; duration }
in
Api.FutureSignKey.
{ key= pub; stamp_start; stamp_expire; stamp_end; signkey_secmod_sig }
@ -90,7 +96,7 @@ module Make (Conn : Pg.CONN) = struct
let duration_withdraw =
Timestamp.diff stamp_start stamp_expire_withdraw
in
signf Secmod_rsa.sign_with_sm_key
signf Secmod_rsa.sign_secmod
{ h_denom_pub; h_section_name; anchor_time; duration_withdraw }
in
FutureDenom.
@ -265,25 +271,21 @@ module Make (Conn : Pg.CONN) = struct
let revoke_signkey pub revoked_sig =
let* opt = find_signkey pub in
match opt with
| None -> Error "signkey not found"
| Some _sk ->
let* () = Secmod_eddsa.revoke_key pub in
let+ () =
Pg.insert_signkey_revocation conn pub revoked_sig |> unwrap_err_caqti
in
()
let* _sk = Option.to_result ~none:"signkey not found" opt in
let* () = Secmod_eddsa.revoke pub in
let+ () =
Pg.insert_signkey_revocation conn pub revoked_sig |> unwrap_err_caqti
in
()
let revoke_denomination h_pub revoked_sig =
let* opt = find_denomination h_pub in
match opt with
| None -> Error "denomination not found"
| Some sk ->
let pub = sk.pub in
let* () = Secmod_rsa.revoke_key pub in
let+ () =
Pg.insert_denomination_revocation conn h_pub revoked_sig
|> unwrap_err_caqti
in
()
let* dn = Option.to_result ~none:"denomination not found" opt in
let pub = dn.pub in
let* () = Secmod_rsa.revoke pub in
let+ () =
Pg.insert_denomination_revocation conn h_pub revoked_sig
|> unwrap_err_caqti
in
()
end