+ test disable auditor
This commit is contained in:
parent
05cfa7a5b1
commit
f3c6424ec9
8 changed files with 90 additions and 73 deletions
19
src/auditor.ml
Normal file
19
src/auditor.ml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
type t = {
|
||||
auditor_pub: Crypto.EddsaPublicKey.t;
|
||||
auditor_url: string;
|
||||
auditor_name: string;
|
||||
last_change: Timestamp.t;
|
||||
is_active: bool;
|
||||
}
|
||||
|
||||
let of_setup_message
|
||||
Api.AuditorSetupMessage.
|
||||
{ auditor_url; auditor_name; auditor_pub; master_sig= _; validity_start }
|
||||
=
|
||||
{
|
||||
auditor_url;
|
||||
auditor_name;
|
||||
auditor_pub;
|
||||
last_change= validity_start;
|
||||
is_active= true;
|
||||
}
|
||||
|
|
@ -153,24 +153,22 @@ module Auditors = struct
|
|||
h_auditor_url= Hash.Cstring.H64.hash auditor_url;
|
||||
}
|
||||
|
||||
(* TODO monotonic time *)
|
||||
let do_ ~db_conn v =
|
||||
let auditor_pub = v.AuditorSetupMessage.auditor_pub in
|
||||
let validity_start = v.AuditorSetupMessage.validity_start in
|
||||
let* last_date_opt =
|
||||
Pg.get_auditor_timestamp db_conn auditor_pub |> unwrap_err_caqti
|
||||
in
|
||||
match last_date_opt with
|
||||
let* opt = Pg.find_auditor db_conn auditor_pub |> unwrap_err_caqti in
|
||||
match opt with
|
||||
| None ->
|
||||
let+ () = Pg.insert_auditor db_conn v |> unwrap_err_caqti in
|
||||
let auditor = Auditor.of_setup_message v in
|
||||
let+ () = Pg.update_auditor db_conn auditor |> unwrap_err_caqti in
|
||||
Logs.info (fun m -> m "enabled auditor");
|
||||
()
|
||||
| Some last_date ->
|
||||
if Timestamp.compare last_date validity_start > 0 then
|
||||
| Some auditor ->
|
||||
if Timestamp.compare auditor.last_change validity_start > 0 then
|
||||
Error
|
||||
"database has more recent auditor data for this auditor public key"
|
||||
else
|
||||
let+ () = Pg.update_auditor db_conn v |> unwrap_err_caqti in
|
||||
let+ () = Pg.update_auditor db_conn auditor |> unwrap_err_caqti in
|
||||
Logs.info (fun m -> m "updated auditor");
|
||||
()
|
||||
|
||||
|
|
@ -198,26 +196,36 @@ module Auditors_disable = struct
|
|||
|
||||
let do_ ~db_conn auditor_pub
|
||||
AuditorTeardownMessage.{ master_sig= _; validity_end } =
|
||||
let* last_date_opt =
|
||||
Pg.get_auditor_timestamp db_conn auditor_pub |> unwrap_err_caqti
|
||||
in
|
||||
match last_date_opt with
|
||||
let* opt = Pg.find_auditor db_conn auditor_pub |> unwrap_err_caqti in
|
||||
match opt with
|
||||
| None -> Error "auditor not found"
|
||||
| Some last_date ->
|
||||
if Timestamp.compare last_date validity_end > 0 then
|
||||
Error
|
||||
"database has more recent auditor data for this auditor public key"
|
||||
else
|
||||
let+ () =
|
||||
Pg.disable_auditor db_conn ~auditor_pub ~change_date:validity_end
|
||||
|> unwrap_err_caqti
|
||||
in
|
||||
()
|
||||
| Some auditor -> (
|
||||
match Timestamp.compare auditor.last_change validity_end > 0 with
|
||||
| true ->
|
||||
Error
|
||||
"database has more recent auditor data for this auditor public \
|
||||
key"
|
||||
| false -> (
|
||||
match auditor.is_active with
|
||||
| false ->
|
||||
Logs.info (fun m -> m "auditor was already revoked");
|
||||
Ok ()
|
||||
| true ->
|
||||
let auditor =
|
||||
{ auditor with last_change= validity_end; is_active= false }
|
||||
in
|
||||
let+ () =
|
||||
Pg.update_auditor db_conn auditor |> unwrap_err_caqti
|
||||
in
|
||||
Logs.info (fun m ->
|
||||
m "revoked auditor `%s`"
|
||||
(Crypto.EddsaPublicKey.to_b32 auditor_pub));
|
||||
()))
|
||||
|
||||
let jsont = AuditorTeardownMessage.jsont
|
||||
|
||||
let f req auditor_pub server _env =
|
||||
Logs.info (fun m -> m "POST /management/auditors/$AUDITOR_PUB/revoke/");
|
||||
Logs.info (fun m -> m "POST /management/auditors/$AUDITOR_PUB/disable/");
|
||||
let keys = Vif.Server.device Devices.keys server in
|
||||
let db_conn = Vif.Server.device Devices.db_connection server in
|
||||
let res =
|
||||
|
|
|
|||
41
src/pg.ml
41
src/pg.ml
|
|
@ -115,43 +115,23 @@ let insert_signkey_revocation =
|
|||
fun (module Conn : CONN) exchange_pub master_sig ->
|
||||
Conn.exec req (exchange_pub, master_sig)
|
||||
|
||||
let get_auditor_timestamp =
|
||||
let find_auditor =
|
||||
let req =
|
||||
Caqti_type.(eddsa_pub ->? time)
|
||||
"SELECT last_change FROM auditors WHERE auditor_pub=$1"
|
||||
Caqti_type.(eddsa_pub ->? auditor)
|
||||
"SELECT auditor_pub, auditor_name, auditor_url, last_change, is_active \
|
||||
FROM auditors WHERE auditor_pub=$1"
|
||||
in
|
||||
fun (module Conn : CONN) auditor_pub -> Conn.find_opt req auditor_pub
|
||||
|
||||
let insert_auditor =
|
||||
let req =
|
||||
Caqti_type.(t4 eddsa_pub string string time ->. unit)
|
||||
"INSERT INTO auditors (auditor_pub, auditor_name, auditor_url, \
|
||||
is_active, last_change) VALUES ($1, $2, $3, true, $4)"
|
||||
in
|
||||
fun (module Conn : CONN)
|
||||
AuditorSetupMessage.
|
||||
{ auditor_url; auditor_name; auditor_pub; master_sig= _; validity_start }
|
||||
-> Conn.exec req (auditor_pub, auditor_name, auditor_url, validity_start)
|
||||
|
||||
let update_auditor =
|
||||
let req =
|
||||
Caqti_type.(t5 eddsa_pub string string bool time ->. unit)
|
||||
"UPDATE auditors SET auditor_url=$2, auditor_name=$3, is_active=$4, \
|
||||
last_change=$5 WHERE auditor_pub=$1"
|
||||
Caqti_type.(auditor ->. unit)
|
||||
"INSERT INTO auditors (auditor_pub, auditor_name, auditor_url, \
|
||||
last_change, is_active) VALUES ($1, $2, $3, $4, $5) ON CONFLICT \
|
||||
(auditor_pub) DO UPDATE SET auditor_name=$2, auditor_url=$3, \
|
||||
last_change=$4, is_active=$5"
|
||||
in
|
||||
fun (module Conn : CONN)
|
||||
AuditorSetupMessage.
|
||||
{ auditor_url; auditor_name; auditor_pub; master_sig= _; validity_start }
|
||||
-> Conn.exec req (auditor_pub, auditor_url, auditor_name, true, validity_start)
|
||||
|
||||
let disable_auditor =
|
||||
let req =
|
||||
Caqti_type.(t5 eddsa_pub string string bool time ->. unit)
|
||||
"UPDATE auditors SET auditor_url=$2, auditor_name=$3, is_active=$4, \
|
||||
last_change=$5 WHERE auditor_pub=$1"
|
||||
in
|
||||
fun (module Conn : CONN) ~auditor_pub ~change_date ->
|
||||
Conn.exec req (auditor_pub, "", "", false, change_date)
|
||||
fun (module Conn : CONN) auditor -> Conn.exec req auditor
|
||||
|
||||
let insert_auditor_denom_sig =
|
||||
let req =
|
||||
|
|
@ -167,6 +147,7 @@ let insert_auditor_denom_sig =
|
|||
Conn.exec req (auditor_pub, h_denom_pub, auditor_sig)
|
||||
|
||||
(* todo auditors
|
||||
map to Auditor.t record
|
||||
maybe check that url and name are unique/same for each auditor_pub
|
||||
and do the ht logic out of pg.ml? *)
|
||||
(* this does not return auditors that are not auditing any denom *)
|
||||
|
|
|
|||
|
|
@ -351,3 +351,14 @@ let exchange_partner_setup =
|
|||
wad_fee;
|
||||
})
|
||||
Caqti_type.(t7 eddsa_pub time time time_span amount master_sig string)
|
||||
|
||||
let auditor =
|
||||
let open Auditor in
|
||||
Caqti_type.custom
|
||||
~encode:(fun
|
||||
{ auditor_pub; auditor_url; auditor_name; last_change; is_active } ->
|
||||
Ok (auditor_pub, auditor_url, auditor_name, last_change, is_active))
|
||||
~decode:(fun
|
||||
(auditor_pub, auditor_url, auditor_name, last_change, is_active) ->
|
||||
Ok { auditor_pub; auditor_url; auditor_name; last_change; is_active })
|
||||
Caqti_type.(t5 eddsa_pub string string time bool)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue