From ac2cb3d8ca8ec58510b34e7255ba7aa7e591e9ee Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 7 Jan 2024 00:33:43 -0500 Subject: [PATCH] keyfork: add `recover` porcelain to start keyforkd --- Cargo.lock | 22 ++++++++++--------- .../src/bin/keyfork-shard-combine-openpgp.rs | 8 +++++-- keyfork-shard/src/openpgp.rs | 2 +- keyfork/Cargo.toml | 2 ++ keyfork/src/cli/mod.rs | 9 ++++---- keyfork/src/cli/shard.rs | 6 ++++- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 335eb99..3432919 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1065,9 +1065,11 @@ dependencies = [ "keyfork-mnemonic-util", "keyfork-plumbing", "keyfork-shard", + "keyforkd", "serde", "smex", "thiserror", + "tokio", ] [[package]] @@ -1273,9 +1275,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "libloading" @@ -1365,9 +1367,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", "log", @@ -2190,9 +2192,9 @@ version = "0.1.0" [[package]] name = "socket2" -version = "0.5.3" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" dependencies = [ "libc", "windows-sys 0.48.0", @@ -2371,9 +2373,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.32.0" +version = "1.35.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" +checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" dependencies = [ "backtrace", "bytes", @@ -2390,9 +2392,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", diff --git a/keyfork-shard/src/bin/keyfork-shard-combine-openpgp.rs b/keyfork-shard/src/bin/keyfork-shard-combine-openpgp.rs index c7c4198..abfd00c 100644 --- a/keyfork-shard/src/bin/keyfork-shard-combine-openpgp.rs +++ b/keyfork-shard/src/bin/keyfork-shard-combine-openpgp.rs @@ -1,6 +1,6 @@ use std::{ env, - io::{stdin, stdout}, + io::stdin, path::PathBuf, process::ExitCode, }; @@ -40,13 +40,17 @@ fn run() -> Result<()> { .pop_front() .expect("any pgp encrypted message"); + let mut bytes = vec![]; + combine( cert_list, &encrypted_metadata, encrypted_messages.into(), - stdout(), + &mut bytes, )?; + print!("{}", smex::encode(&bytes)); + Ok(()) } diff --git a/keyfork-shard/src/openpgp.rs b/keyfork-shard/src/openpgp.rs index daaaadd..1bba1bb 100644 --- a/keyfork-shard/src/openpgp.rs +++ b/keyfork-shard/src/openpgp.rs @@ -559,7 +559,7 @@ pub fn combine( } output - .write_all(smex::encode(&secret).as_bytes()) + .write_all(&secret) .map_err(Error::Io)?; Ok(()) diff --git a/keyfork/Cargo.toml b/keyfork/Cargo.toml index f9d29e8..73dc447 100644 --- a/keyfork/Cargo.toml +++ b/keyfork/Cargo.toml @@ -14,3 +14,5 @@ smex = { version = "0.1.0", path = "../smex" } keyfork-plumbing = { version = "0.1.0", path = "../keyfork-plumbing" } keyfork-shard = { version = "0.1.0", path = "../keyfork-shard" } serde = { version = "1.0.192", features = ["derive"] } +keyforkd = { version = "0.1.0", path = "../keyforkd" } +tokio = { version = "1.35.1", default-features = false, features = ["rt-multi-thread"] } diff --git a/keyfork/src/cli/mod.rs b/keyfork/src/cli/mod.rs index 874af96..48516ac 100644 --- a/keyfork/src/cli/mod.rs +++ b/keyfork/src/cli/mod.rs @@ -3,6 +3,7 @@ use clap::{Parser, Subcommand}; mod mnemonic; mod provision; mod shard; +mod recover; /// The Kitchen Sink of Entropy. #[derive(Parser, Clone, Debug)] @@ -25,8 +26,8 @@ pub enum KeyforkCommands { #[command(subcommand_negates_reqs(true))] Provision(provision::Provision), - /// Keyforkd background daemon to manage derivation. - Daemon, + /// Recover a seed using a recovery mechanism and begin the Keyfork daemon. + Recover(recover::Recover), } impl KeyforkCommands { @@ -43,8 +44,8 @@ impl KeyforkCommands { KeyforkCommands::Provision(p) => { p.handle(keyfork)?; } - KeyforkCommands::Daemon => { - todo!() + KeyforkCommands::Recover(r) => { + r.handle(keyfork)?; } } Ok(()) diff --git a/keyfork/src/cli/shard.rs b/keyfork/src/cli/shard.rs index e9bce3f..945f10b 100644 --- a/keyfork/src/cli/shard.rs +++ b/keyfork/src/cli/shard.rs @@ -86,13 +86,17 @@ impl ShardExec for OpenPGP { .pop_front() .expect("any pgp encrypted message"); + let mut bytes = vec![]; + keyfork_shard::openpgp::combine( certs, &encrypted_metadata, encrypted_messages.into(), - output, + &mut bytes, )?; + write!(output, "{}", smex::encode(&bytes))?; + Ok(()) } }