From 0852f84c8b8dc5d342d872a26c21c74a1418814c Mon Sep 17 00:00:00 2001 From: swrup Date: Tue, 17 Feb 2026 05:19:17 +0100 Subject: [PATCH] --- aaapriv | 1 + aaapriv.pub | 1 + tools/offline.ml | 27 +++++++++++++++++++++------ tools/offline_impl.ml | 22 ++++++++++++++++------ 4 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 aaapriv create mode 100644 aaapriv.pub diff --git a/aaapriv b/aaapriv new file mode 100644 index 00000000..e0383d88 --- /dev/null +++ b/aaapriv @@ -0,0 +1 @@ +-óóÔáÊ’Ó„Î"Œñã{Åá®Vîú©Ï7!lV)d \ No newline at end of file diff --git a/aaapriv.pub b/aaapriv.pub new file mode 100644 index 00000000..40dd7f2d --- /dev/null +++ b/aaapriv.pub @@ -0,0 +1 @@ +47NR39C2HZ0CZBF7SKSTC3XVS2E5QZTSCC07SC43RFJNNHP44YR0 \ No newline at end of file diff --git a/tools/offline.ml b/tools/offline.ml index 5864bd0c..78c99b9e 100644 --- a/tools/offline.ml +++ b/tools/offline.ml @@ -85,25 +85,40 @@ let url = Arg.(required & opt (some string) None & info [ "url" ] ~doc) let setup_cmd = - let doc = "Generate offline master keys" in + let doc = + "Generate offline master keys, write private and public key to file" + in let output = - let doc = "output file" in + let doc = "private key output file" in Arg.(required & opt (some filepath) None & info [ "o"; "output" ] ~doc) in + let output_pubkey = + let doc = + "public key output file, default to --output parameter with a \".pub\" \ + extension" + in + Arg.(value & opt (some filepath) None & info [ "output-pubkey" ] ~doc) + in Cmd.make (Cmd.info "setup" ~doc) @@ - let+ output = output in - setup ~output + let+ output = output and+ output_pubkey = output_pubkey in + let output_pubkey = Option.value ~default:(output ^ ".pub") output_pubkey in + setup ~output ~output_pubkey let download_cmd = - let doc = "GET" in + let doc = + "use curl to send a GET request to --url, write response body to --output" + in Cmd.make (Cmd.info "download" ~doc) @@ let+ output = output and+ url = url in download ~output ~url let upload_cmd = - let doc = "POST" in + let doc = + "use curl to send a POST request to --url, with request body set to \ + --input file content" + in Cmd.make (Cmd.info "upload" ~doc) @@ let+ input = input and+ url = url in diff --git a/tools/offline_impl.ml b/tools/offline_impl.ml index d8a1fa18..9a851fa5 100644 --- a/tools/offline_impl.ml +++ b/tools/offline_impl.ml @@ -163,7 +163,16 @@ let read_master_key_file filename = let download ~output ~url = let open Bos in - OS.Cmd.run Cmd.(v "curl" % "--silent" % "-o" % output % "-X" % "GET" % url) + OS.Cmd.run + Cmd.( + v "curl" + % "--silent" + % "--show-error" + % "-o" + % output + % "-X" + % "GET" + % url) |> unwrap_err_msg let upload ~input ~url = @@ -182,13 +191,14 @@ let upload ~input ~url = % url) |> unwrap_err_msg -let setup ~output = - let () = Mirage_crypto_rng_unix.use_default () in +let setup ~output ~output_pubkey = + Mirage_crypto_rng_unix.use_default (); let priv, pub = Mirage_crypto_ec.Ed25519.generate () in - Fmt.pr "generated master public key:@\n%s@." - (Mirage_crypto_ec.Ed25519.pub_to_octets pub |> B32.encode); let priv_data = Mirage_crypto_ec.Ed25519.priv_to_octets priv in - write_file output priv_data + let* () = write_file output priv_data in + let pub_data = Mirage_crypto_ec.Ed25519.pub_to_octets pub |> B32.encode in + let* () = write_file output_pubkey pub_data in + Ok () let sign ~master_key ~input ~output = let open Crypto in