+ wip /management/keys/

This commit is contained in:
swrup 2025-11-30 14:23:55 +01:00
parent cf4da6b382
commit 83dfd701c0
5 changed files with 30 additions and 53 deletions

View file

@ -1,5 +1,5 @@
(executable
(public_name offline)
(name offline)
(modules offline offline_signature)
(modules offline offline_bin)
(libraries cmdliner bos fmt mirage-crypto ptime mte vif))

View file

@ -1,36 +1,30 @@
(* TODO
- clean up cmdliner
- don't depends on wget
- setup: need public key in config file
- check sigs *)
(* doc: https://docs.taler.net/manpages/taler-exchange-offline.1.html *)
let version = "%%VERSION%%"
let base_url = Uri.of_string "http://localhost:3434/"
let download ~base_url ~output =
let download ~output =
let open Bos in
let uri =
Uri.with_path (Uri.of_string base_url) "/management/keys/" |> Uri.to_string
in
let wget = Cmd.(v "wget" % "-O" % output % uri) in
OS.Cmd.run wget
let uri = Uri.with_path base_url "/management/keys/" |> Uri.to_string in
OS.Cmd.run Cmd.(v "curl" (* % "-s" *) % "-o" % output % "-X" % "GET" % uri)
let upload ~base_url ~input =
let upload ~input =
let open Bos in
let uri =
Uri.with_path (Uri.of_string base_url) "/management/keys/" |> Uri.to_string
in
let wget =
let uri = Uri.with_path base_url "/management/keys/" |> Uri.to_string in
OS.Cmd.run
Cmd.(
v "wget"
% "--method=POST"
% "--header='Content-Type: application/json'"
% "--body-file"
% input
% "-O"
% "/dev/null"
v "curl"
% "-i"
% "-X"
% "POST"
% "-H"
% "Content-Type: application/json"
% "--data"
% ("@" ^ input)
% uri)
in
OS.Cmd.run wget
let setup ~output =
let output = Fpath.v output in
@ -52,8 +46,9 @@ let sign ~input ~output ~master_key =
let* master_key = File.read master_key |> unwrap_err_msg in
let master_key = EddsaPrivateKey.of_octets master_key in
let* future_key_response = Api.decode Api.FutureKeysResponse.jsont input in
let* () = Offline_bin.verify_future_key_response future_key_response in
let master_signatures =
Offline_signature.master_signatures ~master_key future_key_response
Offline_bin.make_master_signatures ~master_key future_key_response
in
let* s = Api.encode Api.MasterSignatures.jsont master_signatures in
let* () = File.write output s |> unwrap_err_msg in
@ -91,14 +86,10 @@ let download_cmd =
let doc = "File to save data to be signed." in
Arg.(value & opt filepath "future_keys.json" & info [ "o"; "output" ] ~doc)
in
let base_url =
let doc = "Base url of the exchange." in
Arg.(value & opt string "http://localhost:3434/" & info [ "base-url" ] ~doc)
in
Cmd.make (Cmd.info "download" ~version ~doc ~man)
@@
let+ output = output and+ base_url = base_url in
match download ~base_url ~output with
let+ output = output in
match download ~output with
| Error (`Msg err) ->
Fmt.epr "Download failure: %s@." err;
exit 1
@ -114,14 +105,10 @@ let upload_cmd =
Arg.(
value & opt filepath "master_signatures.json" & info [ "i"; "input" ] ~doc)
in
let base_url =
let doc = "Base url of the exchange." in
Arg.(value & opt string "http://localhost:3434/" & info [ "base-url" ] ~doc)
in
Cmd.make (Cmd.info "upload" ~version ~doc ~man)
@@
let+ input = input and+ base_url = base_url in
match upload ~base_url ~input with
let+ input = input in
match upload ~input with
| Error (`Msg err) ->
Fmt.epr "Upload failure: %s@." err;
exit 1

View file

@ -70,7 +70,7 @@ let signkey_signature ~master_key
in
Api.SignKeySignature.{ key; master_sig }
let master_signatures ~master_key
let make_master_signatures ~master_key
Api.FutureKeysResponse.
{
future_denoms;
@ -83,3 +83,5 @@ let master_signatures ~master_key
let denom_sigs = List.map (denom_signature ~master_key) future_denoms in
let signkey_sigs = List.map (signkey_signature ~master_key) future_signkeys in
Api.MasterSignatures.{ denom_sigs; signkey_sigs }
let verify_future_key_response _future_key_response = assert false