better secmod
This commit is contained in:
parent
f69f393abb
commit
bf45cdc6b1
6 changed files with 104 additions and 54 deletions
|
|
@ -2,7 +2,10 @@
|
|||
- key rotation
|
||||
- how many signkey to use?
|
||||
we just use 1 for now
|
||||
- does the secmod's own key as metadata/expiration date? *)
|
||||
- does the secmod's own key as metadata/expiration date?
|
||||
- something to refer to valid sk/dn
|
||||
|
||||
- eddsa.ml with phantom type for key-kind + signed-data-kind *)
|
||||
open Syntax
|
||||
open Crypto
|
||||
|
||||
|
|
@ -20,7 +23,31 @@ type t = {
|
|||
Hashtbl.t;
|
||||
}
|
||||
|
||||
let get_sm_key_priv t = t.sm_key_priv
|
||||
(* note: don't expose a signing function if we want a real "security module" one day *)
|
||||
let sign_with_sm_key t s = EddsaSignature.sign ~key:t.sm_key_priv s
|
||||
let verify_with_sm_key t s ~msg = EddsaSignature.verify ~key:t.sm_key_pub s ~msg
|
||||
|
||||
let verify_with_master_key s ~msg =
|
||||
EddsaSignature.verify ~key:Config.master_public_key s ~msg
|
||||
|
||||
(* TODO
|
||||
- do something to force `pub` to be one of the valid signkey
|
||||
how to handle revocation?
|
||||
raise exn for now *)
|
||||
let sign_with_signkey t ~pub s =
|
||||
Miou.Mutex.protect t.lock @@ fun () ->
|
||||
match Hashtbl.find_opt t.sk_ht pub with
|
||||
| None -> Fmt.failwith "secmod failure: public key not found."
|
||||
| Some signkey ->
|
||||
let v = EddsaSignature.sign ~key:signkey.priv s in
|
||||
v
|
||||
|
||||
let verify_with_signkey t ~pub s ~msg =
|
||||
Miou.Mutex.protect t.lock @@ fun () ->
|
||||
match Hashtbl.find_opt t.sk_ht pub with
|
||||
| None -> Error "secmod failure: public key not found."
|
||||
| Some signkey -> EddsaSignature.verify ~key:signkey.pub s ~msg
|
||||
|
||||
let get_sm_key_pub t = t.sm_key_pub
|
||||
|
||||
let get_signkeys t =
|
||||
|
|
@ -31,6 +58,12 @@ let get_denoms t =
|
|||
Miou.Mutex.protect t.lock @@ fun () ->
|
||||
Hashtbl.to_seq_values t.dn_ht |> List.of_seq
|
||||
|
||||
let find_signkey_data t pub =
|
||||
Miou.Mutex.protect t.lock @@ fun () -> Hashtbl.find_opt t.sk_ht pub
|
||||
|
||||
let find_denom_data t h_denom =
|
||||
Miou.Mutex.protect t.lock @@ fun () -> Hashtbl.find_opt t.dn_ht h_denom
|
||||
|
||||
let add_signkey_master_signatures conn t l =
|
||||
Miou.Mutex.protect t.lock @@ fun () ->
|
||||
list_iter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue